CombinedText stringlengths 4 3.42M |
|---|
-- C35A07D.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 FOR FIXED POINT TYPES THE FIRST AND LAST ATTRIBUTES YIELD
-- CORRECT VALUES.
-- CASE D: TYPES TYPICAL OF APPLICATIONS USING FIXED POINT ARITHMETIC.
-- WRG 8/25/86
-- PWN 01/31/95 REMOVED INCONSISTENCIES WITH ADA 9X.
WITH REPORT; USE REPORT;
WITH SYSTEM; USE SYSTEM;
PROCEDURE C35A07D IS
PI : CONSTANT := 3.14159_26535_89793_23846;
TWO_PI : CONSTANT := 2 * PI;
HALF_PI : CONSTANT := PI / 2;
MM : CONSTANT := MAX_MANTISSA;
-- THE NAME OF EACH TYPE OR SUBTYPE ENDS WITH THAT TYPE'S
-- 'MANTISSA VALUE.
TYPE PIXEL_M10 IS DELTA 1.0 / 1024.0 RANGE 0.0 .. 1.0;
TYPE RULER_M8 IS DELTA 1.0 / 16.0 RANGE 0.0 .. 12.0;
TYPE HOURS_M16 IS DELTA 24.0 * 2.0 ** (-15) RANGE 0.0 .. 24.0;
TYPE MILES_M16 IS DELTA 3000.0 * 2.0 ** (-15) RANGE 0.0 .. 3000.0;
TYPE SYMMETRIC_DEGREES_M7 IS
DELTA 2.0 RANGE -180.0 .. 180.0;
TYPE NATURAL_DEGREES_M15 IS
DELTA 2.0 ** (-6) RANGE 0.0 .. 360.0;
TYPE SYMMETRIC_RADIANS_M16 IS
DELTA PI * 2.0 ** (-15) RANGE -PI .. PI;
-- 'SMALL = 2.0 ** (-14) = 0.00006_10351_5625.
TYPE NATURAL_RADIANS_M8 IS
DELTA TWO_PI * 2.0 ** ( -7) RANGE 0.0 .. TWO_PI;
-- 'SMALL = 2.0 ** ( -5) = 0.03125.
-------------------------------------------------------------------
SUBTYPE ST_MILES_M8 IS MILES_M16
DELTA 3000.0 * 2.0 ** (-15) RANGE 0.0 .. 10.0;
SUBTYPE ST_NATURAL_DEGREES_M11 IS NATURAL_DEGREES_M15
DELTA 0.25 RANGE 0.0 .. 360.0;
SUBTYPE ST_SYMMETRIC_RADIANS_M8 IS SYMMETRIC_RADIANS_M16
DELTA HALF_PI * 2.0 ** (-7) RANGE -HALF_PI .. HALF_PI;
-- 'SMALL = 2.0 ** ( -7) = 0.00781_25.
BEGIN
TEST ("C35A07D", "CHECK THAT FOR FIXED POINT TYPES THE FIRST " &
"AND LAST ATTRIBUTES YIELD CORRECT VALUES - " &
"TYPICAL TYPES");
-------------------------------------------------------------------
IF PIXEL_M10'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("PIXEL_M10'FIRST /= 0.0");
END IF;
-------------------------------------------------------------------
IF RULER_M8'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("RULER_M8'FIRST /= 0.0");
END IF;
IF RULER_M8'LAST /= IDENT_INT (1) * 12.0 THEN
FAILED ("RULER_M8'LAST /= 12.0");
END IF;
-------------------------------------------------------------------
IF HOURS_M16'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("HOURS_M16'FIRST /= 0.0");
END IF;
IF HOURS_M16'LAST /= IDENT_INT (1) * 24.0 THEN
FAILED ("HOURS_M16'LAST /= 24.0");
END IF;
-------------------------------------------------------------------
IF MILES_M16'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("MILES_M16'FIRST /= 0.0");
END IF;
IF MILES_M16'LAST /= IDENT_INT (1) * 3000.0 THEN
FAILED ("MILES_M16'LAST /= 3000.0");
END IF;
-------------------------------------------------------------------
IF SYMMETRIC_DEGREES_M7'FIRST /= IDENT_INT (1) * (-180.0) THEN
FAILED ("SYMMETRIC_DEGREES_M7'FIRST /= -180.0");
END IF;
IF SYMMETRIC_DEGREES_M7'LAST /= IDENT_INT (1) * 180.0 THEN
FAILED ("SYMMETRIC_DEGREES_M7'LAST /= 180.0");
END IF;
-------------------------------------------------------------------
IF NATURAL_DEGREES_M15'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("NATURAL_DEGREES_M15'FIRST /= 0.0");
END IF;
IF NATURAL_DEGREES_M15'LAST /= IDENT_INT (1) * 360.0 THEN
FAILED ("NATURAL_DEGREES_M15'LAST /= 360.0");
END IF;
-------------------------------------------------------------------
-- PI IS IN 3.0 + 2319 * 'SMALL .. 3.0 + 2320 * 'SMALL.
IF SYMMETRIC_RADIANS_M16'FIRST NOT IN
-3.14160_15625 .. -3.14154_05273_4375 THEN
FAILED ("SYMMETRIC_RADIANS_M16'FIRST NOT IN " &
"-3.14160_15625 .. -3.14154_05273_4375");
END IF;
IF SYMMETRIC_RADIANS_M16'LAST NOT IN
3.14154_05273_4375 .. 3.14160_15625 THEN
FAILED ("SYMMETRIC_RADIANS_M16'LAST NOT IN " &
"3.14154_05273_4375 .. 3.14160_15625");
END IF;
-------------------------------------------------------------------
IF NATURAL_RADIANS_M8'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("NATURAL_RADIANS_M8'FIRST /= 0.0");
END IF;
-- TWO_PI IS IN 201 * 'SMALL .. 202 * 'SMALL.
IF NATURAL_RADIANS_M8'LAST NOT IN 6.28125 .. 6.3125 THEN
FAILED ("NATURAL_RADIANS_M8'LAST NOT IN 6.28125 .. 6.3125");
END IF;
-------------------------------------------------------------------
IF ST_MILES_M8'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("ST_MILES_M8'FIRST /= 0.0");
END IF;
IF ST_MILES_M8'LAST /= IDENT_INT (1) * 10.0 THEN
FAILED ("ST_MILES_M8'LAST /= 10.0");
END IF;
-------------------------------------------------------------------
IF ST_NATURAL_DEGREES_M11'FIRST /= IDENT_INT (1) * 0.0 THEN
FAILED ("ST_NATURAL_DEGREES_M11'FIRST /= 0.0");
END IF;
IF ST_NATURAL_DEGREES_M11'LAST /= IDENT_INT (1) * 360.0 THEN
FAILED ("ST_NATURAL_DEGREES_M11'LAST /= 360.0");
END IF;
-------------------------------------------------------------------
-- HALF_PI IS IN 201 * 'SMALL .. 202 * 'SMALL.
IF ST_SYMMETRIC_RADIANS_M8'FIRST NOT IN
-1.57812_5 .. -1.57031_25 THEN
FAILED ("ST_SYMMETRIC_RADIANS_M8'FIRST NOT IN " &
"-1.57812_5 .. -1.57031_25");
END IF;
IF ST_SYMMETRIC_RADIANS_M8'LAST NOT IN
1.57031_25 .. 1.57812_5 THEN
FAILED ("ST_SYMMETRIC_RADIANS_M8'LAST NOT IN " &
"1.57031_25 .. 1.57812_5");
END IF;
-------------------------------------------------------------------
RESULT;
END C35A07D;
|
-- REST API Validation
-- API to validate
--
-- The version of the OpenAPI document: 1.0.0
-- Contact: Stephane.Carrez@gmail.com
--
-- NOTE: This package is auto generated by OpenAPI-Generator 5.2.1-SNAPSHOT.
-- https://openapi-generator.tech
-- Do not edit the class manually.
pragma Warnings (Off, "*is not referenced");
with Swagger.Streams;
with Swagger.Servers.Operation;
package body TestAPI.Skeletons is
pragma Style_Checks ("-mr");
pragma Warnings (Off, "*use clause for package*");
use Swagger.Streams;
package body Skeleton is
package API_Orch_Store is
new Swagger.Servers.Operation (Handler => Orch_Store,
Method => Swagger.Servers.POST,
URI => URI_Prefix & "/orchestration");
--
procedure Orch_Store
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Input : Swagger.Value_Type;
Impl : Implementation_Type;
Inline_Object_3Type : InlineObject3_Type;
begin
Swagger.Servers.Read (Req, Input);
TestAPI.Models.Deserialize (Input, "InlineObject3_Type", Inline_Object_3Type);
Impl.Orch_Store
(Inline_Object_3Type, Context);
end Orch_Store;
package API_Do_Create_Ticket is
new Swagger.Servers.Operation (Handler => Do_Create_Ticket,
Method => Swagger.Servers.POST,
URI => URI_Prefix & "/tickets");
-- Create a ticket
procedure Do_Create_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Title : Swagger.UString;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Impl.Do_Create_Ticket
(Title,
Owner,
Status,
Description, Context);
end Do_Create_Ticket;
package API_Do_Delete_Ticket is
new Swagger.Servers.Operation (Handler => Do_Delete_Ticket,
Method => Swagger.Servers.DELETE,
URI => URI_Prefix & "/tickets/{tid}");
-- Delete a ticket
procedure Do_Delete_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Tid : Swagger.Long;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Impl.Do_Delete_Ticket
(Tid, Context);
end Do_Delete_Ticket;
package API_Do_Head_Ticket is
new Swagger.Servers.Operation (Handler => Do_Head_Ticket,
Method => Swagger.Servers.HEAD,
URI => URI_Prefix & "/tickets");
-- List the tickets
procedure Do_Head_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Impl.Do_Head_Ticket (Context);
end Do_Head_Ticket;
package API_Do_Patch_Ticket is
new Swagger.Servers.Operation (Handler => Do_Patch_Ticket,
Method => Swagger.Servers.PATCH,
URI => URI_Prefix & "/tickets/{tid}");
-- Patch a ticket
procedure Do_Patch_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Tid : Swagger.Long;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Title : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Impl.Do_Patch_Ticket
(Tid,
Owner,
Status,
Title,
Description, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Patch_Ticket;
package API_Do_Update_Ticket is
new Swagger.Servers.Operation (Handler => Do_Update_Ticket,
Method => Swagger.Servers.PUT,
URI => URI_Prefix & "/tickets/{tid}");
-- Update a ticket
procedure Do_Update_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Tid : Swagger.Long;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Title : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Impl.Do_Update_Ticket
(Tid,
Owner,
Status,
Title,
Description, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Update_Ticket;
package API_Do_Get_Ticket is
new Swagger.Servers.Operation (Handler => Do_Get_Ticket,
Method => Swagger.Servers.GET,
URI => URI_Prefix & "/tickets/{tid}");
-- Get a ticket
procedure Do_Get_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Tid : Swagger.Long;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Impl.Do_Get_Ticket
(Tid, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Get_Ticket;
package API_Do_List_Tickets is
new Swagger.Servers.Operation (Handler => Do_List_Tickets,
Method => Swagger.Servers.GET,
URI => URI_Prefix & "/tickets");
-- List the tickets
procedure Do_List_Tickets
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Status : Swagger.Nullable_UString;
Owner : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type_Vectors.Vector;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Query_Parameter (Req, "status", Status);
Swagger.Servers.Get_Query_Parameter (Req, "owner", Owner);
Impl.Do_List_Tickets
(Status,
Owner, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_List_Tickets;
package API_Do_Options_Ticket is
new Swagger.Servers.Operation (Handler => Do_Options_Ticket,
Method => Swagger.Servers.OPTIONS,
URI => URI_Prefix & "/tickets/{tid}");
-- Get a ticket
procedure Do_Options_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Impl : Implementation_Type;
Tid : Swagger.Long;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Impl.Do_Options_Ticket
(Tid, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Options_Ticket;
procedure Register (Server : in out Swagger.Servers.Application_Type'Class) is
begin
Swagger.Servers.Register (Server, API_Orch_Store.Definition);
Swagger.Servers.Register (Server, API_Do_Create_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Delete_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Head_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Patch_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Update_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Get_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_List_Tickets.Definition);
Swagger.Servers.Register (Server, API_Do_Options_Ticket.Definition);
end Register;
end Skeleton;
package body Shared_Instance is
--
procedure Orch_Store
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Input : Swagger.Value_Type;
Inline_Object_3Type : InlineObject3_Type;
begin
Swagger.Servers.Read (Req, Input);
TestAPI.Models.Deserialize (Input, "InlineObject3_Type", Inline_Object_3Type);
Server.Orch_Store
(Inline_Object_3Type, Context);
end Orch_Store;
package API_Orch_Store is
new Swagger.Servers.Operation (Handler => Orch_Store,
Method => Swagger.Servers.POST,
URI => URI_Prefix & "/orchestration");
-- Create a ticket
procedure Do_Create_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Title : Swagger.UString;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Server.Do_Create_Ticket
(Title,
Owner,
Status,
Description, Context);
end Do_Create_Ticket;
package API_Do_Create_Ticket is
new Swagger.Servers.Operation (Handler => Do_Create_Ticket,
Method => Swagger.Servers.POST,
URI => URI_Prefix & "/tickets");
-- Delete a ticket
procedure Do_Delete_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Tid : Swagger.Long;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Server.Do_Delete_Ticket
(Tid, Context);
end Do_Delete_Ticket;
package API_Do_Delete_Ticket is
new Swagger.Servers.Operation (Handler => Do_Delete_Ticket,
Method => Swagger.Servers.DELETE,
URI => URI_Prefix & "/tickets/{tid}");
-- List the tickets
procedure Do_Head_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Server.Do_Head_Ticket (Context);
end Do_Head_Ticket;
package API_Do_Head_Ticket is
new Swagger.Servers.Operation (Handler => Do_Head_Ticket,
Method => Swagger.Servers.HEAD,
URI => URI_Prefix & "/tickets");
-- Patch a ticket
procedure Do_Patch_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Tid : Swagger.Long;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Title : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Server.Do_Patch_Ticket
(Tid,
Owner,
Status,
Title,
Description, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Patch_Ticket;
package API_Do_Patch_Ticket is
new Swagger.Servers.Operation (Handler => Do_Patch_Ticket,
Method => Swagger.Servers.PATCH,
URI => URI_Prefix & "/tickets/{tid}");
-- Update a ticket
procedure Do_Update_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Tid : Swagger.Long;
Owner : Swagger.Nullable_UString;
Status : Swagger.Nullable_UString;
Title : Swagger.Nullable_UString;
Description : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Write_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Swagger.Servers.Get_Parameter (Context, "owner", Owner);
Swagger.Servers.Get_Parameter (Context, "status", Status);
Swagger.Servers.Get_Parameter (Context, "title", Title);
Swagger.Servers.Get_Parameter (Context, "description", Description);
Server.Do_Update_Ticket
(Tid,
Owner,
Status,
Title,
Description, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Update_Ticket;
package API_Do_Update_Ticket is
new Swagger.Servers.Operation (Handler => Do_Update_Ticket,
Method => Swagger.Servers.PUT,
URI => URI_Prefix & "/tickets/{tid}");
-- Get a ticket
procedure Do_Get_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Tid : Swagger.Long;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Server.Do_Get_Ticket
(Tid, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Get_Ticket;
package API_Do_Get_Ticket is
new Swagger.Servers.Operation (Handler => Do_Get_Ticket,
Method => Swagger.Servers.GET,
URI => URI_Prefix & "/tickets/{tid}");
-- List the tickets
procedure Do_List_Tickets
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Status : Swagger.Nullable_UString;
Owner : Swagger.Nullable_UString;
Result : TestAPI.Models.Ticket_Type_Vectors.Vector;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Query_Parameter (Req, "status", Status);
Swagger.Servers.Get_Query_Parameter (Req, "owner", Owner);
Server.Do_List_Tickets
(Status,
Owner, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_List_Tickets;
package API_Do_List_Tickets is
new Swagger.Servers.Operation (Handler => Do_List_Tickets,
Method => Swagger.Servers.GET,
URI => URI_Prefix & "/tickets");
-- Get a ticket
procedure Do_Options_Ticket
(Req : in out Swagger.Servers.Request'Class;
Reply : in out Swagger.Servers.Response'Class;
Stream : in out Swagger.Servers.Output_Stream'Class;
Context : in out Swagger.Servers.Context_Type) is
Tid : Swagger.Long;
Result : TestAPI.Models.Ticket_Type;
begin
if not Context.Is_Authenticated then
Context.Set_Error (401, "Not authenticated");
return;
end if;
if not Context.Has_Permission (ACL_Read_Ticket.Permission) then
Context.Set_Error (403, "Permission denied");
return;
end if;
Swagger.Servers.Get_Path_Parameter (Req, 1, Tid);
Server.Do_Options_Ticket
(Tid, Result, Context);
if Context.Get_Status = 200 then
Stream.Start_Document;
TestAPI.Models.Serialize (Stream, "", Result);
Stream.End_Document;
end if;
end Do_Options_Ticket;
package API_Do_Options_Ticket is
new Swagger.Servers.Operation (Handler => Do_Options_Ticket,
Method => Swagger.Servers.OPTIONS,
URI => URI_Prefix & "/tickets/{tid}");
procedure Register (Server : in out Swagger.Servers.Application_Type'Class) is
begin
Swagger.Servers.Register (Server, API_Orch_Store.Definition);
Swagger.Servers.Register (Server, API_Do_Create_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Delete_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Head_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Patch_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Update_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_Get_Ticket.Definition);
Swagger.Servers.Register (Server, API_Do_List_Tickets.Definition);
Swagger.Servers.Register (Server, API_Do_Options_Ticket.Definition);
end Register;
protected body Server is
--
procedure Orch_Store
(Inline_Object_3Type : in InlineObject3_Type;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Orch_Store
(Inline_Object_3Type,
Context);
end Orch_Store;
-- Create a ticket
procedure Do_Create_Ticket
(Title : in Swagger.UString;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Create_Ticket
(Title,
Owner,
Status,
Description,
Context);
end Do_Create_Ticket;
-- Delete a ticket
procedure Do_Delete_Ticket
(Tid : in Swagger.Long;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Delete_Ticket
(Tid,
Context);
end Do_Delete_Ticket;
-- List the tickets
procedure Do_Head_Ticket (Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Head_Ticket (Context);
end Do_Head_Ticket;
-- Patch a ticket
procedure Do_Patch_Ticket
(Tid : in Swagger.Long;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Title : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Patch_Ticket
(Tid,
Owner,
Status,
Title,
Description,
Result,
Context);
end Do_Patch_Ticket;
-- Update a ticket
procedure Do_Update_Ticket
(Tid : in Swagger.Long;
Owner : in Swagger.Nullable_UString;
Status : in Swagger.Nullable_UString;
Title : in Swagger.Nullable_UString;
Description : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Update_Ticket
(Tid,
Owner,
Status,
Title,
Description,
Result,
Context);
end Do_Update_Ticket;
-- Get a ticket
procedure Do_Get_Ticket
(Tid : in Swagger.Long;
Result : out TestAPI.Models.Ticket_Type;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Get_Ticket
(Tid,
Result,
Context);
end Do_Get_Ticket;
-- List the tickets
procedure Do_List_Tickets
(Status : in Swagger.Nullable_UString;
Owner : in Swagger.Nullable_UString;
Result : out TestAPI.Models.Ticket_Type_Vectors.Vector;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_List_Tickets
(Status,
Owner,
Result,
Context);
end Do_List_Tickets;
-- Get a ticket
procedure Do_Options_Ticket
(Tid : in Swagger.Long;
Result : out TestAPI.Models.Ticket_Type;
Context : in out Swagger.Servers.Context_Type) is
begin
Impl.Do_Options_Ticket
(Tid,
Result,
Context);
end Do_Options_Ticket;
end Server;
end Shared_Instance;
end TestAPI.Skeletons;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . O R D E R E D _ M A P S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2004-2006, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 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. --
-- --
--
--
--
--
--
--
--
-- This unit was originally developed by Matthew J Heaney. --
------------------------------------------------------------------------------
with Ada.Containers.Red_Black_Trees;
with Ada.Finalization;
with Ada.Streams;
generic
type Key_Type is private;
type Element_Type is private;
with function "<" (Left, Right : Key_Type) return Boolean is <>;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Ordered_Maps is
pragma Preelaborate;
function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
type Map is tagged private;
pragma Preelaborable_Initialization (Map);
type Cursor is private;
pragma Preelaborable_Initialization (Cursor);
Empty_Map : constant Map;
No_Element : constant Cursor;
function "=" (Left, Right : Map) return Boolean;
function Length (Container : Map) return Count_Type;
function Is_Empty (Container : Map) return Boolean;
procedure Clear (Container : in out Map);
function Key (Position : Cursor) return Key_Type;
function Element (Position : Cursor) return Element_Type;
procedure Replace_Element
(Container : in out Map;
Position : Cursor;
New_Item : Element_Type);
procedure Query_Element
(Position : Cursor;
Process : not null access
procedure (Key : Key_Type; Element : Element_Type));
procedure Update_Element
(Container : in out Map;
Position : Cursor;
Process : not null access
procedure (Key : Key_Type; Element : in out Element_Type));
procedure Move (Target : in out Map; Source : in out Map);
procedure Insert
(Container : in out Map;
Key : Key_Type;
New_Item : Element_Type;
Position : out Cursor;
Inserted : out Boolean);
procedure Insert
(Container : in out Map;
Key : Key_Type;
Position : out Cursor;
Inserted : out Boolean);
procedure Insert
(Container : in out Map;
Key : Key_Type;
New_Item : Element_Type);
procedure Include
(Container : in out Map;
Key : Key_Type;
New_Item : Element_Type);
procedure Replace
(Container : in out Map;
Key : Key_Type;
New_Item : Element_Type);
procedure Exclude (Container : in out Map; Key : Key_Type);
procedure Delete (Container : in out Map; Key : Key_Type);
procedure Delete (Container : in out Map; Position : in out Cursor);
procedure Delete_First (Container : in out Map);
procedure Delete_Last (Container : in out Map);
function First (Container : Map) return Cursor;
function First_Element (Container : Map) return Element_Type;
function First_Key (Container : Map) return Key_Type;
function Last (Container : Map) return Cursor;
function Last_Element (Container : Map) return Element_Type;
function Last_Key (Container : Map) return Key_Type;
function Next (Position : Cursor) return Cursor;
procedure Next (Position : in out Cursor);
function Previous (Position : Cursor) return Cursor;
procedure Previous (Position : in out Cursor);
function Find (Container : Map; Key : Key_Type) return Cursor;
function Element (Container : Map; Key : Key_Type) return Element_Type;
function Floor (Container : Map; Key : Key_Type) return Cursor;
function Ceiling (Container : Map; Key : Key_Type) return Cursor;
function Contains (Container : Map; Key : Key_Type) return Boolean;
function Has_Element (Position : Cursor) return Boolean;
function "<" (Left, Right : Cursor) return Boolean;
function ">" (Left, Right : Cursor) return Boolean;
function "<" (Left : Cursor; Right : Key_Type) return Boolean;
function ">" (Left : Cursor; Right : Key_Type) return Boolean;
function "<" (Left : Key_Type; Right : Cursor) return Boolean;
function ">" (Left : Key_Type; Right : Cursor) return Boolean;
procedure Iterate
(Container : Map;
Process : not null access procedure (Position : Cursor));
procedure Reverse_Iterate
(Container : Map;
Process : not null access procedure (Position : Cursor));
private
type Node_Type;
type Node_Access is access Node_Type;
type Node_Type is limited record
Parent : Node_Access;
Left : Node_Access;
Right : Node_Access;
Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
Key : Key_Type;
Element : Element_Type;
end record;
package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
(Node_Type,
Node_Access);
type Map is new Ada.Finalization.Controlled with record
Tree : Tree_Types.Tree_Type;
end record;
procedure Adjust (Container : in out Map);
procedure Finalize (Container : in out Map) renames Clear;
use Red_Black_Trees;
use Tree_Types;
use Ada.Finalization;
use Ada.Streams;
type Map_Access is access all Map;
for Map_Access'Storage_Size use 0;
type Cursor is record
Container : Map_Access;
Node : Node_Access;
end record;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Item : Cursor);
for Cursor'Write use Write;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Item : out Cursor);
for Cursor'Read use Read;
No_Element : constant Cursor := Cursor'(null, null);
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Container : Map);
for Map'Write use Write;
procedure Read
(Stream : not null access Root_Stream_Type'Class;
Container : out Map);
for Map'Read use Read;
Empty_Map : constant Map :=
(Controlled with Tree => (First => null,
Last => null,
Root => null,
Length => 0,
Busy => 0,
Lock => 0));
end Ada.Containers.Ordered_Maps;
|
with System.Formatting;
with System.Long_Long_Integer_Types;
package body System.Wid_LLI is
use type Long_Long_Integer_Types.Long_Long_Unsigned;
subtype Word_Unsigned is Long_Long_Integer_Types.Word_Unsigned;
subtype Long_Long_Unsigned is Long_Long_Integer_Types.Long_Long_Unsigned;
-- implementation
function Width_Long_Long_Integer (Lo, Hi : Long_Long_Integer)
return Natural is
begin
if Lo > Hi then
return 0;
else
declare
Max_Abs : Long_Long_Unsigned;
Digits_Width : Natural;
begin
if Hi <= 0 then
Max_Abs := -Long_Long_Unsigned'Mod (Lo);
elsif Lo >= 0 then
Max_Abs := Long_Long_Unsigned (Hi);
else -- Lo < 0 and then Hi > 0
Max_Abs := Long_Long_Unsigned'Max (
-Long_Long_Unsigned'Mod (Lo),
Long_Long_Unsigned (Hi));
end if;
if Long_Long_Integer'Size <= Standard'Word_Size then
Digits_Width :=
Formatting.Digits_Width (Word_Unsigned (Max_Abs));
else
Digits_Width := Formatting.Digits_Width (Max_Abs);
end if;
return Digits_Width + 1; -- sign
end;
end if;
end Width_Long_Long_Integer;
end System.Wid_LLI;
|
pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
with System;
with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_fft_gstfft_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_fft_gstffts16_h is
-- GStreamer
-- * Copyright (C) <2007> Sebastian Dröge <slomo@circular-chaos.org>
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
type GstFFTS16;
type u_GstFFTS16_u_padding_array is array (0 .. 3) of System.Address;
--subtype GstFFTS16 is u_GstFFTS16; -- gst/fft/gstffts16.h:30
type GstFFTS16Complex;
--subtype GstFFTS16Complex is u_GstFFTS16Complex; -- gst/fft/gstffts16.h:31
-- FIXME 0.11: Move the struct definition to the sources,
-- * there's no reason to have it public.
--
--*
-- * GstFFTS16:
-- *
-- * Instance structure for #GstFFTS16.
-- *
--
-- <private>
type GstFFTS16 is record
cfg : System.Address; -- gst/fft/gstffts16.h:44
inverse : aliased GLIB.gboolean; -- gst/fft/gstffts16.h:45
len : aliased GLIB.gint; -- gst/fft/gstffts16.h:46
u_padding : u_GstFFTS16_u_padding_array; -- gst/fft/gstffts16.h:47
end record;
pragma Convention (C_Pass_By_Copy, GstFFTS16); -- gst/fft/gstffts16.h:42
-- Copy of kiss_fft_s16_cpx for documentation reasons,
-- * do NOT change!
--*
-- * GstFFTS16Complex:
-- * @r: Real part
-- * @i: Imaginary part
-- *
-- * Data type for complex numbers composed of
-- * signed 16 bit integers.
-- *
--
type GstFFTS16Complex is record
r : aliased GLIB.gint16; -- gst/fft/gstffts16.h:64
i : aliased GLIB.gint16; -- gst/fft/gstffts16.h:65
end record;
pragma Convention (C_Pass_By_Copy, GstFFTS16Complex); -- gst/fft/gstffts16.h:62
-- Functions
function gst_fft_s16_new (len : GLIB.gint; inverse : GLIB.gboolean) return access GstFFTS16; -- gst/fft/gstffts16.h:70
pragma Import (C, gst_fft_s16_new, "gst_fft_s16_new");
procedure gst_fft_s16_fft
(self : access GstFFTS16;
timedata : access GLIB.gint16;
freqdata : access GstFFTS16Complex); -- gst/fft/gstffts16.h:71
pragma Import (C, gst_fft_s16_fft, "gst_fft_s16_fft");
procedure gst_fft_s16_inverse_fft
(self : access GstFFTS16;
freqdata : access constant GstFFTS16Complex;
timedata : access GLIB.gint16); -- gst/fft/gstffts16.h:72
pragma Import (C, gst_fft_s16_inverse_fft, "gst_fft_s16_inverse_fft");
procedure gst_fft_s16_free (self : access GstFFTS16); -- gst/fft/gstffts16.h:73
pragma Import (C, gst_fft_s16_free, "gst_fft_s16_free");
procedure gst_fft_s16_window
(self : access GstFFTS16;
timedata : access GLIB.gint16;
window : GStreamer.GST_Low_Level.gstreamer_0_10_gst_fft_gstfft_h.GstFFTWindow); -- gst/fft/gstffts16.h:75
pragma Import (C, gst_fft_s16_window, "gst_fft_s16_window");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_fft_gstffts16_h;
|
------------------------------------------------------------------------------
-- --
-- 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$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.UML.Regions.Hash is
new AMF.Elements.Generic_Hash (UML_Region, UML_Region_Access);
|
package GESTE_Fonts.FreeSerifBoldItalic8pt7b is
Font : constant Bitmap_Font_Ref;
private
FreeSerifBoldItalic8pt7bBitmaps : aliased constant Font_Bitmap := (
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#80#, 16#03#, 16#00#, 16#0E#, 16#00#, 16#18#, 16#00#, 16#30#,
16#00#, 16#40#, 16#00#, 16#80#, 16#01#, 16#00#, 16#04#, 16#00#, 16#00#,
16#00#, 16#30#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#30#, 16#0C#, 16#40#, 16#18#, 16#80#, 16#23#, 16#00#, 16#44#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#20#, 16#06#, 16#C0#, 16#09#, 16#00#, 16#7F#, 16#00#, 16#4C#,
16#00#, 16#90#, 16#01#, 16#20#, 16#0F#, 16#E0#, 16#09#, 16#00#, 16#36#,
16#00#, 16#48#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#,
16#03#, 16#80#, 16#0A#, 16#C0#, 16#34#, 16#80#, 16#68#, 16#00#, 16#70#,
16#00#, 16#F0#, 16#00#, 16#E0#, 16#01#, 16#60#, 16#12#, 16#C0#, 16#29#,
16#80#, 16#72#, 16#00#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#08#, 16#0D#, 16#E0#, 16#32#, 16#40#, 16#65#, 16#00#, 16#8A#,
16#01#, 16#A9#, 16#C3#, 16#96#, 16#40#, 16#4C#, 16#80#, 16#B1#, 16#02#,
16#64#, 16#04#, 16#C8#, 16#10#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#E0#, 16#03#, 16#20#, 16#06#, 16#40#, 16#0D#, 16#00#, 16#1C#,
16#00#, 16#F3#, 16#83#, 16#62#, 16#04#, 16#E8#, 16#18#, 16#D0#, 16#31#,
16#C0#, 16#71#, 16#80#, 16#7D#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#00#, 16#0C#, 16#00#, 16#18#, 16#00#, 16#20#, 16#00#, 16#40#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#00#, 16#04#, 16#00#, 16#18#, 16#00#, 16#20#, 16#00#, 16#C0#,
16#01#, 16#00#, 16#02#, 16#00#, 16#0C#, 16#00#, 16#18#, 16#00#, 16#10#,
16#00#, 16#20#, 16#00#, 16#40#, 16#00#, 16#40#, 16#00#, 16#80#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#08#, 16#00#, 16#08#, 16#00#, 16#08#, 16#00#, 16#10#, 16#00#, 16#20#,
16#00#, 16#40#, 16#00#, 16#80#, 16#01#, 16#00#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#10#, 16#00#, 16#40#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#00#, 16#06#, 16#00#, 16#39#, 16#00#, 16#1C#, 16#00#, 16#30#,
16#01#, 16#D8#, 16#00#, 16#C0#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#,
16#00#, 16#20#, 16#00#, 16#40#, 16#07#, 16#F8#, 16#01#, 16#00#, 16#02#,
16#00#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#,
16#00#, 16#60#, 16#00#, 16#40#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#60#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#80#, 16#03#, 16#00#, 16#04#, 16#00#, 16#18#, 16#00#, 16#20#,
16#00#, 16#C0#, 16#01#, 16#00#, 16#02#, 16#00#, 16#08#, 16#00#, 16#10#,
16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#80#, 16#0C#, 16#80#, 16#19#, 16#00#, 16#63#, 16#00#, 16#C6#,
16#01#, 16#9C#, 16#07#, 16#30#, 16#0C#, 16#60#, 16#18#, 16#C0#, 16#33#,
16#00#, 16#26#, 16#00#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#C0#, 16#0F#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#30#,
16#00#, 16#60#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#18#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#C0#, 16#09#, 16#C0#, 16#21#, 16#80#, 16#03#, 16#00#, 16#0C#,
16#00#, 16#18#, 16#00#, 16#60#, 16#00#, 16#80#, 16#03#, 16#00#, 16#0C#,
16#00#, 16#31#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#C0#, 16#09#, 16#80#, 16#03#, 16#00#, 16#06#, 16#00#, 16#18#,
16#00#, 16#F0#, 16#00#, 16#70#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#01#,
16#00#, 16#66#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#20#, 16#00#, 16#C0#, 16#03#, 16#80#, 16#0F#, 16#00#, 16#2C#,
16#00#, 16#98#, 16#02#, 16#30#, 16#04#, 16#60#, 16#1F#, 16#C0#, 16#03#,
16#00#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#E0#, 16#08#, 16#00#, 16#10#, 16#00#, 16#3C#, 16#00#, 16#F8#,
16#00#, 16#38#, 16#00#, 16#30#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#01#,
16#00#, 16#66#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#60#, 16#03#, 16#80#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#F8#,
16#01#, 16#98#, 16#03#, 16#30#, 16#0E#, 16#60#, 16#18#, 16#C0#, 16#13#,
16#80#, 16#26#, 16#00#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#E0#, 16#10#, 16#C0#, 16#01#, 16#00#, 16#06#, 16#00#, 16#08#,
16#00#, 16#30#, 16#00#, 16#40#, 16#01#, 16#80#, 16#06#, 16#00#, 16#08#,
16#00#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#C0#, 16#0C#, 16#C0#, 16#19#, 16#80#, 16#33#, 16#00#, 16#7C#,
16#00#, 16#70#, 16#01#, 16#60#, 16#04#, 16#60#, 16#18#, 16#C0#, 16#31#,
16#80#, 16#26#, 16#00#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#C0#, 16#0C#, 16#80#, 16#19#, 16#80#, 16#63#, 16#00#, 16#C6#,
16#01#, 16#9C#, 16#03#, 16#30#, 16#03#, 16#E0#, 16#01#, 16#80#, 16#06#,
16#00#, 16#38#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#,
16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#30#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#,
16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#,
16#00#, 16#70#, 16#00#, 16#60#, 16#00#, 16#80#, 16#02#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#80#, 16#1E#,
16#00#, 16#E0#, 16#03#, 16#00#, 16#07#, 16#00#, 16#03#, 16#80#, 16#01#,
16#E0#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#00#, 16#70#,
16#00#, 16#3C#, 16#00#, 16#0C#, 16#00#, 16#78#, 16#03#, 16#C0#, 16#1C#,
16#00#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#80#, 16#09#, 16#80#, 16#1B#, 16#00#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#30#, 16#00#, 16#C0#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#30#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#F0#, 16#06#, 16#18#, 16#18#, 16#C8#, 16#62#, 16#D0#, 16#CD#,
16#A1#, 16#92#, 16#43#, 16#64#, 16#86#, 16#F9#, 16#04#, 16#DC#, 16#06#,
16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#20#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#07#, 16#00#, 16#16#,
16#00#, 16#2E#, 16#00#, 16#8C#, 16#01#, 16#F8#, 16#04#, 16#30#, 16#10#,
16#60#, 16#20#, 16#C0#, 16#E3#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#F0#, 16#07#, 16#30#, 16#0E#, 16#60#, 16#18#, 16#C0#, 16#33#,
16#80#, 16#FC#, 16#01#, 16#CC#, 16#03#, 16#18#, 16#06#, 16#38#, 16#1C#,
16#60#, 16#39#, 16#C0#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#F4#, 16#07#, 16#18#, 16#1C#, 16#20#, 16#30#, 16#40#, 16#E0#,
16#01#, 16#C0#, 16#03#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#20#, 16#18#, 16#80#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#F0#, 16#07#, 16#38#, 16#0E#, 16#30#, 16#18#, 16#70#, 16#30#,
16#E0#, 16#E1#, 16#C1#, 16#83#, 16#83#, 16#06#, 16#06#, 16#1C#, 16#1C#,
16#30#, 16#39#, 16#C0#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#FC#, 16#07#, 16#18#, 16#0E#, 16#20#, 16#18#, 16#80#, 16#32#,
16#00#, 16#FC#, 16#01#, 16#C8#, 16#03#, 16#10#, 16#06#, 16#08#, 16#1C#,
16#30#, 16#38#, 16#C0#, 16#FF#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#FC#, 16#07#, 16#10#, 16#0E#, 16#20#, 16#18#, 16#00#, 16#32#,
16#00#, 16#FC#, 16#01#, 16#C8#, 16#03#, 16#20#, 16#06#, 16#00#, 16#1C#,
16#00#, 16#38#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#F4#, 16#07#, 16#18#, 16#0C#, 16#10#, 16#30#, 16#00#, 16#E0#,
16#01#, 16#C0#, 16#03#, 16#0F#, 16#86#, 16#0E#, 16#0C#, 16#18#, 16#18#,
16#30#, 16#18#, 16#E0#, 16#1F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#DF#, 16#07#, 16#0C#, 16#0E#, 16#38#, 16#18#, 16#60#, 16#30#,
16#C0#, 16#FF#, 16#81#, 16#87#, 16#03#, 16#0C#, 16#06#, 16#18#, 16#1C#,
16#70#, 16#38#, 16#E0#, 16#FB#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#C0#, 16#07#, 16#00#, 16#0E#, 16#00#, 16#18#, 16#00#, 16#30#,
16#00#, 16#E0#, 16#01#, 16#80#, 16#03#, 16#00#, 16#06#, 16#00#, 16#1C#,
16#00#, 16#38#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#F0#, 16#00#, 16#C0#, 16#03#, 16#80#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#18#, 16#00#, 16#70#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#07#,
16#00#, 16#0C#, 16#00#, 16#D8#, 16#01#, 16#E0#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#DE#, 16#07#, 16#10#, 16#0E#, 16#40#, 16#19#, 16#00#, 16#34#,
16#00#, 16#F8#, 16#01#, 16#B0#, 16#03#, 16#70#, 16#06#, 16#60#, 16#1C#,
16#E0#, 16#38#, 16#C0#, 16#FB#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#C0#, 16#07#, 16#00#, 16#0E#, 16#00#, 16#18#, 16#00#, 16#30#,
16#00#, 16#E0#, 16#01#, 16#80#, 16#03#, 16#00#, 16#06#, 16#08#, 16#1C#,
16#10#, 16#38#, 16#C0#, 16#FF#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#83#, 16#C3#, 16#07#, 16#0E#, 16#1E#, 16#1C#, 16#38#, 16#58#,
16#B0#, 16#BA#, 16#61#, 16#75#, 16#C2#, 16#73#, 16#08#, 16#E6#, 16#11#,
16#9C#, 16#22#, 16#38#, 16#E4#, 16#F8#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#8E#, 16#07#, 16#08#, 16#0E#, 16#10#, 16#1E#, 16#20#, 16#4C#,
16#80#, 16#9D#, 16#01#, 16#1A#, 16#02#, 16#3C#, 16#08#, 16#30#, 16#10#,
16#60#, 16#20#, 16#40#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#F0#, 16#03#, 16#30#, 16#0C#, 16#30#, 16#30#, 16#60#, 16#E0#,
16#C1#, 16#C3#, 16#83#, 16#07#, 16#06#, 16#0C#, 16#0C#, 16#38#, 16#18#,
16#60#, 16#31#, 16#80#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#F0#, 16#07#, 16#30#, 16#0C#, 16#60#, 16#18#, 16#C0#, 16#33#,
16#80#, 16#FC#, 16#01#, 16#80#, 16#03#, 16#00#, 16#06#, 16#00#, 16#1C#,
16#00#, 16#38#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#F0#, 16#03#, 16#30#, 16#0C#, 16#30#, 16#30#, 16#60#, 16#E0#,
16#C1#, 16#C3#, 16#83#, 16#07#, 16#06#, 16#0C#, 16#0C#, 16#38#, 16#18#,
16#60#, 16#11#, 16#80#, 16#1C#, 16#00#, 16#78#, 16#81#, 16#7E#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#F0#, 16#07#, 16#30#, 16#0E#, 16#60#, 16#18#, 16#C0#, 16#33#,
16#80#, 16#FC#, 16#01#, 16#F8#, 16#03#, 16#30#, 16#06#, 16#60#, 16#1C#,
16#E0#, 16#39#, 16#C0#, 16#F9#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#80#, 16#0C#, 16#C0#, 16#18#, 16#80#, 16#31#, 16#00#, 16#70#,
16#00#, 16#F0#, 16#00#, 16#70#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#21#,
16#80#, 16#63#, 16#00#, 16#BC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#FC#, 16#0D#, 16#D8#, 16#13#, 16#10#, 16#06#, 16#00#, 16#1C#,
16#00#, 16#38#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#03#, 16#80#, 16#06#,
16#00#, 16#0C#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#CF#, 16#07#, 16#0C#, 16#0E#, 16#10#, 16#18#, 16#20#, 16#30#,
16#40#, 16#E1#, 16#01#, 16#82#, 16#03#, 16#04#, 16#06#, 16#10#, 16#0C#,
16#20#, 16#18#, 16#80#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#CE#, 16#07#, 16#0C#, 16#0E#, 16#10#, 16#0C#, 16#40#, 16#18#,
16#80#, 16#32#, 16#00#, 16#68#, 16#00#, 16#D0#, 16#01#, 16#C0#, 16#03#,
16#00#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#BE#, 16#C7#, 16#38#, 16#8E#, 16#32#, 16#1C#, 16#E4#, 16#1A#,
16#D0#, 16#35#, 16#A0#, 16#73#, 16#80#, 16#E7#, 16#01#, 16#8C#, 16#03#,
16#18#, 16#04#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#DC#, 16#07#, 16#10#, 16#06#, 16#40#, 16#0D#, 16#00#, 16#1C#,
16#00#, 16#18#, 16#00#, 16#70#, 16#01#, 16#70#, 16#02#, 16#60#, 16#08#,
16#C0#, 16#21#, 16#C0#, 16#E7#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#DC#, 16#06#, 16#10#, 16#0E#, 16#20#, 16#0C#, 16#80#, 16#1A#,
16#00#, 16#38#, 16#00#, 16#70#, 16#00#, 16#E0#, 16#01#, 16#80#, 16#03#,
16#00#, 16#0E#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#F8#, 16#0C#, 16#60#, 16#21#, 16#80#, 16#07#, 16#00#, 16#0C#,
16#00#, 16#30#, 16#00#, 16#E0#, 16#01#, 16#80#, 16#06#, 16#10#, 16#1C#,
16#20#, 16#71#, 16#80#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#80#, 16#0C#, 16#00#, 16#18#, 16#00#, 16#20#, 16#00#, 16#40#,
16#01#, 16#80#, 16#03#, 16#00#, 16#04#, 16#00#, 16#08#, 16#00#, 16#30#,
16#00#, 16#60#, 16#00#, 16#80#, 16#01#, 16#00#, 16#03#, 16#80#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#04#, 16#00#, 16#0C#, 16#00#, 16#08#, 16#00#, 16#10#, 16#00#, 16#30#,
16#00#, 16#60#, 16#00#, 16#40#, 16#00#, 16#80#, 16#01#, 16#80#, 16#01#,
16#00#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#00#, 16#02#, 16#00#, 16#0C#, 16#00#, 16#18#, 16#00#, 16#20#,
16#00#, 16#40#, 16#01#, 16#80#, 16#03#, 16#00#, 16#06#, 16#00#, 16#08#,
16#00#, 16#10#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#03#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#00#, 16#07#, 16#00#, 16#0A#, 16#00#, 16#32#, 16#00#, 16#44#,
16#01#, 16#8C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#0C#, 16#00#, 16#0C#, 16#00#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#,
16#00#, 16#D8#, 16#03#, 16#30#, 16#06#, 16#60#, 16#18#, 16#80#, 16#37#,
16#00#, 16#66#, 16#80#, 16#7E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#00#, 16#06#, 16#00#, 16#08#, 16#00#, 16#30#, 16#00#, 16#7C#,
16#00#, 16#CC#, 16#03#, 16#18#, 16#06#, 16#30#, 16#0C#, 16#C0#, 16#11#,
16#80#, 16#66#, 16#00#, 16#78#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#,
16#00#, 16#D8#, 16#03#, 16#00#, 16#06#, 16#00#, 16#1C#, 16#00#, 16#30#,
16#00#, 16#32#, 16#00#, 16#78#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#70#, 16#00#, 16#40#, 16#01#, 16#80#, 16#03#, 16#00#, 16#3E#,
16#00#, 16#C8#, 16#03#, 16#30#, 16#06#, 16#60#, 16#0C#, 16#C0#, 16#33#,
16#00#, 16#6A#, 16#80#, 16#66#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#,
16#00#, 16#D8#, 16#03#, 16#30#, 16#06#, 16#C0#, 16#0E#, 16#00#, 16#30#,
16#00#, 16#34#, 16#00#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#,
16#01#, 16#A0#, 16#03#, 16#00#, 16#04#, 16#00#, 16#18#, 16#00#, 16#78#,
16#00#, 16#60#, 16#00#, 16#80#, 16#03#, 16#00#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#10#, 16#00#, 16#60#, 16#00#, 16#C0#, 16#03#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#,
16#00#, 16#DC#, 16#03#, 16#30#, 16#06#, 16#60#, 16#07#, 16#80#, 16#18#,
16#00#, 16#3E#, 16#00#, 16#8C#, 16#01#, 16#08#, 16#03#, 16#E0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#66#,
16#00#, 16#FC#, 16#01#, 16#98#, 16#07#, 16#60#, 16#0C#, 16#C0#, 16#19#,
16#80#, 16#33#, 16#80#, 16#C6#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#,
16#00#, 16#C0#, 16#01#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#00#, 16#38#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#80#, 16#03#, 16#00#, 16#00#, 16#00#, 16#30#, 16#00#, 16#38#,
16#00#, 16#60#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#06#, 16#00#, 16#0C#,
16#00#, 16#18#, 16#00#, 16#30#, 16#00#, 16#C0#, 16#03#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#6E#,
16#00#, 16#C8#, 16#01#, 16#A0#, 16#06#, 16#80#, 16#0F#, 16#80#, 16#1B#,
16#00#, 16#36#, 16#80#, 16#C6#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#60#,
16#00#, 16#C0#, 16#01#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#00#, 16#38#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#EE#,
16#C0#, 16#EE#, 16#C3#, 16#9B#, 16#07#, 16#66#, 16#0C#, 16#CC#, 16#19#,
16#B0#, 16#66#, 16#68#, 16#CC#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#EE#,
16#00#, 16#EC#, 16#01#, 16#B0#, 16#07#, 16#60#, 16#0C#, 16#C0#, 16#19#,
16#80#, 16#22#, 16#80#, 16#C6#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#,
16#00#, 16#C8#, 16#03#, 16#10#, 16#06#, 16#60#, 16#18#, 16#C0#, 16#31#,
16#80#, 16#26#, 16#00#, 16#78#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#EC#,
16#00#, 16#EC#, 16#01#, 16#98#, 16#06#, 16#70#, 16#0C#, 16#C0#, 16#19#,
16#80#, 16#66#, 16#00#, 16#F8#, 16#01#, 16#80#, 16#03#, 16#80#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#,
16#00#, 16#D8#, 16#03#, 16#30#, 16#06#, 16#60#, 16#0C#, 16#C0#, 16#33#,
16#00#, 16#66#, 16#00#, 16#7C#, 16#00#, 16#30#, 16#00#, 16#F0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#EC#,
16#00#, 16#F8#, 16#03#, 16#80#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#68#,
16#01#, 16#A0#, 16#03#, 16#00#, 16#07#, 16#00#, 16#06#, 16#00#, 16#06#,
16#00#, 16#4C#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#00#, 16#30#, 16#00#, 16#F0#,
16#00#, 16#C0#, 16#03#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#00#, 16#28#, 16#00#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E6#,
16#00#, 16#CC#, 16#01#, 16#10#, 16#06#, 16#60#, 16#0C#, 16#C0#, 16#1F#,
16#80#, 16#2A#, 16#80#, 16#66#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#00#, 16#4C#,
16#00#, 16#C8#, 16#01#, 16#A0#, 16#03#, 16#40#, 16#07#, 16#00#, 16#0C#,
16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#00#, 16#44#,
16#80#, 16#D9#, 16#01#, 16#B2#, 16#03#, 16#E8#, 16#06#, 16#E0#, 16#0C#,
16#80#, 16#11#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E6#,
16#00#, 16#F0#, 16#01#, 16#C0#, 16#01#, 16#80#, 16#03#, 16#00#, 16#0E#,
16#00#, 16#5D#, 16#00#, 16#CC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#CC#,
16#00#, 16#D8#, 16#01#, 16#90#, 16#03#, 16#40#, 16#06#, 16#80#, 16#06#,
16#00#, 16#0C#, 16#00#, 16#10#, 16#00#, 16#40#, 16#03#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#,
16#01#, 16#20#, 16#00#, 16#80#, 16#02#, 16#00#, 16#08#, 16#00#, 16#18#,
16#00#, 16#5A#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#,
16#01#, 16#80#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#10#, 16#00#, 16#60#,
16#00#, 16#C0#, 16#03#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#18#,
16#00#, 16#30#, 16#00#, 16#40#, 16#00#, 16#80#, 16#01#, 16#80#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#04#, 16#00#, 16#08#, 16#00#, 16#10#, 16#00#, 16#20#, 16#00#, 16#40#,
16#00#, 16#80#, 16#01#, 16#00#, 16#02#, 16#00#, 16#04#, 16#00#, 16#08#,
16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#00#,
16#02#, 16#00#, 16#04#, 16#00#, 16#08#, 16#00#, 16#30#, 16#00#, 16#60#,
16#00#, 16#C0#, 16#01#, 16#80#, 16#03#, 16#00#, 16#0C#, 16#00#, 16#10#,
16#00#, 16#20#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#02#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#03#, 16#C8#, 16#00#, 16#70#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#);
Font_D : aliased constant Bitmap_Font :=
(
Bytes_Per_Glyph => 36,
Glyph_Width => 15,
Glyph_Height => 19,
Data => FreeSerifBoldItalic8pt7bBitmaps'Access);
Font : constant Bitmap_Font_Ref := Font_D'Access;
end GESTE_Fonts.FreeSerifBoldItalic8pt7b;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . E R R O R _ R E P O R T I N G --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2006, AdaCore --
-- --
-- GNARL 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. GNARL 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 GNARL; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
--
--
--
--
--
--
--
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This package must not depend on anything else, since it may be
-- called during elaboration of other packages.
package System.Error_Reporting is
pragma Preelaborate;
function Shutdown (M : String) return Boolean;
-- Perform emergency shutdown of the entire program. Msg is an error
-- message to be printed to the console. This is to be used only for
-- nonrecoverable errors.
end System.Error_Reporting;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A D A . E X C E P T I O N S . E X C E P T I O N _ P R O P A G A T I O N --
-- --
-- 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. --
-- --
-- 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 is the default version, using the __builtin_setjmp/longjmp EH
-- mechanism.
with System.Storage_Elements; use System.Storage_Elements;
pragma Warnings (Off);
-- Since several constructs give warnings in 3.14a1, including unreferenced
-- variables and pragma Unreferenced itself.
separate (Ada.Exceptions)
package body Exception_Propagation is
procedure builtin_longjmp (buffer : Address; Flag : Integer);
pragma No_Return (builtin_longjmp);
pragma Import (C, builtin_longjmp, "_gnat_builtin_longjmp");
---------------------
-- Setup_Exception --
---------------------
procedure Setup_Exception
(Excep : EOA;
Current : EOA;
Reraised : Boolean := False)
is
pragma Unreferenced (Excep, Current, Reraised);
begin
-- In the GNAT-SJLJ case this "stack" only exists implicitely, by way of
-- local occurrence declarations together with save/restore operations
-- generated by the front-end, and this routine has nothing to do.
null;
end Setup_Exception;
-------------------------
-- Propagate_Exception --
-------------------------
procedure Propagate_Exception
(E : Exception_Id;
From_Signal_Handler : Boolean)
is
pragma Inspection_Point (E);
Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
Excep : constant EOA := Get_Current_Excep.all;
begin
-- Compute the backtrace for this occurrence if corresponding binder
-- option has been set. Call_Chain takes care of the reraise case.
Call_Chain (Excep);
-- Note on above call to Call_Chain:
-- We used to only do this if From_Signal_Handler was not set,
-- based on the assumption that backtracing from a signal handler
-- would not work due to stack layout oddities. However, since
-- 1. The flag is never set in tasking programs (Notify_Exception
-- performs regular raise statements), and
-- 2. No problem has shown up in tasking programs around here so
-- far, this turned out to be too strong an assumption.
-- As, in addition, the test was
-- 1. preventing the production of backtraces in non-tasking
-- programs, and
-- 2. introducing a behavior inconsistency between
-- the tasking and non-tasking cases,
-- we have simply removed it
-- If the jump buffer pointer is non-null, transfer control using
-- it. Otherwise announce an unhandled exception (note that this
-- means that we have no finalizations to do other than at the outer
-- level). Perform the necessary notification tasks in both cases.
if Jumpbuf_Ptr /= Null_Address then
if not Excep.Exception_Raised then
Excep.Exception_Raised := True;
Exception_Traces.Notify_Handled_Exception;
end if;
builtin_longjmp (Jumpbuf_Ptr, 1);
else
Exception_Traces.Notify_Unhandled_Exception;
Exception_Traces.Unhandled_Exception_Terminate;
end if;
end Propagate_Exception;
end Exception_Propagation;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . H E L P E R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2015-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/>. --
------------------------------------------------------------------------------
package body Ada.Containers.Helpers is
package body Generic_Implementation is
use type SAC.Atomic_Unsigned;
------------
-- Adjust --
------------
procedure Adjust (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Busy (Control.T_Counts.all);
end if;
end Adjust;
----------
-- Busy --
----------
procedure Busy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Increment (T_Counts.Busy);
end if;
end Busy;
--------------
-- Finalize --
--------------
procedure Finalize (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Unbusy (Control.T_Counts.all);
Control.T_Counts := null;
end if;
end Finalize;
-- No need to protect against double Finalize here, because these types
-- are limited.
procedure Finalize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unbusy (Busy.T_Counts.all);
end Finalize;
procedure Finalize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unlock (Lock.T_Counts.all);
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Busy (Busy.T_Counts.all);
end Initialize;
procedure Initialize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Lock (Lock.T_Counts.all);
end Initialize;
----------
-- Lock --
----------
procedure Lock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Increment (T_Counts.Lock);
SAC.Increment (T_Counts.Busy);
end if;
end Lock;
--------------
-- TC_Check --
--------------
procedure TC_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Busy > 0 then
raise Program_Error with
"attempt to tamper with cursors";
end if;
-- The lock status (which monitors "element tampering") always
-- implies that the busy status (which monitors "cursor tampering")
-- is set too; this is a representation invariant. Thus if the busy
-- bit is not set, then the lock bit must not be set either.
pragma Assert (T_Counts.Lock = 0);
end TC_Check;
--------------
-- TE_Check --
--------------
procedure TE_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Lock > 0 then
raise Program_Error with
"attempt to tamper with elements";
end if;
end TE_Check;
------------
-- Unbusy --
------------
procedure Unbusy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Decrement (T_Counts.Busy);
end if;
end Unbusy;
------------
-- Unlock --
------------
procedure Unlock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
SAC.Decrement (T_Counts.Lock);
SAC.Decrement (T_Counts.Busy);
end if;
end Unlock;
-----------------
-- Zero_Counts --
-----------------
procedure Zero_Counts (T_Counts : out Tamper_Counts) is
begin
if T_Check then
T_Counts := (others => <>);
end if;
end Zero_Counts;
end Generic_Implementation;
end Ada.Containers.Helpers;
|
package Multiplicative_Order is
type Positive_Array is array (Positive range <>) of Positive;
function Find_Order(Element, Modulus: Positive) return Positive;
-- naive algorithm
-- returns the smallest I such that (Element**I) mod Modulus = 1
function Find_Order(Element: Positive;
Coprime_Factors: Positive_Array) return Positive;
-- faster algorithm for the same task
-- computes the order of all Coprime_Factors(I)
-- and returns their least common multiple
-- this gives the same result as Find_Order(Element, Modulus)
-- with Modulus being the product of all the Coprime_Factors(I)
--
-- preconditions: (1) 1 = GCD(Coprime_Factors(I), Coprime_Factors(J))
-- for all pairs I, J with I /= J
-- (2) 1 < Coprime_Factors(I) for all I
end Multiplicative_Order;
|
with Units.Numerics; use Units.Numerics;
with MS5611.Driver; use MS5611;
package body Barometer with SPARK_Mode,
Refined_State => (States_Beyond_Sensor_Template => null)
is
--overriding
procedure initialize (Self : in out Barometer_Tag) is
begin
Driver.Init;
Self.state := READY;
end initialize;
--overriding
procedure read_Measurement(Self : in out Barometer_Tag) is
have_new : Boolean;
begin
Driver.Update_Val (have_new);
pragma Unreferenced (have_new); -- not sure what the side effects are if we only sample on new data
Self.sample.data.pressure := Driver.Get_Pressure;
Self.sample.data.temperature := Driver.Get_Temperature;
end read_Measurement;
function get_Pressure(Self : Barometer_Tag) return Pressure_Type is
begin
return Self.sample.data.pressure;
end get_Pressure;
function get_Temperature(Self : Barometer_Tag) return Temperature_Type is
begin
return Self.sample.data.temperature;
end get_Temperature;
-- international altitude equation
function Altitude(pressure : Pressure_Type) return Length_Type is
subtype Temperature_Gradient_Type is Unit_Type with
Dimension => (Kelvin => 1, Meter => -1, others => 0);
t_ref : constant Temperature_Type := 288.15 * Kelvin;
t_coeff : constant Temperature_Gradient_Type := 6.5 * Milli * Kelvin / Meter;
p_ref : constant Pressure_Type := 1013.25 * Hecto * Pascal;
exp_frac : constant Float := 1.0 / 5.255;
h0 : constant Length_Type := t_ref / t_coeff;
prel : constant Base_Unit_Type := Base_Unit_Type(pressure / P_Ref);
comp : constant Base_Unit_Type := prel**exp_frac; -- TODO: ovf check might fail
neg : constant Base_Unit_Type := 1.0 - comp;
begin
return h0 * Unit_Type(Neg); -- FIXME: overflow check might fail
end Altitude;
function get_Altitude(Self : Barometer_Tag) return Length_Type is
begin
return Altitude(Self.sample.data.pressure);
end get_Altitude;
end Barometer;
|
-- C87B32A.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 OVERLOADING RESOLUTION USES THE FOLLOWING RULES:
-- FOR ATTRIBUTES OF THE FORM: T'SUCC (X), T'PRED (X), T'POS (X),
-- AND T'IMAGE (X) , THE OPERAND X MUST BE OF TYPE T.
--
-- FOR THE ATTRIBUTE OF THE FORM T'VAL (X), THE OPERAND X MUST BE
-- OF AN INTEGER TYPE.
--
-- FOR THE ATTRIBUTE OF THE FORM T'VALUE (X), THE OPERAND X MUST
-- BE OF THE PREDEFINED TYPE STRING.
-- TRH 13 SEPT 82
-- JRK 12 JAN 84
WITH REPORT; USE REPORT;
PROCEDURE C87B32A IS
TYPE COLOR IS (BROWN, RED, WHITE);
TYPE SCHOOL IS (HARVARD, BROWN, YALE);
TYPE COOK IS (SIMMER, SAUTE, BROWN, BOIL);
TYPE SUGAR IS (DEXTROSE, CANE, GLUCOSE, BROWN);
TYPE WHOLE IS NEW INTEGER RANGE 0 .. INTEGER'LAST;
TYPE LIT_CHAR IS ('+', '-', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9');
TYPE LIT_STRING IS ARRAY (POSITIVE RANGE <>) OF LIT_CHAR;
FUNCTION "+" (X, Y : WHOLE) RETURN WHOLE
RENAMES "*";
FUNCTION F1 RETURN STRING IS
BEGIN
RETURN "+10";
END F1;
FUNCTION F1 RETURN LIT_STRING IS
BEGIN
FAILED ("THE VALUE ATTRIBUTE TAKES A PREDEFINED STRING " &
"OPERAND");
RETURN "+3";
END F1;
FUNCTION F1 RETURN CHARACTER IS
BEGIN
FAILED ("THE VALUE ATTRIBUTE TAKES A STRING OPERAND");
RETURN '2';
END F1;
FUNCTION F2 (X : INTEGER) RETURN FLOAT IS
BEGIN
FAILED ("THE VAL ATTRIBUTE TAKES AN INTEGER TYPE OPERAND");
RETURN 0.0;
END F2;
FUNCTION F2 (X : INTEGER := 1) RETURN INTEGER IS
BEGIN
RETURN X;
END F2;
BEGIN
TEST ("C87B32A","OVERLOADED OPERANDS FOR THE ATTRIBUTES " &
"T'PRED, T'SUCC, T'POS, T'VAL, T'IMAGE AND T'VALUE");
IF COLOR'POS (BROWN) /= 0 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 1");
END IF;
IF SCHOOL'POS (BROWN) /= 1 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 2");
END IF;
IF COOK'POS (BROWN) /= 2 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 3");
END IF;
IF SUGAR'POS (BROWN) /= 3 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 4");
END IF;
IF SCHOOL'PRED (BROWN) /= HARVARD THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 5");
END IF;
IF COOK'PRED (BROWN) /= SAUTE THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 6");
END IF;
IF SUGAR'PRED (BROWN) /= GLUCOSE THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 7");
END IF;
IF COLOR'SUCC (BROWN) /= RED THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 8");
END IF;
IF SCHOOL'SUCC (BROWN) /= YALE THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 9");
END IF;
IF COOK'SUCC (BROWN) /= BOIL THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 10");
END IF;
IF COLOR'VAL (F2 (0)) /= BROWN THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 11");
END IF;
IF SCHOOL'VAL (F2) /= BROWN THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 12");
END IF;
IF COOK'VAL (F2 (2)) /= BROWN THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 13");
END IF;
IF SUGAR'VAL (F2) /= CANE THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 14");
END IF;
IF WHOLE'POS (1 + 1) /= 1 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 15");
END IF;
IF WHOLE'VAL (1 + 1) /= 2 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 16");
END IF;
IF WHOLE'SUCC (1 + 1) /= 2 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 17");
END IF;
IF WHOLE'PRED (1 + 1) /= 0 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 18");
END IF;
IF WHOLE'VALUE ("+1") + 1 /= 1 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 19");
END IF;
IF WHOLE'IMAGE (1 + 1) /= " 1" THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 20");
END IF;
IF WHOLE'VALUE (F1) + 1 /= 10 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 21");
END IF;
IF WHOLE'VAL (1) + 1 /= 1 THEN
FAILED ("RESOLUTION INCORRECT FOR OPERANDS OF THE ATTRIBUTES" &
" PRED, SUCC, VAL, POS, IMAGE AND VALUE - 22");
END IF;
RESULT;
END C87B32A;
|
-- This package is intended to set up and tear down the test environment.
-- Once created by GNATtest, this package will never be overwritten
-- automatically. Contents of this package can be modified in any way
-- except for sections surrounded by a 'read only' marker.
package body Combat.Test_Data.Tests.Guns_Container.Test_Data is
procedure Set_Up(Gnattest_T: in out Test) is
pragma Unreferenced(Gnattest_T);
begin
null;
end Set_Up;
procedure Tear_Down(Gnattest_T: in out Test) is
pragma Unreferenced(Gnattest_T);
begin
null;
end Tear_Down;
procedure User_Set_Up(Gnattest_T: in out New_Test) is
pragma Unreferenced(Gnattest_T);
begin
null;
end User_Set_Up;
procedure User_Tear_Down(Gnattest_T: in out New_Test) is
pragma Unreferenced(Gnattest_T);
begin
null;
end User_Tear_Down;
end Combat.Test_Data.Tests.Guns_Container.Test_Data;
|
package I_Am_Ada is
procedure Ada_Procedure;
end I_Am_Ada;
|
-- SPDX-FileCopyrightText: 2010-2021 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with WebIDL.Abstract_Sources;
with League.Strings;
with League.String_Vectors;
with League.Strings.Cursors.Characters;
package WebIDL.String_Sources is
pragma Preelaborate;
type String_Source is new WebIDL.Abstract_Sources.Abstract_Source
with private;
overriding function Get_Next
(Self : not null access String_Source)
return WebIDL.Abstract_Sources.Code_Unit_32;
procedure Set_String_Vector
(Self : out String_Source;
Value : League.String_Vectors.Universal_String_Vector);
private
type String_Source is new WebIDL.Abstract_Sources.Abstract_Source with
record
Vector : League.String_Vectors.Universal_String_Vector;
Index : Positive;
Line : League.Strings.Universal_String;
Cursor : League.Strings.Cursors.Characters.Character_Cursor;
end record;
end WebIDL.String_Sources;
|
--
-- 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.layout; use ewok.layout;
with ewok.tasks; use ewok.tasks;
with ewok.devices_shared; use ewok.devices_shared;
with ewok.devices;
with ewok.exported.dma; use type ewok.exported.dma.t_dma_shm_access;
package body ewok.sanitize
with spark_mode => off
is
function is_word_in_data_slot
(ptr : system_address;
task_id : ewok.tasks_shared.t_task_id;
mode : ewok.tasks_shared.t_task_mode)
return boolean
is
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
if ptr >= user_task.data_slot_start and
ptr + 4 <= user_task.data_slot_end
then
return true;
end if;
-- ISR mode is a special case because the stack is therefore
-- mutualized (thus only one ISR can be executed at the same time)
if mode = TASK_MODE_ISRTHREAD and
ptr >= STACK_BOTTOM_TASK_ISR and
ptr < STACK_TOP_TASK_ISR
then
return true;
end if;
return false;
end is_word_in_data_slot;
function is_word_in_txt_slot
(ptr : system_address;
task_id : ewok.tasks_shared.t_task_id)
return boolean
is
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
if ptr >= user_task.txt_slot_start and
ptr + 4 <= user_task.txt_slot_end
then
return true;
else
return false;
end if;
end is_word_in_txt_slot;
function is_word_in_allocated_device
(ptr : system_address;
task_id : ewok.tasks_shared.t_task_id)
return boolean
is
dev_id : ewok.devices_shared.t_device_id;
dev_size : unsigned_32;
dev_addr : system_address;
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
for i in user_task.devices'range loop
dev_id := user_task.devices(i).device_id;
if dev_id /= ID_DEV_UNUSED then
dev_addr := ewok.devices.get_device_addr (dev_id);
dev_size := ewok.devices.get_device_size (dev_id);
if ptr >= dev_addr and
ptr + 4 >= dev_addr and
ptr + 4 < dev_addr + dev_size
then
return true;
end if;
end if;
end loop;
return false;
end is_word_in_allocated_device;
function is_word_in_any_slot
(ptr : system_address;
task_id : ewok.tasks_shared.t_task_id;
mode : ewok.tasks_shared.t_task_mode)
return boolean
is
begin
return
is_word_in_data_slot (ptr, task_id, mode) or
is_word_in_txt_slot (ptr, task_id);
end is_word_in_any_slot;
function is_range_in_devices_slot
(ptr : system_address;
size : unsigned_32;
task_id : ewok.tasks_shared.t_task_id)
return boolean
is
user_device_size : unsigned_32;
user_device_addr : unsigned_32;
dev_id : t_device_id;
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
for i in user_task.devices'range loop
dev_id := user_task.devices(i).device_id;
if dev_id /= ID_DEV_UNUSED then
user_device_size := ewok.devices.get_device_size (dev_id);
user_device_addr := ewok.devices.get_device_addr (dev_id);
if ptr >= user_device_addr and
ptr + size <= user_device_addr + user_device_size
then
return true;
end if;
end if;
end loop;
return false;
end is_range_in_devices_slot;
function is_range_in_data_slot
(ptr : system_address;
size : unsigned_32;
task_id : ewok.tasks_shared.t_task_id;
mode : ewok.tasks_shared.t_task_mode)
return boolean
is
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
if ptr >= user_task.data_slot_start and
ptr + size >= ptr and
ptr + size <= user_task.data_slot_end
then
return true;
end if;
if mode = TASK_MODE_ISRTHREAD and
ptr >= STACK_BOTTOM_TASK_ISR and
ptr + size >= ptr and
ptr + size < STACK_TOP_TASK_ISR
then
return true;
end if;
return false;
end is_range_in_data_slot;
function is_range_in_txt_slot
(ptr : system_address;
size : unsigned_32;
task_id : ewok.tasks_shared.t_task_id)
return boolean
is
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
if ptr >= user_task.txt_slot_start and
ptr + size >= ptr and
ptr + size <= user_task.txt_slot_end
then
return true;
else
return false;
end if;
end is_range_in_txt_slot;
function is_range_in_any_slot
(ptr : system_address;
size : unsigned_32;
task_id : ewok.tasks_shared.t_task_id;
mode : ewok.tasks_shared.t_task_mode)
return boolean
is
begin
return
is_range_in_data_slot (ptr, size, task_id, mode) or
is_range_in_txt_slot (ptr, size, task_id);
end is_range_in_any_slot;
function is_range_in_dma_shm
(ptr : system_address;
size : unsigned_32;
dma_access : ewok.exported.dma.t_dma_shm_access;
task_id : ewok.tasks_shared.t_task_id)
return boolean
is
user_task : ewok.tasks.t_task renames ewok.tasks.tasks_list(task_id);
begin
for i in 1 .. user_task.num_dma_shms loop
if user_task.dma_shm(i).access_type = dma_access and
ptr >= user_task.dma_shm(i).base and
ptr + size >= ptr and
ptr + size <= (user_task.dma_shm(i).base +
user_task.dma_shm(i).size)
then
return true;
end if;
end loop;
return false;
end is_range_in_dma_shm;
end ewok.sanitize;
|
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired)
--
-- Copyright William A. Whitaker (1936–2010)
--
-- This is a free program, which means it is proper to copy it and pass
-- it on to your friends. Consider it a developmental item for which
-- there is no charge. However, just for form, it is Copyrighted
-- (c). Permission is hereby freely given for any and all use of program
-- and data. You can sell it as your own, but at least tell me.
--
-- This version is distributed without obligation, but the developer
-- would appreciate comments and suggestions.
--
-- All parts of the WORDS system, source code and data files, are made freely
-- available to anyone who wishes to use them, for whatever purpose.
with Ada.Exceptions; use Ada.Exceptions;
with Latin_Utils.Strings_Package; use Latin_Utils.Strings_Package;
with Support_Utils.Word_Parameters; use Support_Utils.Word_Parameters;
with Latin_Utils.Inflections_Package; use Latin_Utils.Inflections_Package;
with Support_Utils.Uniques_Package; use Support_Utils.Uniques_Package;
with Support_Utils.Developer_Parameters; use Support_Utils.Developer_Parameters;
with Support_Utils.Word_Support_Package; use Support_Utils.Word_Support_Package;
use Latin_Utils;
package body Words_Engine.List_Sweep
is
function Allowed_Stem (Pr : Parse_Record) return Boolean is
Allowed : Boolean := True;
-- modify as necessary and return it
De : Dictionary_Entry;
begin
-- TEXT_IO.PUT ("ALLOWED? >");
-- PARSE_RECORD_IO.PUT (PR);
-- TEXT_IO.NEW_LINE;
-- FIXME: duplicates (commented) code below
if Pr.D_K not in General .. Local then
return True;
end if;
Dict_IO.Read (Dict_File (Pr.D_K), De, Pr.MNPC);
-- NOUN CHECKS
case Pr.IR.Qual.Pofs is
when N =>
if Words_Mdev (For_Word_List_Check) then
if (Nom <= Pr.IR.Qual.Noun.Of_Case) and then
(S <= Pr.IR.Qual.Noun.Number)
then
Allowed := True;
elsif (Nom <= Pr.IR.Qual.Noun.Of_Case) and then
(Pr.IR.Qual.Noun.Number = P)
then
Search_For_Pl :
declare
De : Dictionary_Entry;
Mean : Meaning_Type := Null_Meaning_Type;
begin
Allowed := False;
Dict_IO.Read (Dict_File (Pr.D_K), De, Pr.MNPC);
Mean := De.Mean;
for J in Meaning_Type'First .. Meaning_Type'Last - 2
loop
if Mean (J .. J + 2) = "pl." then
Allowed := True;
exit;
end if;
end loop;
end Search_For_Pl;
else
Allowed := False;
end if;
end if;
when Adj =>
if Words_Mdev (For_Word_List_Check) then
Allowed := (Nom <= Pr.IR.Qual.Adj.Of_Case) and then
(S <= Pr.IR.Qual.Adj.Number) and then
(M <= Pr.IR.Qual.Adj.Gender);
end if;
-- VERB CHECKS
when V =>
--TEXT_IO.PUT ("VERB ");
-- Check for Verb 3 1 dic/duc/fac/fer shortened imperative
-- See G&L 130.5
declare
Stem : constant String := Trim (Pr.Stem);
Last_Three : String (1 .. 3);
begin
if (Pr.IR.Qual.Verb = ((3, 1), (Pres, Active, Imp), 2, S)) and
(Pr.IR.Ending.Size = 0)
then -- For this special case
if Stem'Length >= 3 then
Last_Three := Stem (Stem'Last - 2 .. Stem'Last);
if not ((Last_Three = "dic") or
(Last_Three = "duc") or
(Last_Three = "fac") or
(Last_Three = "fer"))
then
Allowed := False;
end if;
else
Allowed := False;
end if;
end if;
end;
-- Check for Verb Imperative being in permitted person
if Pr.IR.Qual.Verb.Tense_Voice_Mood.Mood = Imp and then
not (((Pr.IR.Qual.Verb.Tense_Voice_Mood.Tense = Pres) and
(Pr.IR.Qual.Verb.Person = 2)) or else
((Pr.IR.Qual.Verb.Tense_Voice_Mood.Tense = Fut) and
(Pr.IR.Qual.Verb.Person = 2 or
Pr.IR.Qual.Verb.Person = 3)))
then
Allowed := False;
end if;
-- Check for V IMPERS and demand that only 3rd person
if De.Part.V.Kind = Impers and then Pr.IR.Qual.Verb.Person /= 3
then
Allowed := False;
end if;
-- Check for V DEP and demand PASSIVE
if De.Part.V.Kind = Dep then
--TEXT_IO.PUT ("DEP ");
if (Pr.IR.Qual.Verb.Tense_Voice_Mood.Voice = Active) and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Mood = Inf) and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Tense = Fut)
then
--TEXT_IO.PUT ("PASSIVE ");
Allowed := True;
elsif (Pr.IR.Qual.Verb.Tense_Voice_Mood.Voice = Active) and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Mood in Ind .. Inf)
then
--TEXT_IO.PUT ("ACTIVE ");
Allowed := False;
else
--TEXT_IO.PUT ("?????? ");
null;
end if;
end if;
-- Check for V SEMIDEP and demand PASSIVE ex Perf
if De.Part.V.Kind = Semidep and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Mood in Ind .. Imp) and
(((Pr.IR.Qual.Verb.Tense_Voice_Mood.Voice = Passive) and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Tense in Pres .. Fut)) or
((Pr.IR.Qual.Verb.Tense_Voice_Mood.Voice = Active) and
(Pr.IR.Qual.Verb.Tense_Voice_Mood.Tense in Perf .. Futp)))
then
Allowed := False;
end if;
if Words_Mdev (For_Word_List_Check) then
if (Pr.IR.Qual.Verb.Person = 1) and then
(Pr.IR.Qual.Verb.Number = S)
then
Allowed := (Pr.IR.Qual.Verb.Tense_Voice_Mood =
(Pres, Active, Ind)) and
((De.Part.V.Kind in X .. Intrans) or else
(De.Part.V.Kind = Dep) or else
(De.Part.V.Kind = Semidep) or else
(De.Part.V.Kind = Perfdef));
elsif De.Part.V.Kind = Impers then
Allowed := (Pr.IR.Qual.Verb.Person = 3) and then
(Pr.IR.Qual.Verb.Number = S) and then
(Pr.IR.Qual.Verb.Tense_Voice_Mood = (Pres, Active, Ind));
else
Allowed := False;
end if;
end if;
when others =>
null;
end case;
if Words_Mdev (For_Word_List_Check) then -- Non parts
if Pr.IR.Qual.Pofs in Vpar .. Supine then
Allowed := False;
end if;
end if; -- Non parts
return Allowed;
end Allowed_Stem;
-- FIXME: Pa is effectively passed in twice; Sl is often a slice of Pa
procedure Order_Parse_Array
(Sl : in out Parse_Array;
Diff_J : out Integer;
Pa : in Parse_Array)
is
use Dict_IO;
Hits : Integer := 0;
Sl_Last : Integer := Sl'Last;
Sl_Last_Initial : constant Integer := Sl_Last;
Sm : Parse_Record;
Has_Noun_Abbreviation : Boolean := False;
Not_Only_Archaic : Boolean := False;
Not_Only_Medieval : Boolean := False;
Not_Only_Uncommon : Boolean := False;
function Depr (Pr : Parse_Record) return Dictionary_Entry is
De : Dictionary_Entry;
begin
-- TEXT_IO.PUT ("DEPR ");
-- PARSE_RECORD_IO.PUT (PR);
-- TEXT_IO.NEW_LINE;
-- FIXME: duplicates (commented) code above
if Pr.MNPC = Null_MNPC then
return Null_Dictionary_Entry;
else
if Pr.D_K in General .. Local then
--if PR.MNPC /= OMNPC then
Dict_IO.Set_Index (Dict_File (Pr.D_K), Pr.MNPC);
Dict_IO.Read (Dict_File (Pr.D_K), De);
--OMNPC := PR.MNPC;
--ODE := DE;
--else
--DE := ODE;
--end if;
elsif Pr.D_K = Unique then
De := Uniques_De (Pr.MNPC);
end if;
end if;
return De;
end Depr;
begin
if Sl'Length = 0 then
Diff_J := Sl_Last_Initial - Sl_Last;
return;
end if;
-- FIXME: this code looks like it's duplicated in another file
-- Bubble sort since this list should usually be very small (1-5)
Hit_Loop :
loop
Hits := 0;
--------------------------------------------------
Switch :
declare
function "<" (Left, Right : Quality_Record) return Boolean is
begin
if Left.Pofs = Right.Pofs and then
Left.Pofs = Pron and then
Left.Pron.Decl.Which = 1
then
return (Left.Pron.Decl.Var < Right.Pron.Decl.Var);
else
return Inflections_Package."<"(Left, Right);
end if;
end "<";
function Equ (Left, Right : Quality_Record) return Boolean is
begin
if Left.Pofs = Right.Pofs and then
Left.Pofs = Pron and then
Left.Pron.Decl.Which = 1
then
return (Left.Pron.Decl.Var = Right.Pron.Decl.Var);
else
return Inflections_Package."="(Left, Right);
end if;
end Equ;
function Meaning (Pr : Parse_Record) return Meaning_Type is
begin
return Depr (Pr).Mean;
end Meaning;
function Compare (L : Parse_Record;
R : Parse_Record) return Boolean is
begin
-- Maybe < = on PR.STEM - will have to make up "<"
-- Actually STEM and PART -- and check that later in print
return R.D_K > L.D_K
or else -- Let DICT.LOC list first
(R.D_K = L.D_K and then
R.MNPC < L.MNPC) or else
(R.D_K = L.D_K and then
R.MNPC = L.MNPC and then
R.IR.Qual < L.IR.Qual) or else
(R.D_K = L.D_K and then
R.MNPC = L.MNPC and then
Equ (R.IR.Qual, L.IR.Qual) and then
Meaning (R) < Meaning (L))
or else -- | is > letter
(R.D_K = L.D_K and then
R.MNPC = L.MNPC and then
Equ (R.IR.Qual, L.IR.Qual) and then
Meaning (R) = Meaning (L) and then
R.IR.Ending.Size < L.IR.Ending.Size) or else
(R.D_K = L.D_K and then
R.MNPC = L.MNPC and then
Equ (R.IR.Qual, L.IR.Qual) and then
Meaning (R) = Meaning (L) and then
R.IR.Ending.Size = L.IR.Ending.Size and then
Inflections_Package."<"(R.IR.Qual, L.IR.Qual));
end Compare;
begin
-- Need to remove duplicates in ARRAY_STEMS
-- This sort is very sloppy
-- One problem is that it can mix up some of the order of
-- PREFIX, XXX, LOC
-- I ought to do this for every set of results from
-- different approaches not just in one fell swoop
-- at the end !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Inner_Loop :
for I in Sl'First .. Sl_Last - 1 loop
if Compare (Sl (I), Sl (I + 1)) then
Sm := Sl (I);
Sl (I) := Sl (I + 1);
Sl (I + 1) := Sm;
Hits := Hits + 1;
end if;
end loop Inner_Loop;
end Switch;
--------------------------------------------------
exit Hit_Loop when Hits = 0;
end loop Hit_Loop;
-- Fix up the Archaic/Medieval
if Words_Mode (Trim_Output) then
-- Check to see if we can afford to TRIM,
-- if there will be something left over
for I in Sl'First .. Sl_Last
loop
declare
De : Dictionary_Entry;
begin
if Sl (I).D_K in General .. Local then
Dict_IO.Set_Index (Dict_File (Sl (I).D_K), Sl (I).MNPC);
--TEXT_IO.PUT (INTEGER'IMAGE (INTEGER (SL (I).MNPC)));
Dict_IO.Read (Dict_File (Sl (I).D_K), De);
--DICTIONARY_ENTRY_IO.PUT (DE); TEXT_IO.NEW_LINE;
if ((Sl (I).IR.Age = X) or else (Sl (I).IR.Age > A)) and
((De.Tran.Age = X) or else (De.Tran.Age > A))
then
Not_Only_Archaic := True;
end if;
if ((Sl (I).IR.Age = X) or else (Sl (I).IR.Age < F)) and
-- Or E????
((De.Tran.Age = X) or else (De.Tran.Age < F))
then
Not_Only_Medieval := True;
end if;
if ((Sl (I).IR.Freq = X) or else (Sl (I).IR.Freq < C)) and
-- A/X < C -- C for inflections is uncommon !!!!
((De.Tran.Freq = X) or else (De.Tran.Freq < D))
-- -- E for DICTLINE is uncommon !!!!
then
Not_Only_Uncommon := True;
end if;
if Sl (I).IR.Qual.Pofs = N and then
Sl (I).IR.Qual.Noun.Decl = (9, 8)
then
Has_Noun_Abbreviation := True;
end if;
end if;
end;
end loop;
-- We order and Trim within a subset SL, but have to correct the
-- big set PA also
-- Kill not ALLOWED first, then check the remaining from the top
-- I am assuming there is no Trim ming of FIXES for AGE/ .. .
for I in reverse Sl'First .. Sl_Last loop
-- Remove not ALLOWED_STEM & null
if not Allowed_Stem (Sl (I)) or (Pa (I) = Null_Parse_Record)
then
Sl (I .. Sl_Last - 1) := Sl (I + 1 .. Sl_Last);
Sl_Last := Sl_Last - 1;
Trimmed := True;
elsif (Not_Only_Archaic and Words_Mdev (Omit_Archaic)) and then
Sl (I).IR.Age = A
then
Sl (I .. Sl_Last - 1) := Sl (I + 1 .. Sl_Last);
Sl_Last := Sl_Last - 1;
Trimmed := True;
elsif (Not_Only_Medieval and Words_Mdev (Omit_Medieval)) and then
Sl (I).IR.Age >= F
then
Sl (I .. Sl_Last - 1) := Sl (I + 1 .. Sl_Last);
Sl_Last := Sl_Last - 1;
Trimmed := True;
elsif (Not_Only_Uncommon and Words_Mdev (Omit_Uncommon)) and then
Sl (I).IR.Freq >= C
then -- Remember A < C
Sl (I .. Sl_Last - 1) := Sl (I + 1 .. Sl_Last);
Sl_Last := Sl_Last - 1;
Trimmed := True;
----Big problem. This area has been generaing exceptions.
----At least one difficulty is that suffixes change POFS.
----So one has a N inflection (SL) but a V DE
----When the program checks for VOC, it wants a N
---- and then asks about KIND (P, N, T, .. .)
---- But the DE (v) does not have those
---- The solution would be to fix ADD SUFFIX
---- to do somethnig about
-- passing the ADDON KIND
---- I do not want to face that now
---- It is likely that all this VOC/LOC is worthless anyway.
--- Maybe lower FREQ in INFLECTS
----
---- A further complication is the GANT and AO give
-- different results (AO no exception)
---- That is probably because the program is in
-- error and the result threrfore unspecified
----
----
-- This is really working much too hard!
-- just to kill Roman numeral for three single letters
-- Also strange in that code depends on dictionary knowledge
elsif Has_Noun_Abbreviation and then
(All_Caps and Followed_By_Period)
then
if (Sl (I).IR.Qual.Pofs /= N) or
((Sl (I).IR.Qual /= (N, ((9, 8), X, X, M))) and
(Trim (Sl (I).Stem)'Length = 1 and then
(Sl (I).Stem (1) = 'A' or
Sl (I).Stem (1) = 'C' or
Sl (I).Stem (1) = 'D' or
--SL (I).STEM (1) = 'K' or -- No problem here
Sl (I).Stem (1) = 'L' or
Sl (I).Stem (1) = 'M' -- or
)))
then
Sl (I .. Sl_Last - 1) := Sl (I + 1 .. Sl_Last);
Sl_Last := Sl_Last - 1;
Trimmed := True;
end if;
end if;
end loop;
end if; -- On TRIM
Diff_J := Sl_Last_Initial - Sl_Last;
end Order_Parse_Array;
procedure List_Sweep
(Pa : in out Parse_Array;
Pa_Last : in out Integer)
is
-- This procedure is supposed to process the Output PARSE_ARRAY at
-- PA level
-- before it gets turned into SIRAA and DMNPCA in LIST_PACKAGE
-- Since it does only PARSE_ARRAY it is just cheaking INFLECTIONS, not
-- DICTIONARY
-----------------------------------------------------------
begin -- LIST_SWEEP
if Pa'Length = 0 then
return;
end if;
Reset_Pronoun_Kind :
declare
De : Dictionary_Entry;
begin
for I in 1 .. Pa_Last loop
if Pa (I).D_K = General then
Dict_IO.Set_Index (Dict_File (Pa (I).D_K), Pa (I).MNPC);
Dict_IO.Read (Dict_File (Pa (I).D_K), De);
if De.Part.Pofs = Pron and then
De.Part.Pron.Decl.Which = 1
then
Pa (I).IR.Qual.Pron.Decl.Var :=
Pronoun_Kind_Type'Pos (De.Part.Pron.Kind);
end if;
end if;
end loop;
end Reset_Pronoun_Kind;
---------------------------------------------------
-- NEED TO REMOVE DISALLOWED BEFORE DOING ANYTHING - BUT
-- WITHOUT REORDERING
-- The problem I seem to have to face first, if not the first problem,
-- is the situation in which there are several sets of identical IRs
-- with different MNPC. These may be variants with some other stem
-- (e.g., K=3) not affecting the (K=1) word. Or they might be
-- identical forms with different meanings (| additional meanings)
-- I need to group such common inflections - and pass this on somehow
Sweeping :
-- To remove disallowed stems/inflections and resulting dangling fixes
declare
Internal_Loop_Error : exception;
Fix_On : Boolean := False;
Pw_On : Boolean := False;
P_First : Integer := 1;
P_Last : Integer := 0;
Jj : Integer := 0;
Diff_J : Integer := 0;
subtype Xons is Part_Of_Speech_Type range Tackon .. Suffix;
begin
for J in reverse 1 .. Pa_Last loop -- Sweep backwards over PA
if ((Pa (J).D_K in Addons .. Yyy) or (Pa (J).IR.Qual.Pofs in Xons))
and then (Pw_On)
then -- first FIX/TRICK after regular
Fix_On := True;
Pw_On := False;
P_First := J + 1;
Jj := J;
while Pa (Jj + 1).IR.Qual.Pofs = Pa (Jj).IR.Qual.Pofs loop
P_Last := Jj + 1;
Raise_Exception (Internal_Loop_Error'Identity,
"Programming error; known bug, #70");
end loop;
----Order internal to this set of inflections
Order_Parse_Array (Pa (P_First .. P_Last), Diff_J, Pa);
Pa (P_Last - Diff_J + 1 .. Pa_Last - Diff_J) :=
Pa (P_Last + 1 .. Pa_Last);
Pa_Last := Pa_Last - Diff_J;
P_First := 1;
P_Last := 0;
elsif ((Pa (J).D_K in Addons .. Yyy) or
(Pa (J).IR.Qual.Pofs in Xons)) and then
(Fix_On)
then -- another FIX
null;
elsif ((Pa (J).D_K in Addons .. Yyy) or
(Pa (J).IR.Qual.Pofs = X)) and then -- Kills TRICKS stuff
(not Pw_On)
then
Pa (P_Last - Diff_J + 1 .. Pa_Last - Diff_J) :=
Pa (P_Last + 1 .. Pa_Last);
Pa_Last := Pa_Last - Diff_J;
P_Last := P_Last - 1;
else
Pw_On := True;
Fix_On := False;
if P_Last <= 0 then
P_Last := J;
end if;
if J = 1 then
Order_Parse_Array (Pa (1 .. P_Last), Diff_J, Pa);
Pa (P_Last - Diff_J + 1 .. Pa_Last - Diff_J) :=
Pa (P_Last + 1 .. Pa_Last);
Pa_Last := Pa_Last - Diff_J;
end if;
end if; -- check PART
end loop; -- loop sweep over PA
end Sweeping;
-- Last chance to weed out duplicates
declare
Pr : Parse_Record := Null_Parse_Record;
Opr : Parse_Record := Pa (1);
J : Integer := 2;
begin
Compress_Loop :
loop
exit Compress_Loop when J > Pa_Last;
Pr := Pa (J);
if Pr /= Opr then
Supress_Key_Check :
declare
function "<=" (A, B : Parse_Record) return Boolean is
use Dict_IO;
begin -- !!!!!!!!!!!!!!!!!!!!!!!!!!
return A.IR.Qual = B.IR.Qual and A.MNPC = B.MNPC;
end "<=";
begin
if (Pr.D_K /= Xxx) and (Pr.D_K /= Yyy) and (Pr.D_K /= Ppp)
then
if Pr <= Opr then
-- Get rid of duplicates, if ORDER is OK
Pa (J .. Pa_Last - 1) := Pa (J + 1 .. Pa_Last);
-- Shift PA down 1
Pa_Last := Pa_Last - 1;
-- because found key duplicate
end if;
else
J := J + 1;
end if;
end Supress_Key_Check;
else
J := J + 1;
end if;
Opr := Pr;
end loop Compress_Loop;
end;
for I in 1 .. Pa_Last loop
-- Destroy the artificial VAR for PRON 1 X
if Pa (I).IR.Qual.Pofs = Pron and then
Pa (I).IR.Qual.Pron.Decl.Which = 1
then
Pa (I).IR.Qual.Pron.Decl.Var := 0;
end if;
if Pa (I).IR.Qual.Pofs = V then
if Pa (I).IR.Qual.Verb.Con = (3, 4) then
-- Fix V 3 4 to be 4th conjugation
Pa (I).IR.Qual.Verb.Con := (4, 1);
-- else
-- -- Set to 0 other VAR for V
-- PA (I).IR.QUAL.V.CON.VAR := 0;
end if;
end if;
end loop;
end List_Sweep;
end Words_Engine.List_Sweep;
|
Pragma Ada_2012;
Pragma Assertion_Policy( Check );
With
Interfaces;
Use
Interfaces;
-- Everyone's Verified & Independent Library.
Package EVIL with Pure, SPARK_Mode => On is
End EVIL;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . W I D E _ S P E L L I N G _ C H E C K E R --
-- --
-- S p e c --
-- --
-- Copyright (C) 1998-2019, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Spelling checker
-- This package provides a utility routine for checking for bad spellings
-- for the case of Wide_String arguments.
package GNAT.Wide_Spelling_Checker is
pragma Pure;
function Is_Bad_Spelling_Of
(Found : Wide_String;
Expect : Wide_String) return Boolean;
-- Determines if the string Found is a plausible misspelling of the string
-- Expect. Returns True for an exact match or a probably misspelling, False
-- if no near match is detected. This routine is case sensitive, so the
-- caller should fold both strings to get a case insensitive match.
--
-- Note: the spec of this routine is deliberately rather vague. It is used
-- by GNAT itself to detect misspelled keywords and identifiers, and is
-- heuristically adjusted to be appropriate to this usage. It will work
-- well in any similar case of named entities.
end GNAT.Wide_Spelling_Checker;
|
-- Copyright 2015,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.Storage_Elements;
package Linted.Controls is
pragma Pure;
type Int is range -2**(32 - 1) .. 2**(32 - 1) - 1;
type Packet is record
Z_Tilt : Int := 0;
X_Tilt : Int := 0;
Left : Boolean := False;
Right : Boolean := False;
Forward : Boolean := False;
Back : Boolean := False;
Jumping : Boolean := False;
end record;
Storage_Size : constant := 2 * 4 + 1;
subtype Storage is
System.Storage_Elements.Storage_Array (1 .. Storage_Size);
procedure From_Storage (S : Storage; C : out Packet) with
Global => null,
Depends => (C => S);
end Linted.Controls;
|
with
lace.Event,
lace.Response;
limited
with
lace.Event.Logger;
package lace.Observer
--
-- Provides an interface for an event Observer.
--
is
pragma remote_Types;
type Item is limited interface;
type View is access all Item'Class;
type Views is array (Positive range <>) of View;
type fast_View is access all Item'class;
type fast_Views is array (Positive range <>) of fast_View;
pragma Asynchronous (fast_View);
-- Attributes
--
function Name (Self : in Item) return event.observer_Name is abstract;
-- Responses
--
procedure add (Self : access Item; the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in event.subject_Name) is abstract;
procedure rid (Self : access Item; the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in event.subject_Name) is abstract;
procedure relay_responseless_Events
(Self : in out Item; To : in Observer.view) is abstract;
-- Operations
--
procedure receive (Self : access Item; the_Event : in Event.item'Class := event.null_Event;
from_Subject : in event.subject_Name) is abstract;
--
-- Accepts an Event from a Subject.
procedure respond (Self : access Item) is abstract;
--
-- Performs the Response for (and then removes) each pending Event.
-- Logging
--
procedure Logger_is (Now : access Event.Logger.item'Class);
function Logger return access Event.Logger.item'Class;
end lace.Observer;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_glx_get_minmax_request_t is
-- Item
--
type Item is record
major_opcode : aliased Interfaces.Unsigned_8;
minor_opcode : aliased Interfaces.Unsigned_8;
length : aliased Interfaces.Unsigned_16;
context_tag : aliased xcb.xcb_glx_context_tag_t;
target : aliased Interfaces.Unsigned_32;
format : aliased Interfaces.Unsigned_32;
the_type : aliased Interfaces.Unsigned_32;
swap_bytes : aliased Interfaces.Unsigned_8;
reset : aliased Interfaces.Unsigned_8;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_glx_get_minmax_request_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_minmax_request_t.Item,
Element_Array => xcb.xcb_glx_get_minmax_request_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_glx_get_minmax_request_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_get_minmax_request_t.Pointer,
Element_Array => xcb.xcb_glx_get_minmax_request_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_get_minmax_request_t;
|
with ZMQ;
package ZHelper is
function Rand_Of (First : Integer; Last : Integer) return Integer;
function Rand_Of (First : Float; Last : Float) return Float;
-- Provide random number from First .. Last
procedure Dump (S : ZMQ.Socket_Type'Class);
-- Receives all message parts from socket, prints neatly
function Set_Id (S : ZMQ.Socket_Type'Class) return String;
procedure Set_Id (S : ZMQ.Socket_Type'Class);
-- Set simple random printable identity on socket
end ZHelper;
|
------------------------------------------------------------------------------
-- --
-- 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$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Generic_Collections;
package AMF.UML.Extensions.Collections is
pragma Preelaborate;
package UML_Extension_Collections is
new AMF.Generic_Collections
(UML_Extension,
UML_Extension_Access);
type Set_Of_UML_Extension is
new UML_Extension_Collections.Set with null record;
Empty_Set_Of_UML_Extension : constant Set_Of_UML_Extension;
type Ordered_Set_Of_UML_Extension is
new UML_Extension_Collections.Ordered_Set with null record;
Empty_Ordered_Set_Of_UML_Extension : constant Ordered_Set_Of_UML_Extension;
type Bag_Of_UML_Extension is
new UML_Extension_Collections.Bag with null record;
Empty_Bag_Of_UML_Extension : constant Bag_Of_UML_Extension;
type Sequence_Of_UML_Extension is
new UML_Extension_Collections.Sequence with null record;
Empty_Sequence_Of_UML_Extension : constant Sequence_Of_UML_Extension;
private
Empty_Set_Of_UML_Extension : constant Set_Of_UML_Extension
:= (UML_Extension_Collections.Set with null record);
Empty_Ordered_Set_Of_UML_Extension : constant Ordered_Set_Of_UML_Extension
:= (UML_Extension_Collections.Ordered_Set with null record);
Empty_Bag_Of_UML_Extension : constant Bag_Of_UML_Extension
:= (UML_Extension_Collections.Bag with null record);
Empty_Sequence_Of_UML_Extension : constant Sequence_Of_UML_Extension
:= (UML_Extension_Collections.Sequence with null record);
end AMF.UML.Extensions.Collections;
|
with impact.d3.Shape.convex;
-- #include "BulletCollision/CollisionShapes/impact.d3.Shape.convex.h"
package impact.d3.collision.gjk_epa
--
-- GJK-EPA collision solver by Nathanael Presson, 2008
--
is
use Math;
-- btGjkEpaSolver contributed under zlib by Nathanael Presson
--
package btGjkEpaSolver2
is
type eStatus is (Separated, -- Shapes doesnt penetrate
Penetrating, -- Shapes are penetrating
GJK_Failed, -- GJK phase fail, no big issue, shapes are probably just 'touching'
EPA_Failed); -- EPA phase fail, bigger problem, need to save parameters, and debug
status : eStatus;
type Witnesses is array (1 .. 2) of math.Vector_3;
type sResults is
record
witnesses : btGjkEpaSolver2.Witnesses;
normal : math.Vector_3;
distance : math.Real;
status : eStatus;
end record;
function StackSizeRequirement return Integer;
function Distance (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults) return Boolean;
function Penetration (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults;
usemargins : in Boolean := True) return Boolean;
function SignedDistance (position : in math.Vector_3;
margin : in math.Real;
shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
results : access sResults) return math.Real;
function SignedDistance (shape0 : in impact.d3.Shape.convex.view;
wtrs0 : in Transform_3d;
shape1 : in impact.d3.Shape.convex.view;
wtrs1 : in Transform_3d;
guess : in math.Vector_3;
results : access sResults) return Boolean;
end btGjkEpaSolver2;
end impact.d3.collision.gjk_epa;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with xcb.xcb_request_error_t;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_name_error_t is
-- Item
--
subtype Item is xcb.xcb_request_error_t.Item;
-- Item_Array
--
type Item_Array is
array (Interfaces.C.size_t range <>) of aliased xcb.xcb_name_error_t.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_name_error_t.Item,
Element_Array => xcb.xcb_name_error_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_name_error_t.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_name_error_t.Pointer,
Element_Array => xcb.xcb_name_error_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_name_error_t;
|
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = true
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.59
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot1@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 1
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot2@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 2
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot3@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 3
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot4@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 4
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot5@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 5
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot6@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 6
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot7@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 7
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
AcceptedWhileDraining = false
Activity = "Idle"
AddressV1 = "{[ p=\"primary\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ], [ p=\"IPv4\"; a=\"10.0.0.3\"; port=36347; n=\"Internet\"; alias=\"gthain.localdomain\"; spid=\"startd_888024_2e07\"; noUDP=true; ]}"
Arch = "X86_64"
AuthenticatedIdentity = "condor@family"
AuthenticationMethod = "FAMILY"
CanHibernate = true
ClockDay = 0
ClockMin = 980
COLLECTOR_HOST_STRING = "gthain.localdomain:0"
CondorLoadAvg = 0.0
CondorPlatform = "$CondorPlatform: X86_64-Fedora_33 $"
CondorVersion = "$CondorVersion: 8.9.12 Mar 14 2021 BuildID: UW_development RC $"
ConsoleIdle = 0
CpuBusy = ((LoadAvg - CondorLoadAvg) >= 0.5)
CpuBusyTime = 0
CpuCacheSize = 8192
CpuFamily = 6
CpuIsBusy = false
CpuModelNumber = 142
Cpus = 1
CurrentRank = 0.0
DaemonCoreDutyCycle = 0.0
DaemonLastReconfigTime = 1615756825
DaemonShutdown = time() - DaemonStartTime > 1500
DaemonStartTime = 1615756825
DetectedCpus = 8
DetectedMemory = 15661
Disk = 16190387
EnteredCurrentActivity = 1615756825
EnteredCurrentState = 1615756825
ExpectedMachineGracefulDrainingBadput = 0
ExpectedMachineGracefulDrainingCompletion = 1615756825
ExpectedMachineQuickDrainingBadput = 0
ExpectedMachineQuickDrainingCompletion = 1615756825
FileSystemDomain = "gthain.localdomain"
HardwareAddress = "40:ec:99:82:52:b2"
has_avx = true
has_avx2 = true
has_sse4_1 = true
has_sse4_2 = true
has_ssse3 = true
HasFileTransfer = true
HasIOProxy = true
HasJICLocalConfig = true
HasJICLocalStdin = true
HasJobDeferral = true
HasJobTransferPlugins = true
HasMPI = true
HasPerFileEncryption = true
HasReconnect = true
HasSelfCheckpointTransfers = true
HasSingularity = true
HasTDP = true
HasTransferInputRemaps = true
HasUserNamespaces = true
HasVM = false
HibernationLevel = 0
HibernationState = "NONE"
HibernationSupportedStates = "S3,S4,S5"
IsLocalStartd = false
IsWakeAble = false
IsWakeOnLanEnabled = false
IsWakeOnLanSupported = false
JobPreemptions = 0
JobRankPreemptions = 0
JobStarts = 0
JobUserPrioPreemptions = 0
KeyboardIdle = 0
LastBenchmark = 0
LastFetchWorkCompleted = 0
LastFetchWorkSpawned = 0
LastHeardFrom = 1615756825
LoadAvg = 0.0
Machine = "gthain.localdomain"
MachineMaxVacateTime = 10 * 60
MachineResources = "Cpus Memory Disk Swap"
MaxJobRetirementTime = 0
Memory = 1957
MonitorSelfAge = 1
MonitorSelfCPUUsage = 1.0
MonitorSelfImageSize = 26716
MonitorSelfRegisteredSocketCount = 0
MonitorSelfResidentSetSize = 12836
MonitorSelfSecuritySessions = 10
MonitorSelfTime = 1615756825
MyAddress = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
MyCurrentTime = 1615756825
MyType = "Machine"
Name = "slot8@gthain.localdomain"
NextFetchWorkDelay = -1
NumPids = 0
OpSys = "LINUX"
OpSysAndVer = "Fedora33"
OpSysLegacy = "LINUX"
OpSysLongName = "Fedora release 33 (Thirty Three)"
OpSysMajorVer = 33
OpSysName = "Fedora"
OpSysShortName = "Fedora"
OpSysVer = 3300
Rank = 0.0
RecentDaemonCoreDutyCycle = 0.0
RecentJobPreemptions = 0
RecentJobRankPreemptions = 0
RecentJobStarts = 0
RecentJobUserPrioPreemptions = 0
Requirements = START
RetirementTimeRemaining = 0
SingularityVersion = "singularity version 3.7.1-1.fc33"
SlotID = 8
SlotType = "Static"
SlotTypeID = 0
SlotWeight = Cpus
Start = true
StartdIpAddr = "<10.0.0.3:36347?addrs=10.0.0.3-36347&alias=gthain.localdomain&noUDP&sock=startd_888024_2e07>"
StarterAbilityList = "HasVM,HasMPI,HasFileTransfer,HasJobDeferral,HasSingularity,HasJobTransferPlugins,HasPerFileEncryption,HasReconnect,HasTDP,HasJICLocalStdin,HasTransferInputRemaps,HasSelfCheckpointTransfers,HasJICLocalConfig"
State = "Unclaimed"
SubnetMask = "255.255.255.0"
TargetType = "Job"
TimeToLive = 2147483647
TotalCondorLoadAvg = 0.0
TotalCpus = 8.0
TotalDisk = 129523096
TotalLoadAvg = 0.59
TotalMemory = 15661
TotalSlotCpus = 1
TotalSlotDisk = 16190387.0
TotalSlotMemory = 1957
TotalSlots = 8
TotalVirtualMemory = 28313600
UidDomain = "gthain.localdomain"
Unhibernate = MY.MachineLastMatchTime =!= undefined
UpdateSequenceNumber = 1
UpdatesHistory = "00000000000000000000000000000000"
UpdatesLost = 0
UpdatesSequenced = 0
UpdatesTotal = 1
UtsnameMachine = "x86_64"
UtsnameNodename = "gthain.localdomain"
UtsnameRelease = "5.10.21-200.fc33.x86_64"
UtsnameSysname = "Linux"
UtsnameVersion = "#1 SMP Mon Mar 8 00:24:40 UTC 2021"
VirtualMemory = 3539200
WakeOnLanEnabledFlags = "NONE"
WakeOnLanSupportedFlags = "NONE"
|
with Spark_Unbound.Safe_Alloc;
with AUnit.Assertions; use AUnit.Assertions;
with Ada.Exceptions;
package body SA_Arrays_Tests is
procedure TestAlloc_WithForcingStorageError_ResultNullReturned(T : in out Test_Fixture)
is
type Array_Type is array (Integer range <>) of Integer;
type Array_Acc is access Array_Type;
package Int_Arrays is new Spark_Unbound.Safe_Alloc.Arrays(Element_Type => Integer, Index_Type => Integer, Array_Type => Array_Type, Array_Type_Acc => Array_Acc);
Arr_Acc : Array_Acc;
Array_Last : Integer := 1_000_000_000;
Storage_Error_Forced : Boolean := False;
-- table to keep track of allocated arrays to be freed later
type Acc_Table_Array is array (Integer range <>) of Array_Acc;
Acc_Table : Acc_Table_Array(0 .. 1_000_000);
Table_Index : Integer := Acc_Table'First;
begin
declare
begin
loop
exit when (Storage_Error_Forced or else Table_Index >= Acc_Table'Last);
begin
Arr_Acc := Int_Arrays.Alloc(First => Integer'First, Last => Array_Last);
begin
Acc_Table(Table_Index) := Arr_Acc;
Table_Index := Table_Index + 1;
exception
when others =>
Assert(False, "Table append failed");
end;
if Arr_Acc = null then
Storage_Error_Forced := True;
elsif Array_Last < Integer'Last - Array_Last then
Array_Last := Array_Last + Array_Last;
else
Array_Last := Integer'Last;
end if;
exception
when E : others =>
Assert(False, "Alloc failed: " & Ada.Exceptions.Exception_Name(E) & " => " & Ada.Exceptions.Exception_Message(E));
end;
end loop;
-- free allocated
for I in Acc_Table'First .. Acc_Table'Last loop
Int_Arrays.Free(Acc_Table(I));
end loop;
Assert(Storage_Error_Forced, "Storage_Error could not be forced. Last value = " & Array_Last'Image);
exception
when E : others =>
Assert(False, "Exception got raised with Last = " & Array_Last'Image & " Reason: " & Ada.Exceptions.Exception_Name(E) & " => " & Ada.Exceptions.Exception_Message(E));
end;
end TestAlloc_WithForcingStorageError_ResultNullReturned;
end SA_Arrays_Tests;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ D I S P --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
with Exp_Atag; use Exp_Atag;
with Exp_Ch6; use Exp_Ch6;
with Exp_CG; use Exp_CG;
with Exp_Dbug; use Exp_Dbug;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Ghost; use Ghost;
with Itypes; use Itypes;
with Layout; use Layout;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Namet; use Namet;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Stand; use Stand;
with Stringt; use Stringt;
with SCIL_LL; use SCIL_LL;
with Tbuild; use Tbuild;
package body Exp_Disp is
-----------------------
-- Local Subprograms --
-----------------------
function Default_Prim_Op_Position (E : Entity_Id) return Uint;
-- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
-- of the default primitive operations.
function Has_DT (Typ : Entity_Id) return Boolean;
pragma Inline (Has_DT);
-- Returns true if we generate a dispatch table for tagged type Typ
function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
-- Returns true if Prim is not a predefined dispatching primitive but it is
-- an alias of a predefined dispatching primitive (i.e. through a renaming)
function New_Value (From : Node_Id) return Node_Id;
-- From is the original Expression. New_Value is equivalent to a call to
-- Duplicate_Subexpr with an explicit dereference when From is an access
-- parameter.
function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
-- Check if the type has a private view or if the public view appears in
-- the visible part of a package spec.
function Prim_Op_Kind
(Prim : Entity_Id;
Typ : Entity_Id) return Node_Id;
-- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
-- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
-- enumeration value.
function Tagged_Kind (T : Entity_Id) return Node_Id;
-- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
-- to an RE_Tagged_Kind enumeration value.
----------------------
-- Apply_Tag_Checks --
----------------------
procedure Apply_Tag_Checks (Call_Node : Node_Id) is
Loc : constant Source_Ptr := Sloc (Call_Node);
Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
Param_List : constant List_Id := Parameter_Associations (Call_Node);
Subp : Entity_Id;
CW_Typ : Entity_Id;
Param : Node_Id;
Typ : Entity_Id;
Eq_Prim_Op : Entity_Id := Empty;
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("tagged types", Call_Node);
return;
end if;
-- Apply_Tag_Checks is called directly from the semantics, so we
-- need a check to see whether expansion is active before proceeding.
-- In addition, there is no need to expand the call when compiling
-- under restriction No_Dispatching_Calls; the semantic analyzer has
-- previously notified the violation of this restriction.
if not Expander_Active
or else Restriction_Active (No_Dispatching_Calls)
then
return;
end if;
-- Set subprogram. If this is an inherited operation that was
-- overridden, the body that is being called is its alias.
Subp := Entity (Name (Call_Node));
if Present (Alias (Subp))
and then Is_Inherited_Operation (Subp)
and then No (DTC_Entity (Subp))
then
Subp := Alias (Subp);
end if;
-- Definition of the class-wide type and the tagged type
-- If the controlling argument is itself a tag rather than a tagged
-- object, then use the class-wide type associated with the subprogram's
-- controlling type. This case can occur when a call to an inherited
-- primitive has an actual that originated from a default parameter
-- given by a tag-indeterminate call and when there is no other
-- controlling argument providing the tag (AI-239 requires dispatching).
-- This capability of dispatching directly by tag is also needed by the
-- implementation of AI-260 (for the generic dispatching constructors).
if Ctrl_Typ = RTE (RE_Tag)
or else (RTE_Available (RE_Interface_Tag)
and then Ctrl_Typ = RTE (RE_Interface_Tag))
then
CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
-- Class_Wide_Type is applied to the expressions used to initialize
-- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
-- there are cases where the controlling type is resolved to a specific
-- type (such as for designated types of arguments such as CW'Access).
elsif Is_Access_Type (Ctrl_Typ) then
CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
else
CW_Typ := Class_Wide_Type (Ctrl_Typ);
end if;
Typ := Find_Specific_Type (CW_Typ);
if not Is_Limited_Type (Typ) then
Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
end if;
-- Dispatching call to C++ primitive
if Is_CPP_Class (Typ) then
null;
-- Dispatching call to Ada primitive
elsif Present (Param_List) then
-- Generate the Tag checks when appropriate
Param := First_Actual (Call_Node);
while Present (Param) loop
-- No tag check with itself
if Param = Ctrl_Arg then
null;
-- No tag check for parameter whose type is neither tagged nor
-- access to tagged (for access parameters)
elsif No (Find_Controlling_Arg (Param)) then
null;
-- No tag check for function dispatching on result if the
-- Tag given by the context is this one
elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
null;
-- "=" is the only dispatching operation allowed to get operands
-- with incompatible tags (it just returns false). We use
-- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
-- because the value will be duplicated to check the tags.
elsif Subp = Eq_Prim_Op then
null;
-- No check in presence of suppress flags
elsif Tag_Checks_Suppressed (Etype (Param))
or else (Is_Access_Type (Etype (Param))
and then Tag_Checks_Suppressed
(Designated_Type (Etype (Param))))
then
null;
-- Optimization: no tag checks if the parameters are identical
elsif Is_Entity_Name (Param)
and then Is_Entity_Name (Ctrl_Arg)
and then Entity (Param) = Entity (Ctrl_Arg)
then
null;
-- Now we need to generate the Tag check
else
-- Generate code for tag equality check
-- Perhaps should have Checks.Apply_Tag_Equality_Check???
Insert_Action (Ctrl_Arg,
Make_Implicit_If_Statement (Call_Node,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix => New_Value (Ctrl_Arg),
Selector_Name =>
New_Occurrence_Of
(First_Tag_Component (Typ), Loc)),
Right_Opnd =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Typ, New_Value (Param)),
Selector_Name =>
New_Occurrence_Of
(First_Tag_Component (Typ), Loc))),
Then_Statements =>
New_List (New_Constraint_Error (Loc))));
end if;
Next_Actual (Param);
end loop;
end if;
end Apply_Tag_Checks;
------------------------
-- Building_Static_DT --
------------------------
function Building_Static_DT (Typ : Entity_Id) return Boolean is
Root_Typ : Entity_Id := Root_Type (Typ);
Static_DT : Boolean;
begin
-- Handle private types
if Present (Full_View (Root_Typ)) then
Root_Typ := Full_View (Root_Typ);
end if;
Static_DT :=
Building_Static_Dispatch_Tables
and then Is_Library_Level_Tagged_Type (Typ)
-- If the type is derived from a CPP class we cannot statically
-- build the dispatch tables because we must inherit primitives
-- from the CPP side.
and then not Is_CPP_Class (Root_Typ);
if not Static_DT then
Check_Restriction (Static_Dispatch_Tables, Typ);
end if;
return Static_DT;
end Building_Static_DT;
----------------------------------
-- Building_Static_Secondary_DT --
----------------------------------
function Building_Static_Secondary_DT (Typ : Entity_Id) return Boolean is
Full_Typ : Entity_Id := Typ;
Root_Typ : Entity_Id := Root_Type (Typ);
Static_DT : Boolean;
begin
-- Handle private types
if Present (Full_View (Typ)) then
Full_Typ := Full_View (Typ);
end if;
if Present (Full_View (Root_Typ)) then
Root_Typ := Full_View (Root_Typ);
end if;
Static_DT :=
Building_Static_DT (Full_Typ)
and then not Is_Interface (Full_Typ)
and then Has_Interfaces (Full_Typ)
and then (Full_Typ = Root_Typ
or else not Is_Variable_Size_Record (Etype (Full_Typ)));
if not Static_DT
and then not Is_Interface (Full_Typ)
and then Has_Interfaces (Full_Typ)
then
Check_Restriction (Static_Dispatch_Tables, Typ);
end if;
return Static_DT;
end Building_Static_Secondary_DT;
----------------------------------
-- Build_Static_Dispatch_Tables --
----------------------------------
procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
Target_List : List_Id;
procedure Build_Dispatch_Tables (List : List_Id);
-- Build the static dispatch table of tagged types found in the list of
-- declarations. The generated nodes are added at the end of Target_List
procedure Build_Package_Dispatch_Tables (N : Node_Id);
-- Build static dispatch tables associated with package declaration N
---------------------------
-- Build_Dispatch_Tables --
---------------------------
procedure Build_Dispatch_Tables (List : List_Id) is
D : Node_Id;
begin
D := First (List);
while Present (D) loop
-- Handle nested packages and package bodies recursively. The
-- generated code is placed on the Target_List established for
-- the enclosing compilation unit.
if Nkind (D) = N_Package_Declaration then
Build_Package_Dispatch_Tables (D);
elsif Nkind (D) = N_Package_Body then
Build_Dispatch_Tables (Declarations (D));
elsif Nkind (D) = N_Package_Body_Stub
and then Present (Library_Unit (D))
then
Build_Dispatch_Tables
(Declarations (Proper_Body (Unit (Library_Unit (D)))));
-- Handle full type declarations and derivations of library level
-- tagged types
elsif Nkind (D) in
N_Full_Type_Declaration | N_Derived_Type_Definition
and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
and then not Is_Private_Type (Defining_Entity (D))
then
-- We do not generate dispatch tables for the internal types
-- created for a type extension with unknown discriminants
-- The needed information is shared with the source type,
-- See Expand_N_Record_Extension.
if Is_Underlying_Record_View (Defining_Entity (D))
or else
(not Comes_From_Source (Defining_Entity (D))
and then
Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
and then
not Comes_From_Source
(First_Subtype (Defining_Entity (D))))
then
null;
else
Insert_List_After_And_Analyze (Last (Target_List),
Make_DT (Defining_Entity (D)));
end if;
-- Handle private types of library level tagged types. We must
-- exchange the private and full-view to ensure the correct
-- expansion. If the full view is a synchronized type ignore
-- the type because the table will be built for the corresponding
-- record type, that has its own declaration.
elsif (Nkind (D) = N_Private_Type_Declaration
or else Nkind (D) = N_Private_Extension_Declaration)
and then Present (Full_View (Defining_Entity (D)))
then
declare
E1 : constant Entity_Id := Defining_Entity (D);
E2 : constant Entity_Id := Full_View (E1);
begin
if Is_Library_Level_Tagged_Type (E2)
and then Ekind (E2) /= E_Record_Subtype
and then not Is_Concurrent_Type (E2)
then
Exchange_Declarations (E1);
Insert_List_After_And_Analyze (Last (Target_List),
Make_DT (E1));
Exchange_Declarations (E2);
end if;
end;
end if;
Next (D);
end loop;
end Build_Dispatch_Tables;
-----------------------------------
-- Build_Package_Dispatch_Tables --
-----------------------------------
procedure Build_Package_Dispatch_Tables (N : Node_Id) is
Spec : constant Node_Id := Specification (N);
Id : constant Entity_Id := Defining_Entity (N);
Vis_Decls : constant List_Id := Visible_Declarations (Spec);
Priv_Decls : constant List_Id := Private_Declarations (Spec);
begin
Push_Scope (Id);
if Present (Priv_Decls) then
Build_Dispatch_Tables (Vis_Decls);
Build_Dispatch_Tables (Priv_Decls);
elsif Present (Vis_Decls) then
Build_Dispatch_Tables (Vis_Decls);
end if;
Pop_Scope;
end Build_Package_Dispatch_Tables;
-- Start of processing for Build_Static_Dispatch_Tables
begin
if not Expander_Active
or else not Tagged_Type_Expansion
then
return;
end if;
if Nkind (N) = N_Package_Declaration then
declare
Spec : constant Node_Id := Specification (N);
Vis_Decls : constant List_Id := Visible_Declarations (Spec);
Priv_Decls : constant List_Id := Private_Declarations (Spec);
begin
if Present (Priv_Decls)
and then Is_Non_Empty_List (Priv_Decls)
then
Target_List := Priv_Decls;
elsif not Present (Vis_Decls) then
Target_List := New_List;
Set_Private_Declarations (Spec, Target_List);
else
Target_List := Vis_Decls;
end if;
Build_Package_Dispatch_Tables (N);
end;
else pragma Assert (Nkind (N) = N_Package_Body);
Target_List := Declarations (N);
Build_Dispatch_Tables (Target_List);
end if;
end Build_Static_Dispatch_Tables;
------------------------------
-- Convert_Tag_To_Interface --
------------------------------
function Convert_Tag_To_Interface
(Typ : Entity_Id;
Expr : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Expr);
Anon_Type : Entity_Id;
Result : Node_Id;
begin
pragma Assert (Is_Class_Wide_Type (Typ)
and then Is_Interface (Typ)
and then
((Nkind (Expr) = N_Selected_Component
and then Is_Tag (Entity (Selector_Name (Expr))))
or else
(Nkind (Expr) = N_Function_Call
and then RTE_Available (RE_Displace)
and then Entity (Name (Expr)) = RTE (RE_Displace))));
Anon_Type := Create_Itype (E_Anonymous_Access_Type, Expr);
Set_Directly_Designated_Type (Anon_Type, Typ);
Set_Etype (Anon_Type, Anon_Type);
Set_Can_Never_Be_Null (Anon_Type);
-- Decorate the size and alignment attributes of the anonymous access
-- type, as required by the back end.
Layout_Type (Anon_Type);
if Nkind (Expr) = N_Selected_Component
and then Is_Tag (Entity (Selector_Name (Expr)))
then
Result :=
Make_Explicit_Dereference (Loc,
Unchecked_Convert_To (Anon_Type,
Make_Attribute_Reference (Loc,
Prefix => Expr,
Attribute_Name => Name_Address)));
else
Result :=
Make_Explicit_Dereference (Loc,
Unchecked_Convert_To (Anon_Type, Expr));
end if;
return Result;
end Convert_Tag_To_Interface;
-------------------
-- CPP_Num_Prims --
-------------------
function CPP_Num_Prims (Typ : Entity_Id) return Nat is
CPP_Typ : Entity_Id;
Tag_Comp : Entity_Id;
begin
if not Is_Tagged_Type (Typ)
or else not Is_CPP_Class (Root_Type (Typ))
then
return 0;
else
CPP_Typ := Enclosing_CPP_Parent (Typ);
Tag_Comp := First_Tag_Component (CPP_Typ);
-- If number of primitives already set in the tag component, use it
if Present (Tag_Comp)
and then DT_Entry_Count (Tag_Comp) /= No_Uint
then
return UI_To_Int (DT_Entry_Count (Tag_Comp));
-- Otherwise, count the primitives of the enclosing CPP type
else
declare
Count : Nat := 0;
Elmt : Elmt_Id;
begin
Elmt := First_Elmt (Primitive_Operations (CPP_Typ));
while Present (Elmt) loop
Count := Count + 1;
Next_Elmt (Elmt);
end loop;
return Count;
end;
end if;
end if;
end CPP_Num_Prims;
------------------------------
-- Default_Prim_Op_Position --
------------------------------
function Default_Prim_Op_Position (E : Entity_Id) return Uint is
TSS_Name : TSS_Name_Type;
begin
Get_Name_String (Chars (E));
TSS_Name :=
TSS_Name_Type
(Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
if Chars (E) = Name_uSize then
return Uint_1;
elsif TSS_Name = TSS_Stream_Read then
return Uint_2;
elsif TSS_Name = TSS_Stream_Write then
return Uint_3;
elsif TSS_Name = TSS_Stream_Input then
return Uint_4;
elsif TSS_Name = TSS_Stream_Output then
return Uint_5;
elsif Chars (E) = Name_Op_Eq then
return Uint_6;
elsif Chars (E) = Name_uAssign then
return Uint_7;
elsif TSS_Name = TSS_Deep_Adjust then
return Uint_8;
elsif TSS_Name = TSS_Deep_Finalize then
return Uint_9;
elsif TSS_Name = TSS_Put_Image then
return Uint_10;
-- In VM targets unconditionally allow obtaining the position associated
-- with predefined interface primitives since in these platforms any
-- tagged type has these primitives.
elsif Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion then
if Chars (E) = Name_uDisp_Asynchronous_Select then
return Uint_11;
elsif Chars (E) = Name_uDisp_Conditional_Select then
return Uint_12;
elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
return Uint_13;
elsif Chars (E) = Name_uDisp_Get_Task_Id then
return Uint_14;
elsif Chars (E) = Name_uDisp_Requeue then
return Uint_15;
elsif Chars (E) = Name_uDisp_Timed_Select then
return Uint_16;
end if;
end if;
raise Program_Error;
end Default_Prim_Op_Position;
----------------------
-- Elab_Flag_Needed --
----------------------
function Elab_Flag_Needed (Typ : Entity_Id) return Boolean is
begin
return Ada_Version >= Ada_2005
and then not Is_Interface (Typ)
and then Has_Interfaces (Typ)
and then not Building_Static_DT (Typ);
end Elab_Flag_Needed;
-----------------------------
-- Expand_Dispatching_Call --
-----------------------------
procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
Loc : constant Source_Ptr := Sloc (Call_Node);
Call_Typ : constant Entity_Id := Etype (Call_Node);
Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
Param_List : constant List_Id := Parameter_Associations (Call_Node);
Subp : Entity_Id;
CW_Typ : Entity_Id;
New_Call : Node_Id;
New_Call_Name : Node_Id;
New_Params : List_Id := No_List;
Param : Node_Id;
Res_Typ : Entity_Id;
Subp_Ptr_Typ : Entity_Id;
Subp_Typ : Entity_Id;
Typ : Entity_Id;
Eq_Prim_Op : Entity_Id := Empty;
Controlling_Tag : Node_Id;
procedure Build_Class_Wide_Check;
-- If the denoted subprogram has a class-wide precondition, generate a
-- check using that precondition before the dispatching call, because
-- this is the only class-wide precondition that applies to the call.
function New_Value (From : Node_Id) return Node_Id;
-- From is the original Expression. New_Value is equivalent to a call
-- to Duplicate_Subexpr with an explicit dereference when From is an
-- access parameter.
----------------------------
-- Build_Class_Wide_Check --
----------------------------
procedure Build_Class_Wide_Check is
function Replace_Formals (N : Node_Id) return Traverse_Result;
-- Replace occurrences of the formals of the subprogram by the
-- corresponding actuals in the call, given that this check is
-- performed outside of the body of the subprogram.
-- If the dispatching call appears in the same scope as the
-- declaration of the dispatching subprogram (for example in
-- the expression of a local expression function), the spec
-- has not been analyzed yet, in which case we use the Chars
-- field to recognize intended occurrences of the formals.
---------------------
-- Replace_Formals --
---------------------
function Replace_Formals (N : Node_Id) return Traverse_Result is
A : Node_Id;
F : Entity_Id;
begin
if Is_Entity_Name (N) then
F := First_Formal (Subp);
A := First_Actual (Call_Node);
if Present (Entity (N)) and then Is_Formal (Entity (N)) then
while Present (F) loop
if F = Entity (N) then
Rewrite (N, New_Copy_Tree (A));
-- If the formal is class-wide, and thus not a
-- controlling argument, preserve its type because
-- it may appear in a nested call with a class-wide
-- parameter.
if Is_Class_Wide_Type (Etype (F)) then
Set_Etype (N, Etype (F));
-- Conversely, if this is a controlling argument
-- (in a dispatching call in the condition) that is a
-- dereference, the source is an access-to-class-wide
-- type, so preserve the dispatching nature of the
-- call in the rewritten condition.
elsif Nkind (Parent (N)) = N_Explicit_Dereference
and then Is_Controlling_Actual (Parent (N))
then
Set_Controlling_Argument (Parent (Parent (N)),
Parent (N));
end if;
exit;
end if;
Next_Formal (F);
Next_Actual (A);
end loop;
-- If the node is not analyzed, recognize occurrences of a
-- formal by name, as would be done when resolving the aspect
-- expression in the context of the subprogram.
elsif not Analyzed (N)
and then Nkind (N) = N_Identifier
and then No (Entity (N))
then
while Present (F) loop
if Chars (N) = Chars (F) then
Rewrite (N, New_Copy_Tree (A));
return Skip;
end if;
Next_Formal (F);
Next_Actual (A);
end loop;
end if;
end if;
return OK;
end Replace_Formals;
procedure Update is new Traverse_Proc (Replace_Formals);
-- Local variables
Str_Loc : constant String := Build_Location_String (Loc);
Cond : Node_Id;
Msg : Node_Id;
Prec : Node_Id;
-- Start of processing for Build_Class_Wide_Check
begin
-- Locate class-wide precondition, if any
if Present (Contract (Subp))
and then Present (Pre_Post_Conditions (Contract (Subp)))
then
Prec := Pre_Post_Conditions (Contract (Subp));
while Present (Prec) loop
exit when Pragma_Name (Prec) = Name_Precondition
and then Class_Present (Prec);
Prec := Next_Pragma (Prec);
end loop;
if No (Prec) or else Is_Ignored (Prec) then
return;
end if;
-- The expression for the precondition is analyzed within the
-- generated pragma. The message text is the last parameter of
-- the generated pragma, indicating source of precondition.
Cond :=
New_Copy_Tree
(Expression (First (Pragma_Argument_Associations (Prec))));
Update (Cond);
-- Build message indicating the failed precondition and the
-- dispatching call that caused it.
Msg := Expression (Last (Pragma_Argument_Associations (Prec)));
Name_Len := 0;
Append (Global_Name_Buffer, Strval (Msg));
Append (Global_Name_Buffer, " in dispatching call at ");
Append (Global_Name_Buffer, Str_Loc);
Msg := Make_String_Literal (Loc, Name_Buffer (1 .. Name_Len));
Insert_Action (Call_Node,
Make_If_Statement (Loc,
Condition => Make_Op_Not (Loc, Cond),
Then_Statements => New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (Msg)))));
end if;
end Build_Class_Wide_Check;
---------------
-- New_Value --
---------------
function New_Value (From : Node_Id) return Node_Id is
Res : constant Node_Id := Duplicate_Subexpr (From);
begin
if Is_Access_Type (Etype (From)) then
return
Make_Explicit_Dereference (Sloc (From),
Prefix => Res);
else
return Res;
end if;
end New_Value;
-- Local variables
New_Node : Node_Id;
SCIL_Node : Node_Id := Empty;
SCIL_Related_Node : Node_Id := Call_Node;
-- Start of processing for Expand_Dispatching_Call
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("tagged types", Call_Node);
return;
end if;
-- Expand_Dispatching_Call is called directly from the semantics, so we
-- only proceed if the expander is active.
if not Expander_Active
-- And there is no need to expand the call if we are compiling under
-- restriction No_Dispatching_Calls; the semantic analyzer has
-- previously notified the violation of this restriction.
or else Restriction_Active (No_Dispatching_Calls)
-- No action needed if the dispatching call has been already expanded
or else Is_Expanded_Dispatching_Call (Name (Call_Node))
then
return;
end if;
-- Set subprogram. If this is an inherited operation that was
-- overridden, the body that is being called is its alias.
Subp := Entity (Name (Call_Node));
if Present (Alias (Subp))
and then Is_Inherited_Operation (Subp)
and then No (DTC_Entity (Subp))
then
Subp := Alias (Subp);
end if;
Build_Class_Wide_Check;
-- Definition of the class-wide type and the tagged type
-- If the controlling argument is itself a tag rather than a tagged
-- object, then use the class-wide type associated with the subprogram's
-- controlling type. This case can occur when a call to an inherited
-- primitive has an actual that originated from a default parameter
-- given by a tag-indeterminate call and when there is no other
-- controlling argument providing the tag (AI-239 requires dispatching).
-- This capability of dispatching directly by tag is also needed by the
-- implementation of AI-260 (for the generic dispatching constructors).
if Ctrl_Typ = RTE (RE_Tag)
or else (RTE_Available (RE_Interface_Tag)
and then Ctrl_Typ = RTE (RE_Interface_Tag))
then
CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
-- Class_Wide_Type is applied to the expressions used to initialize
-- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
-- there are cases where the controlling type is resolved to a specific
-- type (such as for designated types of arguments such as CW'Access).
elsif Is_Access_Type (Ctrl_Typ) then
CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
else
CW_Typ := Class_Wide_Type (Ctrl_Typ);
end if;
Typ := Find_Specific_Type (CW_Typ);
if not Is_Limited_Type (Typ) then
Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
end if;
-- Dispatching call to C++ primitive. Create a new parameter list
-- with no tag checks.
New_Params := New_List;
if Is_CPP_Class (Typ) then
Param := First_Actual (Call_Node);
while Present (Param) loop
Append_To (New_Params, Relocate_Node (Param));
Next_Actual (Param);
end loop;
-- Dispatching call to Ada primitive
elsif Present (Param_List) then
Apply_Tag_Checks (Call_Node);
Param := First_Actual (Call_Node);
while Present (Param) loop
-- Cases in which we may have generated run-time checks. Note that
-- we strip any qualification from Param before comparing with the
-- already-stripped controlling argument.
if Unqualify (Param) = Ctrl_Arg or else Subp = Eq_Prim_Op then
Append_To (New_Params,
Duplicate_Subexpr_Move_Checks (Param));
elsif Nkind (Parent (Param)) /= N_Parameter_Association
or else not Is_Accessibility_Actual (Parent (Param))
then
Append_To (New_Params, Relocate_Node (Param));
end if;
Next_Actual (Param);
end loop;
end if;
-- Generate the appropriate subprogram pointer type
if Etype (Subp) = Typ then
Res_Typ := CW_Typ;
else
Res_Typ := Etype (Subp);
end if;
Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
Set_Etype (Subp_Typ, Res_Typ);
Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
Set_Convention (Subp_Typ, Convention (Subp));
-- Notify gigi that the designated type is a dispatching primitive
Set_Is_Dispatch_Table_Entity (Subp_Typ);
-- Create a new list of parameters which is a copy of the old formal
-- list including the creation of a new set of matching entities.
declare
Old_Formal : Entity_Id := First_Formal (Subp);
New_Formal : Entity_Id;
Last_Formal : Entity_Id := Empty;
begin
if Present (Old_Formal) then
New_Formal := New_Copy (Old_Formal);
Set_First_Entity (Subp_Typ, New_Formal);
Param := First_Actual (Call_Node);
loop
Set_Scope (New_Formal, Subp_Typ);
-- Change all the controlling argument types to be class-wide
-- to avoid a recursion in dispatching.
if Is_Controlling_Formal (New_Formal) then
Set_Etype (New_Formal, Etype (Param));
end if;
-- If the type of the formal is an itype, there was code here
-- introduced in 1998 in revision 1.46, to create a new itype
-- by copy. This seems useless, and in fact leads to semantic
-- errors when the itype is the completion of a type derived
-- from a private type.
Last_Formal := New_Formal;
Next_Formal (Old_Formal);
exit when No (Old_Formal);
Link_Entities (New_Formal, New_Copy (Old_Formal));
Next_Entity (New_Formal);
Next_Actual (Param);
end loop;
Unlink_Next_Entity (New_Formal);
Set_Last_Entity (Subp_Typ, Last_Formal);
end if;
-- Now that the explicit formals have been duplicated, any extra
-- formals needed by the subprogram must be duplicated; we know
-- that extra formals are available because they were added when
-- the tagged type was frozen (see Expand_Freeze_Record_Type).
pragma Assert (Is_Frozen (Typ));
-- Warning: The addition of the extra formals cannot be performed
-- here invoking Create_Extra_Formals since we must ensure that all
-- the extra formals of the pointer type and the target subprogram
-- match (and for functions that return a tagged type the profile of
-- the built subprogram type always returns a class-wide type, which
-- may affect the addition of some extra formals).
if Present (Last_Formal)
and then Present (Extra_Formal (Last_Formal))
then
Old_Formal := Extra_Formal (Last_Formal);
New_Formal := New_Copy (Old_Formal);
Set_Scope (New_Formal, Subp_Typ);
Set_Extra_Formal (Last_Formal, New_Formal);
Set_Extra_Formals (Subp_Typ, New_Formal);
if Ekind (Subp) = E_Function
and then Present (Extra_Accessibility_Of_Result (Subp))
and then Extra_Accessibility_Of_Result (Subp) = Old_Formal
then
Set_Extra_Accessibility_Of_Result (Subp_Typ, New_Formal);
end if;
Old_Formal := Extra_Formal (Old_Formal);
while Present (Old_Formal) loop
Set_Extra_Formal (New_Formal, New_Copy (Old_Formal));
New_Formal := Extra_Formal (New_Formal);
Set_Scope (New_Formal, Subp_Typ);
if Ekind (Subp) = E_Function
and then Present (Extra_Accessibility_Of_Result (Subp))
and then Extra_Accessibility_Of_Result (Subp) = Old_Formal
then
Set_Extra_Accessibility_Of_Result (Subp_Typ, New_Formal);
end if;
Old_Formal := Extra_Formal (Old_Formal);
end loop;
end if;
end;
-- Complete description of pointer type, including size information, as
-- must be done with itypes to prevent order-of-elaboration anomalies
-- in gigi.
Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
Layout_Type (Subp_Ptr_Typ);
-- If the controlling argument is a value of type Ada.Tag or an abstract
-- interface class-wide type then use it directly. Otherwise, the tag
-- must be extracted from the controlling object.
if Ctrl_Typ = RTE (RE_Tag)
or else (RTE_Available (RE_Interface_Tag)
and then Ctrl_Typ = RTE (RE_Interface_Tag))
then
Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
-- Extract the tag from an unchecked type conversion. Done to avoid
-- the expansion of additional code just to obtain the value of such
-- tag because the current management of interface type conversions
-- generates in some cases this unchecked type conversion with the
-- tag of the object (see Expand_Interface_Conversion).
elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
and then
(Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
or else
(RTE_Available (RE_Interface_Tag)
and then
Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
then
Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
-- Ada 2005 (AI-251): Abstract interface class-wide type
elsif Is_Interface (Ctrl_Typ)
and then Is_Class_Wide_Type (Ctrl_Typ)
then
Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
elsif Is_Access_Type (Ctrl_Typ) then
Controlling_Tag :=
Make_Selected_Component (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Duplicate_Subexpr_Move_Checks (Ctrl_Arg)),
Selector_Name => New_Occurrence_Of (DTC_Entity (Subp), Loc));
else
Controlling_Tag :=
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
Selector_Name => New_Occurrence_Of (DTC_Entity (Subp), Loc));
end if;
-- Handle dispatching calls to predefined primitives
if Is_Predefined_Dispatching_Operation (Subp)
or else Is_Predefined_Dispatching_Alias (Subp)
then
Build_Get_Predefined_Prim_Op_Address (Loc,
Tag_Node => Controlling_Tag,
Position => DT_Position (Subp),
New_Node => New_Node);
-- Handle dispatching calls to user-defined primitives
else
Build_Get_Prim_Op_Address (Loc,
Typ => Underlying_Type (Find_Dispatching_Type (Subp)),
Tag_Node => Controlling_Tag,
Position => DT_Position (Subp),
New_Node => New_Node);
end if;
New_Call_Name :=
Unchecked_Convert_To (Subp_Ptr_Typ, New_Node);
-- Generate the SCIL node for this dispatching call. Done now because
-- attribute SCIL_Controlling_Tag must be set after the new call name
-- is built to reference the nodes that will see the SCIL backend
-- (because Build_Get_Prim_Op_Address generates an unchecked type
-- conversion which relocates the controlling tag node).
if Generate_SCIL then
SCIL_Node := Make_SCIL_Dispatching_Call (Sloc (Call_Node));
Set_SCIL_Entity (SCIL_Node, Typ);
Set_SCIL_Target_Prim (SCIL_Node, Subp);
-- Common case: the controlling tag is the tag of an object
-- (for example, obj.tag)
if Nkind (Controlling_Tag) = N_Selected_Component then
Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
-- Handle renaming of selected component
elsif Nkind (Controlling_Tag) = N_Identifier
and then Nkind (Parent (Entity (Controlling_Tag))) =
N_Object_Renaming_Declaration
and then Nkind (Name (Parent (Entity (Controlling_Tag)))) =
N_Selected_Component
then
Set_SCIL_Controlling_Tag (SCIL_Node,
Name (Parent (Entity (Controlling_Tag))));
-- If the controlling tag is an identifier, the SCIL node references
-- the corresponding object or parameter declaration
elsif Nkind (Controlling_Tag) = N_Identifier
and then Nkind (Parent (Entity (Controlling_Tag))) in
N_Object_Declaration | N_Parameter_Specification
then
Set_SCIL_Controlling_Tag (SCIL_Node,
Parent (Entity (Controlling_Tag)));
-- If the controlling tag is a dereference, the SCIL node references
-- the corresponding object or parameter declaration
elsif Nkind (Controlling_Tag) = N_Explicit_Dereference
and then Nkind (Prefix (Controlling_Tag)) = N_Identifier
and then Nkind (Parent (Entity (Prefix (Controlling_Tag)))) in
N_Object_Declaration | N_Parameter_Specification
then
Set_SCIL_Controlling_Tag (SCIL_Node,
Parent (Entity (Prefix (Controlling_Tag))));
-- For a direct reference of the tag of the type the SCIL node
-- references the internal object declaration containing the tag
-- of the type.
elsif Nkind (Controlling_Tag) = N_Attribute_Reference
and then Attribute_Name (Controlling_Tag) = Name_Tag
then
Set_SCIL_Controlling_Tag (SCIL_Node,
Parent
(Node
(First_Elmt
(Access_Disp_Table (Entity (Prefix (Controlling_Tag)))))));
-- Interfaces are not supported. For now we leave the SCIL node
-- decorated with the Controlling_Tag. More work needed here???
elsif Is_Interface (Etype (Controlling_Tag)) then
Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
else
pragma Assert (False);
null;
end if;
end if;
if Nkind (Call_Node) = N_Function_Call then
New_Call :=
Make_Function_Call (Loc,
Name => New_Call_Name,
Parameter_Associations => New_Params);
-- If this is a dispatching "=", we must first compare the tags so
-- we generate: x.tag = y.tag and then x = y
if Subp = Eq_Prim_Op then
Param := First_Actual (Call_Node);
New_Call :=
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix => New_Value (Param),
Selector_Name =>
New_Occurrence_Of (First_Tag_Component (Typ),
Loc)),
Right_Opnd =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Typ,
New_Value (Next_Actual (Param))),
Selector_Name =>
New_Occurrence_Of
(First_Tag_Component (Typ), Loc))),
Right_Opnd => New_Call);
SCIL_Related_Node := Right_Opnd (New_Call);
end if;
else
New_Call :=
Make_Procedure_Call_Statement (Loc,
Name => New_Call_Name,
Parameter_Associations => New_Params);
end if;
-- Register the dispatching call in the call graph nodes table
Register_CG_Node (Call_Node);
Rewrite (Call_Node, New_Call);
-- Associate the SCIL node of this dispatching call
if Generate_SCIL then
Set_SCIL_Node (SCIL_Related_Node, SCIL_Node);
end if;
-- Suppress all checks during the analysis of the expanded code to avoid
-- the generation of spurious warnings under ZFP run-time.
Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
end Expand_Dispatching_Call;
---------------------------------
-- Expand_Interface_Conversion --
---------------------------------
procedure Expand_Interface_Conversion (N : Node_Id) is
function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id;
-- Return the underlying record type of Typ
----------------------------
-- Underlying_Record_Type --
----------------------------
function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id is
E : Entity_Id := Typ;
begin
-- Handle access types
if Is_Access_Type (E) then
E := Directly_Designated_Type (E);
end if;
-- Handle class-wide types. This conversion can appear explicitly in
-- the source code. Example: I'Class (Obj)
if Is_Class_Wide_Type (E) then
E := Root_Type (E);
end if;
-- If the target type is a tagged synchronized type, the dispatch
-- table info is in the corresponding record type.
if Is_Concurrent_Type (E) then
E := Corresponding_Record_Type (E);
end if;
-- Handle private types
E := Underlying_Type (E);
-- Handle subtypes
return Base_Type (E);
end Underlying_Record_Type;
-- Local variables
Loc : constant Source_Ptr := Sloc (N);
Etyp : constant Entity_Id := Etype (N);
Operand : constant Node_Id := Expression (N);
Operand_Typ : Entity_Id := Etype (Operand);
Func : Node_Id;
Iface_Typ : constant Entity_Id := Underlying_Record_Type (Etype (N));
Iface_Tag : Entity_Id;
Is_Static : Boolean;
-- Start of processing for Expand_Interface_Conversion
begin
-- Freeze the entity associated with the target interface to have
-- available the attribute Access_Disp_Table.
Freeze_Before (N, Iface_Typ);
-- Ada 2005 (AI-345): Handle synchronized interface type derivations
if Is_Concurrent_Type (Operand_Typ) then
Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
end if;
-- No displacement of the pointer to the object needed when the type of
-- the operand is not an interface type and the interface is one of
-- its parent types (since they share the primary dispatch table).
declare
Opnd : Entity_Id := Operand_Typ;
begin
if Is_Access_Type (Opnd) then
Opnd := Designated_Type (Opnd);
end if;
Opnd := Underlying_Record_Type (Opnd);
if not Is_Interface (Opnd)
and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True)
then
return;
end if;
-- When the type of the operand and the target interface type match,
-- it is generally safe to skip generating code to displace the
-- pointer to the object to reference the secondary dispatch table
-- associated with the target interface type. The exception to this
-- general rule is when the underlying object of the type conversion
-- is an object built by means of a dispatching constructor (since in
-- such case the expansion of the constructor call is a direct call
-- to an object primitive, i.e. without thunks, and the expansion of
-- the constructor call adds an explicit conversion to the target
-- interface type to force the displacement of the pointer to the
-- object to reference the corresponding secondary dispatch table
-- (cf. Make_DT and Expand_Dispatching_Constructor_Call)).
-- At this stage we cannot identify whether the underlying object is
-- a BIP object and hence we cannot skip generating the code to try
-- displacing the pointer to the object. However, under configurable
-- runtime it is safe to skip generating code to displace the pointer
-- to the object, because generic dispatching constructors are not
-- supported.
if Opnd = Iface_Typ and then not RTE_Available (RE_Displace) then
return;
end if;
end;
-- Evaluate if we can statically displace the pointer to the object
declare
Opnd_Typ : constant Node_Id := Underlying_Record_Type (Operand_Typ);
begin
Is_Static :=
not Is_Interface (Opnd_Typ)
and then Interface_Present_In_Ancestor
(Typ => Opnd_Typ,
Iface => Iface_Typ)
and then (Etype (Opnd_Typ) = Opnd_Typ
or else not
Is_Variable_Size_Record (Etype (Opnd_Typ)));
end;
if not Tagged_Type_Expansion then
return;
-- A static conversion to an interface type that is not class-wide is
-- curious but legal if the interface operation is a null procedure.
-- If the operation is abstract it will be rejected later.
elsif Is_Static
and then Is_Interface (Etype (N))
and then not Is_Class_Wide_Type (Etype (N))
and then Comes_From_Source (N)
then
Rewrite (N, Unchecked_Convert_To (Etype (N), N));
Analyze (N);
return;
end if;
if not Is_Static then
-- Give error if configurable run-time and Displace not available
if not RTE_Available (RE_Displace) then
Error_Msg_CRT ("dynamic interface conversion", N);
return;
end if;
-- Handle conversion of access-to-class-wide interface types. Target
-- can be an access to an object or an access to another class-wide
-- interface (see -1- and -2- in the following example):
-- type Iface1_Ref is access all Iface1'Class;
-- type Iface2_Ref is access all Iface1'Class;
-- Acc1 : Iface1_Ref := new ...
-- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
-- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
if Is_Access_Type (Operand_Typ) then
Rewrite (N,
Unchecked_Convert_To (Etype (N),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Displace), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Address),
Relocate_Node (Expression (N))),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
Loc)))));
Analyze (N);
return;
end if;
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Displace), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Expression (N)),
Attribute_Name => Name_Address),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
Loc))));
Analyze (N);
-- If target is a class-wide interface, change the type of the data
-- returned by IW_Convert to indicate this is a dispatching call.
declare
New_Itype : Entity_Id;
begin
New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
Set_Etype (New_Itype, New_Itype);
Set_Directly_Designated_Type (New_Itype, Etyp);
Rewrite (N,
Make_Explicit_Dereference (Loc,
Prefix =>
Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
Analyze (N);
Freeze_Itype (New_Itype, N);
return;
end;
end if;
Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
pragma Assert (Present (Iface_Tag));
-- Keep separate access types to interfaces because one internal
-- function is used to handle the null value (see following comments)
if not Is_Access_Type (Etype (N)) then
-- Statically displace the pointer to the object to reference the
-- component containing the secondary dispatch table.
Rewrite (N,
Convert_Tag_To_Interface (Class_Wide_Type (Iface_Typ),
Make_Selected_Component (Loc,
Prefix => Relocate_Node (Expression (N)),
Selector_Name => New_Occurrence_Of (Iface_Tag, Loc))));
else
-- Build internal function to handle the case in which the actual is
-- null. If the actual is null returns null because no displacement
-- is required; otherwise performs a type conversion that will be
-- expanded in the code that returns the value of the displaced
-- actual. That is:
-- function Func (O : Address) return Iface_Typ is
-- type Op_Typ is access all Operand_Typ;
-- Aux : Op_Typ := To_Op_Typ (O);
-- begin
-- if O = Null_Address then
-- return null;
-- else
-- return Iface_Typ!(Aux.Iface_Tag'Address);
-- end if;
-- end Func;
declare
Desig_Typ : Entity_Id;
Fent : Entity_Id;
New_Typ_Decl : Node_Id;
Stats : List_Id;
begin
Desig_Typ := Etype (Expression (N));
if Is_Access_Type (Desig_Typ) then
Desig_Typ :=
Available_View (Directly_Designated_Type (Desig_Typ));
end if;
if Is_Concurrent_Type (Desig_Typ) then
Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
end if;
New_Typ_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'T'),
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Null_Exclusion_Present => False,
Constant_Present => False,
Subtype_Indication =>
New_Occurrence_Of (Desig_Typ, Loc)));
Stats := New_List (
Make_Simple_Return_Statement (Loc,
Unchecked_Convert_To (Etype (N),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To
(Defining_Identifier (New_Typ_Decl),
Make_Identifier (Loc, Name_uO)),
Selector_Name =>
New_Occurrence_Of (Iface_Tag, Loc)),
Attribute_Name => Name_Address))));
-- If the type is null-excluding, no need for the null branch.
-- Otherwise we need to check for it and return null.
if not Can_Never_Be_Null (Etype (N)) then
Stats := New_List (
Make_If_Statement (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => Make_Identifier (Loc, Name_uO),
Right_Opnd => New_Occurrence_Of
(RTE (RE_Null_Address), Loc)),
Then_Statements => New_List (
Make_Simple_Return_Statement (Loc, Make_Null (Loc))),
Else_Statements => Stats));
end if;
Fent := Make_Temporary (Loc, 'F');
Func :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Fent,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uO),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc))),
Result_Definition =>
New_Occurrence_Of (Etype (N), Loc)),
Declarations => New_List (New_Typ_Decl),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stats));
-- Place function body before the expression containing the
-- conversion. We suppress all checks because the body of the
-- internally generated function already takes care of the case
-- in which the actual is null; therefore there is no need to
-- double check that the pointer is not null when the program
-- executes the alternative that performs the type conversion).
Insert_Action (N, Func, Suppress => All_Checks);
if Is_Access_Type (Etype (Expression (N))) then
-- Generate: Func (Address!(Expression))
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Fent, Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Address),
Relocate_Node (Expression (N))))));
else
-- Generate: Func (Operand_Typ!(Expression)'Address)
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Fent, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Unchecked_Convert_To (Operand_Typ,
Relocate_Node (Expression (N))),
Attribute_Name => Name_Address))));
end if;
end;
end if;
Analyze (N);
end Expand_Interface_Conversion;
------------------------------
-- Expand_Interface_Actuals --
------------------------------
procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
Actual : Node_Id;
Actual_Dup : Node_Id;
Actual_Typ : Entity_Id;
Anon : Entity_Id;
Conversion : Node_Id;
Formal : Entity_Id;
Formal_Typ : Entity_Id;
Subp : Entity_Id;
Formal_DDT : Entity_Id := Empty; -- initialize to prevent warning
Actual_DDT : Entity_Id := Empty; -- initialize to prevent warning
begin
-- This subprogram is called directly from the semantics, so we need a
-- check to see whether expansion is active before proceeding.
if not Expander_Active then
return;
end if;
-- Call using access to subprogram with explicit dereference
if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
Subp := Etype (Name (Call_Node));
-- Call using selected component
elsif Nkind (Name (Call_Node)) = N_Selected_Component then
Subp := Entity (Selector_Name (Name (Call_Node)));
-- Call using direct name
else
Subp := Entity (Name (Call_Node));
end if;
-- Ada 2005 (AI-251): Look for interface type formals to force "this"
-- displacement
Formal := First_Formal (Subp);
Actual := First_Actual (Call_Node);
while Present (Formal) loop
Formal_Typ := Etype (Formal);
if Has_Non_Limited_View (Formal_Typ) then
Formal_Typ := Non_Limited_View (Formal_Typ);
end if;
if Ekind (Formal_Typ) = E_Record_Type_With_Private then
Formal_Typ := Full_View (Formal_Typ);
end if;
if Is_Access_Type (Formal_Typ) then
Formal_DDT := Directly_Designated_Type (Formal_Typ);
if Has_Non_Limited_View (Formal_DDT) then
Formal_DDT := Non_Limited_View (Formal_DDT);
end if;
end if;
Actual_Typ := Etype (Actual);
if Has_Non_Limited_View (Actual_Typ) then
Actual_Typ := Non_Limited_View (Actual_Typ);
end if;
if Is_Access_Type (Actual_Typ) then
Actual_DDT := Directly_Designated_Type (Actual_Typ);
if Has_Non_Limited_View (Actual_DDT) then
Actual_DDT := Non_Limited_View (Actual_DDT);
end if;
end if;
if Is_Interface (Formal_Typ)
and then Is_Class_Wide_Type (Formal_Typ)
then
-- No need to displace the pointer if the type of the actual
-- coincides with the type of the formal.
if Actual_Typ = Formal_Typ then
null;
-- No need to displace the pointer if the interface type is a
-- parent of the type of the actual because in this case the
-- interface primitives are located in the primary dispatch table.
elsif Is_Ancestor (Formal_Typ, Actual_Typ,
Use_Full_View => True)
then
null;
-- Implicit conversion to the class-wide formal type to force the
-- displacement of the pointer.
else
-- Normally, expansion of actuals for calls to build-in-place
-- functions happens as part of Expand_Actuals, but in this
-- case the call will be wrapped in a conversion and soon after
-- expanded further to handle the displacement for a class-wide
-- interface conversion, so if this is a BIP call then we need
-- to handle it now.
if Is_Build_In_Place_Function_Call (Actual) then
Make_Build_In_Place_Call_In_Anonymous_Context (Actual);
end if;
Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
Rewrite (Actual, Conversion);
Analyze_And_Resolve (Actual, Formal_Typ);
end if;
-- Access to class-wide interface type
elsif Is_Access_Type (Formal_Typ)
and then Is_Interface (Formal_DDT)
and then Is_Class_Wide_Type (Formal_DDT)
and then Interface_Present_In_Ancestor
(Typ => Actual_DDT,
Iface => Etype (Formal_DDT))
then
-- Handle attributes 'Access and 'Unchecked_Access
if Nkind (Actual) = N_Attribute_Reference
and then
(Attribute_Name (Actual) = Name_Access
or else Attribute_Name (Actual) = Name_Unchecked_Access)
then
-- This case must have been handled by the analysis and
-- expansion of 'Access. The only exception is when types
-- match and no further expansion is required.
pragma Assert (Base_Type (Etype (Prefix (Actual)))
= Base_Type (Formal_DDT));
null;
-- No need to displace the pointer if the type of the actual
-- coincides with the type of the formal.
elsif Actual_DDT = Formal_DDT then
null;
-- No need to displace the pointer if the interface type is
-- a parent of the type of the actual because in this case the
-- interface primitives are located in the primary dispatch table.
elsif Is_Ancestor (Formal_DDT, Actual_DDT,
Use_Full_View => True)
then
null;
else
Actual_Dup := Relocate_Node (Actual);
if From_Limited_With (Actual_Typ) then
-- If the type of the actual parameter comes from a limited
-- with_clause and the nonlimited view is already available,
-- we replace the anonymous access type by a duplicate
-- declaration whose designated type is the nonlimited view.
if Has_Non_Limited_View (Actual_DDT) then
Anon := New_Copy (Actual_Typ);
if Is_Itype (Anon) then
Set_Scope (Anon, Current_Scope);
end if;
Set_Directly_Designated_Type
(Anon, Non_Limited_View (Actual_DDT));
Set_Etype (Actual_Dup, Anon);
end if;
end if;
Conversion := Convert_To (Formal_Typ, Actual_Dup);
Rewrite (Actual, Conversion);
Analyze_And_Resolve (Actual, Formal_Typ);
end if;
end if;
Next_Actual (Actual);
Next_Formal (Formal);
end loop;
end Expand_Interface_Actuals;
----------------------------
-- Expand_Interface_Thunk --
----------------------------
procedure Expand_Interface_Thunk
(Prim : Node_Id;
Thunk_Id : out Entity_Id;
Thunk_Code : out Node_Id;
Iface : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Prim);
Actuals : constant List_Id := New_List;
Decl : constant List_Id := New_List;
Formals : constant List_Id := New_List;
Target : constant Entity_Id := Ultimate_Alias (Prim);
Decl_1 : Node_Id;
Decl_2 : Node_Id;
Expr : Node_Id;
Formal : Node_Id;
Ftyp : Entity_Id;
Iface_Formal : Node_Id := Empty; -- initialize to prevent warning
Is_Predef_Op : constant Boolean :=
Is_Predefined_Dispatching_Operation (Prim)
or else Is_Predefined_Dispatching_Operation (Target);
New_Arg : Node_Id;
Offset_To_Top : Node_Id;
Target_Formal : Entity_Id;
begin
Thunk_Id := Empty;
Thunk_Code := Empty;
-- No thunk needed if the primitive has been eliminated
if Is_Eliminated (Target) then
return;
-- In case of primitives that are functions without formals and a
-- controlling result there is no need to build the thunk.
elsif not Present (First_Formal (Target)) then
pragma Assert (Ekind (Target) = E_Function
and then Has_Controlling_Result (Target));
return;
end if;
-- Duplicate the formals of the Target primitive. In the thunk, the type
-- of the controlling formal is the covered interface type (instead of
-- the target tagged type). Done to avoid problems with discriminated
-- tagged types because, if the controlling type has discriminants with
-- default values, then the type conversions done inside the body of
-- the thunk (after the displacement of the pointer to the base of the
-- actual object) generate code that modify its contents.
-- Note: This special management is not done for predefined primitives
-- because they don't have available the Interface_Alias attribute (see
-- Sem_Ch3.Add_Internal_Interface_Entities).
if not Is_Predef_Op then
Iface_Formal := First_Formal (Interface_Alias (Prim));
end if;
Formal := First_Formal (Target);
while Present (Formal) loop
Ftyp := Etype (Formal);
-- Use the interface type as the type of the controlling formal (see
-- comment above).
if not Is_Controlling_Formal (Formal) then
Ftyp := Etype (Formal);
Expr := New_Copy_Tree (Expression (Parent (Formal)));
-- For predefined primitives the controlling type of the thunk is
-- the interface type passed by the caller (since they don't have
-- available the Interface_Alias attribute; see comment above).
elsif Is_Predef_Op then
Ftyp := Iface;
Expr := Empty;
else
Ftyp := Etype (Iface_Formal);
Expr := Empty;
-- Sanity check performed to ensure the proper controlling type
-- when the thunk has exactly one controlling parameter and it
-- comes first. In such case the GCC backend reuses the C++
-- thunks machinery which perform a computation equivalent to
-- the code generated by the expander; for other cases the GCC
-- backend translates the expanded code unmodified. However, as
-- a generalization, the check is performed for all controlling
-- types.
if Is_Access_Type (Ftyp) then
pragma Assert (Base_Type (Designated_Type (Ftyp)) = Iface);
null;
else
Ftyp := Base_Type (Ftyp);
pragma Assert (Ftyp = Iface);
end if;
end if;
Append_To (Formals,
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Sloc (Formal),
Chars => Chars (Formal)),
In_Present => In_Present (Parent (Formal)),
Out_Present => Out_Present (Parent (Formal)),
Parameter_Type => New_Occurrence_Of (Ftyp, Loc),
Expression => Expr));
if not Is_Predef_Op then
Next_Formal (Iface_Formal);
end if;
Next_Formal (Formal);
end loop;
Target_Formal := First_Formal (Target);
Formal := First (Formals);
while Present (Formal) loop
-- If the parent is a constrained discriminated type, then the
-- primitive operation will have been defined on a first subtype.
-- For proper matching with controlling type, use base type.
if Ekind (Target_Formal) = E_In_Parameter
and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
then
Ftyp :=
Base_Type (Directly_Designated_Type (Etype (Target_Formal)));
else
Ftyp := Base_Type (Etype (Target_Formal));
end if;
-- For concurrent types, the relevant information is found in the
-- Corresponding_Record_Type, rather than the type entity itself.
if Is_Concurrent_Type (Ftyp) then
Ftyp := Corresponding_Record_Type (Ftyp);
end if;
if Ekind (Target_Formal) = E_In_Parameter
and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
and then Is_Controlling_Formal (Target_Formal)
then
-- Generate:
-- type T is access all <<type of the target formal>>
-- S : Storage_Offset := Storage_Offset!(Formal)
-- + Offset_To_Top (address!(Formal))
Decl_2 :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'T'),
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Null_Exclusion_Present => False,
Constant_Present => False,
Subtype_Indication =>
New_Occurrence_Of (Ftyp, Loc)));
New_Arg :=
Unchecked_Convert_To (RTE (RE_Address),
New_Occurrence_Of (Defining_Identifier (Formal), Loc));
if not RTE_Available (RE_Offset_To_Top) then
Offset_To_Top :=
Build_Offset_To_Top (Loc, New_Arg);
else
Offset_To_Top :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Offset_To_Top), Loc),
Parameter_Associations => New_List (New_Arg));
end if;
Decl_1 :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd =>
Unchecked_Convert_To
(RTE (RE_Storage_Offset),
New_Occurrence_Of
(Defining_Identifier (Formal), Loc)),
Right_Opnd =>
Offset_To_Top));
Append_To (Decl, Decl_2);
Append_To (Decl, Decl_1);
-- Reference the new actual. Generate:
-- T!(S)
Append_To (Actuals,
Unchecked_Convert_To
(Defining_Identifier (Decl_2),
New_Occurrence_Of (Defining_Identifier (Decl_1), Loc)));
elsif Is_Controlling_Formal (Target_Formal) then
-- Generate:
-- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
-- + Offset_To_Top (Formal'Address)
-- S2 : Addr_Ptr := Addr_Ptr!(S1)
New_Arg :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Defining_Identifier (Formal), Loc),
Attribute_Name =>
Name_Address);
if not RTE_Available (RE_Offset_To_Top) then
Offset_To_Top :=
Build_Offset_To_Top (Loc, New_Arg);
else
Offset_To_Top :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Offset_To_Top), Loc),
Parameter_Associations => New_List (New_Arg));
end if;
Decl_1 :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd =>
Unchecked_Convert_To
(RTE (RE_Storage_Offset),
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Defining_Identifier (Formal), Loc),
Attribute_Name => Name_Address)),
Right_Opnd =>
Offset_To_Top));
Decl_2 :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Addr_Ptr), Loc),
Expression =>
Unchecked_Convert_To
(RTE (RE_Addr_Ptr),
New_Occurrence_Of (Defining_Identifier (Decl_1), Loc)));
Append_To (Decl, Decl_1);
Append_To (Decl, Decl_2);
-- Reference the new actual, generate:
-- Target_Formal (S2.all)
Append_To (Actuals,
Unchecked_Convert_To (Ftyp,
Make_Explicit_Dereference (Loc,
New_Occurrence_Of (Defining_Identifier (Decl_2), Loc))));
-- Ensure proper matching of access types. Required to avoid
-- reporting spurious errors.
elsif Is_Access_Type (Etype (Target_Formal)) then
Append_To (Actuals,
Unchecked_Convert_To (Base_Type (Etype (Target_Formal)),
New_Occurrence_Of (Defining_Identifier (Formal), Loc)));
-- No special management required for this actual
else
Append_To (Actuals,
New_Occurrence_Of (Defining_Identifier (Formal), Loc));
end if;
Next_Formal (Target_Formal);
Next (Formal);
end loop;
Thunk_Id := Make_Temporary (Loc, 'T');
-- Note: any change to this symbol name needs to be coordinated
-- with GNATcoverage, as that tool relies on it to identify
-- thunks and exclude them from source coverage analysis.
Set_Ekind (Thunk_Id, Ekind (Prim));
Set_Is_Thunk (Thunk_Id);
Set_Convention (Thunk_Id, Convention (Prim));
Set_Needs_Debug_Info (Thunk_Id, Needs_Debug_Info (Target));
Set_Thunk_Entity (Thunk_Id, Target);
-- Procedure case
if Ekind (Target) = E_Procedure then
Thunk_Code :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Thunk_Id,
Parameter_Specifications => Formals),
Declarations => Decl,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Target, Loc),
Parameter_Associations => Actuals))));
-- Function case
else pragma Assert (Ekind (Target) = E_Function);
declare
Result_Def : Node_Id;
Call_Node : Node_Id;
begin
Call_Node :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Target, Loc),
Parameter_Associations => Actuals);
if not Is_Interface (Etype (Prim)) then
Result_Def := New_Copy (Result_Definition (Parent (Target)));
-- Thunk of function returning a class-wide interface object. No
-- extra displacement needed since the displacement is generated
-- in the return statement of Prim. Example:
-- type Iface is interface ...
-- function F (O : Iface) return Iface'Class;
-- type T is new ... and Iface with ...
-- function F (O : T) return Iface'Class;
elsif Is_Class_Wide_Type (Etype (Prim)) then
Result_Def := New_Occurrence_Of (Etype (Prim), Loc);
-- Thunk of function returning an interface object. Displacement
-- needed. Example:
-- type Iface is interface ...
-- function F (O : Iface) return Iface;
-- type T is new ... and Iface with ...
-- function F (O : T) return T;
else
Result_Def :=
New_Occurrence_Of (Class_Wide_Type (Etype (Prim)), Loc);
-- Adding implicit conversion to force the displacement of
-- the pointer to the object to reference the corresponding
-- secondary dispatch table.
Call_Node :=
Make_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of (Class_Wide_Type (Etype (Prim)), Loc),
Expression => Relocate_Node (Call_Node));
end if;
Thunk_Code :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Thunk_Id,
Parameter_Specifications => Formals,
Result_Definition => Result_Def),
Declarations => Decl,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc, Call_Node))));
end;
end if;
end Expand_Interface_Thunk;
--------------------------
-- Has_CPP_Constructors --
--------------------------
function Has_CPP_Constructors (Typ : Entity_Id) return Boolean is
E : Entity_Id;
begin
-- Look for the constructor entities
E := Next_Entity (Typ);
while Present (E) loop
if Ekind (E) = E_Function and then Is_Constructor (E) then
return True;
end if;
Next_Entity (E);
end loop;
return False;
end Has_CPP_Constructors;
------------
-- Has_DT --
------------
function Has_DT (Typ : Entity_Id) return Boolean is
begin
return not Is_Interface (Typ)
and then not Restriction_Active (No_Dispatching_Calls);
end Has_DT;
----------------------------------
-- Is_Expanded_Dispatching_Call --
----------------------------------
function Is_Expanded_Dispatching_Call (N : Node_Id) return Boolean is
begin
return Nkind (N) in N_Subprogram_Call
and then Nkind (Name (N)) = N_Explicit_Dereference
and then Is_Dispatch_Table_Entity (Etype (Name (N)));
end Is_Expanded_Dispatching_Call;
-------------------------------------
-- Is_Predefined_Dispatching_Alias --
-------------------------------------
function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
is
begin
return not Is_Predefined_Dispatching_Operation (Prim)
and then Present (Alias (Prim))
and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim));
end Is_Predefined_Dispatching_Alias;
----------------------------------------
-- Make_Disp_Asynchronous_Select_Body --
----------------------------------------
-- For interface types, generate:
-- procedure _Disp_Asynchronous_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- B : out System.Storage_Elements.Dummy_Communication_Block;
-- F : out Boolean)
-- is
-- begin
-- F := False;
-- C := Ada.Tags.POK_Function;
-- end _Disp_Asynchronous_Select;
-- For protected types, generate:
-- procedure _Disp_Asynchronous_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- B : out System.Storage_Elements.Dummy_Communication_Block;
-- F : out Boolean)
-- is
-- I : Integer :=
-- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
-- Bnn : System.Tasking.Protected_Objects.Operations.
-- Communication_Block;
-- begin
-- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
-- (T._object'Access,
-- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
-- P,
-- System.Tasking.Asynchronous_Call,
-- Bnn);
-- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
-- end _Disp_Asynchronous_Select;
-- For task types, generate:
-- procedure _Disp_Asynchronous_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- B : out System.Storage_Elements.Dummy_Communication_Block;
-- F : out Boolean)
-- is
-- I : Integer :=
-- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
-- begin
-- System.Tasking.Rendezvous.Task_Entry_Call
-- (T._task_id,
-- System.Tasking.Task_Entry_Index (I),
-- P,
-- System.Tasking.Asynchronous_Call,
-- F);
-- end _Disp_Asynchronous_Select;
function Make_Disp_Asynchronous_Select_Body
(Typ : Entity_Id) return Node_Id
is
Com_Block : Entity_Id;
Conc_Typ : Entity_Id := Empty;
Decls : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (Typ);
Obj_Ref : Node_Id;
Stmts : constant List_Id := New_List;
Tag_Node : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- Null body is generated for interface types
if Is_Interface (Typ) then
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Asynchronous_Select_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)))));
end if;
if Is_Concurrent_Record_Type (Typ) then
Conc_Typ := Corresponding_Concurrent_Type (Typ);
-- Generate:
-- I : Integer :=
-- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
-- where I will be used to capture the entry index of the primitive
-- wrapper at position S.
if Tagged_Type_Expansion then
Tag_Node :=
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uI),
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
Parameter_Associations =>
New_List (Tag_Node, Make_Identifier (Loc, Name_uS)))));
if Ekind (Conc_Typ) = E_Protected_Type then
-- Generate:
-- Bnn : Communication_Block;
Com_Block := Make_Temporary (Loc, 'B');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Com_Block,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
-- Build T._object'Access for calls below
Obj_Ref :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uObject)));
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
-- Generate:
-- Protected_Entry_Call
-- (T._object'Access, -- Object
-- Protected_Entry_Index! (I), -- E
-- P, -- Uninterpreted_Data
-- Asynchronous_Call, -- Mode
-- Bnn); -- Communication_Block
-- where T is the protected object, I is the entry index, P
-- is the wrapped parameters and B is the name of the
-- communication block.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
Parameter_Associations =>
New_List (
Obj_Ref,
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
New_Occurrence_Of -- Asynchronous_Call
(RTE (RE_Asynchronous_Call), Loc),
New_Occurrence_Of -- comm block
(Com_Block, Loc))));
when others =>
raise Program_Error;
end case;
-- Generate:
-- B := Dummy_Communication_Block (Bnn);
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uB),
Expression =>
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Dummy_Communication_Block), Loc),
Expression => New_Occurrence_Of (Com_Block, Loc))));
-- Generate:
-- F := False;
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)));
else
pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
-- Generate:
-- Task_Entry_Call
-- (T._task_id, -- Acceptor
-- Task_Entry_Index! (I), -- E
-- P, -- Uninterpreted_Data
-- Asynchronous_Call, -- Mode
-- F); -- Rendezvous_Successful
-- where T is the task object, I is the entry index, P is the
-- wrapped parameters and F is the status flag.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
Parameter_Associations =>
New_List (
Make_Selected_Component (Loc, -- T._task_id
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
New_Occurrence_Of -- Asynchronous_Call
(RTE (RE_Asynchronous_Call), Loc),
Make_Identifier (Loc, Name_uF)))); -- status flag
end if;
else
-- Ensure that the statements list is non-empty
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)));
end if;
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Asynchronous_Select_Spec (Typ),
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts));
end Make_Disp_Asynchronous_Select_Body;
----------------------------------------
-- Make_Disp_Asynchronous_Select_Spec --
----------------------------------------
function Make_Disp_Asynchronous_Select_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
B_Id : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uB);
Def_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Name_uDisp_Asynchronous_Select);
Params : constant List_Id := New_List;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- T : in out Typ; -- Object parameter
-- S : Integer; -- Primitive operation slot
-- P : Address; -- Wrapped parameters
-- B : out Dummy_Communication_Block; -- Communication block dummy
-- F : out Boolean; -- Status flag
-- The B parameter may be left uninitialized
Set_Warnings_Off (B_Id);
Append_List_To (Params, New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
Parameter_Type => New_Occurrence_Of (Typ, Loc),
In_Present => True,
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => B_Id,
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Dummy_Communication_Block), Loc),
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
Out_Present => True)));
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => Params);
end Make_Disp_Asynchronous_Select_Spec;
---------------------------------------
-- Make_Disp_Conditional_Select_Body --
---------------------------------------
-- For interface types, generate:
-- procedure _Disp_Conditional_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- begin
-- F := False;
-- C := Ada.Tags.POK_Function;
-- end _Disp_Conditional_Select;
-- For protected types, generate:
-- procedure _Disp_Conditional_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- I : Integer;
-- Bnn : System.Tasking.Protected_Objects.Operations.
-- Communication_Block;
-- begin
-- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
-- if C = Ada.Tags.POK_Procedure
-- or else C = Ada.Tags.POK_Protected_Procedure
-- or else C = Ada.Tags.POK_Task_Procedure
-- then
-- F := True;
-- return;
-- end if;
-- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
-- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
-- (T.object'Access,
-- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
-- P,
-- System.Tasking.Conditional_Call,
-- Bnn);
-- F := not Cancelled (Bnn);
-- end _Disp_Conditional_Select;
-- For task types, generate:
-- procedure _Disp_Conditional_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- I : Integer;
-- begin
-- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
-- System.Tasking.Rendezvous.Task_Entry_Call
-- (T._task_id,
-- System.Tasking.Task_Entry_Index (I),
-- P,
-- System.Tasking.Conditional_Call,
-- F);
-- end _Disp_Conditional_Select;
function Make_Disp_Conditional_Select_Body
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Blk_Nam : Entity_Id;
Conc_Typ : Entity_Id := Empty;
Decls : constant List_Id := New_List;
Obj_Ref : Node_Id;
Stmts : constant List_Id := New_List;
Tag_Node : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- Null body is generated for interface types
if Is_Interface (Typ) then
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Conditional_Select_Spec (Typ),
Declarations => No_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)))));
end if;
if Is_Concurrent_Record_Type (Typ) then
Conc_Typ := Corresponding_Concurrent_Type (Typ);
-- Generate:
-- I : Integer;
-- where I will be used to capture the entry index of the primitive
-- wrapper at position S.
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc)));
-- Generate:
-- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure;
-- then
-- F := True;
-- return;
-- end if;
Build_Common_Dispatching_Select_Statements (Typ, Stmts);
-- Generate:
-- Bnn : Communication_Block;
-- where Bnn is the name of the communication block used in the
-- call to Protected_Entry_Call.
Blk_Nam := Make_Temporary (Loc, 'B');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Blk_Nam,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
-- Generate:
-- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
-- I is the entry index and S is the dispatch table slot
if Tagged_Type_Expansion then
Tag_Node :=
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uI),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
Parameter_Associations => New_List (
Tag_Node,
Make_Identifier (Loc, Name_uS)))));
if Ekind (Conc_Typ) = E_Protected_Type then
Obj_Ref := -- T._object'Access
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uObject)));
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
-- Generate:
-- Protected_Entry_Call
-- (T._object'Access, -- Object
-- Protected_Entry_Index! (I), -- E
-- P, -- Uninterpreted_Data
-- Conditional_Call, -- Mode
-- Bnn); -- Block
-- where T is the protected object, I is the entry index, P
-- are the wrapped parameters and Bnn is the name of the
-- communication block.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
Parameter_Associations => New_List (
Obj_Ref,
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
New_Occurrence_Of -- Conditional_Call
(RTE (RE_Conditional_Call), Loc),
New_Occurrence_Of -- Bnn
(Blk_Nam, Loc))));
when System_Tasking_Protected_Objects_Single_Entry =>
-- If we are compiling for a restricted run-time, the call
-- uses the simpler form.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Protected_Single_Entry_Call), Loc),
Parameter_Associations => New_List (
Obj_Ref,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uP),
Attribute_Name => Name_Address),
New_Occurrence_Of
(RTE (RE_Conditional_Call), Loc))));
when others =>
raise Program_Error;
end case;
-- Generate:
-- F := not Cancelled (Bnn);
-- where F is the success flag. The status of Cancelled is negated
-- in order to match the behavior of the version for task types.
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Cancelled), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Blk_Nam, Loc))))));
else
pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
-- Generate:
-- Task_Entry_Call
-- (T._task_id, -- Acceptor
-- Task_Entry_Index! (I), -- E
-- P, -- Uninterpreted_Data
-- Conditional_Call, -- Mode
-- F); -- Rendezvous_Successful
-- where T is the task object, I is the entry index, P are the
-- wrapped parameters and F is the status flag.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
Parameter_Associations => New_List (
Make_Selected_Component (Loc, -- T._task_id
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
New_Occurrence_Of -- Conditional_Call
(RTE (RE_Conditional_Call), Loc),
Make_Identifier (Loc, Name_uF)))); -- status flag
end if;
else
-- Initialize out parameters
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)));
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uC),
Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
end if;
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Conditional_Select_Spec (Typ),
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts));
end Make_Disp_Conditional_Select_Body;
---------------------------------------
-- Make_Disp_Conditional_Select_Spec --
---------------------------------------
function Make_Disp_Conditional_Select_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Def_Id : constant Node_Id :=
Make_Defining_Identifier (Loc,
Name_uDisp_Conditional_Select);
Params : constant List_Id := New_List;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- T : in out Typ; -- Object parameter
-- S : Integer; -- Primitive operation slot
-- P : Address; -- Wrapped parameters
-- C : out Prim_Op_Kind; -- Call kind
-- F : out Boolean; -- Status flag
Append_List_To (Params, New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
Parameter_Type => New_Occurrence_Of (Typ, Loc),
In_Present => True,
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
Out_Present => True)));
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => Params);
end Make_Disp_Conditional_Select_Spec;
-------------------------------------
-- Make_Disp_Get_Prim_Op_Kind_Body --
-------------------------------------
function Make_Disp_Get_Prim_Op_Kind_Body (Typ : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Typ);
Tag_Node : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
if Is_Interface (Typ) then
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (Make_Null_Statement (Loc))));
end if;
-- Generate:
-- C := get_prim_op_kind (tag! (<type>VP), S);
-- where C is the out parameter capturing the call kind and S is the
-- dispatch table slot number.
if Tagged_Type_Expansion then
Tag_Node :=
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
return
Make_Subprogram_Body (Loc,
Specification =>
Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uC),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Get_Prim_Op_Kind), Loc),
Parameter_Associations => New_List (
Tag_Node,
Make_Identifier (Loc, Name_uS)))))));
end Make_Disp_Get_Prim_Op_Kind_Body;
-------------------------------------
-- Make_Disp_Get_Prim_Op_Kind_Spec --
-------------------------------------
function Make_Disp_Get_Prim_Op_Kind_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Def_Id : constant Node_Id :=
Make_Defining_Identifier (Loc, Name_uDisp_Get_Prim_Op_Kind);
Params : constant List_Id := New_List;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- T : in out Typ; -- Object parameter
-- S : Integer; -- Primitive operation slot
-- C : out Prim_Op_Kind; -- Call kind
Append_List_To (Params, New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
Parameter_Type => New_Occurrence_Of (Typ, Loc),
In_Present => True,
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
Out_Present => True)));
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => Params);
end Make_Disp_Get_Prim_Op_Kind_Spec;
--------------------------------
-- Make_Disp_Get_Task_Id_Body --
--------------------------------
function Make_Disp_Get_Task_Id_Body
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Ret : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
if Is_Concurrent_Record_Type (Typ)
and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
then
-- Generate:
-- return To_Address (_T._task_id);
Ret :=
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (RTE (RE_Address), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
-- A null body is constructed for non-task types
else
-- Generate:
-- return Null_Address;
Ret :=
Make_Simple_Return_Statement (Loc,
Expression => New_Occurrence_Of (RTE (RE_Null_Address), Loc));
end if;
return
Make_Subprogram_Body (Loc,
Specification => Make_Disp_Get_Task_Id_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, New_List (Ret)));
end Make_Disp_Get_Task_Id_Body;
--------------------------------
-- Make_Disp_Get_Task_Id_Spec --
--------------------------------
function Make_Disp_Get_Task_Id_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
return
Make_Function_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
Parameter_Type => New_Occurrence_Of (Typ, Loc))),
Result_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc));
end Make_Disp_Get_Task_Id_Spec;
----------------------------
-- Make_Disp_Requeue_Body --
----------------------------
function Make_Disp_Requeue_Body
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Conc_Typ : Entity_Id := Empty;
Stmts : constant List_Id := New_List;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- Null body is generated for interface types and non-concurrent
-- tagged types.
if Is_Interface (Typ)
or else not Is_Concurrent_Record_Type (Typ)
then
return
Make_Subprogram_Body (Loc,
Specification => Make_Disp_Requeue_Spec (Typ),
Declarations => No_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (Make_Null_Statement (Loc))));
end if;
Conc_Typ := Corresponding_Concurrent_Type (Typ);
if Ekind (Conc_Typ) = E_Protected_Type then
-- Generate statements:
-- if F then
-- System.Tasking.Protected_Objects.Operations.
-- Requeue_Protected_Entry
-- (Protection_Entries_Access (P),
-- O._object'Unchecked_Access,
-- Protected_Entry_Index (I),
-- A);
-- else
-- System.Tasking.Protected_Objects.Operations.
-- Requeue_Task_To_Protected_Entry
-- (O._object'Unchecked_Access,
-- Protected_Entry_Index (I),
-- A);
-- end if;
if Restriction_Active (No_Entry_Queue) then
Append_To (Stmts, Make_Null_Statement (Loc));
else
Append_To (Stmts,
Make_If_Statement (Loc,
Condition => Make_Identifier (Loc, Name_uF),
Then_Statements =>
New_List (
-- Call to Requeue_Protected_Entry
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Requeue_Protected_Entry), Loc),
Parameter_Associations =>
New_List (
Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
Subtype_Mark =>
New_Occurrence_Of (
RTE (RE_Protection_Entries_Access), Loc),
Expression =>
Make_Identifier (Loc, Name_uP)),
Make_Attribute_Reference (Loc, -- O._object'Acc
Attribute_Name =>
Name_Unchecked_Access,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Name_uO),
Selector_Name =>
Make_Identifier (Loc, Name_uObject))),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uA)))), -- abort status
Else_Statements =>
New_List (
-- Call to Requeue_Task_To_Protected_Entry
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
Parameter_Associations =>
New_List (
Make_Attribute_Reference (Loc, -- O._object'Acc
Attribute_Name => Name_Unchecked_Access,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Name_uO),
Selector_Name =>
Make_Identifier (Loc, Name_uObject))),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uA)))))); -- abort status
end if;
else
pragma Assert (Is_Task_Type (Conc_Typ));
-- Generate:
-- if F then
-- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
-- (Protection_Entries_Access (P),
-- O._task_id,
-- Task_Entry_Index (I),
-- A);
-- else
-- System.Tasking.Rendezvous.Requeue_Task_Entry
-- (O._task_id,
-- Task_Entry_Index (I),
-- A);
-- end if;
Append_To (Stmts,
Make_If_Statement (Loc,
Condition => Make_Identifier (Loc, Name_uF),
Then_Statements => New_List (
-- Call to Requeue_Protected_To_Task_Entry
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
Parameter_Associations => New_List (
Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protection_Entries_Access), Loc),
Expression => Make_Identifier (Loc, Name_uP)),
Make_Selected_Component (Loc, -- O._task_id
Prefix => Make_Identifier (Loc, Name_uO),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uA)))), -- abort status
Else_Statements => New_List (
-- Call to Requeue_Task_Entry
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc),
Parameter_Associations => New_List (
Make_Selected_Component (Loc, -- O._task_id
Prefix => Make_Identifier (Loc, Name_uO),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uA)))))); -- abort status
end if;
-- Even though no declarations are needed in both cases, we allocate
-- a list for entities added by Freeze.
return
Make_Subprogram_Body (Loc,
Specification => Make_Disp_Requeue_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts));
end Make_Disp_Requeue_Body;
----------------------------
-- Make_Disp_Requeue_Spec --
----------------------------
function Make_Disp_Requeue_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- O : in out Typ; - Object parameter
-- F : Boolean; - Protected (True) / task (False) flag
-- P : Address; - Protection_Entries_Access value
-- I : Entry_Index - Index of entry call
-- A : Boolean - Abort flag
-- Note that the Protection_Entries_Access value is represented as a
-- System.Address in order to avoid dragging in the tasking runtime
-- when compiling sources without tasking constructs.
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc, -- O
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uO),
Parameter_Type =>
New_Occurrence_Of (Typ, Loc),
In_Present => True,
Out_Present => True),
Make_Parameter_Specification (Loc, -- F
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uF),
Parameter_Type =>
New_Occurrence_Of (Standard_Boolean, Loc)),
Make_Parameter_Specification (Loc, -- P
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uP),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc, -- I
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uI),
Parameter_Type =>
New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc, -- A
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uA),
Parameter_Type =>
New_Occurrence_Of (Standard_Boolean, Loc))));
end Make_Disp_Requeue_Spec;
---------------------------------
-- Make_Disp_Timed_Select_Body --
---------------------------------
-- For interface types, generate:
-- procedure _Disp_Timed_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- D : Duration;
-- M : Integer;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- begin
-- F := False;
-- C := Ada.Tags.POK_Function;
-- end _Disp_Timed_Select;
-- For protected types, generate:
-- procedure _Disp_Timed_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- D : Duration;
-- M : Integer;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- I : Integer;
-- begin
-- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
-- if C = Ada.Tags.POK_Procedure
-- or else C = Ada.Tags.POK_Protected_Procedure
-- or else C = Ada.Tags.POK_Task_Procedure
-- then
-- F := True;
-- return;
-- end if;
-- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
-- System.Tasking.Protected_Objects.Operations.
-- Timed_Protected_Entry_Call
-- (T._object'Access,
-- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
-- P,
-- D,
-- M,
-- F);
-- end _Disp_Timed_Select;
-- For task types, generate:
-- procedure _Disp_Timed_Select
-- (T : in out <Typ>;
-- S : Integer;
-- P : System.Address;
-- D : Duration;
-- M : Integer;
-- C : out Ada.Tags.Prim_Op_Kind;
-- F : out Boolean)
-- is
-- I : Integer;
-- begin
-- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
-- System.Tasking.Rendezvous.Timed_Task_Entry_Call
-- (T._task_id,
-- System.Tasking.Task_Entry_Index (I),
-- P,
-- D,
-- M,
-- F);
-- end _Disp_Time_Select;
function Make_Disp_Timed_Select_Body
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Conc_Typ : Entity_Id := Empty;
Decls : constant List_Id := New_List;
Obj_Ref : Node_Id;
Stmts : constant List_Id := New_List;
Tag_Node : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- Null body is generated for interface types
if Is_Interface (Typ) then
return
Make_Subprogram_Body (Loc,
Specification => Make_Disp_Timed_Select_Spec (Typ),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
New_List (
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)))));
end if;
if Is_Concurrent_Record_Type (Typ) then
Conc_Typ := Corresponding_Concurrent_Type (Typ);
-- Generate:
-- I : Integer;
-- where I will be used to capture the entry index of the primitive
-- wrapper at position S.
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc)));
-- Generate:
-- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure;
-- then
-- F := True;
-- return;
-- end if;
Build_Common_Dispatching_Select_Statements (Typ, Stmts);
-- Generate:
-- I := Get_Entry_Index (tag! (<type>VP), S);
-- I is the entry index and S is the dispatch table slot
if Tagged_Type_Expansion then
Tag_Node :=
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uI),
Expression =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
Parameter_Associations => New_List (
Tag_Node,
Make_Identifier (Loc, Name_uS)))));
-- Protected case
if Ekind (Conc_Typ) = E_Protected_Type then
-- Build T._object'Access
Obj_Ref :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uObject)));
-- Normal case, No_Entry_Queue restriction not active. In this
-- case we generate:
-- Timed_Protected_Entry_Call
-- (T._object'access,
-- Protected_Entry_Index! (I),
-- P, D, M, F);
-- where T is the protected object, I is the entry index, P are
-- the wrapped parameters, D is the delay amount, M is the delay
-- mode and F is the status flag.
-- Historically, there was also an implementation for single
-- entry protected types (in s-tposen). However, it was removed
-- by also testing for no No_Select_Statements restriction in
-- Exp_Utils.Corresponding_Runtime_Package. This simplified the
-- implementation of s-tposen.adb and provided consistency between
-- all versions of System.Tasking.Protected_Objects.Single_Entry
-- (s-tposen*.adb).
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Timed_Protected_Entry_Call), Loc),
Parameter_Associations => New_List (
Obj_Ref,
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
Make_Identifier (Loc, Name_uD), -- delay
Make_Identifier (Loc, Name_uM), -- delay mode
Make_Identifier (Loc, Name_uF)))); -- status flag
when others =>
raise Program_Error;
end case;
-- Task case
else
pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
-- Generate:
-- Timed_Task_Entry_Call (
-- T._task_id,
-- Task_Entry_Index! (I),
-- P,
-- D,
-- M,
-- F);
-- where T is the task object, I is the entry index, P are the
-- wrapped parameters, D is the delay amount, M is the delay
-- mode and F is the status flag.
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
Parameter_Associations => New_List (
Make_Selected_Component (Loc, -- T._task_id
Prefix => Make_Identifier (Loc, Name_uT),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
Make_Unchecked_Type_Conversion (Loc, -- entry index
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Make_Identifier (Loc, Name_uI)),
Make_Identifier (Loc, Name_uP), -- parameter block
Make_Identifier (Loc, Name_uD), -- delay
Make_Identifier (Loc, Name_uM), -- delay mode
Make_Identifier (Loc, Name_uF)))); -- status flag
end if;
else
-- Initialize out parameters
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uF),
Expression => New_Occurrence_Of (Standard_False, Loc)));
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Make_Identifier (Loc, Name_uC),
Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
end if;
return
Make_Subprogram_Body (Loc,
Specification => Make_Disp_Timed_Select_Spec (Typ),
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts));
end Make_Disp_Timed_Select_Body;
---------------------------------
-- Make_Disp_Timed_Select_Spec --
---------------------------------
function Make_Disp_Timed_Select_Spec
(Typ : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Typ);
Def_Id : constant Node_Id :=
Make_Defining_Identifier (Loc,
Name_uDisp_Timed_Select);
Params : constant List_Id := New_List;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- T : in out Typ; -- Object parameter
-- S : Integer; -- Primitive operation slot
-- P : Address; -- Wrapped parameters
-- D : Duration; -- Delay
-- M : Integer; -- Delay Mode
-- C : out Prim_Op_Kind; -- Call kind
-- F : out Boolean; -- Status flag
Append_List_To (Params, New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
Parameter_Type => New_Occurrence_Of (Typ, Loc),
In_Present => True,
Out_Present => True),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uD),
Parameter_Type => New_Occurrence_Of (Standard_Duration, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uM),
Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
Out_Present => True)));
Append_To (Params,
Make_Parameter_Specification (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
Out_Present => True));
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => Params);
end Make_Disp_Timed_Select_Spec;
-------------
-- Make_DT --
-------------
-- The frontend supports two models for expanding dispatch tables
-- associated with library-level defined tagged types: statically and
-- non-statically allocated dispatch tables. In the former case the object
-- containing the dispatch table is constant and it is initialized by means
-- of a positional aggregate. In the latter case, the object containing
-- the dispatch table is a variable which is initialized by means of
-- assignments.
-- In case of locally defined tagged types, the object containing the
-- object containing the dispatch table is always a variable (instead of a
-- constant). This is currently required to give support to late overriding
-- of primitives. For example:
-- procedure Example is
-- package Pkg is
-- type T1 is tagged null record;
-- procedure Prim (O : T1);
-- end Pkg;
-- type T2 is new Pkg.T1 with null record;
-- procedure Prim (X : T2) is -- late overriding
-- begin
-- ...
-- ...
-- end;
-- WARNING: This routine manages Ghost regions. Return statements must be
-- replaced by gotos which jump to the end of the routine and restore the
-- Ghost mode.
function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
Loc : constant Source_Ptr := Sloc (Typ);
Max_Predef_Prims : constant Int :=
UI_To_Int
(Intval
(Expression
(Parent (RTE (RE_Max_Predef_Prims)))));
DT_Decl : constant Elist_Id := New_Elmt_List;
DT_Aggr : constant Elist_Id := New_Elmt_List;
-- Entities marked with attribute Is_Dispatch_Table_Entity
Dummy_Object : Entity_Id := Empty;
-- Extra nonexistent object of type Typ internally used to compute the
-- offset to the components that reference secondary dispatch tables.
-- Used to compute the offset of components located at fixed position.
procedure Check_Premature_Freezing
(Subp : Entity_Id;
Tagged_Type : Entity_Id;
Typ : Entity_Id);
-- Verify that all untagged types in the profile of a subprogram are
-- frozen at the point the subprogram is frozen. This enforces the rule
-- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
-- is frozen, enough must be known about it to build the activation
-- record for it, which requires at least that the size of all
-- parameters be known. Controlling arguments are by-reference,
-- and therefore the rule only applies to untagged types. Typical
-- violation of the rule involves an object declaration that freezes a
-- tagged type, when one of its primitive operations has a type in its
-- profile whose full view has not been analyzed yet. More complex cases
-- involve composite types that have one private unfrozen subcomponent.
-- Move this check to sem???
procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
-- Export the dispatch table DT of tagged type Typ. Required to generate
-- forward references and statically allocate the table. For primary
-- dispatch tables Index is 0; for secondary dispatch tables the value
-- of index must match the Suffix_Index value assigned to the table by
-- Make_Tags when generating its unique external name, and it is used to
-- retrieve from the Dispatch_Table_Wrappers list associated with Typ
-- the external name generated by Import_DT.
procedure Make_Secondary_DT
(Typ : Entity_Id;
Iface : Entity_Id;
Iface_Comp : Node_Id;
Suffix_Index : Int;
Num_Iface_Prims : Nat;
Iface_DT_Ptr : Entity_Id;
Predef_Prims_Ptr : Entity_Id;
Build_Thunks : Boolean;
Result : List_Id);
-- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
-- Table of Typ associated with Iface. Each abstract interface of Typ
-- has two secondary dispatch tables: one containing pointers to thunks
-- and another containing pointers to the primitives covering the
-- interface primitives. The former secondary table is generated when
-- Build_Thunks is True, and provides common support for dispatching
-- calls through interface types; the latter secondary table is
-- generated when Build_Thunks is False, and provides support for
-- Generic Dispatching Constructors that dispatch calls through
-- interface types. When constructing this latter table the value of
-- Suffix_Index is -1 to indicate that there is no need to export such
-- table when building statically allocated dispatch tables; a positive
-- value of Suffix_Index must match the Suffix_Index value assigned to
-- this secondary dispatch table by Make_Tags when its unique external
-- name was generated.
function Number_Of_Predefined_Prims (Typ : Entity_Id) return Nat;
-- Returns the number of predefined primitives of Typ
------------------------------
-- Check_Premature_Freezing --
------------------------------
procedure Check_Premature_Freezing
(Subp : Entity_Id;
Tagged_Type : Entity_Id;
Typ : Entity_Id)
is
Comp : Entity_Id;
function Is_Actual_For_Formal_Incomplete_Type
(T : Entity_Id) return Boolean;
-- In Ada 2012, if a nested generic has an incomplete formal type,
-- the actual may be (and usually is) a private type whose completion
-- appears later. It is safe to build the dispatch table in this
-- case, gigi will have full views available.
------------------------------------------
-- Is_Actual_For_Formal_Incomplete_Type --
------------------------------------------
function Is_Actual_For_Formal_Incomplete_Type
(T : Entity_Id) return Boolean
is
Gen_Par : Entity_Id;
F : Node_Id;
begin
if not Is_Generic_Instance (Current_Scope)
or else not Used_As_Generic_Actual (T)
then
return False;
else
Gen_Par := Generic_Parent (Parent (Current_Scope));
end if;
F :=
First
(Generic_Formal_Declarations
(Unit_Declaration_Node (Gen_Par)));
while Present (F) loop
if Ekind (Defining_Identifier (F)) = E_Incomplete_Type then
return True;
end if;
Next (F);
end loop;
return False;
end Is_Actual_For_Formal_Incomplete_Type;
-- Start of processing for Check_Premature_Freezing
begin
-- Note that if the type is a (subtype of) a generic actual, the
-- actual will have been frozen by the instantiation.
if Present (N)
and then Is_Private_Type (Typ)
and then No (Full_View (Typ))
and then not Is_Generic_Type (Typ)
and then not Is_Tagged_Type (Typ)
and then not Is_Frozen (Typ)
and then not Is_Generic_Actual_Type (Typ)
then
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_NE
("declaration must appear after completion of type &", N, Typ);
Error_Msg_NE
("\which is an untagged type in the profile of "
& "primitive operation & declared#", N, Subp);
else
Comp := Private_Component (Typ);
if not Is_Tagged_Type (Typ)
and then Present (Comp)
and then not Is_Frozen (Comp)
and then not Is_Actual_For_Formal_Incomplete_Type (Comp)
then
Error_Msg_Sloc := Sloc (Subp);
Error_Msg_Node_2 := Subp;
Error_Msg_Name_1 := Chars (Tagged_Type);
Error_Msg_NE
("declaration must appear after completion of type &",
N, Comp);
Error_Msg_NE
("\which is a component of untagged type& in the profile "
& "of primitive & of type % that is frozen by the "
& "declaration ", N, Typ);
end if;
end if;
end Check_Premature_Freezing;
---------------
-- Export_DT --
---------------
procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
is
Count : Nat;
Elmt : Elmt_Id;
begin
Set_Is_Statically_Allocated (DT);
Set_Is_True_Constant (DT);
Set_Is_Exported (DT);
Count := 0;
Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
while Count /= Index loop
Next_Elmt (Elmt);
Count := Count + 1;
end loop;
pragma Assert (Related_Type (Node (Elmt)) = Typ);
Get_External_Name (Node (Elmt));
Set_Interface_Name (DT,
Make_String_Literal (Loc,
Strval => String_From_Name_Buffer));
-- Ensure proper Sprint output of this implicit importation
Set_Is_Internal (DT);
Set_Is_Public (DT);
end Export_DT;
-----------------------
-- Make_Secondary_DT --
-----------------------
procedure Make_Secondary_DT
(Typ : Entity_Id;
Iface : Entity_Id;
Iface_Comp : Node_Id;
Suffix_Index : Int;
Num_Iface_Prims : Nat;
Iface_DT_Ptr : Entity_Id;
Predef_Prims_Ptr : Entity_Id;
Build_Thunks : Boolean;
Result : List_Id)
is
Loc : constant Source_Ptr := Sloc (Typ);
Exporting_Table : constant Boolean :=
Building_Static_DT (Typ)
and then Suffix_Index > 0;
Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
DT_Constr_List : List_Id;
DT_Aggr_List : List_Id;
Empty_DT : Boolean := False;
Nb_Prim : Nat;
New_Node : Node_Id;
OSD : Entity_Id;
OSD_Aggr_List : List_Id;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
Prim_Ops_Aggr_List : List_Id;
begin
-- Handle cases in which we do not generate statically allocated
-- dispatch tables.
if not Building_Static_DT (Typ) then
Set_Ekind (Predef_Prims, E_Variable);
Set_Ekind (Iface_DT, E_Variable);
-- Statically allocated dispatch tables and related entities are
-- constants.
else
Set_Ekind (Predef_Prims, E_Constant);
Set_Is_Statically_Allocated (Predef_Prims);
Set_Is_True_Constant (Predef_Prims);
Set_Ekind (Iface_DT, E_Constant);
Set_Is_Statically_Allocated (Iface_DT);
Set_Is_True_Constant (Iface_DT);
end if;
-- Calculate the number of slots of the dispatch table. If the number
-- of primitives of Typ is 0 we reserve a dummy single entry for its
-- DT because at run time the pointer to this dummy entry will be
-- used as the tag.
if Num_Iface_Prims = 0 then
Empty_DT := True;
Nb_Prim := 1;
else
Nb_Prim := Num_Iface_Prims;
end if;
-- Generate:
-- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
-- (predef-prim-op-thunk-1'address,
-- predef-prim-op-thunk-2'address,
-- ...
-- predef-prim-op-thunk-n'address);
-- Create the thunks associated with the predefined primitives and
-- save their entity to fill the aggregate.
declare
Nb_P_Prims : constant Nat := Number_Of_Predefined_Prims (Typ);
Prim_Table : array (Nat range 1 .. Nb_P_Prims) of Entity_Id;
Decl : Node_Id;
Thunk_Id : Entity_Id;
Thunk_Code : Node_Id;
begin
Prim_Ops_Aggr_List := New_List;
Prim_Table := (others => Empty);
if Building_Static_DT (Typ) then
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Abstract_Subprogram (Prim)
and then not Is_Eliminated (Prim)
and then not Generate_SCIL
and then not Present (Prim_Table
(UI_To_Int (DT_Position (Prim))))
then
if not Build_Thunks then
Prim_Table (UI_To_Int (DT_Position (Prim))) :=
Alias (Prim);
else
Expand_Interface_Thunk
(Prim, Thunk_Id, Thunk_Code, Iface);
if Present (Thunk_Id) then
Append_To (Result, Thunk_Code);
Prim_Table (UI_To_Int (DT_Position (Prim))) :=
Thunk_Id;
end if;
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
end if;
for J in Prim_Table'Range loop
if Present (Prim_Table (J)) then
New_Node :=
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
Attribute_Name => Name_Unrestricted_Access));
else
New_Node := Make_Null (Loc);
end if;
Append_To (Prim_Ops_Aggr_List, New_Node);
end loop;
New_Node :=
Make_Aggregate (Loc, Expressions => Prim_Ops_Aggr_List);
-- Remember aggregates initializing dispatch tables
Append_Elmt (New_Node, DT_Aggr);
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Address_Array), Loc));
Append_To (Result, Decl);
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Predef_Prims,
Constant_Present => Building_Static_DT (Typ),
Aliased_Present => True,
Object_Definition => New_Occurrence_Of
(Defining_Identifier (Decl), Loc),
Expression => New_Node));
end;
-- Generate
-- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
-- (OSD_Table => (1 => <value>,
-- ...
-- N => <value>));
-- for OSD'Alignment use Address'Alignment;
-- Iface_DT : Dispatch_Table (Nb_Prims) :=
-- ([ Signature => <sig-value> ],
-- Tag_Kind => <tag_kind-value>,
-- Predef_Prims => Predef_Prims'Address,
-- Offset_To_Top => 0,
-- OSD => OSD'Address,
-- Prims_Ptr => (prim-op-1'address,
-- prim-op-2'address,
-- ...
-- prim-op-n'address));
-- Stage 3: Initialize the discriminant and the record components
DT_Constr_List := New_List;
DT_Aggr_List := New_List;
-- Nb_Prim
Append_To (DT_Constr_List, Make_Integer_Literal (Loc, Nb_Prim));
Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, Nb_Prim));
-- Signature
if RTE_Record_Component_Available (RE_Signature) then
Append_To (DT_Aggr_List,
New_Occurrence_Of (RTE (RE_Secondary_DT), Loc));
end if;
-- Tag_Kind
if RTE_Record_Component_Available (RE_Tag_Kind) then
Append_To (DT_Aggr_List, Tagged_Kind (Typ));
end if;
-- Predef_Prims
Append_To (DT_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Predef_Prims, Loc),
Attribute_Name => Name_Address));
-- Interface component located at variable offset; the value of
-- Offset_To_Top will be set by the init subprogram.
if No (Dummy_Object)
or else Is_Variable_Size_Record (Etype (Scope (Iface_Comp)))
then
Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
-- Interface component located at fixed offset
else
Append_To (DT_Aggr_List,
Make_Op_Minus (Loc,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Dummy_Object, Loc),
Selector_Name =>
New_Occurrence_Of (Iface_Comp, Loc)),
Attribute_Name => Name_Position)));
end if;
-- Generate the Object Specific Data table required to dispatch calls
-- through synchronized interfaces.
if Empty_DT
or else Is_Abstract_Type (Typ)
or else Is_Controlled (Typ)
or else Restriction_Active (No_Dispatching_Calls)
or else not Is_Limited_Type (Typ)
or else not Has_Interfaces (Typ)
or else not Build_Thunks
or else not RTE_Record_Component_Available (RE_OSD_Table)
then
-- No OSD table required
Append_To (DT_Aggr_List,
New_Occurrence_Of (RTE (RE_Null_Address), Loc));
else
OSD_Aggr_List := New_List;
declare
Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
Prim : Entity_Id;
Prim_Alias : Entity_Id;
Prim_Elmt : Elmt_Id;
E : Entity_Id;
Count : Nat := 0;
Pos : Nat;
begin
Prim_Table := (others => Empty);
Prim_Alias := Empty;
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if Present (Interface_Alias (Prim))
and then Find_Dispatching_Type
(Interface_Alias (Prim)) = Iface
then
Prim_Alias := Interface_Alias (Prim);
E := Ultimate_Alias (Prim);
Pos := UI_To_Int (DT_Position (Prim_Alias));
if Present (Prim_Table (Pos)) then
pragma Assert (Prim_Table (Pos) = E);
null;
else
Prim_Table (Pos) := E;
Append_To (OSD_Aggr_List,
Make_Component_Association (Loc,
Choices => New_List (
Make_Integer_Literal (Loc,
DT_Position (Prim_Alias))),
Expression =>
Make_Integer_Literal (Loc,
DT_Position (Alias (Prim)))));
Count := Count + 1;
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
pragma Assert (Count = Nb_Prim);
end;
OSD := Make_Temporary (Loc, 'I');
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => OSD,
Constant_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Object_Specific_Data), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Integer_Literal (Loc, Nb_Prim)))),
Expression =>
Make_Aggregate (Loc,
Component_Associations => New_List (
Make_Component_Association (Loc,
Choices => New_List (
New_Occurrence_Of
(RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
Expression =>
Make_Integer_Literal (Loc, Nb_Prim)),
Make_Component_Association (Loc,
Choices => New_List (
New_Occurrence_Of
(RTE_Record_Component (RE_OSD_Table), Loc)),
Expression => Make_Aggregate (Loc,
Component_Associations => OSD_Aggr_List))))));
Append_To (Result,
Make_Attribute_Definition_Clause (Loc,
Name => New_Occurrence_Of (OSD, Loc),
Chars => Name_Alignment,
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
Attribute_Name => Name_Alignment)));
-- In secondary dispatch tables the Typeinfo component contains
-- the address of the Object Specific Data (see a-tags.ads).
Append_To (DT_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (OSD, Loc),
Attribute_Name => Name_Address));
end if;
-- Initialize the table of primitive operations
Prim_Ops_Aggr_List := New_List;
if Empty_DT then
Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
elsif Is_Abstract_Type (Typ)
or else not Building_Static_DT (Typ)
then
for J in 1 .. Nb_Prim loop
Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
end loop;
else
declare
CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
E : Entity_Id;
Prim_Pos : Nat;
Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
Thunk_Code : Node_Id;
Thunk_Id : Entity_Id;
begin
Prim_Table := (others => Empty);
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
E := Ultimate_Alias (Prim);
Prim_Pos := UI_To_Int (DT_Position (E));
-- Do not reference predefined primitives because they are
-- located in a separate dispatch table; skip abstract and
-- eliminated primitives; skip primitives located in the C++
-- part of the dispatch table because their slot is set by
-- the IC routine.
if not Is_Predefined_Dispatching_Operation (Prim)
and then Present (Interface_Alias (Prim))
and then not Is_Abstract_Subprogram (Alias (Prim))
and then not Is_Eliminated (Alias (Prim))
and then (not Is_CPP_Class (Root_Type (Typ))
or else Prim_Pos > CPP_Nb_Prims)
and then Find_Dispatching_Type
(Interface_Alias (Prim)) = Iface
-- Generate the code of the thunk only if the abstract
-- interface type is not an immediate ancestor of
-- Tagged_Type. Otherwise the DT associated with the
-- interface is the primary DT.
and then not Is_Ancestor (Iface, Typ,
Use_Full_View => True)
then
if not Build_Thunks then
Prim_Pos :=
UI_To_Int (DT_Position (Interface_Alias (Prim)));
Prim_Table (Prim_Pos) := Alias (Prim);
else
Expand_Interface_Thunk
(Prim, Thunk_Id, Thunk_Code, Iface);
if Present (Thunk_Id) then
Prim_Pos :=
UI_To_Int (DT_Position (Interface_Alias (Prim)));
Prim_Table (Prim_Pos) := Thunk_Id;
Append_To (Result, Thunk_Code);
end if;
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
for J in Prim_Table'Range loop
if Present (Prim_Table (J)) then
New_Node :=
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
Attribute_Name => Name_Unrestricted_Access));
else
New_Node := Make_Null (Loc);
end if;
Append_To (Prim_Ops_Aggr_List, New_Node);
end loop;
end;
end if;
New_Node :=
Make_Aggregate (Loc,
Expressions => Prim_Ops_Aggr_List);
Append_To (DT_Aggr_List, New_Node);
-- Remember aggregates initializing dispatch tables
Append_Elmt (New_Node, DT_Aggr);
-- Note: Secondary dispatch tables are declared constant only if
-- we can compute their offset field by means of the extra dummy
-- object; otherwise they cannot be declared constant and the
-- Offset_To_Top component is initialized by the IP routine.
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Iface_DT,
Aliased_Present => True,
Constant_Present => Building_Static_Secondary_DT (Typ),
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of
(RTE (RE_Dispatch_Table_Wrapper), Loc),
Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => DT_Constr_List)),
Expression =>
Make_Aggregate (Loc,
Expressions => DT_Aggr_List)));
if Exporting_Table then
Export_DT (Typ, Iface_DT, Suffix_Index);
-- Generate code to create the pointer to the dispatch table
-- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
-- Note: This declaration is not added here if the table is exported
-- because in such case Make_Tags has already added this declaration.
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Iface_DT_Ptr,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Interface_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Interface_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Iface_DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Prims_Ptr), Loc)),
Attribute_Name => Name_Address))));
end if;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Predef_Prims_Ptr,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Iface_DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Predef_Prims), Loc)),
Attribute_Name => Name_Address)));
-- Remember entities containing dispatch tables
Append_Elmt (Predef_Prims, DT_Decl);
Append_Elmt (Iface_DT, DT_Decl);
end Make_Secondary_DT;
--------------------------------
-- Number_Of_Predefined_Prims --
--------------------------------
function Number_Of_Predefined_Prims (Typ : Entity_Id) return Nat is
Nb_Predef_Prims : Nat := 0;
begin
if not Generate_SCIL then
declare
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
Pos : Nat;
begin
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Abstract_Subprogram (Prim)
then
Pos := UI_To_Int (DT_Position (Prim));
if Pos > Nb_Predef_Prims then
Nb_Predef_Prims := Pos;
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
end;
end if;
pragma Assert (Nb_Predef_Prims <= Max_Predef_Prims);
return Nb_Predef_Prims;
end Number_Of_Predefined_Prims;
-- Local variables
Elab_Code : constant List_Id := New_List;
Result : constant List_Id := New_List;
Tname : constant Name_Id := Chars (Typ);
-- When pragmas Discard_Names and No_Tagged_Streams simultaneously apply
-- we initialize the Expanded_Name and the External_Tag of this tagged
-- type with an empty string. This is useful to avoid exposing entity
-- names at binary level. It can be done when both pragmas apply because
-- (1) Discard_Names allows initializing Expanded_Name with an
-- implementation defined value (Ada RM Section C.5 (7/2)).
-- (2) External_Tag (combined with Internal_Tag) is used for object
-- streaming and No_Tagged_Streams inhibits the generation of
-- streams.
Discard_Names : constant Boolean :=
Present (No_Tagged_Streams_Pragma (Typ))
and then (Global_Discard_Names
or else Einfo.Discard_Names (Typ));
-- The following name entries are used by Make_DT to generate a number
-- of entities related to a tagged type. These entities may be generated
-- in a scope other than that of the tagged type declaration, and if
-- the entities for two tagged types with the same name happen to be
-- generated in the same scope, we have to take care to use different
-- names. This is achieved by means of a unique serial number appended
-- to each generated entity name.
Name_DT : constant Name_Id :=
New_External_Name (Tname, 'T', Suffix_Index => -1);
Name_Exname : constant Name_Id :=
New_External_Name (Tname, 'E', Suffix_Index => -1);
Name_HT_Link : constant Name_Id :=
New_External_Name (Tname, 'H', Suffix_Index => -1);
Name_Predef_Prims : constant Name_Id :=
New_External_Name (Tname, 'R', Suffix_Index => -1);
Name_SSD : constant Name_Id :=
New_External_Name (Tname, 'S', Suffix_Index => -1);
Name_TSD : constant Name_Id :=
New_External_Name (Tname, 'B', Suffix_Index => -1);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
-- Save the Ghost-related attributes to restore on exit
AI : Elmt_Id;
AI_Tag_Elmt : Elmt_Id;
AI_Tag_Comp : Elmt_Id;
DT : Entity_Id;
DT_Aggr_List : List_Id;
DT_Constr_List : List_Id;
DT_Ptr : Entity_Id;
Exname : Entity_Id;
HT_Link : Entity_Id;
ITable : Node_Id;
I_Depth : Nat := 0;
Iface_Table_Node : Node_Id;
Name_ITable : Name_Id;
Nb_Prim : Nat := 0;
New_Node : Node_Id;
Num_Ifaces : Nat := 0;
Parent_Typ : Entity_Id;
Predef_Prims : Entity_Id;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
Prim_Ops_Aggr_List : List_Id;
SSD : Entity_Id;
Suffix_Index : Int;
Typ_Comps : Elist_Id;
Typ_Ifaces : Elist_Id;
TSD : Entity_Id;
TSD_Aggr_List : List_Id;
TSD_Tags_List : List_Id;
-- Start of processing for Make_DT
begin
pragma Assert (Is_Frozen (Typ));
-- The tagged type being processed may be subject to pragma Ghost. Set
-- the mode now to ensure that any nodes generated during dispatch table
-- creation are properly marked as Ghost.
Set_Ghost_Mode (Typ);
-- Handle cases in which there is no need to build the dispatch table
if Has_Dispatch_Table (Typ)
or else No (Access_Disp_Table (Typ))
or else Is_CPP_Class (Typ)
then
goto Leave;
elsif No_Run_Time_Mode then
Error_Msg_CRT ("tagged types", Typ);
goto Leave;
elsif not RTE_Available (RE_Tag) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier =>
Node (First_Elmt (Access_Disp_Table (Typ))),
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Constant_Present => True,
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
Analyze_List (Result, Suppress => All_Checks);
Error_Msg_CRT ("tagged types", Typ);
goto Leave;
end if;
-- Ensure that the value of Max_Predef_Prims defined in a-tags is
-- correct. Valid values are 10 under configurable runtime or 16
-- with full runtime.
if RTE_Available (RE_Interface_Data) then
if Max_Predef_Prims /= 16 then
Error_Msg_N ("run-time library configuration error", Typ);
goto Leave;
end if;
else
if Max_Predef_Prims /= 10 then
Error_Msg_N ("run-time library configuration error", Typ);
Error_Msg_CRT ("tagged types", Typ);
goto Leave;
end if;
end if;
DT := Make_Defining_Identifier (Loc, Name_DT);
Exname := Make_Defining_Identifier (Loc, Name_Exname);
HT_Link := Make_Defining_Identifier (Loc, Name_HT_Link);
Predef_Prims := Make_Defining_Identifier (Loc, Name_Predef_Prims);
SSD := Make_Defining_Identifier (Loc, Name_SSD);
TSD := Make_Defining_Identifier (Loc, Name_TSD);
-- Initialize Parent_Typ handling private types
Parent_Typ := Etype (Typ);
if Present (Full_View (Parent_Typ)) then
Parent_Typ := Full_View (Parent_Typ);
end if;
-- Ensure that all the primitives are frozen. This is only required when
-- building static dispatch tables --- the primitives must be frozen to
-- be referenced (otherwise we have problems with the backend). It is
-- not a requirement with nonstatic dispatch tables because in this case
-- we generate now an empty dispatch table; the extra code required to
-- register the primitives in the slots will be generated later --- when
-- each primitive is frozen (see Freeze_Subprogram).
if Building_Static_DT (Typ) then
declare
Saved_FLLTT : constant Boolean :=
Freezing_Library_Level_Tagged_Type;
Formal : Entity_Id;
Frnodes : List_Id;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
begin
Freezing_Library_Level_Tagged_Type := True;
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
Frnodes := Freeze_Entity (Prim, Typ);
-- We disable this check for abstract subprograms, given that
-- they cannot be called directly and thus the state of their
-- untagged formals is of no concern. The RM is unclear in any
-- case concerning the need for this check, and this topic may
-- go back to the ARG.
if not Is_Abstract_Subprogram (Prim) then
Formal := First_Formal (Prim);
while Present (Formal) loop
Check_Premature_Freezing (Prim, Typ, Etype (Formal));
Next_Formal (Formal);
end loop;
Check_Premature_Freezing (Prim, Typ, Etype (Prim));
end if;
if Present (Frnodes) then
Append_List_To (Result, Frnodes);
end if;
Next_Elmt (Prim_Elmt);
end loop;
Freezing_Library_Level_Tagged_Type := Saved_FLLTT;
end;
end if;
if not Is_Interface (Typ) and then Has_Interfaces (Typ) then
declare
Cannot_Have_Null_Disc : Boolean := False;
Dummy_Object_Typ : constant Entity_Id := Typ;
Name_Dummy_Object : constant Name_Id :=
New_External_Name (Tname,
'P', Suffix_Index => -1);
begin
Dummy_Object := Make_Defining_Identifier (Loc, Name_Dummy_Object);
-- Define the extra object imported and constant to avoid linker
-- errors (since this object is never declared). Required because
-- we implement RM 13.3(19) for exported and imported (variable)
-- objects by making them volatile.
Set_Is_Imported (Dummy_Object);
Set_Ekind (Dummy_Object, E_Constant);
Set_Is_True_Constant (Dummy_Object);
Set_Related_Type (Dummy_Object, Typ);
-- The scope must be set now to call Get_External_Name
Set_Scope (Dummy_Object, Current_Scope);
Get_External_Name (Dummy_Object);
Set_Interface_Name (Dummy_Object,
Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
-- Ensure proper Sprint output of this implicit importation
Set_Is_Internal (Dummy_Object);
if not Has_Discriminants (Dummy_Object_Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Dummy_Object,
Constant_Present => True,
Object_Definition => New_Occurrence_Of
(Dummy_Object_Typ, Loc)));
else
declare
Constr_List : constant List_Id := New_List;
Discrim : Node_Id;
begin
Discrim := First_Discriminant (Dummy_Object_Typ);
while Present (Discrim) loop
if Is_Discrete_Type (Etype (Discrim)) then
Append_To (Constr_List,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Etype (Discrim), Loc),
Attribute_Name => Name_First));
else
pragma Assert (Is_Access_Type (Etype (Discrim)));
Cannot_Have_Null_Disc :=
Cannot_Have_Null_Disc
or else Can_Never_Be_Null (Etype (Discrim));
Append_To (Constr_List, Make_Null (Loc));
end if;
Next_Discriminant (Discrim);
end loop;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Dummy_Object,
Constant_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Dummy_Object_Typ, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constr_List))));
end;
end if;
-- Given that the dummy object will not be declared at run time,
-- analyze its declaration with expansion disabled and warnings
-- and error messages ignored.
Expander_Mode_Save_And_Set (False);
Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
Analyze (Last (Result), Suppress => All_Checks);
Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
Expander_Mode_Restore;
end;
end if;
-- Ada 2005 (AI-251): Build the secondary dispatch tables
if Has_Interfaces (Typ) then
Collect_Interface_Components (Typ, Typ_Comps);
-- Each secondary dispatch table is assigned an unique positive
-- suffix index; such value also corresponds with the location of
-- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
-- Note: This value must be kept sync with the Suffix_Index values
-- generated by Make_Tags
Suffix_Index := 1;
AI_Tag_Elmt :=
Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
AI_Tag_Comp := First_Elmt (Typ_Comps);
while Present (AI_Tag_Comp) loop
pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
-- Build the secondary table containing pointers to thunks
Make_Secondary_DT
(Typ => Typ,
Iface =>
Base_Type (Related_Type (Node (AI_Tag_Comp))),
Iface_Comp => Node (AI_Tag_Comp),
Suffix_Index => Suffix_Index,
Num_Iface_Prims =>
UI_To_Int (DT_Entry_Count (Node (AI_Tag_Comp))),
Iface_DT_Ptr => Node (AI_Tag_Elmt),
Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
Build_Thunks => True,
Result => Result);
-- Skip secondary dispatch table referencing thunks to predefined
-- primitives.
Next_Elmt (AI_Tag_Elmt);
pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
-- Secondary dispatch table referencing user-defined primitives
-- covered by this interface.
Next_Elmt (AI_Tag_Elmt);
pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
-- Build the secondary table containing pointers to primitives
-- (used to give support to Generic Dispatching Constructors).
Make_Secondary_DT
(Typ => Typ,
Iface => Base_Type
(Related_Type (Node (AI_Tag_Comp))),
Iface_Comp => Node (AI_Tag_Comp),
Suffix_Index => -1,
Num_Iface_Prims => UI_To_Int
(DT_Entry_Count (Node (AI_Tag_Comp))),
Iface_DT_Ptr => Node (AI_Tag_Elmt),
Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
Build_Thunks => False,
Result => Result);
-- Skip secondary dispatch table referencing predefined primitives
Next_Elmt (AI_Tag_Elmt);
pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
Suffix_Index := Suffix_Index + 1;
Next_Elmt (AI_Tag_Elmt);
Next_Elmt (AI_Tag_Comp);
end loop;
end if;
-- Get the _tag entity and number of primitives of its dispatch table
DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
if Generate_SCIL then
Nb_Prim := 0;
end if;
Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
Set_Is_Statically_Allocated (Predef_Prims,
Is_Library_Level_Tagged_Type (Typ));
-- In case of locally defined tagged type we declare the object
-- containing the dispatch table by means of a variable. Its
-- initialization is done later by means of an assignment. This is
-- required to generate its External_Tag.
if not Building_Static_DT (Typ) then
-- Generate:
-- DT : No_Dispatch_Table_Wrapper;
-- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
if not Has_DT (Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => False,
Object_Definition =>
New_Occurrence_Of
(RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT_Ptr,
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Constant_Present => True,
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
Attribute_Name => Name_Address))));
Set_Is_Statically_Allocated (DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
-- Generate the SCIL node for the previous object declaration
-- because it has a tag initialization.
if Generate_SCIL then
New_Node :=
Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
Set_SCIL_Entity (New_Node, Typ);
Set_SCIL_Node (Last (Result), New_Node);
goto Leave_SCIL;
-- Gnat2scil has its own implementation of dispatch tables,
-- different than what is being implemented here. Generating
-- further dispatch table initialization code would just
-- cause gnat2scil to generate useless Scil which CodePeer
-- would waste time and space analyzing, so we skip it.
end if;
-- Generate:
-- DT : Dispatch_Table_Wrapper (Nb_Prim);
-- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
else
-- If the tagged type has no primitives we add a dummy slot
-- whose address will be the tag of this type.
if Nb_Prim = 0 then
DT_Constr_List :=
New_List (Make_Integer_Literal (Loc, 1));
else
DT_Constr_List :=
New_List (Make_Integer_Literal (Loc, Nb_Prim));
end if;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => False,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => DT_Constr_List))));
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT_Ptr,
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Constant_Present => True,
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Prims_Ptr), Loc)),
Attribute_Name => Name_Address))));
Set_Is_Statically_Allocated (DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
-- Generate the SCIL node for the previous object declaration
-- because it has a tag initialization.
if Generate_SCIL then
New_Node :=
Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
Set_SCIL_Entity (New_Node, Typ);
Set_SCIL_Node (Last (Result), New_Node);
goto Leave_SCIL;
-- Gnat2scil has its own implementation of dispatch tables,
-- different than what is being implemented here. Generating
-- further dispatch table initialization code would just
-- cause gnat2scil to generate useless Scil which CodePeer
-- would waste time and space analyzing, so we skip it.
end if;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier =>
Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Predef_Prims), Loc)),
Attribute_Name => Name_Address)));
end if;
end if;
-- Generate: Expanded_Name : constant String := "";
if Discard_Names then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Exname,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_String_Literal (Loc, "")));
-- Generate: Exname : constant String := full_qualified_name (typ);
-- The type itself may be an anonymous parent type, so use the first
-- subtype to have a user-recognizable name.
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Exname,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_String_Literal (Loc,
Fully_Qualified_Name_String (First_Subtype (Typ)))));
end if;
Set_Is_Statically_Allocated (Exname);
Set_Is_True_Constant (Exname);
-- Declare the object used by Ada.Tags.Register_Tag
if RTE_Available (RE_Register_Tag) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => HT_Link,
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression => New_Occurrence_Of (RTE (RE_No_Tag), Loc)));
end if;
-- Generate code to create the storage for the type specific data object
-- with enough space to store the tags of the ancestors plus the tags
-- of all the implemented interfaces (as described in a-tags.adb).
-- TSD : Type_Specific_Data (I_Depth) :=
-- (Idepth => I_Depth,
-- Access_Level => Type_Access_Level (Typ),
-- Alignment => Typ'Alignment,
-- Expanded_Name => Cstring_Ptr!(Exname'Address))
-- External_Tag => Cstring_Ptr!(Exname'Address))
-- HT_Link => HT_Link'Address,
-- Transportable => <<boolean-value>>,
-- Is_Abstract => <<boolean-value>>,
-- Needs_Finalization => <<boolean-value>>,
-- [ Size_Func => Size_Prim'Access, ]
-- [ Interfaces_Table => <<access-value>>, ]
-- [ SSD => SSD_Table'Address ]
-- Tags_Table => (0 => null,
-- 1 => Parent'Tag
-- ...);
TSD_Aggr_List := New_List;
-- Idepth: Count ancestors to compute the inheritance depth. For private
-- extensions, always go to the full view in order to compute the real
-- inheritance depth.
declare
Current_Typ : Entity_Id;
Parent_Typ : Entity_Id;
begin
I_Depth := 0;
Current_Typ := Typ;
loop
Parent_Typ := Etype (Current_Typ);
if Is_Private_Type (Parent_Typ) then
Parent_Typ := Full_View (Base_Type (Parent_Typ));
end if;
exit when Parent_Typ = Current_Typ;
I_Depth := I_Depth + 1;
Current_Typ := Parent_Typ;
end loop;
end;
Append_To (TSD_Aggr_List,
Make_Integer_Literal (Loc, I_Depth));
-- Access_Level
Append_To (TSD_Aggr_List,
Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
-- Alignment
-- For CPP types we cannot rely on the value of 'Alignment provided
-- by the backend to initialize this TSD field.
if Convention (Typ) = Convention_CPP
or else Is_CPP_Class (Root_Type (Typ))
then
Append_To (TSD_Aggr_List,
Make_Integer_Literal (Loc, 0));
else
Append_To (TSD_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Alignment));
end if;
-- Expanded_Name
Append_To (TSD_Aggr_List,
Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Exname, Loc),
Attribute_Name => Name_Address)));
-- External_Tag of a local tagged type
-- <typ>A : constant String :=
-- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
-- The reason we generate this strange name is that we do not want to
-- enter local tagged types in the global hash table used to compute
-- the Internal_Tag attribute for two reasons:
-- 1. It is hard to avoid a tasking race condition for entering the
-- entry into the hash table.
-- 2. It would cause a storage leak, unless we rig up considerable
-- mechanism to remove the entry from the hash table on exit.
-- So what we do is to generate the above external tag name, where the
-- hex address is the address of the local dispatch table (i.e. exactly
-- the value we want if Internal_Tag is computed from this string).
-- Of course this value will only be valid if the tagged type is still
-- in scope, but it clearly must be erroneous to compute the internal
-- tag of a tagged type that is out of scope.
-- We don't do this processing if an explicit external tag has been
-- specified. That's an odd case for which we have already issued a
-- warning, where we will not be able to compute the internal tag.
if not Discard_Names
and then not Is_Library_Level_Entity (Typ)
and then not Has_External_Tag_Rep_Clause (Typ)
then
declare
Exname : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Tname, 'A'));
Full_Name : constant String_Id :=
Fully_Qualified_Name_String (First_Subtype (Typ));
Str1_Id : String_Id;
Str2_Id : String_Id;
begin
-- Generate:
-- Str1 = "Internal tag at 16#";
Start_String;
Store_String_Chars ("Internal tag at 16#");
Str1_Id := End_String;
-- Generate:
-- Str2 = "#: <type-full-name>";
Start_String;
Store_String_Chars ("#: ");
Store_String_Chars (Full_Name);
Str2_Id := End_String;
-- Generate:
-- Exname : constant String :=
-- Str1 & Address_Image (Tag) & Str2;
if RTE_Available (RE_Address_Image) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Exname,
Constant_Present => True,
Object_Definition => New_Occurrence_Of
(Standard_String, Loc),
Expression =>
Make_Op_Concat (Loc,
Left_Opnd => Make_String_Literal (Loc, Str1_Id),
Right_Opnd =>
Make_Op_Concat (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Address_Image), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Address),
New_Occurrence_Of (DT_Ptr, Loc)))),
Right_Opnd =>
Make_String_Literal (Loc, Str2_Id)))));
-- Generate:
-- Exname : constant String := Str1 & Str2;
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Exname,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_Op_Concat (Loc,
Left_Opnd => Make_String_Literal (Loc, Str1_Id),
Right_Opnd => Make_String_Literal (Loc, Str2_Id))));
end if;
New_Node :=
Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Exname, Loc),
Attribute_Name => Name_Address));
end;
-- External tag of a library-level tagged type: Check for a definition
-- of External_Tag. The clause is considered only if it applies to this
-- specific tagged type, as opposed to one of its ancestors.
-- If the type is an unconstrained type extension, we are building the
-- dispatch table of its anonymous base type, so the external tag, if
-- any was specified, must be retrieved from the first subtype. Go to
-- the full view in case the clause is in the private part.
else
declare
Def : constant Node_Id := Get_Attribute_Definition_Clause
(Underlying_Type (First_Subtype (Typ)),
Attribute_External_Tag);
Old_Val : String_Id;
New_Val : String_Id;
E : Entity_Id;
begin
if not Present (Def)
or else Entity (Name (Def)) /= First_Subtype (Typ)
then
New_Node :=
Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Exname, Loc),
Attribute_Name => Name_Address));
else
Old_Val := Strval (Expr_Value_S (Expression (Def)));
-- For the rep clause "for <typ>'external_tag use y" generate:
-- <typ>A : constant string := y;
--
-- <typ>A'Address is used to set the External_Tag component
-- of the TSD
-- Create a new nul terminated string if it is not already
if String_Length (Old_Val) > 0
and then
Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
then
New_Val := Old_Val;
else
Start_String (Old_Val);
Store_String_Char (Get_Char_Code (ASCII.NUL));
New_Val := End_String;
end if;
E := Make_Defining_Identifier (Loc,
New_External_Name (Chars (Typ), 'A'));
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => E,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_String_Literal (Loc, New_Val)));
New_Node :=
Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (E, Loc),
Attribute_Name => Name_Address));
end if;
end;
end if;
Append_To (TSD_Aggr_List, New_Node);
-- HT_Link
if RTE_Available (RE_Register_Tag) then
Append_To (TSD_Aggr_List,
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (HT_Link, Loc),
Attribute_Name => Name_Address)));
elsif RTE_Record_Component_Available (RE_HT_Link) then
Append_To (TSD_Aggr_List,
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
end if;
-- Transportable: Set for types that can be used in remote calls
-- with respect to E.4(18) legality rules.
declare
Transportable : Entity_Id;
begin
Transportable :=
Boolean_Literals
(Is_Pure (Typ)
or else Is_Shared_Passive (Typ)
or else
((Is_Remote_Types (Typ)
or else Is_Remote_Call_Interface (Typ))
and then Original_View_In_Visible_Part (Typ))
or else not Comes_From_Source (Typ));
Append_To (TSD_Aggr_List,
New_Occurrence_Of (Transportable, Loc));
end;
-- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
-- available in the HIE runtime.
if RTE_Record_Component_Available (RE_Is_Abstract) then
declare
Is_Abstract : Entity_Id;
begin
Is_Abstract := Boolean_Literals (Is_Abstract_Type (Typ));
Append_To (TSD_Aggr_List,
New_Occurrence_Of (Is_Abstract, Loc));
end;
end if;
-- Needs_Finalization: Set if the type is controlled or has controlled
-- components.
declare
Needs_Fin : Entity_Id;
begin
Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
end;
-- Size_Func
if RTE_Record_Component_Available (RE_Size_Func) then
-- Initialize this field to Null_Address if we are not building
-- static dispatch tables static or if the size function is not
-- available. In the former case we cannot initialize this field
-- until the function is frozen and registered in the dispatch
-- table (see Register_Primitive).
if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
Append_To (TSD_Aggr_List,
Unchecked_Convert_To (RTE (RE_Size_Ptr),
New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
else
declare
Prim_Elmt : Elmt_Id;
Prim : Entity_Id;
Size_Comp : Node_Id := Empty;
begin
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if Chars (Prim) = Name_uSize then
Prim := Ultimate_Alias (Prim);
if Is_Abstract_Subprogram (Prim) then
Size_Comp :=
Unchecked_Convert_To (RTE (RE_Size_Ptr),
New_Occurrence_Of (RTE (RE_Null_Address), Loc));
else
Size_Comp :=
Unchecked_Convert_To (RTE (RE_Size_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim, Loc),
Attribute_Name => Name_Unrestricted_Access));
end if;
exit;
end if;
Next_Elmt (Prim_Elmt);
end loop;
pragma Assert (Present (Size_Comp));
Append_To (TSD_Aggr_List, Size_Comp);
end;
end if;
end if;
-- Interfaces_Table (required for AI-405)
if RTE_Record_Component_Available (RE_Interfaces_Table) then
-- Count the number of interface types implemented by Typ
Collect_Interfaces (Typ, Typ_Ifaces);
AI := First_Elmt (Typ_Ifaces);
while Present (AI) loop
Num_Ifaces := Num_Ifaces + 1;
Next_Elmt (AI);
end loop;
if Num_Ifaces = 0 then
Iface_Table_Node := Make_Null (Loc);
-- Generate the Interface_Table object
else
declare
TSD_Ifaces_List : constant List_Id := New_List;
Elmt : Elmt_Id;
Offset_To_Top : Node_Id;
Sec_DT_Tag : Node_Id;
Dummy_Object_Ifaces_List : Elist_Id := No_Elist;
Dummy_Object_Ifaces_Comp_List : Elist_Id := No_Elist;
Dummy_Object_Ifaces_Tag_List : Elist_Id := No_Elist;
-- Interfaces information of the dummy object
begin
-- Collect interfaces information if we need to compute the
-- offset to the top using the dummy object.
if Present (Dummy_Object) then
Collect_Interfaces_Info (Typ,
Ifaces_List => Dummy_Object_Ifaces_List,
Components_List => Dummy_Object_Ifaces_Comp_List,
Tags_List => Dummy_Object_Ifaces_Tag_List);
end if;
AI := First_Elmt (Typ_Ifaces);
while Present (AI) loop
if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
Sec_DT_Tag := New_Occurrence_Of (DT_Ptr, Loc);
else
Elmt :=
Next_Elmt
(Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
pragma Assert (Has_Thunks (Node (Elmt)));
while Is_Tag (Node (Elmt))
and then not
Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
Use_Full_View => True)
loop
pragma Assert (Has_Thunks (Node (Elmt)));
Next_Elmt (Elmt);
pragma Assert (Has_Thunks (Node (Elmt)));
Next_Elmt (Elmt);
pragma Assert (not Has_Thunks (Node (Elmt)));
Next_Elmt (Elmt);
pragma Assert (not Has_Thunks (Node (Elmt)));
Next_Elmt (Elmt);
end loop;
pragma Assert (Ekind (Node (Elmt)) = E_Constant
and then not
Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
Sec_DT_Tag :=
New_Occurrence_Of
(Node (Next_Elmt (Next_Elmt (Elmt))), Loc);
end if;
-- Use the dummy object to compute Offset_To_Top of
-- components located at fixed position.
if Present (Dummy_Object) then
declare
Iface : constant Node_Id := Node (AI);
Iface_Comp : Node_Id := Empty;
Iface_Comp_Elmt : Elmt_Id;
Iface_Elmt : Elmt_Id;
begin
Iface_Elmt :=
First_Elmt (Dummy_Object_Ifaces_List);
Iface_Comp_Elmt :=
First_Elmt (Dummy_Object_Ifaces_Comp_List);
while Present (Iface_Elmt) loop
if Node (Iface_Elmt) = Iface then
Iface_Comp := Node (Iface_Comp_Elmt);
exit;
end if;
Next_Elmt (Iface_Elmt);
Next_Elmt (Iface_Comp_Elmt);
end loop;
pragma Assert (Present (Iface_Comp));
if not
Is_Variable_Size_Record (Etype (Scope (Iface_Comp)))
then
Offset_To_Top :=
Make_Op_Minus (Loc,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Dummy_Object, Loc),
Selector_Name =>
New_Occurrence_Of (Iface_Comp, Loc)),
Attribute_Name => Name_Position));
else
Offset_To_Top := Make_Integer_Literal (Loc, 0);
end if;
end;
else
Offset_To_Top := Make_Integer_Literal (Loc, 0);
end if;
Append_To (TSD_Ifaces_List,
Make_Aggregate (Loc,
Expressions => New_List (
-- Iface_Tag
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Node (AI)))),
Loc)),
-- Static_Offset_To_Top
New_Occurrence_Of (Standard_True, Loc),
-- Offset_To_Top_Value
Offset_To_Top,
-- Offset_To_Top_Func
Make_Null (Loc),
-- Secondary_DT
Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag))));
Next_Elmt (AI);
end loop;
Name_ITable := New_External_Name (Tname, 'I');
ITable := Make_Defining_Identifier (Loc, Name_ITable);
Set_Is_Statically_Allocated (ITable,
Is_Library_Level_Tagged_Type (Typ));
-- The table of interfaces is constant if we are building a
-- static dispatch table; otherwise is not constant because
-- its slots are filled at run time by the IP routine.
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => ITable,
Aliased_Present => True,
Constant_Present => Building_Static_Secondary_DT (Typ),
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Interface_Data), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Integer_Literal (Loc, Num_Ifaces)))),
Expression =>
Make_Aggregate (Loc,
Expressions => New_List (
Make_Integer_Literal (Loc, Num_Ifaces),
Make_Aggregate (Loc, TSD_Ifaces_List)))));
Iface_Table_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (ITable, Loc),
Attribute_Name => Name_Unchecked_Access);
end;
end if;
Append_To (TSD_Aggr_List, Iface_Table_Node);
end if;
-- Generate the Select Specific Data table for synchronized types that
-- implement synchronized interfaces. The size of the table is
-- constrained by the number of non-predefined primitive operations.
if RTE_Record_Component_Available (RE_SSD) then
if Ada_Version >= Ada_2005
and then Has_DT (Typ)
and then Is_Concurrent_Record_Type (Typ)
and then Has_Interfaces (Typ)
and then Nb_Prim > 0
and then not Is_Abstract_Type (Typ)
and then not Is_Controlled (Typ)
and then not Restriction_Active (No_Dispatching_Calls)
and then not Restriction_Active (No_Select_Statements)
then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => SSD,
Aliased_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (
RTE (RE_Select_Specific_Data), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Integer_Literal (Loc, Nb_Prim))))));
Append_To (Result,
Make_Attribute_Definition_Clause (Loc,
Name => New_Occurrence_Of (SSD, Loc),
Chars => Name_Alignment,
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
Attribute_Name => Name_Alignment)));
-- This table is initialized by Make_Select_Specific_Data_Table,
-- which calls Set_Entry_Index and Set_Prim_Op_Kind.
Append_To (TSD_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (SSD, Loc),
Attribute_Name => Name_Unchecked_Access));
else
Append_To (TSD_Aggr_List, Make_Null (Loc));
end if;
end if;
-- Initialize the table of ancestor tags. In case of interface types
-- this table is not needed.
TSD_Tags_List := New_List;
-- If we are not statically allocating the dispatch table then we must
-- fill position 0 with null because we still have not generated the
-- tag of Typ.
if not Building_Static_DT (Typ)
or else Is_Interface (Typ)
then
Append_To (TSD_Tags_List,
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
-- Otherwise we can safely reference the tag
else
Append_To (TSD_Tags_List,
New_Occurrence_Of (DT_Ptr, Loc));
end if;
-- Fill the rest of the table with the tags of the ancestors
declare
Current_Typ : Entity_Id;
Parent_Typ : Entity_Id;
Pos : Nat;
begin
Pos := 1;
Current_Typ := Typ;
loop
Parent_Typ := Etype (Current_Typ);
if Is_Private_Type (Parent_Typ) then
Parent_Typ := Full_View (Base_Type (Parent_Typ));
end if;
exit when Parent_Typ = Current_Typ;
if Is_CPP_Class (Parent_Typ) then
-- The tags defined in the C++ side will be inherited when
-- the object is constructed (Exp_Ch3.Build_Init_Procedure)
Append_To (TSD_Tags_List,
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
else
Append_To (TSD_Tags_List,
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
Loc));
end if;
Pos := Pos + 1;
Current_Typ := Parent_Typ;
end loop;
pragma Assert (Pos = I_Depth + 1);
end;
Append_To (TSD_Aggr_List,
Make_Aggregate (Loc,
Expressions => TSD_Tags_List));
-- Build the TSD object
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => TSD,
Aliased_Present => True,
Constant_Present => Building_Static_DT (Typ),
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (
RTE (RE_Type_Specific_Data), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Integer_Literal (Loc, I_Depth)))),
Expression => Make_Aggregate (Loc,
Expressions => TSD_Aggr_List)));
Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
-- Initialize or declare the dispatch table object
if not Has_DT (Typ) then
DT_Constr_List := New_List;
DT_Aggr_List := New_List;
-- Typeinfo
New_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (TSD, Loc),
Attribute_Name => Name_Address);
Append_To (DT_Constr_List, New_Node);
Append_To (DT_Aggr_List, New_Copy (New_Node));
Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
-- In case of locally defined tagged types we have already declared
-- and uninitialized object for the dispatch table, which is now
-- initialized by means of the following assignment:
-- DT := (TSD'Address, 0);
if not Building_Static_DT (Typ) then
Append_To (Result,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (DT, Loc),
Expression => Make_Aggregate (Loc, DT_Aggr_List)));
-- In case of library level tagged types we declare and export now
-- the constant object containing the dummy dispatch table. There
-- is no need to declare the tag here because it has been previously
-- declared by Make_Tags
-- DT : aliased constant No_Dispatch_Table :=
-- (NDT_TSD => TSD'Address;
-- NDT_Prims_Ptr => 0);
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
Expression => Make_Aggregate (Loc, DT_Aggr_List)));
Export_DT (Typ, DT);
end if;
-- Common case: Typ has a dispatch table
-- Generate:
-- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
-- (predef-prim-op-1'address,
-- predef-prim-op-2'address,
-- ...
-- predef-prim-op-n'address);
-- DT : Dispatch_Table (Nb_Prims) :=
-- (Signature => <sig-value>,
-- Tag_Kind => <tag_kind-value>,
-- Predef_Prims => Predef_Prims'First'Address,
-- Offset_To_Top => 0,
-- TSD => TSD'Address;
-- Prims_Ptr => (prim-op-1'address,
-- prim-op-2'address,
-- ...
-- prim-op-n'address));
-- for DT'Alignment use Address'Alignment
else
declare
Nb_P_Prims : constant Nat := Number_Of_Predefined_Prims (Typ);
Prim_Table : array (Nat range 1 .. Nb_P_Prims) of Entity_Id;
Decl : Node_Id;
E : Entity_Id;
begin
Prim_Ops_Aggr_List := New_List;
Prim_Table := (others => Empty);
if Building_Static_DT (Typ) then
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Abstract_Subprogram (Prim)
and then not Is_Eliminated (Prim)
and then not Generate_SCIL
and then not Present (Prim_Table
(UI_To_Int (DT_Position (Prim))))
then
E := Ultimate_Alias (Prim);
pragma Assert (not Is_Abstract_Subprogram (E));
Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
end if;
Next_Elmt (Prim_Elmt);
end loop;
end if;
for J in Prim_Table'Range loop
if Present (Prim_Table (J)) then
New_Node :=
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Prim_Table (J), Loc),
Attribute_Name => Name_Unrestricted_Access));
else
New_Node := Make_Null (Loc);
end if;
Append_To (Prim_Ops_Aggr_List, New_Node);
end loop;
New_Node :=
Make_Aggregate (Loc,
Expressions => Prim_Ops_Aggr_List);
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Address_Array), Loc));
Append_To (Result, Decl);
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Predef_Prims,
Aliased_Present => True,
Constant_Present => Building_Static_DT (Typ),
Object_Definition =>
New_Occurrence_Of (Defining_Identifier (Decl), Loc),
Expression => New_Node));
-- Remember aggregates initializing dispatch tables
Append_Elmt (New_Node, DT_Aggr);
end;
-- Stage 1: Initialize the discriminant and the record components
DT_Constr_List := New_List;
DT_Aggr_List := New_List;
-- Num_Prims. If the tagged type has no primitives we add a dummy
-- slot whose address will be the tag of this type.
if Nb_Prim = 0 then
New_Node := Make_Integer_Literal (Loc, 1);
else
New_Node := Make_Integer_Literal (Loc, Nb_Prim);
end if;
Append_To (DT_Constr_List, New_Node);
Append_To (DT_Aggr_List, New_Copy (New_Node));
-- Signature
if RTE_Record_Component_Available (RE_Signature) then
Append_To (DT_Aggr_List,
New_Occurrence_Of (RTE (RE_Primary_DT), Loc));
end if;
-- Tag_Kind
if RTE_Record_Component_Available (RE_Tag_Kind) then
Append_To (DT_Aggr_List, Tagged_Kind (Typ));
end if;
-- Predef_Prims
Append_To (DT_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Predef_Prims, Loc),
Attribute_Name => Name_Address));
-- Offset_To_Top
Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
-- Typeinfo
Append_To (DT_Aggr_List,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (TSD, Loc),
Attribute_Name => Name_Address));
-- Stage 2: Initialize the table of user-defined primitive operations
Prim_Ops_Aggr_List := New_List;
if Nb_Prim = 0 then
Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
elsif not Building_Static_DT (Typ) then
for J in 1 .. Nb_Prim loop
Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
end loop;
else
declare
CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
E : Entity_Id;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
Prim_Pos : Nat;
Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
begin
Prim_Table := (others => Empty);
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- Retrieve the ultimate alias of the primitive for proper
-- handling of renamings and eliminated primitives.
E := Ultimate_Alias (Prim);
-- If the alias is not a primitive operation then Prim does
-- not rename another primitive, but rather an operation
-- declared elsewhere (e.g. in another scope) and therefore
-- Prim is a new primitive.
if No (Find_Dispatching_Type (E)) then
E := Prim;
end if;
Prim_Pos := UI_To_Int (DT_Position (E));
-- Skip predefined primitives because they are located in a
-- separate dispatch table.
if not Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Predefined_Dispatching_Operation (E)
-- Skip entities with attribute Interface_Alias because
-- those are only required to build secondary dispatch
-- tables.
and then not Present (Interface_Alias (Prim))
-- Skip abstract and eliminated primitives
and then not Is_Abstract_Subprogram (E)
and then not Is_Eliminated (E)
-- For derivations of CPP types skip primitives located in
-- the C++ part of the dispatch table because their slots
-- are initialized by the IC routine.
and then (not Is_CPP_Class (Root_Type (Typ))
or else Prim_Pos > CPP_Nb_Prims)
-- Skip ignored Ghost subprograms as those will be removed
-- from the executable.
and then not Is_Ignored_Ghost_Entity (E)
then
pragma Assert
(UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
end if;
Next_Elmt (Prim_Elmt);
end loop;
for J in Prim_Table'Range loop
if Present (Prim_Table (J)) then
New_Node :=
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Prim_Table (J), Loc),
Attribute_Name => Name_Unrestricted_Access));
else
New_Node := Make_Null (Loc);
end if;
Append_To (Prim_Ops_Aggr_List, New_Node);
end loop;
end;
end if;
New_Node :=
Make_Aggregate (Loc,
Expressions => Prim_Ops_Aggr_List);
Append_To (DT_Aggr_List, New_Node);
-- Remember aggregates initializing dispatch tables
Append_Elmt (New_Node, DT_Aggr);
-- In case of locally defined tagged types we have already declared
-- and uninitialized object for the dispatch table, which is now
-- initialized by means of an assignment.
if not Building_Static_DT (Typ) then
Append_To (Result,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (DT, Loc),
Expression => Make_Aggregate (Loc, DT_Aggr_List)));
-- In case of library level tagged types we declare now and export
-- the constant object containing the dispatch table.
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of
(RTE (RE_Dispatch_Table_Wrapper), Loc),
Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => DT_Constr_List)),
Expression => Make_Aggregate (Loc, DT_Aggr_List)));
Export_DT (Typ, DT);
end if;
end if;
-- Initialize the table of ancestor tags if not building static
-- dispatch table
if not Building_Static_DT (Typ)
and then not Is_Interface (Typ)
and then not Is_CPP_Class (Typ)
then
Append_To (Result,
Make_Assignment_Statement (Loc,
Name =>
Make_Indexed_Component (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (TSD, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Tags_Table), Loc)),
Expressions =>
New_List (Make_Integer_Literal (Loc, 0))),
Expression =>
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
end if;
-- Inherit the dispatch tables of the parent. There is no need to
-- inherit anything from the parent when building static dispatch tables
-- because the whole dispatch table (including inherited primitives) has
-- been already built.
if Building_Static_DT (Typ) then
null;
-- If the ancestor is a CPP_Class type we inherit the dispatch tables
-- in the init proc, and we don't need to fill them in here.
elsif Is_CPP_Class (Parent_Typ) then
null;
-- Otherwise we fill in the dispatch tables here
else
if Typ /= Parent_Typ
and then not Is_Interface (Typ)
and then not Restriction_Active (No_Dispatching_Calls)
then
-- Inherit the dispatch table
if not Is_Interface (Typ)
and then not Is_Interface (Parent_Typ)
and then not Is_CPP_Class (Parent_Typ)
then
declare
Nb_Prims : constant Int :=
UI_To_Int (DT_Entry_Count
(First_Tag_Component (Parent_Typ)));
begin
Append_To (Elab_Code,
Build_Inherit_Predefined_Prims (Loc,
Old_Tag_Node =>
New_Occurrence_Of
(Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table (Parent_Typ)))), Loc),
New_Tag_Node =>
New_Occurrence_Of
(Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table (Typ)))), Loc),
Num_Predef_Prims =>
Number_Of_Predefined_Prims (Parent_Typ)));
if Nb_Prims /= 0 then
Append_To (Elab_Code,
Build_Inherit_Prims (Loc,
Typ => Typ,
Old_Tag_Node =>
New_Occurrence_Of
(Node
(First_Elmt
(Access_Disp_Table (Parent_Typ))), Loc),
New_Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
Num_Prims => Nb_Prims));
end if;
end;
end if;
-- Inherit the secondary dispatch tables of the ancestor
if not Is_CPP_Class (Parent_Typ) then
declare
Sec_DT_Ancestor : Elmt_Id :=
Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Parent_Typ))));
Sec_DT_Typ : Elmt_Id :=
Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table (Typ))));
procedure Copy_Secondary_DTs (Typ : Entity_Id);
-- Local procedure required to climb through the ancestors
-- and copy the contents of all their secondary dispatch
-- tables.
------------------------
-- Copy_Secondary_DTs --
------------------------
procedure Copy_Secondary_DTs (Typ : Entity_Id) is
E : Entity_Id;
Iface : Elmt_Id;
begin
-- Climb to the ancestor (if any) handling private types
if Present (Full_View (Etype (Typ))) then
if Full_View (Etype (Typ)) /= Typ then
Copy_Secondary_DTs (Full_View (Etype (Typ)));
end if;
elsif Etype (Typ) /= Typ then
Copy_Secondary_DTs (Etype (Typ));
end if;
if Present (Interfaces (Typ))
and then not Is_Empty_Elmt_List (Interfaces (Typ))
then
Iface := First_Elmt (Interfaces (Typ));
E := First_Entity (Typ);
while Present (E)
and then Present (Node (Sec_DT_Ancestor))
and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
loop
if Is_Tag (E) and then Chars (E) /= Name_uTag then
declare
Num_Prims : constant Int :=
UI_To_Int (DT_Entry_Count (E));
begin
if not Is_Interface (Etype (Typ)) then
-- Inherit first secondary dispatch table
Append_To (Elab_Code,
Build_Inherit_Predefined_Prims (Loc,
Old_Tag_Node =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node
(Next_Elmt (Sec_DT_Ancestor)),
Loc)),
New_Tag_Node =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (Next_Elmt (Sec_DT_Typ)),
Loc)),
Num_Predef_Prims =>
Number_Of_Predefined_Prims
(Parent_Typ)));
if Num_Prims /= 0 then
Append_To (Elab_Code,
Build_Inherit_Prims (Loc,
Typ => Node (Iface),
Old_Tag_Node =>
Unchecked_Convert_To
(RTE (RE_Tag),
New_Occurrence_Of
(Node (Sec_DT_Ancestor),
Loc)),
New_Tag_Node =>
Unchecked_Convert_To
(RTE (RE_Tag),
New_Occurrence_Of
(Node (Sec_DT_Typ), Loc)),
Num_Prims => Num_Prims));
end if;
end if;
Next_Elmt (Sec_DT_Ancestor);
Next_Elmt (Sec_DT_Typ);
-- Skip the secondary dispatch table of
-- predefined primitives
Next_Elmt (Sec_DT_Ancestor);
Next_Elmt (Sec_DT_Typ);
if not Is_Interface (Etype (Typ)) then
-- Inherit second secondary dispatch table
Append_To (Elab_Code,
Build_Inherit_Predefined_Prims (Loc,
Old_Tag_Node =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node
(Next_Elmt (Sec_DT_Ancestor)),
Loc)),
New_Tag_Node =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of
(Node (Next_Elmt (Sec_DT_Typ)),
Loc)),
Num_Predef_Prims =>
Number_Of_Predefined_Prims
(Parent_Typ)));
if Num_Prims /= 0 then
Append_To (Elab_Code,
Build_Inherit_Prims (Loc,
Typ => Node (Iface),
Old_Tag_Node =>
Unchecked_Convert_To
(RTE (RE_Tag),
New_Occurrence_Of
(Node (Sec_DT_Ancestor),
Loc)),
New_Tag_Node =>
Unchecked_Convert_To
(RTE (RE_Tag),
New_Occurrence_Of
(Node (Sec_DT_Typ), Loc)),
Num_Prims => Num_Prims));
end if;
end if;
end;
Next_Elmt (Sec_DT_Ancestor);
Next_Elmt (Sec_DT_Typ);
-- Skip the secondary dispatch table of
-- predefined primitives
Next_Elmt (Sec_DT_Ancestor);
Next_Elmt (Sec_DT_Typ);
Next_Elmt (Iface);
end if;
Next_Entity (E);
end loop;
end if;
end Copy_Secondary_DTs;
begin
if Present (Node (Sec_DT_Ancestor))
and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
then
-- Handle private types
if Present (Full_View (Typ)) then
Copy_Secondary_DTs (Full_View (Typ));
else
Copy_Secondary_DTs (Typ);
end if;
end if;
end;
end if;
end if;
end if;
-- Generate code to check if the external tag of this type is the same
-- as the external tag of some other declaration.
-- Check_TSD (TSD'Unrestricted_Access);
-- This check is a consequence of AI05-0113-1/06, so it officially
-- applies to Ada 2005 (and Ada 2012). It might be argued that it is
-- a desirable check to add in Ada 95 mode, but we hesitate to make
-- this change, as it would be incompatible, and could conceivably
-- cause a problem in existing Ada 95 code.
-- We check for No_Run_Time_Mode here, because we do not want to pick
-- up the RE_Check_TSD entity and call it in No_Run_Time mode.
-- We cannot perform this check if the generation of its expanded name
-- was discarded.
if not No_Run_Time_Mode
and then not Discard_Names
and then Ada_Version >= Ada_2005
and then RTE_Available (RE_Check_TSD)
and then not Duplicated_Tag_Checks_Suppressed (Typ)
then
Append_To (Elab_Code,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Check_TSD), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (TSD, Loc),
Attribute_Name => Name_Unchecked_Access))));
end if;
-- Generate code to register the Tag in the External_Tag hash table for
-- the pure Ada type only.
-- Register_Tag (Dt_Ptr);
-- Skip this action in the following cases:
-- 1) if Register_Tag is not available.
-- 2) in No_Run_Time mode.
-- 3) if Typ is not defined at the library level (this is required
-- to avoid adding concurrency control to the hash table used
-- by the run-time to register the tags).
if not No_Run_Time_Mode
and then Is_Library_Level_Entity (Typ)
and then RTE_Available (RE_Register_Tag)
then
Append_To (Elab_Code,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Register_Tag), Loc),
Parameter_Associations =>
New_List (New_Occurrence_Of (DT_Ptr, Loc))));
end if;
if not Is_Empty_List (Elab_Code) then
Append_List_To (Result, Elab_Code);
end if;
-- Populate the two auxiliary tables used for dispatching asynchronous,
-- conditional and timed selects for synchronized types that implement
-- a limited interface. Skip this step in Ravenscar profile or when
-- general dispatching is forbidden.
if Ada_Version >= Ada_2005
and then Is_Concurrent_Record_Type (Typ)
and then Has_Interfaces (Typ)
and then not Restriction_Active (No_Dispatching_Calls)
and then not Restriction_Active (No_Select_Statements)
then
Append_List_To (Result,
Make_Select_Specific_Data_Table (Typ));
end if;
-- Remember entities containing dispatch tables
Append_Elmt (Predef_Prims, DT_Decl);
Append_Elmt (DT, DT_Decl);
Analyze_List (Result, Suppress => All_Checks);
Set_Has_Dispatch_Table (Typ);
-- Mark entities containing dispatch tables. Required by the backend to
-- handle them properly.
if Has_DT (Typ) then
declare
Elmt : Elmt_Id;
begin
-- Object declarations
Elmt := First_Elmt (DT_Decl);
while Present (Elmt) loop
Set_Is_Dispatch_Table_Entity (Node (Elmt));
pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
Next_Elmt (Elmt);
end loop;
-- Aggregates initializing dispatch tables
Elmt := First_Elmt (DT_Aggr);
while Present (Elmt) loop
Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
Next_Elmt (Elmt);
end loop;
end;
end if;
<<Leave_SCIL>>
-- Register the tagged type in the call graph nodes table
Register_CG_Node (Typ);
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
return Result;
end Make_DT;
-------------------------------------
-- Make_Select_Specific_Data_Table --
-------------------------------------
function Make_Select_Specific_Data_Table
(Typ : Entity_Id) return List_Id
is
Assignments : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (Typ);
Conc_Typ : Entity_Id;
Decls : List_Id := No_List;
Prim : Entity_Id;
Prim_Als : Entity_Id;
Prim_Elmt : Elmt_Id;
Prim_Pos : Uint;
Nb_Prim : Nat := 0;
type Examined_Array is array (Int range <>) of Boolean;
function Find_Entry_Index (E : Entity_Id) return Uint;
-- Given an entry, find its index in the visible declarations of the
-- corresponding concurrent type of Typ.
----------------------
-- Find_Entry_Index --
----------------------
function Find_Entry_Index (E : Entity_Id) return Uint is
Index : Uint := Uint_1;
Subp_Decl : Entity_Id;
begin
if Present (Decls)
and then not Is_Empty_List (Decls)
then
Subp_Decl := First (Decls);
while Present (Subp_Decl) loop
if Nkind (Subp_Decl) = N_Entry_Declaration then
if Defining_Identifier (Subp_Decl) = E then
return Index;
end if;
Index := Index + 1;
end if;
Next (Subp_Decl);
end loop;
end if;
return Uint_0;
end Find_Entry_Index;
-- Local variables
Tag_Node : Node_Id;
-- Start of processing for Make_Select_Specific_Data_Table
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
if Present (Corresponding_Concurrent_Type (Typ)) then
Conc_Typ := Corresponding_Concurrent_Type (Typ);
if Present (Full_View (Conc_Typ)) then
Conc_Typ := Full_View (Conc_Typ);
end if;
if Ekind (Conc_Typ) = E_Protected_Type then
Decls := Visible_Declarations (Protected_Definition (
Parent (Conc_Typ)));
else
pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
Decls := Visible_Declarations (Task_Definition (
Parent (Conc_Typ)));
end if;
end if;
-- Count the non-predefined primitive operations
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if not (Is_Predefined_Dispatching_Operation (Prim)
or else Is_Predefined_Dispatching_Alias (Prim))
then
Nb_Prim := Nb_Prim + 1;
end if;
Next_Elmt (Prim_Elmt);
end loop;
declare
Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
begin
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- Look for primitive overriding an abstract interface subprogram
if Present (Interface_Alias (Prim))
and then not
Is_Ancestor
(Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
Use_Full_View => True)
and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
then
Prim_Pos := DT_Position (Alias (Prim));
pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
Examined (UI_To_Int (Prim_Pos)) := True;
-- Set the primitive operation kind regardless of subprogram
-- type. Generate:
-- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
if Tagged_Type_Expansion then
Tag_Node :=
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
Append_To (Assignments,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Set_Prim_Op_Kind), Loc),
Parameter_Associations => New_List (
Tag_Node,
Make_Integer_Literal (Loc, Prim_Pos),
Prim_Op_Kind (Alias (Prim), Typ))));
-- Retrieve the root of the alias chain
Prim_Als := Ultimate_Alias (Prim);
-- In the case of an entry wrapper, set the entry index
if Ekind (Prim) = E_Procedure
and then Is_Primitive_Wrapper (Prim_Als)
and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
then
-- Generate:
-- Ada.Tags.Set_Entry_Index
-- (DT_Ptr, <position>, <index>);
if Tagged_Type_Expansion then
Tag_Node :=
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
else
Tag_Node :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Tag);
end if;
Append_To (Assignments,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Set_Entry_Index), Loc),
Parameter_Associations => New_List (
Tag_Node,
Make_Integer_Literal (Loc, Prim_Pos),
Make_Integer_Literal (Loc,
Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
end;
return Assignments;
end Make_Select_Specific_Data_Table;
---------------
-- Make_Tags --
---------------
function Make_Tags (Typ : Entity_Id) return List_Id is
Loc : constant Source_Ptr := Sloc (Typ);
Result : constant List_Id := New_List;
procedure Import_DT
(Tag_Typ : Entity_Id;
DT : Entity_Id;
Is_Secondary_DT : Boolean);
-- Import the dispatch table DT of tagged type Tag_Typ. Required to
-- generate forward references and statically allocate the table. For
-- primary dispatch tables that require no dispatch table generate:
-- DT : static aliased constant Non_Dispatch_Table_Wrapper;
-- pragma Import (Ada, DT);
-- Otherwise generate:
-- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
-- pragma Import (Ada, DT);
---------------
-- Import_DT --
---------------
procedure Import_DT
(Tag_Typ : Entity_Id;
DT : Entity_Id;
Is_Secondary_DT : Boolean)
is
DT_Constr_List : List_Id;
Nb_Prim : Nat;
begin
Set_Is_Imported (DT);
Set_Ekind (DT, E_Constant);
Set_Related_Type (DT, Typ);
-- The scope must be set now to call Get_External_Name
Set_Scope (DT, Current_Scope);
Get_External_Name (DT);
Set_Interface_Name (DT,
Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
-- Ensure proper Sprint output of this implicit importation
Set_Is_Internal (DT);
-- Save this entity to allow Make_DT to generate its exportation
Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
-- No dispatch table required
if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of
(RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
else
-- Calculate the number of primitives of the dispatch table and
-- the size of the Type_Specific_Data record.
Nb_Prim :=
UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
-- If the tagged type has no primitives we add a dummy slot whose
-- address will be the tag of this type.
if Nb_Prim = 0 then
DT_Constr_List :=
New_List (Make_Integer_Literal (Loc, 1));
else
DT_Constr_List :=
New_List (Make_Integer_Literal (Loc, Nb_Prim));
end if;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT,
Aliased_Present => True,
Constant_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => DT_Constr_List))));
end if;
end Import_DT;
-- Local variables
Tname : constant Name_Id := Chars (Typ);
AI_Tag_Comp : Elmt_Id;
DT : Node_Id := Empty;
DT_Ptr : Node_Id;
Predef_Prims_Ptr : Node_Id;
Iface_DT : Node_Id := Empty;
Iface_DT_Ptr : Node_Id;
New_Node : Node_Id;
Suffix_Index : Int;
Typ_Name : Name_Id;
Typ_Comps : Elist_Id;
-- Start of processing for Make_Tags
begin
pragma Assert (No (Access_Disp_Table (Typ)));
Set_Access_Disp_Table (Typ, New_Elmt_List);
-- If the elaboration of this tagged type needs a boolean flag then
-- define now its entity. It is initialized to True to indicate that
-- elaboration is still pending; set to False by the IP routine.
-- TypFxx : boolean := True;
if Elab_Flag_Needed (Typ) then
Set_Access_Disp_Table_Elab_Flag (Typ,
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Tname, 'F')));
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Access_Disp_Table_Elab_Flag (Typ),
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc)));
end if;
-- 1) Generate the primary tag entities
-- Primary dispatch table containing user-defined primitives
DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
Set_Etype (DT_Ptr, RTE (RE_Tag));
Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
-- Minimum decoration
Set_Ekind (DT_Ptr, E_Variable);
Set_Related_Type (DT_Ptr, Typ);
-- Notify back end that the types are associated with a dispatch table
Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
-- For CPP types there is no need to build the dispatch tables since
-- they are imported from the C++ side. If the CPP type has an IP then
-- we declare now the variable that will store the copy of the C++ tag.
-- If the CPP type is an interface, we need the variable as well because
-- it becomes the pointer to the corresponding secondary table.
if Is_CPP_Class (Typ) then
if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT_Ptr,
Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
Set_Is_Statically_Allocated (DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
end if;
-- Ada types
else
-- Primary dispatch table containing predefined primitives
Predef_Prims_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Tname, 'Y'));
Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
-- Import the forward declaration of the Dispatch Table wrapper
-- record (Make_DT will take care of exporting it).
if Building_Static_DT (Typ) then
Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
DT :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Tname, 'T'));
Import_DT (Typ, DT, Is_Secondary_DT => False);
if Has_DT (Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT_Ptr,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Prims_Ptr), Loc)),
Attribute_Name => Name_Address))));
-- Generate the SCIL node for the previous object declaration
-- because it has a tag initialization.
if Generate_SCIL then
New_Node :=
Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
Set_SCIL_Entity (New_Node, Typ);
Set_SCIL_Node (Last (Result), New_Node);
end if;
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Predef_Prims_Ptr,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Predef_Prims), Loc)),
Attribute_Name => Name_Address)));
-- No dispatch table required
else
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => DT_Ptr,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_NDT_Prims_Ptr),
Loc)),
Attribute_Name => Name_Address))));
end if;
Set_Is_True_Constant (DT_Ptr);
Set_Is_Statically_Allocated (DT_Ptr);
end if;
end if;
-- 2) Generate the secondary tag entities
-- Collect the components associated with secondary dispatch tables
if Has_Interfaces (Typ) then
Collect_Interface_Components (Typ, Typ_Comps);
-- For each interface type we build a unique external name associated
-- with its secondary dispatch table. This name is used to declare an
-- object that references this secondary dispatch table, whose value
-- will be used for the elaboration of Typ objects, and also for the
-- elaboration of objects of types derived from Typ that do not
-- override the primitives of this interface type.
Suffix_Index := 1;
-- Note: The value of Suffix_Index must be in sync with the values of
-- Suffix_Index in secondary dispatch tables generated by Make_DT.
if Is_CPP_Class (Typ) then
AI_Tag_Comp := First_Elmt (Typ_Comps);
while Present (AI_Tag_Comp) loop
Get_Secondary_DT_External_Name
(Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
Typ_Name := Name_Find;
-- Declare variables to store copy of the C++ secondary tags
Iface_DT_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'P'));
Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
Set_Ekind (Iface_DT_Ptr, E_Variable);
Set_Is_Tag (Iface_DT_Ptr);
Set_Has_Thunks (Iface_DT_Ptr);
Set_Related_Type
(Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Iface_DT_Ptr,
Object_Definition => New_Occurrence_Of
(RTE (RE_Interface_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Interface_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
Set_Is_Statically_Allocated (Iface_DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
Next_Elmt (AI_Tag_Comp);
end loop;
-- This is not a CPP_Class type
else
AI_Tag_Comp := First_Elmt (Typ_Comps);
while Present (AI_Tag_Comp) loop
Get_Secondary_DT_External_Name
(Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
Typ_Name := Name_Find;
if Building_Static_DT (Typ) then
Iface_DT :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'T'));
Import_DT
(Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
DT => Iface_DT,
Is_Secondary_DT => True);
end if;
-- Secondary dispatch table referencing thunks to user-defined
-- primitives covered by this interface.
Iface_DT_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'P'));
Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
Set_Ekind (Iface_DT_Ptr, E_Constant);
Set_Is_Tag (Iface_DT_Ptr);
Set_Has_Thunks (Iface_DT_Ptr);
Set_Is_Statically_Allocated (Iface_DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
Set_Is_True_Constant (Iface_DT_Ptr);
Set_Related_Type
(Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
if Building_Static_DT (Typ) then
Append_To (Result,
Make_Object_Declaration (Loc,
Defining_Identifier => Iface_DT_Ptr,
Constant_Present => True,
Object_Definition => New_Occurrence_Of
(RTE (RE_Interface_Tag), Loc),
Expression =>
Unchecked_Convert_To (RTE (RE_Interface_Tag),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Iface_DT, Loc),
Selector_Name =>
New_Occurrence_Of
(RTE_Record_Component (RE_Prims_Ptr),
Loc)),
Attribute_Name => Name_Address))));
end if;
-- Secondary dispatch table referencing thunks to predefined
-- primitives.
Iface_DT_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'Y'));
Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
Set_Ekind (Iface_DT_Ptr, E_Constant);
Set_Is_Tag (Iface_DT_Ptr);
Set_Has_Thunks (Iface_DT_Ptr);
Set_Is_Statically_Allocated (Iface_DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
Set_Is_True_Constant (Iface_DT_Ptr);
Set_Related_Type
(Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
-- Secondary dispatch table referencing user-defined primitives
-- covered by this interface.
Iface_DT_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'D'));
Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
Set_Ekind (Iface_DT_Ptr, E_Constant);
Set_Is_Tag (Iface_DT_Ptr);
Set_Is_Statically_Allocated (Iface_DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
Set_Is_True_Constant (Iface_DT_Ptr);
Set_Related_Type
(Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
-- Secondary dispatch table referencing predefined primitives
Iface_DT_Ptr :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Typ_Name, 'Z'));
Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
Set_Ekind (Iface_DT_Ptr, E_Constant);
Set_Is_Tag (Iface_DT_Ptr);
Set_Is_Statically_Allocated (Iface_DT_Ptr,
Is_Library_Level_Tagged_Type (Typ));
Set_Is_True_Constant (Iface_DT_Ptr);
Set_Related_Type
(Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
Next_Elmt (AI_Tag_Comp);
end loop;
end if;
end if;
-- 3) At the end of Access_Disp_Table, if the type has user-defined
-- primitives, we add the entity of an access type declaration that
-- is used by Build_Get_Prim_Op_Address to expand dispatching calls
-- through the primary dispatch table.
if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
Analyze_List (Result);
-- Generate:
-- subtype Typ_DT is Address_Array (1 .. Nb_Prims);
-- type Typ_DT_Acc is access Typ_DT;
else
declare
Name_DT_Prims : constant Name_Id :=
New_External_Name (Tname, 'G');
Name_DT_Prims_Acc : constant Name_Id :=
New_External_Name (Tname, 'H');
DT_Prims : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Name_DT_Prims);
DT_Prims_Acc : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Name_DT_Prims_Acc);
begin
Append_To (Result,
Make_Subtype_Declaration (Loc,
Defining_Identifier => DT_Prims,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Address_Array), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc, New_List (
Make_Range (Loc,
Low_Bound => Make_Integer_Literal (Loc, 1),
High_Bound =>
Make_Integer_Literal (Loc,
DT_Entry_Count
(First_Tag_Component (Typ)))))))));
Append_To (Result,
Make_Full_Type_Declaration (Loc,
Defining_Identifier => DT_Prims_Acc,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (DT_Prims, Loc))));
Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
-- Analyze the resulting list and suppress the generation of the
-- Init_Proc associated with the above array declaration because
-- this type is never used in object declarations. It is only used
-- to simplify the expansion associated with dispatching calls.
Analyze_List (Result);
Set_Suppress_Initialization (Base_Type (DT_Prims));
-- Disable backend optimizations based on assumptions about the
-- aliasing status of objects designated by the access to the
-- dispatch table. Required to handle dispatch tables imported
-- from C++.
Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
-- Add the freezing nodes of these declarations; required to avoid
-- generating these freezing nodes in wrong scopes (for example in
-- the IC routine of a derivation of Typ).
-- What is an "IC routine"? Is "init_proc" meant here???
Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
-- Mark entity of dispatch table. Required by the back end to
-- handle them properly.
Set_Is_Dispatch_Table_Entity (DT_Prims);
end;
end if;
-- Mark entities of dispatch table. Required by the back end to handle
-- them properly.
if Present (DT) then
Set_Is_Dispatch_Table_Entity (DT);
Set_Is_Dispatch_Table_Entity (Etype (DT));
end if;
if Present (Iface_DT) then
Set_Is_Dispatch_Table_Entity (Iface_DT);
Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
end if;
if Is_CPP_Class (Root_Type (Typ)) then
Set_Ekind (DT_Ptr, E_Variable);
else
Set_Ekind (DT_Ptr, E_Constant);
end if;
Set_Is_Tag (DT_Ptr);
Set_Related_Type (DT_Ptr, Typ);
return Result;
end Make_Tags;
---------------
-- New_Value --
---------------
function New_Value (From : Node_Id) return Node_Id is
Res : constant Node_Id := Duplicate_Subexpr (From);
begin
if Is_Access_Type (Etype (From)) then
return Make_Explicit_Dereference (Sloc (From), Prefix => Res);
else
return Res;
end if;
end New_Value;
-----------------------------------
-- Original_View_In_Visible_Part --
-----------------------------------
function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
Scop : constant Entity_Id := Scope (Typ);
begin
-- The scope must be a package
if not Is_Package_Or_Generic_Package (Scop) then
return False;
end if;
-- A type with a private declaration has a private view declared in
-- the visible part.
if Has_Private_Declaration (Typ) then
return True;
end if;
return List_Containing (Parent (Typ)) =
Visible_Declarations (Package_Specification (Scop));
end Original_View_In_Visible_Part;
------------------
-- Prim_Op_Kind --
------------------
function Prim_Op_Kind
(Prim : Entity_Id;
Typ : Entity_Id) return Node_Id
is
Full_Typ : Entity_Id := Typ;
Loc : constant Source_Ptr := Sloc (Prim);
Prim_Op : Entity_Id;
begin
-- Retrieve the original primitive operation
Prim_Op := Ultimate_Alias (Prim);
if Ekind (Typ) = E_Record_Type
and then Present (Corresponding_Concurrent_Type (Typ))
then
Full_Typ := Corresponding_Concurrent_Type (Typ);
end if;
-- When a private tagged type is completed by a concurrent type,
-- retrieve the full view.
if Is_Private_Type (Full_Typ) then
Full_Typ := Full_View (Full_Typ);
end if;
if Ekind (Prim_Op) = E_Function then
-- Protected function
if Ekind (Full_Typ) = E_Protected_Type then
return New_Occurrence_Of (RTE (RE_POK_Protected_Function), Loc);
-- Task function
elsif Ekind (Full_Typ) = E_Task_Type then
return New_Occurrence_Of (RTE (RE_POK_Task_Function), Loc);
-- Regular function
else
return New_Occurrence_Of (RTE (RE_POK_Function), Loc);
end if;
else
pragma Assert (Ekind (Prim_Op) = E_Procedure);
if Ekind (Full_Typ) = E_Protected_Type then
-- Protected entry
if Is_Primitive_Wrapper (Prim_Op)
and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
then
return New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc);
-- Protected procedure
else
return
New_Occurrence_Of (RTE (RE_POK_Protected_Procedure), Loc);
end if;
elsif Ekind (Full_Typ) = E_Task_Type then
-- Task entry
if Is_Primitive_Wrapper (Prim_Op)
and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
then
return New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc);
-- Task "procedure". These are the internally Expander-generated
-- procedures (task body for instance).
else
return New_Occurrence_Of (RTE (RE_POK_Task_Procedure), Loc);
end if;
-- Regular procedure
else
return New_Occurrence_Of (RTE (RE_POK_Procedure), Loc);
end if;
end if;
end Prim_Op_Kind;
------------------------
-- Register_Primitive --
------------------------
function Register_Primitive
(Loc : Source_Ptr;
Prim : Entity_Id) return List_Id
is
DT_Ptr : Entity_Id;
Iface_Prim : Entity_Id;
Iface_Typ : Entity_Id;
Iface_DT_Ptr : Entity_Id;
Iface_DT_Elmt : Elmt_Id;
L : constant List_Id := New_List;
Pos : Uint;
Tag : Entity_Id;
Tag_Typ : Entity_Id;
Thunk_Id : Entity_Id;
Thunk_Code : Node_Id;
begin
pragma Assert (not Restriction_Active (No_Dispatching_Calls));
-- Do not register in the dispatch table eliminated primitives
if not RTE_Available (RE_Tag)
or else Is_Eliminated (Ultimate_Alias (Prim))
or else Generate_SCIL
then
return L;
end if;
if not Present (Interface_Alias (Prim)) then
Tag_Typ := Scope (DTC_Entity (Prim));
Pos := DT_Position (Prim);
Tag := First_Tag_Component (Tag_Typ);
if Is_Predefined_Dispatching_Operation (Prim)
or else Is_Predefined_Dispatching_Alias (Prim)
then
DT_Ptr :=
Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
Append_To (L,
Build_Set_Predefined_Prim_Op_Address (Loc,
Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim, Loc),
Attribute_Name => Name_Unrestricted_Access))));
-- Register copy of the pointer to the 'size primitive in the TSD
if Chars (Prim) = Name_uSize
and then RTE_Record_Component_Available (RE_Size_Func)
then
DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
Append_To (L,
Build_Set_Size_Function (Loc,
Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
Size_Func => Prim));
end if;
else
pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
-- Skip registration of primitives located in the C++ part of the
-- dispatch table. Their slot is set by the IC routine.
if not Is_CPP_Class (Root_Type (Tag_Typ))
or else Pos > CPP_Num_Prims (Tag_Typ)
then
DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
Append_To (L,
Build_Set_Prim_Op_Address (Loc,
Typ => Tag_Typ,
Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Prim, Loc),
Attribute_Name => Name_Unrestricted_Access))));
end if;
end if;
-- Ada 2005 (AI-251): Primitive associated with an interface type
-- Generate the code of the thunk only if the interface type is not an
-- immediate ancestor of Typ; otherwise the dispatch table associated
-- with the interface is the primary dispatch table and we have nothing
-- else to do here.
else
Tag_Typ := Find_Dispatching_Type (Alias (Prim));
Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
pragma Assert (Is_Interface (Iface_Typ));
-- No action needed for interfaces that are ancestors of Typ because
-- their primitives are located in the primary dispatch table.
if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
return L;
-- No action needed for primitives located in the C++ part of the
-- dispatch table. Their slot is set by the IC routine.
elsif Is_CPP_Class (Root_Type (Tag_Typ))
and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
and then not Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Predefined_Dispatching_Alias (Prim)
then
return L;
end if;
Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code, Iface_Typ);
if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
and then Present (Thunk_Code)
then
-- Generate the code necessary to fill the appropriate entry of
-- the secondary dispatch table of Prim's controlling type with
-- Thunk_Id's address.
Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
Iface_DT_Ptr := Node (Iface_DT_Elmt);
pragma Assert (Has_Thunks (Iface_DT_Ptr));
Iface_Prim := Interface_Alias (Prim);
Pos := DT_Position (Iface_Prim);
Tag := First_Tag_Component (Iface_Typ);
Prepend_To (L, Thunk_Code);
if Is_Predefined_Dispatching_Operation (Prim)
or else Is_Predefined_Dispatching_Alias (Prim)
then
Append_To (L,
Build_Set_Predefined_Prim_Op_Address (Loc,
Tag_Node =>
New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Thunk_Id, Loc),
Attribute_Name => Name_Unrestricted_Access))));
Next_Elmt (Iface_DT_Elmt);
Next_Elmt (Iface_DT_Elmt);
Iface_DT_Ptr := Node (Iface_DT_Elmt);
pragma Assert (not Has_Thunks (Iface_DT_Ptr));
Append_To (L,
Build_Set_Predefined_Prim_Op_Address (Loc,
Tag_Node =>
New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Alias (Prim), Loc),
Attribute_Name => Name_Unrestricted_Access))));
else
pragma Assert (Pos /= Uint_0
and then Pos <= DT_Entry_Count (Tag));
Append_To (L,
Build_Set_Prim_Op_Address (Loc,
Typ => Iface_Typ,
Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Thunk_Id, Loc),
Attribute_Name => Name_Unrestricted_Access))));
Next_Elmt (Iface_DT_Elmt);
Next_Elmt (Iface_DT_Elmt);
Iface_DT_Ptr := Node (Iface_DT_Elmt);
pragma Assert (not Has_Thunks (Iface_DT_Ptr));
Append_To (L,
Build_Set_Prim_Op_Address (Loc,
Typ => Iface_Typ,
Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
Position => Pos,
Address_Node =>
Unchecked_Convert_To (RTE (RE_Prim_Ptr),
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Ultimate_Alias (Prim), Loc),
Attribute_Name => Name_Unrestricted_Access))));
end if;
end if;
end if;
return L;
end Register_Primitive;
-------------------------
-- Set_All_DT_Position --
-------------------------
procedure Set_All_DT_Position (Typ : Entity_Id) is
function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
-- Returns True if Prim is located in the dispatch table of
-- predefined primitives
procedure Validate_Position (Prim : Entity_Id);
-- Check that position assigned to Prim is completely safe (it has not
-- been assigned to a previously defined primitive operation of Typ).
------------------------
-- In_Predef_Prims_DT --
------------------------
function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
begin
-- Predefined primitives
if Is_Predefined_Dispatching_Operation (Prim) then
return True;
-- Renamings of predefined primitives
elsif Present (Alias (Prim))
and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
then
if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
return True;
-- An overriding operation that is a user-defined renaming of
-- predefined equality inherits its slot from the overridden
-- operation. Otherwise it is treated as a predefined op and
-- occupies the same predefined slot as equality. A call to it is
-- transformed into a call to its alias, which is the predefined
-- equality op. A dispatching call thus uses the proper slot if
-- operation is further inherited and called with class-wide
-- arguments.
else
return
not Comes_From_Source (Prim)
or else No (Overridden_Operation (Prim));
end if;
-- User-defined primitives
else
return False;
end if;
end In_Predef_Prims_DT;
-----------------------
-- Validate_Position --
-----------------------
procedure Validate_Position (Prim : Entity_Id) is
Op_Elmt : Elmt_Id;
Op : Entity_Id;
begin
-- Aliased primitives are safe
if Present (Alias (Prim)) then
return;
end if;
Op_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Op_Elmt) loop
Op := Node (Op_Elmt);
-- No need to check against itself
if Op = Prim then
null;
-- Primitive operations covering abstract interfaces are
-- allocated later
elsif Present (Interface_Alias (Op)) then
null;
-- Predefined dispatching operations are completely safe. They
-- are allocated at fixed positions in a separate table.
elsif Is_Predefined_Dispatching_Operation (Op)
or else Is_Predefined_Dispatching_Alias (Op)
then
null;
-- Aliased subprograms are safe
elsif Present (Alias (Op)) then
null;
elsif DT_Position (Op) = DT_Position (Prim)
and then not Is_Predefined_Dispatching_Operation (Op)
and then not Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Predefined_Dispatching_Alias (Op)
and then not Is_Predefined_Dispatching_Alias (Prim)
then
-- Handle aliased subprograms
declare
Op_1 : Entity_Id;
Op_2 : Entity_Id;
begin
Op_1 := Op;
loop
if Present (Overridden_Operation (Op_1)) then
Op_1 := Overridden_Operation (Op_1);
elsif Present (Alias (Op_1)) then
Op_1 := Alias (Op_1);
else
exit;
end if;
end loop;
Op_2 := Prim;
loop
if Present (Overridden_Operation (Op_2)) then
Op_2 := Overridden_Operation (Op_2);
elsif Present (Alias (Op_2)) then
Op_2 := Alias (Op_2);
else
exit;
end if;
end loop;
if Op_1 /= Op_2 then
raise Program_Error;
end if;
end;
end if;
Next_Elmt (Op_Elmt);
end loop;
end Validate_Position;
-- Local variables
Parent_Typ : constant Entity_Id := Etype (Typ);
First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
The_Tag : constant Entity_Id := First_Tag_Component (Typ);
Adjusted : Boolean := False;
Finalized : Boolean := False;
Count_Prim : Nat;
DT_Length : Nat;
Nb_Prim : Nat;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
-- Start of processing for Set_All_DT_Position
begin
pragma Assert (Present (First_Tag_Component (Typ)));
-- Set the DT_Position for each primitive operation. Perform some sanity
-- checks to avoid building inconsistent dispatch tables.
-- First stage: Set DTC entity of all the primitive operations. This is
-- required to properly read the DT_Position attribute in latter stages.
Prim_Elmt := First_Prim;
Count_Prim := 0;
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- Predefined primitives have a separate dispatch table
if not In_Predef_Prims_DT (Prim) then
Count_Prim := Count_Prim + 1;
end if;
Set_DTC_Entity_Value (Typ, Prim);
-- Clear any previous value of the DT_Position attribute. In this
-- way we ensure that the final position of all the primitives is
-- established by the following stages of this algorithm.
Set_DT_Position_Value (Prim, No_Uint);
Next_Elmt (Prim_Elmt);
end loop;
declare
Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
(others => False);
E : Entity_Id;
procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
-- Called if Typ is declared in a nested package or a public child
-- package to handle inherited primitives that were inherited by Typ
-- in the visible part, but whose declaration was deferred because
-- the parent operation was private and not visible at that point.
procedure Set_Fixed_Prim (Pos : Nat);
-- Sets to true an element of the Fixed_Prim table to indicate
-- that this entry of the dispatch table of Typ is occupied.
------------------------------------------
-- Handle_Inherited_Private_Subprograms --
------------------------------------------
procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
Op_List : Elist_Id;
Op_Elmt : Elmt_Id;
Op_Elmt_2 : Elmt_Id;
Prim_Op : Entity_Id;
Parent_Subp : Entity_Id;
begin
Op_List := Primitive_Operations (Typ);
Op_Elmt := First_Elmt (Op_List);
while Present (Op_Elmt) loop
Prim_Op := Node (Op_Elmt);
-- Search primitives that are implicit operations with an
-- internal name whose parent operation has a normal name.
if Present (Alias (Prim_Op))
and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
and then not Comes_From_Source (Prim_Op)
and then Is_Internal_Name (Chars (Prim_Op))
and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
then
Parent_Subp := Alias (Prim_Op);
-- Check if the type has an explicit overriding for this
-- primitive.
Op_Elmt_2 := Next_Elmt (Op_Elmt);
while Present (Op_Elmt_2) loop
if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
then
Set_DT_Position_Value (Prim_Op,
DT_Position (Parent_Subp));
Set_DT_Position_Value (Node (Op_Elmt_2),
DT_Position (Parent_Subp));
Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
goto Next_Primitive;
end if;
Next_Elmt (Op_Elmt_2);
end loop;
end if;
<<Next_Primitive>>
Next_Elmt (Op_Elmt);
end loop;
end Handle_Inherited_Private_Subprograms;
--------------------
-- Set_Fixed_Prim --
--------------------
procedure Set_Fixed_Prim (Pos : Nat) is
begin
pragma Assert (Pos <= Count_Prim);
Fixed_Prim (Pos) := True;
exception
when Constraint_Error =>
raise Program_Error;
end Set_Fixed_Prim;
begin
-- In case of nested packages and public child package it may be
-- necessary a special management on inherited subprograms so that
-- the dispatch table is properly filled.
if Ekind (Scope (Scope (Typ))) = E_Package
and then Scope (Scope (Typ)) /= Standard_Standard
and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
or else
(Nkind (Parent (Typ)) = N_Private_Extension_Declaration
and then Is_Generic_Type (Typ)))
and then In_Open_Scopes (Scope (Etype (Typ)))
and then Is_Base_Type (Typ)
then
Handle_Inherited_Private_Subprograms (Typ);
end if;
-- Second stage: Register fixed entries
Nb_Prim := 0;
Prim_Elmt := First_Prim;
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- Predefined primitives have a separate table and all its
-- entries are at predefined fixed positions.
if In_Predef_Prims_DT (Prim) then
if Is_Predefined_Dispatching_Operation (Prim) then
Set_DT_Position_Value (Prim,
Default_Prim_Op_Position (Prim));
else pragma Assert (Present (Alias (Prim)));
Set_DT_Position_Value (Prim,
Default_Prim_Op_Position (Ultimate_Alias (Prim)));
end if;
-- Overriding primitives of ancestor abstract interfaces
elsif Present (Interface_Alias (Prim))
and then Is_Ancestor
(Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
Use_Full_View => True)
then
pragma Assert (DT_Position (Prim) = No_Uint
and then Present (DTC_Entity (Interface_Alias (Prim))));
E := Interface_Alias (Prim);
Set_DT_Position_Value (Prim, DT_Position (E));
pragma Assert
(DT_Position (Alias (Prim)) = No_Uint
or else DT_Position (Alias (Prim)) = DT_Position (E));
Set_DT_Position_Value (Alias (Prim), DT_Position (E));
Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
-- Overriding primitives must use the same entry as the overridden
-- primitive. Note that the Alias of the operation is set when the
-- operation is declared by a renaming, in which case it is not
-- overriding. If it renames another primitive it will use the
-- same dispatch table slot, but if it renames an operation in a
-- nested package it's a new primitive and will have its own slot.
elsif not Present (Interface_Alias (Prim))
and then Present (Alias (Prim))
and then Chars (Prim) = Chars (Alias (Prim))
and then Nkind (Unit_Declaration_Node (Prim)) /=
N_Subprogram_Renaming_Declaration
then
declare
Par_Type : constant Entity_Id :=
Find_Dispatching_Type (Alias (Prim));
begin
if Present (Par_Type)
and then Par_Type /= Typ
and then Is_Ancestor (Par_Type, Typ, Use_Full_View => True)
and then Present (DTC_Entity (Alias (Prim)))
then
E := Alias (Prim);
Set_DT_Position_Value (Prim, DT_Position (E));
if not Is_Predefined_Dispatching_Alias (E) then
Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
end if;
end if;
end;
end if;
Next_Elmt (Prim_Elmt);
end loop;
-- Third stage: Fix the position of all the new primitives. Entries
-- associated with primitives covering interfaces are handled in a
-- latter round.
Prim_Elmt := First_Prim;
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- Skip primitives previously set entries
if DT_Position (Prim) /= No_Uint then
null;
-- Primitives covering interface primitives are handled later
elsif Present (Interface_Alias (Prim)) then
null;
else
-- Take the next available position in the DT
loop
Nb_Prim := Nb_Prim + 1;
pragma Assert (Nb_Prim <= Count_Prim);
exit when not Fixed_Prim (Nb_Prim);
end loop;
Set_DT_Position_Value (Prim, UI_From_Int (Nb_Prim));
Set_Fixed_Prim (Nb_Prim);
end if;
Next_Elmt (Prim_Elmt);
end loop;
end;
-- Fourth stage: Complete the decoration of primitives covering
-- interfaces (that is, propagate the DT_Position attribute from
-- the aliased primitive)
Prim_Elmt := First_Prim;
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if DT_Position (Prim) = No_Uint
and then Present (Interface_Alias (Prim))
then
pragma Assert (Present (Alias (Prim))
and then Find_Dispatching_Type (Alias (Prim)) = Typ);
-- Check if this entry will be placed in the primary DT
if Is_Ancestor
(Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
Use_Full_View => True)
then
pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
Set_DT_Position_Value (Prim, DT_Position (Alias (Prim)));
-- Otherwise it will be placed in the secondary DT
else
pragma Assert
(DT_Position (Interface_Alias (Prim)) /= No_Uint);
Set_DT_Position_Value (Prim,
DT_Position (Interface_Alias (Prim)));
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
-- Generate listing showing the contents of the dispatch tables. This
-- action is done before some further static checks because in case of
-- critical errors caused by a wrong dispatch table we need to see the
-- contents of such table.
if Debug_Flag_ZZ then
Write_DT (Typ);
end if;
-- Final stage: Ensure that the table is correct plus some further
-- verifications concerning the primitives.
Prim_Elmt := First_Prim;
DT_Length := 0;
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
-- At this point all the primitives MUST have a position in the
-- dispatch table.
if DT_Position (Prim) = No_Uint then
raise Program_Error;
end if;
-- Calculate real size of the dispatch table
if not In_Predef_Prims_DT (Prim)
and then UI_To_Int (DT_Position (Prim)) > DT_Length
then
DT_Length := UI_To_Int (DT_Position (Prim));
end if;
-- Ensure that the assigned position to non-predefined dispatching
-- operations in the dispatch table is correct.
if not Is_Predefined_Dispatching_Operation (Prim)
and then not Is_Predefined_Dispatching_Alias (Prim)
then
Validate_Position (Prim);
end if;
if Chars (Prim) = Name_Finalize then
Finalized := True;
end if;
if Chars (Prim) = Name_Adjust then
Adjusted := True;
end if;
-- An abstract operation cannot be declared in the private part for a
-- visible abstract type, because it can't be overridden outside this
-- package hierarchy. For explicit declarations this is checked at
-- the point of declaration, but for inherited operations it must be
-- done when building the dispatch table.
-- Ada 2005 (AI-251): Primitives associated with interfaces are
-- excluded from this check because interfaces must be visible in
-- the public and private part (RM 7.3 (7.3/2))
-- We disable this check in Relaxed_RM_Semantics mode, to accommodate
-- legacy Ada code.
if not Relaxed_RM_Semantics
and then Is_Abstract_Type (Typ)
and then Is_Abstract_Subprogram (Prim)
and then Present (Alias (Prim))
and then not Is_Interface
(Find_Dispatching_Type (Ultimate_Alias (Prim)))
and then not Present (Interface_Alias (Prim))
and then Is_Derived_Type (Typ)
and then In_Private_Part (Current_Scope)
and then
List_Containing (Parent (Prim)) =
Private_Declarations (Package_Specification (Current_Scope))
and then Original_View_In_Visible_Part (Typ)
then
-- We exclude Input and Output stream operations because
-- Limited_Controlled inherits useless Input and Output stream
-- operations from Root_Controlled, which can never be overridden.
-- Move this check to sem???
if not Is_TSS (Prim, TSS_Stream_Input)
and then
not Is_TSS (Prim, TSS_Stream_Output)
then
Error_Msg_NE
("abstract inherited private operation&" &
" must be overridden (RM 3.9.3(10))",
Parent (Typ), Prim);
end if;
end if;
Next_Elmt (Prim_Elmt);
end loop;
-- Additional check
if Is_Controlled (Typ) then
if not Finalized then
Error_Msg_N
("controlled type has no explicit Finalize method??", Typ);
elsif not Adjusted then
Error_Msg_N
("controlled type has no explicit Adjust method??", Typ);
end if;
end if;
-- Set the final size of the Dispatch Table
Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
-- The derived type must have at least as many components as its parent
-- (for root types Etype points to itself and the test cannot fail).
if DT_Entry_Count (The_Tag) <
DT_Entry_Count (First_Tag_Component (Parent_Typ))
then
raise Program_Error;
end if;
end Set_All_DT_Position;
--------------------------
-- Set_CPP_Constructors --
--------------------------
procedure Set_CPP_Constructors (Typ : Entity_Id) is
function Gen_Parameters_Profile (E : Entity_Id) return List_Id;
-- Duplicate the parameters profile of the imported C++ constructor
-- adding the "this" pointer to the object as the additional first
-- parameter under the usual form _Init : in out Typ.
----------------------------
-- Gen_Parameters_Profile --
----------------------------
function Gen_Parameters_Profile (E : Entity_Id) return List_Id is
Loc : constant Source_Ptr := Sloc (E);
Parms : List_Id;
P : Node_Id;
begin
Parms :=
New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uInit),
In_Present => True,
Out_Present => True,
Parameter_Type => New_Occurrence_Of (Typ, Loc)));
if Present (Parameter_Specifications (Parent (E))) then
P := First (Parameter_Specifications (Parent (E)));
while Present (P) loop
Append_To (Parms,
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
Chars => Chars (Defining_Identifier (P))),
Parameter_Type => New_Copy_Tree (Parameter_Type (P)),
Expression => New_Copy_Tree (Expression (P))));
Next (P);
end loop;
end if;
return Parms;
end Gen_Parameters_Profile;
-- Local variables
Loc : Source_Ptr;
E : Entity_Id;
Found : Boolean := False;
IP : Entity_Id;
IP_Body : Node_Id;
P : Node_Id;
Parms : List_Id;
Covers_Default_Constructor : Entity_Id := Empty;
-- Start of processing for Set_CPP_Constructor
begin
pragma Assert (Is_CPP_Class (Typ));
-- Look for the constructor entities
E := Next_Entity (Typ);
while Present (E) loop
if Ekind (E) = E_Function
and then Is_Constructor (E)
then
Found := True;
Loc := Sloc (E);
Parms := Gen_Parameters_Profile (E);
IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
-- Case 1: Constructor of untagged type
-- If the C++ class has no virtual methods then the matching Ada
-- type is an untagged record type. In such case there is no need
-- to generate a wrapper of the C++ constructor because the _tag
-- component is not available.
if not Is_Tagged_Type (Typ) then
Discard_Node
(Make_Subprogram_Declaration (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => IP,
Parameter_Specifications => Parms)));
Set_Init_Proc (Typ, IP);
Set_Is_Imported (IP);
Set_Is_Constructor (IP);
Set_Interface_Name (IP, Interface_Name (E));
Set_Convention (IP, Convention_CPP);
Set_Is_Public (IP);
Set_Has_Completion (IP);
-- Case 2: Constructor of a tagged type
-- In this case we generate the IP routine as a wrapper of the
-- C++ constructor because IP must also save a copy of the _tag
-- generated in the C++ side. The copy of the _tag is used by
-- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
-- Generate:
-- procedure IP (_init : in out Typ; ...) is
-- procedure ConstructorP (_init : in out Typ; ...);
-- pragma Import (ConstructorP);
-- begin
-- ConstructorP (_init, ...);
-- if Typ._tag = null then
-- Typ._tag := _init._tag;
-- end if;
-- end IP;
else
declare
Body_Stmts : constant List_Id := New_List;
Constructor_Id : Entity_Id;
Constructor_Decl_Node : Node_Id;
Init_Tags_List : List_Id;
begin
Constructor_Id := Make_Temporary (Loc, 'P');
Constructor_Decl_Node :=
Make_Subprogram_Declaration (Loc,
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Constructor_Id,
Parameter_Specifications => Parms));
Set_Is_Imported (Constructor_Id);
Set_Is_Constructor (Constructor_Id);
Set_Interface_Name (Constructor_Id, Interface_Name (E));
Set_Convention (Constructor_Id, Convention_CPP);
Set_Is_Public (Constructor_Id);
Set_Has_Completion (Constructor_Id);
-- Build the init procedure as a wrapper of this constructor
Parms := Gen_Parameters_Profile (E);
-- Invoke the C++ constructor
declare
Actuals : constant List_Id := New_List;
begin
P := First (Parms);
while Present (P) loop
Append_To (Actuals,
New_Occurrence_Of (Defining_Identifier (P), Loc));
Next (P);
end loop;
Append_To (Body_Stmts,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Constructor_Id, Loc),
Parameter_Associations => Actuals));
end;
-- Initialize copies of C++ primary and secondary tags
Init_Tags_List := New_List;
declare
Tag_Elmt : Elmt_Id;
Tag_Comp : Node_Id;
begin
Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
Tag_Comp := First_Tag_Component (Typ);
while Present (Tag_Elmt)
and then Is_Tag (Node (Tag_Elmt))
loop
-- Skip the following assertion with primary tags
-- because Related_Type is not set on primary tag
-- components.
pragma Assert
(Tag_Comp = First_Tag_Component (Typ)
or else Related_Type (Node (Tag_Elmt))
= Related_Type (Tag_Comp));
Append_To (Init_Tags_List,
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of (Node (Tag_Elmt), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Name_uInit),
Selector_Name =>
New_Occurrence_Of (Tag_Comp, Loc))));
Tag_Comp := Next_Tag_Component (Tag_Comp);
Next_Elmt (Tag_Elmt);
end loop;
end;
Append_To (Body_Stmts,
Make_If_Statement (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of
(Node (First_Elmt (Access_Disp_Table (Typ))),
Loc),
Right_Opnd =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Occurrence_Of (RTE (RE_Null_Address), Loc))),
Then_Statements => Init_Tags_List));
IP_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => IP,
Parameter_Specifications => Parms),
Declarations => New_List (Constructor_Decl_Node),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Body_Stmts,
Exception_Handlers => No_List));
Discard_Node (IP_Body);
Set_Init_Proc (Typ, IP);
end;
end if;
-- If this constructor has parameters and all its parameters have
-- defaults then it covers the default constructor. The semantic
-- analyzer ensures that only one constructor with defaults covers
-- the default constructor.
if Present (Parameter_Specifications (Parent (E)))
and then Needs_No_Actuals (E)
then
Covers_Default_Constructor := IP;
end if;
end if;
Next_Entity (E);
end loop;
-- If there are no constructors, mark the type as abstract since we
-- won't be able to declare objects of that type.
if not Found then
Set_Is_Abstract_Type (Typ);
end if;
-- Handle constructor that has all its parameters with defaults and
-- hence it covers the default constructor. We generate a wrapper IP
-- which calls the covering constructor.
if Present (Covers_Default_Constructor) then
declare
Body_Stmts : List_Id;
begin
Loc := Sloc (Covers_Default_Constructor);
Body_Stmts := New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Covers_Default_Constructor, Loc),
Parameter_Associations => New_List (
Make_Identifier (Loc, Name_uInit))));
IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
IP_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => IP,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uInit),
Parameter_Type => New_Occurrence_Of (Typ, Loc)))),
Declarations => No_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Body_Stmts,
Exception_Handlers => No_List));
Discard_Node (IP_Body);
Set_Init_Proc (Typ, IP);
end;
end if;
-- If the CPP type has constructors then it must import also the default
-- C++ constructor. It is required for default initialization of objects
-- of the type. It is also required to elaborate objects of Ada types
-- that are defined as derivations of this CPP type.
if Has_CPP_Constructors (Typ)
and then No (Init_Proc (Typ))
then
Error_Msg_N ("??default constructor must be imported from C++", Typ);
end if;
end Set_CPP_Constructors;
---------------------------
-- Set_DT_Position_Value --
---------------------------
procedure Set_DT_Position_Value (Prim : Entity_Id; Value : Uint) is
begin
Set_DT_Position (Prim, Value);
-- Propagate the value to the wrapped subprogram (if one is present)
if Ekind (Prim) in E_Function | E_Procedure
and then Is_Primitive_Wrapper (Prim)
and then Present (Wrapped_Entity (Prim))
and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
then
Set_DT_Position (Wrapped_Entity (Prim), Value);
end if;
end Set_DT_Position_Value;
--------------------------
-- Set_DTC_Entity_Value --
--------------------------
procedure Set_DTC_Entity_Value
(Tagged_Type : Entity_Id;
Prim : Entity_Id)
is
begin
if Present (Interface_Alias (Prim))
and then Is_Interface
(Find_Dispatching_Type (Interface_Alias (Prim)))
then
Set_DTC_Entity (Prim,
Find_Interface_Tag
(T => Tagged_Type,
Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
else
Set_DTC_Entity (Prim,
First_Tag_Component (Tagged_Type));
end if;
-- Propagate the value to the wrapped subprogram (if one is present)
if Ekind (Prim) in E_Function | E_Procedure
and then Is_Primitive_Wrapper (Prim)
and then Present (Wrapped_Entity (Prim))
and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
then
Set_DTC_Entity (Wrapped_Entity (Prim), DTC_Entity (Prim));
end if;
end Set_DTC_Entity_Value;
-----------------
-- Tagged_Kind --
-----------------
function Tagged_Kind (T : Entity_Id) return Node_Id is
Conc_Typ : Entity_Id;
Loc : constant Source_Ptr := Sloc (T);
begin
pragma Assert
(Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
-- Abstract kinds
if Is_Abstract_Type (T) then
if Is_Limited_Record (T) then
return New_Occurrence_Of
(RTE (RE_TK_Abstract_Limited_Tagged), Loc);
else
return New_Occurrence_Of
(RTE (RE_TK_Abstract_Tagged), Loc);
end if;
-- Concurrent kinds
elsif Is_Concurrent_Record_Type (T) then
Conc_Typ := Corresponding_Concurrent_Type (T);
if Present (Full_View (Conc_Typ)) then
Conc_Typ := Full_View (Conc_Typ);
end if;
if Ekind (Conc_Typ) = E_Protected_Type then
return New_Occurrence_Of (RTE (RE_TK_Protected), Loc);
else
pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
return New_Occurrence_Of (RTE (RE_TK_Task), Loc);
end if;
-- Regular tagged kinds
else
if Is_Limited_Record (T) then
return New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc);
else
return New_Occurrence_Of (RTE (RE_TK_Tagged), Loc);
end if;
end if;
end Tagged_Kind;
--------------
-- Write_DT --
--------------
procedure Write_DT (Typ : Entity_Id) is
Elmt : Elmt_Id;
Prim : Node_Id;
begin
-- Protect this procedure against wrong usage. Required because it will
-- be used directly from GDB
if not (Typ <= Last_Node_Id)
or else not Is_Tagged_Type (Typ)
then
Write_Str ("wrong usage: Write_DT must be used with tagged types");
Write_Eol;
return;
end if;
Write_Int (Int (Typ));
Write_Str (": ");
Write_Name (Chars (Typ));
if Is_Interface (Typ) then
Write_Str (" is interface");
end if;
Write_Eol;
Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Elmt) loop
Prim := Node (Elmt);
Write_Str (" - ");
-- Indicate if this primitive will be allocated in the primary
-- dispatch table or in a secondary dispatch table associated
-- with an abstract interface type
if Present (DTC_Entity (Prim)) then
if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
Write_Str ("[P] ");
else
Write_Str ("[s] ");
end if;
end if;
-- Output the node of this primitive operation and its name
Write_Int (Int (Prim));
Write_Str (": ");
if Is_Predefined_Dispatching_Operation (Prim) then
Write_Str ("(predefined) ");
end if;
-- Prefix the name of the primitive with its corresponding tagged
-- type to facilitate seeing inherited primitives.
if Present (Alias (Prim)) then
Write_Name
(Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
else
Write_Name (Chars (Typ));
end if;
Write_Str (".");
Write_Name (Chars (Prim));
-- Indicate if this primitive has an aliased primitive
if Present (Alias (Prim)) then
Write_Str (" (alias = ");
Write_Int (Int (Alias (Prim)));
-- If the DTC_Entity attribute is already set we can also output
-- the name of the interface covered by this primitive (if any).
if Ekind (Alias (Prim)) in E_Function | E_Procedure
and then Present (DTC_Entity (Alias (Prim)))
and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
then
Write_Str (" from interface ");
Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
end if;
if Present (Interface_Alias (Prim)) then
Write_Str (", AI_Alias of ");
if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
Write_Str ("null primitive ");
end if;
Write_Name
(Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
Write_Char (':');
Write_Int (Int (Interface_Alias (Prim)));
end if;
Write_Str (")");
end if;
-- Display the final position of this primitive in its associated
-- (primary or secondary) dispatch table.
if Present (DTC_Entity (Prim))
and then DT_Position (Prim) /= No_Uint
then
Write_Str (" at #");
Write_Int (UI_To_Int (DT_Position (Prim)));
end if;
if Is_Abstract_Subprogram (Prim) then
Write_Str (" is abstract;");
-- Check if this is a null primitive
elsif Comes_From_Source (Prim)
and then Ekind (Prim) = E_Procedure
and then Null_Present (Parent (Prim))
then
Write_Str (" is null;");
end if;
if Is_Eliminated (Ultimate_Alias (Prim)) then
Write_Str (" (eliminated)");
end if;
if Is_Imported (Prim)
and then Convention (Prim) = Convention_CPP
then
Write_Str (" (C++)");
end if;
Write_Eol;
Next_Elmt (Elmt);
end loop;
end Write_DT;
end Exp_Disp;
|
------------------------------------------------------------------------------
-- --
-- Giza --
-- --
-- Copyright (C) 2015 Fabien Chouteau (chouteau@adacore.com) --
-- --
-- --
-- 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 Giza.Events; use Giza.Events;
with Giza.Context; use Giza.Context;
with Giza.Types; use Giza.Types;
package Giza.Widget is
type Instance is abstract tagged private;
subtype Class is Instance'Class;
type Reference is access all Class;
type Widget_Ref_Array is array (Positive range <>) of Reference;
function Dirty (This : Instance) return Boolean;
procedure Set_Dirty (This : in out Instance; Dirty : Boolean := True);
procedure Draw (This : in out Instance;
Ctx : in out Context.Class;
Force : Boolean := True) is null;
procedure Set_Disabled (This : in out Instance; Disabled : Boolean := True);
-- When a Instance is disabled, it will no longer react to events
procedure Set_Size (This : in out Instance; Size : Size_T);
function Get_Size (This : Instance) return Size_T;
function On_Position_Event
(This : in out Instance;
Evt : Position_Event_Ref;
Pos : Point_T) return Boolean;
function On_Event
(This : in out Instance;
Evt : Event_Not_Null_Ref) return Boolean;
function On_Click
(This : in out Instance;
Pos : Point_T) return Boolean is (False);
function On_Click_Released
(This : in out Instance) return Boolean is (False);
private
type Instance is abstract tagged record
Is_Dirty : Boolean := True;
Is_Disabled : Boolean := False;
Size : Size_T := (0, 0);
-- Next : access Instance'Class := null;
end record;
end Giza.Widget;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V A L _ R E A L --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Val_Util; use System.Val_Util;
with System.Float_Control;
package body System.Val_Real is
procedure Scan_Integral_Digits
(Str : String;
Index : in out Integer;
Max : Integer;
Value : out Long_Long_Integer;
Scale : out Integer;
Base_Violation : in out Boolean;
Base : Long_Long_Integer := 10;
Base_Specified : Boolean := False);
-- Scan the integral part of a real (i.e: before decimal separator)
--
-- The string parsed is Str (Index .. Max), and after the call Index will
-- point to the first non parsed character.
--
-- For each digit parsed either value := value * base + digit, or scale
-- is incremented by 1.
--
-- Base_Violation will be set to True a digit found is not part of the Base
procedure Scan_Decimal_Digits
(Str : String;
Index : in out Integer;
Max : Integer;
Value : in out Long_Long_Integer;
Scale : in out Integer;
Base_Violation : in out Boolean;
Base : Long_Long_Integer := 10;
Base_Specified : Boolean := False);
-- Scan the decimal part of a real (i.e: after decimal separator)
--
-- The string parsed is Str (Index .. Max), and after the call Index will
-- point to the first non parsed character.
--
-- For each digit parsed value = value * base + digit and scale is
-- decremented by 1. If precision limit is reached remaining digits are
-- still parsed but ignored.
--
-- Base_Violation will be set to True a digit found is not part of the Base
subtype Char_As_Digit is Long_Long_Integer range -2 .. 15;
subtype Valid_Digit is Char_As_Digit range 0 .. Char_As_Digit'Last;
Underscore : constant Char_As_Digit := -2;
E_Digit : constant Char_As_Digit := 14;
function As_Digit (C : Character) return Char_As_Digit;
-- Given a character return the digit it represent. If the character is
-- not a digit then a negative value is returned, -2 for underscore and
-- -1 for any other character.
Precision_Limit : constant Long_Long_Integer :=
2 ** (Long_Long_Float'Machine_Mantissa - 1) - 1;
-- This is an upper bound for the number of bits used to represent the
-- mantissa. Beyond that number, any digits parsed are useless.
--------------
-- As_Digit --
--------------
function As_Digit (C : Character) return Char_As_Digit is
begin
case C is
when '0' .. '9' =>
return Character'Pos (C) - Character'Pos ('0');
when 'a' .. 'f' =>
return Character'Pos (C) - (Character'Pos ('a') - 10);
when 'A' .. 'F' =>
return Character'Pos (C) - (Character'Pos ('A') - 10);
when '_' =>
return Underscore;
when others =>
return -1;
end case;
end As_Digit;
-------------------------
-- Scan_Decimal_Digits --
-------------------------
procedure Scan_Decimal_Digits
(Str : String;
Index : in out Integer;
Max : Integer;
Value : in out Long_Long_Integer;
Scale : in out Integer;
Base_Violation : in out Boolean;
Base : Long_Long_Integer := 10;
Base_Specified : Boolean := False)
is
Precision_Limit_Reached : Boolean := False;
-- Set to True if addition of a digit will cause Value to be superior
-- to Precision_Limit.
Digit : Char_As_Digit;
-- The current digit.
Trailing_Zeros : Natural := 0;
-- Number of trailing zeros at a given point.
begin
pragma Assert (Base in 2 .. 16);
-- If initial Scale is not 0 then it means that Precision_Limit was
-- reached during integral part scanning.
if Scale > 0 then
Precision_Limit_Reached := True;
end if;
-- The function precondition is that the first character is a valid
-- digit.
Digit := As_Digit (Str (Index));
loop
-- Check if base is correct. If the base is not specified the digit
-- E or e cannot be considered as a base violation as it can be used
-- for exponentiation.
if Digit >= Base then
if Base_Specified then
Base_Violation := True;
elsif Digit = E_Digit then
return;
else
Base_Violation := True;
end if;
end if;
-- If precision limit has been reached just ignore any remaining
-- digits for the computation of Value and Scale. The scanning
-- should continue only to assess the validity of the string
if not Precision_Limit_Reached then
if Digit = 0 then
-- Trailing '0' digits are ignored unless a non-zero digit is
-- found.
Trailing_Zeros := Trailing_Zeros + 1;
else
-- Handle accumulated zeros.
for J in 1 .. Trailing_Zeros loop
if Value > Precision_Limit / Base then
Precision_Limit_Reached := True;
exit;
else
Value := Value * Base;
Scale := Scale - 1;
end if;
end loop;
-- Reset trailing zero counter
Trailing_Zeros := 0;
-- Handle current non zero digit
if Value > (Precision_Limit - Digit) / Base then
Precision_Limit_Reached := True;
else
Value := Value * Base + Digit;
Scale := Scale - 1;
end if;
end if;
end if;
-- Check next character
Index := Index + 1;
if Index > Max then
return;
end if;
Digit := As_Digit (Str (Index));
if Digit < 0 then
if Digit = Underscore and Index + 1 <= Max then
-- Underscore is only allowed if followed by a digit
Digit := As_Digit (Str (Index + 1));
if Digit in Valid_Digit then
Index := Index + 1;
else
return;
end if;
else
-- Neither a valid underscore nor a digit.
return;
end if;
end if;
end loop;
end Scan_Decimal_Digits;
--------------------------
-- Scan_Integral_Digits --
--------------------------
procedure Scan_Integral_Digits
(Str : String;
Index : in out Integer;
Max : Integer;
Value : out Long_Long_Integer;
Scale : out Integer;
Base_Violation : in out Boolean;
Base : Long_Long_Integer := 10;
Base_Specified : Boolean := False)
is
Precision_Limit_Reached : Boolean := False;
-- Set to True if addition of a digit will cause Value to be superior
-- to Precision_Limit.
Digit : Char_As_Digit;
-- The current digit
begin
-- Initialize Scale and Value
Value := 0;
Scale := 0;
-- The function precondition is that the first character is a valid
-- digit.
Digit := As_Digit (Str (Index));
loop
-- Check if base is correct. If the base is not specified the digit
-- E or e cannot be considered as a base violation as it can be used
-- for exponentiation.
if Digit >= Base then
if Base_Specified then
Base_Violation := True;
elsif Digit = E_Digit then
return;
else
Base_Violation := True;
end if;
end if;
if Precision_Limit_Reached then
-- Precision limit has been reached so just update the exponent
Scale := Scale + 1;
else
pragma Assert (Base /= 0);
if Value > (Precision_Limit - Digit) / Base then
-- Updating Value will overflow so ignore this digit and any
-- following ones. Only update the scale
Precision_Limit_Reached := True;
Scale := Scale + 1;
else
Value := Value * Base + Digit;
end if;
end if;
-- Look for the next character
Index := Index + 1;
if Index > Max then
return;
end if;
Digit := As_Digit (Str (Index));
if Digit not in Valid_Digit then
-- Next character is not a digit. In that case stop scanning
-- unless the next chracter is an underscore followed by a digit.
if Digit = Underscore and Index + 1 <= Max then
Digit := As_Digit (Str (Index + 1));
if Digit in Valid_Digit then
Index := Index + 1;
else
return;
end if;
else
return;
end if;
end if;
end loop;
end Scan_Integral_Digits;
---------------
-- Scan_Real --
---------------
function Scan_Real
(Str : String;
Ptr : not null access Integer;
Max : Integer)
return Long_Long_Float
is
Start : Positive;
-- Position of starting non-blank character
Minus : Boolean;
-- Set to True if minus sign is present, otherwise to False
Index : Integer;
-- Local copy of string pointer
Int_Value : Long_Long_Integer := -1;
-- Mantissa as an Integer
Int_Scale : Integer := 0;
-- Exponent value
Base_Violation : Boolean := False;
-- If True some digits where not in the base. The float is still scan
-- till the end even if an error will be raised.
Uval : Long_Long_Float := 0.0;
-- Contain the final value at the end of the function
After_Point : Boolean := False;
-- True if a decimal should be parsed
Base : Long_Long_Integer := 10;
-- Current base (default: 10)
Base_Char : Character := ASCII.NUL;
-- Character used to set the base. If Nul this means that default
-- base is used.
begin
-- We do not tolerate strings with Str'Last = Positive'Last
if Str'Last = Positive'Last then
raise Program_Error with
"string upper bound is Positive'Last, not supported";
end if;
-- We call the floating-point processor reset routine so that we can
-- be sure the floating-point processor is properly set for conversion
-- calls. This is notably need on Windows, where calls to the operating
-- system randomly reset the processor into 64-bit mode.
System.Float_Control.Reset;
-- Scan the optional sign
Scan_Sign (Str, Ptr, Max, Minus, Start);
Index := Ptr.all;
Ptr.all := Start;
-- First character can be either a decimal digit or a dot.
if Str (Index) in '0' .. '9' then
pragma Annotate
(CodePeer, Intentional,
"test always true", "defensive code below");
-- If this is a digit it can indicates either the float decimal
-- part or the base to use
Scan_Integral_Digits
(Str,
Index,
Max => Max,
Value => Int_Value,
Scale => Int_Scale,
Base_Violation => Base_Violation,
Base => 10);
elsif Str (Index) = '.' and then
-- A dot is only allowed if followed by a digit.
Index < Max and then
Str (Index + 1) in '0' .. '9'
then
-- Initial point, allowed only if followed by digit (RM 3.5(47))
After_Point := True;
Index := Index + 1;
Int_Value := 0;
else
Bad_Value (Str);
end if;
-- Check if the first number encountered is a base
if Index < Max and then
(Str (Index) = '#' or else Str (Index) = ':')
then
Base_Char := Str (Index);
Base := Int_Value;
-- Reset Int_Value to indicate that parsing of integral value should
-- be done
Int_Value := -1;
if Base < 2 or else Base > 16 then
Base_Violation := True;
Base := 16;
end if;
Index := Index + 1;
if Str (Index) = '.' and then
Index < Max and then
As_Digit (Str (Index + 1)) in Valid_Digit
then
After_Point := True;
Index := Index + 1;
Int_Value := 0;
end if;
end if;
-- Does scanning of integral part needed
if Int_Value < 0 then
if Index > Max or else As_Digit (Str (Index)) not in Valid_Digit then
Bad_Value (Str);
end if;
Scan_Integral_Digits
(Str,
Index,
Max => Max,
Value => Int_Value,
Scale => Int_Scale,
Base_Violation => Base_Violation,
Base => Base,
Base_Specified => Base_Char /= ASCII.NUL);
end if;
-- Do we have a dot ?
if not After_Point and then
Index <= Max and then
Str (Index) = '.'
then
-- At this stage if After_Point was not set, this means that an
-- integral part has been found. Thus the dot is valid even if not
-- followed by a digit.
if Index < Max and then As_Digit (Str (Index + 1)) in Valid_Digit then
After_Point := True;
end if;
Index := Index + 1;
end if;
if After_Point then
-- Parse decimal part
Scan_Decimal_Digits
(Str,
Index,
Max => Max,
Value => Int_Value,
Scale => Int_Scale,
Base_Violation => Base_Violation,
Base => Base,
Base_Specified => Base_Char /= ASCII.NUL);
end if;
-- If an explicit base was specified ensure that the delimiter is found
if Base_Char /= ASCII.NUL then
if Index > Max or else Str (Index) /= Base_Char then
Bad_Value (Str);
else
Index := Index + 1;
end if;
end if;
-- Compute the final value
Uval := Long_Long_Float (Int_Value);
-- Update pointer and scan exponent.
Ptr.all := Index;
Int_Scale := Int_Scale + Scan_Exponent (Str,
Ptr,
Max,
Real => True);
Uval := Uval * Long_Long_Float (Base) ** Int_Scale;
-- Here is where we check for a bad based number
if Base_Violation then
Bad_Value (Str);
-- If OK, then deal with initial minus sign, note that this processing
-- is done even if Uval is zero, so that -0.0 is correctly interpreted.
else
if Minus then
return -Uval;
else
return Uval;
end if;
end if;
end Scan_Real;
----------------
-- Value_Real --
----------------
function Value_Real (Str : String) return Long_Long_Float is
begin
-- We have to special case Str'Last = Positive'Last because the normal
-- circuit ends up setting P to Str'Last + 1 which is out of bounds. We
-- deal with this by converting to a subtype which fixes the bounds.
if Str'Last = Positive'Last then
declare
subtype NT is String (1 .. Str'Length);
begin
return Value_Real (NT (Str));
end;
-- Normal case where Str'Last < Positive'Last
else
declare
V : Long_Long_Float;
P : aliased Integer := Str'First;
begin
V := Scan_Real (Str, P'Access, Str'Last);
Scan_Trailing_Blanks (Str, P);
return V;
end;
end if;
end Value_Real;
end System.Val_Real;
|
with ada.Unchecked_Deallocation;
with impact.d3.Containers;
with impact.d3.collision.Proxy;
package body impact.d3.Dispatcher.collision
is
--- Globals
--
gNumManifold : Integer := 0;
type Object_view is access all impact.d3.Object.item'Class;
--- Forge
--
function to_Dispatcher (collisionConfiguration : access impact.d3.collision.Configuration.Item'Class) return Item
is
use impact.d3.collision.Proxy;
Self : Item;
begin
Self.m_dispatcherFlags := (impact.d3.Dispatcher.collision.CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD);
Self.m_collisionConfiguration := collisionConfiguration;
Self.setNearCallback (defaultNearCallback'Access);
-- m_collisionAlgorithmPoolAllocator = collisionConfiguration->getCollisionAlgorithmPool();
-- m_persistentManifoldPoolAllocator = collisionConfiguration->getPersistentManifoldPool();
for i in BroadphaseNativeTypes
loop
for j in BroadphaseNativeTypes
loop
Self.m_doubleDispatch (i, j) := Self.m_collisionConfiguration.getCollisionAlgorithmCreateFunc (i, j);
pragma Assert (Self.m_doubleDispatch (i, j) /= null);
end loop;
end loop;
return Self;
end to_Dispatcher;
overriding procedure destruct (Self : in out Item)
is
begin
null;
end destruct;
--- Attributes
--
overriding function findAlgorithm (Self : access Item; body0, body1 : access impact.d3.Object.item'Class;
sharedManifold : access impact.d3.Manifold.Item'Class := null) return Algorithm_view
is
ci : impact.d3.collision.Algorithm.AlgorithmConstructionInfo;
algo : impact.d3.Dispatcher.Algorithm_view;
begin
ci.m_dispatcher1 := Self;
ci.m_manifold := sharedManifold;
algo := Self.m_doubleDispatch (body0.getCollisionShape.getShapeType,
body1.getCollisionShape.getShapeType).CreateCollisionAlgorithm (ci, body0, body1);
return algo;
end findAlgorithm;
overriding function getNewManifold (Self : access Item; bod0, bod1 : access Any'Class ) return access impact.d3.Manifold.Item'Class
is
use impact.d3.Manifold;
body0 : constant impact.d3.Object.view := impact.d3.Object.view (bod0);
body1 : constant impact.d3.Object.view := impact.d3.Object.view (bod1);
contactBreakingThreshold,
contactProcessingThreshold : math.Real;
begin
gNumManifold := gNumManifold + 1;
pragma Assert (gNumManifold < 65535);
-- optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance).
--
if (Self.m_dispatcherFlags and impact.d3.Dispatcher.collision.CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) /= 0 then
contactBreakingThreshold := math.Real'Min (body0.getCollisionShape.getContactBreakingThreshold (gContactBreakingThreshold),
body1.getCollisionShape.getContactBreakingThreshold (gContactBreakingThreshold));
else
contactBreakingThreshold := gContactBreakingThreshold;
end if;
contactProcessingThreshold := math.Real'Min (body0.getContactProcessingThreshold,
body1.getContactProcessingThreshold);
declare
manifold : constant impact.d3.Manifold.view := new impact.d3.Manifold.item'(to_Manifold (Containers.Any_view (body0), Containers.Any_view (body1),
0,
contactBreakingThreshold,
contactProcessingThreshold));
begin
Self.m_manifoldsPtr.append (manifold);
manifold.m_index1a := Integer (Self.m_manifoldsPtr.Length);
return manifold;
end;
end getNewManifold;
overriding procedure releaseManifold (Self : in out Item; manifold : access impact.d3.Manifold.Item'Class)
is
findIndex : Integer;
begin
gNumManifold := gNumManifold - 1;
Self.clearManifold (manifold);
findIndex := manifold.m_index1a; pragma Assert (findIndex <= Integer (Self.m_manifoldsPtr.Length));
Self.m_manifoldsPtr.swap (findIndex, Integer (Self.m_manifoldsPtr.Length) - 0);
Self.m_manifoldsPtr.Element (findIndex).m_index1a := findIndex;
Self.m_manifoldsPtr.delete_Last;
manifold.destruct;
declare
procedure free is new ada.Unchecked_Deallocation (impact.d3.Manifold.item'Class, impact.d3.Manifold.view);
the_Manifold : impact.d3.Manifold.view := manifold.all'Access;
begin
free (the_Manifold);
end;
end releaseManifold;
overriding procedure clearManifold (Self : in out Item; manifold : access impact.d3.Manifold.Item'Class)
is
pragma Unreferenced (Self);
begin
manifold.clearManifold;
end clearManifold;
function getDispatcherFlags (Self : in Item) return Flags
is
begin
return Self.m_dispatcherFlags;
end getDispatcherFlags;
procedure setDispatcherFlags (Self : in out Item; To : in Flags)
is
begin
Self.m_dispatcherFlags := To;
end setDispatcherFlags;
-- 'registerCollisionCreateFunc' allows registration of custom/alternative collision create functions.
--
procedure registerCollisionCreateFunc (Self : in out Item; proxyType0, proxyType1 : in impact.d3.collision.Proxy.BroadphaseNativeTypes;
createFunc : access impact.d3.collision.create_Func.item)
is
begin
Self.m_doubleDispatch (proxyType0, proxyType1) := createFunc;
end registerCollisionCreateFunc;
overriding function getNumManifolds (Self : in Item) return Natural
is
begin
return Natural (Self.m_manifoldsPtr.Length);
end getNumManifolds;
overriding function getInternalManifoldPointer (Self : access Item) return access impact.d3.Manifold.Vector
-- function getInternalManifoldPointer (Self : access Item) return access impact.d3.Manifold_view
is
begin
return Self.m_manifoldsPtr'Access;
end getInternalManifoldPointer;
overriding function getManifoldByIndexInternal (Self : in Item; index : in Integer) return impact.d3.Manifold.view
-- function getManifoldByIndexInternal (Self : access Item; index : in Integer) return impact.d3.Manifold_view
is
begin
return Self.m_manifoldsPtr.Element (index);
end getManifoldByIndexInternal;
overriding function needsCollision (Self : access Item; body0, body1 : access impact.d3.Object.item'Class) return Boolean
is
pragma Assert (body0 /= null);
pragma Assert (body1 /= null);
Result : Boolean := True;
begin
if (not body0.isActive)
and then (not body1.isActive)
then
Result := False;
elsif not body0.checkCollideWith (body1) then
Result := False;
end if;
return Result;
end needsCollision;
overriding function needsResponse (Self : access Item; body0, body1 : access impact.d3.Object.item'Class) return Boolean
is
pragma Unreferenced (Self);
hasResponse : Boolean := body0.hasContactResponse and then body1.hasContactResponse; -- Here you can do filtering.
begin
-- no response between two static/kinematic bodies:
--
hasResponse := hasResponse
and then ( (not body0.isStaticOrKinematicObject)
or else (not body1.isStaticOrKinematicObject));
return hasResponse;
end needsResponse;
procedure setNearCallback (Self : in out Item; nearCallback : in btNearCallback)
is
begin
Self.m_nearCallback := nearCallback;
end setNearCallback;
function getNearCallback (Self : in Item) return btNearCallback
is
begin
return Self.m_nearCallback;
end getNearCallback;
-- By default, Bullet will use this near callback.
--
procedure defaultNearCallback (collisionPair : access impact.d3.collision.Proxy.btBroadphasePair;
dispatcher : access impact.d3.Dispatcher.collision.Item'Class;
dispatchInfo : out impact.d3.Dispatcher.DispatcherInfo)
is
colObj0 : constant impact.d3.Object.view := impact.d3.Object.view (collisionPair.m_pProxy0.m_clientObject);
colObj1 : constant impact.d3.Object.view := impact.d3.Object.view (collisionPair.m_pProxy1.m_clientObject);
contactPointResult : aliased impact.d3.collision.manifold_Result.item;
toi : math.Real;
begin
if dispatcher.needsCollision (colObj0, colObj1) then
-- Dispatcher will keep algorithms persistent in the collision pair.
--
if collisionPair.m_algorithm = null then
collisionPair.m_algorithm := dispatcher.findAlgorithm (colObj0, colObj1);
end if;
if collisionPair.m_algorithm /= null then
contactPointResult := impact.d3.collision.manifold_Result.Forge.to_manifold_Result (colObj0, colObj1);
if dispatchInfo.m_dispatchFunc = DISPATCH_DISCRETE then -- Discrete collision detection query.
collisionPair.m_algorithm.processCollision (colObj0, colObj1,
dispatchInfo,
contactPointResult);
else -- Continuous collision detection query, time of impact (toi).
toi := collisionPair.m_algorithm.calculateTimeOfImpact (colObj0, colObj1,
dispatchInfo,
contactPointResult'Access);
if dispatchInfo.m_timeOfImpact > toi then
dispatchInfo.m_timeOfImpact := toi;
end if;
end if;
end if;
end if;
end defaultNearCallback;
function allocateCollisionAlgorithm (Self : access Item; size : in Integer) return system.Address
is
pragma Unreferenced (Self, size);
begin
return system.Null_Address;
end allocateCollisionAlgorithm;
overriding procedure freeCollisionAlgorithm (Self : in out Item; ptr : access impact.d3.collision.Algorithm.item'Class)
is
pragma Unreferenced (Self, ptr);
begin
return;
end freeCollisionAlgorithm;
function getCollisionConfiguration (Self : access Item) return access impact.d3.collision.Configuration.Item'Class
is
begin
return Self.m_collisionConfiguration;
end getCollisionConfiguration;
procedure setCollisionConfiguration (Self : in out Item; config : access impact.d3.collision.Configuration.item'Class)
is
begin
Self.m_collisionConfiguration := config;
end setCollisionConfiguration;
-- Interface for iterating all overlapping collision pairs, no matter how those pairs are stored (array, set, map etc).
-- This is useful for the collision dispatcher.
--
type btCollisionPairCallback (m_dispatchInfo : access impact.d3.Dispatcher.DispatcherInfo)
is new impact.d3.collision.overlapped_pair_Callback.cached.btOverlapCallback with
record
m_dispatcher : access impact.d3.Dispatcher.collision.item'Class;
end record;
overriding function processOverlap (Self : in btCollisionPairCallback; pair : access impact.d3.collision.Proxy.btBroadphasePair) return Boolean;
function to_btCollisionPairCallback (dispatchInfo : access impact.d3.Dispatcher.DispatcherInfo;
dispatcher : access impact.d3.Dispatcher.collision.item'Class) return btCollisionPairCallback
is
Self : btCollisionPairCallback (dispatchInfo);
begin
Self.m_dispatcher := dispatcher;
return Self;
end to_btCollisionPairCallback;
overriding function processOverlap (Self : in btCollisionPairCallback; pair : access impact.d3.collision.Proxy.btBroadphasePair) return Boolean
is
begin
Self.m_dispatcher.getNearCallback.all (pair,
Self.m_dispatcher,
Self.m_dispatchInfo.all);
return False;
end processOverlap;
overriding procedure dispatchAllCollisionPairs (Self : in out Item; pairCache : access impact.d3.collision.overlapped_pair_Callback.cached.item'Class;
dispatchInfo : access impact.d3.Dispatcher.DispatcherInfo;
dispatcher : access impact.d3.Dispatcher.item'Class)
is
begin
-- m_blockedForChanges = true;
declare
collisionCallback : aliased btCollisionPairCallback := to_btCollisionPairCallback (dispatchInfo, Self'Unchecked_Access);
begin
pairCache.processAllOverlappingPairs (collisionCallback'Access, dispatcher);
end;
-- m_blockedForChanges = false;
end dispatchAllCollisionPairs;
end impact.d3.Dispatcher.collision;
|
-------------------------------------------------------------------------------
-- This file is part of libsparkcrypto.
--
-- Copyright (C) 2010, Alexander Senier
-- Copyright (C) 2010, secunet Security Networks AG
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- * Neither the name of the nor the names of its contributors may be used
-- to endorse or promote products derived from this software without
-- specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
with LSC.Internal.Types;
use type LSC.Internal.Types.Word32;
use type LSC.Internal.Types.Index;
-------------------------------------------------------------------------------
-- Operations over 32-bit words
-------------------------------------------------------------------------------
package LSC.Internal.Ops32 is
pragma Pure;
-- Convert the four byte values @Byte0@, @Byte1@, @Byte2@ and @Byte3@ to a
-- 32-bit word
function Bytes_To_Word
(Byte0 : Types.Byte;
Byte1 : Types.Byte;
Byte2 : Types.Byte;
Byte3 : Types.Byte) return Types.Word32;
pragma Inline (Bytes_To_Word);
-- Return a byte at @Position@ of the 32-bit word @Value@
function ByteX (Value : Types.Word32;
Position : Types.Byte_Array32_Index) return Types.Byte;
pragma Inline (ByteX);
-- Return the first byte of the 32-bit word @Value@
function Byte0 (Value : Types.Word32) return Types.Byte;
pragma Inline (Byte0);
-- Return the second byte of the 32-bit word @Value@
function Byte1 (Value : Types.Word32) return Types.Byte;
pragma Inline (Byte1);
-- Return the third byte of the 32-bit word @Value@
function Byte2 (Value : Types.Word32) return Types.Byte;
pragma Inline (Byte2);
-- Return the fourth byte of the 32-bit word @Value@
function Byte3 (Value : Types.Word32) return Types.Byte;
pragma Inline (Byte3);
-- Perform XOR on two 32-bit words @V0@ and @V1@
function XOR2 (V0, V1 : Types.Word32) return Types.Word32
with Post => XOR2'Result = (V0 xor V1);
pragma Inline (XOR2);
-- Perform XOR on three 32-bit words @V0@, @V1@ and @V2@
function XOR3 (V0, V1, V2 : Types.Word32) return Types.Word32
with Post => XOR3'Result = (V0 xor V1 xor V2);
pragma Inline (XOR3);
-- Perform XOR on four 32-bit words @V0@, @V1@, @V2@ and @V3@
function XOR4 (V0, V1, V2, V3 : Types.Word32) return Types.Word32
with Post => XOR4'Result = (V0 xor V1 xor V2 xor V3);
pragma Inline (XOR4);
-- Perform XOR on four 32-bit words @V0@, @V1@, @V2@, @V3@ and @V4@
function XOR5 (V0, V1, V2, V3, V4 : Types.Word32) return Types.Word32
with Post => XOR5'Result = (V0 xor V1 xor V2 xor V3 xor V4);
pragma Inline (XOR5);
-- Perform XOR on two arrays of 32-bit words
--
-- @Left@ - First input array <br>
-- @Right@ - Second input array <br>
-- @Result@ - Result array <br>
procedure Block_XOR
(Left : in Types.Word32_Array_Type;
Right : in Types.Word32_Array_Type;
Result : out Types.Word32_Array_Type)
with
Depends =>
(Result =>+ (Left, Right)),
Pre =>
Left'First = Right'First and
Left'Last = Right'Last and
Right'First = Result'First and
Right'Last = Result'Last,
Post =>
(for all I in Types.Index range Left'First .. Left'Last =>
(Result (I) = XOR2 (Left (I), Right (I))));
pragma Inline (Block_XOR);
-- Copy all elements of @Source@ to @Dest@. Should @Source@ be shorter than
-- @Dest@, remaining elements stay unchanged.
procedure Block_Copy
(Source : in Types.Word32_Array_Type;
Dest : in out Types.Word32_Array_Type)
with
Depends =>
(Dest =>+ Source),
Pre =>
Source'First = Dest'First and
Source'Last <= Dest'Last,
Post =>
(for all P in Types.Index range Source'First .. Source'Last =>
(Dest (P) = Source (P)));
pragma Inline (Block_Copy);
end LSC.Internal.Ops32;
|
with Ada.Numerics.Big_Numbers.Big_Integers;
use Ada.Numerics.Big_Numbers.Big_Integers;
package Fibonacci is
function Fib_Iter (N : Natural) return Big_Natural;
function Fib_Naive (N : Natural) return Natural;
function Fib_Recur (N : Natural) return Big_Natural;
function Big_Natural_Image (N : Big_Natural) return String;
end Fibonacci;
|
-----------------------------------------------------------------------
-- Facelet Tests - Unit tests for ASF.Views.Facelet
-- Copyright (C) 2009, 2010, 2011, 2018 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.Test_Caller;
with EL.Objects;
with ASF.Converters;
with ASF.Validators;
with ASF.Contexts.Facelets;
package body ASF.Views.Facelets.Tests is
use ASF.Contexts.Facelets;
type Facelet_Context is new ASF.Contexts.Facelets.Facelet_Context with null record;
-- Get a converter from a name.
-- Returns the converter object or null if there is no converter.
overriding
function Get_Converter (Context : in Facelet_Context;
Name : in EL.Objects.Object)
return ASF.Converters.Converter_Access;
-- Get a validator from a name.
-- Returns the validator object or null if there is no validator.
overriding
function Get_Validator (Context : in Facelet_Context;
Name : in EL.Objects.Object)
return ASF.Validators.Validator_Access;
-- ------------------------------
-- Get a converter from a name.
-- Returns the converter object or null if there is no converter.
-- ------------------------------
overriding
function Get_Converter (Context : in Facelet_Context;
Name : in EL.Objects.Object)
return ASF.Converters.Converter_Access is
pragma Unreferenced (Context, Name);
begin
return null;
end Get_Converter;
-- ------------------------------
-- Get a validator from a name.
-- Returns the validator object or null if there is no validator.
-- ------------------------------
overriding
function Get_Validator (Context : in Facelet_Context;
Name : in EL.Objects.Object)
return ASF.Validators.Validator_Access is
pragma Unreferenced (Context, Name);
begin
return null;
end Get_Validator;
-- ------------------------------
-- Set up performed before each test case
-- ------------------------------
overriding
procedure Set_Up (T : in out Test) is
begin
null;
end Set_Up;
-- ------------------------------
-- Tear down performed after each test case
-- ------------------------------
overriding
procedure Tear_Down (T : in out Test) is
begin
null;
end Tear_Down;
-- ------------------------------
-- Test loading of facelet file
-- ------------------------------
procedure Test_Load_Facelet (T : in out Test) is
Factory : ASF.Views.Facelets.Facelet_Factory;
Components : aliased ASF.Factory.Component_Factory;
View : ASF.Views.Facelets.Facelet;
Ctx : Facelet_Context;
begin
Initialize (Factory, Components'Unchecked_Access, "regtests/files/views;.",
True, True, True);
Find_Facelet (Factory, "text.xhtml", Ctx, View);
T.Assert (Condition => not Is_Null (View),
Message => "Loading an existing facelet should return a view");
end Test_Load_Facelet;
-- ------------------------------
-- Test loading of an unknown file
-- ------------------------------
procedure Test_Load_Unknown_Facelet (T : in out Test) is
Factory : ASF.Views.Facelets.Facelet_Factory;
Components : aliased ASF.Factory.Component_Factory;
View : ASF.Views.Facelets.Facelet;
Ctx : Facelet_Context;
begin
Initialize (Factory, Components'Unchecked_Access, "regtests/files;.", True, True, True);
Find_Facelet (Factory, "not-found-file.xhtml", Ctx, View);
T.Assert (Condition => Is_Null (View),
Message => "Loading a missing facelet should not raise any exception");
end Test_Load_Unknown_Facelet;
package Caller is new Util.Test_Caller (Test, "Views.Facelets");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
-- To document what is tested, register the test methods for each
-- operation that is tested.
Caller.Add_Test (Suite, "Test ASF.Views.Facelets.Find_Facelet",
Test_Load_Facelet'Access);
Caller.Add_Test (Suite, "Test ASF.Views.Facelets.Find_Facelet",
Test_Load_Unknown_Facelet'Access);
end Add_Tests;
end ASF.Views.Facelets.Tests;
|
-----------------------------------------------------------------------
-- ADO Objects Tests -- Tests for ADO.Objects
-- Copyright (C) 2011, 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 Util.Tests;
package ADO.Objects.Tests is
type Test is new Util.Tests.Test with null record;
procedure Test_Key (T : in out Test);
procedure Test_Object_Ref (T : in out Test);
procedure Test_Create_Object (T : in out Test);
procedure Test_Delete_Object (T : in out Test);
-- Test Is_Inserted and Is_Null
procedure Test_Is_Inserted (T : in out Test);
-- Test Is_Modified
procedure Test_Is_Modified (T : in out Test);
-- Test object creation/update/load with string as key.
procedure Test_String_Key (T : in out Test);
-- Add the tests in the test suite
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
end ADO.Objects.Tests;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . E X C E P T I O N _ T R A C E S --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 2000 Ada Core Technologies, 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 is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- This package provides an interface allowing to control *automatic* output
-- to standard error upon exception occurrences (as opposed to explicit
-- generation of traceback information using GNAT.Traceback).
--
-- This output includes the basic information associated with the exception
-- (name, message) as well as a backtrace of the call chain at the point
-- where the exception occurred. This backtrace is only output if the call
-- chain information is available, depending if the binder switch dedicated
-- to that purpose has been used or not.
--
-- The default backtrace is in the form of absolute code locations which may
-- be converted to corresponding source locations using the addr2line utility
-- or from within GDB. Please refer to GNAT.Traceback for information about
-- what is necessary to be able to exploit thisg possibility.
--
-- The backtrace output can also be customized by way of a "decorator" which
-- may return any string output in association with a provided call chain.
with GNAT.Traceback; use GNAT.Traceback;
package GNAT.Exception_Traces is
-- The following defines the exact situations in which raises will
-- cause automatic output of trace information.
type Trace_Kind is
(Every_Raise,
-- Denotes the initial raise event for any exception occurrence, either
-- explicit or due to a specific language rule, within the context of a
-- task or not.
Unhandled_Raise
-- Denotes the raise events corresponding to exceptions for which there
-- is no user defined handler, in particular, when a task dies due to an
-- unhandled exception.
);
-- The following procedures can be used to activate and deactivate
-- traces identified by the above trace kind values.
procedure Trace_On (Kind : in Trace_Kind);
-- Activate the traces denoted by Kind.
procedure Trace_Off;
-- Stop the tracing requested by the last call to Trace_On.
-- Has no effect if no such call has ever occurred.
-- The following provide the backtrace decorating facilities
type Traceback_Decorator is access
function (Traceback : Tracebacks_Array) return String;
-- A backtrace decorator is a function which returns the string to be
-- output for a call chain provided by way of a tracebacks array.
procedure Set_Trace_Decorator (Decorator : Traceback_Decorator);
-- Set the decorator to be used for future automatic outputs. Restore
-- the default behavior (output of raw addresses) if the provided
-- access value is null.
end GNAT.Exception_Traces;
|
-- This package has been generated automatically by GNATtest.
-- You are allowed to add your code to the bodies of test routines.
-- Such changes will be kept during further regeneration of this file.
-- All code placed outside of test routine bodies will be lost. The
-- code intended to set up and tear down the test environment should be
-- placed into Crafts.Test_Data.
with AUnit.Assertions; use AUnit.Assertions;
with System.Assertions;
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only
with Ships.Cargo; use Ships.Cargo;
-- begin read only
-- end read only
package body Crafts.Test_Data.Tests is
-- begin read only
-- id:2.2/01/
--
-- This section can be used to add global variables and other elements.
--
-- end read only
-- begin read only
-- end read only
-- begin read only
procedure Wrap_Test_Manufacturing_dd583a_cf804c(Minutes: Positive) is
begin
GNATtest_Generated.GNATtest_Standard.Crafts.Manufacturing(Minutes);
end Wrap_Test_Manufacturing_dd583a_cf804c;
-- end read only
-- begin read only
procedure Test_Manufacturing_test_manufacturing(Gnattest_T: in out Test);
procedure Test_Manufacturing_dd583a_cf804c(Gnattest_T: in out Test) renames
Test_Manufacturing_test_manufacturing;
-- id:2.2/dd583af67efcd5dc/Manufacturing/1/0/test_manufacturing/
procedure Test_Manufacturing_test_manufacturing(Gnattest_T: in out Test) is
procedure Manufacturing(Minutes: Positive) renames
Wrap_Test_Manufacturing_dd583a_cf804c;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
Manufacturing(15);
Assert(True, "This test can only crash.");
-- begin read only
end Test_Manufacturing_test_manufacturing;
-- end read only
-- begin read only
function Wrap_Test_CheckRecipe_6b22c5_37e1c4
(RecipeIndex: Unbounded_String) return Positive is
begin
begin
pragma Assert(RecipeIndex /= Null_Unbounded_String);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(crafts.ads:0):Test_CheckRecipe test requirement violated");
end;
declare
Test_CheckRecipe_6b22c5_37e1c4_Result: constant Positive :=
GNATtest_Generated.GNATtest_Standard.Crafts.CheckRecipe
(RecipeIndex);
begin
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(crafts.ads:0:):Test_CheckRecipe test commitment violated");
end;
return Test_CheckRecipe_6b22c5_37e1c4_Result;
end;
end Wrap_Test_CheckRecipe_6b22c5_37e1c4;
-- end read only
-- begin read only
procedure Test_CheckRecipe_test_checkrecipe(Gnattest_T: in out Test);
procedure Test_CheckRecipe_6b22c5_37e1c4(Gnattest_T: in out Test) renames
Test_CheckRecipe_test_checkrecipe;
-- id:2.2/6b22c50e71f35d02/CheckRecipe/1/0/test_checkrecipe/
procedure Test_CheckRecipe_test_checkrecipe(Gnattest_T: in out Test) is
function CheckRecipe
(RecipeIndex: Unbounded_String) return Positive renames
Wrap_Test_CheckRecipe_6b22c5_37e1c4;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
UpdateCargo(Player_Ship, To_Unbounded_String("6"), 10);
Assert
(CheckRecipe(To_Unbounded_String("1")) = 10,
"Failed to check crafting recipe requirements.");
-- begin read only
end Test_CheckRecipe_test_checkrecipe;
-- end read only
-- begin read only
procedure Wrap_Test_SetRecipe_d9013b_447571
(Workshop, Amount: Positive; RecipeIndex: Unbounded_String) is
begin
begin
pragma Assert
((Workshop <= Player_Ship.Modules.Last_Index and
RecipeIndex /= Null_Unbounded_String));
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"req_sloc(crafts.ads:0):Test_SetRecipe test requirement violated");
end;
GNATtest_Generated.GNATtest_Standard.Crafts.SetRecipe
(Workshop, Amount, RecipeIndex);
begin
pragma Assert(True);
null;
exception
when System.Assertions.Assert_Failure =>
AUnit.Assertions.Assert
(False,
"ens_sloc(crafts.ads:0:):Test_SetRecipe test commitment violated");
end;
end Wrap_Test_SetRecipe_d9013b_447571;
-- end read only
-- begin read only
procedure Test_SetRecipe_test_setrecipe(Gnattest_T: in out Test);
procedure Test_SetRecipe_d9013b_447571(Gnattest_T: in out Test) renames
Test_SetRecipe_test_setrecipe;
-- id:2.2/d9013bfcb0ae8d7e/SetRecipe/1/0/test_setrecipe/
procedure Test_SetRecipe_test_setrecipe(Gnattest_T: in out Test) is
procedure SetRecipe
(Workshop, Amount: Positive; RecipeIndex: Unbounded_String) renames
Wrap_Test_SetRecipe_d9013b_447571;
-- end read only
pragma Unreferenced(Gnattest_T);
begin
UpdateCargo(Player_Ship, To_Unbounded_String("6"), 10);
SetRecipe(9, 10, To_Unbounded_String("1"));
Assert
(Player_Ship.Modules(9).Crafting_Amount = 10,
"Failed to set crafting recipe.");
-- begin read only
end Test_SetRecipe_test_setrecipe;
-- end read only
-- begin read only
-- id:2.2/02/
--
-- This section can be used to add elaboration code for the global state.
--
begin
-- end read only
null;
-- begin read only
-- end read only
end Crafts.Test_Data.Tests;
|
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
-- Objectif : Afficher un tableau trié suivant le principe du tri par sélection.
procedure Tri_Selection is
CAPACITE: constant Integer := 10; -- la capacité du tableau
type Tableau_Entier is array (1..CAPACITE) of Integer;
type Tableau is
record
Elements : Tableau_Entier;
Taille : Integer; --{ Taille in [0..CAPACITE] }
end record;
-- Objectif : Afficher le tableau Tab.
-- Paramètres :
-- Tab : le tableau à afficher
-- Nécessite : ---
-- Assure : Le tableau est affiché.
procedure Afficher (Tab : in Tableau) is
begin
Put ("[");
if Tab.Taille > 0 then
-- Afficher le premier élément
Put (Tab.Elements (1), 1);
-- Afficher les autres éléments
for Indice in 2..Tab.Taille loop
Put (", ");
Put (Tab.Elements (Indice), 1);
end loop;
end if;
Put ("]");
end Afficher;
function Min_Index_Tableau ( Tab : in Tableau_Entier; Init_Index, Taille : in Integer) return Integer is
Min : Integer;
begin
Min := Init_Index;
for i in (Init_Index + 1)..Taille loop
if Tab(i) < Tab(Min) then
Min := i;
end if;
end loop;
return Min;
end Min_Index_Tableau;
function Permute ( Tab : in out Tableau_Entier; Min, Init_Index : in Integer) return Tableau_Entier is
Temp : Integer;
begin
if Min /= Init_Index then
Temp := Tab(Init_Index);
Tab(Init_Index) := Tab(Min);
Tab(Min) := Temp;
end if;
return Tab;
end Permute;
function Tri_Tableau (Tab : In Out Tableau) return Tableau is
Init_Index : Integer;
begin
Init_Index := 1;
Put("Initial vector : ");
Afficher (Tab);
New_Line(1);
Tri_Tab:
loop
Tab.Elements := Permute(Tab.Elements, Min_Index_Tableau(Tab.Elements, Init_Index, Tab.Taille), Init_Index);
New_Line(1);
Put("After"& Integer'Image(Init_Index) & " step : ");
Afficher (Tab);
New_Line(1);
Init_Index := Init_Index + 1;
exit Tri_Tab when Init_Index = Tab.Taille;
end loop Tri_Tab;
New_Line(1);
return Tab;
end Tri_Tableau;
procedure Verifier_tri (Tab : In Tableau) is
begin
for i in 1..(Tab.Taille - 1) loop
if Tab.Elements(i) > Tab.Elements(i + 1) then
Put_Line("Error in the program");
end if;
end loop;
end Verifier_tri;
function Occurrence ( Tab : In Tableau; Item : In Integer) return Integer is
Count : Integer;
begin
Count := 0;
for i in 1..Tab.Taille loop
if Tab.Elements(i) = Item then
Count := Count + 1;
end if;
end loop;
return Count;
end Occurrence;
procedure Verifier_elements ( Tab_Trie, Tab : IN Tableau) is
begin
for i in 1..Tab.Taille loop
for j in 1..Tab.Taille loop
if Tab_Trie.Elements(i) = Tab.Elements(j) and Occurrence ( Tab, Tab.Elements(j)) /= Occurrence ( Tab_Trie, Tab_Trie.Elements(j)) then
Put_Line("Error in the program");
end if;
end loop;
end loop;
end Verifier_Elements;
procedure Verifier_Taille ( Tab_Trie, Tab : In Tableau) is
begin
if Tab_Trie.Taille /= Tab.Taille then
Put_Line("Error in the program");
end if;
end Verifier_Taille;
procedure Test ( Tab_Trie, Tab : In Tableau) is
begin
Verifier_Taille ( Tab_Trie, Tab );
Verifier_Elements ( Tab_Trie, Tab );
Verifier_Tri ( Tab );
end Test;
Tab1, Tab2, Tab3 , Trie1, Trie2, Trie3 : Tableau;
begin
-- Initialiser le tableau
Tab1 := ( (1, 3, 4, 2, others => 0), 4);
Tab2 := ( (4, 3, 2, 1, others => 0), 4);
Tab3 := ( (-5, 3, 8, 1, -25, 0, 8, 1, 1, 1), 10);
-- Trier les tableaux
Trie1 := Tri_Tableau (Tab1);
Test ( Trie1, Tab1);
Trie2 := Tri_Tableau (Tab2);
Test ( Trie2, Tab2);
Trie3 := Tri_Tableau (Tab3);
Test ( Trie3, Tab3);
end Tri_Selection;
|
with My_Button; use My_Button;
package body Solar_System.Button is
task body Button_Monitor is
Body_Data : Body_Type;
begin
loop
My_Button.Button.Wait_Press;
for PO_Body of Bodies loop
Body_Data := PO_Body.Get_Data;
Body_Data.Speed := -Body_Data.Speed;
PO_Body.Set_Data (Body_Data);
end loop;
end loop;
end Button_Monitor;
end Solar_System.Button;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_render_picture_iterator_t is
-- Item
--
type Item is record
data : access xcb.xcb_render_picture_t;
the_rem : aliased Interfaces.C.int;
index : aliased Interfaces.C.int;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_render_picture_iterator_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_render_picture_iterator_t.Item,
Element_Array => xcb.xcb_render_picture_iterator_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C
.size_t range <>) of aliased xcb.xcb_render_picture_iterator_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_render_picture_iterator_t.Pointer,
Element_Array => xcb.xcb_render_picture_iterator_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_render_picture_iterator_t;
|
with STM32F4.LCD; use STM32F4.LCD;
package Screen_Interface is
subtype Width is STM32F4.LCD.Width;
subtype Height is STM32F4.LCD.Height;
type Touch_State is record
Touch_Detected : Boolean;
X : Width;
Y : Height;
end record;
type Point is record
X : Width;
Y : Height;
end record;
function "+" (P1, P2 : Point) return Point is (P1.X + P2.X, P1.Y + P2.Y);
function "-" (P1, P2 : Point) return Point is (P1.X - P2.X, P1.Y - P2.Y);
subtype Color is STM32F4.LCD.Pixel;
Black : Color renames STM32F4.LCD.Black;
White : Color renames STM32F4.LCD.White;
Red : Color renames STM32F4.LCD.Red;
Green : Color renames STM32F4.LCD.Green;
Blue : Color renames STM32F4.LCD.Blue;
Gray : Color renames STM32F4.LCD.Gray;
Light_Gray : Color renames STM32F4.LCD.Light_Gray;
Sky_Blue : Color renames STM32F4.LCD.Sky_Blue;
Yellow : Color renames STM32F4.LCD.Yellow;
Orange : Color renames STM32F4.LCD.Orange;
Pink : Color renames STM32F4.LCD.Pink;
Violet : Color renames STM32F4.LCD.Violet;
procedure Initialize;
function Get_Touch_State return Touch_State;
procedure Set_Pixel (P : Point; Col : Color; Layer : LCD_Layer := Layer1);
procedure Fill_Screen (Col : Color; Layer : LCD_Layer := Layer1);
procedure Fast_Horiz_Line (Col : Color; X1: Width; X2 : Width; Y : Height; Layer : LCD_Layer := Layer1);
type RGB_Value is new Natural range 0 .. 255;
function RGB_To_Color (R, G, B : RGB_Value) return Color;
end Screen_Interface;
|
with GESTE;
pragma Style_Checks (Off);
package Game_Assets.Tileset_Collisions is
Tiles : aliased constant GESTE.Tile_Collisions_Array :=
(
1 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
2 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
3 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
4 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
5 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,False,False)),
6 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False)),
7 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
8 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
9 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
10 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
11 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
12 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
13 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False)),
14 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False)),
15 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
16 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
17 => ((False,False,False,False,False,False,True,True,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,True,True,True,True,True,False,False,False,False,False),
(False,False,False,False,False,False,True,True,True,True,True,True,False,False,False,False),
(False,False,False,False,False,True,True,True,True,True,True,True,False,False,False,False),
(False,False,False,False,False,True,True,True,True,True,True,True,False,False,False,False),
(False,False,False,False,False,True,True,True,True,True,True,False,False,False,False,False),
(False,False,False,False,True,True,True,True,True,True,True,False,False,False,False,False),
(False,False,False,False,True,True,True,True,True,True,True,False,False,False,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,False,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,False,False,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,False,False,False,False,True,True,True),
(False,False,False,True,True,True,True,True,False,False,False,False,False,True,True,True),
(False,False,False,False,False,True,True,True,False,False,False,False,False,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,True,True,True)),
18 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,True,True,False,False,False,False,False,False,False),
(False,False,False,False,False,False,True,True,True,True,True,False,False,False,False,False),
(False,False,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(False,False,True,True,True,True,True,True,True,True,True,False,False,False,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,False,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,False,False,False,True,True),
(False,False,True,True,True,True,True,True,True,True,True,False,False,False,True,True),
(False,False,True,True,True,True,True,False,False,False,False,False,False,False,False,False),
(False,False,False,True,True,True,False,False,False,False,False,False,False,False,False,False)),
19 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False)),
20 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False)),
21 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
22 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
23 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
24 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
25 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
26 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
27 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
28 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,True,True,True,True,False,False,False,False,False,False,False,False),
(False,False,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(False,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(False,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False)),
29 => ((True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,True,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False)),
30 => ((True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(True,True,True,True,True,True,True,True,True,True,True,True,False,False,False,False),
(False,True,True,True,True,True,True,True,True,True,True,False,False,False,False,False),
(False,False,True,True,True,True,True,True,True,True,False,False,False,False,False,False),
(False,False,False,False,True,True,True,True,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
31 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True)),
32 => ((False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True)),
33 => ((False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True)),
34 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True)),
35 => ((False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True)),
36 => ((False,False,False,False,False,False,False,False,False,False,False,False,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,True,True,True)),
37 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True)),
38 => ((False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True)),
39 => ((False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
40 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
41 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
42 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
43 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
44 => ((True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False),
(True,True,True,True,True,True,True,True,False,False,False,False,False,False,False,False)),
45 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
46 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
47 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
48 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
49 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
50 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
51 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
52 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
53 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
54 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
55 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
56 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
57 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
58 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
59 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
60 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
61 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
62 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
63 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
64 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
65 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
66 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
67 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
68 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
69 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
70 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
71 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
72 => ((False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
73 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,True,True,True,True,True,True,False,False,False,False,False),
(False,False,False,False,True,True,True,True,True,True,True,True,False,False,False,False),
(False,False,False,True,True,True,True,True,True,True,True,True,True,False,False,False),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,False,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,False),
(False,False,True,True,True,True,True,True,True,True,True,True,True,True,False,False),
(False,False,False,True,True,True,True,True,True,True,True,True,True,False,False,False),
(False,False,False,False,True,True,True,True,True,True,True,True,False,False,False,False),
(False,False,False,False,False,True,True,True,True,True,True,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
74 => ((False,False,False,False,False,False,False,False,False,False,True,True,True,True,False,False),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,True,True,True,True,True,True,True,True),
(False,False,False,False,False,False,False,False,False,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,True,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,True,False),
(False,False,False,False,False,False,False,False,False,False,True,True,True,True,False,False)),
75 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
76 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
77 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
78 => ((True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True),
(True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True)),
79 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
80 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
81 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)),
82 => ((False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False),
(False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False)));
end Game_Assets.Tileset_Collisions;
|
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions; use Ada.Exceptions;
with Qt.QObject; use Qt.QObject;
with Qt.QUiLoader; use Qt.QUiLoader;
with Qt.QSpinBox; use Qt.QSpinBox;
with Qt.QWidget; use Qt.QWidget;
with Qt.QString; use Qt.QString;
with Qt.QLabel; use Qt.QLabel;
with Qt.QComboBox; use Qt.QComboBox;
with Qt.QStringList; use Qt.QStringList;
with Qt.QLineSeries; use Qt.QLineSeries;
with Qt.QXYSeries; use Qt.QXYSeries;
with Qt.QGraphicsView; use Qt.QGraphicsView;
with Qt.QChart; use Qt.QChart;
with Qt.QLegend; use Qt.QLegend;
with Qt.QChartView; use Qt.QChartView;
with Qt.QPainter; use Qt.QPainter;
with Qt.QLayout; use Qt.QLayout;
with Qt.QSize; use Qt.QSize;
with Qt.QGroupBox; use Qt.QGroupBox;
with Qt.QAbstractSeries; use Qt.QAbstractSeries;
with Qt.QValueAxis; use Qt.QValueAxis;
with Qt.QAbstractAxis; use Qt.QAbstractAxis;
with Qt.QObjectList; use Qt.QObjectList;
with Qt.QButton; use Qt.QButton;
with Qt.QStackedLayout; use Qt.QStackedLayout;
with Qt.QStackedWidget; use Qt.QStackedWidget;
with Qt.QDateTime; use Qt.QDateTime;
with Qt.QCheckBox; use Qt.QCheckBox;
with platform; use platform;
with covid_19; use covid_19;
with xph_model; use xph_model;
package body CovidSimForm is
simulation_engine_choice : QComboBoxH;
simulation_engines : QStringListH := QStringList_create;
--stack : QStackedLayoutH;
--stack_widget: QStackedWidgetH;
scenario_choice : QComboBoxH;
scenarios : QStringListH := QStringList_create;
graphic_view : QGraphicsViewH;
chart : QChartH;
number_iterations : QSpinBoxH;
number_population : QSpinBoxH;
export_button : QAbstractButtonH;
function enum_image_to_beautiful_image (image : String) return String is
lower_name : String := to_lower (image);
begin
for i in lower_name'Range loop
if lower_name(i) = '_' then
lower_name(i) := ' ';
end if;
end loop;
return lower_name;
end;
function beautiful_image_to_enum_image (lower_name : String) return String is
upper_name : String := to_upper(lower_name);
begin
for i in upper_name'Range loop
if upper_name(i) = ' ' then
upper_name(i) := '_';
end if;
end loop;
return upper_name;
end;
procedure init_simulation_engine_choice is
begin
simulation_engine_choice := QComboBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("simulation_engine_choice")));
for s in simulation_engine loop
QStringList_append(handle => simulation_engines, s => s2qs(enum_image_to_beautiful_image(s'Image)));
end loop;
QComboBox_addItems (handle => simulation_engine_choice, texts => simulation_engines);
end;
procedure update_line_chart (sim_data : Simulation_Data; scenario_beautiful_name: QStringH) is
type Series is array (Status) of QSeriesH;
data_series : Series;
axes : QObjectListH;
begin
QChart_removeAllSeries (chart);
for i in sim_data'range (1) loop
data_series(i) := QLineSeries_create;
QAbstractSeries_setName(data_series(i), s2qs(enum_image_to_beautiful_image(i'Image)));
for j in sim_data'range (2) loop
QXYSeries_append (data_series (i), qreal (j), qreal (sim_data(i,j)));
end loop;
QChart_addSeries (chart, data_series(i));
end loop;
QChart_createDefaultAxes (chart);
axes := QChart_axes(chart);
QAbstractAxis_setTitletext(QAxisH(QObjectList_at(axes, 0)), s2qs("Iterations"));
QValueAxis_setLabelFormat(QAxisH(QObjectList_at(axes, 0)), s2qs("%d"));
QAbstractAxis_setTitletext(QAxisH(QObjectList_at(axes, 1)), s2qs("Population"));
QValueAxis_setLabelFormat(QAxisH(QObjectList_at(axes, 1)), s2qs("%d"));
QChart_setTitle (chart, scenario_beautiful_name);
exception
when Error: others =>
Put ("Unexpected exception: ");
Put_Line (Exception_Information(Error));
end;
procedure update_simulation is
scenario_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(scenario_choice)));
results : Simulation_Data := Simulation(Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));
begin
update_line_chart(results, QComboBox_currentText(scenario_choice));
end;
procedure set_simulation_engine_panel is
simulation_engine_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(simulation_engine_choice)));
simulation_choice : Simulation_Engine := Simulation_Engine'Value(simulation_engine_name);
stack : QStackedWidgetH := QStackedWidgetH (QObject_findChild (QObjectH (covidsim_form), s2qs ("simulation_panels")));
begin
if simulation_choice = XPH_Pharmaceutical then
QStackedWidget_setCurrentIndex (stack, 0);
slot_change_country_choice (s2qs (""));
end if;
if simulation_choice = Lancet then
QStackedWidget_setCurrentIndex (stack, 1);
update_simulation; -- lancet model stuff TODO : move to lancet_model
end if;
end;
procedure init_chart is
legend : QLegendH;
chart_view : QGraphicsViewH;
horizontal_layout : QBoxLayoutH := QHBoxLayout_create;
begin
chart := QChart_create;
legend := QChart_legend (chart);
QLegend_setVisible (legend, true);
chart_view := QChartView_create (chart);
QGraphicsView_setRenderHint (chart_view, QPainterAntialiasing);
QBoxLayout_addWidget (horizontal_layout, QWidgetH(chart_view));
QWidget_setLayout (QwidgetH (graphic_view), horizontal_layout);
end;
procedure init_scenario_choices is
begin
scenario_choice := QComboBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("scenario_choice")));
for s in Scenario loop
QStringList_append(handle => scenarios, s => s2qs(enum_image_to_beautiful_image(s'Image)));
end loop;
QComboBox_addItems (handle => scenario_choice, texts => scenarios);
end;
procedure set_xph_model_ui (form : QWidgetH) is
compute_xph_button : QPushButtonH := QPushButtonH (QObject_findChild (QObjectH (covidsim_form), s2qs ("compute_xph")));
country_choice : QComboBoxH := QComboBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("country_choice")));
start_date_value : QDateEditH := QDateEditH (QObject_findChild (QObjectH (covidsim_form), s2qs ("start_date_value")));
end_date_value : QDateEditH := QDateEditH (QObject_findChild (QObjectH (covidsim_form), s2qs ("end_date_value")));
forecast_days_value : QSpinBoxH := QSpinBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("forecast_days_value")));
refine_search : QCheckBoxH := QCheckBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("refine_search")));
begin
QAbstractButton_signal_slot_clicked (compute_xph_button, slot_compute_xph'access);
QComboBox_signal_slot_activated2 (country_choice, slot_change_country_choice'access);
QDateEdit_signal_slot_userDateChanged (start_date_value, slot_start_date_changed'access);
QDateEdit_signal_slot_userDateChanged (end_date_value, slot_end_date_changed'access);
QSpinBox_signal_slot_valueChanged (forecast_days_value, slot_change_forecast_days'access);
QCheckBox_signal_slot_stateChanged (refine_search, slot_change_refine_search'access);
init_model (form, chart);
end;
procedure covidsim_form_init (parent : QWidgetH := null) is
begin
-- create the UI based on QTDesigner .ui file specification
covidsim_form := QUiLoader_loadFromFile (QUiLoader_create, s2qs (get_ui_specification_filepath));
-- fetch and 'cache' the widgets we want to manipulate, by name, from our .ui design
graphic_view := QGraphicsViewH (QObject_findChild (QObjectH (covidsim_form), s2qs ("graphic_view")));
number_iterations := QSpinBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("number_iterations")));
number_population := QSpinBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs ("number_population")));
export_button := QAbstractButtonH (QObject_findChild (QObjectH (covidsim_form), s2qs ("export_to_csv")));
-- populate 'complex' widgets
init_chart;
init_scenario_choices;
init_simulation_engine_choice;
set_simulation_engine_panel;
-- define and set qt 'callbacks' on widgets of interest
QComboBox_signal_slot_activated2 (simulation_engine_choice, slot_change_simulation_engine'access);
QComboBox_signal_slot_activated2 (scenario_choice, slot_change_scenario'access);
QSpinBox_signal_slot_valueChanged (number_iterations, slot_change_iterations'access);
QSpinBox_signal_slot_valueChanged (number_population, slot_change_population'access);
QAbstractButton_signal_slot_clicked (export_button, slot_export_to_csv'access);
set_xph_model_ui (covidsim_form);
-- we do a first draw of the chart
update_simulation;
exception
when Error: others =>
Put ("Unexpected exception: ");
Put_Line (Exception_Information(Error));
end;
procedure slot_change_simulation_engine (simulation_engine_beautiful_name: QStringH) is
begin
set_simulation_engine_panel;
end;
procedure slot_change_scenario (scenario_beautiful_name: QStringH) is
begin
update_simulation;
end;
procedure slot_change_iterations (iterations: Integer) is
begin
update_simulation;
end;
procedure slot_change_population (population: Integer) is
begin
update_simulation;
end;
procedure slot_export_to_csv is
scenario_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(scenario_choice)));
results : Simulation_Data := Simulation(Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));
begin
Export_To_CSV (results, Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));
end;
end;
|
with
opengl.Display .privvy,
opengl.surface_Profile.privvy,
opengl.Surface .privvy,
egl.Binding,
System;
package body openGL.Context
is
use egl.Binding,
System;
procedure define (Self : in out Item; the_Display : access opengl.Display.item'Class;
the_surface_Profile : in opengl.surface_Profile.item)
is
use EGL,
opengl.Display .privvy,
opengl.surface_Profile.privvy;
contextAttribs : EGLint_array := (EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE);
begin
Self.egl_Context := eglCreateContext (to_eGL (the_Display.all),
to_eGL (the_surface_Profile),
EGL_NO_CONTEXT,
contextAttribs (contextAttribs'First)'Unchecked_Access);
if Self.egl_Context = EGL_NO_CONTEXT then
raise opengl.Error with "Unable to create an EGL Context.";
end if;
Self.Display := the_Display;
end define;
procedure make_Current (Self : in Item; read_Surface : in opengl.Surface.item;
write_Surface : in opengl.Surface.item)
is
use eGL,
opengl.Display.privvy,
opengl.Surface.privvy;
use type EGLBoolean;
Success : constant EGLBoolean := eglmakeCurrent (to_eGL (Self.Display.all),
to_eGL (read_Surface),
to_eGL (write_Surface),
Self.egl_Context);
begin
if Success = EGL_FALSE then
raise openGL.Error with "unable to make egl Context current";
end if;
end make_Current;
function egl_Context_debug (Self : in Item'Class) return egl.EGLConfig
is
begin
return self.egl_Context;
end egl_Context_debug;
end openGL.Context;
|
with AUnit.Test_Fixtures;
with AUnit.Test_Suites;
package SHA2_Streams_Tests is
function Suite return AUnit.Test_Suites.Access_Test_Suite;
private
type Fixture is new AUnit.Test_Fixtures.Test_Fixture with null record;
procedure SHA2_224_Test (Object : in out Fixture);
procedure SHA2_224_One_Million_Test (Object : in out Fixture);
procedure SHA2_224_Extremely_Long_Test (Object : in out Fixture);
procedure SHA2_256_Test (Object : in out Fixture);
procedure SHA2_256_One_Million_Test (Object : in out Fixture);
procedure SHA2_256_Extremely_Long_Test (Object : in out Fixture);
procedure SHA2_384_Test (Object : in out Fixture);
procedure SHA2_384_One_Million_Test (Object : in out Fixture);
procedure SHA2_384_Extremely_Long_Test (Object : in out Fixture);
procedure SHA2_512_Test (Object : in out Fixture);
procedure SHA2_512_One_Million_Test (Object : in out Fixture);
procedure SHA2_512_Extremely_Long_Test (Object : in out Fixture);
procedure SHA2_512_224_Test (Object : in out Fixture);
procedure SHA2_512_224_One_Million_Test (Object : in out Fixture);
procedure SHA2_512_256_Test (Object : in out Fixture);
procedure SHA2_512_256_One_Million_Test (Object : in out Fixture);
end SHA2_Streams_Tests;
|
with
AdaM.Factory;
package body AdaM.Declaration.of_renaming
is
-- Storage Pool
--
record_Version : constant := 1;
pool_Size : constant := 5_000;
package Pool is new AdaM.Factory.Pools (".adam-store",
"Declaration.of_renamings",
pool_Size,
record_Version,
Declaration.of_renaming.item,
Declaration.of_renaming.view);
-- Forge
--
procedure define (Self : in out Item)
is
begin
null;
end define;
overriding
procedure destruct (Self : in out Item)
is
begin
null;
end destruct;
function new_Declaration return View
is
new_View : constant Declaration.of_renaming.view := Pool.new_Item;
begin
define (Declaration.of_renaming.item (new_View.all));
return new_View;
end new_Declaration;
procedure free (Self : in out Declaration.of_renaming.view)
is
begin
destruct (Declaration.of_renaming.item (Self.all));
Pool.free (Self);
end free;
-- Attributes
--
overriding
function Id (Self : access Item) return AdaM.Id
is
begin
return Pool.to_Id (Self);
end Id;
-- Streams
--
procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : in View)
renames Pool.View_write;
procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Self : out View)
renames Pool.View_read;
end AdaM.Declaration.of_renaming;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
package Orka.Transforms.Singles is
pragma Pure;
end Orka.Transforms.Singles;
|
with External; use External;
with Node; use Node;
with Ada.Containers.Doubly_Linked_Lists;
with Logger;
with RandInt;
procedure Main is
package LST is new Ada.Containers.Doubly_Linked_Lists(Element_Type => pNodeObj);
n: Natural;
d: Natural;
k: Natural;
maxSleep: Natural;
begin
if CMD.Argument_Count /= 4 then
PrintBounded("four arguments necessary");
return;
end if;
n := Natural'Value(CMD.Argument(1));
d := Natural'Value(CMD.Argument(2));
k := Natural'Value(CMD.Argument(3));
maxSleep := Natural'Value(CMD.Argument(4));
declare
subtype RangeN is Natural range 1..n;
nodes: pArray_pNodeObj;
-- holder of `d` additional edges
subtype RangeD is Natural range 1..d;
-- RangeD (extended): `0` means there is no shortcut
subtype RangeDE is Natural range 0..d;
package RAD renames RandInt;
type AdditionalEdges is array (RangeD, 1..2) of Natural;
type pAdditionalEdges is access AdditionalEdges;
shortcuts: pAdditionalEdges;
type AdditionalEdgesArrayLengths is array (RangeN) of Natural;
type pAdditionalEdgesArrayLengths is access AdditionalEdgesArrayLengths;
shortcutsLengths: pAdditionalEdgesArrayLengths;
subtype RangeK is Natural range 1..k;
package LOG renames Logger;
loggerReceiver: LOG.pLoggerReceiver;
tmp: Natural := 0;
tmp2: Natural := 0;
tmp3: Natural := 0;
tmpExit: Boolean := False;
tmpNodeObj: pNodeObj;
tmpNodeObj2: pNodeObj;
tmpMessage: pMessage;
task type SenderTask(firstNode: pNodeObj);
task body SenderTask is
begin
for I in RangeK'Range loop
tmpMessage := new Message'(content => I);
firstNode.all.nodeTask.all.SendMessage(tmpMessage);
end loop;
end SenderTask;
type pSenderTask is access SenderTask;
sender: pSenderTask;
begin
-- instantiate the logger task
loggerReceiver := new LOG.LoggerReceiver(n, d, k);
-- create all nodes
nodes := new Array_pNodeObj(RangeN);
for I in RangeN'Range loop
nodes.all(I) := new NodeObj;
nodes.all(I).all.id := I-1;
end loop;
-- generate shortcuts
shortcuts := new AdditionalEdges;
for I in RangeD'Range loop
tmp := RAD.Next(n);
tmp2 := RAD.Next(n);
if tmp > tmp2 then
tmp3 := tmp;
tmp := tmp2;
tmp2 := tmp3;
end if;
if tmp /= tmp2 then
-- shortcut successfully created
shortcuts(I, 1) := tmp;
shortcuts(I, 2) := tmp2;
loggerReceiver.Log("shortcut" & Natural'Image(tmp-1) & " →" & Natural'Image(tmp2-1));
else
shortcuts(I, 1) := 0;
shortcuts(I, 2) := 0;
end if;
end loop;
loggerReceiver.Log("---");
-- we need to precalculate the neighbours’ array size
shortcutsLengths := new AdditionalEdgesArrayLengths;
-- initialize with `1`, because each node has at least one neighbour
for I in RangeN'Range loop
shortcutsLengths.all(I) := 1;
end loop;
shortcutsLengths.all(RangeN'Last) := 0;
-- count all the additional edges
for I in RangeD'Range loop
-- get the beginning node
tmp := shortcuts(I, 1);
if tmp > 0 and tmp <= n then
shortcutsLengths.all(tmp) := shortcutsLengths.all(tmp) + 1;
end if;
end loop;
-- special case for the last node
-- now we can initialize our nodes
for I in RangeN'Range loop
tmpNodeObj := nodes.all(I);
tmpNodeObj.all.neighbours := new Array_pNodeObj(1..shortcutsLengths.all(I));
if I < n then
tmpNodeObj.all.nodeTask := new NodeTask(tmpNodeObj, maxSleep, loggerReceiver, False);
else
tmpNodeObj.all.nodeTask := new NodeTask(tmpNodeObj, maxSleep, loggerReceiver, True);
end if;
end loop;
-- and add pointers to neighbours
for I in RangeD'Range loop
-- get the beginning node of the edge
tmp := shortcuts.all(I, 1);
if tmp /= 0 then
tmpNodeObj := nodes.all(tmp);
-- get the ending node of the edge
tmp2 := shortcuts.all(I, 2);
tmpNodeObj2 := nodes.all(tmp2);
-- add the neighbour (we’re using the lengths array as our pointer)
tmpNodeObj.all.neighbours(shortcutsLengths.all(tmp)) := tmpNodeObj2;
-- decrease the array pointer
shortcutsLengths.all(tmp) := shortcutsLengths.all(tmp) - 1;
end if;
end loop;
-- also add the edges for adjacent nodes
for I in RangeN'Range loop
-- current node
tmpNodeObj := nodes(I);
if I < n then
-- next node
tmpNodeObj2 := nodes(I+1);
-- add as neighbour
tmpNodeObj.all.neighbours(1) := tmpNodeObj2;
else
-- special case for the last node
null;
end if;
end loop;
-- send the messages
tmpNodeObj2 := nodes(RangeN'First);
sender := new SenderTask(tmpNodeObj2);
-- receive the messages
tmpNodeObj := nodes(RangeN'Last);
for I in RangeK'Range loop
tmpMessage := new Message;
if tmpMessage /= null then
tmpNodeObj.all.nodeTask.all.ReceiveMessage(tmpMessage);
loggerReceiver.Log("→→→message" & Natural'Image(tmpMessage.all.content) & " received");
end if;
end loop;
for I in RangeN'Range loop
nodes(I).all.nodeTask.Stop;
end loop;
loggerReceiver.Stop;
end;
end Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K I N G . U T I L I T I E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
-- --
-- GNARL 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/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides RTS Internal Declarations
-- These declarations are not part of the GNARLI
pragma Polling (Off);
-- Turn off polling, we do not want ATC polling to take place during tasking
-- operations. It causes infinite loops and other problems.
with System.Tasking.Debug;
with System.Task_Primitives.Operations;
with System.Tasking.Initialization;
with System.Tasking.Queuing;
with System.Parameters;
with System.Traces.Tasking;
package body System.Tasking.Utilities is
package STPO renames System.Task_Primitives.Operations;
use Parameters;
use Tasking.Debug;
use Task_Primitives;
use Task_Primitives.Operations;
use System.Traces;
use System.Traces.Tasking;
--------------------
-- Abort_One_Task --
--------------------
-- Similar to Locked_Abort_To_Level (Self_ID, T, 0), but:
-- (1) caller should be holding no locks except RTS_Lock when Single_Lock
-- (2) may be called for tasks that have not yet been activated
-- (3) always aborts whole task
procedure Abort_One_Task (Self_ID : Task_Id; T : Task_Id) is
begin
if Parameters.Runtime_Traces then
Send_Trace_Info (T_Abort, Self_ID, T);
end if;
Write_Lock (T);
if T.Common.State = Unactivated then
T.Common.Activator := null;
T.Common.State := Terminated;
T.Callable := False;
Cancel_Queued_Entry_Calls (T);
elsif T.Common.State /= Terminated then
Initialization.Locked_Abort_To_Level (Self_ID, T, 0);
end if;
Unlock (T);
end Abort_One_Task;
-----------------
-- Abort_Tasks --
-----------------
-- This must be called to implement the abort statement.
-- Much of the actual work of the abort is done by the abortee,
-- via the Abort_Handler signal handler, and propagation of the
-- Abort_Signal special exception.
procedure Abort_Tasks (Tasks : Task_List) is
Self_Id : constant Task_Id := STPO.Self;
C : Task_Id;
P : Task_Id;
begin
-- If pragma Detect_Blocking is active then Program_Error must be
-- raised if this potentially blocking operation is called from a
-- protected action.
if System.Tasking.Detect_Blocking
and then Self_Id.Common.Protected_Action_Nesting > 0
then
raise Program_Error with "potentially blocking operation";
end if;
Initialization.Defer_Abort_Nestable (Self_Id);
-- ?????
-- Really should not be nested deferral here.
-- Patch for code generation error that defers abort before
-- evaluating parameters of an entry call (at least, timed entry
-- calls), and so may propagate an exception that causes abort
-- to remain undeferred indefinitely. See C97404B. When all
-- such bugs are fixed, this patch can be removed.
Lock_RTS;
for J in Tasks'Range loop
C := Tasks (J);
Abort_One_Task (Self_Id, C);
end loop;
C := All_Tasks_List;
while C /= null loop
if C.Pending_ATC_Level > 0 then
P := C.Common.Parent;
while P /= null loop
if P.Pending_ATC_Level = 0 then
Abort_One_Task (Self_Id, C);
exit;
end if;
P := P.Common.Parent;
end loop;
end if;
C := C.Common.All_Tasks_Link;
end loop;
Unlock_RTS;
Initialization.Undefer_Abort_Nestable (Self_Id);
end Abort_Tasks;
-------------------------------
-- Cancel_Queued_Entry_Calls --
-------------------------------
-- This should only be called by T, unless T is a terminated previously
-- unactivated task.
procedure Cancel_Queued_Entry_Calls (T : Task_Id) is
Next_Entry_Call : Entry_Call_Link;
Entry_Call : Entry_Call_Link;
Self_Id : constant Task_Id := STPO.Self;
Caller : Task_Id;
pragma Unreferenced (Caller);
-- Should this be removed ???
Level : Integer;
pragma Unreferenced (Level);
-- Should this be removed ???
begin
pragma Assert (T = Self or else T.Common.State = Terminated);
for J in 1 .. T.Entry_Num loop
Queuing.Dequeue_Head (T.Entry_Queues (J), Entry_Call);
while Entry_Call /= null loop
-- Leave Entry_Call.Done = False, since this is cancelled
Caller := Entry_Call.Self;
Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
Queuing.Dequeue_Head (T.Entry_Queues (J), Next_Entry_Call);
Level := Entry_Call.Level - 1;
Unlock (T);
Write_Lock (Entry_Call.Self);
Initialization.Wakeup_Entry_Caller
(Self_Id, Entry_Call, Cancelled);
Unlock (Entry_Call.Self);
Write_Lock (T);
Entry_Call.State := Done;
Entry_Call := Next_Entry_Call;
end loop;
end loop;
end Cancel_Queued_Entry_Calls;
------------------------
-- Exit_One_ATC_Level --
------------------------
-- Call only with abort deferred and holding lock of Self_Id.
-- This is a bit of common code for all entry calls.
-- The effect is to exit one level of ATC nesting.
-- If we have reached the desired ATC nesting level, reset the
-- requested level to effective infinity, to allow further calls.
-- In any case, reset Self_Id.Aborting, to allow re-raising of
-- Abort_Signal.
procedure Exit_One_ATC_Level (Self_ID : Task_Id) is
begin
Self_ID.ATC_Nesting_Level := Self_ID.ATC_Nesting_Level - 1;
pragma Debug
(Debug.Trace (Self_ID, "EOAL: exited to ATC level: " &
ATC_Level'Image (Self_ID.ATC_Nesting_Level), 'A'));
pragma Assert (Self_ID.ATC_Nesting_Level >= 1);
if Self_ID.Pending_ATC_Level < ATC_Level_Infinity then
if Self_ID.Pending_ATC_Level = Self_ID.ATC_Nesting_Level then
Self_ID.Pending_ATC_Level := ATC_Level_Infinity;
Self_ID.Aborting := False;
else
-- Force the next Undefer_Abort to re-raise Abort_Signal
pragma Assert
(Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level);
if Self_ID.Aborting then
Self_ID.ATC_Hack := True;
Self_ID.Pending_Action := True;
end if;
end if;
end if;
end Exit_One_ATC_Level;
----------------------
-- Make_Independent --
----------------------
function Make_Independent return Boolean is
Self_Id : constant Task_Id := STPO.Self;
Environment_Task : constant Task_Id := STPO.Environment_Task;
Parent : constant Task_Id := Self_Id.Common.Parent;
begin
if Self_Id.Known_Tasks_Index /= -1 then
Known_Tasks (Self_Id.Known_Tasks_Index) := null;
end if;
Initialization.Defer_Abort (Self_Id);
if Single_Lock then
Lock_RTS;
end if;
Write_Lock (Environment_Task);
Write_Lock (Self_Id);
-- The run time assumes that the parent of an independent task is the
-- environment task.
pragma Assert (Parent = Environment_Task);
Self_Id.Master_of_Task := Independent_Task_Level;
-- Update Independent_Task_Count that is needed for the GLADE
-- termination rule. See also pending update in
-- System.Tasking.Stages.Check_Independent
Independent_Task_Count := Independent_Task_Count + 1;
-- This should be called before the task reaches its "begin" (see spec),
-- which ensures that the environment task cannot race ahead and be
-- already waiting for children to complete.
Unlock (Self_Id);
pragma Assert (Environment_Task.Common.State /= Master_Completion_Sleep);
Unlock (Environment_Task);
if Single_Lock then
Unlock_RTS;
end if;
Initialization.Undefer_Abort (Self_Id);
-- Return True. Actually the return value is junk, since we expect it
-- always to be ignored (see spec), but we have to return something!
return True;
end Make_Independent;
------------------
-- Make_Passive --
------------------
procedure Make_Passive (Self_ID : Task_Id; Task_Completed : Boolean) is
C : Task_Id := Self_ID;
P : Task_Id := C.Common.Parent;
Master_Completion_Phase : Integer;
begin
if P /= null then
Write_Lock (P);
end if;
Write_Lock (C);
if Task_Completed then
Self_ID.Common.State := Terminated;
if Self_ID.Awake_Count = 0 then
-- We are completing via a terminate alternative.
-- Our parent should wait in Phase 2 of Complete_Master.
Master_Completion_Phase := 2;
pragma Assert (Task_Completed);
pragma Assert (Self_ID.Terminate_Alternative);
pragma Assert (Self_ID.Alive_Count = 1);
else
-- We are NOT on a terminate alternative.
-- Our parent should wait in Phase 1 of Complete_Master.
Master_Completion_Phase := 1;
pragma Assert (Self_ID.Awake_Count >= 1);
end if;
-- We are accepting with a terminate alternative
else
if Self_ID.Open_Accepts = null then
-- Somebody started a rendezvous while we had our lock open.
-- Skip the terminate alternative.
Unlock (C);
if P /= null then
Unlock (P);
end if;
return;
end if;
Self_ID.Terminate_Alternative := True;
Master_Completion_Phase := 0;
pragma Assert (Self_ID.Terminate_Alternative);
pragma Assert (Self_ID.Awake_Count >= 1);
end if;
if Master_Completion_Phase = 2 then
-- Since our Awake_Count is zero but our Alive_Count
-- is nonzero, we have been accepting with a terminate
-- alternative, and we now have been told to terminate
-- by a completed master (in some ancestor task) that
-- is waiting (with zero Awake_Count) in Phase 2 of
-- Complete_Master.
pragma Debug (Debug.Trace (Self_ID, "Make_Passive: Phase 2", 'M'));
pragma Assert (P /= null);
C.Alive_Count := C.Alive_Count - 1;
if C.Alive_Count > 0 then
Unlock (C);
Unlock (P);
return;
end if;
-- C's count just went to zero, indicating that
-- all of C's dependents are terminated.
-- C has a parent, P.
loop
-- C's count just went to zero, indicating that all of C's
-- dependents are terminated. C has a parent, P. Notify P that
-- C and its dependents have all terminated.
P.Alive_Count := P.Alive_Count - 1;
exit when P.Alive_Count > 0;
Unlock (C);
Unlock (P);
C := P;
P := C.Common.Parent;
-- Environment task cannot have terminated yet
pragma Assert (P /= null);
Write_Lock (P);
Write_Lock (C);
end loop;
if P.Common.State = Master_Phase_2_Sleep
and then C.Master_of_Task = P.Master_Within
then
pragma Assert (P.Common.Wait_Count > 0);
P.Common.Wait_Count := P.Common.Wait_Count - 1;
if P.Common.Wait_Count = 0 then
Wakeup (P, Master_Phase_2_Sleep);
end if;
end if;
Unlock (C);
Unlock (P);
return;
end if;
-- We are terminating in Phase 1 or Complete_Master,
-- or are accepting on a terminate alternative.
C.Awake_Count := C.Awake_Count - 1;
if Task_Completed then
C.Alive_Count := C.Alive_Count - 1;
end if;
if C.Awake_Count > 0 or else P = null then
Unlock (C);
if P /= null then
Unlock (P);
end if;
return;
end if;
-- C's count just went to zero, indicating that all of C's
-- dependents are terminated or accepting with terminate alt.
-- C has a parent, P.
loop
-- Notify P that C has gone passive
if P.Awake_Count > 0 then
P.Awake_Count := P.Awake_Count - 1;
end if;
if Task_Completed and then C.Alive_Count = 0 then
P.Alive_Count := P.Alive_Count - 1;
end if;
exit when P.Awake_Count > 0;
Unlock (C);
Unlock (P);
C := P;
P := C.Common.Parent;
if P = null then
return;
end if;
Write_Lock (P);
Write_Lock (C);
end loop;
-- P has non-passive dependents
if P.Common.State = Master_Completion_Sleep
and then C.Master_of_Task = P.Master_Within
then
pragma Debug
(Debug.Trace
(Self_ID, "Make_Passive: Phase 1, parent waiting", 'M'));
-- If parent is in Master_Completion_Sleep, it cannot be on a
-- terminate alternative, hence it cannot have Wait_Count of zero.
pragma Assert (P.Common.Wait_Count > 0);
P.Common.Wait_Count := P.Common.Wait_Count - 1;
if P.Common.Wait_Count = 0 then
Wakeup (P, Master_Completion_Sleep);
end if;
else
pragma Debug
(Debug.Trace (Self_ID, "Make_Passive: Phase 1, parent awake", 'M'));
null;
end if;
Unlock (C);
Unlock (P);
end Make_Passive;
end System.Tasking.Utilities;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . G E N E R I C _ A R R A Y _ S O R T --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
generic
type Index_Type is (<>);
type Element_Type is private;
type Array_Type is array (Index_Type range <>) of Element_Type;
with function "<" (Left, Right : Element_Type) return Boolean is <>;
procedure Ada.Containers.Generic_Array_Sort (Container : in out Array_Type);
pragma Pure (Ada.Containers.Generic_Array_Sort);
-- Reorders the elements of Container such that the elements are sorted
-- smallest first as determined by the generic formal "<" operator provided.
-- Any exception raised during evaluation of "<" is propagated.
--
-- The actual function for the generic formal function "<" is expected to
-- return the same value each time it is called with a particular pair of
-- element values. It should not modify Container and it should define a
-- strict weak ordering relationship: irreflexive, asymmetric, transitive, and
-- in addition, if x < y for any values x and y, then for all other values z,
-- (x < z) or (z < y). If the actual for "<" behaves in some other manner,
-- the behavior of the instance of Generic_Array_Sort is unspecified. The
-- number of times Generic_Array_Sort calls "<" is unspecified.
|
-----------------------------------------------------------------------
-- asf-navigations-mappers -- Read XML navigation files
-- Copyright (C) 2010, 2011 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
with Util.Serialize.Mappers.Record_Mapper;
with Util.Serialize.IO.XML;
with EL.Contexts;
-- The <b>ASF.Navigations.Reader</b> package defines an XML mapper that can be used
-- to read the XML navigation files.
package ASF.Navigations.Mappers is
type Navigation_Case_Fields is (FROM_VIEW_ID, OUTCOME, ACTION, TO_VIEW, REDIRECT, CONDITION,
CONTENT, CONTENT_TYPE, NAVIGATION_CASE, NAVIGATION_RULE);
-- ------------------------------
-- Navigation Config Reader
-- ------------------------------
-- When reading and parsing the XML navigation file, the <b>Nav_Config</b> object
-- is populated by calls through the <b>Set_Member</b> procedure. The data is
-- collected and when the end of the navigation case element is reached,
-- the new navigation case is inserted in the navigation handler.
type Nav_Config is limited record
Outcome : Util.Beans.Objects.Object;
Action : Util.Beans.Objects.Object;
To_View : Util.Beans.Objects.Object;
From_View : Util.Beans.Objects.Object;
Redirect : Boolean := False;
Condition : Util.Beans.Objects.Object;
Content : Util.Beans.Objects.Object;
Content_Type : Util.Beans.Objects.Object;
Context : EL.Contexts.ELContext_Access;
Handler : Navigation_Handler_Access;
end record;
type Nav_Config_Access is access all Nav_Config;
-- Save in the navigation config object the value associated with the given field.
-- When the <b>NAVIGATION_CASE</b> field is reached, insert the new navigation rule
-- that was collected in the navigation handler.
procedure Set_Member (N : in out Nav_Config;
Field : in Navigation_Case_Fields;
Value : in Util.Beans.Objects.Object);
-- Setup the XML parser to read the navigation rules.
generic
Reader : in out Util.Serialize.IO.XML.Parser;
Handler : in Navigation_Handler_Access;
Context : in EL.Contexts.ELContext_Access;
package Reader_Config is
Config : aliased Nav_Config;
end Reader_Config;
private
-- Reset the navigation config before parsing a new rule.
procedure Reset (N : in out Nav_Config);
package Navigation_Mapper is
new Util.Serialize.Mappers.Record_Mapper (Element_Type => Nav_Config,
Element_Type_Access => Nav_Config_Access,
Fields => Navigation_Case_Fields,
Set_Member => Set_Member);
end ASF.Navigations.Mappers;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- F N A M E . S F --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- This child package contains a routine to read and process Source_File_Name
-- pragmas from the gnat.adc file in the current directory. In order to use
-- the routines in package Fname.UF, it is required that Source_File_Name
-- pragmas be processed. There are two places where such processing takes
-- place:
-- The compiler front end (par-prag.adb), which is the general circuit
-- for processing all pragmas, including Source_File_Name.
-- The stand alone routine in this unit, which is convenient to use
-- from tools that do not want to include the compiler front end.
-- Note that this unit does depend on several of the compiler front-end
-- sources, including osint. If it is necessary to scan source file name
-- pragmas with less dependence on such sources, look at unit SFN_Scan.
package Fname.SF is
procedure Read_Source_File_Name_Pragmas;
-- This procedure is called to read the gnat.adc file and process any
-- Source_File_Name pragmas contained in this file. All other pragmas
-- are ignored. The result is appropriate calls to routines in the
-- package Fname.UF to register the pragmas so that subsequent calls
-- to Get_File_Name work correctly.
--
-- Note: The caller must have made an appropriate call to the
-- Osint.Initialize routine to initialize Osint before calling
-- this procedure.
--
-- If a syntax error is detected while scanning the gnat.adc file,
-- then the exception SFN_Scan.Syntax_Error_In_GNAT_ADC is raised
-- and SFN_Scan.Cursor contains the approximate index relative to
-- the start of the gnat.adc file of the error.
end Fname.SF;
|
------------------------------------------------------------------------------
-- --
-- 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.Device; use STM32.Device;
with STM32.GPIO; use STM32.GPIO;
package body Framebuffer_RK043FN48H is
LCD_BL_CTRL : GPIO_Point renames PK3;
LCD_ENABLE : GPIO_Point renames PI12;
LCD_HSYNC : GPIO_Point renames PI10;
LCD_VSYNC : GPIO_Point renames PI9;
LCD_CLK : GPIO_Point renames PI14;
LCD_DE : GPIO_Point renames PK7;
LCD_INT : GPIO_Point renames PI13;
NC1 : GPIO_Point renames PI8;
LCD_CTRL_PINS : constant GPIO_Points :=
(LCD_VSYNC, LCD_HSYNC, LCD_INT,
LCD_CLK, LCD_DE, NC1);
LCD_RGB_AF14 : constant GPIO_Points :=
(PI15, PJ0, PJ1, PJ2, PJ3, PJ4, PJ5, PJ6, -- Red
PJ7, PJ8, PJ9, PJ10, PJ11, PK0, PK1, PK2, -- Green
PE4, PJ13, PJ14, PJ15, PK4, PK5, PK6); -- Blue
LCD_RGB_AF9 : constant GPIO_Points :=
(1 => PG12); -- B4
procedure Init_Pins;
---------------
-- Init_Pins --
---------------
procedure Init_Pins
is
LTDC_Pins : constant GPIO_Points :=
LCD_CTRL_PINS & LCD_RGB_AF14 & LCD_RGB_AF9;
begin
Enable_Clock (LTDC_Pins);
Configure_Alternate_Function
(LCD_CTRL_PINS & LCD_RGB_AF14, GPIO_AF_LTDC_14);
Configure_Alternate_Function (LCD_RGB_AF9, GPIO_AF_LTDC_9);
Configure_IO
(Points => LTDC_Pins,
Config => (Speed => Speed_50MHz,
Mode => Mode_AF,
Output_Type => Push_Pull,
Resistors => Floating));
Lock (LTDC_Pins);
Configure_IO
(GPIO_Points'(LCD_ENABLE, LCD_BL_CTRL),
Config => (Speed => Speed_2MHz,
Mode => Mode_Out,
Output_Type => Push_Pull,
Resistors => Pull_Down));
Lock (LCD_ENABLE & LCD_BL_CTRL);
end Init_Pins;
----------------
-- Initialize --
----------------
procedure Initialize
(Display : in out Frame_Buffer;
Orientation : HAL.Framebuffer.Display_Orientation := Default;
Mode : HAL.Framebuffer.Wait_Mode := Interrupt)
is
begin
Init_Pins;
Display.Initialize
(Width => LCD_Natural_Width,
Height => LCD_Natural_Height,
H_Sync => 41,
H_Back_Porch => 13,
H_Front_Porch => 32,
V_Sync => 10,
V_Back_Porch => 2,
V_Front_Porch => 2,
PLLSAI_N => 192,
PLLSAI_R => 5,
DivR => 4,
Orientation => Orientation,
Mode => Mode);
STM32.GPIO.Set (LCD_ENABLE);
STM32.GPIO.Set (LCD_BL_CTRL);
end Initialize;
end Framebuffer_RK043FN48H;
|
package body DFA
with SPARK_Mode => On
is
function F1 (X : in Integer) return Integer
is
Tmp : Integer;
begin
-- The most basic form of DFA bug - Tmp is definitely not initialized. We
-- call this an Unconditional Data Flow Error
return X + Tmp;
end F1;
function F2 (X : in Integer) return Integer
is
Tmp : Integer;
begin
case X is
when Integer'First .. -1 =>
Tmp := -1;
when 0 =>
null;
when 1 .. Integer'Last =>
Tmp := 1;
end case;
-- Slightly more subtle - Tmp _might_ not be initialized, depending on
-- the initial value of X. We call this a Conditional Data Flow Error.
-- Note that the error message issued here is different from that issued
-- in F1 above.
return X + Tmp;
end F2;
end DFA;
|
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_IO;
procedure Main is
package FIO is new Ada.Text_IO.Float_IO (Float);
type Point is record
X, Y : Float;
end record;
function "-" (Left, Right : Point) return Point is
begin
return (Left.X - Right.X, Left.Y - Right.Y);
end "-";
type Edge is array (1 .. 2) of Point;
package Point_Lists is new Ada.Containers.Doubly_Linked_Lists
(Element_Type => Point);
use type Point_Lists.List;
subtype Polygon is Point_Lists.List;
function Inside (P : Point; E : Edge) return Boolean is
begin
return (E (2).X - E (1).X) * (P.Y - E (1).Y) >
(E (2).Y - E (1).Y) * (P.X - E (1).X);
end Inside;
function Intersecton (P1, P2 : Point; E : Edge) return Point is
DE : Point := E (1) - E (2);
DP : Point := P1 - P2;
N1 : Float := E (1).X * E (2).Y - E (1).Y * E (2).X;
N2 : Float := P1.X * P2.Y - P1.Y * P2.X;
N3 : Float := 1.0 / (DE.X * DP.Y - DE.Y * DP.X);
begin
return ((N1 * DP.X - N2 * DE.X) * N3, (N1 * DP.Y - N2 * DE.Y) * N3);
end Intersecton;
function Clip (P, C : Polygon) return Polygon is
use Point_Lists;
A, B, S, E : Cursor;
Inputlist : List;
Outputlist : List := P;
AB : Edge;
begin
A := C.First;
B := C.Last;
while A /= No_Element loop
AB := (Element (B), Element (A));
Inputlist := Outputlist;
Outputlist.Clear;
S := Inputlist.Last;
E := Inputlist.First;
while E /= No_Element loop
if Inside (Element (E), AB) then
if not Inside (Element (S), AB) then
Outputlist.Append
(Intersecton (Element (S), Element (E), AB));
end if;
Outputlist.Append (Element (E));
elsif Inside (Element (S), AB) then
Outputlist.Append
(Intersecton (Element (S), Element (E), AB));
end if;
S := E;
E := Next (E);
end loop;
B := A;
A := Next (A);
end loop;
return Outputlist;
end Clip;
procedure Print (P : Polygon) is
use Point_Lists;
C : Cursor := P.First;
begin
Ada.Text_IO.Put_Line ("{");
while C /= No_Element loop
Ada.Text_IO.Put (" (");
FIO.Put (Element (C).X, Exp => 0);
Ada.Text_IO.Put (',');
FIO.Put (Element (C).Y, Exp => 0);
Ada.Text_IO.Put (')');
C := Next (C);
if C /= No_Element then
Ada.Text_IO.Put (',');
end if;
Ada.Text_IO.New_Line;
end loop;
Ada.Text_IO.Put_Line ("}");
end Print;
Source : Polygon;
Clipper : Polygon;
Result : Polygon;
begin
Source.Append ((50.0, 150.0));
Source.Append ((200.0, 50.0));
Source.Append ((350.0, 150.0));
Source.Append ((350.0, 300.0));
Source.Append ((250.0, 300.0));
Source.Append ((200.0, 250.0));
Source.Append ((150.0, 350.0));
Source.Append ((100.0, 250.0));
Source.Append ((100.0, 200.0));
Clipper.Append ((100.0, 100.0));
Clipper.Append ((300.0, 100.0));
Clipper.Append ((300.0, 300.0));
Clipper.Append ((100.0, 300.0));
Result := Clip (Source, Clipper);
Print (Result);
end Main;
|
-- { dg-do compile }
procedure Discr_Test is
procedure P is begin null; end P;
task type Tsk1 is
entry rvT;
end Tsk1;
task body Tsk1 is
begin
accept rvT;
end Tsk1;
task type Tsk2 (pS : not null access procedure) is
entry rvT;
end Tsk2;
task body Tsk2 is
tskT : Tsk1;
begin
accept rvT do
requeue tskT.rvT;
end rvT;
pS.all;
end;
Obj : Tsk2 (P'access);
begin
Obj.rvT;
end;
|
package Array23_Pkg3 is
C0 : Natural := 2;
end Array23_Pkg3;
|
-----------------------------------------------------------------------
-- asf-views-facelets -- Facelets representation and management
-- Copyright (C) 2009, 2010, 2011, 2014, 2015, 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 Ada.Calendar;
with ASF.Views.Nodes;
with ASF.Contexts.Facelets;
with ASF.Factory;
with ASF.Components.Base;
with Ada.Finalization;
private with Ada.Strings.Unbounded;
private with Ada.Containers.Hashed_Sets;
private with Util.Refs;
private with Ada.Strings.Hash;
-- The <b>ASF.Views.Facelets</b> package contains the facelet factory
-- responsible for getting the facelet tree from a facelet name.
-- The facelets (or *.xhtml) files are loaded by the reader to form
-- a tag node tree which is cached by the factory. The facelet factory
-- is shared by multiple requests and threads.
package ASF.Views.Facelets is
type Facelet is private;
-- Returns True if the facelet is null/empty.
function Is_Null (F : Facelet) return Boolean;
-- ------------------------------
-- Facelet factory
-- ------------------------------
-- The facelet factory allows to retrieve the node tree to build the
-- component tree. The node tree can be shared by several component trees.
-- The node tree is initialized from the <b>XHTML</b> view file. It is put
-- in a cache to avoid loading and parsing the file several times.
type Facelet_Factory is limited private;
-- Get the facelet identified by the given name. If the facelet is already
-- loaded, the cached value is returned. The facelet file is searched in
-- a set of directories configured in the facelet factory.
procedure Find_Facelet (Factory : in out Facelet_Factory;
Name : in String;
Context : in ASF.Contexts.Facelets.Facelet_Context'Class;
Result : out Facelet;
Ignore : in Boolean := False);
-- Create the component tree from the facelet view.
procedure Build_View (View : in Facelet;
Context : in out ASF.Contexts.Facelets.Facelet_Context'Class;
Root : in ASF.Components.Base.UIComponent_Access);
-- Initialize the facelet factory.
-- Set the search directories for facelet files.
-- Set the ignore white space configuration when reading XHTML files.
-- Set the ignore empty lines configuration when reading XHTML files.
-- Set the escape unknown tags configuration when reading XHTML files.
procedure Initialize (Factory : in out Facelet_Factory;
Components : access ASF.Factory.Component_Factory;
Paths : in String;
Ignore_White_Spaces : in Boolean;
Ignore_Empty_Lines : in Boolean;
Escape_Unknown_Tags : in Boolean);
-- Find the facelet file in one of the facelet directories.
-- Returns the path to be used for reading the facelet file.
function Find_Facelet_Path (Factory : in Facelet_Factory;
Name : in String) return String;
-- Clear the facelet cache
procedure Clear_Cache (Factory : in out Facelet_Factory);
private
use Ada.Strings.Unbounded;
CHECK_FILE_DELAY : constant := 10.0;
type Facelet_Type (Len : Natural) is limited new Util.Refs.Ref_Entity with record
Root : ASF.Views.Nodes.Tag_Node_Access;
File : ASF.Views.File_Info_Access;
Modify_Time : Ada.Calendar.Time;
Check_Time : Ada.Calendar.Time;
Name : String (1 .. Len);
end record;
type Facelet_Access is access all Facelet_Type;
package Ref is
new Util.Refs.Indefinite_References (Facelet_Type, Facelet_Access);
type Facelet is record
Facelet : Facelet_Access;
end record;
Empty : constant Facelet := (others => <>);
function Hash (Item : in Facelet_Access) return Ada.Containers.Hash_Type is
(Ada.Strings.Hash (Item.Name));
function Compare (Left, Right : in Facelet_Access) return Boolean is
(Left.Name = Right.Name);
-- Tag library map indexed on the library namespace.
package Facelet_Sets is new
Ada.Containers.Hashed_Sets (Element_Type => Facelet_Access,
Hash => Hash,
Equivalent_Elements => Compare);
use Facelet_Sets;
protected type Facelet_Cache is
-- Find the facelet entry associated with the given name.
function Find (Name : in String) return Facelet_Access;
-- Insert or replace the facelet entry associated with the given name.
procedure Insert (Facelet : in Facelet_Access);
-- Clear the cache.
procedure Clear;
private
Map : Facelet_Sets.Set;
end Facelet_Cache;
type Facelet_Factory is new Ada.Finalization.Limited_Controlled with record
Paths : Unbounded_String := To_Unbounded_String ("");
-- The facelet cache.
Map : Facelet_Cache;
-- The component factory
Factory : access ASF.Factory.Component_Factory;
-- Whether the unknown tags are escaped using XML escape rules.
Escape_Unknown_Tags : Boolean := True;
-- Whether white spaces can be ignored.
Ignore_White_Spaces : Boolean := True;
-- Whether empty lines should be ignored (when white spaces are kept).
Ignore_Empty_Lines : Boolean := True;
end record;
-- Free the storage held by the factory cache.
overriding
procedure Finalize (Factory : in out Facelet_Factory);
end ASF.Views.Facelets;
|
-- { dg-do compile }
with Ada.Strings.Bounded;
package formal_type is
generic
with package BI is
new Ada.Strings.Bounded.Generic_Bounded_Length (<>);
type NB is new BI.Bounded_String;
package G is end;
package BI is new Ada.Strings.Bounded.Generic_Bounded_Length (30);
type NB is new BI.Bounded_String;
Thing : NB;
package GI is new G (BI, NB);
end;
|
------------------------------------------------------------------------------
-- --
-- GNAT SYSTEM UTILITIES --
-- --
-- C S I N F O --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2012, 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. --
-- --
------------------------------------------------------------------------------
-- Check consistency of sinfo.ads and sinfo.adb. Checks that field name usage
-- is consistent and that assertion cross-reference lists are correct, as well
-- as making sure that all the comments on field name usage are consistent.
-- Note that this is used both as a standalone program, and as a procedure
-- called by XSinfo. This raises an unhandled exception if it finds any
-- errors; we don't attempt any sophisticated error recovery.
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Spitbol; use GNAT.Spitbol;
with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
with GNAT.Spitbol.Table_Boolean;
with GNAT.Spitbol.Table_VString;
procedure CSinfo is
package TB renames GNAT.Spitbol.Table_Boolean;
package TV renames GNAT.Spitbol.Table_VString;
use TB, TV;
Infil : File_Type;
Lineno : Natural := 0;
Err : exception;
-- Raised on fatal error
Done : exception;
-- Raised after error is found to terminate run
WSP : constant Pattern := Span (' ' & ASCII.HT);
Fields : TV.Table (300);
Fields1 : TV.Table (300);
Refs : TV.Table (300);
Refscopy : TV.Table (300);
Special : TB.Table (50);
Inlines : TV.Table (100);
-- The following define the standard fields used for binary operator,
-- unary operator, and other expression nodes. Numbers in the range 1-5
-- refer to the Fieldn fields. Letters D-R refer to flags:
-- D = Flag4
-- E = Flag5
-- F = Flag6
-- G = Flag7
-- H = Flag8
-- I = Flag9
-- J = Flag10
-- K = Flag11
-- L = Flag12
-- M = Flag13
-- N = Flag14
-- O = Flag15
-- P = Flag16
-- Q = Flag17
-- R = Flag18
Flags : TV.Table (20);
-- Maps flag numbers to letters
N_Fields : constant Pattern := BreakX ("JL");
E_Fields : constant Pattern := BreakX ("5EFGHIJLOP");
U_Fields : constant Pattern := BreakX ("1345EFGHIJKLOPQ");
B_Fields : constant Pattern := BreakX ("12345EFGHIJKLOPQ");
Line : VString;
Bad : Boolean;
Field : constant VString := Nul;
Fields_Used : VString := Nul;
Name : constant VString := Nul;
Next : constant VString := Nul;
Node : VString := Nul;
Ref : VString := Nul;
Synonym : constant VString := Nul;
Nxtref : constant VString := Nul;
Which_Field : aliased VString := Nul;
Node_Search : constant Pattern := WSP & "-- N_" & Rest * Node;
Break_Punc : constant Pattern := Break (" .,");
Plus_Binary : constant Pattern := WSP
& "-- plus fields for binary operator";
Plus_Unary : constant Pattern := WSP
& "-- plus fields for unary operator";
Plus_Expr : constant Pattern := WSP
& "-- plus fields for expression";
Break_Syn : constant Pattern := WSP & "-- "
& Break (' ') * Synonym
& " (" & Break (')') * Field;
Break_Field : constant Pattern := BreakX ('-') * Field;
Get_Field : constant Pattern := BreakX (Decimal_Digit_Set)
& Span (Decimal_Digit_Set) * Which_Field;
Break_WFld : constant Pattern := Break (Which_Field'Access);
Get_Funcsyn : constant Pattern := WSP & "function " & Rest * Synonym;
Extr_Field : constant Pattern := BreakX ('-') & "-- " & Rest * Field;
Get_Procsyn : constant Pattern := WSP & "procedure Set_" & Rest * Synonym;
Get_Inline : constant Pattern := WSP & "pragma Inline ("
& Break (')') * Name;
Set_Name : constant Pattern := "Set_" & Rest * Name;
Func_Rest : constant Pattern := " function " & Rest * Synonym;
Get_Nxtref : constant Pattern := Break (',') * Nxtref & ',';
Test_Syn : constant Pattern := Break ('=') & "= N_"
& (Break (" ,)") or Rest) * Next;
Chop_Comma : constant Pattern := BreakX (',') * Next;
Return_Fld : constant Pattern := WSP & "return " & Break (' ') * Field;
Set_Syn : constant Pattern := " procedure Set_" & Rest * Synonym;
Set_Fld : constant Pattern := WSP & "Set_" & Break (' ') * Field
& " (N, Val)";
Break_With : constant Pattern := Break ('_') ** Field & "_With_Parent";
type VStringA is array (Natural range <>) of VString;
procedure Next_Line;
-- Read next line trimmed from Infil into Line and bump Lineno
procedure Sort (A : in out VStringA);
-- Sort a (small) array of VString's
procedure Next_Line is
begin
Line := Get_Line (Infil);
Trim (Line);
Lineno := Lineno + 1;
end Next_Line;
procedure Sort (A : in out VStringA) is
Temp : VString;
begin
<<Sort>>
for J in 1 .. A'Length - 1 loop
if A (J) > A (J + 1) then
Temp := A (J);
A (J) := A (J + 1);
A (J + 1) := Temp;
goto Sort;
end if;
end loop;
end Sort;
-- Start of processing for CSinfo
begin
Anchored_Mode := True;
New_Line;
Open (Infil, In_File, "sinfo.ads");
Put_Line ("Check for field name consistency");
-- Setup table for mapping flag numbers to letters
Set (Flags, "4", V ("D"));
Set (Flags, "5", V ("E"));
Set (Flags, "6", V ("F"));
Set (Flags, "7", V ("G"));
Set (Flags, "8", V ("H"));
Set (Flags, "9", V ("I"));
Set (Flags, "10", V ("J"));
Set (Flags, "11", V ("K"));
Set (Flags, "12", V ("L"));
Set (Flags, "13", V ("M"));
Set (Flags, "14", V ("N"));
Set (Flags, "15", V ("O"));
Set (Flags, "16", V ("P"));
Set (Flags, "17", V ("Q"));
Set (Flags, "18", V ("R"));
-- Special fields table. The following names are not recorded or checked
-- by Csinfo, since they are specially handled. This means that any field
-- definition or subprogram with a matching name is ignored.
Set (Special, "Analyzed", True);
Set (Special, "Assignment_OK", True);
Set (Special, "Associated_Node", True);
Set (Special, "Cannot_Be_Constant", True);
Set (Special, "Chars", True);
Set (Special, "Comes_From_Source", True);
Set (Special, "Do_Overflow_Check", True);
Set (Special, "Do_Range_Check", True);
Set (Special, "Entity", True);
Set (Special, "Entity_Or_Associated_Node", True);
Set (Special, "Error_Posted", True);
Set (Special, "Etype", True);
Set (Special, "Evaluate_Once", True);
Set (Special, "First_Itype", True);
Set (Special, "Has_Aspect_Specifications", True);
Set (Special, "Has_Dynamic_Itype", True);
Set (Special, "Has_Dynamic_Range_Check", True);
Set (Special, "Has_Dynamic_Length_Check", True);
Set (Special, "Has_Private_View", True);
Set (Special, "Implicit_With_From_Instantiation", True);
Set (Special, "Is_Controlling_Actual", True);
Set (Special, "Is_Overloaded", True);
Set (Special, "Is_Static_Expression", True);
Set (Special, "Left_Opnd", True);
Set (Special, "Must_Not_Freeze", True);
Set (Special, "Nkind_In", True);
Set (Special, "Parens", True);
Set (Special, "Pragma_Name", True);
Set (Special, "Raises_Constraint_Error", True);
Set (Special, "Right_Opnd", True);
-- Loop to acquire information from node definitions in sinfo.ads,
-- checking for consistency in Op/Flag assignments to each synonym
loop
Bad := False;
Next_Line;
exit when Match (Line, " -- Node Access Functions");
if Match (Line, Node_Search)
and then not Match (Node, Break_Punc)
then
Fields_Used := Nul;
elsif Node = "" then
null;
elsif Line = "" then
Node := Nul;
elsif Match (Line, Plus_Binary) then
Bad := Match (Fields_Used, B_Fields);
elsif Match (Line, Plus_Unary) then
Bad := Match (Fields_Used, U_Fields);
elsif Match (Line, Plus_Expr) then
Bad := Match (Fields_Used, E_Fields);
elsif not Match (Line, Break_Syn) then
null;
elsif Match (Synonym, "plus") then
null;
else
Match (Field, Break_Field);
if not Present (Special, Synonym) then
if Present (Fields, Synonym) then
if Field /= Get (Fields, Synonym) then
Put_Line
("Inconsistent field reference at line" &
Lineno'Img & " for " & Synonym);
raise Done;
end if;
else
Set (Fields, Synonym, Field);
end if;
Set (Refs, Synonym, Node & ',' & Get (Refs, Synonym));
Match (Field, Get_Field);
if Match (Field, "Flag") then
Which_Field := Get (Flags, Which_Field);
end if;
if Match (Fields_Used, Break_WFld) then
Put_Line
("Overlapping field at line " & Lineno'Img &
" for " & Synonym);
raise Done;
end if;
Append (Fields_Used, Which_Field);
Bad := Bad or Match (Fields_Used, N_Fields);
end if;
end if;
if Bad then
Put_Line ("fields conflict with standard fields for node " & Node);
raise Done;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check for function consistency");
-- Loop through field function definitions to make sure they are OK
Fields1 := Fields;
loop
Next_Line;
exit when Match (Line, " -- Node Update");
if Match (Line, Get_Funcsyn)
and then not Present (Special, Synonym)
then
if not Present (Fields1, Synonym) then
Put_Line
("function on line " & Lineno &
" is for unused synonym");
raise Done;
end if;
Next_Line;
if not Match (Line, Extr_Field) then
raise Err;
end if;
if Field /= Get (Fields1, Synonym) then
Put_Line ("Wrong field in function " & Synonym);
raise Done;
else
Delete (Fields1, Synonym);
end if;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check for missing functions");
declare
List : constant TV.Table_Array := Convert_To_Array (Fields1);
begin
if List'Length > 0 then
Put_Line ("No function for field synonym " & List (1).Name);
raise Done;
end if;
end;
-- Check field set procedures
Put_Line (" OK");
New_Line;
Put_Line ("Check for set procedure consistency");
Fields1 := Fields;
loop
Next_Line;
exit when Match (Line, " -- Inline Pragmas");
exit when Match (Line, " -- Iterator Procedures");
if Match (Line, Get_Procsyn)
and then not Present (Special, Synonym)
then
if not Present (Fields1, Synonym) then
Put_Line
("procedure on line " & Lineno & " is for unused synonym");
raise Done;
end if;
Next_Line;
if not Match (Line, Extr_Field) then
raise Err;
end if;
if Field /= Get (Fields1, Synonym) then
Put_Line ("Wrong field in procedure Set_" & Synonym);
raise Done;
else
Delete (Fields1, Synonym);
end if;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check for missing set procedures");
declare
List : constant TV.Table_Array := Convert_To_Array (Fields1);
begin
if List'Length > 0 then
Put_Line ("No procedure for field synonym Set_" & List (1).Name);
raise Done;
end if;
end;
Put_Line (" OK");
New_Line;
Put_Line ("Check pragma Inlines are all for existing subprograms");
Clear (Fields1);
while not End_Of_File (Infil) loop
Next_Line;
if Match (Line, Get_Inline)
and then not Present (Special, Name)
then
exit when Match (Name, Set_Name);
if not Present (Fields, Name) then
Put_Line
("Pragma Inline on line " & Lineno &
" does not correspond to synonym");
raise Done;
else
Set (Inlines, Name, Get (Inlines, Name) & 'r');
end if;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check no pragma Inlines were omitted");
declare
List : constant TV.Table_Array := Convert_To_Array (Fields);
Nxt : VString := Nul;
begin
for M in List'Range loop
Nxt := List (M).Name;
if Get (Inlines, Nxt) /= "r" then
Put_Line ("Incorrect pragma Inlines for " & Nxt);
raise Done;
end if;
end loop;
end;
Put_Line (" OK");
New_Line;
Clear (Inlines);
Close (Infil);
Open (Infil, In_File, "sinfo.adb");
Lineno := 0;
Put_Line ("Check references in functions in body");
Refscopy := Refs;
loop
Next_Line;
exit when Match (Line, " -- Field Access Functions --");
end loop;
loop
Next_Line;
exit when Match (Line, " -- Field Set Procedures --");
if Match (Line, Func_Rest)
and then not Present (Special, Synonym)
then
Ref := Get (Refs, Synonym);
Delete (Refs, Synonym);
if Ref = "" then
Put_Line
("Function on line " & Lineno & " is for unknown synonym");
raise Err;
end if;
-- Alpha sort of references for this entry
declare
Refa : VStringA (1 .. 100);
N : Natural := 0;
begin
loop
exit when not Match (Ref, Get_Nxtref, Nul);
N := N + 1;
Refa (N) := Nxtref;
end loop;
Sort (Refa (1 .. N));
Next_Line;
Next_Line;
Next_Line;
-- Checking references for one entry
for M in 1 .. N loop
Next_Line;
if not Match (Line, Test_Syn) then
Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
raise Done;
end if;
Match (Next, Chop_Comma);
if Next /= Refa (M) then
Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
raise Done;
end if;
end loop;
Next_Line;
Match (Line, Return_Fld);
if Field /= Get (Fields, Synonym) then
Put_Line
("Wrong field for function " & Synonym & " at line " &
Lineno & " should be " & Get (Fields, Synonym));
raise Done;
end if;
end;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check for missing functions in body");
declare
List : constant TV.Table_Array := Convert_To_Array (Refs);
begin
if List'Length /= 0 then
Put_Line ("Missing function " & List (1).Name & " in body");
raise Done;
end if;
end;
Put_Line (" OK");
New_Line;
Put_Line ("Check Set procedures in body");
Refs := Refscopy;
loop
Next_Line;
exit when Match (Line, "end");
exit when Match (Line, " -- Iterator Procedures");
if Match (Line, Set_Syn)
and then not Present (Special, Synonym)
then
Ref := Get (Refs, Synonym);
Delete (Refs, Synonym);
if Ref = "" then
Put_Line
("Function on line " & Lineno & " is for unknown synonym");
raise Err;
end if;
-- Alpha sort of references for this entry
declare
Refa : VStringA (1 .. 100);
N : Natural;
begin
N := 0;
loop
exit when not Match (Ref, Get_Nxtref, Nul);
N := N + 1;
Refa (N) := Nxtref;
end loop;
Sort (Refa (1 .. N));
Next_Line;
Next_Line;
Next_Line;
-- Checking references for one entry
for M in 1 .. N loop
Next_Line;
if not Match (Line, Test_Syn)
or else Next /= Refa (M)
then
Put_Line ("Expecting N_" & Refa (M) & " at line " & Lineno);
raise Err;
end if;
end loop;
loop
Next_Line;
exit when Match (Line, Set_Fld);
end loop;
Match (Field, Break_With);
if Field /= Get (Fields, Synonym) then
Put_Line
("Wrong field for procedure Set_" & Synonym &
" at line " & Lineno & " should be " &
Get (Fields, Synonym));
raise Done;
end if;
Delete (Fields1, Synonym);
end;
end if;
end loop;
Put_Line (" OK");
New_Line;
Put_Line ("Check for missing set procedures in body");
declare
List : constant TV.Table_Array := Convert_To_Array (Fields1);
begin
if List'Length /= 0 then
Put_Line ("Missing procedure Set_" & List (1).Name & " in body");
raise Done;
end if;
end;
Put_Line (" OK");
New_Line;
Put_Line ("All tests completed successfully, no errors detected");
end CSinfo;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ A T T R --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Errout; use Errout;
with Eval_Fat;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Freeze; use Freeze;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sdefault; use Sdefault;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Dist; use Sem_Dist;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Stringt; use Stringt;
with Targparm; use Targparm;
with Ttypes; use Ttypes;
with Ttypef; use Ttypef;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body Sem_Attr is
True_Value : constant Uint := Uint_1;
False_Value : constant Uint := Uint_0;
-- Synonyms to be used when these constants are used as Boolean values
Bad_Attribute : exception;
-- Exception raised if an error is detected during attribute processing,
-- used so that we can abandon the processing so we don't run into
-- trouble with cascaded errors.
-- The following array is the list of attributes defined in the Ada 83 RM
Attribute_83 : constant Attribute_Class_Array := Attribute_Class_Array'(
Attribute_Address |
Attribute_Aft |
Attribute_Alignment |
Attribute_Base |
Attribute_Callable |
Attribute_Constrained |
Attribute_Count |
Attribute_Delta |
Attribute_Digits |
Attribute_Emax |
Attribute_Epsilon |
Attribute_First |
Attribute_First_Bit |
Attribute_Fore |
Attribute_Image |
Attribute_Large |
Attribute_Last |
Attribute_Last_Bit |
Attribute_Leading_Part |
Attribute_Length |
Attribute_Machine_Emax |
Attribute_Machine_Emin |
Attribute_Machine_Mantissa |
Attribute_Machine_Overflows |
Attribute_Machine_Radix |
Attribute_Machine_Rounds |
Attribute_Mantissa |
Attribute_Pos |
Attribute_Position |
Attribute_Pred |
Attribute_Range |
Attribute_Safe_Emax |
Attribute_Safe_Large |
Attribute_Safe_Small |
Attribute_Size |
Attribute_Small |
Attribute_Storage_Size |
Attribute_Succ |
Attribute_Terminated |
Attribute_Val |
Attribute_Value |
Attribute_Width => True,
others => False);
-----------------------
-- Local_Subprograms --
-----------------------
procedure Eval_Attribute (N : Node_Id);
-- Performs compile time evaluation of attributes where possible, leaving
-- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
-- set, and replacing the node with a literal node if the value can be
-- computed at compile time. All static attribute references are folded,
-- as well as a number of cases of non-static attributes that can always
-- be computed at compile time (e.g. floating-point model attributes that
-- are applied to non-static subtypes). Of course in such cases, the
-- Is_Static_Expression flag will not be set on the resulting literal.
-- Note that the only required action of this procedure is to catch the
-- static expression cases as described in the RM. Folding of other cases
-- is done where convenient, but some additional non-static folding is in
-- N_Expand_Attribute_Reference in cases where this is more convenient.
function Is_Anonymous_Tagged_Base
(Anon : Entity_Id;
Typ : Entity_Id)
return Boolean;
-- For derived tagged types that constrain parent discriminants we build
-- an anonymous unconstrained base type. We need to recognize the relation
-- between the two when analyzing an access attribute for a constrained
-- component, before the full declaration for Typ has been analyzed, and
-- where therefore the prefix of the attribute does not match the enclosing
-- scope.
-----------------------
-- Analyze_Attribute --
-----------------------
procedure Analyze_Attribute (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Aname : constant Name_Id := Attribute_Name (N);
P : constant Node_Id := Prefix (N);
Exprs : constant List_Id := Expressions (N);
Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
E1 : Node_Id;
E2 : Node_Id;
P_Type : Entity_Id;
-- Type of prefix after analysis
P_Base_Type : Entity_Id;
-- Base type of prefix after analysis
-----------------------
-- Local Subprograms --
-----------------------
procedure Analyze_Access_Attribute;
-- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
-- Internally, Id distinguishes which of the three cases is involved.
procedure Check_Array_Or_Scalar_Type;
-- Common procedure used by First, Last, Range attribute to check
-- that the prefix is a constrained array or scalar type, or a name
-- of an array object, and that an argument appears only if appropriate
-- (i.e. only in the array case).
procedure Check_Array_Type;
-- Common semantic checks for all array attributes. Checks that the
-- prefix is a constrained array type or the name of an array object.
-- The error message for non-arrays is specialized appropriately.
procedure Check_Asm_Attribute;
-- Common semantic checks for Asm_Input and Asm_Output attributes
procedure Check_Component;
-- Common processing for Bit_Position, First_Bit, Last_Bit, and
-- Position. Checks prefix is an appropriate selected component.
procedure Check_Decimal_Fixed_Point_Type;
-- Check that prefix of attribute N is a decimal fixed-point type
procedure Check_Dereference;
-- If the prefix of attribute is an object of an access type, then
-- introduce an explicit deference, and adjust P_Type accordingly.
procedure Check_Discrete_Type;
-- Verify that prefix of attribute N is a discrete type
procedure Check_E0;
-- Check that no attribute arguments are present
procedure Check_Either_E0_Or_E1;
-- Check that there are zero or one attribute arguments present
procedure Check_E1;
-- Check that exactly one attribute argument is present
procedure Check_E2;
-- Check that two attribute arguments are present
procedure Check_Enum_Image;
-- If the prefix type is an enumeration type, set all its literals
-- as referenced, since the image function could possibly end up
-- referencing any of the literals indirectly.
procedure Check_Fixed_Point_Type;
-- Verify that prefix of attribute N is a fixed type
procedure Check_Fixed_Point_Type_0;
-- Verify that prefix of attribute N is a fixed type and that
-- no attribute expressions are present
procedure Check_Floating_Point_Type;
-- Verify that prefix of attribute N is a float type
procedure Check_Floating_Point_Type_0;
-- Verify that prefix of attribute N is a float type and that
-- no attribute expressions are present
procedure Check_Floating_Point_Type_1;
-- Verify that prefix of attribute N is a float type and that
-- exactly one attribute expression is present
procedure Check_Floating_Point_Type_2;
-- Verify that prefix of attribute N is a float type and that
-- two attribute expressions are present
procedure Legal_Formal_Attribute;
-- Common processing for attributes Definite, Has_Access_Values,
-- and Has_Discriminants
procedure Check_Integer_Type;
-- Verify that prefix of attribute N is an integer type
procedure Check_Library_Unit;
-- Verify that prefix of attribute N is a library unit
procedure Check_Modular_Integer_Type;
-- Verify that prefix of attribute N is a modular integer type
procedure Check_Not_Incomplete_Type;
-- Check that P (the prefix of the attribute) is not an incomplete
-- type or a private type for which no full view has been given.
procedure Check_Object_Reference (P : Node_Id);
-- Check that P (the prefix of the attribute) is an object reference
procedure Check_Program_Unit;
-- Verify that prefix of attribute N is a program unit
procedure Check_Real_Type;
-- Verify that prefix of attribute N is fixed or float type
procedure Check_Scalar_Type;
-- Verify that prefix of attribute N is a scalar type
procedure Check_Standard_Prefix;
-- Verify that prefix of attribute N is package Standard
procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
-- Validity checking for stream attribute. Nam is the TSS name of the
-- corresponding possible defined attribute function (e.g. for the
-- Read attribute, Nam will be TSS_Stream_Read).
procedure Check_Task_Prefix;
-- Verify that prefix of attribute N is a task or task type
procedure Check_Type;
-- Verify that the prefix of attribute N is a type
procedure Check_Unit_Name (Nod : Node_Id);
-- Check that Nod is of the form of a library unit name, i.e that
-- it is an identifier, or a selected component whose prefix is
-- itself of the form of a library unit name. Note that this is
-- quite different from Check_Program_Unit, since it only checks
-- the syntactic form of the name, not the semantic identity. This
-- is because it is used with attributes (Elab_Body, Elab_Spec, and
-- UET_Address) which can refer to non-visible unit.
procedure Error_Attr (Msg : String; Error_Node : Node_Id);
pragma No_Return (Error_Attr);
procedure Error_Attr;
pragma No_Return (Error_Attr);
-- Posts error using Error_Msg_N at given node, sets type of attribute
-- node to Any_Type, and then raises Bad_Attribute to avoid any further
-- semantic processing. The message typically contains a % insertion
-- character which is replaced by the attribute name. The call with
-- no arguments is used when the caller has already generated the
-- required error messages.
procedure Standard_Attribute (Val : Int);
-- Used to process attributes whose prefix is package Standard which
-- yield values of type Universal_Integer. The attribute reference
-- node is rewritten with an integer literal of the given value.
procedure Unexpected_Argument (En : Node_Id);
-- Signal unexpected attribute argument (En is the argument)
procedure Validate_Non_Static_Attribute_Function_Call;
-- Called when processing an attribute that is a function call to a
-- non-static function, i.e. an attribute function that either takes
-- non-scalar arguments or returns a non-scalar result. Verifies that
-- such a call does not appear in a preelaborable context.
------------------------------
-- Analyze_Access_Attribute --
------------------------------
procedure Analyze_Access_Attribute is
Acc_Type : Entity_Id;
Scop : Entity_Id;
Typ : Entity_Id;
function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
-- Build an access-to-object type whose designated type is DT,
-- and whose Ekind is appropriate to the attribute type. The
-- type that is constructed is returned as the result.
procedure Build_Access_Subprogram_Type (P : Node_Id);
-- Build an access to subprogram whose designated type is
-- the type of the prefix. If prefix is overloaded, so it the
-- node itself. The result is stored in Acc_Type.
------------------------------
-- Build_Access_Object_Type --
------------------------------
function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
Typ : Entity_Id;
begin
if Aname = Name_Unrestricted_Access then
Typ :=
New_Internal_Entity
(E_Allocator_Type, Current_Scope, Loc, 'A');
else
Typ :=
New_Internal_Entity
(E_Access_Attribute_Type, Current_Scope, Loc, 'A');
end if;
Set_Etype (Typ, Typ);
Init_Size_Align (Typ);
Set_Is_Itype (Typ);
Set_Associated_Node_For_Itype (Typ, N);
Set_Directly_Designated_Type (Typ, DT);
return Typ;
end Build_Access_Object_Type;
----------------------------------
-- Build_Access_Subprogram_Type --
----------------------------------
procedure Build_Access_Subprogram_Type (P : Node_Id) is
Index : Interp_Index;
It : Interp;
function Get_Kind (E : Entity_Id) return Entity_Kind;
-- Distinguish between access to regular/protected subprograms
--------------
-- Get_Kind --
--------------
function Get_Kind (E : Entity_Id) return Entity_Kind is
begin
if Convention (E) = Convention_Protected then
return E_Access_Protected_Subprogram_Type;
else
return E_Access_Subprogram_Type;
end if;
end Get_Kind;
-- Start of processing for Build_Access_Subprogram_Type
begin
-- In the case of an access to subprogram, use the name of the
-- subprogram itself as the designated type. Type-checking in
-- this case compares the signatures of the designated types.
Set_Etype (N, Any_Type);
if not Is_Overloaded (P) then
if not Is_Intrinsic_Subprogram (Entity (P)) then
Acc_Type :=
New_Internal_Entity
(Get_Kind (Entity (P)), Current_Scope, Loc, 'A');
Set_Etype (Acc_Type, Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Entity (P));
Set_Etype (N, Acc_Type);
end if;
else
Get_First_Interp (P, Index, It);
while Present (It.Nam) loop
if not Is_Intrinsic_Subprogram (It.Nam) then
Acc_Type :=
New_Internal_Entity
(Get_Kind (It.Nam), Current_Scope, Loc, 'A');
Set_Etype (Acc_Type, Acc_Type);
Set_Directly_Designated_Type (Acc_Type, It.Nam);
Add_One_Interp (N, Acc_Type, Acc_Type);
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
if Etype (N) = Any_Type then
Error_Attr ("prefix of % attribute cannot be intrinsic", P);
end if;
end Build_Access_Subprogram_Type;
-- Start of processing for Analyze_Access_Attribute
begin
Check_E0;
if Nkind (P) = N_Character_Literal then
Error_Attr
("prefix of % attribute cannot be enumeration literal", P);
end if;
-- Case of access to subprogram
if Is_Entity_Name (P)
and then Is_Overloadable (Entity (P))
then
-- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
-- restriction set (since in general a trampoline is required).
if not Is_Library_Level_Entity (Entity (P)) then
Check_Restriction (No_Implicit_Dynamic_Code, P);
end if;
if Is_Always_Inlined (Entity (P)) then
Error_Attr
("prefix of % attribute cannot be Inline_Always subprogram",
P);
end if;
-- Build the appropriate subprogram type
Build_Access_Subprogram_Type (P);
-- For unrestricted access, kill current values, since this
-- attribute allows a reference to a local subprogram that
-- could modify local variables to be passed out of scope
if Aname = Name_Unrestricted_Access then
Kill_Current_Values;
end if;
return;
-- Component is an operation of a protected type
elsif Nkind (P) = N_Selected_Component
and then Is_Overloadable (Entity (Selector_Name (P)))
then
if Ekind (Entity (Selector_Name (P))) = E_Entry then
Error_Attr ("prefix of % attribute must be subprogram", P);
end if;
Build_Access_Subprogram_Type (Selector_Name (P));
return;
end if;
-- Deal with incorrect reference to a type, but note that some
-- accesses are allowed (references to the current type instance).
if Is_Entity_Name (P) then
Typ := Entity (P);
-- The reference may appear in an aggregate that has been expanded
-- into a loop. Locate scope of type definition, if any.
Scop := Current_Scope;
while Ekind (Scop) = E_Loop loop
Scop := Scope (Scop);
end loop;
if Is_Type (Typ) then
-- OK if we are within the scope of a limited type
-- let's mark the component as having per object constraint
if Is_Anonymous_Tagged_Base (Scop, Typ) then
Typ := Scop;
Set_Entity (P, Typ);
Set_Etype (P, Typ);
end if;
if Typ = Scop then
declare
Q : Node_Id := Parent (N);
begin
while Present (Q)
and then Nkind (Q) /= N_Component_Declaration
loop
Q := Parent (Q);
end loop;
if Present (Q) then
Set_Has_Per_Object_Constraint (
Defining_Identifier (Q), True);
end if;
end;
if Nkind (P) = N_Expanded_Name then
Error_Msg_N
("current instance prefix must be a direct name", P);
end if;
-- If a current instance attribute appears within a
-- a component constraint it must appear alone; other
-- contexts (default expressions, within a task body)
-- are not subject to this restriction.
if not In_Default_Expression
and then not Has_Completion (Scop)
and then
Nkind (Parent (N)) /= N_Discriminant_Association
and then
Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
then
Error_Msg_N
("current instance attribute must appear alone", N);
end if;
-- OK if we are in initialization procedure for the type
-- in question, in which case the reference to the type
-- is rewritten as a reference to the current object.
elsif Ekind (Scop) = E_Procedure
and then Is_Init_Proc (Scop)
and then Etype (First_Formal (Scop)) = Typ
then
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Attribute_Name => Name_Unrestricted_Access));
Analyze (N);
return;
-- OK if a task type, this test needs sharpening up ???
elsif Is_Task_Type (Typ) then
null;
-- Otherwise we have an error case
else
Error_Attr ("% attribute cannot be applied to type", P);
return;
end if;
end if;
end if;
-- If we fall through, we have a normal access to object case.
-- Unrestricted_Access is legal wherever an allocator would be
-- legal, so its Etype is set to E_Allocator. The expected type
-- of the other attributes is a general access type, and therefore
-- we label them with E_Access_Attribute_Type.
if not Is_Overloaded (P) then
Acc_Type := Build_Access_Object_Type (P_Type);
Set_Etype (N, Acc_Type);
else
declare
Index : Interp_Index;
It : Interp;
begin
Set_Etype (N, Any_Type);
Get_First_Interp (P, Index, It);
while Present (It.Typ) loop
Acc_Type := Build_Access_Object_Type (It.Typ);
Add_One_Interp (N, Acc_Type, Acc_Type);
Get_Next_Interp (Index, It);
end loop;
end;
end if;
-- If we have an access to an object, and the attribute comes
-- from source, then set the object as potentially source modified.
-- We do this because the resulting access pointer can be used to
-- modify the variable, and we might not detect this, leading to
-- some junk warnings.
if Is_Entity_Name (P) then
Set_Never_Set_In_Source (Entity (P), False);
end if;
-- Check for aliased view unless unrestricted case. We allow
-- a nonaliased prefix when within an instance because the
-- prefix may have been a tagged formal object, which is
-- defined to be aliased even when the actual might not be
-- (other instance cases will have been caught in the generic).
-- Similarly, within an inlined body we know that the attribute
-- is legal in the original subprogram, and therefore legal in
-- the expansion.
if Aname /= Name_Unrestricted_Access
and then not Is_Aliased_View (P)
and then not In_Instance
and then not In_Inlined_Body
then
Error_Attr ("prefix of % attribute must be aliased", P);
end if;
end Analyze_Access_Attribute;
--------------------------------
-- Check_Array_Or_Scalar_Type --
--------------------------------
procedure Check_Array_Or_Scalar_Type is
Index : Entity_Id;
D : Int;
-- Dimension number for array attributes
begin
-- Case of string literal or string literal subtype. These cases
-- cannot arise from legal Ada code, but the expander is allowed
-- to generate them. They require special handling because string
-- literal subtypes do not have standard bounds (the whole idea
-- of these subtypes is to avoid having to generate the bounds)
if Ekind (P_Type) = E_String_Literal_Subtype then
Set_Etype (N, Etype (First_Index (P_Base_Type)));
return;
-- Scalar types
elsif Is_Scalar_Type (P_Type) then
Check_Type;
if Present (E1) then
Error_Attr ("invalid argument in % attribute", E1);
else
Set_Etype (N, P_Base_Type);
return;
end if;
-- The following is a special test to allow 'First to apply to
-- private scalar types if the attribute comes from generated
-- code. This occurs in the case of Normalize_Scalars code.
elsif Is_Private_Type (P_Type)
and then Present (Full_View (P_Type))
and then Is_Scalar_Type (Full_View (P_Type))
and then not Comes_From_Source (N)
then
Set_Etype (N, Implementation_Base_Type (P_Type));
-- Array types other than string literal subtypes handled above
else
Check_Array_Type;
-- We know prefix is an array type, or the name of an array
-- object, and that the expression, if present, is static
-- and within the range of the dimensions of the type.
pragma Assert (Is_Array_Type (P_Type));
Index := First_Index (P_Base_Type);
if No (E1) then
-- First dimension assumed
Set_Etype (N, Base_Type (Etype (Index)));
else
D := UI_To_Int (Intval (E1));
for J in 1 .. D - 1 loop
Next_Index (Index);
end loop;
Set_Etype (N, Base_Type (Etype (Index)));
Set_Etype (E1, Standard_Integer);
end if;
end if;
end Check_Array_Or_Scalar_Type;
----------------------
-- Check_Array_Type --
----------------------
procedure Check_Array_Type is
D : Int;
-- Dimension number for array attributes
begin
-- If the type is a string literal type, then this must be generated
-- internally, and no further check is required on its legality.
if Ekind (P_Type) = E_String_Literal_Subtype then
return;
-- If the type is a composite, it is an illegal aggregate, no point
-- in going on.
elsif P_Type = Any_Composite then
raise Bad_Attribute;
end if;
-- Normal case of array type or subtype
Check_Either_E0_Or_E1;
Check_Dereference;
if Is_Array_Type (P_Type) then
if not Is_Constrained (P_Type)
and then Is_Entity_Name (P)
and then Is_Type (Entity (P))
then
-- Note: we do not call Error_Attr here, since we prefer to
-- continue, using the relevant index type of the array,
-- even though it is unconstrained. This gives better error
-- recovery behavior.
Error_Msg_Name_1 := Aname;
Error_Msg_N
("prefix for % attribute must be constrained array", P);
end if;
D := Number_Dimensions (P_Type);
else
if Is_Private_Type (P_Type) then
Error_Attr
("prefix for % attribute may not be private type", P);
elsif Is_Access_Type (P_Type)
and then Is_Array_Type (Designated_Type (P_Type))
and then Is_Entity_Name (P)
and then Is_Type (Entity (P))
then
Error_Attr ("prefix of % attribute cannot be access type", P);
elsif Attr_Id = Attribute_First
or else
Attr_Id = Attribute_Last
then
Error_Attr ("invalid prefix for % attribute", P);
else
Error_Attr ("prefix for % attribute must be array", P);
end if;
end if;
if Present (E1) then
Resolve (E1, Any_Integer);
Set_Etype (E1, Standard_Integer);
if not Is_Static_Expression (E1)
or else Raises_Constraint_Error (E1)
then
Flag_Non_Static_Expr
("expression for dimension must be static!", E1);
Error_Attr;
elsif UI_To_Int (Expr_Value (E1)) > D
or else UI_To_Int (Expr_Value (E1)) < 1
then
Error_Attr ("invalid dimension number for array type", E1);
end if;
end if;
end Check_Array_Type;
-------------------------
-- Check_Asm_Attribute --
-------------------------
procedure Check_Asm_Attribute is
begin
Check_Type;
Check_E2;
-- Check first argument is static string expression
Analyze_And_Resolve (E1, Standard_String);
if Etype (E1) = Any_Type then
return;
elsif not Is_OK_Static_Expression (E1) then
Flag_Non_Static_Expr
("constraint argument must be static string expression!", E1);
Error_Attr;
end if;
-- Check second argument is right type
Analyze_And_Resolve (E2, Entity (P));
-- Note: that is all we need to do, we don't need to check
-- that it appears in a correct context. The Ada type system
-- will do that for us.
end Check_Asm_Attribute;
---------------------
-- Check_Component --
---------------------
procedure Check_Component is
begin
Check_E0;
if Nkind (P) /= N_Selected_Component
or else
(Ekind (Entity (Selector_Name (P))) /= E_Component
and then
Ekind (Entity (Selector_Name (P))) /= E_Discriminant)
then
Error_Attr
("prefix for % attribute must be selected component", P);
end if;
end Check_Component;
------------------------------------
-- Check_Decimal_Fixed_Point_Type --
------------------------------------
procedure Check_Decimal_Fixed_Point_Type is
begin
Check_Type;
if not Is_Decimal_Fixed_Point_Type (P_Type) then
Error_Attr
("prefix of % attribute must be decimal type", P);
end if;
end Check_Decimal_Fixed_Point_Type;
-----------------------
-- Check_Dereference --
-----------------------
procedure Check_Dereference is
begin
-- Case of a subtype mark
if Is_Entity_Name (P)
and then Is_Type (Entity (P))
then
return;
end if;
-- Case of an expression
Resolve (P);
if Is_Access_Type (P_Type) then
-- If there is an implicit dereference, then we must freeze
-- the designated type of the access type, since the type of
-- the referenced array is this type (see AI95-00106).
Freeze_Before (N, Designated_Type (P_Type));
Rewrite (P,
Make_Explicit_Dereference (Sloc (P),
Prefix => Relocate_Node (P)));
Analyze_And_Resolve (P);
P_Type := Etype (P);
if P_Type = Any_Type then
raise Bad_Attribute;
end if;
P_Base_Type := Base_Type (P_Type);
end if;
end Check_Dereference;
-------------------------
-- Check_Discrete_Type --
-------------------------
procedure Check_Discrete_Type is
begin
Check_Type;
if not Is_Discrete_Type (P_Type) then
Error_Attr ("prefix of % attribute must be discrete type", P);
end if;
end Check_Discrete_Type;
--------------
-- Check_E0 --
--------------
procedure Check_E0 is
begin
if Present (E1) then
Unexpected_Argument (E1);
end if;
end Check_E0;
--------------
-- Check_E1 --
--------------
procedure Check_E1 is
begin
Check_Either_E0_Or_E1;
if No (E1) then
-- Special-case attributes that are functions and that appear as
-- the prefix of another attribute. Error is posted on parent.
if Nkind (Parent (N)) = N_Attribute_Reference
and then (Attribute_Name (Parent (N)) = Name_Address
or else
Attribute_Name (Parent (N)) = Name_Code_Address
or else
Attribute_Name (Parent (N)) = Name_Access)
then
Error_Msg_Name_1 := Attribute_Name (Parent (N));
Error_Msg_N ("illegal prefix for % attribute", Parent (N));
Set_Etype (Parent (N), Any_Type);
Set_Entity (Parent (N), Any_Type);
raise Bad_Attribute;
else
Error_Attr ("missing argument for % attribute", N);
end if;
end if;
end Check_E1;
--------------
-- Check_E2 --
--------------
procedure Check_E2 is
begin
if No (E1) then
Error_Attr ("missing arguments for % attribute (2 required)", N);
elsif No (E2) then
Error_Attr ("missing argument for % attribute (2 required)", N);
end if;
end Check_E2;
---------------------------
-- Check_Either_E0_Or_E1 --
---------------------------
procedure Check_Either_E0_Or_E1 is
begin
if Present (E2) then
Unexpected_Argument (E2);
end if;
end Check_Either_E0_Or_E1;
----------------------
-- Check_Enum_Image --
----------------------
procedure Check_Enum_Image is
Lit : Entity_Id;
begin
if Is_Enumeration_Type (P_Base_Type) then
Lit := First_Literal (P_Base_Type);
while Present (Lit) loop
Set_Referenced (Lit);
Next_Literal (Lit);
end loop;
end if;
end Check_Enum_Image;
----------------------------
-- Check_Fixed_Point_Type --
----------------------------
procedure Check_Fixed_Point_Type is
begin
Check_Type;
if not Is_Fixed_Point_Type (P_Type) then
Error_Attr ("prefix of % attribute must be fixed point type", P);
end if;
end Check_Fixed_Point_Type;
------------------------------
-- Check_Fixed_Point_Type_0 --
------------------------------
procedure Check_Fixed_Point_Type_0 is
begin
Check_Fixed_Point_Type;
Check_E0;
end Check_Fixed_Point_Type_0;
-------------------------------
-- Check_Floating_Point_Type --
-------------------------------
procedure Check_Floating_Point_Type is
begin
Check_Type;
if not Is_Floating_Point_Type (P_Type) then
Error_Attr ("prefix of % attribute must be float type", P);
end if;
end Check_Floating_Point_Type;
---------------------------------
-- Check_Floating_Point_Type_0 --
---------------------------------
procedure Check_Floating_Point_Type_0 is
begin
Check_Floating_Point_Type;
Check_E0;
end Check_Floating_Point_Type_0;
---------------------------------
-- Check_Floating_Point_Type_1 --
---------------------------------
procedure Check_Floating_Point_Type_1 is
begin
Check_Floating_Point_Type;
Check_E1;
end Check_Floating_Point_Type_1;
---------------------------------
-- Check_Floating_Point_Type_2 --
---------------------------------
procedure Check_Floating_Point_Type_2 is
begin
Check_Floating_Point_Type;
Check_E2;
end Check_Floating_Point_Type_2;
------------------------
-- Check_Integer_Type --
------------------------
procedure Check_Integer_Type is
begin
Check_Type;
if not Is_Integer_Type (P_Type) then
Error_Attr ("prefix of % attribute must be integer type", P);
end if;
end Check_Integer_Type;
------------------------
-- Check_Library_Unit --
------------------------
procedure Check_Library_Unit is
begin
if not Is_Compilation_Unit (Entity (P)) then
Error_Attr ("prefix of % attribute must be library unit", P);
end if;
end Check_Library_Unit;
--------------------------------
-- Check_Modular_Integer_Type --
--------------------------------
procedure Check_Modular_Integer_Type is
begin
Check_Type;
if not Is_Modular_Integer_Type (P_Type) then
Error_Attr
("prefix of % attribute must be modular integer type", P);
end if;
end Check_Modular_Integer_Type;
-------------------------------
-- Check_Not_Incomplete_Type --
-------------------------------
procedure Check_Not_Incomplete_Type is
E : Entity_Id;
Typ : Entity_Id;
begin
-- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
-- dereference we have to check wrong uses of incomplete types
-- (other wrong uses are checked at their freezing point).
-- Example 1: Limited-with
-- limited with Pkg;
-- package P is
-- type Acc is access Pkg.T;
-- X : Acc;
-- S : Integer := X.all'Size; -- ERROR
-- end P;
-- Example 2: Tagged incomplete
-- type T is tagged;
-- type Acc is access all T;
-- X : Acc;
-- S : constant Integer := X.all'Size; -- ERROR
-- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
if Ada_Version >= Ada_05
and then Nkind (P) = N_Explicit_Dereference
then
E := P;
while Nkind (E) = N_Explicit_Dereference loop
E := Prefix (E);
end loop;
if From_With_Type (Etype (E)) then
Error_Attr
("prefix of % attribute cannot be an incomplete type", P);
else
if Is_Access_Type (Etype (E)) then
Typ := Directly_Designated_Type (Etype (E));
else
Typ := Etype (E);
end if;
if Ekind (Typ) = E_Incomplete_Type
and then No (Full_View (Typ))
then
Error_Attr
("prefix of % attribute cannot be an incomplete type", P);
end if;
end if;
end if;
if not Is_Entity_Name (P)
or else not Is_Type (Entity (P))
or else In_Default_Expression
then
return;
else
Check_Fully_Declared (P_Type, P);
end if;
end Check_Not_Incomplete_Type;
----------------------------
-- Check_Object_Reference --
----------------------------
procedure Check_Object_Reference (P : Node_Id) is
Rtyp : Entity_Id;
begin
-- If we need an object, and we have a prefix that is the name of
-- a function entity, convert it into a function call.
if Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Function
then
Rtyp := Etype (Entity (P));
Rewrite (P,
Make_Function_Call (Sloc (P),
Name => Relocate_Node (P)));
Analyze_And_Resolve (P, Rtyp);
-- Otherwise we must have an object reference
elsif not Is_Object_Reference (P) then
Error_Attr ("prefix of % attribute must be object", P);
end if;
end Check_Object_Reference;
------------------------
-- Check_Program_Unit --
------------------------
procedure Check_Program_Unit is
begin
if Is_Entity_Name (P) then
declare
K : constant Entity_Kind := Ekind (Entity (P));
T : constant Entity_Id := Etype (Entity (P));
begin
if K in Subprogram_Kind
or else K in Task_Kind
or else K in Protected_Kind
or else K = E_Package
or else K in Generic_Unit_Kind
or else (K = E_Variable
and then
(Is_Task_Type (T)
or else
Is_Protected_Type (T)))
then
return;
end if;
end;
end if;
Error_Attr ("prefix of % attribute must be program unit", P);
end Check_Program_Unit;
---------------------
-- Check_Real_Type --
---------------------
procedure Check_Real_Type is
begin
Check_Type;
if not Is_Real_Type (P_Type) then
Error_Attr ("prefix of % attribute must be real type", P);
end if;
end Check_Real_Type;
-----------------------
-- Check_Scalar_Type --
-----------------------
procedure Check_Scalar_Type is
begin
Check_Type;
if not Is_Scalar_Type (P_Type) then
Error_Attr ("prefix of % attribute must be scalar type", P);
end if;
end Check_Scalar_Type;
---------------------------
-- Check_Standard_Prefix --
---------------------------
procedure Check_Standard_Prefix is
begin
Check_E0;
if Nkind (P) /= N_Identifier
or else Chars (P) /= Name_Standard
then
Error_Attr ("only allowed prefix for % attribute is Standard", P);
end if;
end Check_Standard_Prefix;
----------------------------
-- Check_Stream_Attribute --
----------------------------
procedure Check_Stream_Attribute (Nam : TSS_Name_Type) is
Etyp : Entity_Id;
Btyp : Entity_Id;
begin
Validate_Non_Static_Attribute_Function_Call;
-- With the exception of 'Input, Stream attributes are procedures,
-- and can only appear at the position of procedure calls. We check
-- for this here, before they are rewritten, to give a more precise
-- diagnostic.
if Nam = TSS_Stream_Input then
null;
elsif Is_List_Member (N)
and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
and then Nkind (Parent (N)) /= N_Aggregate
then
null;
else
Error_Attr
("invalid context for attribute%, which is a procedure", N);
end if;
Check_Type;
Btyp := Implementation_Base_Type (P_Type);
-- Stream attributes not allowed on limited types unless the
-- attribute reference was generated by the expander (in which
-- case the underlying type will be used, as described in Sinfo),
-- or the attribute was specified explicitly for the type itself
-- or one of its ancestors (taking visibility rules into account if
-- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
-- (with no visibility restriction).
if Comes_From_Source (N)
and then not Stream_Attribute_Available (P_Type, Nam)
and then not Has_Rep_Pragma (Btyp, Name_Stream_Convert)
then
Error_Msg_Name_1 := Aname;
if Is_Limited_Type (P_Type) then
Error_Msg_NE
("limited type& has no% attribute", P, P_Type);
Explain_Limited_Type (P_Type, P);
else
Error_Msg_NE
("attribute% for type& is not available", P, P_Type);
end if;
end if;
-- Check for violation of restriction No_Stream_Attributes
if Is_RTE (P_Type, RE_Exception_Id)
or else
Is_RTE (P_Type, RE_Exception_Occurrence)
then
Check_Restriction (No_Exception_Registration, P);
end if;
-- Here we must check that the first argument is an access type
-- that is compatible with Ada.Streams.Root_Stream_Type'Class.
Analyze_And_Resolve (E1);
Etyp := Etype (E1);
-- Note: the double call to Root_Type here is needed because the
-- root type of a class-wide type is the corresponding type (e.g.
-- X for X'Class, and we really want to go to the root.
if not Is_Access_Type (Etyp)
or else Root_Type (Root_Type (Designated_Type (Etyp))) /=
RTE (RE_Root_Stream_Type)
then
Error_Attr
("expected access to Ada.Streams.Root_Stream_Type''Class", E1);
end if;
-- Check that the second argument is of the right type if there is
-- one (the Input attribute has only one argument so this is skipped)
if Present (E2) then
Analyze (E2);
if Nam = TSS_Stream_Read
and then not Is_OK_Variable_For_Out_Formal (E2)
then
Error_Attr
("second argument of % attribute must be a variable", E2);
end if;
Resolve (E2, P_Type);
end if;
end Check_Stream_Attribute;
-----------------------
-- Check_Task_Prefix --
-----------------------
procedure Check_Task_Prefix is
begin
Analyze (P);
-- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
-- task interface class-wide types.
if Is_Task_Type (Etype (P))
or else (Is_Access_Type (Etype (P))
and then Is_Task_Type (Designated_Type (Etype (P))))
or else (Ada_Version >= Ada_05
and then Ekind (Etype (P)) = E_Class_Wide_Type
and then Is_Interface (Etype (P))
and then Is_Task_Interface (Etype (P)))
then
Resolve (P);
else
if Ada_Version >= Ada_05 then
Error_Attr ("prefix of % attribute must be a task or a task "
& "interface class-wide object", P);
else
Error_Attr ("prefix of % attribute must be a task", P);
end if;
end if;
end Check_Task_Prefix;
----------------
-- Check_Type --
----------------
-- The possibilities are an entity name denoting a type, or an
-- attribute reference that denotes a type (Base or Class). If
-- the type is incomplete, replace it with its full view.
procedure Check_Type is
begin
if not Is_Entity_Name (P)
or else not Is_Type (Entity (P))
then
Error_Attr ("prefix of % attribute must be a type", P);
elsif Ekind (Entity (P)) = E_Incomplete_Type
and then Present (Full_View (Entity (P)))
then
P_Type := Full_View (Entity (P));
Set_Entity (P, P_Type);
end if;
end Check_Type;
---------------------
-- Check_Unit_Name --
---------------------
procedure Check_Unit_Name (Nod : Node_Id) is
begin
if Nkind (Nod) = N_Identifier then
return;
elsif Nkind (Nod) = N_Selected_Component then
Check_Unit_Name (Prefix (Nod));
if Nkind (Selector_Name (Nod)) = N_Identifier then
return;
end if;
end if;
Error_Attr ("argument for % attribute must be unit name", P);
end Check_Unit_Name;
----------------
-- Error_Attr --
----------------
procedure Error_Attr is
begin
Set_Etype (N, Any_Type);
Set_Entity (N, Any_Type);
raise Bad_Attribute;
end Error_Attr;
procedure Error_Attr (Msg : String; Error_Node : Node_Id) is
begin
Error_Msg_Name_1 := Aname;
Error_Msg_N (Msg, Error_Node);
Error_Attr;
end Error_Attr;
----------------------------
-- Legal_Formal_Attribute --
----------------------------
procedure Legal_Formal_Attribute is
begin
Check_E0;
if not Is_Entity_Name (P)
or else not Is_Type (Entity (P))
then
Error_Attr ("prefix of % attribute must be generic type", N);
elsif Is_Generic_Actual_Type (Entity (P))
or else In_Instance
or else In_Inlined_Body
then
null;
elsif Is_Generic_Type (Entity (P)) then
if not Is_Indefinite_Subtype (Entity (P)) then
Error_Attr
("prefix of % attribute must be indefinite generic type", N);
end if;
else
Error_Attr
("prefix of % attribute must be indefinite generic type", N);
end if;
Set_Etype (N, Standard_Boolean);
end Legal_Formal_Attribute;
------------------------
-- Standard_Attribute --
------------------------
procedure Standard_Attribute (Val : Int) is
begin
Check_Standard_Prefix;
-- First a special check (more like a kludge really). For GNAT5
-- on Windows, the alignments in GCC are severely mixed up. In
-- particular, we have a situation where the maximum alignment
-- that GCC thinks is possible is greater than the guaranteed
-- alignment at run-time. That causes many problems. As a partial
-- cure for this situation, we force a value of 4 for the maximum
-- alignment attribute on this target. This still does not solve
-- all problems, but it helps.
-- A further (even more horrible) dimension to this kludge is now
-- installed. There are two uses for Maximum_Alignment, one is to
-- determine the maximum guaranteed alignment, that's the one we
-- want the kludge to yield as 4. The other use is to maximally
-- align objects, we can't use 4 here, since for example, long
-- long integer has an alignment of 8, so we will get errors.
-- It is of course impossible to determine which use the programmer
-- has in mind, but an approximation for now is to disconnect the
-- kludge if the attribute appears in an alignment clause.
-- To be removed if GCC ever gets its act together here ???
Alignment_Kludge : declare
P : Node_Id;
function On_X86 return Boolean;
-- Determine if target is x86 (ia32), return True if so
------------
-- On_X86 --
------------
function On_X86 return Boolean is
T : constant String := Sdefault.Target_Name.all;
begin
-- There is no clean way to check this. That's not surprising,
-- the front end should not be doing this kind of test ???. The
-- way we do it is test for either "86" or "pentium" being in
-- the string for the target name. However, we need to exclude
-- x86_64 for this check.
for J in T'First .. T'Last - 1 loop
if (T (J .. J + 1) = "86"
and then
(J + 4 > T'Last
or else T (J + 2 .. J + 4) /= "_64"))
or else (J <= T'Last - 6
and then T (J .. J + 6) = "pentium")
then
return True;
end if;
end loop;
return False;
end On_X86;
begin
if Aname = Name_Maximum_Alignment and then On_X86 then
P := Parent (N);
while Nkind (P) in N_Subexpr loop
P := Parent (P);
end loop;
if Nkind (P) /= N_Attribute_Definition_Clause
or else Chars (P) /= Name_Alignment
then
Rewrite (N, Make_Integer_Literal (Loc, 4));
Analyze (N);
return;
end if;
end if;
end Alignment_Kludge;
-- Normally we get the value from gcc ???
Rewrite (N, Make_Integer_Literal (Loc, Val));
Analyze (N);
end Standard_Attribute;
-------------------------
-- Unexpected Argument --
-------------------------
procedure Unexpected_Argument (En : Node_Id) is
begin
Error_Attr ("unexpected argument for % attribute", En);
end Unexpected_Argument;
-------------------------------------------------
-- Validate_Non_Static_Attribute_Function_Call --
-------------------------------------------------
-- This function should be moved to Sem_Dist ???
procedure Validate_Non_Static_Attribute_Function_Call is
begin
if In_Preelaborated_Unit
and then not In_Subprogram_Or_Concurrent_Unit
then
Flag_Non_Static_Expr
("non-static function call in preelaborated unit!", N);
end if;
end Validate_Non_Static_Attribute_Function_Call;
-----------------------------------------------
-- Start of Processing for Analyze_Attribute --
-----------------------------------------------
begin
-- Immediate return if unrecognized attribute (already diagnosed
-- by parser, so there is nothing more that we need to do)
if not Is_Attribute_Name (Aname) then
raise Bad_Attribute;
end if;
-- Deal with Ada 83 and Features issues
if Comes_From_Source (N) then
if not Attribute_83 (Attr_Id) then
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
Error_Msg_Name_1 := Aname;
Error_Msg_N ("(Ada 83) attribute% is not standard?", N);
end if;
if Attribute_Impl_Def (Attr_Id) then
Check_Restriction (No_Implementation_Attributes, N);
end if;
end if;
end if;
-- Remote access to subprogram type access attribute reference needs
-- unanalyzed copy for tree transformation. The analyzed copy is used
-- for its semantic information (whether prefix is a remote subprogram
-- name), the unanalyzed copy is used to construct new subtree rooted
-- with N_Aggregate which represents a fat pointer aggregate.
if Aname = Name_Access then
Discard_Node (Copy_Separate_Tree (N));
end if;
-- Analyze prefix and exit if error in analysis. If the prefix is an
-- incomplete type, use full view if available. A special case is
-- that we never analyze the prefix of an Elab_Body or Elab_Spec
-- or UET_Address attribute.
if Aname /= Name_Elab_Body
and then
Aname /= Name_Elab_Spec
and then
Aname /= Name_UET_Address
then
Analyze (P);
P_Type := Etype (P);
if Is_Entity_Name (P)
and then Present (Entity (P))
and then Is_Type (Entity (P))
then
if Ekind (Entity (P)) = E_Incomplete_Type then
P_Type := Get_Full_View (P_Type);
Set_Entity (P, P_Type);
Set_Etype (P, P_Type);
elsif Entity (P) = Current_Scope
and then Is_Record_Type (Entity (P))
then
-- Use of current instance within the type. Verify that if the
-- attribute appears within a constraint, it yields an access
-- type, other uses are illegal.
declare
Par : Node_Id;
begin
Par := Parent (N);
while Present (Par)
and then Nkind (Parent (Par)) /= N_Component_Definition
loop
Par := Parent (Par);
end loop;
if Present (Par)
and then Nkind (Par) = N_Subtype_Indication
then
if Attr_Id /= Attribute_Access
and then Attr_Id /= Attribute_Unchecked_Access
and then Attr_Id /= Attribute_Unrestricted_Access
then
Error_Msg_N
("in a constraint the current instance can only"
& " be used with an access attribute", N);
end if;
end if;
end;
end if;
end if;
if P_Type = Any_Type then
raise Bad_Attribute;
end if;
P_Base_Type := Base_Type (P_Type);
end if;
-- Analyze expressions that may be present, exiting if an error occurs
if No (Exprs) then
E1 := Empty;
E2 := Empty;
else
E1 := First (Exprs);
Analyze (E1);
-- Check for missing or bad expression (result of previous error)
if No (E1) or else Etype (E1) = Any_Type then
raise Bad_Attribute;
end if;
E2 := Next (E1);
if Present (E2) then
Analyze (E2);
if Etype (E2) = Any_Type then
raise Bad_Attribute;
end if;
if Present (Next (E2)) then
Unexpected_Argument (Next (E2));
end if;
end if;
end if;
-- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
-- output compiling in Ada 95 mode
if Ada_Version < Ada_05
and then Is_Overloaded (P)
and then Aname /= Name_Access
and then Aname /= Name_Address
and then Aname /= Name_Code_Address
and then Aname /= Name_Count
and then Aname /= Name_Unchecked_Access
then
Error_Attr ("ambiguous prefix for % attribute", P);
elsif Ada_Version >= Ada_05
and then Is_Overloaded (P)
and then Aname /= Name_Access
and then Aname /= Name_Address
and then Aname /= Name_Code_Address
and then Aname /= Name_Unchecked_Access
then
-- Ada 2005 (AI-345): Since protected and task types have primitive
-- entry wrappers, the attributes Count, Caller and AST_Entry require
-- a context check
if Ada_Version >= Ada_05
and then (Aname = Name_Count
or else Aname = Name_Caller
or else Aname = Name_AST_Entry)
then
declare
Count : Natural := 0;
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
if Comes_From_Source (It.Nam) then
Count := Count + 1;
else
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
if Count > 1 then
Error_Attr ("ambiguous prefix for % attribute", P);
else
Set_Is_Overloaded (P, False);
end if;
end;
else
Error_Attr ("ambiguous prefix for % attribute", P);
end if;
end if;
-- Remaining processing depends on attribute
case Attr_Id is
------------------
-- Abort_Signal --
------------------
when Attribute_Abort_Signal =>
Check_Standard_Prefix;
Rewrite (N,
New_Reference_To (Stand.Abort_Signal, Loc));
Analyze (N);
------------
-- Access --
------------
when Attribute_Access =>
Analyze_Access_Attribute;
-------------
-- Address --
-------------
when Attribute_Address =>
Check_E0;
-- Check for some junk cases, where we have to allow the address
-- attribute but it does not make much sense, so at least for now
-- just replace with Null_Address.
-- We also do this if the prefix is a reference to the AST_Entry
-- attribute. If expansion is active, the attribute will be
-- replaced by a function call, and address will work fine and
-- get the proper value, but if expansion is not active, then
-- the check here allows proper semantic analysis of the reference.
-- An Address attribute created by expansion is legal even when it
-- applies to other entity-denoting expressions.
if Is_Entity_Name (P) then
declare
Ent : constant Entity_Id := Entity (P);
begin
if Is_Subprogram (Ent) then
if not Is_Library_Level_Entity (Ent) then
Check_Restriction (No_Implicit_Dynamic_Code, P);
end if;
Set_Address_Taken (Ent);
-- An Address attribute is accepted when generated by
-- the compiler for dispatching operation, and an error
-- is issued once the subprogram is frozen (to avoid
-- confusing errors about implicit uses of Address in
-- the dispatch table initialization).
if Is_Always_Inlined (Entity (P))
and then Comes_From_Source (P)
then
Error_Attr
("prefix of % attribute cannot be Inline_Always" &
" subprogram", P);
end if;
elsif Is_Object (Ent)
or else Ekind (Ent) = E_Label
then
Set_Address_Taken (Ent);
-- If we have an address of an object, and the attribute
-- comes from source, then set the object as potentially
-- source modified. We do this because the resulting address
-- can potentially be used to modify the variable and we
-- might not detect this, leading to some junk warnings.
Set_Never_Set_In_Source (Ent, False);
elsif (Is_Concurrent_Type (Etype (Ent))
and then Etype (Ent) = Base_Type (Ent))
or else Ekind (Ent) = E_Package
or else Is_Generic_Unit (Ent)
then
Rewrite (N,
New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
else
Error_Attr ("invalid prefix for % attribute", P);
end if;
end;
elsif Nkind (P) = N_Attribute_Reference
and then Attribute_Name (P) = Name_AST_Entry
then
Rewrite (N,
New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
elsif Is_Object_Reference (P) then
null;
elsif Nkind (P) = N_Selected_Component
and then Is_Subprogram (Entity (Selector_Name (P)))
then
null;
-- What exactly are we allowing here ??? and is this properly
-- documented in the sinfo documentation for this node ???
elsif not Comes_From_Source (N) then
null;
else
Error_Attr ("invalid prefix for % attribute", P);
end if;
Set_Etype (N, RTE (RE_Address));
------------------
-- Address_Size --
------------------
when Attribute_Address_Size =>
Standard_Attribute (System_Address_Size);
--------------
-- Adjacent --
--------------
when Attribute_Adjacent =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
Resolve (E2, P_Base_Type);
---------
-- Aft --
---------
when Attribute_Aft =>
Check_Fixed_Point_Type_0;
Set_Etype (N, Universal_Integer);
---------------
-- Alignment --
---------------
when Attribute_Alignment =>
-- Don't we need more checking here, cf Size ???
Check_E0;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
---------------
-- Asm_Input --
---------------
when Attribute_Asm_Input =>
Check_Asm_Attribute;
Set_Etype (N, RTE (RE_Asm_Input_Operand));
----------------
-- Asm_Output --
----------------
when Attribute_Asm_Output =>
Check_Asm_Attribute;
if Etype (E2) = Any_Type then
return;
elsif Aname = Name_Asm_Output then
if not Is_Variable (E2) then
Error_Attr
("second argument for Asm_Output is not variable", E2);
end if;
end if;
Note_Possible_Modification (E2);
Set_Etype (N, RTE (RE_Asm_Output_Operand));
---------------
-- AST_Entry --
---------------
when Attribute_AST_Entry => AST_Entry : declare
Ent : Entity_Id;
Pref : Node_Id;
Ptyp : Entity_Id;
Indexed : Boolean;
-- Indicates if entry family index is present. Note the coding
-- here handles the entry family case, but in fact it cannot be
-- executed currently, because pragma AST_Entry does not permit
-- the specification of an entry family.
procedure Bad_AST_Entry;
-- Signal a bad AST_Entry pragma
function OK_Entry (E : Entity_Id) return Boolean;
-- Checks that E is of an appropriate entity kind for an entry
-- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
-- is set True for the entry family case). In the True case,
-- makes sure that Is_AST_Entry is set on the entry.
procedure Bad_AST_Entry is
begin
Error_Attr ("prefix for % attribute must be task entry", P);
end Bad_AST_Entry;
function OK_Entry (E : Entity_Id) return Boolean is
Result : Boolean;
begin
if Indexed then
Result := (Ekind (E) = E_Entry_Family);
else
Result := (Ekind (E) = E_Entry);
end if;
if Result then
if not Is_AST_Entry (E) then
Error_Msg_Name_2 := Aname;
Error_Attr
("% attribute requires previous % pragma", P);
end if;
end if;
return Result;
end OK_Entry;
-- Start of processing for AST_Entry
begin
Check_VMS (N);
Check_E0;
-- Deal with entry family case
if Nkind (P) = N_Indexed_Component then
Pref := Prefix (P);
Indexed := True;
else
Pref := P;
Indexed := False;
end if;
Ptyp := Etype (Pref);
if Ptyp = Any_Type or else Error_Posted (Pref) then
return;
end if;
-- If the prefix is a selected component whose prefix is of an
-- access type, then introduce an explicit dereference.
-- ??? Could we reuse Check_Dereference here?
if Nkind (Pref) = N_Selected_Component
and then Is_Access_Type (Ptyp)
then
Rewrite (Pref,
Make_Explicit_Dereference (Sloc (Pref),
Relocate_Node (Pref)));
Analyze_And_Resolve (Pref, Designated_Type (Ptyp));
end if;
-- Prefix can be of the form a.b, where a is a task object
-- and b is one of the entries of the corresponding task type.
if Nkind (Pref) = N_Selected_Component
and then OK_Entry (Entity (Selector_Name (Pref)))
and then Is_Object_Reference (Prefix (Pref))
and then Is_Task_Type (Etype (Prefix (Pref)))
then
null;
-- Otherwise the prefix must be an entry of a containing task,
-- or of a variable of the enclosing task type.
else
if Nkind (Pref) = N_Identifier
or else Nkind (Pref) = N_Expanded_Name
then
Ent := Entity (Pref);
if not OK_Entry (Ent)
or else not In_Open_Scopes (Scope (Ent))
then
Bad_AST_Entry;
end if;
else
Bad_AST_Entry;
end if;
end if;
Set_Etype (N, RTE (RE_AST_Handler));
end AST_Entry;
----------
-- Base --
----------
-- Note: when the base attribute appears in the context of a subtype
-- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
-- the following circuit.
when Attribute_Base => Base : declare
Typ : Entity_Id;
begin
Check_Either_E0_Or_E1;
Find_Type (P);
Typ := Entity (P);
if Ada_Version >= Ada_95
and then not Is_Scalar_Type (Typ)
and then not Is_Generic_Type (Typ)
then
Error_Msg_N ("prefix of Base attribute must be scalar type", N);
elsif Sloc (Typ) = Standard_Location
and then Base_Type (Typ) = Typ
and then Warn_On_Redundant_Constructs
then
Error_Msg_NE
("?redudant attribute, & is its own base type", N, Typ);
end if;
Set_Etype (N, Base_Type (Entity (P)));
-- If we have an expression present, then really this is a conversion
-- and the tree must be reformed. Note that this is one of the cases
-- in which we do a replace rather than a rewrite, because the
-- original tree is junk.
if Present (E1) then
Replace (N,
Make_Type_Conversion (Loc,
Subtype_Mark =>
Make_Attribute_Reference (Loc,
Prefix => Prefix (N),
Attribute_Name => Name_Base),
Expression => Relocate_Node (E1)));
-- E1 may be overloaded, and its interpretations preserved
Save_Interps (E1, Expression (N));
Analyze (N);
-- For other cases, set the proper type as the entity of the
-- attribute reference, and then rewrite the node to be an
-- occurrence of the referenced base type. This way, no one
-- else in the compiler has to worry about the base attribute.
else
Set_Entity (N, Base_Type (Entity (P)));
Rewrite (N,
New_Reference_To (Entity (N), Loc));
Analyze (N);
end if;
end Base;
---------
-- Bit --
---------
when Attribute_Bit => Bit :
begin
Check_E0;
if not Is_Object_Reference (P) then
Error_Attr ("prefix for % attribute must be object", P);
-- What about the access object cases ???
else
null;
end if;
Set_Etype (N, Universal_Integer);
end Bit;
---------------
-- Bit_Order --
---------------
when Attribute_Bit_Order => Bit_Order :
begin
Check_E0;
Check_Type;
if not Is_Record_Type (P_Type) then
Error_Attr ("prefix of % attribute must be record type", P);
end if;
if Bytes_Big_Endian xor Reverse_Bit_Order (P_Type) then
Rewrite (N,
New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
else
Rewrite (N,
New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
end if;
Set_Etype (N, RTE (RE_Bit_Order));
Resolve (N);
-- Reset incorrect indication of staticness
Set_Is_Static_Expression (N, False);
end Bit_Order;
------------------
-- Bit_Position --
------------------
-- Note: in generated code, we can have a Bit_Position attribute
-- applied to a (naked) record component (i.e. the prefix is an
-- identifier that references an E_Component or E_Discriminant
-- entity directly, and this is interpreted as expected by Gigi.
-- The following code will not tolerate such usage, but when the
-- expander creates this special case, it marks it as analyzed
-- immediately and sets an appropriate type.
when Attribute_Bit_Position =>
if Comes_From_Source (N) then
Check_Component;
end if;
Set_Etype (N, Universal_Integer);
------------------
-- Body_Version --
------------------
when Attribute_Body_Version =>
Check_E0;
Check_Program_Unit;
Set_Etype (N, RTE (RE_Version_String));
--------------
-- Callable --
--------------
when Attribute_Callable =>
Check_E0;
Set_Etype (N, Standard_Boolean);
Check_Task_Prefix;
------------
-- Caller --
------------
when Attribute_Caller => Caller : declare
Ent : Entity_Id;
S : Entity_Id;
begin
Check_E0;
if Nkind (P) = N_Identifier
or else Nkind (P) = N_Expanded_Name
then
Ent := Entity (P);
if not Is_Entry (Ent) then
Error_Attr ("invalid entry name", N);
end if;
else
Error_Attr ("invalid entry name", N);
return;
end if;
for J in reverse 0 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
if S = Scope (Ent) then
Error_Attr ("Caller must appear in matching accept or body", N);
elsif S = Ent then
exit;
end if;
end loop;
Set_Etype (N, RTE (RO_AT_Task_Id));
end Caller;
-------------
-- Ceiling --
-------------
when Attribute_Ceiling =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
-----------
-- Class --
-----------
when Attribute_Class => Class : declare
P : constant Entity_Id := Prefix (N);
begin
Check_Restriction (No_Dispatch, N);
Check_Either_E0_Or_E1;
-- If we have an expression present, then really this is a conversion
-- and the tree must be reformed into a proper conversion. This is a
-- Replace rather than a Rewrite, because the original tree is junk.
-- If expression is overloaded, propagate interpretations to new one.
if Present (E1) then
Replace (N,
Make_Type_Conversion (Loc,
Subtype_Mark =>
Make_Attribute_Reference (Loc,
Prefix => P,
Attribute_Name => Name_Class),
Expression => Relocate_Node (E1)));
Save_Interps (E1, Expression (N));
if not Is_Interface (Etype (P)) then
Analyze (N);
-- Ada 2005 (AI-251): In case of abstract interfaces we have to
-- analyze and resolve the type conversion to generate the code
-- that displaces the reference to the base of the object.
else
Analyze_And_Resolve (N, Etype (P));
end if;
-- Otherwise we just need to find the proper type
else
Find_Type (N);
end if;
end Class;
------------------
-- Code_Address --
------------------
when Attribute_Code_Address =>
Check_E0;
if Nkind (P) = N_Attribute_Reference
and then (Attribute_Name (P) = Name_Elab_Body
or else
Attribute_Name (P) = Name_Elab_Spec)
then
null;
elsif not Is_Entity_Name (P)
or else (Ekind (Entity (P)) /= E_Function
and then
Ekind (Entity (P)) /= E_Procedure)
then
Error_Attr ("invalid prefix for % attribute", P);
Set_Address_Taken (Entity (P));
end if;
Set_Etype (N, RTE (RE_Address));
--------------------
-- Component_Size --
--------------------
when Attribute_Component_Size =>
Check_E0;
Set_Etype (N, Universal_Integer);
-- Note: unlike other array attributes, unconstrained arrays are OK
if Is_Array_Type (P_Type) and then not Is_Constrained (P_Type) then
null;
else
Check_Array_Type;
end if;
-------------
-- Compose --
-------------
when Attribute_Compose =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
Resolve (E2, Any_Integer);
-----------------
-- Constrained --
-----------------
when Attribute_Constrained =>
Check_E0;
Set_Etype (N, Standard_Boolean);
-- Case from RM J.4(2) of constrained applied to private type
if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
Check_Restriction (No_Obsolescent_Features, N);
if Warn_On_Obsolescent_Feature then
Error_Msg_N
("constrained for private type is an " &
"obsolescent feature ('R'M 'J.4)?", N);
end if;
-- If we are within an instance, the attribute must be legal
-- because it was valid in the generic unit. Ditto if this is
-- an inlining of a function declared in an instance.
if In_Instance
or else In_Inlined_Body
then
return;
-- For sure OK if we have a real private type itself, but must
-- be completed, cannot apply Constrained to incomplete type.
elsif Is_Private_Type (Entity (P)) then
-- Note: this is one of the Annex J features that does not
-- generate a warning from -gnatwj, since in fact it seems
-- very useful, and is used in the GNAT runtime.
Check_Not_Incomplete_Type;
return;
end if;
-- Normal (non-obsolescent case) of application to object of
-- a discriminated type.
else
Check_Object_Reference (P);
-- If N does not come from source, then we allow the
-- the attribute prefix to be of a private type whose
-- full type has discriminants. This occurs in cases
-- involving expanded calls to stream attributes.
if not Comes_From_Source (N) then
P_Type := Underlying_Type (P_Type);
end if;
-- Must have discriminants or be an access type designating
-- a type with discriminants. If it is a classwide type is
-- has unknown discriminants.
if Has_Discriminants (P_Type)
or else Has_Unknown_Discriminants (P_Type)
or else
(Is_Access_Type (P_Type)
and then Has_Discriminants (Designated_Type (P_Type)))
then
return;
-- Also allow an object of a generic type if extensions allowed
-- and allow this for any type at all.
elsif (Is_Generic_Type (P_Type)
or else Is_Generic_Actual_Type (P_Type))
and then Extensions_Allowed
then
return;
end if;
end if;
-- Fall through if bad prefix
Error_Attr
("prefix of % attribute must be object of discriminated type", P);
---------------
-- Copy_Sign --
---------------
when Attribute_Copy_Sign =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
Resolve (E2, P_Base_Type);
-----------
-- Count --
-----------
when Attribute_Count => Count :
declare
Ent : Entity_Id;
S : Entity_Id;
Tsk : Entity_Id;
begin
Check_E0;
if Nkind (P) = N_Identifier
or else Nkind (P) = N_Expanded_Name
then
Ent := Entity (P);
if Ekind (Ent) /= E_Entry then
Error_Attr ("invalid entry name", N);
end if;
elsif Nkind (P) = N_Indexed_Component then
if not Is_Entity_Name (Prefix (P))
or else No (Entity (Prefix (P)))
or else Ekind (Entity (Prefix (P))) /= E_Entry_Family
then
if Nkind (Prefix (P)) = N_Selected_Component
and then Present (Entity (Selector_Name (Prefix (P))))
and then Ekind (Entity (Selector_Name (Prefix (P)))) =
E_Entry_Family
then
Error_Attr
("attribute % must apply to entry of current task", P);
else
Error_Attr ("invalid entry family name", P);
end if;
return;
else
Ent := Entity (Prefix (P));
end if;
elsif Nkind (P) = N_Selected_Component
and then Present (Entity (Selector_Name (P)))
and then Ekind (Entity (Selector_Name (P))) = E_Entry
then
Error_Attr
("attribute % must apply to entry of current task", P);
else
Error_Attr ("invalid entry name", N);
return;
end if;
for J in reverse 0 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
if S = Scope (Ent) then
if Nkind (P) = N_Expanded_Name then
Tsk := Entity (Prefix (P));
-- The prefix denotes either the task type, or else a
-- single task whose task type is being analyzed.
if (Is_Type (Tsk)
and then Tsk = S)
or else (not Is_Type (Tsk)
and then Etype (Tsk) = S
and then not (Comes_From_Source (S)))
then
null;
else
Error_Attr
("Attribute % must apply to entry of current task", N);
end if;
end if;
exit;
elsif Ekind (Scope (Ent)) in Task_Kind
and then Ekind (S) /= E_Loop
and then Ekind (S) /= E_Block
and then Ekind (S) /= E_Entry
and then Ekind (S) /= E_Entry_Family
then
Error_Attr ("Attribute % cannot appear in inner unit", N);
elsif Ekind (Scope (Ent)) = E_Protected_Type
and then not Has_Completion (Scope (Ent))
then
Error_Attr ("attribute % can only be used inside body", N);
end if;
end loop;
if Is_Overloaded (P) then
declare
Index : Interp_Index;
It : Interp;
begin
Get_First_Interp (P, Index, It);
while Present (It.Nam) loop
if It.Nam = Ent then
null;
-- Ada 2005 (AI-345): Do not consider primitive entry
-- wrappers generated for task or protected types.
elsif Ada_Version >= Ada_05
and then not Comes_From_Source (It.Nam)
then
null;
else
Error_Attr ("ambiguous entry name", N);
end if;
Get_Next_Interp (Index, It);
end loop;
end;
end if;
Set_Etype (N, Universal_Integer);
end Count;
-----------------------
-- Default_Bit_Order --
-----------------------
when Attribute_Default_Bit_Order => Default_Bit_Order :
begin
Check_Standard_Prefix;
Check_E0;
if Bytes_Big_Endian then
Rewrite (N,
Make_Integer_Literal (Loc, False_Value));
else
Rewrite (N,
Make_Integer_Literal (Loc, True_Value));
end if;
Set_Etype (N, Universal_Integer);
Set_Is_Static_Expression (N);
end Default_Bit_Order;
--------------
-- Definite --
--------------
when Attribute_Definite =>
Legal_Formal_Attribute;
-----------
-- Delta --
-----------
when Attribute_Delta =>
Check_Fixed_Point_Type_0;
Set_Etype (N, Universal_Real);
------------
-- Denorm --
------------
when Attribute_Denorm =>
Check_Floating_Point_Type_0;
Set_Etype (N, Standard_Boolean);
------------
-- Digits --
------------
when Attribute_Digits =>
Check_E0;
Check_Type;
if not Is_Floating_Point_Type (P_Type)
and then not Is_Decimal_Fixed_Point_Type (P_Type)
then
Error_Attr
("prefix of % attribute must be float or decimal type", P);
end if;
Set_Etype (N, Universal_Integer);
---------------
-- Elab_Body --
---------------
-- Also handles processing for Elab_Spec
when Attribute_Elab_Body | Attribute_Elab_Spec =>
Check_E0;
Check_Unit_Name (P);
Set_Etype (N, Standard_Void_Type);
-- We have to manually call the expander in this case to get
-- the necessary expansion (normally attributes that return
-- entities are not expanded).
Expand (N);
---------------
-- Elab_Spec --
---------------
-- Shares processing with Elab_Body
----------------
-- Elaborated --
----------------
when Attribute_Elaborated =>
Check_E0;
Check_Library_Unit;
Set_Etype (N, Standard_Boolean);
----------
-- Emax --
----------
when Attribute_Emax =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
--------------
-- Enum_Rep --
--------------
when Attribute_Enum_Rep => Enum_Rep : declare
begin
if Present (E1) then
Check_E1;
Check_Discrete_Type;
Resolve (E1, P_Base_Type);
else
if not Is_Entity_Name (P)
or else (not Is_Object (Entity (P))
and then
Ekind (Entity (P)) /= E_Enumeration_Literal)
then
Error_Attr
("prefix of %attribute must be " &
"discrete type/object or enum literal", P);
end if;
end if;
Set_Etype (N, Universal_Integer);
end Enum_Rep;
-------------
-- Epsilon --
-------------
when Attribute_Epsilon =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Real);
--------------
-- Exponent --
--------------
when Attribute_Exponent =>
Check_Floating_Point_Type_1;
Set_Etype (N, Universal_Integer);
Resolve (E1, P_Base_Type);
------------------
-- External_Tag --
------------------
when Attribute_External_Tag =>
Check_E0;
Check_Type;
Set_Etype (N, Standard_String);
if not Is_Tagged_Type (P_Type) then
Error_Attr ("prefix of % attribute must be tagged", P);
end if;
-----------
-- First --
-----------
when Attribute_First =>
Check_Array_Or_Scalar_Type;
---------------
-- First_Bit --
---------------
when Attribute_First_Bit =>
Check_Component;
Set_Etype (N, Universal_Integer);
-----------------
-- Fixed_Value --
-----------------
when Attribute_Fixed_Value =>
Check_E1;
Check_Fixed_Point_Type;
Resolve (E1, Any_Integer);
Set_Etype (N, P_Base_Type);
-----------
-- Floor --
-----------
when Attribute_Floor =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
----------
-- Fore --
----------
when Attribute_Fore =>
Check_Fixed_Point_Type_0;
Set_Etype (N, Universal_Integer);
--------------
-- Fraction --
--------------
when Attribute_Fraction =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
-----------------------
-- Has_Access_Values --
-----------------------
when Attribute_Has_Access_Values =>
Check_Type;
Check_E0;
Set_Etype (N, Standard_Boolean);
-----------------------
-- Has_Discriminants --
-----------------------
when Attribute_Has_Discriminants =>
Legal_Formal_Attribute;
--------------
-- Identity --
--------------
when Attribute_Identity =>
Check_E0;
Analyze (P);
if Etype (P) = Standard_Exception_Type then
Set_Etype (N, RTE (RE_Exception_Id));
-- Ada 2005 (AI-345): Attribute 'Identity may be applied to
-- task interface class-wide types.
elsif Is_Task_Type (Etype (P))
or else (Is_Access_Type (Etype (P))
and then Is_Task_Type (Designated_Type (Etype (P))))
or else (Ada_Version >= Ada_05
and then Ekind (Etype (P)) = E_Class_Wide_Type
and then Is_Interface (Etype (P))
and then Is_Task_Interface (Etype (P)))
then
Resolve (P);
Set_Etype (N, RTE (RO_AT_Task_Id));
else
if Ada_Version >= Ada_05 then
Error_Attr ("prefix of % attribute must be an exception, a "
& "task or a task interface class-wide object", P);
else
Error_Attr ("prefix of % attribute must be a task or an "
& "exception", P);
end if;
end if;
-----------
-- Image --
-----------
when Attribute_Image => Image :
begin
Set_Etype (N, Standard_String);
Check_Scalar_Type;
if Is_Real_Type (P_Type) then
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
Error_Msg_Name_1 := Aname;
Error_Msg_N
("(Ada 83) % attribute not allowed for real types", N);
end if;
end if;
if Is_Enumeration_Type (P_Type) then
Check_Restriction (No_Enumeration_Maps, N);
end if;
Check_E1;
Resolve (E1, P_Base_Type);
Check_Enum_Image;
Validate_Non_Static_Attribute_Function_Call;
end Image;
---------
-- Img --
---------
when Attribute_Img => Img :
begin
Set_Etype (N, Standard_String);
if not Is_Scalar_Type (P_Type)
or else (Is_Entity_Name (P) and then Is_Type (Entity (P)))
then
Error_Attr
("prefix of % attribute must be scalar object name", N);
end if;
Check_Enum_Image;
end Img;
-----------
-- Input --
-----------
when Attribute_Input =>
Check_E1;
Check_Stream_Attribute (TSS_Stream_Input);
Set_Etype (N, P_Base_Type);
-------------------
-- Integer_Value --
-------------------
when Attribute_Integer_Value =>
Check_E1;
Check_Integer_Type;
Resolve (E1, Any_Fixed);
Set_Etype (N, P_Base_Type);
-----------
-- Large --
-----------
when Attribute_Large =>
Check_E0;
Check_Real_Type;
Set_Etype (N, Universal_Real);
----------
-- Last --
----------
when Attribute_Last =>
Check_Array_Or_Scalar_Type;
--------------
-- Last_Bit --
--------------
when Attribute_Last_Bit =>
Check_Component;
Set_Etype (N, Universal_Integer);
------------------
-- Leading_Part --
------------------
when Attribute_Leading_Part =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
Resolve (E2, Any_Integer);
------------
-- Length --
------------
when Attribute_Length =>
Check_Array_Type;
Set_Etype (N, Universal_Integer);
-------------
-- Machine --
-------------
when Attribute_Machine =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
------------------
-- Machine_Emax --
------------------
when Attribute_Machine_Emax =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
------------------
-- Machine_Emin --
------------------
when Attribute_Machine_Emin =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
----------------------
-- Machine_Mantissa --
----------------------
when Attribute_Machine_Mantissa =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
-----------------------
-- Machine_Overflows --
-----------------------
when Attribute_Machine_Overflows =>
Check_Real_Type;
Check_E0;
Set_Etype (N, Standard_Boolean);
-------------------
-- Machine_Radix --
-------------------
when Attribute_Machine_Radix =>
Check_Real_Type;
Check_E0;
Set_Etype (N, Universal_Integer);
----------------------
-- Machine_Rounding --
----------------------
when Attribute_Machine_Rounding =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
--------------------
-- Machine_Rounds --
--------------------
when Attribute_Machine_Rounds =>
Check_Real_Type;
Check_E0;
Set_Etype (N, Standard_Boolean);
------------------
-- Machine_Size --
------------------
when Attribute_Machine_Size =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
--------------
-- Mantissa --
--------------
when Attribute_Mantissa =>
Check_E0;
Check_Real_Type;
Set_Etype (N, Universal_Integer);
---------
-- Max --
---------
when Attribute_Max =>
Check_E2;
Check_Scalar_Type;
Resolve (E1, P_Base_Type);
Resolve (E2, P_Base_Type);
Set_Etype (N, P_Base_Type);
----------------------------------
-- Max_Size_In_Storage_Elements --
----------------------------------
when Attribute_Max_Size_In_Storage_Elements =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
-----------------------
-- Maximum_Alignment --
-----------------------
when Attribute_Maximum_Alignment =>
Standard_Attribute (Ttypes.Maximum_Alignment);
--------------------
-- Mechanism_Code --
--------------------
when Attribute_Mechanism_Code =>
if not Is_Entity_Name (P)
or else not Is_Subprogram (Entity (P))
then
Error_Attr ("prefix of % attribute must be subprogram", P);
end if;
Check_Either_E0_Or_E1;
if Present (E1) then
Resolve (E1, Any_Integer);
Set_Etype (E1, Standard_Integer);
if not Is_Static_Expression (E1) then
Flag_Non_Static_Expr
("expression for parameter number must be static!", E1);
Error_Attr;
elsif UI_To_Int (Intval (E1)) > Number_Formals (Entity (P))
or else UI_To_Int (Intval (E1)) < 0
then
Error_Attr ("invalid parameter number for %attribute", E1);
end if;
end if;
Set_Etype (N, Universal_Integer);
---------
-- Min --
---------
when Attribute_Min =>
Check_E2;
Check_Scalar_Type;
Resolve (E1, P_Base_Type);
Resolve (E2, P_Base_Type);
Set_Etype (N, P_Base_Type);
---------
-- Mod --
---------
when Attribute_Mod =>
-- Note: this attribute is only allowed in Ada 2005 mode, but
-- we do not need to test that here, since Mod is only recognized
-- as an attribute name in Ada 2005 mode during the parse.
Check_E1;
Check_Modular_Integer_Type;
Resolve (E1, Any_Integer);
Set_Etype (N, P_Base_Type);
-----------
-- Model --
-----------
when Attribute_Model =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
----------------
-- Model_Emin --
----------------
when Attribute_Model_Emin =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
-------------------
-- Model_Epsilon --
-------------------
when Attribute_Model_Epsilon =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Real);
--------------------
-- Model_Mantissa --
--------------------
when Attribute_Model_Mantissa =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
-----------------
-- Model_Small --
-----------------
when Attribute_Model_Small =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Real);
-------------
-- Modulus --
-------------
when Attribute_Modulus =>
Check_E0;
Check_Modular_Integer_Type;
Set_Etype (N, Universal_Integer);
--------------------
-- Null_Parameter --
--------------------
when Attribute_Null_Parameter => Null_Parameter : declare
Parnt : constant Node_Id := Parent (N);
GParnt : constant Node_Id := Parent (Parnt);
procedure Bad_Null_Parameter (Msg : String);
-- Used if bad Null parameter attribute node is found. Issues
-- given error message, and also sets the type to Any_Type to
-- avoid blowups later on from dealing with a junk node.
procedure Must_Be_Imported (Proc_Ent : Entity_Id);
-- Called to check that Proc_Ent is imported subprogram
------------------------
-- Bad_Null_Parameter --
------------------------
procedure Bad_Null_Parameter (Msg : String) is
begin
Error_Msg_N (Msg, N);
Set_Etype (N, Any_Type);
end Bad_Null_Parameter;
----------------------
-- Must_Be_Imported --
----------------------
procedure Must_Be_Imported (Proc_Ent : Entity_Id) is
Pent : Entity_Id := Proc_Ent;
begin
while Present (Alias (Pent)) loop
Pent := Alias (Pent);
end loop;
-- Ignore check if procedure not frozen yet (we will get
-- another chance when the default parameter is reanalyzed)
if not Is_Frozen (Pent) then
return;
elsif not Is_Imported (Pent) then
Bad_Null_Parameter
("Null_Parameter can only be used with imported subprogram");
else
return;
end if;
end Must_Be_Imported;
-- Start of processing for Null_Parameter
begin
Check_Type;
Check_E0;
Set_Etype (N, P_Type);
-- Case of attribute used as default expression
if Nkind (Parnt) = N_Parameter_Specification then
Must_Be_Imported (Defining_Entity (GParnt));
-- Case of attribute used as actual for subprogram (positional)
elsif (Nkind (Parnt) = N_Procedure_Call_Statement
or else
Nkind (Parnt) = N_Function_Call)
and then Is_Entity_Name (Name (Parnt))
then
Must_Be_Imported (Entity (Name (Parnt)));
-- Case of attribute used as actual for subprogram (named)
elsif Nkind (Parnt) = N_Parameter_Association
and then (Nkind (GParnt) = N_Procedure_Call_Statement
or else
Nkind (GParnt) = N_Function_Call)
and then Is_Entity_Name (Name (GParnt))
then
Must_Be_Imported (Entity (Name (GParnt)));
-- Not an allowed case
else
Bad_Null_Parameter
("Null_Parameter must be actual or default parameter");
end if;
end Null_Parameter;
-----------------
-- Object_Size --
-----------------
when Attribute_Object_Size =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
------------
-- Output --
------------
when Attribute_Output =>
Check_E2;
Check_Stream_Attribute (TSS_Stream_Output);
Set_Etype (N, Standard_Void_Type);
Resolve (N, Standard_Void_Type);
------------------
-- Partition_ID --
------------------
when Attribute_Partition_ID =>
Check_E0;
if P_Type /= Any_Type then
if not Is_Library_Level_Entity (Entity (P)) then
Error_Attr
("prefix of % attribute must be library-level entity", P);
-- The defining entity of prefix should not be declared inside
-- a Pure unit. RM E.1(8).
-- The Is_Pure flag has been set during declaration.
elsif Is_Entity_Name (P)
and then Is_Pure (Entity (P))
then
Error_Attr
("prefix of % attribute must not be declared pure", P);
end if;
end if;
Set_Etype (N, Universal_Integer);
-------------------------
-- Passed_By_Reference --
-------------------------
when Attribute_Passed_By_Reference =>
Check_E0;
Check_Type;
Set_Etype (N, Standard_Boolean);
------------------
-- Pool_Address --
------------------
when Attribute_Pool_Address =>
Check_E0;
Set_Etype (N, RTE (RE_Address));
---------
-- Pos --
---------
when Attribute_Pos =>
Check_Discrete_Type;
Check_E1;
Resolve (E1, P_Base_Type);
Set_Etype (N, Universal_Integer);
--------------
-- Position --
--------------
when Attribute_Position =>
Check_Component;
Set_Etype (N, Universal_Integer);
----------
-- Pred --
----------
when Attribute_Pred =>
Check_Scalar_Type;
Check_E1;
Resolve (E1, P_Base_Type);
Set_Etype (N, P_Base_Type);
-- Nothing to do for real type case
if Is_Real_Type (P_Type) then
null;
-- If not modular type, test for overflow check required
else
if not Is_Modular_Integer_Type (P_Type)
and then not Range_Checks_Suppressed (P_Base_Type)
then
Enable_Range_Check (E1);
end if;
end if;
-----------
-- Range --
-----------
when Attribute_Range =>
Check_Array_Or_Scalar_Type;
if Ada_Version = Ada_83
and then Is_Scalar_Type (P_Type)
and then Comes_From_Source (N)
then
Error_Attr
("(Ada 83) % attribute not allowed for scalar type", P);
end if;
------------------
-- Range_Length --
------------------
when Attribute_Range_Length =>
Check_Discrete_Type;
Set_Etype (N, Universal_Integer);
----------
-- Read --
----------
when Attribute_Read =>
Check_E2;
Check_Stream_Attribute (TSS_Stream_Read);
Set_Etype (N, Standard_Void_Type);
Resolve (N, Standard_Void_Type);
Note_Possible_Modification (E2);
---------------
-- Remainder --
---------------
when Attribute_Remainder =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
Resolve (E2, P_Base_Type);
-----------
-- Round --
-----------
when Attribute_Round =>
Check_E1;
Check_Decimal_Fixed_Point_Type;
Set_Etype (N, P_Base_Type);
-- Because the context is universal_real (3.5.10(12)) it is a legal
-- context for a universal fixed expression. This is the only
-- attribute whose functional description involves U_R.
if Etype (E1) = Universal_Fixed then
declare
Conv : constant Node_Id := Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc),
Expression => Relocate_Node (E1));
begin
Rewrite (E1, Conv);
Analyze (E1);
end;
end if;
Resolve (E1, Any_Real);
--------------
-- Rounding --
--------------
when Attribute_Rounding =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
---------------
-- Safe_Emax --
---------------
when Attribute_Safe_Emax =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Integer);
----------------
-- Safe_First --
----------------
when Attribute_Safe_First =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Real);
----------------
-- Safe_Large --
----------------
when Attribute_Safe_Large =>
Check_E0;
Check_Real_Type;
Set_Etype (N, Universal_Real);
---------------
-- Safe_Last --
---------------
when Attribute_Safe_Last =>
Check_Floating_Point_Type_0;
Set_Etype (N, Universal_Real);
----------------
-- Safe_Small --
----------------
when Attribute_Safe_Small =>
Check_E0;
Check_Real_Type;
Set_Etype (N, Universal_Real);
-----------
-- Scale --
-----------
when Attribute_Scale =>
Check_E0;
Check_Decimal_Fixed_Point_Type;
Set_Etype (N, Universal_Integer);
-------------
-- Scaling --
-------------
when Attribute_Scaling =>
Check_Floating_Point_Type_2;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
------------------
-- Signed_Zeros --
------------------
when Attribute_Signed_Zeros =>
Check_Floating_Point_Type_0;
Set_Etype (N, Standard_Boolean);
----------
-- Size --
----------
when Attribute_Size | Attribute_VADS_Size =>
Check_E0;
-- If prefix is parameterless function call, rewrite and resolve
-- as such.
if Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Function
then
Resolve (P);
-- Similar processing for a protected function call
elsif Nkind (P) = N_Selected_Component
and then Ekind (Entity (Selector_Name (P))) = E_Function
then
Resolve (P);
end if;
if Is_Object_Reference (P) then
Check_Object_Reference (P);
elsif Is_Entity_Name (P)
and then (Is_Type (Entity (P))
or else Ekind (Entity (P)) = E_Enumeration_Literal)
then
null;
elsif Nkind (P) = N_Type_Conversion
and then not Comes_From_Source (P)
then
null;
else
Error_Attr ("invalid prefix for % attribute", P);
end if;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
-----------
-- Small --
-----------
when Attribute_Small =>
Check_E0;
Check_Real_Type;
Set_Etype (N, Universal_Real);
------------------
-- Storage_Pool --
------------------
when Attribute_Storage_Pool =>
if Is_Access_Type (P_Type) then
Check_E0;
-- Set appropriate entity
if Present (Associated_Storage_Pool (Root_Type (P_Type))) then
Set_Entity (N, Associated_Storage_Pool (Root_Type (P_Type)));
else
Set_Entity (N, RTE (RE_Global_Pool_Object));
end if;
Set_Etype (N, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
-- Validate_Remote_Access_To_Class_Wide_Type for attribute
-- Storage_Pool since this attribute is not defined for such
-- types (RM E.2.3(22)).
Validate_Remote_Access_To_Class_Wide_Type (N);
else
Error_Attr ("prefix of % attribute must be access type", P);
end if;
------------------
-- Storage_Size --
------------------
when Attribute_Storage_Size =>
if Is_Task_Type (P_Type) then
Check_E0;
Set_Etype (N, Universal_Integer);
elsif Is_Access_Type (P_Type) then
if Is_Entity_Name (P)
and then Is_Type (Entity (P))
then
Check_E0;
Check_Type;
Set_Etype (N, Universal_Integer);
-- Validate_Remote_Access_To_Class_Wide_Type for attribute
-- Storage_Size since this attribute is not defined for
-- such types (RM E.2.3(22)).
Validate_Remote_Access_To_Class_Wide_Type (N);
-- The prefix is allowed to be an implicit dereference
-- of an access value designating a task.
else
Check_E0;
Check_Task_Prefix;
Set_Etype (N, Universal_Integer);
end if;
else
Error_Attr
("prefix of % attribute must be access or task type", P);
end if;
------------------
-- Storage_Unit --
------------------
when Attribute_Storage_Unit =>
Standard_Attribute (Ttypes.System_Storage_Unit);
-----------------
-- Stream_Size --
-----------------
when Attribute_Stream_Size =>
Check_E0;
Check_Type;
if Is_Entity_Name (P)
and then Is_Elementary_Type (Entity (P))
then
Set_Etype (N, Universal_Integer);
else
Error_Attr ("invalid prefix for % attribute", P);
end if;
----------
-- Succ --
----------
when Attribute_Succ =>
Check_Scalar_Type;
Check_E1;
Resolve (E1, P_Base_Type);
Set_Etype (N, P_Base_Type);
-- Nothing to do for real type case
if Is_Real_Type (P_Type) then
null;
-- If not modular type, test for overflow check required
else
if not Is_Modular_Integer_Type (P_Type)
and then not Range_Checks_Suppressed (P_Base_Type)
then
Enable_Range_Check (E1);
end if;
end if;
---------
-- Tag --
---------
when Attribute_Tag =>
Check_E0;
Check_Dereference;
if not Is_Tagged_Type (P_Type) then
Error_Attr ("prefix of % attribute must be tagged", P);
-- Next test does not apply to generated code
-- why not, and what does the illegal reference mean???
elsif Is_Object_Reference (P)
and then not Is_Class_Wide_Type (P_Type)
and then Comes_From_Source (N)
then
Error_Attr
("% attribute can only be applied to objects of class-wide type",
P);
end if;
Set_Etype (N, RTE (RE_Tag));
-----------------
-- Target_Name --
-----------------
when Attribute_Target_Name => Target_Name : declare
TN : constant String := Sdefault.Target_Name.all;
TL : Natural;
begin
Check_Standard_Prefix;
Check_E0;
TL := TN'Last;
if TN (TL) = '/' or else TN (TL) = '\' then
TL := TL - 1;
end if;
Rewrite (N,
Make_String_Literal (Loc,
Strval => TN (TN'First .. TL)));
Analyze_And_Resolve (N, Standard_String);
end Target_Name;
----------------
-- Terminated --
----------------
when Attribute_Terminated =>
Check_E0;
Set_Etype (N, Standard_Boolean);
Check_Task_Prefix;
----------------
-- To_Address --
----------------
when Attribute_To_Address =>
Check_E1;
Analyze (P);
if Nkind (P) /= N_Identifier
or else Chars (P) /= Name_System
then
Error_Attr ("prefix of %attribute must be System", P);
end if;
Generate_Reference (RTE (RE_Address), P);
Analyze_And_Resolve (E1, Any_Integer);
Set_Etype (N, RTE (RE_Address));
----------------
-- Truncation --
----------------
when Attribute_Truncation =>
Check_Floating_Point_Type_1;
Resolve (E1, P_Base_Type);
Set_Etype (N, P_Base_Type);
----------------
-- Type_Class --
----------------
when Attribute_Type_Class =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, RTE (RE_Type_Class));
-----------------
-- UET_Address --
-----------------
when Attribute_UET_Address =>
Check_E0;
Check_Unit_Name (P);
Set_Etype (N, RTE (RE_Address));
-----------------------
-- Unbiased_Rounding --
-----------------------
when Attribute_Unbiased_Rounding =>
Check_Floating_Point_Type_1;
Set_Etype (N, P_Base_Type);
Resolve (E1, P_Base_Type);
----------------------
-- Unchecked_Access --
----------------------
when Attribute_Unchecked_Access =>
if Comes_From_Source (N) then
Check_Restriction (No_Unchecked_Access, N);
end if;
Analyze_Access_Attribute;
-------------------------
-- Unconstrained_Array --
-------------------------
when Attribute_Unconstrained_Array =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, Standard_Boolean);
------------------------------
-- Universal_Literal_String --
------------------------------
-- This is a GNAT specific attribute whose prefix must be a named
-- number where the expression is either a single numeric literal,
-- or a numeric literal immediately preceded by a minus sign. The
-- result is equivalent to a string literal containing the text of
-- the literal as it appeared in the source program with a possible
-- leading minus sign.
when Attribute_Universal_Literal_String => Universal_Literal_String :
begin
Check_E0;
if not Is_Entity_Name (P)
or else Ekind (Entity (P)) not in Named_Kind
then
Error_Attr ("prefix for % attribute must be named number", P);
else
declare
Expr : Node_Id;
Negative : Boolean;
S : Source_Ptr;
Src : Source_Buffer_Ptr;
begin
Expr := Original_Node (Expression (Parent (Entity (P))));
if Nkind (Expr) = N_Op_Minus then
Negative := True;
Expr := Original_Node (Right_Opnd (Expr));
else
Negative := False;
end if;
if Nkind (Expr) /= N_Integer_Literal
and then Nkind (Expr) /= N_Real_Literal
then
Error_Attr
("named number for % attribute must be simple literal", N);
end if;
-- Build string literal corresponding to source literal text
Start_String;
if Negative then
Store_String_Char (Get_Char_Code ('-'));
end if;
S := Sloc (Expr);
Src := Source_Text (Get_Source_File_Index (S));
while Src (S) /= ';' and then Src (S) /= ' ' loop
Store_String_Char (Get_Char_Code (Src (S)));
S := S + 1;
end loop;
-- Now we rewrite the attribute with the string literal
Rewrite (N,
Make_String_Literal (Loc, End_String));
Analyze (N);
end;
end if;
end Universal_Literal_String;
-------------------------
-- Unrestricted_Access --
-------------------------
-- This is a GNAT specific attribute which is like Access except that
-- all scope checks and checks for aliased views are omitted.
when Attribute_Unrestricted_Access =>
if Comes_From_Source (N) then
Check_Restriction (No_Unchecked_Access, N);
end if;
if Is_Entity_Name (P) then
Set_Address_Taken (Entity (P));
end if;
Analyze_Access_Attribute;
---------
-- Val --
---------
when Attribute_Val => Val : declare
begin
Check_E1;
Check_Discrete_Type;
Resolve (E1, Any_Integer);
Set_Etype (N, P_Base_Type);
-- Note, we need a range check in general, but we wait for the
-- Resolve call to do this, since we want to let Eval_Attribute
-- have a chance to find an static illegality first!
end Val;
-----------
-- Valid --
-----------
when Attribute_Valid =>
Check_E0;
-- Ignore check for object if we have a 'Valid reference generated
-- by the expanded code, since in some cases valid checks can occur
-- on items that are names, but are not objects (e.g. attributes).
if Comes_From_Source (N) then
Check_Object_Reference (P);
end if;
if not Is_Scalar_Type (P_Type) then
Error_Attr ("object for % attribute must be of scalar type", P);
end if;
Set_Etype (N, Standard_Boolean);
-----------
-- Value --
-----------
when Attribute_Value => Value :
begin
Check_E1;
Check_Scalar_Type;
if Is_Enumeration_Type (P_Type) then
Check_Restriction (No_Enumeration_Maps, N);
end if;
-- Set Etype before resolving expression because expansion of
-- expression may require enclosing type. Note that the type
-- returned by 'Value is the base type of the prefix type.
Set_Etype (N, P_Base_Type);
Validate_Non_Static_Attribute_Function_Call;
end Value;
----------------
-- Value_Size --
----------------
when Attribute_Value_Size =>
Check_E0;
Check_Type;
Check_Not_Incomplete_Type;
Set_Etype (N, Universal_Integer);
-------------
-- Version --
-------------
when Attribute_Version =>
Check_E0;
Check_Program_Unit;
Set_Etype (N, RTE (RE_Version_String));
------------------
-- Wchar_T_Size --
------------------
when Attribute_Wchar_T_Size =>
Standard_Attribute (Interfaces_Wchar_T_Size);
----------------
-- Wide_Image --
----------------
when Attribute_Wide_Image => Wide_Image :
begin
Check_Scalar_Type;
Set_Etype (N, Standard_Wide_String);
Check_E1;
Resolve (E1, P_Base_Type);
Validate_Non_Static_Attribute_Function_Call;
end Wide_Image;
---------------------
-- Wide_Wide_Image --
---------------------
when Attribute_Wide_Wide_Image => Wide_Wide_Image :
begin
Check_Scalar_Type;
Set_Etype (N, Standard_Wide_Wide_String);
Check_E1;
Resolve (E1, P_Base_Type);
Validate_Non_Static_Attribute_Function_Call;
end Wide_Wide_Image;
----------------
-- Wide_Value --
----------------
when Attribute_Wide_Value => Wide_Value :
begin
Check_E1;
Check_Scalar_Type;
-- Set Etype before resolving expression because expansion
-- of expression may require enclosing type.
Set_Etype (N, P_Type);
Validate_Non_Static_Attribute_Function_Call;
end Wide_Value;
---------------------
-- Wide_Wide_Value --
---------------------
when Attribute_Wide_Wide_Value => Wide_Wide_Value :
begin
Check_E1;
Check_Scalar_Type;
-- Set Etype before resolving expression because expansion
-- of expression may require enclosing type.
Set_Etype (N, P_Type);
Validate_Non_Static_Attribute_Function_Call;
end Wide_Wide_Value;
---------------------
-- Wide_Wide_Width --
---------------------
when Attribute_Wide_Wide_Width =>
Check_E0;
Check_Scalar_Type;
Set_Etype (N, Universal_Integer);
----------------
-- Wide_Width --
----------------
when Attribute_Wide_Width =>
Check_E0;
Check_Scalar_Type;
Set_Etype (N, Universal_Integer);
-----------
-- Width --
-----------
when Attribute_Width =>
Check_E0;
Check_Scalar_Type;
Set_Etype (N, Universal_Integer);
---------------
-- Word_Size --
---------------
when Attribute_Word_Size =>
Standard_Attribute (System_Word_Size);
-----------
-- Write --
-----------
when Attribute_Write =>
Check_E2;
Check_Stream_Attribute (TSS_Stream_Write);
Set_Etype (N, Standard_Void_Type);
Resolve (N, Standard_Void_Type);
end case;
-- All errors raise Bad_Attribute, so that we get out before any further
-- damage occurs when an error is detected (for example, if we check for
-- one attribute expression, and the check succeeds, we want to be able
-- to proceed securely assuming that an expression is in fact present.
-- Note: we set the attribute analyzed in this case to prevent any
-- attempt at reanalysis which could generate spurious error msgs.
exception
when Bad_Attribute =>
Set_Analyzed (N);
Set_Etype (N, Any_Type);
return;
end Analyze_Attribute;
--------------------
-- Eval_Attribute --
--------------------
procedure Eval_Attribute (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Aname : constant Name_Id := Attribute_Name (N);
Id : constant Attribute_Id := Get_Attribute_Id (Aname);
P : constant Node_Id := Prefix (N);
C_Type : constant Entity_Id := Etype (N);
-- The type imposed by the context
E1 : Node_Id;
-- First expression, or Empty if none
E2 : Node_Id;
-- Second expression, or Empty if none
P_Entity : Entity_Id;
-- Entity denoted by prefix
P_Type : Entity_Id;
-- The type of the prefix
P_Base_Type : Entity_Id;
-- The base type of the prefix type
P_Root_Type : Entity_Id;
-- The root type of the prefix type
Static : Boolean;
-- True if the result is Static. This is set by the general processing
-- to true if the prefix is static, and all expressions are static. It
-- can be reset as processing continues for particular attributes
Lo_Bound, Hi_Bound : Node_Id;
-- Expressions for low and high bounds of type or array index referenced
-- by First, Last, or Length attribute for array, set by Set_Bounds.
CE_Node : Node_Id;
-- Constraint error node used if we have an attribute reference has
-- an argument that raises a constraint error. In this case we replace
-- the attribute with a raise constraint_error node. This is important
-- processing, since otherwise gigi might see an attribute which it is
-- unprepared to deal with.
function Aft_Value return Nat;
-- Computes Aft value for current attribute prefix (used by Aft itself
-- and also by Width for computing the Width of a fixed point type).
procedure Check_Expressions;
-- In case where the attribute is not foldable, the expressions, if
-- any, of the attribute, are in a non-static context. This procedure
-- performs the required additional checks.
function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean;
-- Determines if the given type has compile time known bounds. Note
-- that we enter the case statement even in cases where the prefix
-- type does NOT have known bounds, so it is important to guard any
-- attempt to evaluate both bounds with a call to this function.
procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint);
-- This procedure is called when the attribute N has a non-static
-- but compile time known value given by Val. It includes the
-- necessary checks for out of range values.
procedure Float_Attribute_Universal_Integer
(IEEES_Val : Int;
IEEEL_Val : Int;
IEEEX_Val : Int;
VAXFF_Val : Int;
VAXDF_Val : Int;
VAXGF_Val : Int;
AAMPS_Val : Int;
AAMPL_Val : Int);
-- This procedure evaluates a float attribute with no arguments that
-- returns a universal integer result. The parameters give the values
-- for the possible floating-point root types. See ttypef for details.
-- The prefix type is a float type (and is thus not a generic type).
procedure Float_Attribute_Universal_Real
(IEEES_Val : String;
IEEEL_Val : String;
IEEEX_Val : String;
VAXFF_Val : String;
VAXDF_Val : String;
VAXGF_Val : String;
AAMPS_Val : String;
AAMPL_Val : String);
-- This procedure evaluates a float attribute with no arguments that
-- returns a universal real result. The parameters give the values
-- required for the possible floating-point root types in string
-- format as real literals with a possible leading minus sign.
-- The prefix type is a float type (and is thus not a generic type).
function Fore_Value return Nat;
-- Computes the Fore value for the current attribute prefix, which is
-- known to be a static fixed-point type. Used by Fore and Width.
function Mantissa return Uint;
-- Returns the Mantissa value for the prefix type
procedure Set_Bounds;
-- Used for First, Last and Length attributes applied to an array or
-- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
-- and high bound expressions for the index referenced by the attribute
-- designator (i.e. the first index if no expression is present, and
-- the N'th index if the value N is present as an expression). Also
-- used for First and Last of scalar types. Static is reset to False
-- if the type or index type is not statically constrained.
function Statically_Denotes_Entity (N : Node_Id) return Boolean;
-- Verify that the prefix of a potentially static array attribute
-- satisfies the conditions of 4.9 (14).
---------------
-- Aft_Value --
---------------
function Aft_Value return Nat is
Result : Nat;
Delta_Val : Ureal;
begin
Result := 1;
Delta_Val := Delta_Value (P_Type);
while Delta_Val < Ureal_Tenth loop
Delta_Val := Delta_Val * Ureal_10;
Result := Result + 1;
end loop;
return Result;
end Aft_Value;
-----------------------
-- Check_Expressions --
-----------------------
procedure Check_Expressions is
E : Node_Id := E1;
begin
while Present (E) loop
Check_Non_Static_Context (E);
Next (E);
end loop;
end Check_Expressions;
----------------------------------
-- Compile_Time_Known_Attribute --
----------------------------------
procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint) is
T : constant Entity_Id := Etype (N);
begin
Fold_Uint (N, Val, False);
-- Check that result is in bounds of the type if it is static
if Is_In_Range (N, T) then
null;
elsif Is_Out_Of_Range (N, T) then
Apply_Compile_Time_Constraint_Error
(N, "value not in range of}?", CE_Range_Check_Failed);
elsif not Range_Checks_Suppressed (T) then
Enable_Range_Check (N);
else
Set_Do_Range_Check (N, False);
end if;
end Compile_Time_Known_Attribute;
-------------------------------
-- Compile_Time_Known_Bounds --
-------------------------------
function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean is
begin
return
Compile_Time_Known_Value (Type_Low_Bound (Typ))
and then
Compile_Time_Known_Value (Type_High_Bound (Typ));
end Compile_Time_Known_Bounds;
---------------------------------------
-- Float_Attribute_Universal_Integer --
---------------------------------------
procedure Float_Attribute_Universal_Integer
(IEEES_Val : Int;
IEEEL_Val : Int;
IEEEX_Val : Int;
VAXFF_Val : Int;
VAXDF_Val : Int;
VAXGF_Val : Int;
AAMPS_Val : Int;
AAMPL_Val : Int)
is
Val : Int;
Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
begin
if Vax_Float (P_Base_Type) then
if Digs = VAXFF_Digits then
Val := VAXFF_Val;
elsif Digs = VAXDF_Digits then
Val := VAXDF_Val;
else pragma Assert (Digs = VAXGF_Digits);
Val := VAXGF_Val;
end if;
elsif Is_AAMP_Float (P_Base_Type) then
if Digs = AAMPS_Digits then
Val := AAMPS_Val;
else pragma Assert (Digs = AAMPL_Digits);
Val := AAMPL_Val;
end if;
else
if Digs = IEEES_Digits then
Val := IEEES_Val;
elsif Digs = IEEEL_Digits then
Val := IEEEL_Val;
else pragma Assert (Digs = IEEEX_Digits);
Val := IEEEX_Val;
end if;
end if;
Fold_Uint (N, UI_From_Int (Val), True);
end Float_Attribute_Universal_Integer;
------------------------------------
-- Float_Attribute_Universal_Real --
------------------------------------
procedure Float_Attribute_Universal_Real
(IEEES_Val : String;
IEEEL_Val : String;
IEEEX_Val : String;
VAXFF_Val : String;
VAXDF_Val : String;
VAXGF_Val : String;
AAMPS_Val : String;
AAMPL_Val : String)
is
Val : Node_Id;
Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
begin
if Vax_Float (P_Base_Type) then
if Digs = VAXFF_Digits then
Val := Real_Convert (VAXFF_Val);
elsif Digs = VAXDF_Digits then
Val := Real_Convert (VAXDF_Val);
else pragma Assert (Digs = VAXGF_Digits);
Val := Real_Convert (VAXGF_Val);
end if;
elsif Is_AAMP_Float (P_Base_Type) then
if Digs = AAMPS_Digits then
Val := Real_Convert (AAMPS_Val);
else pragma Assert (Digs = AAMPL_Digits);
Val := Real_Convert (AAMPL_Val);
end if;
else
if Digs = IEEES_Digits then
Val := Real_Convert (IEEES_Val);
elsif Digs = IEEEL_Digits then
Val := Real_Convert (IEEEL_Val);
else pragma Assert (Digs = IEEEX_Digits);
Val := Real_Convert (IEEEX_Val);
end if;
end if;
Set_Sloc (Val, Loc);
Rewrite (N, Val);
Set_Is_Static_Expression (N, Static);
Analyze_And_Resolve (N, C_Type);
end Float_Attribute_Universal_Real;
----------------
-- Fore_Value --
----------------
-- Note that the Fore calculation is based on the actual values
-- of the bounds, and does not take into account possible rounding.
function Fore_Value return Nat is
Lo : constant Uint := Expr_Value (Type_Low_Bound (P_Type));
Hi : constant Uint := Expr_Value (Type_High_Bound (P_Type));
Small : constant Ureal := Small_Value (P_Type);
Lo_Real : constant Ureal := Lo * Small;
Hi_Real : constant Ureal := Hi * Small;
T : Ureal;
R : Nat;
begin
-- Bounds are given in terms of small units, so first compute
-- proper values as reals.
T := UR_Max (abs Lo_Real, abs Hi_Real);
R := 2;
-- Loop to compute proper value if more than one digit required
while T >= Ureal_10 loop
R := R + 1;
T := T / Ureal_10;
end loop;
return R;
end Fore_Value;
--------------
-- Mantissa --
--------------
-- Table of mantissa values accessed by function Computed using
-- the relation:
-- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
-- where D is T'Digits (RM83 3.5.7)
Mantissa_Value : constant array (Nat range 1 .. 40) of Nat := (
1 => 5,
2 => 8,
3 => 11,
4 => 15,
5 => 18,
6 => 21,
7 => 25,
8 => 28,
9 => 31,
10 => 35,
11 => 38,
12 => 41,
13 => 45,
14 => 48,
15 => 51,
16 => 55,
17 => 58,
18 => 61,
19 => 65,
20 => 68,
21 => 71,
22 => 75,
23 => 78,
24 => 81,
25 => 85,
26 => 88,
27 => 91,
28 => 95,
29 => 98,
30 => 101,
31 => 104,
32 => 108,
33 => 111,
34 => 114,
35 => 118,
36 => 121,
37 => 124,
38 => 128,
39 => 131,
40 => 134);
function Mantissa return Uint is
begin
return
UI_From_Int (Mantissa_Value (UI_To_Int (Digits_Value (P_Type))));
end Mantissa;
----------------
-- Set_Bounds --
----------------
procedure Set_Bounds is
Ndim : Nat;
Indx : Node_Id;
Ityp : Entity_Id;
begin
-- For a string literal subtype, we have to construct the bounds.
-- Valid Ada code never applies attributes to string literals, but
-- it is convenient to allow the expander to generate attribute
-- references of this type (e.g. First and Last applied to a string
-- literal).
-- Note that the whole point of the E_String_Literal_Subtype is to
-- avoid this construction of bounds, but the cases in which we
-- have to materialize them are rare enough that we don't worry!
-- The low bound is simply the low bound of the base type. The
-- high bound is computed from the length of the string and this
-- low bound.
if Ekind (P_Type) = E_String_Literal_Subtype then
Ityp := Etype (First_Index (Base_Type (P_Type)));
Lo_Bound := Type_Low_Bound (Ityp);
Hi_Bound :=
Make_Integer_Literal (Sloc (P),
Intval =>
Expr_Value (Lo_Bound) + String_Literal_Length (P_Type) - 1);
Set_Parent (Hi_Bound, P);
Analyze_And_Resolve (Hi_Bound, Etype (Lo_Bound));
return;
-- For non-array case, just get bounds of scalar type
elsif Is_Scalar_Type (P_Type) then
Ityp := P_Type;
-- For a fixed-point type, we must freeze to get the attributes
-- of the fixed-point type set now so we can reference them.
if Is_Fixed_Point_Type (P_Type)
and then not Is_Frozen (Base_Type (P_Type))
and then Compile_Time_Known_Value (Type_Low_Bound (P_Type))
and then Compile_Time_Known_Value (Type_High_Bound (P_Type))
then
Freeze_Fixed_Point_Type (Base_Type (P_Type));
end if;
-- For array case, get type of proper index
else
if No (E1) then
Ndim := 1;
else
Ndim := UI_To_Int (Expr_Value (E1));
end if;
Indx := First_Index (P_Type);
for J in 1 .. Ndim - 1 loop
Next_Index (Indx);
end loop;
-- If no index type, get out (some other error occurred, and
-- we don't have enough information to complete the job!)
if No (Indx) then
Lo_Bound := Error;
Hi_Bound := Error;
return;
end if;
Ityp := Etype (Indx);
end if;
-- A discrete range in an index constraint is allowed to be a
-- subtype indication. This is syntactically a pain, but should
-- not propagate to the entity for the corresponding index subtype.
-- After checking that the subtype indication is legal, the range
-- of the subtype indication should be transfered to the entity.
-- The attributes for the bounds should remain the simple retrievals
-- that they are now.
Lo_Bound := Type_Low_Bound (Ityp);
Hi_Bound := Type_High_Bound (Ityp);
if not Is_Static_Subtype (Ityp) then
Static := False;
end if;
end Set_Bounds;
-------------------------------
-- Statically_Denotes_Entity --
-------------------------------
function Statically_Denotes_Entity (N : Node_Id) return Boolean is
E : Entity_Id;
begin
if not Is_Entity_Name (N) then
return False;
else
E := Entity (N);
end if;
return
Nkind (Parent (E)) /= N_Object_Renaming_Declaration
or else Statically_Denotes_Entity (Renamed_Object (E));
end Statically_Denotes_Entity;
-- Start of processing for Eval_Attribute
begin
-- Acquire first two expressions (at the moment, no attributes
-- take more than two expressions in any case).
if Present (Expressions (N)) then
E1 := First (Expressions (N));
E2 := Next (E1);
else
E1 := Empty;
E2 := Empty;
end if;
-- Special processing for cases where the prefix is an object. For
-- this purpose, a string literal counts as an object (attributes
-- of string literals can only appear in generated code).
if Is_Object_Reference (P) or else Nkind (P) = N_String_Literal then
-- For Component_Size, the prefix is an array object, and we apply
-- the attribute to the type of the object. This is allowed for
-- both unconstrained and constrained arrays, since the bounds
-- have no influence on the value of this attribute.
if Id = Attribute_Component_Size then
P_Entity := Etype (P);
-- For First and Last, the prefix is an array object, and we apply
-- the attribute to the type of the array, but we need a constrained
-- type for this, so we use the actual subtype if available.
elsif Id = Attribute_First
or else
Id = Attribute_Last
or else
Id = Attribute_Length
then
declare
AS : constant Entity_Id := Get_Actual_Subtype_If_Available (P);
begin
if Present (AS) and then Is_Constrained (AS) then
P_Entity := AS;
-- If we have an unconstrained type, cannot fold
else
Check_Expressions;
return;
end if;
end;
-- For Size, give size of object if available, otherwise we
-- cannot fold Size.
elsif Id = Attribute_Size then
if Is_Entity_Name (P)
and then Known_Esize (Entity (P))
then
Compile_Time_Known_Attribute (N, Esize (Entity (P)));
return;
else
Check_Expressions;
return;
end if;
-- For Alignment, give size of object if available, otherwise we
-- cannot fold Alignment.
elsif Id = Attribute_Alignment then
if Is_Entity_Name (P)
and then Known_Alignment (Entity (P))
then
Fold_Uint (N, Alignment (Entity (P)), False);
return;
else
Check_Expressions;
return;
end if;
-- No other attributes for objects are folded
else
Check_Expressions;
return;
end if;
-- Cases where P is not an object. Cannot do anything if P is
-- not the name of an entity.
elsif not Is_Entity_Name (P) then
Check_Expressions;
return;
-- Otherwise get prefix entity
else
P_Entity := Entity (P);
end if;
-- At this stage P_Entity is the entity to which the attribute
-- is to be applied. This is usually simply the entity of the
-- prefix, except in some cases of attributes for objects, where
-- as described above, we apply the attribute to the object type.
-- First foldable possibility is a scalar or array type (RM 4.9(7))
-- that is not generic (generic types are eliminated by RM 4.9(25)).
-- Note we allow non-static non-generic types at this stage as further
-- described below.
if Is_Type (P_Entity)
and then (Is_Scalar_Type (P_Entity) or Is_Array_Type (P_Entity))
and then (not Is_Generic_Type (P_Entity))
then
P_Type := P_Entity;
-- Second foldable possibility is an array object (RM 4.9(8))
elsif (Ekind (P_Entity) = E_Variable
or else
Ekind (P_Entity) = E_Constant)
and then Is_Array_Type (Etype (P_Entity))
and then (not Is_Generic_Type (Etype (P_Entity)))
then
P_Type := Etype (P_Entity);
-- If the entity is an array constant with an unconstrained nominal
-- subtype then get the type from the initial value. If the value has
-- been expanded into assignments, there is no expression and the
-- attribute reference remains dynamic.
-- We could do better here and retrieve the type ???
if Ekind (P_Entity) = E_Constant
and then not Is_Constrained (P_Type)
then
if No (Constant_Value (P_Entity)) then
return;
else
P_Type := Etype (Constant_Value (P_Entity));
end if;
end if;
-- Definite must be folded if the prefix is not a generic type,
-- that is to say if we are within an instantiation. Same processing
-- applies to the GNAT attributes Has_Discriminants, Type_Class,
-- and Unconstrained_Array.
elsif (Id = Attribute_Definite
or else
Id = Attribute_Has_Access_Values
or else
Id = Attribute_Has_Discriminants
or else
Id = Attribute_Type_Class
or else
Id = Attribute_Unconstrained_Array)
and then not Is_Generic_Type (P_Entity)
then
P_Type := P_Entity;
-- We can fold 'Size applied to a type if the size is known
-- (as happens for a size from an attribute definition clause).
-- At this stage, this can happen only for types (e.g. record
-- types) for which the size is always non-static. We exclude
-- generic types from consideration (since they have bogus
-- sizes set within templates).
elsif Id = Attribute_Size
and then Is_Type (P_Entity)
and then (not Is_Generic_Type (P_Entity))
and then Known_Static_RM_Size (P_Entity)
then
Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
return;
-- We can fold 'Alignment applied to a type if the alignment is known
-- (as happens for an alignment from an attribute definition clause).
-- At this stage, this can happen only for types (e.g. record
-- types) for which the size is always non-static. We exclude
-- generic types from consideration (since they have bogus
-- sizes set within templates).
elsif Id = Attribute_Alignment
and then Is_Type (P_Entity)
and then (not Is_Generic_Type (P_Entity))
and then Known_Alignment (P_Entity)
then
Compile_Time_Known_Attribute (N, Alignment (P_Entity));
return;
-- If this is an access attribute that is known to fail accessibility
-- check, rewrite accordingly.
elsif Attribute_Name (N) = Name_Access
and then Raises_Constraint_Error (N)
then
Rewrite (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Accessibility_Check_Failed));
Set_Etype (N, C_Type);
return;
-- No other cases are foldable (they certainly aren't static, and at
-- the moment we don't try to fold any cases other than these three).
else
Check_Expressions;
return;
end if;
-- If either attribute or the prefix is Any_Type, then propagate
-- Any_Type to the result and don't do anything else at all.
if P_Type = Any_Type
or else (Present (E1) and then Etype (E1) = Any_Type)
or else (Present (E2) and then Etype (E2) = Any_Type)
then
Set_Etype (N, Any_Type);
return;
end if;
-- Scalar subtype case. We have not yet enforced the static requirement
-- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
-- of non-static attribute references (e.g. S'Digits for a non-static
-- floating-point type, which we can compute at compile time).
-- Note: this folding of non-static attributes is not simply a case of
-- optimization. For many of the attributes affected, Gigi cannot handle
-- the attribute and depends on the front end having folded them away.
-- Note: although we don't require staticness at this stage, we do set
-- the Static variable to record the staticness, for easy reference by
-- those attributes where it matters (e.g. Succ and Pred), and also to
-- be used to ensure that non-static folded things are not marked as
-- being static (a check that is done right at the end).
P_Root_Type := Root_Type (P_Type);
P_Base_Type := Base_Type (P_Type);
-- If the root type or base type is generic, then we cannot fold. This
-- test is needed because subtypes of generic types are not always
-- marked as being generic themselves (which seems odd???)
if Is_Generic_Type (P_Root_Type)
or else Is_Generic_Type (P_Base_Type)
then
return;
end if;
if Is_Scalar_Type (P_Type) then
Static := Is_OK_Static_Subtype (P_Type);
-- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
-- since we can't do anything with unconstrained arrays. In addition,
-- only the First, Last and Length attributes are possibly static.
-- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
-- Unconstrained_Array are again exceptions, because they apply as
-- well to unconstrained types.
-- In addition Component_Size is an exception since it is possibly
-- foldable, even though it is never static, and it does apply to
-- unconstrained arrays. Furthermore, it is essential to fold this
-- in the packed case, since otherwise the value will be incorrect.
elsif Id = Attribute_Definite
or else
Id = Attribute_Has_Access_Values
or else
Id = Attribute_Has_Discriminants
or else
Id = Attribute_Type_Class
or else
Id = Attribute_Unconstrained_Array
or else
Id = Attribute_Component_Size
then
Static := False;
else
if not Is_Constrained (P_Type)
or else (Id /= Attribute_First and then
Id /= Attribute_Last and then
Id /= Attribute_Length)
then
Check_Expressions;
return;
end if;
-- The rules in (RM 4.9(7,8)) require a static array, but as in the
-- scalar case, we hold off on enforcing staticness, since there are
-- cases which we can fold at compile time even though they are not
-- static (e.g. 'Length applied to a static index, even though other
-- non-static indexes make the array type non-static). This is only
-- an optimization, but it falls out essentially free, so why not.
-- Again we compute the variable Static for easy reference later
-- (note that no array attributes are static in Ada 83).
Static := Ada_Version >= Ada_95
and then Statically_Denotes_Entity (P);
declare
N : Node_Id;
begin
N := First_Index (P_Type);
while Present (N) loop
Static := Static and then Is_Static_Subtype (Etype (N));
-- If however the index type is generic, attributes cannot
-- be folded.
if Is_Generic_Type (Etype (N))
and then Id /= Attribute_Component_Size
then
return;
end if;
Next_Index (N);
end loop;
end;
end if;
-- Check any expressions that are present. Note that these expressions,
-- depending on the particular attribute type, are either part of the
-- attribute designator, or they are arguments in a case where the
-- attribute reference returns a function. In the latter case, the
-- rule in (RM 4.9(22)) applies and in particular requires the type
-- of the expressions to be scalar in order for the attribute to be
-- considered to be static.
declare
E : Node_Id;
begin
E := E1;
while Present (E) loop
-- If expression is not static, then the attribute reference
-- result certainly cannot be static.
if not Is_Static_Expression (E) then
Static := False;
end if;
-- If the result is not known at compile time, or is not of
-- a scalar type, then the result is definitely not static,
-- so we can quit now.
if not Compile_Time_Known_Value (E)
or else not Is_Scalar_Type (Etype (E))
then
-- An odd special case, if this is a Pos attribute, this
-- is where we need to apply a range check since it does
-- not get done anywhere else.
if Id = Attribute_Pos then
if Is_Integer_Type (Etype (E)) then
Apply_Range_Check (E, Etype (N));
end if;
end if;
Check_Expressions;
return;
-- If the expression raises a constraint error, then so does
-- the attribute reference. We keep going in this case because
-- we are still interested in whether the attribute reference
-- is static even if it is not static.
elsif Raises_Constraint_Error (E) then
Set_Raises_Constraint_Error (N);
end if;
Next (E);
end loop;
if Raises_Constraint_Error (Prefix (N)) then
return;
end if;
end;
-- Deal with the case of a static attribute reference that raises
-- constraint error. The Raises_Constraint_Error flag will already
-- have been set, and the Static flag shows whether the attribute
-- reference is static. In any case we certainly can't fold such an
-- attribute reference.
-- Note that the rewriting of the attribute node with the constraint
-- error node is essential in this case, because otherwise Gigi might
-- blow up on one of the attributes it never expects to see.
-- The constraint_error node must have the type imposed by the context,
-- to avoid spurious errors in the enclosing expression.
if Raises_Constraint_Error (N) then
CE_Node :=
Make_Raise_Constraint_Error (Sloc (N),
Reason => CE_Range_Check_Failed);
Set_Etype (CE_Node, Etype (N));
Set_Raises_Constraint_Error (CE_Node);
Check_Expressions;
Rewrite (N, Relocate_Node (CE_Node));
Set_Is_Static_Expression (N, Static);
return;
end if;
-- At this point we have a potentially foldable attribute reference.
-- If Static is set, then the attribute reference definitely obeys
-- the requirements in (RM 4.9(7,8,22)), and it definitely can be
-- folded. If Static is not set, then the attribute may or may not
-- be foldable, and the individual attribute processing routines
-- test Static as required in cases where it makes a difference.
-- In the case where Static is not set, we do know that all the
-- expressions present are at least known at compile time (we
-- assumed above that if this was not the case, then there was
-- no hope of static evaluation). However, we did not require
-- that the bounds of the prefix type be compile time known,
-- let alone static). That's because there are many attributes
-- that can be computed at compile time on non-static subtypes,
-- even though such references are not static expressions.
case Id is
--------------
-- Adjacent --
--------------
when Attribute_Adjacent =>
Fold_Ureal (N,
Eval_Fat.Adjacent
(P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
---------
-- Aft --
---------
when Attribute_Aft =>
Fold_Uint (N, UI_From_Int (Aft_Value), True);
---------------
-- Alignment --
---------------
when Attribute_Alignment => Alignment_Block : declare
P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
begin
-- Fold if alignment is set and not otherwise
if Known_Alignment (P_TypeA) then
Fold_Uint (N, Alignment (P_TypeA), Is_Discrete_Type (P_TypeA));
end if;
end Alignment_Block;
---------------
-- AST_Entry --
---------------
-- Can only be folded in No_Ast_Handler case
when Attribute_AST_Entry =>
if not Is_AST_Entry (P_Entity) then
Rewrite (N,
New_Occurrence_Of (RTE (RE_No_AST_Handler), Loc));
else
null;
end if;
---------
-- Bit --
---------
-- Bit can never be folded
when Attribute_Bit =>
null;
------------------
-- Body_Version --
------------------
-- Body_version can never be static
when Attribute_Body_Version =>
null;
-------------
-- Ceiling --
-------------
when Attribute_Ceiling =>
Fold_Ureal (N,
Eval_Fat.Ceiling (P_Root_Type, Expr_Value_R (E1)), Static);
--------------------
-- Component_Size --
--------------------
when Attribute_Component_Size =>
if Known_Static_Component_Size (P_Type) then
Fold_Uint (N, Component_Size (P_Type), False);
end if;
-------------
-- Compose --
-------------
when Attribute_Compose =>
Fold_Ureal (N,
Eval_Fat.Compose
(P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)),
Static);
-----------------
-- Constrained --
-----------------
-- Constrained is never folded for now, there may be cases that
-- could be handled at compile time. to be looked at later.
when Attribute_Constrained =>
null;
---------------
-- Copy_Sign --
---------------
when Attribute_Copy_Sign =>
Fold_Ureal (N,
Eval_Fat.Copy_Sign
(P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
-----------
-- Delta --
-----------
when Attribute_Delta =>
Fold_Ureal (N, Delta_Value (P_Type), True);
--------------
-- Definite --
--------------
when Attribute_Definite =>
Rewrite (N, New_Occurrence_Of (
Boolean_Literals (not Is_Indefinite_Subtype (P_Entity)), Loc));
Analyze_And_Resolve (N, Standard_Boolean);
------------
-- Denorm --
------------
when Attribute_Denorm =>
Fold_Uint
(N, UI_From_Int (Boolean'Pos (Denorm_On_Target)), True);
------------
-- Digits --
------------
when Attribute_Digits =>
Fold_Uint (N, Digits_Value (P_Type), True);
----------
-- Emax --
----------
when Attribute_Emax =>
-- Ada 83 attribute is defined as (RM83 3.5.8)
-- T'Emax = 4 * T'Mantissa
Fold_Uint (N, 4 * Mantissa, True);
--------------
-- Enum_Rep --
--------------
when Attribute_Enum_Rep =>
-- For an enumeration type with a non-standard representation use
-- the Enumeration_Rep field of the proper constant. Note that this
-- will not work for types Character/Wide_[Wide-]Character, since no
-- real entities are created for the enumeration literals, but that
-- does not matter since these two types do not have non-standard
-- representations anyway.
if Is_Enumeration_Type (P_Type)
and then Has_Non_Standard_Rep (P_Type)
then
Fold_Uint (N, Enumeration_Rep (Expr_Value_E (E1)), Static);
-- For enumeration types with standard representations and all
-- other cases (i.e. all integer and modular types), Enum_Rep
-- is equivalent to Pos.
else
Fold_Uint (N, Expr_Value (E1), Static);
end if;
-------------
-- Epsilon --
-------------
when Attribute_Epsilon =>
-- Ada 83 attribute is defined as (RM83 3.5.8)
-- T'Epsilon = 2.0**(1 - T'Mantissa)
Fold_Ureal (N, Ureal_2 ** (1 - Mantissa), True);
--------------
-- Exponent --
--------------
when Attribute_Exponent =>
Fold_Uint (N,
Eval_Fat.Exponent (P_Root_Type, Expr_Value_R (E1)), Static);
-----------
-- First --
-----------
when Attribute_First => First_Attr :
begin
Set_Bounds;
if Compile_Time_Known_Value (Lo_Bound) then
if Is_Real_Type (P_Type) then
Fold_Ureal (N, Expr_Value_R (Lo_Bound), Static);
else
Fold_Uint (N, Expr_Value (Lo_Bound), Static);
end if;
end if;
end First_Attr;
-----------------
-- Fixed_Value --
-----------------
when Attribute_Fixed_Value =>
null;
-----------
-- Floor --
-----------
when Attribute_Floor =>
Fold_Ureal (N,
Eval_Fat.Floor (P_Root_Type, Expr_Value_R (E1)), Static);
----------
-- Fore --
----------
when Attribute_Fore =>
if Compile_Time_Known_Bounds (P_Type) then
Fold_Uint (N, UI_From_Int (Fore_Value), Static);
end if;
--------------
-- Fraction --
--------------
when Attribute_Fraction =>
Fold_Ureal (N,
Eval_Fat.Fraction (P_Root_Type, Expr_Value_R (E1)), Static);
-----------------------
-- Has_Access_Values --
-----------------------
when Attribute_Has_Access_Values =>
Rewrite (N, New_Occurrence_Of
(Boolean_Literals (Has_Access_Values (P_Root_Type)), Loc));
Analyze_And_Resolve (N, Standard_Boolean);
-----------------------
-- Has_Discriminants --
-----------------------
when Attribute_Has_Discriminants =>
Rewrite (N, New_Occurrence_Of (
Boolean_Literals (Has_Discriminants (P_Entity)), Loc));
Analyze_And_Resolve (N, Standard_Boolean);
--------------
-- Identity --
--------------
when Attribute_Identity =>
null;
-----------
-- Image --
-----------
-- Image is a scalar attribute, but is never static, because it is
-- not a static function (having a non-scalar argument (RM 4.9(22))
when Attribute_Image =>
null;
---------
-- Img --
---------
-- Img is a scalar attribute, but is never static, because it is
-- not a static function (having a non-scalar argument (RM 4.9(22))
when Attribute_Img =>
null;
-------------------
-- Integer_Value --
-------------------
when Attribute_Integer_Value =>
null;
-----------
-- Large --
-----------
when Attribute_Large =>
-- For fixed-point, we use the identity:
-- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
if Is_Fixed_Point_Type (P_Type) then
Rewrite (N,
Make_Op_Multiply (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Op_Expon (Loc,
Left_Opnd =>
Make_Real_Literal (Loc, Ureal_2),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => P,
Attribute_Name => Name_Mantissa)),
Right_Opnd => Make_Real_Literal (Loc, Ureal_1)),
Right_Opnd =>
Make_Real_Literal (Loc, Small_Value (Entity (P)))));
Analyze_And_Resolve (N, C_Type);
-- Floating-point (Ada 83 compatibility)
else
-- Ada 83 attribute is defined as (RM83 3.5.8)
-- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
-- where
-- T'Emax = 4 * T'Mantissa
Fold_Ureal (N,
Ureal_2 ** (4 * Mantissa) * (Ureal_1 - Ureal_2 ** (-Mantissa)),
True);
end if;
----------
-- Last --
----------
when Attribute_Last => Last :
begin
Set_Bounds;
if Compile_Time_Known_Value (Hi_Bound) then
if Is_Real_Type (P_Type) then
Fold_Ureal (N, Expr_Value_R (Hi_Bound), Static);
else
Fold_Uint (N, Expr_Value (Hi_Bound), Static);
end if;
end if;
end Last;
------------------
-- Leading_Part --
------------------
when Attribute_Leading_Part =>
Fold_Ureal (N,
Eval_Fat.Leading_Part
(P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
------------
-- Length --
------------
when Attribute_Length => Length : declare
Ind : Node_Id;
begin
-- In the case of a generic index type, the bounds may
-- appear static but the computation is not meaningful,
-- and may generate a spurious warning.
Ind := First_Index (P_Type);
while Present (Ind) loop
if Is_Generic_Type (Etype (Ind)) then
return;
end if;
Next_Index (Ind);
end loop;
Set_Bounds;
if Compile_Time_Known_Value (Lo_Bound)
and then Compile_Time_Known_Value (Hi_Bound)
then
Fold_Uint (N,
UI_Max (0, 1 + (Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound))),
True);
end if;
end Length;
-------------
-- Machine --
-------------
when Attribute_Machine =>
Fold_Ureal (N,
Eval_Fat.Machine
(P_Root_Type, Expr_Value_R (E1), Eval_Fat.Round, N),
Static);
------------------
-- Machine_Emax --
------------------
when Attribute_Machine_Emax =>
Float_Attribute_Universal_Integer (
IEEES_Machine_Emax,
IEEEL_Machine_Emax,
IEEEX_Machine_Emax,
VAXFF_Machine_Emax,
VAXDF_Machine_Emax,
VAXGF_Machine_Emax,
AAMPS_Machine_Emax,
AAMPL_Machine_Emax);
------------------
-- Machine_Emin --
------------------
when Attribute_Machine_Emin =>
Float_Attribute_Universal_Integer (
IEEES_Machine_Emin,
IEEEL_Machine_Emin,
IEEEX_Machine_Emin,
VAXFF_Machine_Emin,
VAXDF_Machine_Emin,
VAXGF_Machine_Emin,
AAMPS_Machine_Emin,
AAMPL_Machine_Emin);
----------------------
-- Machine_Mantissa --
----------------------
when Attribute_Machine_Mantissa =>
Float_Attribute_Universal_Integer (
IEEES_Machine_Mantissa,
IEEEL_Machine_Mantissa,
IEEEX_Machine_Mantissa,
VAXFF_Machine_Mantissa,
VAXDF_Machine_Mantissa,
VAXGF_Machine_Mantissa,
AAMPS_Machine_Mantissa,
AAMPL_Machine_Mantissa);
-----------------------
-- Machine_Overflows --
-----------------------
when Attribute_Machine_Overflows =>
-- Always true for fixed-point
if Is_Fixed_Point_Type (P_Type) then
Fold_Uint (N, True_Value, True);
-- Floating point case
else
Fold_Uint (N,
UI_From_Int (Boolean'Pos (Machine_Overflows_On_Target)),
True);
end if;
-------------------
-- Machine_Radix --
-------------------
when Attribute_Machine_Radix =>
if Is_Fixed_Point_Type (P_Type) then
if Is_Decimal_Fixed_Point_Type (P_Type)
and then Machine_Radix_10 (P_Type)
then
Fold_Uint (N, Uint_10, True);
else
Fold_Uint (N, Uint_2, True);
end if;
-- All floating-point type always have radix 2
else
Fold_Uint (N, Uint_2, True);
end if;
----------------------
-- Machine_Rounding --
----------------------
-- Note: for the folding case, it is fine to treat Machine_Rounding
-- exactly the same way as Rounding, since this is one of the allowed
-- behaviors, and performance is not an issue here. It might be a bit
-- better to give the same result as it would give at run-time, even
-- though the non-determinism is certainly permitted.
when Attribute_Machine_Rounding =>
Fold_Ureal (N,
Eval_Fat.Rounding (P_Root_Type, Expr_Value_R (E1)), Static);
--------------------
-- Machine_Rounds --
--------------------
when Attribute_Machine_Rounds =>
-- Always False for fixed-point
if Is_Fixed_Point_Type (P_Type) then
Fold_Uint (N, False_Value, True);
-- Else yield proper floating-point result
else
Fold_Uint
(N, UI_From_Int (Boolean'Pos (Machine_Rounds_On_Target)), True);
end if;
------------------
-- Machine_Size --
------------------
-- Note: Machine_Size is identical to Object_Size
when Attribute_Machine_Size => Machine_Size : declare
P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
begin
if Known_Esize (P_TypeA) then
Fold_Uint (N, Esize (P_TypeA), True);
end if;
end Machine_Size;
--------------
-- Mantissa --
--------------
when Attribute_Mantissa =>
-- Fixed-point mantissa
if Is_Fixed_Point_Type (P_Type) then
-- Compile time foldable case
if Compile_Time_Known_Value (Type_Low_Bound (P_Type))
and then
Compile_Time_Known_Value (Type_High_Bound (P_Type))
then
-- The calculation of the obsolete Ada 83 attribute Mantissa
-- is annoying, because of AI00143, quoted here:
-- !question 84-01-10
-- Consider the model numbers for F:
-- type F is delta 1.0 range -7.0 .. 8.0;
-- The wording requires that F'MANTISSA be the SMALLEST
-- integer number for which each bound of the specified
-- range is either a model number or lies at most small
-- distant from a model number. This means F'MANTISSA
-- is required to be 3 since the range -7.0 .. 7.0 fits
-- in 3 signed bits, and 8 is "at most" 1.0 from a model
-- number, namely, 7. Is this analysis correct? Note that
-- this implies the upper bound of the range is not
-- represented as a model number.
-- !response 84-03-17
-- The analysis is correct. The upper and lower bounds for
-- a fixed point type can lie outside the range of model
-- numbers.
declare
Siz : Uint;
LBound : Ureal;
UBound : Ureal;
Bound : Ureal;
Max_Man : Uint;
begin
LBound := Expr_Value_R (Type_Low_Bound (P_Type));
UBound := Expr_Value_R (Type_High_Bound (P_Type));
Bound := UR_Max (UR_Abs (LBound), UR_Abs (UBound));
Max_Man := UR_Trunc (Bound / Small_Value (P_Type));
-- If the Bound is exactly a model number, i.e. a multiple
-- of Small, then we back it off by one to get the integer
-- value that must be representable.
if Small_Value (P_Type) * Max_Man = Bound then
Max_Man := Max_Man - 1;
end if;
-- Now find corresponding size = Mantissa value
Siz := Uint_0;
while 2 ** Siz < Max_Man loop
Siz := Siz + 1;
end loop;
Fold_Uint (N, Siz, True);
end;
else
-- The case of dynamic bounds cannot be evaluated at compile
-- time. Instead we use a runtime routine (see Exp_Attr).
null;
end if;
-- Floating-point Mantissa
else
Fold_Uint (N, Mantissa, True);
end if;
---------
-- Max --
---------
when Attribute_Max => Max :
begin
if Is_Real_Type (P_Type) then
Fold_Ureal
(N, UR_Max (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
else
Fold_Uint (N, UI_Max (Expr_Value (E1), Expr_Value (E2)), Static);
end if;
end Max;
----------------------------------
-- Max_Size_In_Storage_Elements --
----------------------------------
-- Max_Size_In_Storage_Elements is simply the Size rounded up to a
-- Storage_Unit boundary. We can fold any cases for which the size
-- is known by the front end.
when Attribute_Max_Size_In_Storage_Elements =>
if Known_Esize (P_Type) then
Fold_Uint (N,
(Esize (P_Type) + System_Storage_Unit - 1) /
System_Storage_Unit,
Static);
end if;
--------------------
-- Mechanism_Code --
--------------------
when Attribute_Mechanism_Code =>
declare
Val : Int;
Formal : Entity_Id;
Mech : Mechanism_Type;
begin
if No (E1) then
Mech := Mechanism (P_Entity);
else
Val := UI_To_Int (Expr_Value (E1));
Formal := First_Formal (P_Entity);
for J in 1 .. Val - 1 loop
Next_Formal (Formal);
end loop;
Mech := Mechanism (Formal);
end if;
if Mech < 0 then
Fold_Uint (N, UI_From_Int (Int (-Mech)), True);
end if;
end;
---------
-- Min --
---------
when Attribute_Min => Min :
begin
if Is_Real_Type (P_Type) then
Fold_Ureal
(N, UR_Min (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
else
Fold_Uint
(N, UI_Min (Expr_Value (E1), Expr_Value (E2)), Static);
end if;
end Min;
---------
-- Mod --
---------
when Attribute_Mod =>
Fold_Uint
(N, UI_Mod (Expr_Value (E1), Modulus (P_Base_Type)), Static);
-----------
-- Model --
-----------
when Attribute_Model =>
Fold_Ureal (N,
Eval_Fat.Model (P_Root_Type, Expr_Value_R (E1)), Static);
----------------
-- Model_Emin --
----------------
when Attribute_Model_Emin =>
Float_Attribute_Universal_Integer (
IEEES_Model_Emin,
IEEEL_Model_Emin,
IEEEX_Model_Emin,
VAXFF_Model_Emin,
VAXDF_Model_Emin,
VAXGF_Model_Emin,
AAMPS_Model_Emin,
AAMPL_Model_Emin);
-------------------
-- Model_Epsilon --
-------------------
when Attribute_Model_Epsilon =>
Float_Attribute_Universal_Real (
IEEES_Model_Epsilon'Universal_Literal_String,
IEEEL_Model_Epsilon'Universal_Literal_String,
IEEEX_Model_Epsilon'Universal_Literal_String,
VAXFF_Model_Epsilon'Universal_Literal_String,
VAXDF_Model_Epsilon'Universal_Literal_String,
VAXGF_Model_Epsilon'Universal_Literal_String,
AAMPS_Model_Epsilon'Universal_Literal_String,
AAMPL_Model_Epsilon'Universal_Literal_String);
--------------------
-- Model_Mantissa --
--------------------
when Attribute_Model_Mantissa =>
Float_Attribute_Universal_Integer (
IEEES_Model_Mantissa,
IEEEL_Model_Mantissa,
IEEEX_Model_Mantissa,
VAXFF_Model_Mantissa,
VAXDF_Model_Mantissa,
VAXGF_Model_Mantissa,
AAMPS_Model_Mantissa,
AAMPL_Model_Mantissa);
-----------------
-- Model_Small --
-----------------
when Attribute_Model_Small =>
Float_Attribute_Universal_Real (
IEEES_Model_Small'Universal_Literal_String,
IEEEL_Model_Small'Universal_Literal_String,
IEEEX_Model_Small'Universal_Literal_String,
VAXFF_Model_Small'Universal_Literal_String,
VAXDF_Model_Small'Universal_Literal_String,
VAXGF_Model_Small'Universal_Literal_String,
AAMPS_Model_Small'Universal_Literal_String,
AAMPL_Model_Small'Universal_Literal_String);
-------------
-- Modulus --
-------------
when Attribute_Modulus =>
Fold_Uint (N, Modulus (P_Type), True);
--------------------
-- Null_Parameter --
--------------------
-- Cannot fold, we know the value sort of, but the whole point is
-- that there is no way to talk about this imaginary value except
-- by using the attribute, so we leave it the way it is.
when Attribute_Null_Parameter =>
null;
-----------------
-- Object_Size --
-----------------
-- The Object_Size attribute for a type returns the Esize of the
-- type and can be folded if this value is known.
when Attribute_Object_Size => Object_Size : declare
P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
begin
if Known_Esize (P_TypeA) then
Fold_Uint (N, Esize (P_TypeA), True);
end if;
end Object_Size;
-------------------------
-- Passed_By_Reference --
-------------------------
-- Scalar types are never passed by reference
when Attribute_Passed_By_Reference =>
Fold_Uint (N, False_Value, True);
---------
-- Pos --
---------
when Attribute_Pos =>
Fold_Uint (N, Expr_Value (E1), True);
----------
-- Pred --
----------
when Attribute_Pred => Pred :
begin
-- Floating-point case
if Is_Floating_Point_Type (P_Type) then
Fold_Ureal (N,
Eval_Fat.Pred (P_Root_Type, Expr_Value_R (E1)), Static);
-- Fixed-point case
elsif Is_Fixed_Point_Type (P_Type) then
Fold_Ureal (N,
Expr_Value_R (E1) - Small_Value (P_Type), True);
-- Modular integer case (wraps)
elsif Is_Modular_Integer_Type (P_Type) then
Fold_Uint (N, (Expr_Value (E1) - 1) mod Modulus (P_Type), Static);
-- Other scalar cases
else
pragma Assert (Is_Scalar_Type (P_Type));
if Is_Enumeration_Type (P_Type)
and then Expr_Value (E1) =
Expr_Value (Type_Low_Bound (P_Base_Type))
then
Apply_Compile_Time_Constraint_Error
(N, "Pred of `&''First`",
CE_Overflow_Check_Failed,
Ent => P_Base_Type,
Warn => not Static);
Check_Expressions;
return;
end if;
Fold_Uint (N, Expr_Value (E1) - 1, Static);
end if;
end Pred;
-----------
-- Range --
-----------
-- No processing required, because by this stage, Range has been
-- replaced by First .. Last, so this branch can never be taken.
when Attribute_Range =>
raise Program_Error;
------------------
-- Range_Length --
------------------
when Attribute_Range_Length =>
Set_Bounds;
if Compile_Time_Known_Value (Hi_Bound)
and then Compile_Time_Known_Value (Lo_Bound)
then
Fold_Uint (N,
UI_Max
(0, Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound) + 1),
Static);
end if;
---------------
-- Remainder --
---------------
when Attribute_Remainder => Remainder : declare
X : constant Ureal := Expr_Value_R (E1);
Y : constant Ureal := Expr_Value_R (E2);
begin
if UR_Is_Zero (Y) then
Apply_Compile_Time_Constraint_Error
(N, "division by zero in Remainder",
CE_Overflow_Check_Failed,
Warn => not Static);
Check_Expressions;
return;
end if;
Fold_Ureal (N, Eval_Fat.Remainder (P_Root_Type, X, Y), Static);
end Remainder;
-----------
-- Round --
-----------
when Attribute_Round => Round :
declare
Sr : Ureal;
Si : Uint;
begin
-- First we get the (exact result) in units of small
Sr := Expr_Value_R (E1) / Small_Value (C_Type);
-- Now round that exactly to an integer
Si := UR_To_Uint (Sr);
-- Finally the result is obtained by converting back to real
Fold_Ureal (N, Si * Small_Value (C_Type), Static);
end Round;
--------------
-- Rounding --
--------------
when Attribute_Rounding =>
Fold_Ureal (N,
Eval_Fat.Rounding (P_Root_Type, Expr_Value_R (E1)), Static);
---------------
-- Safe_Emax --
---------------
when Attribute_Safe_Emax =>
Float_Attribute_Universal_Integer (
IEEES_Safe_Emax,
IEEEL_Safe_Emax,
IEEEX_Safe_Emax,
VAXFF_Safe_Emax,
VAXDF_Safe_Emax,
VAXGF_Safe_Emax,
AAMPS_Safe_Emax,
AAMPL_Safe_Emax);
----------------
-- Safe_First --
----------------
when Attribute_Safe_First =>
Float_Attribute_Universal_Real (
IEEES_Safe_First'Universal_Literal_String,
IEEEL_Safe_First'Universal_Literal_String,
IEEEX_Safe_First'Universal_Literal_String,
VAXFF_Safe_First'Universal_Literal_String,
VAXDF_Safe_First'Universal_Literal_String,
VAXGF_Safe_First'Universal_Literal_String,
AAMPS_Safe_First'Universal_Literal_String,
AAMPL_Safe_First'Universal_Literal_String);
----------------
-- Safe_Large --
----------------
when Attribute_Safe_Large =>
if Is_Fixed_Point_Type (P_Type) then
Fold_Ureal
(N, Expr_Value_R (Type_High_Bound (P_Base_Type)), Static);
else
Float_Attribute_Universal_Real (
IEEES_Safe_Large'Universal_Literal_String,
IEEEL_Safe_Large'Universal_Literal_String,
IEEEX_Safe_Large'Universal_Literal_String,
VAXFF_Safe_Large'Universal_Literal_String,
VAXDF_Safe_Large'Universal_Literal_String,
VAXGF_Safe_Large'Universal_Literal_String,
AAMPS_Safe_Large'Universal_Literal_String,
AAMPL_Safe_Large'Universal_Literal_String);
end if;
---------------
-- Safe_Last --
---------------
when Attribute_Safe_Last =>
Float_Attribute_Universal_Real (
IEEES_Safe_Last'Universal_Literal_String,
IEEEL_Safe_Last'Universal_Literal_String,
IEEEX_Safe_Last'Universal_Literal_String,
VAXFF_Safe_Last'Universal_Literal_String,
VAXDF_Safe_Last'Universal_Literal_String,
VAXGF_Safe_Last'Universal_Literal_String,
AAMPS_Safe_Last'Universal_Literal_String,
AAMPL_Safe_Last'Universal_Literal_String);
----------------
-- Safe_Small --
----------------
when Attribute_Safe_Small =>
-- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
-- for fixed-point, since is the same as Small, but we implement
-- it for backwards compatibility.
if Is_Fixed_Point_Type (P_Type) then
Fold_Ureal (N, Small_Value (P_Type), Static);
-- Ada 83 Safe_Small for floating-point cases
else
Float_Attribute_Universal_Real (
IEEES_Safe_Small'Universal_Literal_String,
IEEEL_Safe_Small'Universal_Literal_String,
IEEEX_Safe_Small'Universal_Literal_String,
VAXFF_Safe_Small'Universal_Literal_String,
VAXDF_Safe_Small'Universal_Literal_String,
VAXGF_Safe_Small'Universal_Literal_String,
AAMPS_Safe_Small'Universal_Literal_String,
AAMPL_Safe_Small'Universal_Literal_String);
end if;
-----------
-- Scale --
-----------
when Attribute_Scale =>
Fold_Uint (N, Scale_Value (P_Type), True);
-------------
-- Scaling --
-------------
when Attribute_Scaling =>
Fold_Ureal (N,
Eval_Fat.Scaling
(P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
------------------
-- Signed_Zeros --
------------------
when Attribute_Signed_Zeros =>
Fold_Uint
(N, UI_From_Int (Boolean'Pos (Signed_Zeros_On_Target)), Static);
----------
-- Size --
----------
-- Size attribute returns the RM size. All scalar types can be folded,
-- as well as any types for which the size is known by the front end,
-- including any type for which a size attribute is specified.
when Attribute_Size | Attribute_VADS_Size => Size : declare
P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
begin
if RM_Size (P_TypeA) /= Uint_0 then
-- VADS_Size case
if Id = Attribute_VADS_Size or else Use_VADS_Size then
declare
S : constant Node_Id := Size_Clause (P_TypeA);
begin
-- If a size clause applies, then use the size from it.
-- This is one of the rare cases where we can use the
-- Size_Clause field for a subtype when Has_Size_Clause
-- is False. Consider:
-- type x is range 1 .. 64;
-- for x'size use 12;
-- subtype y is x range 0 .. 3;
-- Here y has a size clause inherited from x, but normally
-- it does not apply, and y'size is 2. However, y'VADS_Size
-- is indeed 12 and not 2.
if Present (S)
and then Is_OK_Static_Expression (Expression (S))
then
Fold_Uint (N, Expr_Value (Expression (S)), True);
-- If no size is specified, then we simply use the object
-- size in the VADS_Size case (e.g. Natural'Size is equal
-- to Integer'Size, not one less).
else
Fold_Uint (N, Esize (P_TypeA), True);
end if;
end;
-- Normal case (Size) in which case we want the RM_Size
else
Fold_Uint (N,
RM_Size (P_TypeA),
Static and then Is_Discrete_Type (P_TypeA));
end if;
end if;
end Size;
-----------
-- Small --
-----------
when Attribute_Small =>
-- The floating-point case is present only for Ada 83 compatability.
-- Note that strictly this is an illegal addition, since we are
-- extending an Ada 95 defined attribute, but we anticipate an
-- ARG ruling that will permit this.
if Is_Floating_Point_Type (P_Type) then
-- Ada 83 attribute is defined as (RM83 3.5.8)
-- T'Small = 2.0**(-T'Emax - 1)
-- where
-- T'Emax = 4 * T'Mantissa
Fold_Ureal (N, Ureal_2 ** ((-(4 * Mantissa)) - 1), Static);
-- Normal Ada 95 fixed-point case
else
Fold_Ureal (N, Small_Value (P_Type), True);
end if;
-----------------
-- Stream_Size --
-----------------
when Attribute_Stream_Size =>
null;
----------
-- Succ --
----------
when Attribute_Succ => Succ :
begin
-- Floating-point case
if Is_Floating_Point_Type (P_Type) then
Fold_Ureal (N,
Eval_Fat.Succ (P_Root_Type, Expr_Value_R (E1)), Static);
-- Fixed-point case
elsif Is_Fixed_Point_Type (P_Type) then
Fold_Ureal (N,
Expr_Value_R (E1) + Small_Value (P_Type), Static);
-- Modular integer case (wraps)
elsif Is_Modular_Integer_Type (P_Type) then
Fold_Uint (N, (Expr_Value (E1) + 1) mod Modulus (P_Type), Static);
-- Other scalar cases
else
pragma Assert (Is_Scalar_Type (P_Type));
if Is_Enumeration_Type (P_Type)
and then Expr_Value (E1) =
Expr_Value (Type_High_Bound (P_Base_Type))
then
Apply_Compile_Time_Constraint_Error
(N, "Succ of `&''Last`",
CE_Overflow_Check_Failed,
Ent => P_Base_Type,
Warn => not Static);
Check_Expressions;
return;
else
Fold_Uint (N, Expr_Value (E1) + 1, Static);
end if;
end if;
end Succ;
----------------
-- Truncation --
----------------
when Attribute_Truncation =>
Fold_Ureal (N,
Eval_Fat.Truncation (P_Root_Type, Expr_Value_R (E1)), Static);
----------------
-- Type_Class --
----------------
when Attribute_Type_Class => Type_Class : declare
Typ : constant Entity_Id := Underlying_Type (P_Base_Type);
Id : RE_Id;
begin
if Is_Descendent_Of_Address (Typ) then
Id := RE_Type_Class_Address;
elsif Is_Enumeration_Type (Typ) then
Id := RE_Type_Class_Enumeration;
elsif Is_Integer_Type (Typ) then
Id := RE_Type_Class_Integer;
elsif Is_Fixed_Point_Type (Typ) then
Id := RE_Type_Class_Fixed_Point;
elsif Is_Floating_Point_Type (Typ) then
Id := RE_Type_Class_Floating_Point;
elsif Is_Array_Type (Typ) then
Id := RE_Type_Class_Array;
elsif Is_Record_Type (Typ) then
Id := RE_Type_Class_Record;
elsif Is_Access_Type (Typ) then
Id := RE_Type_Class_Access;
elsif Is_Enumeration_Type (Typ) then
Id := RE_Type_Class_Enumeration;
elsif Is_Task_Type (Typ) then
Id := RE_Type_Class_Task;
-- We treat protected types like task types. It would make more
-- sense to have another enumeration value, but after all the
-- whole point of this feature is to be exactly DEC compatible,
-- and changing the type Type_Clas would not meet this requirement.
elsif Is_Protected_Type (Typ) then
Id := RE_Type_Class_Task;
-- Not clear if there are any other possibilities, but if there
-- are, then we will treat them as the address case.
else
Id := RE_Type_Class_Address;
end if;
Rewrite (N, New_Occurrence_Of (RTE (Id), Loc));
end Type_Class;
-----------------------
-- Unbiased_Rounding --
-----------------------
when Attribute_Unbiased_Rounding =>
Fold_Ureal (N,
Eval_Fat.Unbiased_Rounding (P_Root_Type, Expr_Value_R (E1)),
Static);
-------------------------
-- Unconstrained_Array --
-------------------------
when Attribute_Unconstrained_Array => Unconstrained_Array : declare
Typ : constant Entity_Id := Underlying_Type (P_Type);
begin
Rewrite (N, New_Occurrence_Of (
Boolean_Literals (
Is_Array_Type (P_Type)
and then not Is_Constrained (Typ)), Loc));
-- Analyze and resolve as boolean, note that this attribute is
-- a static attribute in GNAT.
Analyze_And_Resolve (N, Standard_Boolean);
Static := True;
end Unconstrained_Array;
---------------
-- VADS_Size --
---------------
-- Processing is shared with Size
---------
-- Val --
---------
when Attribute_Val => Val :
begin
if Expr_Value (E1) < Expr_Value (Type_Low_Bound (P_Base_Type))
or else
Expr_Value (E1) > Expr_Value (Type_High_Bound (P_Base_Type))
then
Apply_Compile_Time_Constraint_Error
(N, "Val expression out of range",
CE_Range_Check_Failed,
Warn => not Static);
Check_Expressions;
return;
else
Fold_Uint (N, Expr_Value (E1), Static);
end if;
end Val;
----------------
-- Value_Size --
----------------
-- The Value_Size attribute for a type returns the RM size of the
-- type. This an always be folded for scalar types, and can also
-- be folded for non-scalar types if the size is set.
when Attribute_Value_Size => Value_Size : declare
P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
begin
if RM_Size (P_TypeA) /= Uint_0 then
Fold_Uint (N, RM_Size (P_TypeA), True);
end if;
end Value_Size;
-------------
-- Version --
-------------
-- Version can never be static
when Attribute_Version =>
null;
----------------
-- Wide_Image --
----------------
-- Wide_Image is a scalar attribute, but is never static, because it
-- is not a static function (having a non-scalar argument (RM 4.9(22))
when Attribute_Wide_Image =>
null;
---------------------
-- Wide_Wide_Image --
---------------------
-- Wide_Wide_Image is a scalar attribute but is never static, because it
-- is not a static function (having a non-scalar argument (RM 4.9(22)).
when Attribute_Wide_Wide_Image =>
null;
---------------------
-- Wide_Wide_Width --
---------------------
-- Processing for Wide_Wide_Width is combined with Width
----------------
-- Wide_Width --
----------------
-- Processing for Wide_Width is combined with Width
-----------
-- Width --
-----------
-- This processing also handles the case of Wide_[Wide_]Width
when Attribute_Width |
Attribute_Wide_Width |
Attribute_Wide_Wide_Width => Width :
begin
if Compile_Time_Known_Bounds (P_Type) then
-- Floating-point types
if Is_Floating_Point_Type (P_Type) then
-- Width is zero for a null range (RM 3.5 (38))
if Expr_Value_R (Type_High_Bound (P_Type)) <
Expr_Value_R (Type_Low_Bound (P_Type))
then
Fold_Uint (N, Uint_0, True);
else
-- For floating-point, we have +N.dddE+nnn where length
-- of ddd is determined by type'Digits - 1, but is one
-- if Digits is one (RM 3.5 (33)).
-- nnn is set to 2 for Short_Float and Float (32 bit
-- floats), and 3 for Long_Float and Long_Long_Float.
-- For machines where Long_Long_Float is the IEEE
-- extended precision type, the exponent takes 4 digits.
declare
Len : Int :=
Int'Max (2, UI_To_Int (Digits_Value (P_Type)));
begin
if Esize (P_Type) <= 32 then
Len := Len + 6;
elsif Esize (P_Type) = 64 then
Len := Len + 7;
else
Len := Len + 8;
end if;
Fold_Uint (N, UI_From_Int (Len), True);
end;
end if;
-- Fixed-point types
elsif Is_Fixed_Point_Type (P_Type) then
-- Width is zero for a null range (RM 3.5 (38))
if Expr_Value (Type_High_Bound (P_Type)) <
Expr_Value (Type_Low_Bound (P_Type))
then
Fold_Uint (N, Uint_0, True);
-- The non-null case depends on the specific real type
else
-- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
Fold_Uint
(N, UI_From_Int (Fore_Value + 1 + Aft_Value), True);
end if;
-- Discrete types
else
declare
R : constant Entity_Id := Root_Type (P_Type);
Lo : constant Uint :=
Expr_Value (Type_Low_Bound (P_Type));
Hi : constant Uint :=
Expr_Value (Type_High_Bound (P_Type));
W : Nat;
Wt : Nat;
T : Uint;
L : Node_Id;
C : Character;
begin
-- Empty ranges
if Lo > Hi then
W := 0;
-- Width for types derived from Standard.Character
-- and Standard.Wide_[Wide_]Character.
elsif R = Standard_Character
or else R = Standard_Wide_Character
or else R = Standard_Wide_Wide_Character
then
W := 0;
-- Set W larger if needed
for J in UI_To_Int (Lo) .. UI_To_Int (Hi) loop
-- All wide characters look like Hex_hhhhhhhh
if J > 255 then
W := 12;
else
C := Character'Val (J);
-- Test for all cases where Character'Image
-- yields an image that is longer than three
-- characters. First the cases of Reserved_xxx
-- names (length = 12).
case C is
when Reserved_128 | Reserved_129 |
Reserved_132 | Reserved_153
=> Wt := 12;
when BS | HT | LF | VT | FF | CR |
SO | SI | EM | FS | GS | RS |
US | RI | MW | ST | PM
=> Wt := 2;
when NUL | SOH | STX | ETX | EOT |
ENQ | ACK | BEL | DLE | DC1 |
DC2 | DC3 | DC4 | NAK | SYN |
ETB | CAN | SUB | ESC | DEL |
BPH | NBH | NEL | SSA | ESA |
HTS | HTJ | VTS | PLD | PLU |
SS2 | SS3 | DCS | PU1 | PU2 |
STS | CCH | SPA | EPA | SOS |
SCI | CSI | OSC | APC
=> Wt := 3;
when Space .. Tilde |
No_Break_Space .. LC_Y_Diaeresis
=> Wt := 3;
end case;
W := Int'Max (W, Wt);
end if;
end loop;
-- Width for types derived from Standard.Boolean
elsif R = Standard_Boolean then
if Lo = 0 then
W := 5; -- FALSE
else
W := 4; -- TRUE
end if;
-- Width for integer types
elsif Is_Integer_Type (P_Type) then
T := UI_Max (abs Lo, abs Hi);
W := 2;
while T >= 10 loop
W := W + 1;
T := T / 10;
end loop;
-- Only remaining possibility is user declared enum type
else
pragma Assert (Is_Enumeration_Type (P_Type));
W := 0;
L := First_Literal (P_Type);
while Present (L) loop
-- Only pay attention to in range characters
if Lo <= Enumeration_Pos (L)
and then Enumeration_Pos (L) <= Hi
then
-- For Width case, use decoded name
if Id = Attribute_Width then
Get_Decoded_Name_String (Chars (L));
Wt := Nat (Name_Len);
-- For Wide_[Wide_]Width, use encoded name, and
-- then adjust for the encoding.
else
Get_Name_String (Chars (L));
-- Character literals are always of length 3
if Name_Buffer (1) = 'Q' then
Wt := 3;
-- Otherwise loop to adjust for upper/wide chars
else
Wt := Nat (Name_Len);
for J in 1 .. Name_Len loop
if Name_Buffer (J) = 'U' then
Wt := Wt - 2;
elsif Name_Buffer (J) = 'W' then
Wt := Wt - 4;
end if;
end loop;
end if;
end if;
W := Int'Max (W, Wt);
end if;
Next_Literal (L);
end loop;
end if;
Fold_Uint (N, UI_From_Int (W), True);
end;
end if;
end if;
end Width;
-- The following attributes can never be folded, and furthermore we
-- should not even have entered the case statement for any of these.
-- Note that in some cases, the values have already been folded as
-- a result of the processing in Analyze_Attribute.
when Attribute_Abort_Signal |
Attribute_Access |
Attribute_Address |
Attribute_Address_Size |
Attribute_Asm_Input |
Attribute_Asm_Output |
Attribute_Base |
Attribute_Bit_Order |
Attribute_Bit_Position |
Attribute_Callable |
Attribute_Caller |
Attribute_Class |
Attribute_Code_Address |
Attribute_Count |
Attribute_Default_Bit_Order |
Attribute_Elaborated |
Attribute_Elab_Body |
Attribute_Elab_Spec |
Attribute_External_Tag |
Attribute_First_Bit |
Attribute_Input |
Attribute_Last_Bit |
Attribute_Maximum_Alignment |
Attribute_Output |
Attribute_Partition_ID |
Attribute_Pool_Address |
Attribute_Position |
Attribute_Read |
Attribute_Storage_Pool |
Attribute_Storage_Size |
Attribute_Storage_Unit |
Attribute_Tag |
Attribute_Target_Name |
Attribute_Terminated |
Attribute_To_Address |
Attribute_UET_Address |
Attribute_Unchecked_Access |
Attribute_Universal_Literal_String |
Attribute_Unrestricted_Access |
Attribute_Valid |
Attribute_Value |
Attribute_Wchar_T_Size |
Attribute_Wide_Value |
Attribute_Wide_Wide_Value |
Attribute_Word_Size |
Attribute_Write =>
raise Program_Error;
end case;
-- At the end of the case, one more check. If we did a static evaluation
-- so that the result is now a literal, then set Is_Static_Expression
-- in the constant only if the prefix type is a static subtype. For
-- non-static subtypes, the folding is still OK, but not static.
-- An exception is the GNAT attribute Constrained_Array which is
-- defined to be a static attribute in all cases.
if Nkind (N) = N_Integer_Literal
or else Nkind (N) = N_Real_Literal
or else Nkind (N) = N_Character_Literal
or else Nkind (N) = N_String_Literal
or else (Is_Entity_Name (N)
and then Ekind (Entity (N)) = E_Enumeration_Literal)
then
Set_Is_Static_Expression (N, Static);
-- If this is still an attribute reference, then it has not been folded
-- and that means that its expressions are in a non-static context.
elsif Nkind (N) = N_Attribute_Reference then
Check_Expressions;
-- Note: the else case not covered here are odd cases where the
-- processing has transformed the attribute into something other
-- than a constant. Nothing more to do in such cases.
else
null;
end if;
end Eval_Attribute;
------------------------------
-- Is_Anonymous_Tagged_Base --
------------------------------
function Is_Anonymous_Tagged_Base
(Anon : Entity_Id;
Typ : Entity_Id)
return Boolean
is
begin
return
Anon = Current_Scope
and then Is_Itype (Anon)
and then Associated_Node_For_Itype (Anon) = Parent (Typ);
end Is_Anonymous_Tagged_Base;
-----------------------
-- Resolve_Attribute --
-----------------------
procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Prefix (N);
Aname : constant Name_Id := Attribute_Name (N);
Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
Btyp : constant Entity_Id := Base_Type (Typ);
Index : Interp_Index;
It : Interp;
Nom_Subt : Entity_Id;
procedure Accessibility_Message;
-- Error, or warning within an instance, if the static accessibility
-- rules of 3.10.2 are violated.
---------------------------
-- Accessibility_Message --
---------------------------
procedure Accessibility_Message is
Indic : Node_Id := Parent (Parent (N));
begin
-- In an instance, this is a runtime check, but one we
-- know will fail, so generate an appropriate warning.
if In_Instance_Body then
Error_Msg_N
("?non-local pointer cannot point to local object", P);
Error_Msg_N
("\?Program_Error will be raised at run time", P);
Rewrite (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Accessibility_Check_Failed));
Set_Etype (N, Typ);
return;
else
Error_Msg_N
("non-local pointer cannot point to local object", P);
-- Check for case where we have a missing access definition
if Is_Record_Type (Current_Scope)
and then
(Nkind (Parent (N)) = N_Discriminant_Association
or else
Nkind (Parent (N)) = N_Index_Or_Discriminant_Constraint)
then
Indic := Parent (Parent (N));
while Present (Indic)
and then Nkind (Indic) /= N_Subtype_Indication
loop
Indic := Parent (Indic);
end loop;
if Present (Indic) then
Error_Msg_NE
("\use an access definition for" &
" the access discriminant of&", N,
Entity (Subtype_Mark (Indic)));
end if;
end if;
end if;
end Accessibility_Message;
-- Start of processing for Resolve_Attribute
begin
-- If error during analysis, no point in continuing, except for
-- array types, where we get better recovery by using unconstrained
-- indices than nothing at all (see Check_Array_Type).
if Error_Posted (N)
and then Attr_Id /= Attribute_First
and then Attr_Id /= Attribute_Last
and then Attr_Id /= Attribute_Length
and then Attr_Id /= Attribute_Range
then
return;
end if;
-- If attribute was universal type, reset to actual type
if Etype (N) = Universal_Integer
or else Etype (N) = Universal_Real
then
Set_Etype (N, Typ);
end if;
-- Remaining processing depends on attribute
case Attr_Id is
------------
-- Access --
------------
-- For access attributes, if the prefix denotes an entity, it is
-- interpreted as a name, never as a call. It may be overloaded,
-- in which case resolution uses the profile of the context type.
-- Otherwise prefix must be resolved.
when Attribute_Access
| Attribute_Unchecked_Access
| Attribute_Unrestricted_Access =>
if Is_Variable (P) then
Note_Possible_Modification (P);
end if;
if Is_Entity_Name (P) then
if Is_Overloaded (P) then
Get_First_Interp (P, Index, It);
while Present (It.Nam) loop
if Type_Conformant (Designated_Type (Typ), It.Nam) then
Set_Entity (P, It.Nam);
-- The prefix is definitely NOT overloaded anymore
-- at this point, so we reset the Is_Overloaded
-- flag to avoid any confusion when reanalyzing
-- the node.
Set_Is_Overloaded (P, False);
Generate_Reference (Entity (P), P);
exit;
end if;
Get_Next_Interp (Index, It);
end loop;
-- If it is a subprogram name or a type, there is nothing
-- to resolve.
elsif not Is_Overloadable (Entity (P))
and then not Is_Type (Entity (P))
then
Resolve (P);
end if;
Error_Msg_Name_1 := Aname;
if not Is_Entity_Name (P) then
null;
elsif Is_Abstract (Entity (P))
and then Is_Overloadable (Entity (P))
then
Error_Msg_N ("prefix of % attribute cannot be abstract", P);
Set_Etype (N, Any_Type);
elsif Convention (Entity (P)) = Convention_Intrinsic then
if Ekind (Entity (P)) = E_Enumeration_Literal then
Error_Msg_N
("prefix of % attribute cannot be enumeration literal",
P);
else
Error_Msg_N
("prefix of % attribute cannot be intrinsic", P);
end if;
Set_Etype (N, Any_Type);
elsif Is_Thread_Body (Entity (P)) then
Error_Msg_N
("prefix of % attribute cannot be a thread body", P);
end if;
-- Assignments, return statements, components of aggregates,
-- generic instantiations will require convention checks if
-- the type is an access to subprogram. Given that there will
-- also be accessibility checks on those, this is where the
-- checks can eventually be centralized ???
if Ekind (Btyp) = E_Access_Subprogram_Type
or else
Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
or else
Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type
then
if Convention (Btyp) /= Convention (Entity (P)) then
Error_Msg_N
("subprogram has invalid convention for context", P);
else
Check_Subtype_Conformant
(New_Id => Entity (P),
Old_Id => Designated_Type (Btyp),
Err_Loc => P);
end if;
if Attr_Id = Attribute_Unchecked_Access then
Error_Msg_Name_1 := Aname;
Error_Msg_N
("attribute% cannot be applied to a subprogram", P);
elsif Aname = Name_Unrestricted_Access then
null; -- Nothing to check
-- Check the static accessibility rule of 3.10.2(32).
-- This rule also applies within the private part of an
-- instantiation. This rule does not apply to anonymous
-- access-to-subprogram types (Ada 2005).
elsif Attr_Id = Attribute_Access
and then not In_Instance_Body
and then Subprogram_Access_Level (Entity (P)) >
Type_Access_Level (Btyp)
and then Ekind (Btyp) /=
E_Anonymous_Access_Subprogram_Type
and then Ekind (Btyp) /=
E_Anonymous_Access_Protected_Subprogram_Type
then
Error_Msg_N
("subprogram must not be deeper than access type", P);
-- Check the restriction of 3.10.2(32) that disallows the
-- access attribute within a generic body when the ultimate
-- ancestor of the type of the attribute is declared outside
-- of the generic unit and the subprogram is declared within
-- that generic unit. This includes any such attribute that
-- occurs within the body of a generic unit that is a child
-- of the generic unit where the subprogram is declared.
-- The rule also prohibits applying the attibute when the
-- access type is a generic formal access type (since the
-- level of the actual type is not known). This restriction
-- does not apply when the attribute type is an anonymous
-- access-to-subprogram type. Note that this check was
-- revised by AI-229, because the originally Ada 95 rule
-- was too lax. The original rule only applied when the
-- subprogram was declared within the body of the generic,
-- which allowed the possibility of dangling references).
-- The rule was also too strict in some case, in that it
-- didn't permit the access to be declared in the generic
-- spec, whereas the revised rule does (as long as it's not
-- a formal type).
-- There are a couple of subtleties of the test for applying
-- the check that are worth noting. First, we only apply it
-- when the levels of the subprogram and access type are the
-- same (the case where the subprogram is statically deeper
-- was applied above, and the case where the type is deeper
-- is always safe). Second, we want the check to apply
-- within nested generic bodies and generic child unit
-- bodies, but not to apply to an attribute that appears in
-- the generic unit's specification. This is done by testing
-- that the attribute's innermost enclosing generic body is
-- not the same as the innermost generic body enclosing the
-- generic unit where the subprogram is declared (we don't
-- want the check to apply when the access attribute is in
-- the spec and there's some other generic body enclosing
-- generic). Finally, there's no point applying the check
-- when within an instance, because any violations will
-- have been caught by the compilation of the generic unit.
elsif Attr_Id = Attribute_Access
and then not In_Instance
and then Present (Enclosing_Generic_Unit (Entity (P)))
and then Present (Enclosing_Generic_Body (N))
and then Enclosing_Generic_Body (N) /=
Enclosing_Generic_Body
(Enclosing_Generic_Unit (Entity (P)))
and then Subprogram_Access_Level (Entity (P)) =
Type_Access_Level (Btyp)
and then Ekind (Btyp) /=
E_Anonymous_Access_Subprogram_Type
and then Ekind (Btyp) /=
E_Anonymous_Access_Protected_Subprogram_Type
then
-- The attribute type's ultimate ancestor must be
-- declared within the same generic unit as the
-- subprogram is declared. The error message is
-- specialized to say "ancestor" for the case where
-- the access type is not its own ancestor, since
-- saying simply "access type" would be very confusing.
if Enclosing_Generic_Unit (Entity (P)) /=
Enclosing_Generic_Unit (Root_Type (Btyp))
then
if Root_Type (Btyp) = Btyp then
Error_Msg_N
("access type must not be outside generic unit",
N);
else
Error_Msg_N
("ancestor access type must not be outside " &
"generic unit", N);
end if;
-- If the ultimate ancestor of the attribute's type is
-- a formal type, then the attribute is illegal because
-- the actual type might be declared at a higher level.
-- The error message is specialized to say "ancestor"
-- for the case where the access type is not its own
-- ancestor, since saying simply "access type" would be
-- very confusing.
elsif Is_Generic_Type (Root_Type (Btyp)) then
if Root_Type (Btyp) = Btyp then
Error_Msg_N
("access type must not be a generic formal type",
N);
else
Error_Msg_N
("ancestor access type must not be a generic " &
"formal type", N);
end if;
end if;
end if;
end if;
-- If this is a renaming, an inherited operation, or a
-- subprogram instance, use the original entity.
if Is_Entity_Name (P)
and then Is_Overloadable (Entity (P))
and then Present (Alias (Entity (P)))
then
Rewrite (P,
New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
end if;
elsif Nkind (P) = N_Selected_Component
and then Is_Overloadable (Entity (Selector_Name (P)))
then
-- Protected operation. If operation is overloaded, must
-- disambiguate. Prefix that denotes protected object itself
-- is resolved with its own type.
if Attr_Id = Attribute_Unchecked_Access then
Error_Msg_Name_1 := Aname;
Error_Msg_N
("attribute% cannot be applied to protected operation", P);
end if;
Resolve (Prefix (P));
Generate_Reference (Entity (Selector_Name (P)), P);
elsif Is_Overloaded (P) then
-- Use the designated type of the context to disambiguate
-- Note that this was not strictly conformant to Ada 95,
-- but was the implementation adopted by most Ada 95 compilers.
-- The use of the context type to resolve an Access attribute
-- reference is now mandated in AI-235 for Ada 2005.
declare
Index : Interp_Index;
It : Interp;
begin
Get_First_Interp (P, Index, It);
while Present (It.Typ) loop
if Covers (Designated_Type (Typ), It.Typ) then
Resolve (P, It.Typ);
exit;
end if;
Get_Next_Interp (Index, It);
end loop;
end;
else
Resolve (P);
end if;
-- X'Access is illegal if X denotes a constant and the access
-- type is access-to-variable. Same for 'Unchecked_Access.
-- The rule does not apply to 'Unrestricted_Access.
if not (Ekind (Btyp) = E_Access_Subprogram_Type
or else Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
or else (Is_Record_Type (Btyp) and then
Present (Corresponding_Remote_Type (Btyp)))
or else Ekind (Btyp) = E_Access_Protected_Subprogram_Type
or else Ekind (Btyp)
= E_Anonymous_Access_Protected_Subprogram_Type
or else Is_Access_Constant (Btyp)
or else Is_Variable (P)
or else Attr_Id = Attribute_Unrestricted_Access)
then
if Comes_From_Source (N) then
Error_Msg_N ("access-to-variable designates constant", P);
end if;
end if;
if (Attr_Id = Attribute_Access
or else
Attr_Id = Attribute_Unchecked_Access)
and then (Ekind (Btyp) = E_General_Access_Type
or else Ekind (Btyp) = E_Anonymous_Access_Type)
then
-- Ada 2005 (AI-230): Check the accessibility of anonymous
-- access types in record and array components. For a
-- component definition the level is the same of the
-- enclosing composite type.
if Ada_Version >= Ada_05
and then Is_Local_Anonymous_Access (Btyp)
and then Object_Access_Level (P) > Type_Access_Level (Btyp)
then
-- In an instance, this is a runtime check, but one we
-- know will fail, so generate an appropriate warning.
if In_Instance_Body then
Error_Msg_N
("?non-local pointer cannot point to local object", P);
Error_Msg_N
("\?Program_Error will be raised at run time", P);
Rewrite (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Accessibility_Check_Failed));
Set_Etype (N, Typ);
else
Error_Msg_N
("non-local pointer cannot point to local object", P);
end if;
end if;
if Is_Dependent_Component_Of_Mutable_Object (P) then
Error_Msg_N
("illegal attribute for discriminant-dependent component",
P);
end if;
-- Check the static matching rule of 3.10.2(27). The
-- nominal subtype of the prefix must statically
-- match the designated type.
Nom_Subt := Etype (P);
if Is_Constr_Subt_For_U_Nominal (Nom_Subt) then
Nom_Subt := Etype (Nom_Subt);
end if;
if Is_Tagged_Type (Designated_Type (Typ)) then
-- If the attribute is in the context of an access
-- parameter, then the prefix is allowed to be of
-- the class-wide type (by AI-127).
if Ekind (Typ) = E_Anonymous_Access_Type then
if not Covers (Designated_Type (Typ), Nom_Subt)
and then not Covers (Nom_Subt, Designated_Type (Typ))
then
declare
Desig : Entity_Id;
begin
Desig := Designated_Type (Typ);
if Is_Class_Wide_Type (Desig) then
Desig := Etype (Desig);
end if;
if Is_Anonymous_Tagged_Base (Nom_Subt, Desig) then
null;
else
Error_Msg_NE
("type of prefix: & not compatible",
P, Nom_Subt);
Error_Msg_NE
("\with &, the expected designated type",
P, Designated_Type (Typ));
end if;
end;
end if;
elsif not Covers (Designated_Type (Typ), Nom_Subt)
or else
(not Is_Class_Wide_Type (Designated_Type (Typ))
and then Is_Class_Wide_Type (Nom_Subt))
then
Error_Msg_NE
("type of prefix: & is not covered", P, Nom_Subt);
Error_Msg_NE
("\by &, the expected designated type" &
" ('R'M 3.10.2 (27))", P, Designated_Type (Typ));
end if;
if Is_Class_Wide_Type (Designated_Type (Typ))
and then Has_Discriminants (Etype (Designated_Type (Typ)))
and then Is_Constrained (Etype (Designated_Type (Typ)))
and then Designated_Type (Typ) /= Nom_Subt
then
Apply_Discriminant_Check
(N, Etype (Designated_Type (Typ)));
end if;
elsif not Subtypes_Statically_Match
(Designated_Type (Base_Type (Typ)), Nom_Subt)
and then
not (Has_Discriminants (Designated_Type (Typ))
and then
not Is_Constrained
(Designated_Type (Base_Type (Typ))))
then
Error_Msg_N
("object subtype must statically match "
& "designated subtype", P);
if Is_Entity_Name (P)
and then Is_Array_Type (Designated_Type (Typ))
then
declare
D : constant Node_Id := Declaration_Node (Entity (P));
begin
Error_Msg_N ("aliased object has explicit bounds?",
D);
Error_Msg_N ("\declare without bounds"
& " (and with explicit initialization)?", D);
Error_Msg_N ("\for use with unconstrained access?", D);
end;
end if;
end if;
-- Check the static accessibility rule of 3.10.2(28).
-- Note that this check is not performed for the
-- case of an anonymous access type, since the access
-- attribute is always legal in such a context.
if Attr_Id /= Attribute_Unchecked_Access
and then Object_Access_Level (P) > Type_Access_Level (Btyp)
and then Ekind (Btyp) = E_General_Access_Type
then
Accessibility_Message;
return;
end if;
end if;
if Ekind (Btyp) = E_Access_Protected_Subprogram_Type
or else
Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type
then
if Is_Entity_Name (P)
and then not Is_Protected_Type (Scope (Entity (P)))
then
Error_Msg_N ("context requires a protected subprogram", P);
-- Check accessibility of protected object against that
-- of the access type, but only on user code, because
-- the expander creates access references for handlers.
-- If the context is an anonymous_access_to_protected,
-- there are no accessibility checks either.
elsif Object_Access_Level (P) > Type_Access_Level (Btyp)
and then Comes_From_Source (N)
and then Ekind (Btyp) = E_Access_Protected_Subprogram_Type
and then No (Original_Access_Type (Typ))
then
Accessibility_Message;
return;
end if;
elsif (Ekind (Btyp) = E_Access_Subprogram_Type
or else
Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type)
and then Ekind (Etype (N)) = E_Access_Protected_Subprogram_Type
then
Error_Msg_N ("context requires a non-protected subprogram", P);
end if;
-- The context cannot be a pool-specific type, but this is a
-- legality rule, not a resolution rule, so it must be checked
-- separately, after possibly disambiguation (see AI-245).
if Ekind (Btyp) = E_Access_Type
and then Attr_Id /= Attribute_Unrestricted_Access
then
Wrong_Type (N, Typ);
end if;
Set_Etype (N, Typ);
-- Check for incorrect atomic/volatile reference (RM C.6(12))
if Attr_Id /= Attribute_Unrestricted_Access then
if Is_Atomic_Object (P)
and then not Is_Atomic (Designated_Type (Typ))
then
Error_Msg_N
("access to atomic object cannot yield access-to-" &
"non-atomic type", P);
elsif Is_Volatile_Object (P)
and then not Is_Volatile (Designated_Type (Typ))
then
Error_Msg_N
("access to volatile object cannot yield access-to-" &
"non-volatile type", P);
end if;
end if;
-------------
-- Address --
-------------
-- Deal with resolving the type for Address attribute, overloading
-- is not permitted here, since there is no context to resolve it.
when Attribute_Address | Attribute_Code_Address =>
-- To be safe, assume that if the address of a variable is taken,
-- it may be modified via this address, so note modification.
if Is_Variable (P) then
Note_Possible_Modification (P);
end if;
if Nkind (P) in N_Subexpr
and then Is_Overloaded (P)
then
Get_First_Interp (P, Index, It);
Get_Next_Interp (Index, It);
if Present (It.Nam) then
Error_Msg_Name_1 := Aname;
Error_Msg_N
("prefix of % attribute cannot be overloaded", P);
return;
end if;
end if;
if not Is_Entity_Name (P)
or else not Is_Overloadable (Entity (P))
then
if not Is_Task_Type (Etype (P))
or else Nkind (P) = N_Explicit_Dereference
then
Resolve (P);
end if;
end if;
-- If this is the name of a derived subprogram, or that of a
-- generic actual, the address is that of the original entity.
if Is_Entity_Name (P)
and then Is_Overloadable (Entity (P))
and then Present (Alias (Entity (P)))
then
Rewrite (P,
New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
end if;
---------------
-- AST_Entry --
---------------
-- Prefix of the AST_Entry attribute is an entry name which must
-- not be resolved, since this is definitely not an entry call.
when Attribute_AST_Entry =>
null;
------------------
-- Body_Version --
------------------
-- Prefix of Body_Version attribute can be a subprogram name which
-- must not be resolved, since this is not a call.
when Attribute_Body_Version =>
null;
------------
-- Caller --
------------
-- Prefix of Caller attribute is an entry name which must not
-- be resolved, since this is definitely not an entry call.
when Attribute_Caller =>
null;
------------------
-- Code_Address --
------------------
-- Shares processing with Address attribute
-----------
-- Count --
-----------
-- If the prefix of the Count attribute is an entry name it must not
-- be resolved, since this is definitely not an entry call. However,
-- if it is an element of an entry family, the index itself may
-- have to be resolved because it can be a general expression.
when Attribute_Count =>
if Nkind (P) = N_Indexed_Component
and then Is_Entity_Name (Prefix (P))
then
declare
Indx : constant Node_Id := First (Expressions (P));
Fam : constant Entity_Id := Entity (Prefix (P));
begin
Resolve (Indx, Entry_Index_Type (Fam));
Apply_Range_Check (Indx, Entry_Index_Type (Fam));
end;
end if;
----------------
-- Elaborated --
----------------
-- Prefix of the Elaborated attribute is a subprogram name which
-- must not be resolved, since this is definitely not a call. Note
-- that it is a library unit, so it cannot be overloaded here.
when Attribute_Elaborated =>
null;
--------------------
-- Mechanism_Code --
--------------------
-- Prefix of the Mechanism_Code attribute is a function name
-- which must not be resolved. Should we check for overloaded ???
when Attribute_Mechanism_Code =>
null;
------------------
-- Partition_ID --
------------------
-- Most processing is done in sem_dist, after determining the
-- context type. Node is rewritten as a conversion to a runtime call.
when Attribute_Partition_ID =>
Process_Partition_Id (N);
return;
when Attribute_Pool_Address =>
Resolve (P);
-----------
-- Range --
-----------
-- We replace the Range attribute node with a range expression
-- whose bounds are the 'First and 'Last attributes applied to the
-- same prefix. The reason that we do this transformation here
-- instead of in the expander is that it simplifies other parts of
-- the semantic analysis which assume that the Range has been
-- replaced; thus it must be done even when in semantic-only mode
-- (note that the RM specifically mentions this equivalence, we
-- take care that the prefix is only evaluated once).
when Attribute_Range => Range_Attribute :
declare
LB : Node_Id;
HB : Node_Id;
function Check_Discriminated_Prival
(N : Node_Id)
return Node_Id;
-- The range of a private component constrained by a
-- discriminant is rewritten to make the discriminant
-- explicit. This solves some complex visibility problems
-- related to the use of privals.
--------------------------------
-- Check_Discriminated_Prival --
--------------------------------
function Check_Discriminated_Prival
(N : Node_Id)
return Node_Id
is
begin
if Is_Entity_Name (N)
and then Ekind (Entity (N)) = E_In_Parameter
and then not Within_Init_Proc
then
return Make_Identifier (Sloc (N), Chars (Entity (N)));
else
return Duplicate_Subexpr (N);
end if;
end Check_Discriminated_Prival;
-- Start of processing for Range_Attribute
begin
if not Is_Entity_Name (P)
or else not Is_Type (Entity (P))
then
Resolve (P);
end if;
-- Check whether prefix is (renaming of) private component
-- of protected type.
if Is_Entity_Name (P)
and then Comes_From_Source (N)
and then Is_Array_Type (Etype (P))
and then Number_Dimensions (Etype (P)) = 1
and then (Ekind (Scope (Entity (P))) = E_Protected_Type
or else
Ekind (Scope (Scope (Entity (P)))) =
E_Protected_Type)
then
LB :=
Check_Discriminated_Prival
(Type_Low_Bound (Etype (First_Index (Etype (P)))));
HB :=
Check_Discriminated_Prival
(Type_High_Bound (Etype (First_Index (Etype (P)))));
else
HB :=
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (P),
Attribute_Name => Name_Last,
Expressions => Expressions (N));
LB :=
Make_Attribute_Reference (Loc,
Prefix => P,
Attribute_Name => Name_First,
Expressions => Expressions (N));
end if;
-- If the original was marked as Must_Not_Freeze (see code
-- in Sem_Ch3.Make_Index), then make sure the rewriting
-- does not freeze either.
if Must_Not_Freeze (N) then
Set_Must_Not_Freeze (HB);
Set_Must_Not_Freeze (LB);
Set_Must_Not_Freeze (Prefix (HB));
Set_Must_Not_Freeze (Prefix (LB));
end if;
if Raises_Constraint_Error (Prefix (N)) then
-- Preserve Sloc of prefix in the new bounds, so that
-- the posted warning can be removed if we are within
-- unreachable code.
Set_Sloc (LB, Sloc (Prefix (N)));
Set_Sloc (HB, Sloc (Prefix (N)));
end if;
Rewrite (N, Make_Range (Loc, LB, HB));
Analyze_And_Resolve (N, Typ);
-- Normally after resolving attribute nodes, Eval_Attribute
-- is called to do any possible static evaluation of the node.
-- However, here since the Range attribute has just been
-- transformed into a range expression it is no longer an
-- attribute node and therefore the call needs to be avoided
-- and is accomplished by simply returning from the procedure.
return;
end Range_Attribute;
-----------------
-- UET_Address --
-----------------
-- Prefix must not be resolved in this case, since it is not a
-- real entity reference. No action of any kind is require!
when Attribute_UET_Address =>
return;
----------------------
-- Unchecked_Access --
----------------------
-- Processing is shared with Access
-------------------------
-- Unrestricted_Access --
-------------------------
-- Processing is shared with Access
---------
-- Val --
---------
-- Apply range check. Note that we did not do this during the
-- analysis phase, since we wanted Eval_Attribute to have a
-- chance at finding an illegal out of range value.
when Attribute_Val =>
-- Note that we do our own Eval_Attribute call here rather than
-- use the common one, because we need to do processing after
-- the call, as per above comment.
Eval_Attribute (N);
-- Eval_Attribute may replace the node with a raise CE, or
-- fold it to a constant. Obviously we only apply a scalar
-- range check if this did not happen!
if Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Val
then
Apply_Scalar_Range_Check (First (Expressions (N)), Btyp);
end if;
return;
-------------
-- Version --
-------------
-- Prefix of Version attribute can be a subprogram name which
-- must not be resolved, since this is not a call.
when Attribute_Version =>
null;
----------------------
-- Other Attributes --
----------------------
-- For other attributes, resolve prefix unless it is a type. If
-- the attribute reference itself is a type name ('Base and 'Class)
-- then this is only legal within a task or protected record.
when others =>
if not Is_Entity_Name (P)
or else not Is_Type (Entity (P))
then
Resolve (P);
end if;
-- If the attribute reference itself is a type name ('Base,
-- 'Class) then this is only legal within a task or protected
-- record. What is this all about ???
if Is_Entity_Name (N)
and then Is_Type (Entity (N))
then
if Is_Concurrent_Type (Entity (N))
and then In_Open_Scopes (Entity (P))
then
null;
else
Error_Msg_N
("invalid use of subtype name in expression or call", N);
end if;
end if;
-- For attributes whose argument may be a string, complete
-- resolution of argument now. This avoids premature expansion
-- (and the creation of transient scopes) before the attribute
-- reference is resolved.
case Attr_Id is
when Attribute_Value =>
Resolve (First (Expressions (N)), Standard_String);
when Attribute_Wide_Value =>
Resolve (First (Expressions (N)), Standard_Wide_String);
when Attribute_Wide_Wide_Value =>
Resolve (First (Expressions (N)), Standard_Wide_Wide_String);
when others => null;
end case;
end case;
-- Normally the Freezing is done by Resolve but sometimes the Prefix
-- is not resolved, in which case the freezing must be done now.
Freeze_Expression (P);
-- Finally perform static evaluation on the attribute reference
Eval_Attribute (N);
end Resolve_Attribute;
--------------------------------
-- Stream_Attribute_Available --
--------------------------------
function Stream_Attribute_Available
(Typ : Entity_Id;
Nam : TSS_Name_Type;
Partial_View : Node_Id := Empty) return Boolean
is
Etyp : Entity_Id := Typ;
function Has_Specified_Stream_Attribute
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Boolean;
-- True iff there is a visible attribute definition clause specifying
-- attribute Nam for Typ.
------------------------------------
-- Has_Specified_Stream_Attribute --
------------------------------------
function Has_Specified_Stream_Attribute
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Boolean
is
begin
return False
or else
(Nam = TSS_Stream_Input
and then Has_Specified_Stream_Input (Typ))
or else
(Nam = TSS_Stream_Output
and then Has_Specified_Stream_Output (Typ))
or else
(Nam = TSS_Stream_Read
and then Has_Specified_Stream_Read (Typ))
or else
(Nam = TSS_Stream_Write
and then Has_Specified_Stream_Write (Typ));
end Has_Specified_Stream_Attribute;
-- Start of processing for Stream_Attribute_Available
begin
-- We need some comments in this body ???
if Has_Specified_Stream_Attribute (Typ, Nam) then
return True;
end if;
if Is_Class_Wide_Type (Typ) then
return not Is_Limited_Type (Typ)
or else Stream_Attribute_Available (Etype (Typ), Nam);
end if;
if Nam = TSS_Stream_Input
and then Is_Abstract (Typ)
and then not Is_Class_Wide_Type (Typ)
then
return False;
end if;
if not (Is_Limited_Type (Typ)
or else (Present (Partial_View)
and then Is_Limited_Type (Partial_View)))
then
return True;
end if;
-- In Ada 2005, Input can invoke Read, and Output can invoke Write
if Nam = TSS_Stream_Input
and then Ada_Version >= Ada_05
and then Stream_Attribute_Available (Etyp, TSS_Stream_Read)
then
return True;
elsif Nam = TSS_Stream_Output
and then Ada_Version >= Ada_05
and then Stream_Attribute_Available (Etyp, TSS_Stream_Write)
then
return True;
end if;
-- Case of Read and Write: check for attribute definition clause that
-- applies to an ancestor type.
while Etype (Etyp) /= Etyp loop
Etyp := Etype (Etyp);
if Has_Specified_Stream_Attribute (Etyp, Nam) then
return True;
end if;
end loop;
if Ada_Version < Ada_05 then
-- In Ada 95 mode, also consider a non-visible definition
declare
Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
begin
return Btyp /= Typ
and then Stream_Attribute_Available
(Btyp, Nam, Partial_View => Typ);
end;
end if;
return False;
end Stream_Attribute_Available;
end Sem_Attr;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . P R O T E C T I O N --
-- --
-- S p e c --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2004 The European Space Agency --
-- Copyright (C) 2003-2021, AdaCore --
-- --
-- GNARL 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. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
-- This package provides the functionality required to protect the data
-- handled by the low level tasking system.
pragma Restrictions (No_Elaboration_Code);
package System.BB.Protection is
pragma Preelaborate;
Wakeup_Served_Entry_Callback : access procedure := null;
-- Callback set by upper layer
procedure Enter_Kernel;
pragma Inline (Enter_Kernel);
-- This procedure is executed to signal the access to kernel data. Its use
-- protect the consistence of the kernel. Interrupts are disabled while
-- kernel data is being accessed.
procedure Leave_Kernel;
-- Leave_Kernel must be called when the access to kernel data finishes.
-- Interrupts are enable to the appropriate level (according to the active
-- priority of the running thread).
end System.BB.Protection;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation
-- the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------
with Ada.Real_Time; use Ada.Real_Time;
with DecaDriver;
with DW1000.BSP;
with DW1000.Driver; use DW1000.Driver;
with DW1000.Types;
-- This simple example demonstrates using the DW1000 to receive packets.
procedure Receive_Example
with SPARK_Mode,
Global => (Input => Ada.Real_Time.Clock_Time,
In_Out => (DW1000.BSP.Device_State,
DecaDriver.Driver)),
Depends => (DecaDriver.Driver =>+ DW1000.BSP.Device_State,
DW1000.BSP.Device_State =>+ DecaDriver.Driver,
null => Ada.Real_Time.Clock_Time)
is
Rx_Packet : DW1000.Types.Byte_Array (1 .. 127) := (others => 0);
Rx_Packet_Length : DecaDriver.Frame_Length_Number;
Rx_Frame_Info : DecaDriver.Frame_Info_Type;
Rx_Status : DecaDriver.Rx_Status_Type;
Rx_Overrun : Boolean;
begin
-- Driver must be initialized once before it is used.
DecaDriver.Driver.Initialize
(Load_Antenna_Delay => True,
Load_XTAL_Trim => True,
Load_UCode_From_ROM => True);
-- Configure the DW1000
DecaDriver.Driver.Configure
(DecaDriver.Configuration_Type'
(Channel => 1,
PRF => PRF_64MHz,
Tx_Preamble_Length => PLEN_1024,
Rx_PAC => PAC_8,
Tx_Preamble_Code => 9,
Rx_Preamble_Code => 9,
Use_Nonstandard_SFD => False,
Data_Rate => Data_Rate_110k,
PHR_Mode => Standard_Frames,
SFD_Timeout => 1024 + 64 + 1));
-- We don't need to configure the transmit power in this example, because
-- we don't transmit any frames!
-- Enable the LEDs controlled by the DW1000.
DW1000.Driver.Configure_LEDs
(Tx_LED_Enable => True, -- Enable transmit LED
Rx_LED_Enable => True, -- Enable receive LED
Rx_OK_LED_Enable => False,
SFD_LED_Enable => False,
Test_Flash => True); -- Flash both LEDs once
-- In this example we only want to receive valid packets without errors,
-- so configure the DW1000 to automatically re-enable the receiver when
-- errors occur. The driver will not be notified of receiver errors whilst
-- this is enabled.
DW1000.Driver.Set_Auto_Rx_Reenable (Enable => True);
-- Continuously receive packets
loop
-- Enable the receiver to listen for a packet
DecaDriver.Driver.Start_Rx_Immediate;
-- Wait for a packet
DecaDriver.Driver.Rx_Wait
(Frame => Rx_Packet,
Length => Rx_Packet_Length,
Frame_Info => Rx_Frame_Info,
Status => Rx_Status,
Overrun => Rx_Overrun);
-- When execution has reached here then a packet has been received
-- successfully.
end loop;
end Receive_Example;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Declarations;
with Program.Elements.Defining_Identifiers;
with Program.Lexical_Elements;
with Program.Elements.Discrete_Ranges;
package Program.Elements.Loop_Parameter_Specifications is
pragma Pure (Program.Elements.Loop_Parameter_Specifications);
type Loop_Parameter_Specification is
limited interface and Program.Elements.Declarations.Declaration;
type Loop_Parameter_Specification_Access is
access all Loop_Parameter_Specification'Class with Storage_Size => 0;
not overriding function Name
(Self : Loop_Parameter_Specification)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access is abstract;
not overriding function Definition
(Self : Loop_Parameter_Specification)
return not null Program.Elements.Discrete_Ranges.Discrete_Range_Access
is abstract;
not overriding function Has_Reverse
(Self : Loop_Parameter_Specification)
return Boolean is abstract;
type Loop_Parameter_Specification_Text is limited interface;
type Loop_Parameter_Specification_Text_Access is
access all Loop_Parameter_Specification_Text'Class with Storage_Size => 0;
not overriding function To_Loop_Parameter_Specification_Text
(Self : in out Loop_Parameter_Specification)
return Loop_Parameter_Specification_Text_Access is abstract;
not overriding function In_Token
(Self : Loop_Parameter_Specification_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Reverse_Token
(Self : Loop_Parameter_Specification_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
end Program.Elements.Loop_Parameter_Specifications;
|
-----------------------------------------------------------------------
-- jason-projects-beans -- Beans for module projects
-- Copyright (C) 2016, 2017, 2018, 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 AWA.Services.Contexts;
with AWA.Tags.Modules;
with AWA.Wikis.Modules;
with ADO.Sessions;
with ADO.Sessions.Entities;
with ADO.Queries;
with ADO.Utils;
with ADO.Datasets;
package body Jason.Projects.Beans is
package ASC renames AWA.Services.Contexts;
-- ------------------------------
-- Create project action.
-- ------------------------------
overriding
procedure Create (Bean : in out Project_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Create (Bean);
Bean.Tags.Update_Tags (Bean.Get_Id);
end Create;
-- ------------------------------
-- Save project action.
-- ------------------------------
overriding
procedure Save (Bean : in out Project_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Save (Bean);
Bean.Tags.Update_Tags (Bean.Get_Id);
end Save;
-- ------------------------------
-- Load project information.
-- ------------------------------
overriding
procedure Load (Bean : in out Project_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
use type ADO.Identifier;
begin
if Bean.Id = ADO.NO_IDENTIFIER then
Outcome := Ada.Strings.Unbounded.To_Unbounded_String ("failed");
return;
end if;
Bean.Module.Load_Project (Bean, Bean.Wiki_Space, Bean.Tags, Bean.Id, ADO.NO_IDENTIFIER);
Outcome := Ada.Strings.Unbounded.To_Unbounded_String ("loaded");
end Load;
-- ------------------------------
-- Create the wiki space.
-- ------------------------------
overriding
procedure Create_Wiki (Bean : in out Project_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
begin
Bean.Module.Create_Wiki (Bean, Bean.Wiki_Space);
end Create_Wiki;
-- ------------------------------
-- Load the project if it is associated with the current wiki space.
-- ------------------------------
overriding
procedure Load_Wiki (Bean : in out Project_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
Page : constant AWA.Wikis.Beans.Wiki_View_Bean_Access
:= AWA.Wikis.Beans.Get_Wiki_View_Bean ("wikiView");
begin
-- Page.Load (Outcome);
if not Page.Wiki_Space.Is_Null then
Bean.Module.Load_Project (Bean, Bean.Wiki_Space, Bean.Tags, ADO.NO_IDENTIFIER,
Page.Wiki_Space.Get_Id);
end if;
Outcome := Ada.Strings.Unbounded.To_Unbounded_String ("loaded");
end Load_Wiki;
-- ------------------------------
-- Get the value identified by the name.
-- ------------------------------
overriding
function Get_Value (From : in Project_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "count" then
return Util.Beans.Objects.To_Object (From.Count);
elsif Name = "tags" then
return Util.Beans.Objects.To_Object (From.Tags_Bean, Util.Beans.Objects.STATIC);
elsif Name = "has_wiki" then
return Util.Beans.Objects.To_Object (not From.Wiki_Space.Is_Null);
elsif Name = "wiki" then
return From.Wiki_Space.Get_Value ("name");
elsif Name = "wiki_id" then
return From.Wiki_Space.Get_Value ("id");
else
return Jason.Projects.Models.Project_Bean (From).Get_Value (Name);
end if;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- ------------------------------
overriding
procedure Set_Value (From : in out Project_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then
From.Id := ADO.Utils.To_Identifier (Value);
From.Module.Load_Project (From, From.Wiki_Space, From.Tags, From.Id, ADO.NO_IDENTIFIER);
elsif Name = "wiki" then
From.Wiki_Space.Set_Value ("name", Value);
else
Jason.Projects.Models.Project_Bean (From).Set_Value (Name, Value);
end if;
end Set_Value;
-- ------------------------------
-- Create the Project_Bean bean instance.
-- ------------------------------
function Create_Project_Bean (Module : in Jason.Projects.Modules.Project_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Object : constant Project_Bean_Access := new Project_Bean;
begin
Object.Module := Module;
Object.Tags_Bean := Object.Tags'Access;
Object.Tags.Set_Entity_Type (Jason.Projects.Models.PROJECT_TABLE);
Object.Tags.Set_Permission ("project-update");
Object.Wiki_Space.Module := AWA.Wikis.Modules.Get_Wiki_Module;
return Object.all'Access;
end Create_Project_Bean;
-- ------------------------------
-- Get the value identified by the name.
-- ------------------------------
overriding
function Get_Value (From : in Project_List_Bean;
Name : in String) return Util.Beans.Objects.Object is
Pos : Natural;
begin
if Name = "tags" then
Pos := From.Projects.Get_Row_Index;
if Pos = 0 then
return Util.Beans.Objects.Null_Object;
end if;
declare
Item : constant Models.List_Info := From.Projects.List.Element (Pos - 1);
begin
return From.Tags.Get_Tags (Item.Id);
end;
elsif Name = "page_count" then
return Util.Beans.Objects.To_Object ((From.Count + From.Page_Size - 1) / From.Page_Size);
elsif Name = "projects" then
return Util.Beans.Objects.To_Object (Value => From.Projects_Bean,
Storage => Util.Beans.Objects.STATIC);
else
return Jason.Projects.Models.Project_List_Bean (From).Get_Value (Name);
end if;
end Get_Value;
-- ------------------------------
-- Set the value identified by the name.
-- ------------------------------
overriding
procedure Set_Value (From : in out Project_List_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if not Util.Beans.Objects.Is_Empty (Value) or else Name = "tags" then
Jason.Projects.Models.Project_List_Bean (From).Set_Value (Name, Value);
end if;
end Set_Value;
-- ------------------------------
-- Load list of projects.
-- ------------------------------
overriding
procedure Load (Bean : in out Project_List_Bean;
Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is
pragma Unreferenced (Outcome);
use type ADO.Identifier;
use Jason.Projects.Models;
Ctx : constant ASC.Service_Context_Access := ASC.Current;
User : constant ADO.Identifier := Ctx.Get_User_Identifier;
Session : ADO.Sessions.Session := Bean.Module.Get_Session;
Query : ADO.Queries.Context;
Count_Query : ADO.Queries.Context;
Tag_Id : ADO.Identifier;
First : constant Natural := (Bean.Page - 1) * Bean.Page_Size;
begin
AWA.Tags.Modules.Find_Tag_Id (Session, Ada.Strings.Unbounded.To_String (Bean.Tag), Tag_Id);
if Tag_Id /= ADO.NO_IDENTIFIER then
Query.Set_Query (Jason.Projects.Models.Query_List_Tag_Filter);
Query.Bind_Param (Name => "tag", Value => Tag_Id);
Count_Query.Set_Count_Query (Jason.Projects.Models.Query_List_Tag_Filter);
Count_Query.Bind_Param (Name => "tag", Value => Tag_Id);
else
Query.Set_Query (Jason.Projects.Models.Query_List);
Count_Query.Set_Count_Query (Jason.Projects.Models.Query_List);
end if;
Query.Bind_Param (Name => "first", Value => First);
Query.Bind_Param (Name => "count", Value => Bean.Page_Size);
Query.Bind_Param (Name => "user_id", Value => User);
Count_Query.Bind_Param (Name => "user_id", Value => User);
ADO.Sessions.Entities.Bind_Param (Params => Query,
Name => "project_table",
Table => Jason.Projects.Models.PROJECT_TABLE,
Session => Session);
ADO.Sessions.Entities.Bind_Param (Params => Count_Query,
Name => "project_table",
Table => Jason.Projects.Models.PROJECT_TABLE,
Session => Session);
Jason.Projects.Models.List (Bean.Projects, Session, Query);
Bean.Count := ADO.Datasets.Get_Count (Session, Count_Query);
declare
List : ADO.Utils.Identifier_Vector;
Iter : Models.List_Info_Vectors.Cursor := Bean.Projects.List.First;
begin
while Models.List_Info_Vectors.Has_Element (Iter) loop
List.Append (Models.List_Info_Vectors.Element (Iter).Id);
Models.List_Info_Vectors.Next (Iter);
end loop;
Bean.Tags.Load_Tags (Session, Jason.Projects.Models.PROJECT_TABLE.Table.all,
List);
end;
end Load;
-- ------------------------------
-- Create the Project_List_Bean bean instance.
-- ------------------------------
function Create_Project_List_Bean (Module : in Jason.Projects.Modules.Project_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Object : constant Project_List_Bean_Access := new Project_List_Bean;
begin
Object.Module := Module;
Object.Page_Size := 20;
Object.Count := 0;
Object.Page := 1;
Object.Projects_Bean := Object.Projects'Access;
return Object.all'Access;
end Create_Project_List_Bean;
end Jason.Projects.Beans;
|
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the Maxim Reznik, IE nor the names of its
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
package Asis.Gela.Elements.Defs.Accs is
---------------------------------------
-- Anonymous_Access_To_Variable_Node --
---------------------------------------
type Anonymous_Access_To_Variable_Node is
new Access_Definition_Node with private;
type Anonymous_Access_To_Variable_Ptr is
access all Anonymous_Access_To_Variable_Node;
for Anonymous_Access_To_Variable_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Variable_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Variable_Ptr;
function Anonymous_Access_To_Object_Subtype_Mark
(Element : Anonymous_Access_To_Variable_Node) return Asis.Name;
procedure Set_Anonymous_Access_To_Object_Subtype_Mark
(Element : in out Anonymous_Access_To_Variable_Node;
Value : in Asis.Name);
function Access_Definition_Kind (Element : Anonymous_Access_To_Variable_Node)
return Asis.Access_Definition_Kinds;
function Children (Element : access Anonymous_Access_To_Variable_Node)
return Traverse_List;
function Clone
(Element : Anonymous_Access_To_Variable_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Variable_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
---------------------------------------
-- Anonymous_Access_To_Constant_Node --
---------------------------------------
type Anonymous_Access_To_Constant_Node is
new Anonymous_Access_To_Variable_Node with private;
type Anonymous_Access_To_Constant_Ptr is
access all Anonymous_Access_To_Constant_Node;
for Anonymous_Access_To_Constant_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Constant_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Constant_Ptr;
function Access_Definition_Kind (Element : Anonymous_Access_To_Constant_Node)
return Asis.Access_Definition_Kinds;
function Clone
(Element : Anonymous_Access_To_Constant_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Constant_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
----------------------------------------
-- Anonymous_Access_To_Procedure_Node --
----------------------------------------
type Anonymous_Access_To_Procedure_Node is
new Access_Definition_Node with private;
type Anonymous_Access_To_Procedure_Ptr is
access all Anonymous_Access_To_Procedure_Node;
for Anonymous_Access_To_Procedure_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Procedure_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Procedure_Ptr;
function Access_To_Subprogram_Parameter_Profile
(Element : Anonymous_Access_To_Procedure_Node;
Include_Pragmas : in Boolean := False) return Asis.Element_List;
procedure Set_Access_To_Subprogram_Parameter_Profile
(Element : in out Anonymous_Access_To_Procedure_Node;
Value : in Asis.Element);
function Access_To_Subprogram_Parameter_Profile_List
(Element : Anonymous_Access_To_Procedure_Node) return Asis.Element;
function Access_Definition_Kind (Element : Anonymous_Access_To_Procedure_Node)
return Asis.Access_Definition_Kinds;
function Children (Element : access Anonymous_Access_To_Procedure_Node)
return Traverse_List;
function Clone
(Element : Anonymous_Access_To_Procedure_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Procedure_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
--------------------------------------------------
-- Anonymous_Access_To_Protected_Procedure_Node --
--------------------------------------------------
type Anonymous_Access_To_Protected_Procedure_Node is
new Anonymous_Access_To_Procedure_Node with private;
type Anonymous_Access_To_Protected_Procedure_Ptr is
access all Anonymous_Access_To_Protected_Procedure_Node;
for Anonymous_Access_To_Protected_Procedure_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Protected_Procedure_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Protected_Procedure_Ptr;
function Access_Definition_Kind (Element : Anonymous_Access_To_Protected_Procedure_Node)
return Asis.Access_Definition_Kinds;
function Clone
(Element : Anonymous_Access_To_Protected_Procedure_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Protected_Procedure_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
---------------------------------------
-- Anonymous_Access_To_Function_Node --
---------------------------------------
type Anonymous_Access_To_Function_Node is
new Anonymous_Access_To_Procedure_Node with private;
type Anonymous_Access_To_Function_Ptr is
access all Anonymous_Access_To_Function_Node;
for Anonymous_Access_To_Function_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Function_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Function_Ptr;
function Access_To_Function_Result_Subtype
(Element : Anonymous_Access_To_Function_Node) return Asis.Definition;
procedure Set_Access_To_Function_Result_Subtype
(Element : in out Anonymous_Access_To_Function_Node;
Value : in Asis.Definition);
function Access_Definition_Kind (Element : Anonymous_Access_To_Function_Node)
return Asis.Access_Definition_Kinds;
function Children (Element : access Anonymous_Access_To_Function_Node)
return Traverse_List;
function Clone
(Element : Anonymous_Access_To_Function_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Function_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
-------------------------------------------------
-- Anonymous_Access_To_Protected_Function_Node --
-------------------------------------------------
type Anonymous_Access_To_Protected_Function_Node is
new Anonymous_Access_To_Function_Node with private;
type Anonymous_Access_To_Protected_Function_Ptr is
access all Anonymous_Access_To_Protected_Function_Node;
for Anonymous_Access_To_Protected_Function_Ptr'Storage_Pool use Lists.Pool;
function New_Anonymous_Access_To_Protected_Function_Node
(The_Context : ASIS.Context)
return Anonymous_Access_To_Protected_Function_Ptr;
function Access_Definition_Kind (Element : Anonymous_Access_To_Protected_Function_Node)
return Asis.Access_Definition_Kinds;
function Clone
(Element : Anonymous_Access_To_Protected_Function_Node;
Parent : Asis.Element)
return Asis.Element;
procedure Copy
(Source : in Asis.Element;
Target : access Anonymous_Access_To_Protected_Function_Node;
Cloner : in Cloner_Class;
Parent : in Asis.Element);
private
type Anonymous_Access_To_Variable_Node is
new Access_Definition_Node with
record
Anonymous_Access_To_Object_Subtype_Mark : aliased Asis.Name;
end record;
type Anonymous_Access_To_Constant_Node is
new Anonymous_Access_To_Variable_Node with
record
null;
end record;
type Anonymous_Access_To_Procedure_Node is
new Access_Definition_Node with
record
Access_To_Subprogram_Parameter_Profile : aliased Primary_Parameter_Lists.List;
end record;
type Anonymous_Access_To_Protected_Procedure_Node is
new Anonymous_Access_To_Procedure_Node with
record
null;
end record;
type Anonymous_Access_To_Function_Node is
new Anonymous_Access_To_Procedure_Node with
record
Access_To_Function_Result_Subtype : aliased Asis.Definition;
end record;
type Anonymous_Access_To_Protected_Function_Node is
new Anonymous_Access_To_Function_Node with
record
null;
end record;
end Asis.Gela.Elements.Defs.Accs;
|
-- C43204I.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 AN AGGREGATE WITH AN OTHERS CLAUSE CAN APPEAR AS THE
-- EXPRESSION IN AN ASSIGNMENT STATEMENT, AND THAT THE BOUNDS OF
-- THE AGGREGATE ARE DETERMINED CORRECTLY.
-- HISTORY:
-- JET 08/15/88 CREATED ORIGINAL TEST.
WITH REPORT; USE REPORT;
PROCEDURE C43204I IS
TYPE ARR11 IS ARRAY (INTEGER RANGE -3 .. 3) OF INTEGER;
TYPE ARR12 IS ARRAY (IDENT_INT(-3) .. IDENT_INT(3)) OF INTEGER;
TYPE ARR13 IS ARRAY (IDENT_INT(1) .. IDENT_INT(-1)) OF INTEGER;
TYPE ARR21 IS ARRAY (INTEGER RANGE -1 .. 1,
INTEGER RANGE -1 .. 1) OF INTEGER;
TYPE ARR22 IS ARRAY (IDENT_INT(-1) .. IDENT_INT(1),
IDENT_INT(-1) .. IDENT_INT(1)) OF INTEGER;
TYPE ARR23 IS ARRAY (INTEGER RANGE -1 .. 1,
IDENT_INT(-1) .. IDENT_INT(1)) OF INTEGER;
TYPE ARR24 IS ARRAY (IDENT_INT(1) .. IDENT_INT(-1),
IDENT_INT(-1) .. IDENT_INT(1)) OF INTEGER;
VA11 : ARR11;
VA12 : ARR12;
VA13 : ARR13;
VA21 : ARR21;
VA22 : ARR22;
VA23 : ARR23;
VA24 : ARR24;
BEGIN
TEST ("C43204I", "CHECK THAT AN AGGREGATE WITH AN OTHERS CLAUSE " &
"CAN APPEAR AS THE EXPRESSION IN AN ASSIGNMENT " &
"STATEMENT, AND THAT THE BOUNDS OF THE " &
"AGGREGATE ARE DETERMINED CORRECTLY");
VA11 := (1,1, OTHERS => IDENT_INT(2));
VA12 := (OTHERS => IDENT_INT(2));
VA13 := (OTHERS => IDENT_INT(2));
VA21 := ((1,1,1), OTHERS => (-1..1 => IDENT_INT(2)));
VA22 := (-1 => (1,1,1), 0..1 => (OTHERS => IDENT_INT(2)));
VA23 := (OTHERS => (OTHERS => IDENT_INT(2)));
VA24 := (OTHERS => (OTHERS => IDENT_INT(2)));
IF VA11 /= (1, 1, 2, 2, 2, 2, 2) THEN
FAILED("INCORRECT VALUE OF VA11");
END IF;
IF VA12 /= (2, 2, 2, 2, 2, 2, 2) THEN
FAILED("INCORRECT VALUE OF VA12");
END IF;
IF VA13'LENGTH /= 0 THEN
FAILED("INCORRECT VALUE OF VA13");
END IF;
IF VA21 /= ((1,1,1), (2,2,2), (2,2,2)) THEN
FAILED("INCORRECT VALUE OF VA21");
END IF;
IF VA22 /= ((1,1,1), (2,2,2), (2,2,2)) THEN
FAILED("INCORRECT VALUE OF VA22");
END IF;
IF VA23 /= ((2,2,2), (2,2,2), (2,2,2)) THEN
FAILED("INCORRECT VALUE OF VA23");
END IF;
IF VA24'LENGTH /= 0 OR VA24'LENGTH(2) /= 3 THEN
FAILED("INCORRECT VALUE OF VA24");
END IF;
RESULT;
EXCEPTION
WHEN OTHERS =>
FAILED ("UNEXPECTED CONSTRAINT_ERROR OR OTHER EXCEPTION " &
"RAISED");
RESULT;
END C43204I;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
package body Program.Nodes.Single_Protected_Declarations is
function Create
(Protected_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
With_Token : Program.Lexical_Elements.Lexical_Element_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Is_Token : not null Program.Lexical_Elements
.Lexical_Element_Access;
New_Token : Program.Lexical_Elements.Lexical_Element_Access;
Progenitors : Program.Elements.Expressions.Expression_Vector_Access;
With_Token_2 : Program.Lexical_Elements.Lexical_Element_Access;
Definition : not null Program.Elements.Protected_Definitions
.Protected_Definition_Access;
Semicolon_Token : not null Program.Lexical_Elements
.Lexical_Element_Access)
return Single_Protected_Declaration is
begin
return Result : Single_Protected_Declaration :=
(Protected_Token => Protected_Token, Name => Name,
With_Token => With_Token, Aspects => Aspects, Is_Token => Is_Token,
New_Token => New_Token, Progenitors => Progenitors,
With_Token_2 => With_Token_2, Definition => Definition,
Semicolon_Token => Semicolon_Token, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
function Create
(Name : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access;
Aspects : Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access;
Progenitors : Program.Elements.Expressions
.Expression_Vector_Access;
Definition : not null Program.Elements.Protected_Definitions
.Protected_Definition_Access;
Is_Part_Of_Implicit : Boolean := False;
Is_Part_Of_Inherited : Boolean := False;
Is_Part_Of_Instance : Boolean := False)
return Implicit_Single_Protected_Declaration is
begin
return Result : Implicit_Single_Protected_Declaration :=
(Name => Name, Aspects => Aspects, Progenitors => Progenitors,
Definition => Definition, Is_Part_Of_Implicit => Is_Part_Of_Implicit,
Is_Part_Of_Inherited => Is_Part_Of_Inherited,
Is_Part_Of_Instance => Is_Part_Of_Instance, Enclosing_Element => null)
do
Initialize (Result);
end return;
end Create;
overriding function Name
(Self : Base_Single_Protected_Declaration)
return not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access is
begin
return Self.Name;
end Name;
overriding function Aspects
(Self : Base_Single_Protected_Declaration)
return Program.Elements.Aspect_Specifications
.Aspect_Specification_Vector_Access is
begin
return Self.Aspects;
end Aspects;
overriding function Progenitors
(Self : Base_Single_Protected_Declaration)
return Program.Elements.Expressions.Expression_Vector_Access is
begin
return Self.Progenitors;
end Progenitors;
overriding function Definition
(Self : Base_Single_Protected_Declaration)
return not null Program.Elements.Protected_Definitions
.Protected_Definition_Access is
begin
return Self.Definition;
end Definition;
overriding function Protected_Token
(Self : Single_Protected_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Protected_Token;
end Protected_Token;
overriding function With_Token
(Self : Single_Protected_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.With_Token;
end With_Token;
overriding function Is_Token
(Self : Single_Protected_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Is_Token;
end Is_Token;
overriding function New_Token
(Self : Single_Protected_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.New_Token;
end New_Token;
overriding function With_Token_2
(Self : Single_Protected_Declaration)
return Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.With_Token_2;
end With_Token_2;
overriding function Semicolon_Token
(Self : Single_Protected_Declaration)
return not null Program.Lexical_Elements.Lexical_Element_Access is
begin
return Self.Semicolon_Token;
end Semicolon_Token;
overriding function Is_Part_Of_Implicit
(Self : Implicit_Single_Protected_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Implicit;
end Is_Part_Of_Implicit;
overriding function Is_Part_Of_Inherited
(Self : Implicit_Single_Protected_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Inherited;
end Is_Part_Of_Inherited;
overriding function Is_Part_Of_Instance
(Self : Implicit_Single_Protected_Declaration)
return Boolean is
begin
return Self.Is_Part_Of_Instance;
end Is_Part_Of_Instance;
procedure Initialize
(Self : in out Base_Single_Protected_Declaration'Class) is
begin
Set_Enclosing_Element (Self.Name, Self'Unchecked_Access);
for Item in Self.Aspects.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
for Item in Self.Progenitors.Each_Element loop
Set_Enclosing_Element (Item.Element, Self'Unchecked_Access);
end loop;
Set_Enclosing_Element (Self.Definition, Self'Unchecked_Access);
null;
end Initialize;
overriding function Is_Single_Protected_Declaration
(Self : Base_Single_Protected_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Single_Protected_Declaration;
overriding function Is_Declaration
(Self : Base_Single_Protected_Declaration)
return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Declaration;
overriding procedure Visit
(Self : not null access Base_Single_Protected_Declaration;
Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is
begin
Visitor.Single_Protected_Declaration (Self);
end Visit;
overriding function To_Single_Protected_Declaration_Text
(Self : in out Single_Protected_Declaration)
return Program.Elements.Single_Protected_Declarations
.Single_Protected_Declaration_Text_Access is
begin
return Self'Unchecked_Access;
end To_Single_Protected_Declaration_Text;
overriding function To_Single_Protected_Declaration_Text
(Self : in out Implicit_Single_Protected_Declaration)
return Program.Elements.Single_Protected_Declarations
.Single_Protected_Declaration_Text_Access is
pragma Unreferenced (Self);
begin
return null;
end To_Single_Protected_Declaration_Text;
end Program.Nodes.Single_Protected_Declarations;
|
with AUnit; use AUnit;
with AUnit.Test_Cases; use AUnit.Test_Cases;
package HistogramTests is
type TestCase is new AUnit.Test_Cases.Test_Case with null record;
procedure Register_Tests(T: in out TestCase);
function Name(T: TestCase) return Message_String;
procedure testBasicHistograms(T : in out Test_Cases.Test_Case'Class);
procedure testRescale(T : in out Test_Cases.Test_Case'Class);
procedure testMultiplication(T: in out Test_Cases.Test_Case'Class);
procedure testProjections(T : in out Test_Cases.Test_Case'Class);
procedure testDistance(T : in out Test_Cases.Test_Case'Class);
end HistogramTests;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . E X C E P T I O N S . M A C H I N E --
-- --
-- S p e c --
-- --
-- Copyright (C) 2013-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Declaration of the machine exception and some associated facilities. The
-- machine exception is the object that is propagated by low level routines
-- and that contains the Ada exception occurrence.
-- This is the version using the GCC EH mechanism
with Ada.Unchecked_Conversion;
with Ada.Exceptions;
package System.Exceptions.Machine is
pragma Preelaborate;
------------------------------------------------
-- Entities to interface with the GCC runtime --
------------------------------------------------
-- These come from "C++ ABI for Itanium: Exception handling", which is
-- the reference for GCC.
-- Return codes from the GCC runtime functions used to propagate
-- an exception.
type Unwind_Reason_Code is
(URC_NO_REASON,
URC_FOREIGN_EXCEPTION_CAUGHT,
URC_PHASE2_ERROR,
URC_PHASE1_ERROR,
URC_NORMAL_STOP,
URC_END_OF_STACK,
URC_HANDLER_FOUND,
URC_INSTALL_CONTEXT,
URC_CONTINUE_UNWIND);
pragma Unreferenced
(URC_NO_REASON,
URC_FOREIGN_EXCEPTION_CAUGHT,
URC_PHASE2_ERROR,
URC_PHASE1_ERROR,
URC_NORMAL_STOP,
URC_END_OF_STACK,
URC_HANDLER_FOUND,
URC_INSTALL_CONTEXT,
URC_CONTINUE_UNWIND);
pragma Convention (C, Unwind_Reason_Code);
-- Phase identifiers
type Unwind_Action is new Integer;
pragma Convention (C, Unwind_Action);
UA_SEARCH_PHASE : constant Unwind_Action := 1;
UA_CLEANUP_PHASE : constant Unwind_Action := 2;
UA_HANDLER_FRAME : constant Unwind_Action := 4;
UA_FORCE_UNWIND : constant Unwind_Action := 8;
UA_END_OF_STACK : constant Unwind_Action := 16; -- GCC extension
pragma Unreferenced
(UA_SEARCH_PHASE,
UA_CLEANUP_PHASE,
UA_HANDLER_FRAME,
UA_FORCE_UNWIND,
UA_END_OF_STACK);
-- Mandatory common header for any exception object handled by the
-- GCC unwinding runtime.
type Exception_Class is mod 2 ** 64;
GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
-- "GNU-Ada\0"
type Unwind_Word is mod 2 ** System.Word_Size;
for Unwind_Word'Size use System.Word_Size;
-- Map the corresponding C type used in Unwind_Exception below
type Unwind_Exception is record
Class : Exception_Class;
Cleanup : System.Address;
Private1 : Unwind_Word;
Private2 : Unwind_Word;
-- Usual exception structure has only two private fields, but the SEH
-- one has six. To avoid making this file more complex, we use six
-- fields on all platforms, wasting a few bytes on some.
Private3 : Unwind_Word;
Private4 : Unwind_Word;
Private5 : Unwind_Word;
Private6 : Unwind_Word;
end record;
pragma Convention (C, Unwind_Exception);
-- Map the GCC struct used for exception handling
for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
-- The C++ ABI mandates the common exception header to be at least
-- doubleword aligned, and the libGCC implementation actually makes it
-- maximally aligned (see unwind.h). See additional comments on the
-- alignment below.
-- There is a subtle issue with the common header alignment, since the C
-- version is aligned on BIGGEST_ALIGNMENT, the Ada version is aligned on
-- Standard'Maximum_Alignment, and those two values don't quite represent
-- the same concepts and so may be decoupled someday. One typical reason
-- is that BIGGEST_ALIGNMENT may be larger than what the underlying system
-- allocator guarantees, and there are extra costs involved in allocating
-- objects aligned to such factors.
-- To deal with the potential alignment differences between the C and Ada
-- representations, the Ada part of the whole structure is only accessed
-- by the personality routine through accessors. Ada specific fields are
-- thus always accessed through consistent layout, and we expect the
-- actual alignment to always be large enough to avoid traps from the C
-- accesses to the common header. Besides, accessors alleviate the need
-- for a C struct whole counterpart, both painful and error-prone to
-- maintain anyway.
type GCC_Exception_Access is access all Unwind_Exception;
-- Pointer to a GCC exception
procedure Unwind_DeleteException (Excp : not null GCC_Exception_Access);
pragma Import (C, Unwind_DeleteException, "_Unwind_DeleteException");
-- Procedure to free any GCC exception
--------------------------------------------------------------
-- GNAT Specific Entities To Deal With The GCC EH Circuitry --
--------------------------------------------------------------
-- A GNAT exception object to be dealt with by the personality routine
-- called by the GCC unwinding runtime.
type GNAT_GCC_Exception is record
Header : Unwind_Exception;
-- ABI Exception header first
Occurrence : aliased Ada.Exceptions.Exception_Occurrence;
-- The Ada occurrence
end record;
pragma Convention (C, GNAT_GCC_Exception);
type GNAT_GCC_Exception_Access is access all GNAT_GCC_Exception;
function To_GCC_Exception is new
Ada.Unchecked_Conversion (System.Address, GCC_Exception_Access);
function To_GNAT_GCC_Exception is new
Ada.Unchecked_Conversion
(GCC_Exception_Access, GNAT_GCC_Exception_Access);
function New_Occurrence return GNAT_GCC_Exception_Access is
(new GNAT_GCC_Exception'
(Header => (Class => GNAT_Exception_Class,
Cleanup => Null_Address,
others => 0),
Occurrence => <>));
-- Allocate and initialize a machine occurrence
end System.Exceptions.Machine;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ U T I L --
-- --
-- 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 Treepr; -- ???For debugging code below
with Aspects; use Aspects;
with Atree; use Atree;
with Casing; use Casing;
with Checks; use Checks;
with Debug; use Debug;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Exp_Disp; use Exp_Disp;
with Exp_Util; use Exp_Util;
with Fname; use Fname;
with Freeze; use Freeze;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet.Sp; use Namet.Sp;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Attr; use Sem_Attr;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Warn; use Sem_Warn;
with Sem_Type; use Sem_Type;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Stand; use Stand;
with Style;
with Stringt; use Stringt;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uname; use Uname;
with GNAT.HTable; use GNAT.HTable;
package body Sem_Util is
-----------------------
-- Local Subprograms --
-----------------------
function Build_Component_Subtype
(C : List_Id;
Loc : Source_Ptr;
T : Entity_Id) return Node_Id;
-- This function builds the subtype for Build_Actual_Subtype_Of_Component
-- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
-- Loc is the source location, T is the original subtype.
function Has_Enabled_Property
(Item_Id : Entity_Id;
Property : Name_Id) return Boolean;
-- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
-- Determine whether an abstract state or a variable denoted by entity
-- Item_Id has enabled property Property.
function Has_Null_Extension (T : Entity_Id) return Boolean;
-- T is a derived tagged type. Check whether the type extension is null.
-- If the parent type is fully initialized, T can be treated as such.
function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
-- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
-- with discriminants whose default values are static, examine only the
-- components in the selected variant to determine whether all of them
-- have a default.
function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
-- ???We retain the old and new algorithms for Requires_Transient_Scope for
-- the time being. New_Requires_Transient_Scope is used by default; the
-- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
-- instead. The intent is to use this temporarily to measure before/after
-- efficiency. Note: when this temporary code is removed, the documentation
-- of dQ in debug.adb should be removed.
procedure Results_Differ
(Id : Entity_Id;
Old_Val : Boolean;
New_Val : Boolean);
-- ???Debugging code. Called when the Old_Val and New_Val differ. This
-- routine will be removed eventially when New_Requires_Transient_Scope
-- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
-- eliminated.
------------------------------
-- Abstract_Interface_List --
------------------------------
function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
Nod : Node_Id;
begin
if Is_Concurrent_Type (Typ) then
-- If we are dealing with a synchronized subtype, go to the base
-- type, whose declaration has the interface list.
-- Shouldn't this be Declaration_Node???
Nod := Parent (Base_Type (Typ));
if Nkind (Nod) = N_Full_Type_Declaration then
return Empty_List;
end if;
elsif Ekind (Typ) = E_Record_Type_With_Private then
if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
Nod := Type_Definition (Parent (Typ));
elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
if Present (Full_View (Typ))
and then
Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
then
Nod := Type_Definition (Parent (Full_View (Typ)));
-- If the full-view is not available we cannot do anything else
-- here (the source has errors).
else
return Empty_List;
end if;
-- Support for generic formals with interfaces is still missing ???
elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
return Empty_List;
else
pragma Assert
(Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
Nod := Parent (Typ);
end if;
elsif Ekind (Typ) = E_Record_Subtype then
Nod := Type_Definition (Parent (Etype (Typ)));
elsif Ekind (Typ) = E_Record_Subtype_With_Private then
-- Recurse, because parent may still be a private extension. Also
-- note that the full view of the subtype or the full view of its
-- base type may (both) be unavailable.
return Abstract_Interface_List (Etype (Typ));
else pragma Assert ((Ekind (Typ)) = E_Record_Type);
if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
Nod := Formal_Type_Definition (Parent (Typ));
else
Nod := Type_Definition (Parent (Typ));
end if;
end if;
return Interface_List (Nod);
end Abstract_Interface_List;
--------------------------------
-- Add_Access_Type_To_Process --
--------------------------------
procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
L : Elist_Id;
begin
Ensure_Freeze_Node (E);
L := Access_Types_To_Process (Freeze_Node (E));
if No (L) then
L := New_Elmt_List;
Set_Access_Types_To_Process (Freeze_Node (E), L);
end if;
Append_Elmt (A, L);
end Add_Access_Type_To_Process;
--------------------------
-- Add_Block_Identifier --
--------------------------
procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
begin
pragma Assert (Nkind (N) = N_Block_Statement);
-- The block already has a label, return its entity
if Present (Identifier (N)) then
Id := Entity (Identifier (N));
-- Create a new block label and set its attributes
else
Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
Set_Etype (Id, Standard_Void_Type);
Set_Parent (Id, N);
Set_Identifier (N, New_Occurrence_Of (Id, Loc));
Set_Block_Node (Id, Identifier (N));
end if;
end Add_Block_Identifier;
----------------------------
-- Add_Global_Declaration --
----------------------------
procedure Add_Global_Declaration (N : Node_Id) is
Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
begin
if No (Declarations (Aux_Node)) then
Set_Declarations (Aux_Node, New_List);
end if;
Append_To (Declarations (Aux_Node), N);
Analyze (N);
end Add_Global_Declaration;
--------------------------------
-- Address_Integer_Convert_OK --
--------------------------------
function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
begin
if Allow_Integer_Address
and then ((Is_Descendant_Of_Address (T1)
and then Is_Private_Type (T1)
and then Is_Integer_Type (T2))
or else
(Is_Descendant_Of_Address (T2)
and then Is_Private_Type (T2)
and then Is_Integer_Type (T1)))
then
return True;
else
return False;
end if;
end Address_Integer_Convert_OK;
-------------------
-- Address_Value --
-------------------
function Address_Value (N : Node_Id) return Node_Id is
Expr : Node_Id := N;
begin
loop
-- For constant, get constant expression
if Is_Entity_Name (Expr)
and then Ekind (Entity (Expr)) = E_Constant
then
Expr := Constant_Value (Entity (Expr));
-- For unchecked conversion, get result to convert
elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
Expr := Expression (Expr);
-- For (common case) of To_Address call, get argument
elsif Nkind (Expr) = N_Function_Call
and then Is_Entity_Name (Name (Expr))
and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
then
Expr := First (Parameter_Associations (Expr));
if Nkind (Expr) = N_Parameter_Association then
Expr := Explicit_Actual_Parameter (Expr);
end if;
-- We finally have the real expression
else
exit;
end if;
end loop;
return Expr;
end Address_Value;
-----------------
-- Addressable --
-----------------
-- For now, just 8/16/32/64
function Addressable (V : Uint) return Boolean is
begin
return V = Uint_8 or else
V = Uint_16 or else
V = Uint_32 or else
V = Uint_64;
end Addressable;
function Addressable (V : Int) return Boolean is
begin
return V = 8 or else
V = 16 or else
V = 32 or else
V = 64;
end Addressable;
---------------------------------
-- Aggregate_Constraint_Checks --
---------------------------------
procedure Aggregate_Constraint_Checks
(Exp : Node_Id;
Check_Typ : Entity_Id)
is
Exp_Typ : constant Entity_Id := Etype (Exp);
begin
if Raises_Constraint_Error (Exp) then
return;
end if;
-- Ada 2005 (AI-230): Generate a conversion to an anonymous access
-- component's type to force the appropriate accessibility checks.
-- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
-- force the corresponding run-time check
if Is_Access_Type (Check_Typ)
and then Is_Local_Anonymous_Access (Check_Typ)
then
Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
Analyze_And_Resolve (Exp, Check_Typ);
Check_Unset_Reference (Exp);
end if;
-- What follows is really expansion activity, so check that expansion
-- is on and is allowed. In GNATprove mode, we also want check flags to
-- be added in the tree, so that the formal verification can rely on
-- those to be present. In GNATprove mode for formal verification, some
-- treatment typically only done during expansion needs to be performed
-- on the tree, but it should not be applied inside generics. Otherwise,
-- this breaks the name resolution mechanism for generic instances.
if not Expander_Active
and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
then
return;
end if;
if Is_Access_Type (Check_Typ)
and then Can_Never_Be_Null (Check_Typ)
and then not Can_Never_Be_Null (Exp_Typ)
then
Install_Null_Excluding_Check (Exp);
end if;
-- First check if we have to insert discriminant checks
if Has_Discriminants (Exp_Typ) then
Apply_Discriminant_Check (Exp, Check_Typ);
-- Next emit length checks for array aggregates
elsif Is_Array_Type (Exp_Typ) then
Apply_Length_Check (Exp, Check_Typ);
-- Finally emit scalar and string checks. If we are dealing with a
-- scalar literal we need to check by hand because the Etype of
-- literals is not necessarily correct.
elsif Is_Scalar_Type (Exp_Typ)
and then Compile_Time_Known_Value (Exp)
then
if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
Apply_Compile_Time_Constraint_Error
(Exp, "value not in range of}??", CE_Range_Check_Failed,
Ent => Base_Type (Check_Typ),
Typ => Base_Type (Check_Typ));
elsif Is_Out_Of_Range (Exp, Check_Typ) then
Apply_Compile_Time_Constraint_Error
(Exp, "value not in range of}??", CE_Range_Check_Failed,
Ent => Check_Typ,
Typ => Check_Typ);
elsif not Range_Checks_Suppressed (Check_Typ) then
Apply_Scalar_Range_Check (Exp, Check_Typ);
end if;
-- Verify that target type is also scalar, to prevent view anomalies
-- in instantiations.
elsif (Is_Scalar_Type (Exp_Typ)
or else Nkind (Exp) = N_String_Literal)
and then Is_Scalar_Type (Check_Typ)
and then Exp_Typ /= Check_Typ
then
if Is_Entity_Name (Exp)
and then Ekind (Entity (Exp)) = E_Constant
then
-- If expression is a constant, it is worthwhile checking whether
-- it is a bound of the type.
if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
or else
(Is_Entity_Name (Type_High_Bound (Check_Typ))
and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
then
return;
else
Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
Analyze_And_Resolve (Exp, Check_Typ);
Check_Unset_Reference (Exp);
end if;
-- Could use a comment on this case ???
else
Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
Analyze_And_Resolve (Exp, Check_Typ);
Check_Unset_Reference (Exp);
end if;
end if;
end Aggregate_Constraint_Checks;
-----------------------
-- Alignment_In_Bits --
-----------------------
function Alignment_In_Bits (E : Entity_Id) return Uint is
begin
return Alignment (E) * System_Storage_Unit;
end Alignment_In_Bits;
--------------------------------------
-- All_Composite_Constraints_Static --
--------------------------------------
function All_Composite_Constraints_Static
(Constr : Node_Id) return Boolean
is
begin
if No (Constr) or else Error_Posted (Constr) then
return True;
end if;
case Nkind (Constr) is
when N_Subexpr =>
if Nkind (Constr) in N_Has_Entity
and then Present (Entity (Constr))
then
if Is_Type (Entity (Constr)) then
return
not Is_Discrete_Type (Entity (Constr))
or else Is_OK_Static_Subtype (Entity (Constr));
end if;
elsif Nkind (Constr) = N_Range then
return
Is_OK_Static_Expression (Low_Bound (Constr))
and then
Is_OK_Static_Expression (High_Bound (Constr));
elsif Nkind (Constr) = N_Attribute_Reference
and then Attribute_Name (Constr) = Name_Range
then
return
Is_OK_Static_Expression
(Type_Low_Bound (Etype (Prefix (Constr))))
and then
Is_OK_Static_Expression
(Type_High_Bound (Etype (Prefix (Constr))));
end if;
return
not Present (Etype (Constr)) -- previous error
or else not Is_Discrete_Type (Etype (Constr))
or else Is_OK_Static_Expression (Constr);
when N_Discriminant_Association =>
return All_Composite_Constraints_Static (Expression (Constr));
when N_Range_Constraint =>
return
All_Composite_Constraints_Static (Range_Expression (Constr));
when N_Index_Or_Discriminant_Constraint =>
declare
One_Cstr : Entity_Id;
begin
One_Cstr := First (Constraints (Constr));
while Present (One_Cstr) loop
if not All_Composite_Constraints_Static (One_Cstr) then
return False;
end if;
Next (One_Cstr);
end loop;
end;
return True;
when N_Subtype_Indication =>
return
All_Composite_Constraints_Static (Subtype_Mark (Constr))
and then
All_Composite_Constraints_Static (Constraint (Constr));
when others =>
raise Program_Error;
end case;
end All_Composite_Constraints_Static;
---------------------------------
-- Append_Inherited_Subprogram --
---------------------------------
procedure Append_Inherited_Subprogram (S : Entity_Id) is
Par : constant Entity_Id := Alias (S);
-- The parent subprogram
Scop : constant Entity_Id := Scope (Par);
-- The scope of definition of the parent subprogram
Typ : constant Entity_Id := Defining_Entity (Parent (S));
-- The derived type of which S is a primitive operation
Decl : Node_Id;
Next_E : Entity_Id;
begin
if Ekind (Current_Scope) = E_Package
and then In_Private_Part (Current_Scope)
and then Has_Private_Declaration (Typ)
and then Is_Tagged_Type (Typ)
and then Scop = Current_Scope
then
-- The inherited operation is available at the earliest place after
-- the derived type declaration ( RM 7.3.1 (6/1)). This is only
-- relevant for type extensions. If the parent operation appears
-- after the type extension, the operation is not visible.
Decl := First
(Visible_Declarations
(Package_Specification (Current_Scope)));
while Present (Decl) loop
if Nkind (Decl) = N_Private_Extension_Declaration
and then Defining_Entity (Decl) = Typ
then
if Sloc (Decl) > Sloc (Par) then
Next_E := Next_Entity (Par);
Set_Next_Entity (Par, S);
Set_Next_Entity (S, Next_E);
return;
else
exit;
end if;
end if;
Next (Decl);
end loop;
end if;
-- If partial view is not a type extension, or it appears before the
-- subprogram declaration, insert normally at end of entity list.
Append_Entity (S, Current_Scope);
end Append_Inherited_Subprogram;
-----------------------------------------
-- Apply_Compile_Time_Constraint_Error --
-----------------------------------------
procedure Apply_Compile_Time_Constraint_Error
(N : Node_Id;
Msg : String;
Reason : RT_Exception_Code;
Ent : Entity_Id := Empty;
Typ : Entity_Id := Empty;
Loc : Source_Ptr := No_Location;
Rep : Boolean := True;
Warn : Boolean := False)
is
Stat : constant Boolean := Is_Static_Expression (N);
R_Stat : constant Node_Id :=
Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
Rtyp : Entity_Id;
begin
if No (Typ) then
Rtyp := Etype (N);
else
Rtyp := Typ;
end if;
Discard_Node
(Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
-- In GNATprove mode, do not replace the node with an exception raised.
-- In such a case, either the call to Compile_Time_Constraint_Error
-- issues an error which stops analysis, or it issues a warning in
-- a few cases where a suitable check flag is set for GNATprove to
-- generate a check message.
if not Rep or GNATprove_Mode then
return;
end if;
-- Now we replace the node by an N_Raise_Constraint_Error node
-- This does not need reanalyzing, so set it as analyzed now.
Rewrite (N, R_Stat);
Set_Analyzed (N, True);
Set_Etype (N, Rtyp);
Set_Raises_Constraint_Error (N);
-- Now deal with possible local raise handling
Possible_Local_Raise (N, Standard_Constraint_Error);
-- If the original expression was marked as static, the result is
-- still marked as static, but the Raises_Constraint_Error flag is
-- always set so that further static evaluation is not attempted.
if Stat then
Set_Is_Static_Expression (N);
end if;
end Apply_Compile_Time_Constraint_Error;
---------------------------
-- Async_Readers_Enabled --
---------------------------
function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
begin
return Has_Enabled_Property (Id, Name_Async_Readers);
end Async_Readers_Enabled;
---------------------------
-- Async_Writers_Enabled --
---------------------------
function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
begin
return Has_Enabled_Property (Id, Name_Async_Writers);
end Async_Writers_Enabled;
--------------------------------------
-- Available_Full_View_Of_Component --
--------------------------------------
function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
ST : constant Entity_Id := Scope (T);
SCT : constant Entity_Id := Scope (Component_Type (T));
begin
return In_Open_Scopes (ST)
and then In_Open_Scopes (SCT)
and then Scope_Depth (ST) >= Scope_Depth (SCT);
end Available_Full_View_Of_Component;
-------------------
-- Bad_Attribute --
-------------------
procedure Bad_Attribute
(N : Node_Id;
Nam : Name_Id;
Warn : Boolean := False)
is
begin
Error_Msg_Warn := Warn;
Error_Msg_N ("unrecognized attribute&<<", N);
-- Check for possible misspelling
Error_Msg_Name_1 := First_Attribute_Name;
while Error_Msg_Name_1 <= Last_Attribute_Name loop
if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
Error_Msg_N -- CODEFIX
("\possible misspelling of %<<", N);
exit;
end if;
Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
end loop;
end Bad_Attribute;
--------------------------------
-- Bad_Predicated_Subtype_Use --
--------------------------------
procedure Bad_Predicated_Subtype_Use
(Msg : String;
N : Node_Id;
Typ : Entity_Id;
Suggest_Static : Boolean := False)
is
Gen : Entity_Id;
begin
-- Avoid cascaded errors
if Error_Posted (N) then
return;
end if;
if Inside_A_Generic then
Gen := Current_Scope;
while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
Gen := Scope (Gen);
end loop;
if No (Gen) then
return;
end if;
if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
Set_No_Predicate_On_Actual (Typ);
end if;
elsif Has_Predicates (Typ) then
if Is_Generic_Actual_Type (Typ) then
-- The restriction on loop parameters is only that the type
-- should have no dynamic predicates.
if Nkind (Parent (N)) = N_Loop_Parameter_Specification
and then not Has_Dynamic_Predicate_Aspect (Typ)
and then Is_OK_Static_Subtype (Typ)
then
return;
end if;
Gen := Current_Scope;
while not Is_Generic_Instance (Gen) loop
Gen := Scope (Gen);
end loop;
pragma Assert (Present (Gen));
if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_FE (Msg & "<<", N, Typ);
Error_Msg_F ("\Program_Error [<<", N);
Insert_Action (N,
Make_Raise_Program_Error (Sloc (N),
Reason => PE_Bad_Predicated_Generic_Type));
else
Error_Msg_FE (Msg & "<<", N, Typ);
end if;
else
Error_Msg_FE (Msg, N, Typ);
end if;
-- Emit an optional suggestion on how to remedy the error if the
-- context warrants it.
if Suggest_Static and then Has_Static_Predicate (Typ) then
Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
end if;
end if;
end Bad_Predicated_Subtype_Use;
-----------------------------------------
-- Bad_Unordered_Enumeration_Reference --
-----------------------------------------
function Bad_Unordered_Enumeration_Reference
(N : Node_Id;
T : Entity_Id) return Boolean
is
begin
return Is_Enumeration_Type (T)
and then Warn_On_Unordered_Enumeration_Type
and then not Is_Generic_Type (T)
and then Comes_From_Source (N)
and then not Has_Pragma_Ordered (T)
and then not In_Same_Extended_Unit (N, T);
end Bad_Unordered_Enumeration_Reference;
--------------------------
-- Build_Actual_Subtype --
--------------------------
function Build_Actual_Subtype
(T : Entity_Id;
N : Node_Or_Entity_Id) return Node_Id
is
Loc : Source_Ptr;
-- Normally Sloc (N), but may point to corresponding body in some cases
Constraints : List_Id;
Decl : Node_Id;
Discr : Entity_Id;
Hi : Node_Id;
Lo : Node_Id;
Subt : Entity_Id;
Disc_Type : Entity_Id;
Obj : Node_Id;
begin
Loc := Sloc (N);
if Nkind (N) = N_Defining_Identifier then
Obj := New_Occurrence_Of (N, Loc);
-- If this is a formal parameter of a subprogram declaration, and
-- we are compiling the body, we want the declaration for the
-- actual subtype to carry the source position of the body, to
-- prevent anomalies in gdb when stepping through the code.
if Is_Formal (N) then
declare
Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
begin
if Nkind (Decl) = N_Subprogram_Declaration
and then Present (Corresponding_Body (Decl))
then
Loc := Sloc (Corresponding_Body (Decl));
end if;
end;
end if;
else
Obj := N;
end if;
if Is_Array_Type (T) then
Constraints := New_List;
for J in 1 .. Number_Dimensions (T) loop
-- Build an array subtype declaration with the nominal subtype and
-- the bounds of the actual. Add the declaration in front of the
-- local declarations for the subprogram, for analysis before any
-- reference to the formal in the body.
Lo :=
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
Attribute_Name => Name_First,
Expressions => New_List (
Make_Integer_Literal (Loc, J)));
Hi :=
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
Attribute_Name => Name_Last,
Expressions => New_List (
Make_Integer_Literal (Loc, J)));
Append (Make_Range (Loc, Lo, Hi), Constraints);
end loop;
-- If the type has unknown discriminants there is no constrained
-- subtype to build. This is never called for a formal or for a
-- lhs, so returning the type is ok ???
elsif Has_Unknown_Discriminants (T) then
return T;
else
Constraints := New_List;
-- Type T is a generic derived type, inherit the discriminants from
-- the parent type.
if Is_Private_Type (T)
and then No (Full_View (T))
-- T was flagged as an error if it was declared as a formal
-- derived type with known discriminants. In this case there
-- is no need to look at the parent type since T already carries
-- its own discriminants.
and then not Error_Posted (T)
then
Disc_Type := Etype (Base_Type (T));
else
Disc_Type := T;
end if;
Discr := First_Discriminant (Disc_Type);
while Present (Discr) loop
Append_To (Constraints,
Make_Selected_Component (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Obj),
Selector_Name => New_Occurrence_Of (Discr, Loc)));
Next_Discriminant (Discr);
end loop;
end if;
Subt := Make_Temporary (Loc, 'S', Related_Node => N);
Set_Is_Internal (Subt);
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Subt,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (T, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constraints)));
Mark_Rewrite_Insertion (Decl);
return Decl;
end Build_Actual_Subtype;
---------------------------------------
-- Build_Actual_Subtype_Of_Component --
---------------------------------------
function Build_Actual_Subtype_Of_Component
(T : Entity_Id;
N : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Prefix (N);
D : Elmt_Id;
Id : Node_Id;
Index_Typ : Entity_Id;
Desig_Typ : Entity_Id;
-- This is either a copy of T, or if T is an access type, then it is
-- the directly designated type of this access type.
function Build_Actual_Array_Constraint return List_Id;
-- If one or more of the bounds of the component depends on
-- discriminants, build actual constraint using the discriminants
-- of the prefix.
function Build_Actual_Record_Constraint return List_Id;
-- Similar to previous one, for discriminated components constrained
-- by the discriminant of the enclosing object.
-----------------------------------
-- Build_Actual_Array_Constraint --
-----------------------------------
function Build_Actual_Array_Constraint return List_Id is
Constraints : constant List_Id := New_List;
Indx : Node_Id;
Hi : Node_Id;
Lo : Node_Id;
Old_Hi : Node_Id;
Old_Lo : Node_Id;
begin
Indx := First_Index (Desig_Typ);
while Present (Indx) loop
Old_Lo := Type_Low_Bound (Etype (Indx));
Old_Hi := Type_High_Bound (Etype (Indx));
if Denotes_Discriminant (Old_Lo) then
Lo :=
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (P),
Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
else
Lo := New_Copy_Tree (Old_Lo);
-- The new bound will be reanalyzed in the enclosing
-- declaration. For literal bounds that come from a type
-- declaration, the type of the context must be imposed, so
-- insure that analysis will take place. For non-universal
-- types this is not strictly necessary.
Set_Analyzed (Lo, False);
end if;
if Denotes_Discriminant (Old_Hi) then
Hi :=
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (P),
Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
else
Hi := New_Copy_Tree (Old_Hi);
Set_Analyzed (Hi, False);
end if;
Append (Make_Range (Loc, Lo, Hi), Constraints);
Next_Index (Indx);
end loop;
return Constraints;
end Build_Actual_Array_Constraint;
------------------------------------
-- Build_Actual_Record_Constraint --
------------------------------------
function Build_Actual_Record_Constraint return List_Id is
Constraints : constant List_Id := New_List;
D : Elmt_Id;
D_Val : Node_Id;
begin
D := First_Elmt (Discriminant_Constraint (Desig_Typ));
while Present (D) loop
if Denotes_Discriminant (Node (D)) then
D_Val := Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (P),
Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
else
D_Val := New_Copy_Tree (Node (D));
end if;
Append (D_Val, Constraints);
Next_Elmt (D);
end loop;
return Constraints;
end Build_Actual_Record_Constraint;
-- Start of processing for Build_Actual_Subtype_Of_Component
begin
-- Why the test for Spec_Expression mode here???
if In_Spec_Expression then
return Empty;
-- More comments for the rest of this body would be good ???
elsif Nkind (N) = N_Explicit_Dereference then
if Is_Composite_Type (T)
and then not Is_Constrained (T)
and then not (Is_Class_Wide_Type (T)
and then Is_Constrained (Root_Type (T)))
and then not Has_Unknown_Discriminants (T)
then
-- If the type of the dereference is already constrained, it is an
-- actual subtype.
if Is_Array_Type (Etype (N))
and then Is_Constrained (Etype (N))
then
return Empty;
else
Remove_Side_Effects (P);
return Build_Actual_Subtype (T, N);
end if;
else
return Empty;
end if;
end if;
if Ekind (T) = E_Access_Subtype then
Desig_Typ := Designated_Type (T);
else
Desig_Typ := T;
end if;
if Ekind (Desig_Typ) = E_Array_Subtype then
Id := First_Index (Desig_Typ);
while Present (Id) loop
Index_Typ := Underlying_Type (Etype (Id));
if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
or else
Denotes_Discriminant (Type_High_Bound (Index_Typ))
then
Remove_Side_Effects (P);
return
Build_Component_Subtype
(Build_Actual_Array_Constraint, Loc, Base_Type (T));
end if;
Next_Index (Id);
end loop;
elsif Is_Composite_Type (Desig_Typ)
and then Has_Discriminants (Desig_Typ)
and then not Has_Unknown_Discriminants (Desig_Typ)
then
if Is_Private_Type (Desig_Typ)
and then No (Discriminant_Constraint (Desig_Typ))
then
Desig_Typ := Full_View (Desig_Typ);
end if;
D := First_Elmt (Discriminant_Constraint (Desig_Typ));
while Present (D) loop
if Denotes_Discriminant (Node (D)) then
Remove_Side_Effects (P);
return
Build_Component_Subtype (
Build_Actual_Record_Constraint, Loc, Base_Type (T));
end if;
Next_Elmt (D);
end loop;
end if;
-- If none of the above, the actual and nominal subtypes are the same
return Empty;
end Build_Actual_Subtype_Of_Component;
-----------------------------
-- Build_Component_Subtype --
-----------------------------
function Build_Component_Subtype
(C : List_Id;
Loc : Source_Ptr;
T : Entity_Id) return Node_Id
is
Subt : Entity_Id;
Decl : Node_Id;
begin
-- Unchecked_Union components do not require component subtypes
if Is_Unchecked_Union (T) then
return Empty;
end if;
Subt := Make_Temporary (Loc, 'S');
Set_Is_Internal (Subt);
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Subt,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => C)));
Mark_Rewrite_Insertion (Decl);
return Decl;
end Build_Component_Subtype;
---------------------------
-- Build_Default_Subtype --
---------------------------
function Build_Default_Subtype
(T : Entity_Id;
N : Node_Id) return Entity_Id
is
Loc : constant Source_Ptr := Sloc (N);
Disc : Entity_Id;
Bas : Entity_Id;
-- The base type that is to be constrained by the defaults
begin
if not Has_Discriminants (T) or else Is_Constrained (T) then
return T;
end if;
Bas := Base_Type (T);
-- If T is non-private but its base type is private, this is the
-- completion of a subtype declaration whose parent type is private
-- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
-- are to be found in the full view of the base. Check that the private
-- status of T and its base differ.
if Is_Private_Type (Bas)
and then not Is_Private_Type (T)
and then Present (Full_View (Bas))
then
Bas := Full_View (Bas);
end if;
Disc := First_Discriminant (T);
if No (Discriminant_Default_Value (Disc)) then
return T;
end if;
declare
Act : constant Entity_Id := Make_Temporary (Loc, 'S');
Constraints : constant List_Id := New_List;
Decl : Node_Id;
begin
while Present (Disc) loop
Append_To (Constraints,
New_Copy_Tree (Discriminant_Default_Value (Disc)));
Next_Discriminant (Disc);
end loop;
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Act,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Bas, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constraints)));
Insert_Action (N, Decl);
-- If the context is a component declaration the subtype declaration
-- will be analyzed when the enclosing type is frozen, otherwise do
-- it now.
if Ekind (Current_Scope) /= E_Record_Type then
Analyze (Decl);
end if;
return Act;
end;
end Build_Default_Subtype;
--------------------------------------------
-- Build_Discriminal_Subtype_Of_Component --
--------------------------------------------
function Build_Discriminal_Subtype_Of_Component
(T : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (T);
D : Elmt_Id;
Id : Node_Id;
function Build_Discriminal_Array_Constraint return List_Id;
-- If one or more of the bounds of the component depends on
-- discriminants, build actual constraint using the discriminants
-- of the prefix.
function Build_Discriminal_Record_Constraint return List_Id;
-- Similar to previous one, for discriminated components constrained by
-- the discriminant of the enclosing object.
----------------------------------------
-- Build_Discriminal_Array_Constraint --
----------------------------------------
function Build_Discriminal_Array_Constraint return List_Id is
Constraints : constant List_Id := New_List;
Indx : Node_Id;
Hi : Node_Id;
Lo : Node_Id;
Old_Hi : Node_Id;
Old_Lo : Node_Id;
begin
Indx := First_Index (T);
while Present (Indx) loop
Old_Lo := Type_Low_Bound (Etype (Indx));
Old_Hi := Type_High_Bound (Etype (Indx));
if Denotes_Discriminant (Old_Lo) then
Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
else
Lo := New_Copy_Tree (Old_Lo);
end if;
if Denotes_Discriminant (Old_Hi) then
Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
else
Hi := New_Copy_Tree (Old_Hi);
end if;
Append (Make_Range (Loc, Lo, Hi), Constraints);
Next_Index (Indx);
end loop;
return Constraints;
end Build_Discriminal_Array_Constraint;
-----------------------------------------
-- Build_Discriminal_Record_Constraint --
-----------------------------------------
function Build_Discriminal_Record_Constraint return List_Id is
Constraints : constant List_Id := New_List;
D : Elmt_Id;
D_Val : Node_Id;
begin
D := First_Elmt (Discriminant_Constraint (T));
while Present (D) loop
if Denotes_Discriminant (Node (D)) then
D_Val :=
New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
else
D_Val := New_Copy_Tree (Node (D));
end if;
Append (D_Val, Constraints);
Next_Elmt (D);
end loop;
return Constraints;
end Build_Discriminal_Record_Constraint;
-- Start of processing for Build_Discriminal_Subtype_Of_Component
begin
if Ekind (T) = E_Array_Subtype then
Id := First_Index (T);
while Present (Id) loop
if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
or else
Denotes_Discriminant (Type_High_Bound (Etype (Id)))
then
return Build_Component_Subtype
(Build_Discriminal_Array_Constraint, Loc, T);
end if;
Next_Index (Id);
end loop;
elsif Ekind (T) = E_Record_Subtype
and then Has_Discriminants (T)
and then not Has_Unknown_Discriminants (T)
then
D := First_Elmt (Discriminant_Constraint (T));
while Present (D) loop
if Denotes_Discriminant (Node (D)) then
return Build_Component_Subtype
(Build_Discriminal_Record_Constraint, Loc, T);
end if;
Next_Elmt (D);
end loop;
end if;
-- If none of the above, the actual and nominal subtypes are the same
return Empty;
end Build_Discriminal_Subtype_Of_Component;
------------------------------
-- Build_Elaboration_Entity --
------------------------------
procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Decl : Node_Id;
Elab_Ent : Entity_Id;
procedure Set_Package_Name (Ent : Entity_Id);
-- Given an entity, sets the fully qualified name of the entity in
-- Name_Buffer, with components separated by double underscores. This
-- is a recursive routine that climbs the scope chain to Standard.
----------------------
-- Set_Package_Name --
----------------------
procedure Set_Package_Name (Ent : Entity_Id) is
begin
if Scope (Ent) /= Standard_Standard then
Set_Package_Name (Scope (Ent));
declare
Nam : constant String := Get_Name_String (Chars (Ent));
begin
Name_Buffer (Name_Len + 1) := '_';
Name_Buffer (Name_Len + 2) := '_';
Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
Name_Len := Name_Len + Nam'Length + 2;
end;
else
Get_Name_String (Chars (Ent));
end if;
end Set_Package_Name;
-- Start of processing for Build_Elaboration_Entity
begin
-- Ignore call if already constructed
if Present (Elaboration_Entity (Spec_Id)) then
return;
-- Ignore in ASIS mode, elaboration entity is not in source and plays
-- no role in analysis.
elsif ASIS_Mode then
return;
-- See if we need elaboration entity.
-- We always need an elaboration entity when preserving control flow, as
-- we want to remain explicit about the unit's elaboration order.
elsif Opt.Suppress_Control_Flow_Optimizations then
null;
-- We always need an elaboration entity for the dynamic elaboration
-- model, since it is needed to properly generate the PE exception for
-- access before elaboration.
elsif Dynamic_Elaboration_Checks then
null;
-- For the static model, we don't need the elaboration counter if this
-- unit is sure to have no elaboration code, since that means there
-- is no elaboration unit to be called. Note that we can't just decide
-- after the fact by looking to see whether there was elaboration code,
-- because that's too late to make this decision.
elsif Restriction_Active (No_Elaboration_Code) then
return;
-- Similarly, for the static model, we can skip the elaboration counter
-- if we have the No_Multiple_Elaboration restriction, since for the
-- static model, that's the only purpose of the counter (to avoid
-- multiple elaboration).
elsif Restriction_Active (No_Multiple_Elaboration) then
return;
end if;
-- Here we need the elaboration entity
-- Construct name of elaboration entity as xxx_E, where xxx is the unit
-- name with dots replaced by double underscore. We have to manually
-- construct this name, since it will be elaborated in the outer scope,
-- and thus will not have the unit name automatically prepended.
Set_Package_Name (Spec_Id);
Add_Str_To_Name_Buffer ("_E");
-- Create elaboration counter
Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
Set_Elaboration_Entity (Spec_Id, Elab_Ent);
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Elab_Ent,
Object_Definition =>
New_Occurrence_Of (Standard_Short_Integer, Loc),
Expression => Make_Integer_Literal (Loc, Uint_0));
Push_Scope (Standard_Standard);
Add_Global_Declaration (Decl);
Pop_Scope;
-- Reset True_Constant indication, since we will indeed assign a value
-- to the variable in the binder main. We also kill the Current_Value
-- and Last_Assignment fields for the same reason.
Set_Is_True_Constant (Elab_Ent, False);
Set_Current_Value (Elab_Ent, Empty);
Set_Last_Assignment (Elab_Ent, Empty);
-- We do not want any further qualification of the name (if we did not
-- do this, we would pick up the name of the generic package in the case
-- of a library level generic instantiation).
Set_Has_Qualified_Name (Elab_Ent);
Set_Has_Fully_Qualified_Name (Elab_Ent);
end Build_Elaboration_Entity;
--------------------------------
-- Build_Explicit_Dereference --
--------------------------------
procedure Build_Explicit_Dereference
(Expr : Node_Id;
Disc : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Expr);
I : Interp_Index;
It : Interp;
begin
-- An entity of a type with a reference aspect is overloaded with
-- both interpretations: with and without the dereference. Now that
-- the dereference is made explicit, set the type of the node properly,
-- to prevent anomalies in the backend. Same if the expression is an
-- overloaded function call whose return type has a reference aspect.
if Is_Entity_Name (Expr) then
Set_Etype (Expr, Etype (Entity (Expr)));
-- The designated entity will not be examined again when resolving
-- the dereference, so generate a reference to it now.
Generate_Reference (Entity (Expr), Expr);
elsif Nkind (Expr) = N_Function_Call then
-- If the name of the indexing function is overloaded, locate the one
-- whose return type has an implicit dereference on the desired
-- discriminant, and set entity and type of function call.
if Is_Overloaded (Name (Expr)) then
Get_First_Interp (Name (Expr), I, It);
while Present (It.Nam) loop
if Ekind ((It.Typ)) = E_Record_Type
and then First_Entity ((It.Typ)) = Disc
then
Set_Entity (Name (Expr), It.Nam);
Set_Etype (Name (Expr), Etype (It.Nam));
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- Set type of call from resolved function name.
Set_Etype (Expr, Etype (Name (Expr)));
end if;
Set_Is_Overloaded (Expr, False);
-- The expression will often be a generalized indexing that yields a
-- container element that is then dereferenced, in which case the
-- generalized indexing call is also non-overloaded.
if Nkind (Expr) = N_Indexed_Component
and then Present (Generalized_Indexing (Expr))
then
Set_Is_Overloaded (Generalized_Indexing (Expr), False);
end if;
Rewrite (Expr,
Make_Explicit_Dereference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Relocate_Node (Expr),
Selector_Name => New_Occurrence_Of (Disc, Loc))));
Set_Etype (Prefix (Expr), Etype (Disc));
Set_Etype (Expr, Designated_Type (Etype (Disc)));
end Build_Explicit_Dereference;
-----------------------------------
-- Cannot_Raise_Constraint_Error --
-----------------------------------
function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
begin
if Compile_Time_Known_Value (Expr) then
return True;
elsif Do_Range_Check (Expr) then
return False;
elsif Raises_Constraint_Error (Expr) then
return False;
else
case Nkind (Expr) is
when N_Identifier =>
return True;
when N_Expanded_Name =>
return True;
when N_Selected_Component =>
return not Do_Discriminant_Check (Expr);
when N_Attribute_Reference =>
if Do_Overflow_Check (Expr) then
return False;
elsif No (Expressions (Expr)) then
return True;
else
declare
N : Node_Id;
begin
N := First (Expressions (Expr));
while Present (N) loop
if Cannot_Raise_Constraint_Error (N) then
Next (N);
else
return False;
end if;
end loop;
return True;
end;
end if;
when N_Type_Conversion =>
if Do_Overflow_Check (Expr)
or else Do_Length_Check (Expr)
or else Do_Tag_Check (Expr)
then
return False;
else
return Cannot_Raise_Constraint_Error (Expression (Expr));
end if;
when N_Unchecked_Type_Conversion =>
return Cannot_Raise_Constraint_Error (Expression (Expr));
when N_Unary_Op =>
if Do_Overflow_Check (Expr) then
return False;
else
return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
end if;
when N_Op_Divide
| N_Op_Mod
| N_Op_Rem
=>
if Do_Division_Check (Expr)
or else
Do_Overflow_Check (Expr)
then
return False;
else
return
Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
and then
Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
end if;
when N_Op_Add
| N_Op_And
| N_Op_Concat
| N_Op_Eq
| N_Op_Expon
| N_Op_Ge
| N_Op_Gt
| N_Op_Le
| N_Op_Lt
| N_Op_Multiply
| N_Op_Ne
| N_Op_Or
| N_Op_Rotate_Left
| N_Op_Rotate_Right
| N_Op_Shift_Left
| N_Op_Shift_Right
| N_Op_Shift_Right_Arithmetic
| N_Op_Subtract
| N_Op_Xor
=>
if Do_Overflow_Check (Expr) then
return False;
else
return
Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
and then
Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
end if;
when others =>
return False;
end case;
end if;
end Cannot_Raise_Constraint_Error;
-----------------------------
-- Check_Part_Of_Reference --
-----------------------------
procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
Decl : Node_Id;
OK_Use : Boolean := False;
Par : Node_Id;
Prag_Nam : Name_Id;
Spec_Id : Entity_Id;
begin
-- Traverse the parent chain looking for a suitable context for the
-- reference to the concurrent constituent.
Par := Parent (Ref);
while Present (Par) loop
if Nkind (Par) = N_Pragma then
Prag_Nam := Pragma_Name (Par);
-- A concurrent constituent is allowed to appear in pragmas
-- Initial_Condition and Initializes as this is part of the
-- elaboration checks for the constituent (SPARK RM 9.3).
if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
OK_Use := True;
exit;
-- When the reference appears within pragma Depends or Global,
-- check whether the pragma applies to a single task type. Note
-- that the pragma is not encapsulated by the type definition,
-- but this is still a valid context.
elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
Decl := Find_Related_Declaration_Or_Body (Par);
if Nkind (Decl) = N_Object_Declaration
and then Defining_Entity (Decl) = Conc_Typ
then
OK_Use := True;
exit;
end if;
end if;
-- The reference appears somewhere in the definition of the single
-- protected/task type (SPARK RM 9.3).
elsif Nkind_In (Par, N_Single_Protected_Declaration,
N_Single_Task_Declaration)
and then Defining_Entity (Par) = Conc_Typ
then
OK_Use := True;
exit;
-- The reference appears within the expanded declaration or the body
-- of the single protected/task type (SPARK RM 9.3).
elsif Nkind_In (Par, N_Protected_Body,
N_Protected_Type_Declaration,
N_Task_Body,
N_Task_Type_Declaration)
then
Spec_Id := Unique_Defining_Entity (Par);
if Present (Anonymous_Object (Spec_Id))
and then Anonymous_Object (Spec_Id) = Conc_Typ
then
OK_Use := True;
exit;
end if;
-- The reference has been relocated within an internally generated
-- package or subprogram. Assume that the reference is legal as the
-- real check was already performed in the original context of the
-- reference.
elsif Nkind_In (Par, N_Package_Body,
N_Package_Declaration,
N_Subprogram_Body,
N_Subprogram_Declaration)
and then not Comes_From_Source (Par)
then
OK_Use := True;
exit;
-- The reference has been relocated to an inlined body for GNATprove.
-- Assume that the reference is legal as the real check was already
-- performed in the original context of the reference.
elsif GNATprove_Mode
and then Nkind (Par) = N_Subprogram_Body
and then Chars (Defining_Entity (Par)) = Name_uParent
then
OK_Use := True;
exit;
end if;
Par := Parent (Par);
end loop;
-- The reference is illegal as it appears outside the definition or
-- body of the single protected/task type.
if not OK_Use then
Error_Msg_NE
("reference to variable & cannot appear in this context",
Ref, Var_Id);
Error_Msg_Name_1 := Chars (Var_Id);
if Ekind (Conc_Typ) = E_Protected_Type then
Error_Msg_NE
("\% is constituent of single protected type &", Ref, Conc_Typ);
else
Error_Msg_NE
("\% is constituent of single task type &", Ref, Conc_Typ);
end if;
end if;
end Check_Part_Of_Reference;
-----------------------------------------
-- Check_Dynamically_Tagged_Expression --
-----------------------------------------
procedure Check_Dynamically_Tagged_Expression
(Expr : Node_Id;
Typ : Entity_Id;
Related_Nod : Node_Id)
is
begin
pragma Assert (Is_Tagged_Type (Typ));
-- In order to avoid spurious errors when analyzing the expanded code,
-- this check is done only for nodes that come from source and for
-- actuals of generic instantiations.
if (Comes_From_Source (Related_Nod)
or else In_Generic_Actual (Expr))
and then (Is_Class_Wide_Type (Etype (Expr))
or else Is_Dynamically_Tagged (Expr))
and then Is_Tagged_Type (Typ)
and then not Is_Class_Wide_Type (Typ)
then
Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
end if;
end Check_Dynamically_Tagged_Expression;
--------------------------
-- Check_Fully_Declared --
--------------------------
procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
begin
if Ekind (T) = E_Incomplete_Type then
-- Ada 2005 (AI-50217): If the type is available through a limited
-- with_clause, verify that its full view has been analyzed.
if From_Limited_With (T)
and then Present (Non_Limited_View (T))
and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
then
-- The non-limited view is fully declared
null;
else
Error_Msg_NE
("premature usage of incomplete}", N, First_Subtype (T));
end if;
-- Need comments for these tests ???
elsif Has_Private_Component (T)
and then not Is_Generic_Type (Root_Type (T))
and then not In_Spec_Expression
then
-- Special case: if T is the anonymous type created for a single
-- task or protected object, use the name of the source object.
if Is_Concurrent_Type (T)
and then not Comes_From_Source (T)
and then Nkind (N) = N_Object_Declaration
then
Error_Msg_NE
("type of& has incomplete component",
N, Defining_Identifier (N));
else
Error_Msg_NE
("premature usage of incomplete}",
N, First_Subtype (T));
end if;
end if;
end Check_Fully_Declared;
-------------------------------------------
-- Check_Function_With_Address_Parameter --
-------------------------------------------
procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
F : Entity_Id;
T : Entity_Id;
begin
F := First_Formal (Subp_Id);
while Present (F) loop
T := Etype (F);
if Is_Private_Type (T) and then Present (Full_View (T)) then
T := Full_View (T);
end if;
if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
Set_Is_Pure (Subp_Id, False);
exit;
end if;
Next_Formal (F);
end loop;
end Check_Function_With_Address_Parameter;
-------------------------------------
-- Check_Function_Writable_Actuals --
-------------------------------------
procedure Check_Function_Writable_Actuals (N : Node_Id) is
Writable_Actuals_List : Elist_Id := No_Elist;
Identifiers_List : Elist_Id := No_Elist;
Aggr_Error_Node : Node_Id := Empty;
Error_Node : Node_Id := Empty;
procedure Collect_Identifiers (N : Node_Id);
-- In a single traversal of subtree N collect in Writable_Actuals_List
-- all the actuals of functions with writable actuals, and in the list
-- Identifiers_List collect all the identifiers that are not actuals of
-- functions with writable actuals. If a writable actual is referenced
-- twice as writable actual then Error_Node is set to reference its
-- second occurrence, the error is reported, and the tree traversal
-- is abandoned.
function Get_Function_Id (Call : Node_Id) return Entity_Id;
-- Return the entity associated with the function call
procedure Preanalyze_Without_Errors (N : Node_Id);
-- Preanalyze N without reporting errors. Very dubious, you can't just
-- go analyzing things more than once???
-------------------------
-- Collect_Identifiers --
-------------------------
procedure Collect_Identifiers (N : Node_Id) is
function Check_Node (N : Node_Id) return Traverse_Result;
-- Process a single node during the tree traversal to collect the
-- writable actuals of functions and all the identifiers which are
-- not writable actuals of functions.
function Contains (List : Elist_Id; N : Node_Id) return Boolean;
-- Returns True if List has a node whose Entity is Entity (N)
----------------
-- Check_Node --
----------------
function Check_Node (N : Node_Id) return Traverse_Result is
Is_Writable_Actual : Boolean := False;
Id : Entity_Id;
begin
if Nkind (N) = N_Identifier then
-- No analysis possible if the entity is not decorated
if No (Entity (N)) then
return Skip;
-- Don't collect identifiers of packages, called functions, etc
elsif Ekind_In (Entity (N), E_Package,
E_Function,
E_Procedure,
E_Entry)
then
return Skip;
-- For rewritten nodes, continue the traversal in the original
-- subtree. Needed to handle aggregates in original expressions
-- extracted from the tree by Remove_Side_Effects.
elsif Is_Rewrite_Substitution (N) then
Collect_Identifiers (Original_Node (N));
return Skip;
-- For now we skip aggregate discriminants, since they require
-- performing the analysis in two phases to identify conflicts:
-- first one analyzing discriminants and second one analyzing
-- the rest of components (since at run time, discriminants are
-- evaluated prior to components): too much computation cost
-- to identify a corner case???
elsif Nkind (Parent (N)) = N_Component_Association
and then Nkind_In (Parent (Parent (N)),
N_Aggregate,
N_Extension_Aggregate)
then
declare
Choice : constant Node_Id := First (Choices (Parent (N)));
begin
if Ekind (Entity (N)) = E_Discriminant then
return Skip;
elsif Expression (Parent (N)) = N
and then Nkind (Choice) = N_Identifier
and then Ekind (Entity (Choice)) = E_Discriminant
then
return Skip;
end if;
end;
-- Analyze if N is a writable actual of a function
elsif Nkind (Parent (N)) = N_Function_Call then
declare
Call : constant Node_Id := Parent (N);
Actual : Node_Id;
Formal : Node_Id;
begin
Id := Get_Function_Id (Call);
-- In case of previous error, no check is possible
if No (Id) then
return Abandon;
end if;
if Ekind_In (Id, E_Function, E_Generic_Function)
and then Has_Out_Or_In_Out_Parameter (Id)
then
Formal := First_Formal (Id);
Actual := First_Actual (Call);
while Present (Actual) and then Present (Formal) loop
if Actual = N then
if Ekind_In (Formal, E_Out_Parameter,
E_In_Out_Parameter)
then
Is_Writable_Actual := True;
end if;
exit;
end if;
Next_Formal (Formal);
Next_Actual (Actual);
end loop;
end if;
end;
end if;
if Is_Writable_Actual then
-- Skip checking the error in non-elementary types since
-- RM 6.4.1(6.15/3) is restricted to elementary types, but
-- store this actual in Writable_Actuals_List since it is
-- needed to perform checks on other constructs that have
-- arbitrary order of evaluation (for example, aggregates).
if not Is_Elementary_Type (Etype (N)) then
if not Contains (Writable_Actuals_List, N) then
Append_New_Elmt (N, To => Writable_Actuals_List);
end if;
-- Second occurrence of an elementary type writable actual
elsif Contains (Writable_Actuals_List, N) then
-- Report the error on the second occurrence of the
-- identifier. We cannot assume that N is the second
-- occurrence (according to their location in the
-- sources), since Traverse_Func walks through Field2
-- last (see comment in the body of Traverse_Func).
declare
Elmt : Elmt_Id;
begin
Elmt := First_Elmt (Writable_Actuals_List);
while Present (Elmt)
and then Entity (Node (Elmt)) /= Entity (N)
loop
Next_Elmt (Elmt);
end loop;
if Sloc (N) > Sloc (Node (Elmt)) then
Error_Node := N;
else
Error_Node := Node (Elmt);
end if;
Error_Msg_NE
("value may be affected by call to & "
& "because order of evaluation is arbitrary",
Error_Node, Id);
return Abandon;
end;
-- First occurrence of a elementary type writable actual
else
Append_New_Elmt (N, To => Writable_Actuals_List);
end if;
else
if Identifiers_List = No_Elist then
Identifiers_List := New_Elmt_List;
end if;
Append_Unique_Elmt (N, Identifiers_List);
end if;
end if;
return OK;
end Check_Node;
--------------
-- Contains --
--------------
function Contains
(List : Elist_Id;
N : Node_Id) return Boolean
is
pragma Assert (Nkind (N) in N_Has_Entity);
Elmt : Elmt_Id;
begin
if List = No_Elist then
return False;
end if;
Elmt := First_Elmt (List);
while Present (Elmt) loop
if Entity (Node (Elmt)) = Entity (N) then
return True;
else
Next_Elmt (Elmt);
end if;
end loop;
return False;
end Contains;
------------------
-- Do_Traversal --
------------------
procedure Do_Traversal is new Traverse_Proc (Check_Node);
-- The traversal procedure
-- Start of processing for Collect_Identifiers
begin
if Present (Error_Node) then
return;
end if;
if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
return;
end if;
Do_Traversal (N);
end Collect_Identifiers;
---------------------
-- Get_Function_Id --
---------------------
function Get_Function_Id (Call : Node_Id) return Entity_Id is
Nam : constant Node_Id := Name (Call);
Id : Entity_Id;
begin
if Nkind (Nam) = N_Explicit_Dereference then
Id := Etype (Nam);
pragma Assert (Ekind (Id) = E_Subprogram_Type);
elsif Nkind (Nam) = N_Selected_Component then
Id := Entity (Selector_Name (Nam));
elsif Nkind (Nam) = N_Indexed_Component then
Id := Entity (Selector_Name (Prefix (Nam)));
else
Id := Entity (Nam);
end if;
return Id;
end Get_Function_Id;
-------------------------------
-- Preanalyze_Without_Errors --
-------------------------------
procedure Preanalyze_Without_Errors (N : Node_Id) is
Status : constant Boolean := Get_Ignore_Errors;
begin
Set_Ignore_Errors (True);
Preanalyze (N);
Set_Ignore_Errors (Status);
end Preanalyze_Without_Errors;
-- Start of processing for Check_Function_Writable_Actuals
begin
-- The check only applies to Ada 2012 code on which Check_Actuals has
-- been set, and only to constructs that have multiple constituents
-- whose order of evaluation is not specified by the language.
if Ada_Version < Ada_2012
or else not Check_Actuals (N)
or else (not (Nkind (N) in N_Op)
and then not (Nkind (N) in N_Membership_Test)
and then not Nkind_In (N, N_Range,
N_Aggregate,
N_Extension_Aggregate,
N_Full_Type_Declaration,
N_Function_Call,
N_Procedure_Call_Statement,
N_Entry_Call_Statement))
or else (Nkind (N) = N_Full_Type_Declaration
and then not Is_Record_Type (Defining_Identifier (N)))
-- In addition, this check only applies to source code, not to code
-- generated by constraint checks.
or else not Comes_From_Source (N)
then
return;
end if;
-- If a construct C has two or more direct constituents that are names
-- or expressions whose evaluation may occur in an arbitrary order, at
-- least one of which contains a function call with an in out or out
-- parameter, then the construct is legal only if: for each name N that
-- is passed as a parameter of mode in out or out to some inner function
-- call C2 (not including the construct C itself), there is no other
-- name anywhere within a direct constituent of the construct C other
-- than the one containing C2, that is known to refer to the same
-- object (RM 6.4.1(6.17/3)).
case Nkind (N) is
when N_Range =>
Collect_Identifiers (Low_Bound (N));
Collect_Identifiers (High_Bound (N));
when N_Membership_Test
| N_Op
=>
declare
Expr : Node_Id;
begin
Collect_Identifiers (Left_Opnd (N));
if Present (Right_Opnd (N)) then
Collect_Identifiers (Right_Opnd (N));
end if;
if Nkind_In (N, N_In, N_Not_In)
and then Present (Alternatives (N))
then
Expr := First (Alternatives (N));
while Present (Expr) loop
Collect_Identifiers (Expr);
Next (Expr);
end loop;
end if;
end;
when N_Full_Type_Declaration =>
declare
function Get_Record_Part (N : Node_Id) return Node_Id;
-- Return the record part of this record type definition
function Get_Record_Part (N : Node_Id) return Node_Id is
Type_Def : constant Node_Id := Type_Definition (N);
begin
if Nkind (Type_Def) = N_Derived_Type_Definition then
return Record_Extension_Part (Type_Def);
else
return Type_Def;
end if;
end Get_Record_Part;
Comp : Node_Id;
Def_Id : Entity_Id := Defining_Identifier (N);
Rec : Node_Id := Get_Record_Part (N);
begin
-- No need to perform any analysis if the record has no
-- components
if No (Rec) or else No (Component_List (Rec)) then
return;
end if;
-- Collect the identifiers starting from the deepest
-- derivation. Done to report the error in the deepest
-- derivation.
loop
if Present (Component_List (Rec)) then
Comp := First (Component_Items (Component_List (Rec)));
while Present (Comp) loop
if Nkind (Comp) = N_Component_Declaration
and then Present (Expression (Comp))
then
Collect_Identifiers (Expression (Comp));
end if;
Next (Comp);
end loop;
end if;
exit when No (Underlying_Type (Etype (Def_Id)))
or else Base_Type (Underlying_Type (Etype (Def_Id)))
= Def_Id;
Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
Rec := Get_Record_Part (Parent (Def_Id));
end loop;
end;
when N_Entry_Call_Statement
| N_Subprogram_Call
=>
declare
Id : constant Entity_Id := Get_Function_Id (N);
Formal : Node_Id;
Actual : Node_Id;
begin
Formal := First_Formal (Id);
Actual := First_Actual (N);
while Present (Actual) and then Present (Formal) loop
if Ekind_In (Formal, E_Out_Parameter,
E_In_Out_Parameter)
then
Collect_Identifiers (Actual);
end if;
Next_Formal (Formal);
Next_Actual (Actual);
end loop;
end;
when N_Aggregate
| N_Extension_Aggregate
=>
declare
Assoc : Node_Id;
Choice : Node_Id;
Comp_Expr : Node_Id;
begin
-- Handle the N_Others_Choice of array aggregates with static
-- bounds. There is no need to perform this analysis in
-- aggregates without static bounds since we cannot evaluate
-- if the N_Others_Choice covers several elements. There is
-- no need to handle the N_Others choice of record aggregates
-- since at this stage it has been already expanded by
-- Resolve_Record_Aggregate.
if Is_Array_Type (Etype (N))
and then Nkind (N) = N_Aggregate
and then Present (Aggregate_Bounds (N))
and then Compile_Time_Known_Bounds (Etype (N))
and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
>
Expr_Value (Low_Bound (Aggregate_Bounds (N)))
then
declare
Count_Components : Uint := Uint_0;
Num_Components : Uint;
Others_Assoc : Node_Id;
Others_Choice : Node_Id := Empty;
Others_Box_Present : Boolean := False;
begin
-- Count positional associations
if Present (Expressions (N)) then
Comp_Expr := First (Expressions (N));
while Present (Comp_Expr) loop
Count_Components := Count_Components + 1;
Next (Comp_Expr);
end loop;
end if;
-- Count the rest of elements and locate the N_Others
-- choice (if any)
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
Choice := First (Choices (Assoc));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Others_Assoc := Assoc;
Others_Choice := Choice;
Others_Box_Present := Box_Present (Assoc);
-- Count several components
elsif Nkind_In (Choice, N_Range,
N_Subtype_Indication)
or else (Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice)))
then
declare
L, H : Node_Id;
begin
Get_Index_Bounds (Choice, L, H);
pragma Assert
(Compile_Time_Known_Value (L)
and then Compile_Time_Known_Value (H));
Count_Components :=
Count_Components
+ Expr_Value (H) - Expr_Value (L) + 1;
end;
-- Count single component. No other case available
-- since we are handling an aggregate with static
-- bounds.
else
pragma Assert (Is_OK_Static_Expression (Choice)
or else Nkind (Choice) = N_Identifier
or else Nkind (Choice) = N_Integer_Literal);
Count_Components := Count_Components + 1;
end if;
Next (Choice);
end loop;
Next (Assoc);
end loop;
Num_Components :=
Expr_Value (High_Bound (Aggregate_Bounds (N))) -
Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
pragma Assert (Count_Components <= Num_Components);
-- Handle the N_Others choice if it covers several
-- components
if Present (Others_Choice)
and then (Num_Components - Count_Components) > 1
then
if not Others_Box_Present then
-- At this stage, if expansion is active, the
-- expression of the others choice has not been
-- analyzed. Hence we generate a duplicate and
-- we analyze it silently to have available the
-- minimum decoration required to collect the
-- identifiers.
if not Expander_Active then
Comp_Expr := Expression (Others_Assoc);
else
Comp_Expr :=
New_Copy_Tree (Expression (Others_Assoc));
Preanalyze_Without_Errors (Comp_Expr);
end if;
Collect_Identifiers (Comp_Expr);
if Writable_Actuals_List /= No_Elist then
-- As suggested by Robert, at current stage we
-- report occurrences of this case as warnings.
Error_Msg_N
("writable function parameter may affect "
& "value in other component because order "
& "of evaluation is unspecified??",
Node (First_Elmt (Writable_Actuals_List)));
end if;
end if;
end if;
end;
-- For an array aggregate, a discrete_choice_list that has
-- a nonstatic range is considered as two or more separate
-- occurrences of the expression (RM 6.4.1(20/3)).
elsif Is_Array_Type (Etype (N))
and then Nkind (N) = N_Aggregate
and then Present (Aggregate_Bounds (N))
and then not Compile_Time_Known_Bounds (Etype (N))
then
-- Collect identifiers found in the dynamic bounds
declare
Count_Components : Natural := 0;
Low, High : Node_Id;
begin
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
Choice := First (Choices (Assoc));
while Present (Choice) loop
if Nkind_In (Choice, N_Range,
N_Subtype_Indication)
or else (Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice)))
then
Get_Index_Bounds (Choice, Low, High);
if not Compile_Time_Known_Value (Low) then
Collect_Identifiers (Low);
if No (Aggr_Error_Node) then
Aggr_Error_Node := Low;
end if;
end if;
if not Compile_Time_Known_Value (High) then
Collect_Identifiers (High);
if No (Aggr_Error_Node) then
Aggr_Error_Node := High;
end if;
end if;
-- The RM rule is violated if there is more than
-- a single choice in a component association.
else
Count_Components := Count_Components + 1;
if No (Aggr_Error_Node)
and then Count_Components > 1
then
Aggr_Error_Node := Choice;
end if;
if not Compile_Time_Known_Value (Choice) then
Collect_Identifiers (Choice);
end if;
end if;
Next (Choice);
end loop;
Next (Assoc);
end loop;
end;
end if;
-- Handle ancestor part of extension aggregates
if Nkind (N) = N_Extension_Aggregate then
Collect_Identifiers (Ancestor_Part (N));
end if;
-- Handle positional associations
if Present (Expressions (N)) then
Comp_Expr := First (Expressions (N));
while Present (Comp_Expr) loop
if not Is_OK_Static_Expression (Comp_Expr) then
Collect_Identifiers (Comp_Expr);
end if;
Next (Comp_Expr);
end loop;
end if;
-- Handle discrete associations
if Present (Component_Associations (N)) then
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
if not Box_Present (Assoc) then
Choice := First (Choices (Assoc));
while Present (Choice) loop
-- For now we skip discriminants since it requires
-- performing the analysis in two phases: first one
-- analyzing discriminants and second one analyzing
-- the rest of components since discriminants are
-- evaluated prior to components: too much extra
-- work to detect a corner case???
if Nkind (Choice) in N_Has_Entity
and then Present (Entity (Choice))
and then Ekind (Entity (Choice)) = E_Discriminant
then
null;
elsif Box_Present (Assoc) then
null;
else
if not Analyzed (Expression (Assoc)) then
Comp_Expr :=
New_Copy_Tree (Expression (Assoc));
Set_Parent (Comp_Expr, Parent (N));
Preanalyze_Without_Errors (Comp_Expr);
else
Comp_Expr := Expression (Assoc);
end if;
Collect_Identifiers (Comp_Expr);
end if;
Next (Choice);
end loop;
end if;
Next (Assoc);
end loop;
end if;
end;
when others =>
return;
end case;
-- No further action needed if we already reported an error
if Present (Error_Node) then
return;
end if;
-- Check violation of RM 6.20/3 in aggregates
if Present (Aggr_Error_Node)
and then Writable_Actuals_List /= No_Elist
then
Error_Msg_N
("value may be affected by call in other component because they "
& "are evaluated in unspecified order",
Node (First_Elmt (Writable_Actuals_List)));
return;
end if;
-- Check if some writable argument of a function is referenced
if Writable_Actuals_List /= No_Elist
and then Identifiers_List /= No_Elist
then
declare
Elmt_1 : Elmt_Id;
Elmt_2 : Elmt_Id;
begin
Elmt_1 := First_Elmt (Writable_Actuals_List);
while Present (Elmt_1) loop
Elmt_2 := First_Elmt (Identifiers_List);
while Present (Elmt_2) loop
if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
case Nkind (Parent (Node (Elmt_2))) is
when N_Aggregate
| N_Component_Association
| N_Component_Declaration
=>
Error_Msg_N
("value may be affected by call in other "
& "component because they are evaluated "
& "in unspecified order",
Node (Elmt_2));
when N_In
| N_Not_In
=>
Error_Msg_N
("value may be affected by call in other "
& "alternative because they are evaluated "
& "in unspecified order",
Node (Elmt_2));
when others =>
Error_Msg_N
("value of actual may be affected by call in "
& "other actual because they are evaluated "
& "in unspecified order",
Node (Elmt_2));
end case;
end if;
Next_Elmt (Elmt_2);
end loop;
Next_Elmt (Elmt_1);
end loop;
end;
end if;
end Check_Function_Writable_Actuals;
--------------------------------
-- Check_Implicit_Dereference --
--------------------------------
procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
Disc : Entity_Id;
Desig : Entity_Id;
Nam : Node_Id;
begin
if Nkind (N) = N_Indexed_Component
and then Present (Generalized_Indexing (N))
then
Nam := Generalized_Indexing (N);
else
Nam := N;
end if;
if Ada_Version < Ada_2012
or else not Has_Implicit_Dereference (Base_Type (Typ))
then
return;
elsif not Comes_From_Source (N)
and then Nkind (N) /= N_Indexed_Component
then
return;
elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
null;
else
Disc := First_Discriminant (Typ);
while Present (Disc) loop
if Has_Implicit_Dereference (Disc) then
Desig := Designated_Type (Etype (Disc));
Add_One_Interp (Nam, Disc, Desig);
-- If the node is a generalized indexing, add interpretation
-- to that node as well, for subsequent resolution.
if Nkind (N) = N_Indexed_Component then
Add_One_Interp (N, Disc, Desig);
end if;
-- If the operation comes from a generic unit and the context
-- is a selected component, the selector name may be global
-- and set in the instance already. Remove the entity to
-- force resolution of the selected component, and the
-- generation of an explicit dereference if needed.
if In_Instance
and then Nkind (Parent (Nam)) = N_Selected_Component
then
Set_Entity (Selector_Name (Parent (Nam)), Empty);
end if;
exit;
end if;
Next_Discriminant (Disc);
end loop;
end if;
end Check_Implicit_Dereference;
----------------------------------
-- Check_Internal_Protected_Use --
----------------------------------
procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
S : Entity_Id;
Prot : Entity_Id;
begin
S := Current_Scope;
while Present (S) loop
if S = Standard_Standard then
return;
elsif Ekind (S) = E_Function
and then Ekind (Scope (S)) = E_Protected_Type
then
Prot := Scope (S);
exit;
end if;
S := Scope (S);
end loop;
if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
-- An indirect function call (e.g. a callback within a protected
-- function body) is not statically illegal. If the access type is
-- anonymous and is the type of an access parameter, the scope of Nam
-- will be the protected type, but it is not a protected operation.
if Ekind (Nam) = E_Subprogram_Type
and then
Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
then
null;
elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
Error_Msg_N
("within protected function cannot use protected "
& "procedure in renaming or as generic actual", N);
elsif Nkind (N) = N_Attribute_Reference then
Error_Msg_N
("within protected function cannot take access of "
& " protected procedure", N);
else
Error_Msg_N
("within protected function, protected object is constant", N);
Error_Msg_N
("\cannot call operation that may modify it", N);
end if;
end if;
end Check_Internal_Protected_Use;
---------------------------------------
-- Check_Later_Vs_Basic_Declarations --
---------------------------------------
procedure Check_Later_Vs_Basic_Declarations
(Decls : List_Id;
During_Parsing : Boolean)
is
Body_Sloc : Source_Ptr;
Decl : Node_Id;
function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
-- Return whether Decl is considered as a declarative item.
-- When During_Parsing is True, the semantics of Ada 83 is followed.
-- When During_Parsing is False, the semantics of SPARK is followed.
-------------------------------
-- Is_Later_Declarative_Item --
-------------------------------
function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
begin
if Nkind (Decl) in N_Later_Decl_Item then
return True;
elsif Nkind (Decl) = N_Pragma then
return True;
elsif During_Parsing then
return False;
-- In SPARK, a package declaration is not considered as a later
-- declarative item.
elsif Nkind (Decl) = N_Package_Declaration then
return False;
-- In SPARK, a renaming is considered as a later declarative item
elsif Nkind (Decl) in N_Renaming_Declaration then
return True;
else
return False;
end if;
end Is_Later_Declarative_Item;
-- Start of processing for Check_Later_Vs_Basic_Declarations
begin
Decl := First (Decls);
-- Loop through sequence of basic declarative items
Outer : while Present (Decl) loop
if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
and then Nkind (Decl) not in N_Body_Stub
then
Next (Decl);
-- Once a body is encountered, we only allow later declarative
-- items. The inner loop checks the rest of the list.
else
Body_Sloc := Sloc (Decl);
Inner : while Present (Decl) loop
if not Is_Later_Declarative_Item (Decl) then
if During_Parsing then
if Ada_Version = Ada_83 then
Error_Msg_Sloc := Body_Sloc;
Error_Msg_N
("(Ada 83) decl cannot appear after body#", Decl);
end if;
else
Error_Msg_Sloc := Body_Sloc;
Check_SPARK_05_Restriction
("decl cannot appear after body#", Decl);
end if;
end if;
Next (Decl);
end loop Inner;
end if;
end loop Outer;
end Check_Later_Vs_Basic_Declarations;
---------------------------
-- Check_No_Hidden_State --
---------------------------
procedure Check_No_Hidden_State (Id : Entity_Id) is
function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
-- Determine whether the entity of a package denoted by Pkg has a null
-- abstract state.
-----------------------------
-- Has_Null_Abstract_State --
-----------------------------
function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
States : constant Elist_Id := Abstract_States (Pkg);
begin
-- Check first available state of related package. A null abstract
-- state always appears as the sole element of the state list.
return
Present (States)
and then Is_Null_State (Node (First_Elmt (States)));
end Has_Null_Abstract_State;
-- Local variables
Context : Entity_Id := Empty;
Not_Visible : Boolean := False;
Scop : Entity_Id;
-- Start of processing for Check_No_Hidden_State
begin
pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
-- Find the proper context where the object or state appears
Scop := Scope (Id);
while Present (Scop) loop
Context := Scop;
-- Keep track of the context's visibility
Not_Visible := Not_Visible or else In_Private_Part (Context);
-- Prevent the search from going too far
if Context = Standard_Standard then
return;
-- Objects and states that appear immediately within a subprogram or
-- inside a construct nested within a subprogram do not introduce a
-- hidden state. They behave as local variable declarations.
elsif Is_Subprogram (Context) then
return;
-- When examining a package body, use the entity of the spec as it
-- carries the abstract state declarations.
elsif Ekind (Context) = E_Package_Body then
Context := Spec_Entity (Context);
end if;
-- Stop the traversal when a package subject to a null abstract state
-- has been found.
if Ekind_In (Context, E_Generic_Package, E_Package)
and then Has_Null_Abstract_State (Context)
then
exit;
end if;
Scop := Scope (Scop);
end loop;
-- At this point we know that there is at least one package with a null
-- abstract state in visibility. Emit an error message unconditionally
-- if the entity being processed is a state because the placement of the
-- related package is irrelevant. This is not the case for objects as
-- the intermediate context matters.
if Present (Context)
and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
then
Error_Msg_N ("cannot introduce hidden state &", Id);
Error_Msg_NE ("\package & has null abstract state", Id, Context);
end if;
end Check_No_Hidden_State;
----------------------------------------
-- Check_Nonvolatile_Function_Profile --
----------------------------------------
procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
Formal : Entity_Id;
begin
-- Inspect all formal parameters
Formal := First_Formal (Func_Id);
while Present (Formal) loop
if Is_Effectively_Volatile (Etype (Formal)) then
Error_Msg_NE
("nonvolatile function & cannot have a volatile parameter",
Formal, Func_Id);
end if;
Next_Formal (Formal);
end loop;
-- Inspect the return type
if Is_Effectively_Volatile (Etype (Func_Id)) then
Error_Msg_NE
("nonvolatile function & cannot have a volatile return type",
Result_Definition (Parent (Func_Id)), Func_Id);
end if;
end Check_Nonvolatile_Function_Profile;
------------------------------------------
-- Check_Potentially_Blocking_Operation --
------------------------------------------
procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
S : Entity_Id;
begin
-- N is one of the potentially blocking operations listed in 9.5.1(8).
-- When pragma Detect_Blocking is active, the run time will raise
-- Program_Error. Here we only issue a warning, since we generally
-- support the use of potentially blocking operations in the absence
-- of the pragma.
-- Indirect blocking through a subprogram call cannot be diagnosed
-- statically without interprocedural analysis, so we do not attempt
-- to do it here.
S := Scope (Current_Scope);
while Present (S) and then S /= Standard_Standard loop
if Is_Protected_Type (S) then
Error_Msg_N
("potentially blocking operation in protected operation??", N);
return;
end if;
S := Scope (S);
end loop;
end Check_Potentially_Blocking_Operation;
---------------------------------
-- Check_Result_And_Post_State --
---------------------------------
procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
procedure Check_Result_And_Post_State_In_Pragma
(Prag : Node_Id;
Result_Seen : in out Boolean);
-- Determine whether pragma Prag mentions attribute 'Result and whether
-- the pragma contains an expression that evaluates differently in pre-
-- and post-state. Prag is a [refined] postcondition or a contract-cases
-- pragma. Result_Seen is set when the pragma mentions attribute 'Result
function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
-- Determine whether subprogram Subp_Id contains at least one IN OUT
-- formal parameter.
-------------------------------------------
-- Check_Result_And_Post_State_In_Pragma --
-------------------------------------------
procedure Check_Result_And_Post_State_In_Pragma
(Prag : Node_Id;
Result_Seen : in out Boolean)
is
procedure Check_Expression (Expr : Node_Id);
-- Perform the 'Result and post-state checks on a given expression
function Is_Function_Result (N : Node_Id) return Traverse_Result;
-- Attempt to find attribute 'Result in a subtree denoted by N
function Is_Trivial_Boolean (N : Node_Id) return Boolean;
-- Determine whether source node N denotes "True" or "False"
function Mentions_Post_State (N : Node_Id) return Boolean;
-- Determine whether a subtree denoted by N mentions any construct
-- that denotes a post-state.
procedure Check_Function_Result is
new Traverse_Proc (Is_Function_Result);
----------------------
-- Check_Expression --
----------------------
procedure Check_Expression (Expr : Node_Id) is
begin
if not Is_Trivial_Boolean (Expr) then
Check_Function_Result (Expr);
if not Mentions_Post_State (Expr) then
if Pragma_Name (Prag) = Name_Contract_Cases then
Error_Msg_NE
("contract case does not check the outcome of calling "
& "&?T?", Expr, Subp_Id);
elsif Pragma_Name (Prag) = Name_Refined_Post then
Error_Msg_NE
("refined postcondition does not check the outcome of "
& "calling &?T?", Prag, Subp_Id);
else
Error_Msg_NE
("postcondition does not check the outcome of calling "
& "&?T?", Prag, Subp_Id);
end if;
end if;
end if;
end Check_Expression;
------------------------
-- Is_Function_Result --
------------------------
function Is_Function_Result (N : Node_Id) return Traverse_Result is
begin
if Is_Attribute_Result (N) then
Result_Seen := True;
return Abandon;
-- Continue the traversal
else
return OK;
end if;
end Is_Function_Result;
------------------------
-- Is_Trivial_Boolean --
------------------------
function Is_Trivial_Boolean (N : Node_Id) return Boolean is
begin
return
Comes_From_Source (N)
and then Is_Entity_Name (N)
and then (Entity (N) = Standard_True
or else
Entity (N) = Standard_False);
end Is_Trivial_Boolean;
-------------------------
-- Mentions_Post_State --
-------------------------
function Mentions_Post_State (N : Node_Id) return Boolean is
Post_State_Seen : Boolean := False;
function Is_Post_State (N : Node_Id) return Traverse_Result;
-- Attempt to find a construct that denotes a post-state. If this
-- is the case, set flag Post_State_Seen.
-------------------
-- Is_Post_State --
-------------------
function Is_Post_State (N : Node_Id) return Traverse_Result is
Ent : Entity_Id;
begin
if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
Post_State_Seen := True;
return Abandon;
elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
Ent := Entity (N);
-- The entity may be modifiable through an implicit
-- dereference.
if No (Ent)
or else Ekind (Ent) in Assignable_Kind
or else (Is_Access_Type (Etype (Ent))
and then Nkind (Parent (N)) =
N_Selected_Component)
then
Post_State_Seen := True;
return Abandon;
end if;
elsif Nkind (N) = N_Attribute_Reference then
if Attribute_Name (N) = Name_Old then
return Skip;
elsif Attribute_Name (N) = Name_Result then
Post_State_Seen := True;
return Abandon;
end if;
end if;
return OK;
end Is_Post_State;
procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
-- Start of processing for Mentions_Post_State
begin
Find_Post_State (N);
return Post_State_Seen;
end Mentions_Post_State;
-- Local variables
Expr : constant Node_Id :=
Get_Pragma_Arg
(First (Pragma_Argument_Associations (Prag)));
Nam : constant Name_Id := Pragma_Name (Prag);
CCase : Node_Id;
-- Start of processing for Check_Result_And_Post_State_In_Pragma
begin
-- Examine all consequences
if Nam = Name_Contract_Cases then
CCase := First (Component_Associations (Expr));
while Present (CCase) loop
Check_Expression (Expression (CCase));
Next (CCase);
end loop;
-- Examine the expression of a postcondition
else pragma Assert (Nam_In (Nam, Name_Postcondition,
Name_Refined_Post));
Check_Expression (Expr);
end if;
end Check_Result_And_Post_State_In_Pragma;
--------------------------
-- Has_In_Out_Parameter --
--------------------------
function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
Formal : Entity_Id;
begin
-- Traverse the formals looking for an IN OUT parameter
Formal := First_Formal (Subp_Id);
while Present (Formal) loop
if Ekind (Formal) = E_In_Out_Parameter then
return True;
end if;
Next_Formal (Formal);
end loop;
return False;
end Has_In_Out_Parameter;
-- Local variables
Items : constant Node_Id := Contract (Subp_Id);
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
Case_Prag : Node_Id := Empty;
Post_Prag : Node_Id := Empty;
Prag : Node_Id;
Seen_In_Case : Boolean := False;
Seen_In_Post : Boolean := False;
Spec_Id : Entity_Id;
-- Start of processing for Check_Result_And_Post_State
begin
-- The lack of attribute 'Result or a post-state is classified as a
-- suspicious contract. Do not perform the check if the corresponding
-- swich is not set.
if not Warn_On_Suspicious_Contract then
return;
-- Nothing to do if there is no contract
elsif No (Items) then
return;
end if;
-- Retrieve the entity of the subprogram spec (if any)
if Nkind (Subp_Decl) = N_Subprogram_Body
and then Present (Corresponding_Spec (Subp_Decl))
then
Spec_Id := Corresponding_Spec (Subp_Decl);
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
then
Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
else
Spec_Id := Subp_Id;
end if;
-- Examine all postconditions for attribute 'Result and a post-state
Prag := Pre_Post_Conditions (Items);
while Present (Prag) loop
if Nam_In (Pragma_Name_Unmapped (Prag),
Name_Postcondition, Name_Refined_Post)
and then not Error_Posted (Prag)
then
Post_Prag := Prag;
Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
end if;
Prag := Next_Pragma (Prag);
end loop;
-- Examine the contract cases of the subprogram for attribute 'Result
-- and a post-state.
Prag := Contract_Test_Cases (Items);
while Present (Prag) loop
if Pragma_Name (Prag) = Name_Contract_Cases
and then not Error_Posted (Prag)
then
Case_Prag := Prag;
Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
end if;
Prag := Next_Pragma (Prag);
end loop;
-- Do not emit any errors if the subprogram is not a function
if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
null;
-- Regardless of whether the function has postconditions or contract
-- cases, or whether they mention attribute 'Result, an IN OUT formal
-- parameter is always treated as a result.
elsif Has_In_Out_Parameter (Spec_Id) then
null;
-- The function has both a postcondition and contract cases and they do
-- not mention attribute 'Result.
elsif Present (Case_Prag)
and then not Seen_In_Case
and then Present (Post_Prag)
and then not Seen_In_Post
then
Error_Msg_N
("neither postcondition nor contract cases mention function "
& "result?T?", Post_Prag);
-- The function has contract cases only and they do not mention
-- attribute 'Result.
elsif Present (Case_Prag) and then not Seen_In_Case then
Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
-- The function has postconditions only and they do not mention
-- attribute 'Result.
elsif Present (Post_Prag) and then not Seen_In_Post then
Error_Msg_N
("postcondition does not mention function result?T?", Post_Prag);
end if;
end Check_Result_And_Post_State;
-----------------------------
-- Check_State_Refinements --
-----------------------------
procedure Check_State_Refinements
(Context : Node_Id;
Is_Main_Unit : Boolean := False)
is
procedure Check_Package (Pack : Node_Id);
-- Verify that all abstract states of a [generic] package denoted by its
-- declarative node Pack have proper refinement. Recursively verify the
-- visible and private declarations of the [generic] package for other
-- nested packages.
procedure Check_Packages_In (Decls : List_Id);
-- Seek out [generic] package declarations within declarative list Decls
-- and verify the status of their abstract state refinement.
function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
-- Determine whether construct N is subject to pragma SPARK_Mode Off
-------------------
-- Check_Package --
-------------------
procedure Check_Package (Pack : Node_Id) is
Body_Id : constant Entity_Id := Corresponding_Body (Pack);
Spec : constant Node_Id := Specification (Pack);
States : constant Elist_Id :=
Abstract_States (Defining_Entity (Pack));
State_Elmt : Elmt_Id;
State_Id : Entity_Id;
begin
-- Do not verify proper state refinement when the package is subject
-- to pragma SPARK_Mode Off because this disables the requirement for
-- state refinement.
if SPARK_Mode_Is_Off (Pack) then
null;
-- State refinement can only occur in a completing packge body. Do
-- not verify proper state refinement when the body is subject to
-- pragma SPARK_Mode Off because this disables the requirement for
-- state refinement.
elsif Present (Body_Id)
and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
then
null;
-- Do not verify proper state refinement when the package is an
-- instance as this check was already performed in the generic.
elsif Present (Generic_Parent (Spec)) then
null;
-- Otherwise examine the contents of the package
else
if Present (States) then
State_Elmt := First_Elmt (States);
while Present (State_Elmt) loop
State_Id := Node (State_Elmt);
-- Emit an error when a non-null state lacks any form of
-- refinement.
if not Is_Null_State (State_Id)
and then not Has_Null_Refinement (State_Id)
and then not Has_Non_Null_Refinement (State_Id)
then
Error_Msg_N ("state & requires refinement", State_Id);
end if;
Next_Elmt (State_Elmt);
end loop;
end if;
Check_Packages_In (Visible_Declarations (Spec));
Check_Packages_In (Private_Declarations (Spec));
end if;
end Check_Package;
-----------------------
-- Check_Packages_In --
-----------------------
procedure Check_Packages_In (Decls : List_Id) is
Decl : Node_Id;
begin
if Present (Decls) then
Decl := First (Decls);
while Present (Decl) loop
if Nkind_In (Decl, N_Generic_Package_Declaration,
N_Package_Declaration)
then
Check_Package (Decl);
end if;
Next (Decl);
end loop;
end if;
end Check_Packages_In;
-----------------------
-- SPARK_Mode_Is_Off --
-----------------------
function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
Prag : constant Node_Id := SPARK_Pragma (Defining_Entity (N));
begin
return
Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
end SPARK_Mode_Is_Off;
-- Start of processing for Check_State_Refinements
begin
-- A block may declare a nested package
if Nkind (Context) = N_Block_Statement then
Check_Packages_In (Declarations (Context));
-- An entry, protected, subprogram, or task body may declare a nested
-- package.
elsif Nkind_In (Context, N_Entry_Body,
N_Protected_Body,
N_Subprogram_Body,
N_Task_Body)
then
-- Do not verify proper state refinement when the body is subject to
-- pragma SPARK_Mode Off because this disables the requirement for
-- state refinement.
if not SPARK_Mode_Is_Off (Context) then
Check_Packages_In (Declarations (Context));
end if;
-- A package body may declare a nested package
elsif Nkind (Context) = N_Package_Body then
Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
-- Do not verify proper state refinement when the body is subject to
-- pragma SPARK_Mode Off because this disables the requirement for
-- state refinement.
if not SPARK_Mode_Is_Off (Context) then
Check_Packages_In (Declarations (Context));
end if;
-- A library level [generic] package may declare a nested package
elsif Nkind_In (Context, N_Generic_Package_Declaration,
N_Package_Declaration)
and then Is_Main_Unit
then
Check_Package (Context);
end if;
end Check_State_Refinements;
------------------------------
-- Check_Unprotected_Access --
------------------------------
procedure Check_Unprotected_Access
(Context : Node_Id;
Expr : Node_Id)
is
Cont_Encl_Typ : Entity_Id;
Pref_Encl_Typ : Entity_Id;
function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
-- Check whether Obj is a private component of a protected object.
-- Return the protected type where the component resides, Empty
-- otherwise.
function Is_Public_Operation return Boolean;
-- Verify that the enclosing operation is callable from outside the
-- protected object, to minimize false positives.
------------------------------
-- Enclosing_Protected_Type --
------------------------------
function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
begin
if Is_Entity_Name (Obj) then
declare
Ent : Entity_Id := Entity (Obj);
begin
-- The object can be a renaming of a private component, use
-- the original record component.
if Is_Prival (Ent) then
Ent := Prival_Link (Ent);
end if;
if Is_Protected_Type (Scope (Ent)) then
return Scope (Ent);
end if;
end;
end if;
-- For indexed and selected components, recursively check the prefix
if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
return Enclosing_Protected_Type (Prefix (Obj));
-- The object does not denote a protected component
else
return Empty;
end if;
end Enclosing_Protected_Type;
-------------------------
-- Is_Public_Operation --
-------------------------
function Is_Public_Operation return Boolean is
S : Entity_Id;
E : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Pref_Encl_Typ loop
if Scope (S) = Pref_Encl_Typ then
E := First_Entity (Pref_Encl_Typ);
while Present (E)
and then E /= First_Private_Entity (Pref_Encl_Typ)
loop
if E = S then
return True;
end if;
Next_Entity (E);
end loop;
end if;
S := Scope (S);
end loop;
return False;
end Is_Public_Operation;
-- Start of processing for Check_Unprotected_Access
begin
if Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Unchecked_Access
then
Cont_Encl_Typ := Enclosing_Protected_Type (Context);
Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
-- Check whether we are trying to export a protected component to a
-- context with an equal or lower access level.
if Present (Pref_Encl_Typ)
and then No (Cont_Encl_Typ)
and then Is_Public_Operation
and then Scope_Depth (Pref_Encl_Typ) >=
Object_Access_Level (Context)
then
Error_Msg_N
("??possible unprotected access to protected data", Expr);
end if;
end if;
end Check_Unprotected_Access;
------------------------------
-- Check_Unused_Body_States --
------------------------------
procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
procedure Process_Refinement_Clause
(Clause : Node_Id;
States : Elist_Id);
-- Inspect all constituents of refinement clause Clause and remove any
-- matches from body state list States.
procedure Report_Unused_Body_States (States : Elist_Id);
-- Emit errors for each abstract state or object found in list States
-------------------------------
-- Process_Refinement_Clause --
-------------------------------
procedure Process_Refinement_Clause
(Clause : Node_Id;
States : Elist_Id)
is
procedure Process_Constituent (Constit : Node_Id);
-- Remove constituent Constit from body state list States
-------------------------
-- Process_Constituent --
-------------------------
procedure Process_Constituent (Constit : Node_Id) is
Constit_Id : Entity_Id;
begin
-- Guard against illegal constituents. Only abstract states and
-- objects can appear on the right hand side of a refinement.
if Is_Entity_Name (Constit) then
Constit_Id := Entity_Of (Constit);
if Present (Constit_Id)
and then Ekind_In (Constit_Id, E_Abstract_State,
E_Constant,
E_Variable)
then
Remove (States, Constit_Id);
end if;
end if;
end Process_Constituent;
-- Local variables
Constit : Node_Id;
-- Start of processing for Process_Refinement_Clause
begin
if Nkind (Clause) = N_Component_Association then
Constit := Expression (Clause);
-- Multiple constituents appear as an aggregate
if Nkind (Constit) = N_Aggregate then
Constit := First (Expressions (Constit));
while Present (Constit) loop
Process_Constituent (Constit);
Next (Constit);
end loop;
-- Various forms of a single constituent
else
Process_Constituent (Constit);
end if;
end if;
end Process_Refinement_Clause;
-------------------------------
-- Report_Unused_Body_States --
-------------------------------
procedure Report_Unused_Body_States (States : Elist_Id) is
Posted : Boolean := False;
State_Elmt : Elmt_Id;
State_Id : Entity_Id;
begin
if Present (States) then
State_Elmt := First_Elmt (States);
while Present (State_Elmt) loop
State_Id := Node (State_Elmt);
-- Constants are part of the hidden state of a package, but the
-- compiler cannot determine whether they have variable input
-- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
-- hidden state. Do not emit an error when a constant does not
-- participate in a state refinement, even though it acts as a
-- hidden state.
if Ekind (State_Id) = E_Constant then
null;
-- Generate an error message of the form:
-- body of package ... has unused hidden states
-- abstract state ... defined at ...
-- variable ... defined at ...
else
if not Posted then
Posted := True;
SPARK_Msg_N
("body of package & has unused hidden states", Body_Id);
end if;
Error_Msg_Sloc := Sloc (State_Id);
if Ekind (State_Id) = E_Abstract_State then
SPARK_Msg_NE
("\abstract state & defined #", Body_Id, State_Id);
else
SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
end if;
end if;
Next_Elmt (State_Elmt);
end loop;
end if;
end Report_Unused_Body_States;
-- Local variables
Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
Clause : Node_Id;
States : Elist_Id;
-- Start of processing for Check_Unused_Body_States
begin
-- Inspect the clauses of pragma Refined_State and determine whether all
-- visible states declared within the package body participate in the
-- refinement.
if Present (Prag) then
Clause := Expression (Get_Argument (Prag, Spec_Id));
States := Collect_Body_States (Body_Id);
-- Multiple non-null state refinements appear as an aggregate
if Nkind (Clause) = N_Aggregate then
Clause := First (Component_Associations (Clause));
while Present (Clause) loop
Process_Refinement_Clause (Clause, States);
Next (Clause);
end loop;
-- Various forms of a single state refinement
else
Process_Refinement_Clause (Clause, States);
end if;
-- Ensure that all abstract states and objects declared in the
-- package body state space are utilized as constituents.
Report_Unused_Body_States (States);
end if;
end Check_Unused_Body_States;
-----------------
-- Choice_List --
-----------------
function Choice_List (N : Node_Id) return List_Id is
begin
if Nkind (N) = N_Iterated_Component_Association then
return Discrete_Choices (N);
else
return Choices (N);
end if;
end Choice_List;
-------------------------
-- Collect_Body_States --
-------------------------
function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
-- Determine whether object Obj_Id is a suitable visible state of a
-- package body.
procedure Collect_Visible_States
(Pack_Id : Entity_Id;
States : in out Elist_Id);
-- Gather the entities of all abstract states and objects declared in
-- the visible state space of package Pack_Id.
----------------------------
-- Collect_Visible_States --
----------------------------
procedure Collect_Visible_States
(Pack_Id : Entity_Id;
States : in out Elist_Id)
is
Item_Id : Entity_Id;
begin
-- Traverse the entity chain of the package and inspect all visible
-- items.
Item_Id := First_Entity (Pack_Id);
while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
-- Do not consider internally generated items as those cannot be
-- named and participate in refinement.
if not Comes_From_Source (Item_Id) then
null;
elsif Ekind (Item_Id) = E_Abstract_State then
Append_New_Elmt (Item_Id, States);
elsif Ekind_In (Item_Id, E_Constant, E_Variable)
and then Is_Visible_Object (Item_Id)
then
Append_New_Elmt (Item_Id, States);
-- Recursively gather the visible states of a nested package
elsif Ekind (Item_Id) = E_Package then
Collect_Visible_States (Item_Id, States);
end if;
Next_Entity (Item_Id);
end loop;
end Collect_Visible_States;
-----------------------
-- Is_Visible_Object --
-----------------------
function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
begin
-- Objects that map generic formals to their actuals are not visible
-- from outside the generic instantiation.
if Present (Corresponding_Generic_Association
(Declaration_Node (Obj_Id)))
then
return False;
-- Constituents of a single protected/task type act as components of
-- the type and are not visible from outside the type.
elsif Ekind (Obj_Id) = E_Variable
and then Present (Encapsulating_State (Obj_Id))
and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
then
return False;
else
return True;
end if;
end Is_Visible_Object;
-- Local variables
Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
Decl : Node_Id;
Item_Id : Entity_Id;
States : Elist_Id := No_Elist;
-- Start of processing for Collect_Body_States
begin
-- Inspect the declarations of the body looking for source objects,
-- packages and package instantiations. Note that even though this
-- processing is very similar to Collect_Visible_States, a package
-- body does not have a First/Next_Entity list.
Decl := First (Declarations (Body_Decl));
while Present (Decl) loop
-- Capture source objects as internally generated temporaries cannot
-- be named and participate in refinement.
if Nkind (Decl) = N_Object_Declaration then
Item_Id := Defining_Entity (Decl);
if Comes_From_Source (Item_Id)
and then Is_Visible_Object (Item_Id)
then
Append_New_Elmt (Item_Id, States);
end if;
-- Capture the visible abstract states and objects of a source
-- package [instantiation].
elsif Nkind (Decl) = N_Package_Declaration then
Item_Id := Defining_Entity (Decl);
if Comes_From_Source (Item_Id) then
Collect_Visible_States (Item_Id, States);
end if;
end if;
Next (Decl);
end loop;
return States;
end Collect_Body_States;
------------------------
-- Collect_Interfaces --
------------------------
procedure Collect_Interfaces
(T : Entity_Id;
Ifaces_List : out Elist_Id;
Exclude_Parents : Boolean := False;
Use_Full_View : Boolean := True)
is
procedure Collect (Typ : Entity_Id);
-- Subsidiary subprogram used to traverse the whole list
-- of directly and indirectly implemented interfaces
-------------
-- Collect --
-------------
procedure Collect (Typ : Entity_Id) is
Ancestor : Entity_Id;
Full_T : Entity_Id;
Id : Node_Id;
Iface : Entity_Id;
begin
Full_T := Typ;
-- Handle private types and subtypes
if Use_Full_View
and then Is_Private_Type (Typ)
and then Present (Full_View (Typ))
then
Full_T := Full_View (Typ);
if Ekind (Full_T) = E_Record_Subtype then
Full_T := Etype (Typ);
if Present (Full_View (Full_T)) then
Full_T := Full_View (Full_T);
end if;
end if;
end if;
-- Include the ancestor if we are generating the whole list of
-- abstract interfaces.
if Etype (Full_T) /= Typ
-- Protect the frontend against wrong sources. For example:
-- package P is
-- type A is tagged null record;
-- type B is new A with private;
-- type C is new A with private;
-- private
-- type B is new C with null record;
-- type C is new B with null record;
-- end P;
and then Etype (Full_T) /= T
then
Ancestor := Etype (Full_T);
Collect (Ancestor);
if Is_Interface (Ancestor) and then not Exclude_Parents then
Append_Unique_Elmt (Ancestor, Ifaces_List);
end if;
end if;
-- Traverse the graph of ancestor interfaces
if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
Id := First (Abstract_Interface_List (Full_T));
while Present (Id) loop
Iface := Etype (Id);
-- Protect against wrong uses. For example:
-- type I is interface;
-- type O is tagged null record;
-- type Wrong is new I and O with null record; -- ERROR
if Is_Interface (Iface) then
if Exclude_Parents
and then Etype (T) /= T
and then Interface_Present_In_Ancestor (Etype (T), Iface)
then
null;
else
Collect (Iface);
Append_Unique_Elmt (Iface, Ifaces_List);
end if;
end if;
Next (Id);
end loop;
end if;
end Collect;
-- Start of processing for Collect_Interfaces
begin
pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
Ifaces_List := New_Elmt_List;
Collect (T);
end Collect_Interfaces;
----------------------------------
-- Collect_Interface_Components --
----------------------------------
procedure Collect_Interface_Components
(Tagged_Type : Entity_Id;
Components_List : out Elist_Id)
is
procedure Collect (Typ : Entity_Id);
-- Subsidiary subprogram used to climb to the parents
-------------
-- Collect --
-------------
procedure Collect (Typ : Entity_Id) is
Tag_Comp : Entity_Id;
Parent_Typ : Entity_Id;
begin
-- Handle private types
if Present (Full_View (Etype (Typ))) then
Parent_Typ := Full_View (Etype (Typ));
else
Parent_Typ := Etype (Typ);
end if;
if Parent_Typ /= Typ
-- Protect the frontend against wrong sources. For example:
-- package P is
-- type A is tagged null record;
-- type B is new A with private;
-- type C is new A with private;
-- private
-- type B is new C with null record;
-- type C is new B with null record;
-- end P;
and then Parent_Typ /= Tagged_Type
then
Collect (Parent_Typ);
end if;
-- Collect the components containing tags of secondary dispatch
-- tables.
Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
while Present (Tag_Comp) loop
pragma Assert (Present (Related_Type (Tag_Comp)));
Append_Elmt (Tag_Comp, Components_List);
Tag_Comp := Next_Tag_Component (Tag_Comp);
end loop;
end Collect;
-- Start of processing for Collect_Interface_Components
begin
pragma Assert (Ekind (Tagged_Type) = E_Record_Type
and then Is_Tagged_Type (Tagged_Type));
Components_List := New_Elmt_List;
Collect (Tagged_Type);
end Collect_Interface_Components;
-----------------------------
-- Collect_Interfaces_Info --
-----------------------------
procedure Collect_Interfaces_Info
(T : Entity_Id;
Ifaces_List : out Elist_Id;
Components_List : out Elist_Id;
Tags_List : out Elist_Id)
is
Comps_List : Elist_Id;
Comp_Elmt : Elmt_Id;
Comp_Iface : Entity_Id;
Iface_Elmt : Elmt_Id;
Iface : Entity_Id;
function Search_Tag (Iface : Entity_Id) return Entity_Id;
-- Search for the secondary tag associated with the interface type
-- Iface that is implemented by T.
----------------
-- Search_Tag --
----------------
function Search_Tag (Iface : Entity_Id) return Entity_Id is
ADT : Elmt_Id;
begin
if not Is_CPP_Class (T) then
ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
else
ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
end if;
while Present (ADT)
and then Is_Tag (Node (ADT))
and then Related_Type (Node (ADT)) /= Iface
loop
-- Skip secondary dispatch table referencing thunks to user
-- defined primitives covered by this interface.
pragma Assert (Has_Suffix (Node (ADT), 'P'));
Next_Elmt (ADT);
-- Skip secondary dispatch tables of Ada types
if not Is_CPP_Class (T) then
-- Skip secondary dispatch table referencing thunks to
-- predefined primitives.
pragma Assert (Has_Suffix (Node (ADT), 'Y'));
Next_Elmt (ADT);
-- Skip secondary dispatch table referencing user-defined
-- primitives covered by this interface.
pragma Assert (Has_Suffix (Node (ADT), 'D'));
Next_Elmt (ADT);
-- Skip secondary dispatch table referencing predefined
-- primitives.
pragma Assert (Has_Suffix (Node (ADT), 'Z'));
Next_Elmt (ADT);
end if;
end loop;
pragma Assert (Is_Tag (Node (ADT)));
return Node (ADT);
end Search_Tag;
-- Start of processing for Collect_Interfaces_Info
begin
Collect_Interfaces (T, Ifaces_List);
Collect_Interface_Components (T, Comps_List);
-- Search for the record component and tag associated with each
-- interface type of T.
Components_List := New_Elmt_List;
Tags_List := New_Elmt_List;
Iface_Elmt := First_Elmt (Ifaces_List);
while Present (Iface_Elmt) loop
Iface := Node (Iface_Elmt);
-- Associate the primary tag component and the primary dispatch table
-- with all the interfaces that are parents of T
if Is_Ancestor (Iface, T, Use_Full_View => True) then
Append_Elmt (First_Tag_Component (T), Components_List);
Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
-- Otherwise search for the tag component and secondary dispatch
-- table of Iface
else
Comp_Elmt := First_Elmt (Comps_List);
while Present (Comp_Elmt) loop
Comp_Iface := Related_Type (Node (Comp_Elmt));
if Comp_Iface = Iface
or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
then
Append_Elmt (Node (Comp_Elmt), Components_List);
Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
exit;
end if;
Next_Elmt (Comp_Elmt);
end loop;
pragma Assert (Present (Comp_Elmt));
end if;
Next_Elmt (Iface_Elmt);
end loop;
end Collect_Interfaces_Info;
---------------------
-- Collect_Parents --
---------------------
procedure Collect_Parents
(T : Entity_Id;
List : out Elist_Id;
Use_Full_View : Boolean := True)
is
Current_Typ : Entity_Id := T;
Parent_Typ : Entity_Id;
begin
List := New_Elmt_List;
-- No action if the if the type has no parents
if T = Etype (T) then
return;
end if;
loop
Parent_Typ := Etype (Current_Typ);
if Is_Private_Type (Parent_Typ)
and then Present (Full_View (Parent_Typ))
and then Use_Full_View
then
Parent_Typ := Full_View (Base_Type (Parent_Typ));
end if;
Append_Elmt (Parent_Typ, List);
exit when Parent_Typ = Current_Typ;
Current_Typ := Parent_Typ;
end loop;
end Collect_Parents;
----------------------------------
-- Collect_Primitive_Operations --
----------------------------------
function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
B_Type : constant Entity_Id := Base_Type (T);
B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
B_Scope : Entity_Id := Scope (B_Type);
Op_List : Elist_Id;
Formal : Entity_Id;
Is_Prim : Boolean;
Is_Type_In_Pkg : Boolean;
Formal_Derived : Boolean := False;
Id : Entity_Id;
function Match (E : Entity_Id) return Boolean;
-- True if E's base type is B_Type, or E is of an anonymous access type
-- and the base type of its designated type is B_Type.
-----------
-- Match --
-----------
function Match (E : Entity_Id) return Boolean is
Etyp : Entity_Id := Etype (E);
begin
if Ekind (Etyp) = E_Anonymous_Access_Type then
Etyp := Designated_Type (Etyp);
end if;
-- In Ada 2012 a primitive operation may have a formal of an
-- incomplete view of the parent type.
return Base_Type (Etyp) = B_Type
or else
(Ada_Version >= Ada_2012
and then Ekind (Etyp) = E_Incomplete_Type
and then Full_View (Etyp) = B_Type);
end Match;
-- Start of processing for Collect_Primitive_Operations
begin
-- For tagged types, the primitive operations are collected as they
-- are declared, and held in an explicit list which is simply returned.
if Is_Tagged_Type (B_Type) then
return Primitive_Operations (B_Type);
-- An untagged generic type that is a derived type inherits the
-- primitive operations of its parent type. Other formal types only
-- have predefined operators, which are not explicitly represented.
elsif Is_Generic_Type (B_Type) then
if Nkind (B_Decl) = N_Formal_Type_Declaration
and then Nkind (Formal_Type_Definition (B_Decl)) =
N_Formal_Derived_Type_Definition
then
Formal_Derived := True;
else
return New_Elmt_List;
end if;
end if;
Op_List := New_Elmt_List;
if B_Scope = Standard_Standard then
if B_Type = Standard_String then
Append_Elmt (Standard_Op_Concat, Op_List);
elsif B_Type = Standard_Wide_String then
Append_Elmt (Standard_Op_Concatw, Op_List);
else
null;
end if;
-- Locate the primitive subprograms of the type
else
-- The primitive operations appear after the base type, except
-- if the derivation happens within the private part of B_Scope
-- and the type is a private type, in which case both the type
-- and some primitive operations may appear before the base
-- type, and the list of candidates starts after the type.
if In_Open_Scopes (B_Scope)
and then Scope (T) = B_Scope
and then In_Private_Part (B_Scope)
then
Id := Next_Entity (T);
-- In Ada 2012, If the type has an incomplete partial view, there
-- may be primitive operations declared before the full view, so
-- we need to start scanning from the incomplete view, which is
-- earlier on the entity chain.
elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
and then Present (Incomplete_View (Parent (B_Type)))
then
Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
-- If T is a derived from a type with an incomplete view declared
-- elsewhere, that incomplete view is irrelevant, we want the
-- operations in the scope of T.
if Scope (Id) /= Scope (B_Type) then
Id := Next_Entity (B_Type);
end if;
else
Id := Next_Entity (B_Type);
end if;
-- Set flag if this is a type in a package spec
Is_Type_In_Pkg :=
Is_Package_Or_Generic_Package (B_Scope)
and then
Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
N_Package_Body;
while Present (Id) loop
-- Test whether the result type or any of the parameter types of
-- each subprogram following the type match that type when the
-- type is declared in a package spec, is a derived type, or the
-- subprogram is marked as primitive. (The Is_Primitive test is
-- needed to find primitives of nonderived types in declarative
-- parts that happen to override the predefined "=" operator.)
-- Note that generic formal subprograms are not considered to be
-- primitive operations and thus are never inherited.
if Is_Overloadable (Id)
and then (Is_Type_In_Pkg
or else Is_Derived_Type (B_Type)
or else Is_Primitive (Id))
and then Nkind (Parent (Parent (Id)))
not in N_Formal_Subprogram_Declaration
then
Is_Prim := False;
if Match (Id) then
Is_Prim := True;
else
Formal := First_Formal (Id);
while Present (Formal) loop
if Match (Formal) then
Is_Prim := True;
exit;
end if;
Next_Formal (Formal);
end loop;
end if;
-- For a formal derived type, the only primitives are the ones
-- inherited from the parent type. Operations appearing in the
-- package declaration are not primitive for it.
if Is_Prim
and then (not Formal_Derived or else Present (Alias (Id)))
then
-- In the special case of an equality operator aliased to
-- an overriding dispatching equality belonging to the same
-- type, we don't include it in the list of primitives.
-- This avoids inheriting multiple equality operators when
-- deriving from untagged private types whose full type is
-- tagged, which can otherwise cause ambiguities. Note that
-- this should only happen for this kind of untagged parent
-- type, since normally dispatching operations are inherited
-- using the type's Primitive_Operations list.
if Chars (Id) = Name_Op_Eq
and then Is_Dispatching_Operation (Id)
and then Present (Alias (Id))
and then Present (Overridden_Operation (Alias (Id)))
and then Base_Type (Etype (First_Entity (Id))) =
Base_Type (Etype (First_Entity (Alias (Id))))
then
null;
-- Include the subprogram in the list of primitives
else
Append_Elmt (Id, Op_List);
end if;
end if;
end if;
Next_Entity (Id);
-- For a type declared in System, some of its operations may
-- appear in the target-specific extension to System.
if No (Id)
and then B_Scope = RTU_Entity (System)
and then Present_System_Aux
then
B_Scope := System_Aux_Id;
Id := First_Entity (System_Aux_Id);
end if;
end loop;
end if;
return Op_List;
end Collect_Primitive_Operations;
-----------------------------------
-- Compile_Time_Constraint_Error --
-----------------------------------
function Compile_Time_Constraint_Error
(N : Node_Id;
Msg : String;
Ent : Entity_Id := Empty;
Loc : Source_Ptr := No_Location;
Warn : Boolean := False) return Node_Id
is
Msgc : String (1 .. Msg'Length + 3);
-- Copy of message, with room for possible ?? or << and ! at end
Msgl : Natural;
Wmsg : Boolean;
Eloc : Source_Ptr;
-- Start of processing for Compile_Time_Constraint_Error
begin
-- If this is a warning, convert it into an error if we are in code
-- subject to SPARK_Mode being set On, unless Warn is True to force a
-- warning. The rationale is that a compile-time constraint error should
-- lead to an error instead of a warning when SPARK_Mode is On, but in
-- a few cases we prefer to issue a warning and generate both a suitable
-- run-time error in GNAT and a suitable check message in GNATprove.
-- Those cases are those that likely correspond to deactivated SPARK
-- code, so that this kind of code can be compiled and analyzed instead
-- of being rejected.
Error_Msg_Warn := Warn or SPARK_Mode /= On;
-- A static constraint error in an instance body is not a fatal error.
-- we choose to inhibit the message altogether, because there is no
-- obvious node (for now) on which to post it. On the other hand the
-- offending node must be replaced with a constraint_error in any case.
-- No messages are generated if we already posted an error on this node
if not Error_Posted (N) then
if Loc /= No_Location then
Eloc := Loc;
else
Eloc := Sloc (N);
end if;
-- Copy message to Msgc, converting any ? in the message into
-- < instead, so that we have an error in GNATprove mode.
Msgl := Msg'Length;
for J in 1 .. Msgl loop
if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
Msgc (J) := '<';
else
Msgc (J) := Msg (J);
end if;
end loop;
-- Message is a warning, even in Ada 95 case
if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
Wmsg := True;
-- In Ada 83, all messages are warnings. In the private part and
-- the body of an instance, constraint_checks are only warnings.
-- We also make this a warning if the Warn parameter is set.
elsif Warn
or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
then
Msgl := Msgl + 1;
Msgc (Msgl) := '<';
Msgl := Msgl + 1;
Msgc (Msgl) := '<';
Wmsg := True;
elsif In_Instance_Not_Visible then
Msgl := Msgl + 1;
Msgc (Msgl) := '<';
Msgl := Msgl + 1;
Msgc (Msgl) := '<';
Wmsg := True;
-- Otherwise we have a real error message (Ada 95 static case)
-- and we make this an unconditional message. Note that in the
-- warning case we do not make the message unconditional, it seems
-- quite reasonable to delete messages like this (about exceptions
-- that will be raised) in dead code.
else
Wmsg := False;
Msgl := Msgl + 1;
Msgc (Msgl) := '!';
end if;
-- One more test, skip the warning if the related expression is
-- statically unevaluated, since we don't want to warn about what
-- will happen when something is evaluated if it never will be
-- evaluated.
if not Is_Statically_Unevaluated (N) then
if Present (Ent) then
Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
else
Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
end if;
if Wmsg then
-- Check whether the context is an Init_Proc
if Inside_Init_Proc then
declare
Conc_Typ : constant Entity_Id :=
Corresponding_Concurrent_Type
(Entity (Parameter_Type (First
(Parameter_Specifications
(Parent (Current_Scope))))));
begin
-- Don't complain if the corresponding concurrent type
-- doesn't come from source (i.e. a single task/protected
-- object).
if Present (Conc_Typ)
and then not Comes_From_Source (Conc_Typ)
then
Error_Msg_NEL
("\& [<<", N, Standard_Constraint_Error, Eloc);
else
if GNATprove_Mode then
Error_Msg_NEL
("\& would have been raised for objects of this "
& "type", N, Standard_Constraint_Error, Eloc);
else
Error_Msg_NEL
("\& will be raised for objects of this type??",
N, Standard_Constraint_Error, Eloc);
end if;
end if;
end;
else
Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
end if;
else
Error_Msg ("\static expression fails Constraint_Check", Eloc);
Set_Error_Posted (N);
end if;
end if;
end if;
return N;
end Compile_Time_Constraint_Error;
-----------------------
-- Conditional_Delay --
-----------------------
procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
begin
if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
Set_Has_Delayed_Freeze (New_Ent);
end if;
end Conditional_Delay;
----------------------------
-- Contains_Refined_State --
----------------------------
function Contains_Refined_State (Prag : Node_Id) return Boolean is
function Has_State_In_Dependency (List : Node_Id) return Boolean;
-- Determine whether a dependency list mentions a state with a visible
-- refinement.
function Has_State_In_Global (List : Node_Id) return Boolean;
-- Determine whether a global list mentions a state with a visible
-- refinement.
function Is_Refined_State (Item : Node_Id) return Boolean;
-- Determine whether Item is a reference to an abstract state with a
-- visible refinement.
-----------------------------
-- Has_State_In_Dependency --
-----------------------------
function Has_State_In_Dependency (List : Node_Id) return Boolean is
Clause : Node_Id;
Output : Node_Id;
begin
-- A null dependency list does not mention any states
if Nkind (List) = N_Null then
return False;
-- Dependency clauses appear as component associations of an
-- aggregate.
elsif Nkind (List) = N_Aggregate
and then Present (Component_Associations (List))
then
Clause := First (Component_Associations (List));
while Present (Clause) loop
-- Inspect the outputs of a dependency clause
Output := First (Choices (Clause));
while Present (Output) loop
if Is_Refined_State (Output) then
return True;
end if;
Next (Output);
end loop;
-- Inspect the outputs of a dependency clause
if Is_Refined_State (Expression (Clause)) then
return True;
end if;
Next (Clause);
end loop;
-- If we get here, then none of the dependency clauses mention a
-- state with visible refinement.
return False;
-- An illegal pragma managed to sneak in
else
raise Program_Error;
end if;
end Has_State_In_Dependency;
-------------------------
-- Has_State_In_Global --
-------------------------
function Has_State_In_Global (List : Node_Id) return Boolean is
Item : Node_Id;
begin
-- A null global list does not mention any states
if Nkind (List) = N_Null then
return False;
-- Simple global list or moded global list declaration
elsif Nkind (List) = N_Aggregate then
-- The declaration of a simple global list appear as a collection
-- of expressions.
if Present (Expressions (List)) then
Item := First (Expressions (List));
while Present (Item) loop
if Is_Refined_State (Item) then
return True;
end if;
Next (Item);
end loop;
-- The declaration of a moded global list appears as a collection
-- of component associations where individual choices denote
-- modes.
else
Item := First (Component_Associations (List));
while Present (Item) loop
if Has_State_In_Global (Expression (Item)) then
return True;
end if;
Next (Item);
end loop;
end if;
-- If we get here, then the simple/moded global list did not
-- mention any states with a visible refinement.
return False;
-- Single global item declaration
elsif Is_Entity_Name (List) then
return Is_Refined_State (List);
-- An illegal pragma managed to sneak in
else
raise Program_Error;
end if;
end Has_State_In_Global;
----------------------
-- Is_Refined_State --
----------------------
function Is_Refined_State (Item : Node_Id) return Boolean is
Elmt : Node_Id;
Item_Id : Entity_Id;
begin
if Nkind (Item) = N_Null then
return False;
-- States cannot be subject to attribute 'Result. This case arises
-- in dependency relations.
elsif Nkind (Item) = N_Attribute_Reference
and then Attribute_Name (Item) = Name_Result
then
return False;
-- Multiple items appear as an aggregate. This case arises in
-- dependency relations.
elsif Nkind (Item) = N_Aggregate
and then Present (Expressions (Item))
then
Elmt := First (Expressions (Item));
while Present (Elmt) loop
if Is_Refined_State (Elmt) then
return True;
end if;
Next (Elmt);
end loop;
-- If we get here, then none of the inputs or outputs reference a
-- state with visible refinement.
return False;
-- Single item
else
Item_Id := Entity_Of (Item);
return
Present (Item_Id)
and then Ekind (Item_Id) = E_Abstract_State
and then Has_Visible_Refinement (Item_Id);
end if;
end Is_Refined_State;
-- Local variables
Arg : constant Node_Id :=
Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
Nam : constant Name_Id := Pragma_Name (Prag);
-- Start of processing for Contains_Refined_State
begin
if Nam = Name_Depends then
return Has_State_In_Dependency (Arg);
else pragma Assert (Nam = Name_Global);
return Has_State_In_Global (Arg);
end if;
end Contains_Refined_State;
-------------------------
-- Copy_Component_List --
-------------------------
function Copy_Component_List
(R_Typ : Entity_Id;
Loc : Source_Ptr) return List_Id
is
Comp : Node_Id;
Comps : constant List_Id := New_List;
begin
Comp := First_Component (Underlying_Type (R_Typ));
while Present (Comp) loop
if Comes_From_Source (Comp) then
declare
Comp_Decl : constant Node_Id := Declaration_Node (Comp);
begin
Append_To (Comps,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Comp)),
Component_Definition =>
New_Copy_Tree
(Component_Definition (Comp_Decl), New_Sloc => Loc)));
end;
end if;
Next_Component (Comp);
end loop;
return Comps;
end Copy_Component_List;
-------------------------
-- Copy_Parameter_List --
-------------------------
function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
Loc : constant Source_Ptr := Sloc (Subp_Id);
Plist : List_Id;
Formal : Entity_Id;
begin
if No (First_Formal (Subp_Id)) then
return No_List;
else
Plist := New_List;
Formal := First_Formal (Subp_Id);
while Present (Formal) loop
Append_To (Plist,
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
In_Present => In_Present (Parent (Formal)),
Out_Present => Out_Present (Parent (Formal)),
Parameter_Type =>
New_Occurrence_Of (Etype (Formal), Loc),
Expression =>
New_Copy_Tree (Expression (Parent (Formal)))));
Next_Formal (Formal);
end loop;
end if;
return Plist;
end Copy_Parameter_List;
----------------------------
-- Copy_SPARK_Mode_Aspect --
----------------------------
procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
pragma Assert (not Has_Aspects (To));
Asp : Node_Id;
begin
if Has_Aspects (From) then
Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
if Present (Asp) then
Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
Set_Has_Aspects (To, True);
end if;
end if;
end Copy_SPARK_Mode_Aspect;
--------------------------
-- Copy_Subprogram_Spec --
--------------------------
function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
Def_Id : Node_Id;
Formal_Spec : Node_Id;
Result : Node_Id;
begin
-- The structure of the original tree must be replicated without any
-- alterations. Use New_Copy_Tree for this purpose.
Result := New_Copy_Tree (Spec);
-- Create a new entity for the defining unit name
Def_Id := Defining_Unit_Name (Result);
Set_Defining_Unit_Name (Result,
Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
-- Create new entities for the formal parameters
if Present (Parameter_Specifications (Result)) then
Formal_Spec := First (Parameter_Specifications (Result));
while Present (Formal_Spec) loop
Def_Id := Defining_Identifier (Formal_Spec);
Set_Defining_Identifier (Formal_Spec,
Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
Next (Formal_Spec);
end loop;
end if;
return Result;
end Copy_Subprogram_Spec;
--------------------------------
-- Corresponding_Generic_Type --
--------------------------------
function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
Inst : Entity_Id;
Gen : Entity_Id;
Typ : Entity_Id;
begin
if not Is_Generic_Actual_Type (T) then
return Any_Type;
-- If the actual is the actual of an enclosing instance, resolution
-- was correct in the generic.
elsif Nkind (Parent (T)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (T)))
and then
Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
then
return Any_Type;
else
Inst := Scope (T);
if Is_Wrapper_Package (Inst) then
Inst := Related_Instance (Inst);
end if;
Gen :=
Generic_Parent
(Specification (Unit_Declaration_Node (Inst)));
-- Generic actual has the same name as the corresponding formal
Typ := First_Entity (Gen);
while Present (Typ) loop
if Chars (Typ) = Chars (T) then
return Typ;
end if;
Next_Entity (Typ);
end loop;
return Any_Type;
end if;
end Corresponding_Generic_Type;
--------------------
-- Current_Entity --
--------------------
-- The currently visible definition for a given identifier is the
-- one most chained at the start of the visibility chain, i.e. the
-- one that is referenced by the Node_Id value of the name of the
-- given identifier.
function Current_Entity (N : Node_Id) return Entity_Id is
begin
return Get_Name_Entity_Id (Chars (N));
end Current_Entity;
-----------------------------
-- Current_Entity_In_Scope --
-----------------------------
function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
E : Entity_Id;
CS : constant Entity_Id := Current_Scope;
Transient_Case : constant Boolean := Scope_Is_Transient;
begin
E := Get_Name_Entity_Id (Chars (N));
while Present (E)
and then Scope (E) /= CS
and then (not Transient_Case or else Scope (E) /= Scope (CS))
loop
E := Homonym (E);
end loop;
return E;
end Current_Entity_In_Scope;
-------------------
-- Current_Scope --
-------------------
function Current_Scope return Entity_Id is
begin
if Scope_Stack.Last = -1 then
return Standard_Standard;
else
declare
C : constant Entity_Id :=
Scope_Stack.Table (Scope_Stack.Last).Entity;
begin
if Present (C) then
return C;
else
return Standard_Standard;
end if;
end;
end if;
end Current_Scope;
----------------------------
-- Current_Scope_No_Loops --
----------------------------
function Current_Scope_No_Loops return Entity_Id is
S : Entity_Id;
begin
-- Examine the scope stack starting from the current scope and skip any
-- internally generated loops.
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
S := Scope (S);
else
exit;
end if;
end loop;
return S;
end Current_Scope_No_Loops;
------------------------
-- Current_Subprogram --
------------------------
function Current_Subprogram return Entity_Id is
Scop : constant Entity_Id := Current_Scope;
begin
if Is_Subprogram_Or_Generic_Subprogram (Scop) then
return Scop;
else
return Enclosing_Subprogram (Scop);
end if;
end Current_Subprogram;
----------------------------------
-- Deepest_Type_Access_Level --
----------------------------------
function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
begin
if Ekind (Typ) = E_Anonymous_Access_Type
and then not Is_Local_Anonymous_Access (Typ)
and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
then
-- Typ is the type of an Ada 2012 stand-alone object of an anonymous
-- access type.
return
Scope_Depth (Enclosing_Dynamic_Scope
(Defining_Identifier
(Associated_Node_For_Itype (Typ))));
-- For generic formal type, return Int'Last (infinite).
-- See comment preceding Is_Generic_Type call in Type_Access_Level.
elsif Is_Generic_Type (Root_Type (Typ)) then
return UI_From_Int (Int'Last);
else
return Type_Access_Level (Typ);
end if;
end Deepest_Type_Access_Level;
---------------------
-- Defining_Entity --
---------------------
function Defining_Entity
(N : Node_Id;
Empty_On_Errors : Boolean := False) return Entity_Id
is
Err : Entity_Id := Empty;
begin
case Nkind (N) is
when N_Abstract_Subprogram_Declaration
| N_Expression_Function
| N_Formal_Subprogram_Declaration
| N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Subprogram_Body
| N_Subprogram_Body_Stub
| N_Subprogram_Declaration
| N_Subprogram_Renaming_Declaration
=>
return Defining_Entity (Specification (N));
when N_Component_Declaration
| N_Defining_Program_Unit_Name
| N_Discriminant_Specification
| N_Entry_Body
| N_Entry_Declaration
| N_Entry_Index_Specification
| N_Exception_Declaration
| N_Exception_Renaming_Declaration
| N_Formal_Object_Declaration
| N_Formal_Package_Declaration
| N_Formal_Type_Declaration
| N_Full_Type_Declaration
| N_Implicit_Label_Declaration
| N_Incomplete_Type_Declaration
| N_Iterator_Specification
| N_Loop_Parameter_Specification
| N_Number_Declaration
| N_Object_Declaration
| N_Object_Renaming_Declaration
| N_Package_Body_Stub
| N_Parameter_Specification
| N_Private_Extension_Declaration
| N_Private_Type_Declaration
| N_Protected_Body
| N_Protected_Body_Stub
| N_Protected_Type_Declaration
| N_Single_Protected_Declaration
| N_Single_Task_Declaration
| N_Subtype_Declaration
| N_Task_Body
| N_Task_Body_Stub
| N_Task_Type_Declaration
=>
return Defining_Identifier (N);
when N_Subunit =>
return Defining_Entity (Proper_Body (N));
when N_Function_Instantiation
| N_Function_Specification
| N_Generic_Function_Renaming_Declaration
| N_Generic_Package_Renaming_Declaration
| N_Generic_Procedure_Renaming_Declaration
| N_Package_Body
| N_Package_Instantiation
| N_Package_Renaming_Declaration
| N_Package_Specification
| N_Procedure_Instantiation
| N_Procedure_Specification
=>
declare
Nam : constant Node_Id := Defining_Unit_Name (N);
begin
if Nkind (Nam) in N_Entity then
return Nam;
-- For Error, make up a name and attach to declaration so we
-- can continue semantic analysis.
elsif Nam = Error then
if Empty_On_Errors then
return Empty;
else
Err := Make_Temporary (Sloc (N), 'T');
Set_Defining_Unit_Name (N, Err);
return Err;
end if;
-- If not an entity, get defining identifier
else
return Defining_Identifier (Nam);
end if;
end;
when N_Block_Statement
| N_Loop_Statement
=>
return Entity (Identifier (N));
when others =>
if Empty_On_Errors then
return Empty;
else
raise Program_Error;
end if;
end case;
end Defining_Entity;
--------------------------
-- Denotes_Discriminant --
--------------------------
function Denotes_Discriminant
(N : Node_Id;
Check_Concurrent : Boolean := False) return Boolean
is
E : Entity_Id;
begin
if not Is_Entity_Name (N) or else No (Entity (N)) then
return False;
else
E := Entity (N);
end if;
-- If we are checking for a protected type, the discriminant may have
-- been rewritten as the corresponding discriminal of the original type
-- or of the corresponding concurrent record, depending on whether we
-- are in the spec or body of the protected type.
return Ekind (E) = E_Discriminant
or else
(Check_Concurrent
and then Ekind (E) = E_In_Parameter
and then Present (Discriminal_Link (E))
and then
(Is_Concurrent_Type (Scope (Discriminal_Link (E)))
or else
Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
end Denotes_Discriminant;
-------------------------
-- Denotes_Same_Object --
-------------------------
function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
Obj1 : Node_Id := A1;
Obj2 : Node_Id := A2;
function Has_Prefix (N : Node_Id) return Boolean;
-- Return True if N has attribute Prefix
function Is_Renaming (N : Node_Id) return Boolean;
-- Return true if N names a renaming entity
function Is_Valid_Renaming (N : Node_Id) return Boolean;
-- For renamings, return False if the prefix of any dereference within
-- the renamed object_name is a variable, or any expression within the
-- renamed object_name contains references to variables or calls on
-- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
----------------
-- Has_Prefix --
----------------
function Has_Prefix (N : Node_Id) return Boolean is
begin
return
Nkind_In (N,
N_Attribute_Reference,
N_Expanded_Name,
N_Explicit_Dereference,
N_Indexed_Component,
N_Reference,
N_Selected_Component,
N_Slice);
end Has_Prefix;
-----------------
-- Is_Renaming --
-----------------
function Is_Renaming (N : Node_Id) return Boolean is
begin
return Is_Entity_Name (N)
and then Present (Renamed_Entity (Entity (N)));
end Is_Renaming;
-----------------------
-- Is_Valid_Renaming --
-----------------------
function Is_Valid_Renaming (N : Node_Id) return Boolean is
function Check_Renaming (N : Node_Id) return Boolean;
-- Recursive function used to traverse all the prefixes of N
function Check_Renaming (N : Node_Id) return Boolean is
begin
if Is_Renaming (N)
and then not Check_Renaming (Renamed_Entity (Entity (N)))
then
return False;
end if;
if Nkind (N) = N_Indexed_Component then
declare
Indx : Node_Id;
begin
Indx := First (Expressions (N));
while Present (Indx) loop
if not Is_OK_Static_Expression (Indx) then
return False;
end if;
Next_Index (Indx);
end loop;
end;
end if;
if Has_Prefix (N) then
declare
P : constant Node_Id := Prefix (N);
begin
if Nkind (N) = N_Explicit_Dereference
and then Is_Variable (P)
then
return False;
elsif Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Function
then
return False;
elsif Nkind (P) = N_Function_Call then
return False;
end if;
-- Recursion to continue traversing the prefix of the
-- renaming expression
return Check_Renaming (P);
end;
end if;
return True;
end Check_Renaming;
-- Start of processing for Is_Valid_Renaming
begin
return Check_Renaming (N);
end Is_Valid_Renaming;
-- Start of processing for Denotes_Same_Object
begin
-- Both names statically denote the same stand-alone object or parameter
-- (RM 6.4.1(6.5/3))
if Is_Entity_Name (Obj1)
and then Is_Entity_Name (Obj2)
and then Entity (Obj1) = Entity (Obj2)
then
return True;
end if;
-- For renamings, the prefix of any dereference within the renamed
-- object_name is not a variable, and any expression within the
-- renamed object_name contains no references to variables nor
-- calls on nonstatic functions (RM 6.4.1(6.10/3)).
if Is_Renaming (Obj1) then
if Is_Valid_Renaming (Obj1) then
Obj1 := Renamed_Entity (Entity (Obj1));
else
return False;
end if;
end if;
if Is_Renaming (Obj2) then
if Is_Valid_Renaming (Obj2) then
Obj2 := Renamed_Entity (Entity (Obj2));
else
return False;
end if;
end if;
-- No match if not same node kind (such cases are handled by
-- Denotes_Same_Prefix)
if Nkind (Obj1) /= Nkind (Obj2) then
return False;
-- After handling valid renamings, one of the two names statically
-- denoted a renaming declaration whose renamed object_name is known
-- to denote the same object as the other (RM 6.4.1(6.10/3))
elsif Is_Entity_Name (Obj1) then
if Is_Entity_Name (Obj2) then
return Entity (Obj1) = Entity (Obj2);
else
return False;
end if;
-- Both names are selected_components, their prefixes are known to
-- denote the same object, and their selector_names denote the same
-- component (RM 6.4.1(6.6/3)).
elsif Nkind (Obj1) = N_Selected_Component then
return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
and then
Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
-- Both names are dereferences and the dereferenced names are known to
-- denote the same object (RM 6.4.1(6.7/3))
elsif Nkind (Obj1) = N_Explicit_Dereference then
return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
-- Both names are indexed_components, their prefixes are known to denote
-- the same object, and each of the pairs of corresponding index values
-- are either both static expressions with the same static value or both
-- names that are known to denote the same object (RM 6.4.1(6.8/3))
elsif Nkind (Obj1) = N_Indexed_Component then
if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
return False;
else
declare
Indx1 : Node_Id;
Indx2 : Node_Id;
begin
Indx1 := First (Expressions (Obj1));
Indx2 := First (Expressions (Obj2));
while Present (Indx1) loop
-- Indexes must denote the same static value or same object
if Is_OK_Static_Expression (Indx1) then
if not Is_OK_Static_Expression (Indx2) then
return False;
elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
return False;
end if;
elsif not Denotes_Same_Object (Indx1, Indx2) then
return False;
end if;
Next (Indx1);
Next (Indx2);
end loop;
return True;
end;
end if;
-- Both names are slices, their prefixes are known to denote the same
-- object, and the two slices have statically matching index constraints
-- (RM 6.4.1(6.9/3))
elsif Nkind (Obj1) = N_Slice
and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
then
declare
Lo1, Lo2, Hi1, Hi2 : Node_Id;
begin
Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
-- Check whether bounds are statically identical. There is no
-- attempt to detect partial overlap of slices.
return Denotes_Same_Object (Lo1, Lo2)
and then
Denotes_Same_Object (Hi1, Hi2);
end;
-- In the recursion, literals appear as indexes
elsif Nkind (Obj1) = N_Integer_Literal
and then
Nkind (Obj2) = N_Integer_Literal
then
return Intval (Obj1) = Intval (Obj2);
else
return False;
end if;
end Denotes_Same_Object;
-------------------------
-- Denotes_Same_Prefix --
-------------------------
function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
begin
if Is_Entity_Name (A1) then
if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
and then not Is_Access_Type (Etype (A1))
then
return Denotes_Same_Object (A1, Prefix (A2))
or else Denotes_Same_Prefix (A1, Prefix (A2));
else
return False;
end if;
elsif Is_Entity_Name (A2) then
return Denotes_Same_Prefix (A1 => A2, A2 => A1);
elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
and then
Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
then
declare
Root1, Root2 : Node_Id;
Depth1, Depth2 : Nat := 0;
begin
Root1 := Prefix (A1);
while not Is_Entity_Name (Root1) loop
if not Nkind_In
(Root1, N_Selected_Component, N_Indexed_Component)
then
return False;
else
Root1 := Prefix (Root1);
end if;
Depth1 := Depth1 + 1;
end loop;
Root2 := Prefix (A2);
while not Is_Entity_Name (Root2) loop
if not Nkind_In (Root2, N_Selected_Component,
N_Indexed_Component)
then
return False;
else
Root2 := Prefix (Root2);
end if;
Depth2 := Depth2 + 1;
end loop;
-- If both have the same depth and they do not denote the same
-- object, they are disjoint and no warning is needed.
if Depth1 = Depth2 then
return False;
elsif Depth1 > Depth2 then
Root1 := Prefix (A1);
for J in 1 .. Depth1 - Depth2 - 1 loop
Root1 := Prefix (Root1);
end loop;
return Denotes_Same_Object (Root1, A2);
else
Root2 := Prefix (A2);
for J in 1 .. Depth2 - Depth1 - 1 loop
Root2 := Prefix (Root2);
end loop;
return Denotes_Same_Object (A1, Root2);
end if;
end;
else
return False;
end if;
end Denotes_Same_Prefix;
----------------------
-- Denotes_Variable --
----------------------
function Denotes_Variable (N : Node_Id) return Boolean is
begin
return Is_Variable (N) and then Paren_Count (N) = 0;
end Denotes_Variable;
-----------------------------
-- Depends_On_Discriminant --
-----------------------------
function Depends_On_Discriminant (N : Node_Id) return Boolean is
L : Node_Id;
H : Node_Id;
begin
Get_Index_Bounds (N, L, H);
return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
end Depends_On_Discriminant;
-------------------------
-- Designate_Same_Unit --
-------------------------
function Designate_Same_Unit
(Name1 : Node_Id;
Name2 : Node_Id) return Boolean
is
K1 : constant Node_Kind := Nkind (Name1);
K2 : constant Node_Kind := Nkind (Name2);
function Prefix_Node (N : Node_Id) return Node_Id;
-- Returns the parent unit name node of a defining program unit name
-- or the prefix if N is a selected component or an expanded name.
function Select_Node (N : Node_Id) return Node_Id;
-- Returns the defining identifier node of a defining program unit
-- name or the selector node if N is a selected component or an
-- expanded name.
-----------------
-- Prefix_Node --
-----------------
function Prefix_Node (N : Node_Id) return Node_Id is
begin
if Nkind (N) = N_Defining_Program_Unit_Name then
return Name (N);
else
return Prefix (N);
end if;
end Prefix_Node;
-----------------
-- Select_Node --
-----------------
function Select_Node (N : Node_Id) return Node_Id is
begin
if Nkind (N) = N_Defining_Program_Unit_Name then
return Defining_Identifier (N);
else
return Selector_Name (N);
end if;
end Select_Node;
-- Start of processing for Designate_Same_Unit
begin
if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
and then
Nkind_In (K2, N_Identifier, N_Defining_Identifier)
then
return Chars (Name1) = Chars (Name2);
elsif Nkind_In (K1, N_Expanded_Name,
N_Selected_Component,
N_Defining_Program_Unit_Name)
and then
Nkind_In (K2, N_Expanded_Name,
N_Selected_Component,
N_Defining_Program_Unit_Name)
then
return
(Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
and then
Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
else
return False;
end if;
end Designate_Same_Unit;
------------------------------------------
-- function Dynamic_Accessibility_Level --
------------------------------------------
function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
E : Entity_Id;
Loc : constant Source_Ptr := Sloc (Expr);
function Make_Level_Literal (Level : Uint) return Node_Id;
-- Construct an integer literal representing an accessibility level
-- with its type set to Natural.
------------------------
-- Make_Level_Literal --
------------------------
function Make_Level_Literal (Level : Uint) return Node_Id is
Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
begin
Set_Etype (Result, Standard_Natural);
return Result;
end Make_Level_Literal;
-- Start of processing for Dynamic_Accessibility_Level
begin
if Is_Entity_Name (Expr) then
E := Entity (Expr);
if Present (Renamed_Object (E)) then
return Dynamic_Accessibility_Level (Renamed_Object (E));
end if;
if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
if Present (Extra_Accessibility (E)) then
return New_Occurrence_Of (Extra_Accessibility (E), Loc);
end if;
end if;
end if;
-- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
case Nkind (Expr) is
-- For access discriminant, the level of the enclosing object
when N_Selected_Component =>
if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
E_Anonymous_Access_Type
then
return Make_Level_Literal (Object_Access_Level (Expr));
end if;
when N_Attribute_Reference =>
case Get_Attribute_Id (Attribute_Name (Expr)) is
-- For X'Access, the level of the prefix X
when Attribute_Access =>
return Make_Level_Literal
(Object_Access_Level (Prefix (Expr)));
-- Treat the unchecked attributes as library-level
when Attribute_Unchecked_Access
| Attribute_Unrestricted_Access
=>
return Make_Level_Literal (Scope_Depth (Standard_Standard));
-- No other access-valued attributes
when others =>
raise Program_Error;
end case;
when N_Allocator =>
-- Unimplemented: depends on context. As an actual parameter where
-- formal type is anonymous, use
-- Scope_Depth (Current_Scope) + 1.
-- For other cases, see 3.10.2(14/3) and following. ???
null;
when N_Type_Conversion =>
if not Is_Local_Anonymous_Access (Etype (Expr)) then
-- Handle type conversions introduced for a rename of an
-- Ada 2012 stand-alone object of an anonymous access type.
return Dynamic_Accessibility_Level (Expression (Expr));
end if;
when others =>
null;
end case;
return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
end Dynamic_Accessibility_Level;
-----------------------------------
-- Effective_Extra_Accessibility --
-----------------------------------
function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
begin
if Present (Renamed_Object (Id))
and then Is_Entity_Name (Renamed_Object (Id))
then
return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
else
return Extra_Accessibility (Id);
end if;
end Effective_Extra_Accessibility;
-----------------------------
-- Effective_Reads_Enabled --
-----------------------------
function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
begin
return Has_Enabled_Property (Id, Name_Effective_Reads);
end Effective_Reads_Enabled;
------------------------------
-- Effective_Writes_Enabled --
------------------------------
function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
begin
return Has_Enabled_Property (Id, Name_Effective_Writes);
end Effective_Writes_Enabled;
------------------------------
-- Enclosing_Comp_Unit_Node --
------------------------------
function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
Current_Node : Node_Id;
begin
Current_Node := N;
while Present (Current_Node)
and then Nkind (Current_Node) /= N_Compilation_Unit
loop
Current_Node := Parent (Current_Node);
end loop;
if Nkind (Current_Node) /= N_Compilation_Unit then
return Empty;
else
return Current_Node;
end if;
end Enclosing_Comp_Unit_Node;
--------------------------
-- Enclosing_CPP_Parent --
--------------------------
function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
Parent_Typ : Entity_Id := Typ;
begin
while not Is_CPP_Class (Parent_Typ)
and then Etype (Parent_Typ) /= Parent_Typ
loop
Parent_Typ := Etype (Parent_Typ);
if Is_Private_Type (Parent_Typ) then
Parent_Typ := Full_View (Base_Type (Parent_Typ));
end if;
end loop;
pragma Assert (Is_CPP_Class (Parent_Typ));
return Parent_Typ;
end Enclosing_CPP_Parent;
---------------------------
-- Enclosing_Declaration --
---------------------------
function Enclosing_Declaration (N : Node_Id) return Node_Id is
Decl : Node_Id := N;
begin
while Present (Decl)
and then not (Nkind (Decl) in N_Declaration
or else
Nkind (Decl) in N_Later_Decl_Item)
loop
Decl := Parent (Decl);
end loop;
return Decl;
end Enclosing_Declaration;
----------------------------
-- Enclosing_Generic_Body --
----------------------------
function Enclosing_Generic_Body
(N : Node_Id) return Node_Id
is
P : Node_Id;
Decl : Node_Id;
Spec : Node_Id;
begin
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_Package_Body
or else Nkind (P) = N_Subprogram_Body
then
Spec := Corresponding_Spec (P);
if Present (Spec) then
Decl := Unit_Declaration_Node (Spec);
if Nkind (Decl) = N_Generic_Package_Declaration
or else Nkind (Decl) = N_Generic_Subprogram_Declaration
then
return P;
end if;
end if;
end if;
P := Parent (P);
end loop;
return Empty;
end Enclosing_Generic_Body;
----------------------------
-- Enclosing_Generic_Unit --
----------------------------
function Enclosing_Generic_Unit
(N : Node_Id) return Node_Id
is
P : Node_Id;
Decl : Node_Id;
Spec : Node_Id;
begin
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_Generic_Package_Declaration
or else Nkind (P) = N_Generic_Subprogram_Declaration
then
return P;
elsif Nkind (P) = N_Package_Body
or else Nkind (P) = N_Subprogram_Body
then
Spec := Corresponding_Spec (P);
if Present (Spec) then
Decl := Unit_Declaration_Node (Spec);
if Nkind (Decl) = N_Generic_Package_Declaration
or else Nkind (Decl) = N_Generic_Subprogram_Declaration
then
return Decl;
end if;
end if;
end if;
P := Parent (P);
end loop;
return Empty;
end Enclosing_Generic_Unit;
-------------------------------
-- Enclosing_Lib_Unit_Entity --
-------------------------------
function Enclosing_Lib_Unit_Entity
(E : Entity_Id := Current_Scope) return Entity_Id
is
Unit_Entity : Entity_Id;
begin
-- Look for enclosing library unit entity by following scope links.
-- Equivalent to, but faster than indexing through the scope stack.
Unit_Entity := E;
while (Present (Scope (Unit_Entity))
and then Scope (Unit_Entity) /= Standard_Standard)
and not Is_Child_Unit (Unit_Entity)
loop
Unit_Entity := Scope (Unit_Entity);
end loop;
return Unit_Entity;
end Enclosing_Lib_Unit_Entity;
-----------------------------
-- Enclosing_Lib_Unit_Node --
-----------------------------
function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
Encl_Unit : Node_Id;
begin
Encl_Unit := Enclosing_Comp_Unit_Node (N);
while Present (Encl_Unit)
and then Nkind (Unit (Encl_Unit)) = N_Subunit
loop
Encl_Unit := Library_Unit (Encl_Unit);
end loop;
pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
return Encl_Unit;
end Enclosing_Lib_Unit_Node;
-----------------------
-- Enclosing_Package --
-----------------------
function Enclosing_Package (E : Entity_Id) return Entity_Id is
Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
begin
if Dynamic_Scope = Standard_Standard then
return Standard_Standard;
elsif Dynamic_Scope = Empty then
return Empty;
elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
E_Generic_Package)
then
return Dynamic_Scope;
else
return Enclosing_Package (Dynamic_Scope);
end if;
end Enclosing_Package;
-------------------------------------
-- Enclosing_Package_Or_Subprogram --
-------------------------------------
function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
S : Entity_Id;
begin
S := Scope (E);
while Present (S) loop
if Is_Package_Or_Generic_Package (S)
or else Ekind (S) = E_Package_Body
then
return S;
elsif Is_Subprogram_Or_Generic_Subprogram (S)
or else Ekind (S) = E_Subprogram_Body
then
return S;
else
S := Scope (S);
end if;
end loop;
return Empty;
end Enclosing_Package_Or_Subprogram;
--------------------------
-- Enclosing_Subprogram --
--------------------------
function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
begin
if Dynamic_Scope = Standard_Standard then
return Empty;
elsif Dynamic_Scope = Empty then
return Empty;
elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
elsif Ekind (Dynamic_Scope) = E_Block
or else Ekind (Dynamic_Scope) = E_Return_Statement
then
return Enclosing_Subprogram (Dynamic_Scope);
elsif Ekind (Dynamic_Scope) = E_Task_Type then
return Get_Task_Body_Procedure (Dynamic_Scope);
elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
and then Present (Full_View (Dynamic_Scope))
and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
then
return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
-- No body is generated if the protected operation is eliminated
elsif Convention (Dynamic_Scope) = Convention_Protected
and then not Is_Eliminated (Dynamic_Scope)
and then Present (Protected_Body_Subprogram (Dynamic_Scope))
then
return Protected_Body_Subprogram (Dynamic_Scope);
else
return Dynamic_Scope;
end if;
end Enclosing_Subprogram;
------------------------
-- Ensure_Freeze_Node --
------------------------
procedure Ensure_Freeze_Node (E : Entity_Id) is
FN : Node_Id;
begin
if No (Freeze_Node (E)) then
FN := Make_Freeze_Entity (Sloc (E));
Set_Has_Delayed_Freeze (E);
Set_Freeze_Node (E, FN);
Set_Access_Types_To_Process (FN, No_Elist);
Set_TSS_Elist (FN, No_Elist);
Set_Entity (FN, E);
end if;
end Ensure_Freeze_Node;
----------------
-- Enter_Name --
----------------
procedure Enter_Name (Def_Id : Entity_Id) is
C : constant Entity_Id := Current_Entity (Def_Id);
E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
S : constant Entity_Id := Current_Scope;
begin
Generate_Definition (Def_Id);
-- Add new name to current scope declarations. Check for duplicate
-- declaration, which may or may not be a genuine error.
if Present (E) then
-- Case of previous entity entered because of a missing declaration
-- or else a bad subtype indication. Best is to use the new entity,
-- and make the previous one invisible.
if Etype (E) = Any_Type then
Set_Is_Immediately_Visible (E, False);
-- Case of renaming declaration constructed for package instances.
-- if there is an explicit declaration with the same identifier,
-- the renaming is not immediately visible any longer, but remains
-- visible through selected component notation.
elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
and then not Comes_From_Source (E)
then
Set_Is_Immediately_Visible (E, False);
-- The new entity may be the package renaming, which has the same
-- same name as a generic formal which has been seen already.
elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
and then not Comes_From_Source (Def_Id)
then
Set_Is_Immediately_Visible (E, False);
-- For a fat pointer corresponding to a remote access to subprogram,
-- we use the same identifier as the RAS type, so that the proper
-- name appears in the stub. This type is only retrieved through
-- the RAS type and never by visibility, and is not added to the
-- visibility list (see below).
elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
and then Ekind (Def_Id) = E_Record_Type
and then Present (Corresponding_Remote_Type (Def_Id))
then
null;
-- Case of an implicit operation or derived literal. The new entity
-- hides the implicit one, which is removed from all visibility,
-- i.e. the entity list of its scope, and homonym chain of its name.
elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
or else Is_Internal (E)
then
declare
Decl : constant Node_Id := Parent (E);
Prev : Entity_Id;
Prev_Vis : Entity_Id;
begin
-- If E is an implicit declaration, it cannot be the first
-- entity in the scope.
Prev := First_Entity (Current_Scope);
while Present (Prev) and then Next_Entity (Prev) /= E loop
Next_Entity (Prev);
end loop;
if No (Prev) then
-- If E is not on the entity chain of the current scope,
-- it is an implicit declaration in the generic formal
-- part of a generic subprogram. When analyzing the body,
-- the generic formals are visible but not on the entity
-- chain of the subprogram. The new entity will become
-- the visible one in the body.
pragma Assert
(Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
null;
else
Set_Next_Entity (Prev, Next_Entity (E));
if No (Next_Entity (Prev)) then
Set_Last_Entity (Current_Scope, Prev);
end if;
if E = Current_Entity (E) then
Prev_Vis := Empty;
else
Prev_Vis := Current_Entity (E);
while Homonym (Prev_Vis) /= E loop
Prev_Vis := Homonym (Prev_Vis);
end loop;
end if;
if Present (Prev_Vis) then
-- Skip E in the visibility chain
Set_Homonym (Prev_Vis, Homonym (E));
else
Set_Name_Entity_Id (Chars (E), Homonym (E));
end if;
end if;
end;
-- This section of code could use a comment ???
elsif Present (Etype (E))
and then Is_Concurrent_Type (Etype (E))
and then E = Def_Id
then
return;
-- If the homograph is a protected component renaming, it should not
-- be hiding the current entity. Such renamings are treated as weak
-- declarations.
elsif Is_Prival (E) then
Set_Is_Immediately_Visible (E, False);
-- In this case the current entity is a protected component renaming.
-- Perform minimal decoration by setting the scope and return since
-- the prival should not be hiding other visible entities.
elsif Is_Prival (Def_Id) then
Set_Scope (Def_Id, Current_Scope);
return;
-- Analogous to privals, the discriminal generated for an entry index
-- parameter acts as a weak declaration. Perform minimal decoration
-- to avoid bogus errors.
elsif Is_Discriminal (Def_Id)
and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
then
Set_Scope (Def_Id, Current_Scope);
return;
-- In the body or private part of an instance, a type extension may
-- introduce a component with the same name as that of an actual. The
-- legality rule is not enforced, but the semantics of the full type
-- with two components of same name are not clear at this point???
elsif In_Instance_Not_Visible then
null;
-- When compiling a package body, some child units may have become
-- visible. They cannot conflict with local entities that hide them.
elsif Is_Child_Unit (E)
and then In_Open_Scopes (Scope (E))
and then not Is_Immediately_Visible (E)
then
null;
-- Conversely, with front-end inlining we may compile the parent body
-- first, and a child unit subsequently. The context is now the
-- parent spec, and body entities are not visible.
elsif Is_Child_Unit (Def_Id)
and then Is_Package_Body_Entity (E)
and then not In_Package_Body (Current_Scope)
then
null;
-- Case of genuine duplicate declaration
else
Error_Msg_Sloc := Sloc (E);
-- If the previous declaration is an incomplete type declaration
-- this may be an attempt to complete it with a private type. The
-- following avoids confusing cascaded errors.
if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
then
Error_Msg_N
("incomplete type cannot be completed with a private " &
"declaration", Parent (Def_Id));
Set_Is_Immediately_Visible (E, False);
Set_Full_View (E, Def_Id);
-- An inherited component of a record conflicts with a new
-- discriminant. The discriminant is inserted first in the scope,
-- but the error should be posted on it, not on the component.
elsif Ekind (E) = E_Discriminant
and then Present (Scope (Def_Id))
and then Scope (Def_Id) /= Current_Scope
then
Error_Msg_Sloc := Sloc (Def_Id);
Error_Msg_N ("& conflicts with declaration#", E);
return;
-- If the name of the unit appears in its own context clause, a
-- dummy package with the name has already been created, and the
-- error emitted. Try to continue quietly.
elsif Error_Posted (E)
and then Sloc (E) = No_Location
and then Nkind (Parent (E)) = N_Package_Specification
and then Current_Scope = Standard_Standard
then
Set_Scope (Def_Id, Current_Scope);
return;
else
Error_Msg_N ("& conflicts with declaration#", Def_Id);
-- Avoid cascaded messages with duplicate components in
-- derived types.
if Ekind_In (E, E_Component, E_Discriminant) then
return;
end if;
end if;
if Nkind (Parent (Parent (Def_Id))) =
N_Generic_Subprogram_Declaration
and then Def_Id =
Defining_Entity (Specification (Parent (Parent (Def_Id))))
then
Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
end if;
-- If entity is in standard, then we are in trouble, because it
-- means that we have a library package with a duplicated name.
-- That's hard to recover from, so abort.
if S = Standard_Standard then
raise Unrecoverable_Error;
-- Otherwise we continue with the declaration. Having two
-- identical declarations should not cause us too much trouble.
else
null;
end if;
end if;
end if;
-- If we fall through, declaration is OK, at least OK enough to continue
-- If Def_Id is a discriminant or a record component we are in the midst
-- of inheriting components in a derived record definition. Preserve
-- their Ekind and Etype.
if Ekind_In (Def_Id, E_Discriminant, E_Component) then
null;
-- If a type is already set, leave it alone (happens when a type
-- declaration is reanalyzed following a call to the optimizer).
elsif Present (Etype (Def_Id)) then
null;
-- Otherwise, the kind E_Void insures that premature uses of the entity
-- will be detected. Any_Type insures that no cascaded errors will occur
else
Set_Ekind (Def_Id, E_Void);
Set_Etype (Def_Id, Any_Type);
end if;
-- Inherited discriminants and components in derived record types are
-- immediately visible. Itypes are not.
-- Unless the Itype is for a record type with a corresponding remote
-- type (what is that about, it was not commented ???)
if Ekind_In (Def_Id, E_Discriminant, E_Component)
or else
((not Is_Record_Type (Def_Id)
or else No (Corresponding_Remote_Type (Def_Id)))
and then not Is_Itype (Def_Id))
then
Set_Is_Immediately_Visible (Def_Id);
Set_Current_Entity (Def_Id);
end if;
Set_Homonym (Def_Id, C);
Append_Entity (Def_Id, S);
Set_Public_Status (Def_Id);
-- Declaring a homonym is not allowed in SPARK ...
if Present (C) and then Restriction_Check_Required (SPARK_05) then
declare
Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
begin
-- ... unless the new declaration is in a subprogram, and the
-- visible declaration is a variable declaration or a parameter
-- specification outside that subprogram.
if Present (Enclosing_Subp)
and then Nkind_In (Parent (C), N_Object_Declaration,
N_Parameter_Specification)
and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
then
null;
-- ... or the new declaration is in a package, and the visible
-- declaration occurs outside that package.
elsif Present (Enclosing_Pack)
and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
then
null;
-- ... or the new declaration is a component declaration in a
-- record type definition.
elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
null;
-- Don't issue error for non-source entities
elsif Comes_From_Source (Def_Id)
and then Comes_From_Source (C)
then
Error_Msg_Sloc := Sloc (C);
Check_SPARK_05_Restriction
("redeclaration of identifier &#", Def_Id);
end if;
end;
end if;
-- Warn if new entity hides an old one
if Warn_On_Hiding and then Present (C)
-- Don't warn for record components since they always have a well
-- defined scope which does not confuse other uses. Note that in
-- some cases, Ekind has not been set yet.
and then Ekind (C) /= E_Component
and then Ekind (C) /= E_Discriminant
and then Nkind (Parent (C)) /= N_Component_Declaration
and then Ekind (Def_Id) /= E_Component
and then Ekind (Def_Id) /= E_Discriminant
and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
-- Don't warn for one character variables. It is too common to use
-- such variables as locals and will just cause too many false hits.
and then Length_Of_Name (Chars (C)) /= 1
-- Don't warn for non-source entities
and then Comes_From_Source (C)
and then Comes_From_Source (Def_Id)
-- Don't warn unless entity in question is in extended main source
and then In_Extended_Main_Source_Unit (Def_Id)
-- Finally, the hidden entity must be either immediately visible or
-- use visible (i.e. from a used package).
and then
(Is_Immediately_Visible (C)
or else
Is_Potentially_Use_Visible (C))
then
Error_Msg_Sloc := Sloc (C);
Error_Msg_N ("declaration hides &#?h?", Def_Id);
end if;
end Enter_Name;
---------------
-- Entity_Of --
---------------
function Entity_Of (N : Node_Id) return Entity_Id is
Id : Entity_Id;
begin
Id := Empty;
if Is_Entity_Name (N) then
Id := Entity (N);
-- Follow a possible chain of renamings to reach the root renamed
-- object.
while Present (Id)
and then Is_Object (Id)
and then Present (Renamed_Object (Id))
loop
if Is_Entity_Name (Renamed_Object (Id)) then
Id := Entity (Renamed_Object (Id));
else
Id := Empty;
exit;
end if;
end loop;
end if;
return Id;
end Entity_Of;
--------------------------
-- Explain_Limited_Type --
--------------------------
procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
C : Entity_Id;
begin
-- For array, component type must be limited
if Is_Array_Type (T) then
Error_Msg_Node_2 := T;
Error_Msg_NE
("\component type& of type& is limited", N, Component_Type (T));
Explain_Limited_Type (Component_Type (T), N);
elsif Is_Record_Type (T) then
-- No need for extra messages if explicit limited record
if Is_Limited_Record (Base_Type (T)) then
return;
end if;
-- Otherwise find a limited component. Check only components that
-- come from source, or inherited components that appear in the
-- source of the ancestor.
C := First_Component (T);
while Present (C) loop
if Is_Limited_Type (Etype (C))
and then
(Comes_From_Source (C)
or else
(Present (Original_Record_Component (C))
and then
Comes_From_Source (Original_Record_Component (C))))
then
Error_Msg_Node_2 := T;
Error_Msg_NE ("\component& of type& has limited type", N, C);
Explain_Limited_Type (Etype (C), N);
return;
end if;
Next_Component (C);
end loop;
-- The type may be declared explicitly limited, even if no component
-- of it is limited, in which case we fall out of the loop.
return;
end if;
end Explain_Limited_Type;
---------------------------------------
-- Expression_Of_Expression_Function --
---------------------------------------
function Expression_Of_Expression_Function
(Subp : Entity_Id) return Node_Id
is
Expr_Func : Node_Id;
begin
pragma Assert (Is_Expression_Function_Or_Completion (Subp));
if Nkind (Original_Node (Subprogram_Spec (Subp))) =
N_Expression_Function
then
Expr_Func := Original_Node (Subprogram_Spec (Subp));
elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
N_Expression_Function
then
Expr_Func := Original_Node (Subprogram_Body (Subp));
else
pragma Assert (False);
null;
end if;
return Original_Node (Expression (Expr_Func));
end Expression_Of_Expression_Function;
-------------------------------
-- Extensions_Visible_Status --
-------------------------------
function Extensions_Visible_Status
(Id : Entity_Id) return Extensions_Visible_Mode
is
Arg : Node_Id;
Decl : Node_Id;
Expr : Node_Id;
Prag : Node_Id;
Subp : Entity_Id;
begin
-- When a formal parameter is subject to Extensions_Visible, the pragma
-- is stored in the contract of related subprogram.
if Is_Formal (Id) then
Subp := Scope (Id);
elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
Subp := Id;
-- No other construct carries this pragma
else
return Extensions_Visible_None;
end if;
Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
-- In certain cases analysis may request the Extensions_Visible status
-- of an expression function before the pragma has been analyzed yet.
-- Inspect the declarative items after the expression function looking
-- for the pragma (if any).
if No (Prag) and then Is_Expression_Function (Subp) then
Decl := Next (Unit_Declaration_Node (Subp));
while Present (Decl) loop
if Nkind (Decl) = N_Pragma
and then Pragma_Name (Decl) = Name_Extensions_Visible
then
Prag := Decl;
exit;
-- A source construct ends the region where Extensions_Visible may
-- appear, stop the traversal. An expanded expression function is
-- no longer a source construct, but it must still be recognized.
elsif Comes_From_Source (Decl)
or else
(Nkind_In (Decl, N_Subprogram_Body,
N_Subprogram_Declaration)
and then Is_Expression_Function (Defining_Entity (Decl)))
then
exit;
end if;
Next (Decl);
end loop;
end if;
-- Extract the value from the Boolean expression (if any)
if Present (Prag) then
Arg := First (Pragma_Argument_Associations (Prag));
if Present (Arg) then
Expr := Get_Pragma_Arg (Arg);
-- When the associated subprogram is an expression function, the
-- argument of the pragma may not have been analyzed.
if not Analyzed (Expr) then
Preanalyze_And_Resolve (Expr, Standard_Boolean);
end if;
-- Guard against cascading errors when the argument of pragma
-- Extensions_Visible is not a valid static Boolean expression.
if Error_Posted (Expr) then
return Extensions_Visible_None;
elsif Is_True (Expr_Value (Expr)) then
return Extensions_Visible_True;
else
return Extensions_Visible_False;
end if;
-- Otherwise the aspect or pragma defaults to True
else
return Extensions_Visible_True;
end if;
-- Otherwise aspect or pragma Extensions_Visible is not inherited or
-- directly specified. In SPARK code, its value defaults to "False".
elsif SPARK_Mode = On then
return Extensions_Visible_False;
-- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
-- "True".
else
return Extensions_Visible_True;
end if;
end Extensions_Visible_Status;
-----------------
-- Find_Actual --
-----------------
procedure Find_Actual
(N : Node_Id;
Formal : out Entity_Id;
Call : out Node_Id)
is
Context : constant Node_Id := Parent (N);
Actual : Node_Id;
Call_Nam : Node_Id;
begin
if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
and then N = Prefix (Context)
then
Find_Actual (Context, Formal, Call);
return;
elsif Nkind (Context) = N_Parameter_Association
and then N = Explicit_Actual_Parameter (Context)
then
Call := Parent (Context);
elsif Nkind_In (Context, N_Entry_Call_Statement,
N_Function_Call,
N_Procedure_Call_Statement)
then
Call := Context;
else
Formal := Empty;
Call := Empty;
return;
end if;
-- If we have a call to a subprogram look for the parameter. Note that
-- we exclude overloaded calls, since we don't know enough to be sure
-- of giving the right answer in this case.
if Nkind_In (Call, N_Entry_Call_Statement,
N_Function_Call,
N_Procedure_Call_Statement)
then
Call_Nam := Name (Call);
-- A call to a protected or task entry appears as a selected
-- component rather than an expanded name.
if Nkind (Call_Nam) = N_Selected_Component then
Call_Nam := Selector_Name (Call_Nam);
end if;
if Is_Entity_Name (Call_Nam)
and then Present (Entity (Call_Nam))
and then Is_Overloadable (Entity (Call_Nam))
and then not Is_Overloaded (Call_Nam)
then
-- If node is name in call it is not an actual
if N = Call_Nam then
Formal := Empty;
Call := Empty;
return;
end if;
-- Fall here if we are definitely a parameter
Actual := First_Actual (Call);
Formal := First_Formal (Entity (Call_Nam));
while Present (Formal) and then Present (Actual) loop
if Actual = N then
return;
-- An actual that is the prefix in a prefixed call may have
-- been rewritten in the call, after the deferred reference
-- was collected. Check if sloc and kinds and names match.
elsif Sloc (Actual) = Sloc (N)
and then Nkind (Actual) = N_Identifier
and then Nkind (Actual) = Nkind (N)
and then Chars (Actual) = Chars (N)
then
return;
else
Actual := Next_Actual (Actual);
Formal := Next_Formal (Formal);
end if;
end loop;
end if;
end if;
-- Fall through here if we did not find matching actual
Formal := Empty;
Call := Empty;
end Find_Actual;
---------------------------
-- Find_Body_Discriminal --
---------------------------
function Find_Body_Discriminal
(Spec_Discriminant : Entity_Id) return Entity_Id
is
Tsk : Entity_Id;
Disc : Entity_Id;
begin
-- If expansion is suppressed, then the scope can be the concurrent type
-- itself rather than a corresponding concurrent record type.
if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
Tsk := Scope (Spec_Discriminant);
else
pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
end if;
-- Find discriminant of original concurrent type, and use its current
-- discriminal, which is the renaming within the task/protected body.
Disc := First_Discriminant (Tsk);
while Present (Disc) loop
if Chars (Disc) = Chars (Spec_Discriminant) then
return Discriminal (Disc);
end if;
Next_Discriminant (Disc);
end loop;
-- That loop should always succeed in finding a matching entry and
-- returning. Fatal error if not.
raise Program_Error;
end Find_Body_Discriminal;
-------------------------------------
-- Find_Corresponding_Discriminant --
-------------------------------------
function Find_Corresponding_Discriminant
(Id : Node_Id;
Typ : Entity_Id) return Entity_Id
is
Par_Disc : Entity_Id;
Old_Disc : Entity_Id;
New_Disc : Entity_Id;
begin
Par_Disc := Original_Record_Component (Original_Discriminant (Id));
-- The original type may currently be private, and the discriminant
-- only appear on its full view.
if Is_Private_Type (Scope (Par_Disc))
and then not Has_Discriminants (Scope (Par_Disc))
and then Present (Full_View (Scope (Par_Disc)))
then
Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
else
Old_Disc := First_Discriminant (Scope (Par_Disc));
end if;
if Is_Class_Wide_Type (Typ) then
New_Disc := First_Discriminant (Root_Type (Typ));
else
New_Disc := First_Discriminant (Typ);
end if;
while Present (Old_Disc) and then Present (New_Disc) loop
if Old_Disc = Par_Disc then
return New_Disc;
end if;
Next_Discriminant (Old_Disc);
Next_Discriminant (New_Disc);
end loop;
-- Should always find it
raise Program_Error;
end Find_Corresponding_Discriminant;
----------------------------------
-- Find_Enclosing_Iterator_Loop --
----------------------------------
function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
Constr : Node_Id;
S : Entity_Id;
begin
-- Traverse the scope chain looking for an iterator loop. Such loops are
-- usually transformed into blocks, hence the use of Original_Node.
S := Id;
while Present (S) and then S /= Standard_Standard loop
if Ekind (S) = E_Loop
and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
then
Constr := Original_Node (Label_Construct (Parent (S)));
if Nkind (Constr) = N_Loop_Statement
and then Present (Iteration_Scheme (Constr))
and then Nkind (Iterator_Specification
(Iteration_Scheme (Constr))) =
N_Iterator_Specification
then
return S;
end if;
end if;
S := Scope (S);
end loop;
return Empty;
end Find_Enclosing_Iterator_Loop;
------------------------------------
-- Find_Loop_In_Conditional_Block --
------------------------------------
function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
Stmt : Node_Id;
begin
Stmt := N;
if Nkind (Stmt) = N_If_Statement then
Stmt := First (Then_Statements (Stmt));
end if;
pragma Assert (Nkind (Stmt) = N_Block_Statement);
-- Inspect the statements of the conditional block. In general the loop
-- should be the first statement in the statement sequence of the block,
-- but the finalization machinery may have introduced extra object
-- declarations.
Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
while Present (Stmt) loop
if Nkind (Stmt) = N_Loop_Statement then
return Stmt;
end if;
Next (Stmt);
end loop;
-- The expansion of attribute 'Loop_Entry produced a malformed block
raise Program_Error;
end Find_Loop_In_Conditional_Block;
--------------------------
-- Find_Overlaid_Entity --
--------------------------
procedure Find_Overlaid_Entity
(N : Node_Id;
Ent : out Entity_Id;
Off : out Boolean)
is
Expr : Node_Id;
begin
-- We are looking for one of the two following forms:
-- for X'Address use Y'Address
-- or
-- Const : constant Address := expr;
-- ...
-- for X'Address use Const;
-- In the second case, the expr is either Y'Address, or recursively a
-- constant that eventually references Y'Address.
Ent := Empty;
Off := False;
if Nkind (N) = N_Attribute_Definition_Clause
and then Chars (N) = Name_Address
then
Expr := Expression (N);
-- This loop checks the form of the expression for Y'Address,
-- using recursion to deal with intermediate constants.
loop
-- Check for Y'Address
if Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Address
then
Expr := Prefix (Expr);
exit;
-- Check for Const where Const is a constant entity
elsif Is_Entity_Name (Expr)
and then Ekind (Entity (Expr)) = E_Constant
then
Expr := Constant_Value (Entity (Expr));
-- Anything else does not need checking
else
return;
end if;
end loop;
-- This loop checks the form of the prefix for an entity, using
-- recursion to deal with intermediate components.
loop
-- Check for Y where Y is an entity
if Is_Entity_Name (Expr) then
Ent := Entity (Expr);
return;
-- Check for components
elsif
Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
then
Expr := Prefix (Expr);
Off := True;
-- Anything else does not need checking
else
return;
end if;
end loop;
end if;
end Find_Overlaid_Entity;
-------------------------
-- Find_Parameter_Type --
-------------------------
function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
begin
if Nkind (Param) /= N_Parameter_Specification then
return Empty;
-- For an access parameter, obtain the type from the formal entity
-- itself, because access to subprogram nodes do not carry a type.
-- Shouldn't we always use the formal entity ???
elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
return Etype (Defining_Identifier (Param));
else
return Etype (Parameter_Type (Param));
end if;
end Find_Parameter_Type;
-----------------------------------
-- Find_Placement_In_State_Space --
-----------------------------------
procedure Find_Placement_In_State_Space
(Item_Id : Entity_Id;
Placement : out State_Space_Kind;
Pack_Id : out Entity_Id)
is
Context : Entity_Id;
begin
-- Assume that the item does not appear in the state space of a package
Placement := Not_In_Package;
Pack_Id := Empty;
-- Climb the scope stack and examine the enclosing context
Context := Scope (Item_Id);
while Present (Context) and then Context /= Standard_Standard loop
if Ekind (Context) = E_Package then
Pack_Id := Context;
-- A package body is a cut off point for the traversal as the item
-- cannot be visible to the outside from this point on. Note that
-- this test must be done first as a body is also classified as a
-- private part.
if In_Package_Body (Context) then
Placement := Body_State_Space;
return;
-- The private part of a package is a cut off point for the
-- traversal as the item cannot be visible to the outside from
-- this point on.
elsif In_Private_Part (Context) then
Placement := Private_State_Space;
return;
-- When the item appears in the visible state space of a package,
-- continue to climb the scope stack as this may not be the final
-- state space.
else
Placement := Visible_State_Space;
-- The visible state space of a child unit acts as the proper
-- placement of an item.
if Is_Child_Unit (Context) then
return;
end if;
end if;
-- The item or its enclosing package appear in a construct that has
-- no state space.
else
Placement := Not_In_Package;
return;
end if;
Context := Scope (Context);
end loop;
end Find_Placement_In_State_Space;
------------------------
-- Find_Specific_Type --
------------------------
function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
Typ : Entity_Id := Root_Type (CW);
begin
if Ekind (Typ) = E_Incomplete_Type then
if From_Limited_With (Typ) then
Typ := Non_Limited_View (Typ);
else
Typ := Full_View (Typ);
end if;
end if;
if Is_Private_Type (Typ)
and then not Is_Tagged_Type (Typ)
and then Present (Full_View (Typ))
then
return Full_View (Typ);
else
return Typ;
end if;
end Find_Specific_Type;
-----------------------------
-- Find_Static_Alternative --
-----------------------------
function Find_Static_Alternative (N : Node_Id) return Node_Id is
Expr : constant Node_Id := Expression (N);
Val : constant Uint := Expr_Value (Expr);
Alt : Node_Id;
Choice : Node_Id;
begin
Alt := First (Alternatives (N));
Search : loop
if Nkind (Alt) /= N_Pragma then
Choice := First (Discrete_Choices (Alt));
while Present (Choice) loop
-- Others choice, always matches
if Nkind (Choice) = N_Others_Choice then
exit Search;
-- Range, check if value is in the range
elsif Nkind (Choice) = N_Range then
exit Search when
Val >= Expr_Value (Low_Bound (Choice))
and then
Val <= Expr_Value (High_Bound (Choice));
-- Choice is a subtype name. Note that we know it must
-- be a static subtype, since otherwise it would have
-- been diagnosed as illegal.
elsif Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice))
then
exit Search when Is_In_Range (Expr, Etype (Choice),
Assume_Valid => False);
-- Choice is a subtype indication
elsif Nkind (Choice) = N_Subtype_Indication then
declare
C : constant Node_Id := Constraint (Choice);
R : constant Node_Id := Range_Expression (C);
begin
exit Search when
Val >= Expr_Value (Low_Bound (R))
and then
Val <= Expr_Value (High_Bound (R));
end;
-- Choice is a simple expression
else
exit Search when Val = Expr_Value (Choice);
end if;
Next (Choice);
end loop;
end if;
Next (Alt);
pragma Assert (Present (Alt));
end loop Search;
-- The above loop *must* terminate by finding a match, since we know the
-- case statement is valid, and the value of the expression is known at
-- compile time. When we fall out of the loop, Alt points to the
-- alternative that we know will be selected at run time.
return Alt;
end Find_Static_Alternative;
------------------
-- First_Actual --
------------------
function First_Actual (Node : Node_Id) return Node_Id is
N : Node_Id;
begin
if No (Parameter_Associations (Node)) then
return Empty;
end if;
N := First (Parameter_Associations (Node));
if Nkind (N) = N_Parameter_Association then
return First_Named_Actual (Node);
else
return N;
end if;
end First_Actual;
-------------
-- Fix_Msg --
-------------
function Fix_Msg (Id : Entity_Id; Msg : String) return String is
Is_Task : constant Boolean :=
Ekind_In (Id, E_Task_Body, E_Task_Type)
or else Is_Single_Task_Object (Id);
Msg_Last : constant Natural := Msg'Last;
Msg_Index : Natural;
Res : String (Msg'Range) := (others => ' ');
Res_Index : Natural;
begin
-- Copy all characters from the input message Msg to result Res with
-- suitable replacements.
Msg_Index := Msg'First;
Res_Index := Res'First;
while Msg_Index <= Msg_Last loop
-- Replace "subprogram" with a different word
if Msg_Index <= Msg_Last - 10
and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
then
if Ekind_In (Id, E_Entry, E_Entry_Family) then
Res (Res_Index .. Res_Index + 4) := "entry";
Res_Index := Res_Index + 5;
elsif Is_Task then
Res (Res_Index .. Res_Index + 8) := "task type";
Res_Index := Res_Index + 9;
else
Res (Res_Index .. Res_Index + 9) := "subprogram";
Res_Index := Res_Index + 10;
end if;
Msg_Index := Msg_Index + 10;
-- Replace "protected" with a different word
elsif Msg_Index <= Msg_Last - 9
and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
and then Is_Task
then
Res (Res_Index .. Res_Index + 3) := "task";
Res_Index := Res_Index + 4;
Msg_Index := Msg_Index + 9;
-- Otherwise copy the character
else
Res (Res_Index) := Msg (Msg_Index);
Msg_Index := Msg_Index + 1;
Res_Index := Res_Index + 1;
end if;
end loop;
return Res (Res'First .. Res_Index - 1);
end Fix_Msg;
-----------------------
-- Gather_Components --
-----------------------
procedure Gather_Components
(Typ : Entity_Id;
Comp_List : Node_Id;
Governed_By : List_Id;
Into : Elist_Id;
Report_Errors : out Boolean)
is
Assoc : Node_Id;
Variant : Node_Id;
Discrete_Choice : Node_Id;
Comp_Item : Node_Id;
Discrim : Entity_Id;
Discrim_Name : Node_Id;
Discrim_Value : Node_Id;
begin
Report_Errors := False;
if No (Comp_List) or else Null_Present (Comp_List) then
return;
elsif Present (Component_Items (Comp_List)) then
Comp_Item := First (Component_Items (Comp_List));
else
Comp_Item := Empty;
end if;
while Present (Comp_Item) loop
-- Skip the tag of a tagged record, the interface tags, as well
-- as all items that are not user components (anonymous types,
-- rep clauses, Parent field, controller field).
if Nkind (Comp_Item) = N_Component_Declaration then
declare
Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
begin
if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
Append_Elmt (Comp, Into);
end if;
end;
end if;
Next (Comp_Item);
end loop;
if No (Variant_Part (Comp_List)) then
return;
else
Discrim_Name := Name (Variant_Part (Comp_List));
Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
end if;
-- Look for the discriminant that governs this variant part.
-- The discriminant *must* be in the Governed_By List
Assoc := First (Governed_By);
Find_Constraint : loop
Discrim := First (Choices (Assoc));
exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
or else (Present (Corresponding_Discriminant (Entity (Discrim)))
and then
Chars (Corresponding_Discriminant (Entity (Discrim))) =
Chars (Discrim_Name))
or else Chars (Original_Record_Component (Entity (Discrim)))
= Chars (Discrim_Name);
if No (Next (Assoc)) then
if not Is_Constrained (Typ)
and then Is_Derived_Type (Typ)
and then Present (Stored_Constraint (Typ))
then
-- If the type is a tagged type with inherited discriminants,
-- use the stored constraint on the parent in order to find
-- the values of discriminants that are otherwise hidden by an
-- explicit constraint. Renamed discriminants are handled in
-- the code above.
-- If several parent discriminants are renamed by a single
-- discriminant of the derived type, the call to obtain the
-- Corresponding_Discriminant field only retrieves the last
-- of them. We recover the constraint on the others from the
-- Stored_Constraint as well.
declare
D : Entity_Id;
C : Elmt_Id;
begin
D := First_Discriminant (Etype (Typ));
C := First_Elmt (Stored_Constraint (Typ));
while Present (D) and then Present (C) loop
if Chars (Discrim_Name) = Chars (D) then
if Is_Entity_Name (Node (C))
and then Entity (Node (C)) = Entity (Discrim)
then
-- D is renamed by Discrim, whose value is given in
-- Assoc.
null;
else
Assoc :=
Make_Component_Association (Sloc (Typ),
New_List
(New_Occurrence_Of (D, Sloc (Typ))),
Duplicate_Subexpr_No_Checks (Node (C)));
end if;
exit Find_Constraint;
end if;
Next_Discriminant (D);
Next_Elmt (C);
end loop;
end;
end if;
end if;
if No (Next (Assoc)) then
Error_Msg_NE (" missing value for discriminant&",
First (Governed_By), Discrim_Name);
Report_Errors := True;
return;
end if;
Next (Assoc);
end loop Find_Constraint;
Discrim_Value := Expression (Assoc);
if not Is_OK_Static_Expression (Discrim_Value) then
-- If the variant part is governed by a discriminant of the type
-- this is an error. If the variant part and the discriminant are
-- inherited from an ancestor this is legal (AI05-120) unless the
-- components are being gathered for an aggregate, in which case
-- the caller must check Report_Errors.
if Scope (Original_Record_Component
((Entity (First (Choices (Assoc)))))) = Typ
then
Error_Msg_FE
("value for discriminant & must be static!",
Discrim_Value, Discrim);
Why_Not_Static (Discrim_Value);
end if;
Report_Errors := True;
return;
end if;
Search_For_Discriminant_Value : declare
Low : Node_Id;
High : Node_Id;
UI_High : Uint;
UI_Low : Uint;
UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
begin
Find_Discrete_Value : while Present (Variant) loop
Discrete_Choice := First (Discrete_Choices (Variant));
while Present (Discrete_Choice) loop
exit Find_Discrete_Value when
Nkind (Discrete_Choice) = N_Others_Choice;
Get_Index_Bounds (Discrete_Choice, Low, High);
UI_Low := Expr_Value (Low);
UI_High := Expr_Value (High);
exit Find_Discrete_Value when
UI_Low <= UI_Discrim_Value
and then
UI_High >= UI_Discrim_Value;
Next (Discrete_Choice);
end loop;
Next_Non_Pragma (Variant);
end loop Find_Discrete_Value;
end Search_For_Discriminant_Value;
-- The case statement must include a variant that corresponds to the
-- value of the discriminant, unless the discriminant type has a
-- static predicate. In that case the absence of an others_choice that
-- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
if No (Variant)
and then not Has_Static_Predicate (Etype (Discrim_Name))
then
Error_Msg_NE
("value of discriminant & is out of range", Discrim_Value, Discrim);
Report_Errors := True;
return;
end if;
-- If we have found the corresponding choice, recursively add its
-- components to the Into list. The nested components are part of
-- the same record type.
if Present (Variant) then
Gather_Components
(Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
end if;
end Gather_Components;
------------------------
-- Get_Actual_Subtype --
------------------------
function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
Typ : constant Entity_Id := Etype (N);
Utyp : Entity_Id := Underlying_Type (Typ);
Decl : Node_Id;
Atyp : Entity_Id;
begin
if No (Utyp) then
Utyp := Typ;
end if;
-- If what we have is an identifier that references a subprogram
-- formal, or a variable or constant object, then we get the actual
-- subtype from the referenced entity if one has been built.
if Nkind (N) = N_Identifier
and then
(Is_Formal (Entity (N))
or else Ekind (Entity (N)) = E_Constant
or else Ekind (Entity (N)) = E_Variable)
and then Present (Actual_Subtype (Entity (N)))
then
return Actual_Subtype (Entity (N));
-- Actual subtype of unchecked union is always itself. We never need
-- the "real" actual subtype. If we did, we couldn't get it anyway
-- because the discriminant is not available. The restrictions on
-- Unchecked_Union are designed to make sure that this is OK.
elsif Is_Unchecked_Union (Base_Type (Utyp)) then
return Typ;
-- Here for the unconstrained case, we must find actual subtype
-- No actual subtype is available, so we must build it on the fly.
-- Checking the type, not the underlying type, for constrainedness
-- seems to be necessary. Maybe all the tests should be on the type???
elsif (not Is_Constrained (Typ))
and then (Is_Array_Type (Utyp)
or else (Is_Record_Type (Utyp)
and then Has_Discriminants (Utyp)))
and then not Has_Unknown_Discriminants (Utyp)
and then not (Ekind (Utyp) = E_String_Literal_Subtype)
then
-- Nothing to do if in spec expression (why not???)
if In_Spec_Expression then
return Typ;
elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
-- If the type has no discriminants, there is no subtype to
-- build, even if the underlying type is discriminated.
return Typ;
-- Else build the actual subtype
else
Decl := Build_Actual_Subtype (Typ, N);
Atyp := Defining_Identifier (Decl);
-- If Build_Actual_Subtype generated a new declaration then use it
if Atyp /= Typ then
-- The actual subtype is an Itype, so analyze the declaration,
-- but do not attach it to the tree, to get the type defined.
Set_Parent (Decl, N);
Set_Is_Itype (Atyp);
Analyze (Decl, Suppress => All_Checks);
Set_Associated_Node_For_Itype (Atyp, N);
Set_Has_Delayed_Freeze (Atyp, False);
-- We need to freeze the actual subtype immediately. This is
-- needed, because otherwise this Itype will not get frozen
-- at all, and it is always safe to freeze on creation because
-- any associated types must be frozen at this point.
Freeze_Itype (Atyp, N);
return Atyp;
-- Otherwise we did not build a declaration, so return original
else
return Typ;
end if;
end if;
-- For all remaining cases, the actual subtype is the same as
-- the nominal type.
else
return Typ;
end if;
end Get_Actual_Subtype;
-------------------------------------
-- Get_Actual_Subtype_If_Available --
-------------------------------------
function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
Typ : constant Entity_Id := Etype (N);
begin
-- If what we have is an identifier that references a subprogram
-- formal, or a variable or constant object, then we get the actual
-- subtype from the referenced entity if one has been built.
if Nkind (N) = N_Identifier
and then
(Is_Formal (Entity (N))
or else Ekind (Entity (N)) = E_Constant
or else Ekind (Entity (N)) = E_Variable)
and then Present (Actual_Subtype (Entity (N)))
then
return Actual_Subtype (Entity (N));
-- Otherwise the Etype of N is returned unchanged
else
return Typ;
end if;
end Get_Actual_Subtype_If_Available;
------------------------
-- Get_Body_From_Stub --
------------------------
function Get_Body_From_Stub (N : Node_Id) return Node_Id is
begin
return Proper_Body (Unit (Library_Unit (N)));
end Get_Body_From_Stub;
---------------------
-- Get_Cursor_Type --
---------------------
function Get_Cursor_Type
(Aspect : Node_Id;
Typ : Entity_Id) return Entity_Id
is
Assoc : Node_Id;
Func : Entity_Id;
First_Op : Entity_Id;
Cursor : Entity_Id;
begin
-- If error already detected, return
if Error_Posted (Aspect) then
return Any_Type;
end if;
-- The cursor type for an Iterable aspect is the return type of a
-- non-overloaded First primitive operation. Locate association for
-- First.
Assoc := First (Component_Associations (Expression (Aspect)));
First_Op := Any_Id;
while Present (Assoc) loop
if Chars (First (Choices (Assoc))) = Name_First then
First_Op := Expression (Assoc);
exit;
end if;
Next (Assoc);
end loop;
if First_Op = Any_Id then
Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
return Any_Type;
end if;
Cursor := Any_Type;
-- Locate function with desired name and profile in scope of type
-- In the rare case where the type is an integer type, a base type
-- is created for it, check that the base type of the first formal
-- of First matches the base type of the domain.
Func := First_Entity (Scope (Typ));
while Present (Func) loop
if Chars (Func) = Chars (First_Op)
and then Ekind (Func) = E_Function
and then Present (First_Formal (Func))
and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
and then No (Next_Formal (First_Formal (Func)))
then
if Cursor /= Any_Type then
Error_Msg_N
("Operation First for iterable type must be unique", Aspect);
return Any_Type;
else
Cursor := Etype (Func);
end if;
end if;
Next_Entity (Func);
end loop;
-- If not found, no way to resolve remaining primitives.
if Cursor = Any_Type then
Error_Msg_N
("No legal primitive operation First for Iterable type", Aspect);
end if;
return Cursor;
end Get_Cursor_Type;
function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
begin
return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
end Get_Cursor_Type;
-------------------------------
-- Get_Default_External_Name --
-------------------------------
function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
begin
Get_Decoded_Name_String (Chars (E));
if Opt.External_Name_Imp_Casing = Uppercase then
Set_Casing (All_Upper_Case);
else
Set_Casing (All_Lower_Case);
end if;
return
Make_String_Literal (Sloc (E),
Strval => String_From_Name_Buffer);
end Get_Default_External_Name;
--------------------------
-- Get_Enclosing_Object --
--------------------------
function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
begin
if Is_Entity_Name (N) then
return Entity (N);
else
case Nkind (N) is
when N_Indexed_Component
| N_Selected_Component
| N_Slice
=>
-- If not generating code, a dereference may be left implicit.
-- In thoses cases, return Empty.
if Is_Access_Type (Etype (Prefix (N))) then
return Empty;
else
return Get_Enclosing_Object (Prefix (N));
end if;
when N_Type_Conversion =>
return Get_Enclosing_Object (Expression (N));
when others =>
return Empty;
end case;
end if;
end Get_Enclosing_Object;
---------------------------
-- Get_Enum_Lit_From_Pos --
---------------------------
function Get_Enum_Lit_From_Pos
(T : Entity_Id;
Pos : Uint;
Loc : Source_Ptr) return Node_Id
is
Btyp : Entity_Id := Base_Type (T);
Lit : Node_Id;
LLoc : Source_Ptr;
begin
-- In the case where the literal is of type Character, Wide_Character
-- or Wide_Wide_Character or of a type derived from them, there needs
-- to be some special handling since there is no explicit chain of
-- literals to search. Instead, an N_Character_Literal node is created
-- with the appropriate Char_Code and Chars fields.
if Is_Standard_Character_Type (T) then
Set_Character_Literal_Name (UI_To_CC (Pos));
return
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value => Pos);
-- For all other cases, we have a complete table of literals, and
-- we simply iterate through the chain of literal until the one
-- with the desired position value is found.
else
if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
Btyp := Full_View (Btyp);
end if;
Lit := First_Literal (Btyp);
for J in 1 .. UI_To_Int (Pos) loop
Next_Literal (Lit);
-- If Lit is Empty, Pos is not in range, so raise Constraint_Error
-- inside the loop to avoid calling Next_Literal on Empty.
if No (Lit) then
raise Constraint_Error;
end if;
end loop;
-- Create a new node from Lit, with source location provided by Loc
-- if not equal to No_Location, or by copying the source location of
-- Lit otherwise.
LLoc := Loc;
if LLoc = No_Location then
LLoc := Sloc (Lit);
end if;
return New_Occurrence_Of (Lit, LLoc);
end if;
end Get_Enum_Lit_From_Pos;
------------------------
-- Get_Generic_Entity --
------------------------
function Get_Generic_Entity (N : Node_Id) return Entity_Id is
Ent : constant Entity_Id := Entity (Name (N));
begin
if Present (Renamed_Object (Ent)) then
return Renamed_Object (Ent);
else
return Ent;
end if;
end Get_Generic_Entity;
-------------------------------------
-- Get_Incomplete_View_Of_Ancestor --
-------------------------------------
function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
Par_Scope : Entity_Id;
Par_Type : Entity_Id;
begin
-- The incomplete view of an ancestor is only relevant for private
-- derived types in child units.
if not Is_Derived_Type (E)
or else not Is_Child_Unit (Cur_Unit)
then
return Empty;
else
Par_Scope := Scope (Cur_Unit);
if No (Par_Scope) then
return Empty;
end if;
Par_Type := Etype (Base_Type (E));
-- Traverse list of ancestor types until we find one declared in
-- a parent or grandparent unit (two levels seem sufficient).
while Present (Par_Type) loop
if Scope (Par_Type) = Par_Scope
or else Scope (Par_Type) = Scope (Par_Scope)
then
return Par_Type;
elsif not Is_Derived_Type (Par_Type) then
return Empty;
else
Par_Type := Etype (Base_Type (Par_Type));
end if;
end loop;
-- If none found, there is no relevant ancestor type.
return Empty;
end if;
end Get_Incomplete_View_Of_Ancestor;
----------------------
-- Get_Index_Bounds --
----------------------
procedure Get_Index_Bounds
(N : Node_Id;
L : out Node_Id;
H : out Node_Id;
Use_Full_View : Boolean := False)
is
function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
-- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
-- Typ qualifies, the scalar range is obtained from the full view of the
-- type.
--------------------------
-- Scalar_Range_Of_Type --
--------------------------
function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
T : Entity_Id := Typ;
begin
if Use_Full_View and then Present (Full_View (T)) then
T := Full_View (T);
end if;
return Scalar_Range (T);
end Scalar_Range_Of_Type;
-- Local variables
Kind : constant Node_Kind := Nkind (N);
Rng : Node_Id;
-- Start of processing for Get_Index_Bounds
begin
if Kind = N_Range then
L := Low_Bound (N);
H := High_Bound (N);
elsif Kind = N_Subtype_Indication then
Rng := Range_Expression (Constraint (N));
if Rng = Error then
L := Error;
H := Error;
return;
else
L := Low_Bound (Range_Expression (Constraint (N)));
H := High_Bound (Range_Expression (Constraint (N)));
end if;
elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
Rng := Scalar_Range_Of_Type (Entity (N));
if Error_Posted (Rng) then
L := Error;
H := Error;
elsif Nkind (Rng) = N_Subtype_Indication then
Get_Index_Bounds (Rng, L, H);
else
L := Low_Bound (Rng);
H := High_Bound (Rng);
end if;
else
-- N is an expression, indicating a range with one value
L := N;
H := N;
end if;
end Get_Index_Bounds;
---------------------------------
-- Get_Iterable_Type_Primitive --
---------------------------------
function Get_Iterable_Type_Primitive
(Typ : Entity_Id;
Nam : Name_Id) return Entity_Id
is
Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
Assoc : Node_Id;
begin
if No (Funcs) then
return Empty;
else
Assoc := First (Component_Associations (Funcs));
while Present (Assoc) loop
if Chars (First (Choices (Assoc))) = Nam then
return Entity (Expression (Assoc));
end if;
Assoc := Next (Assoc);
end loop;
return Empty;
end if;
end Get_Iterable_Type_Primitive;
----------------------------------
-- Get_Library_Unit_Name_string --
----------------------------------
procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
begin
Get_Unit_Name_String (Unit_Name_Id);
-- Remove seven last character (" (spec)" or " (body)")
Name_Len := Name_Len - 7;
pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
end Get_Library_Unit_Name_String;
--------------------------
-- Get_Max_Queue_Length --
--------------------------
function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
pragma Assert (Is_Entry (Id));
Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
begin
-- A value of 0 represents no maximum specified, and entries and entry
-- families with no Max_Queue_Length aspect or pragma default to it.
if not Present (Prag) then
return Uint_0;
end if;
return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
end Get_Max_Queue_Length;
------------------------
-- Get_Name_Entity_Id --
------------------------
function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
begin
return Entity_Id (Get_Name_Table_Int (Id));
end Get_Name_Entity_Id;
------------------------------
-- Get_Name_From_CTC_Pragma --
------------------------------
function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
Arg : constant Node_Id :=
Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
begin
return Strval (Expr_Value_S (Arg));
end Get_Name_From_CTC_Pragma;
-----------------------
-- Get_Parent_Entity --
-----------------------
function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
begin
if Nkind (Unit) = N_Package_Body
and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
then
return Defining_Entity
(Specification (Instance_Spec (Original_Node (Unit))));
elsif Nkind (Unit) = N_Package_Instantiation then
return Defining_Entity (Specification (Instance_Spec (Unit)));
else
return Defining_Entity (Unit);
end if;
end Get_Parent_Entity;
-------------------
-- Get_Pragma_Id --
-------------------
function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
begin
return Get_Pragma_Id (Pragma_Name_Unmapped (N));
end Get_Pragma_Id;
------------------------
-- Get_Qualified_Name --
------------------------
function Get_Qualified_Name
(Id : Entity_Id;
Suffix : Entity_Id := Empty) return Name_Id
is
Suffix_Nam : Name_Id := No_Name;
begin
if Present (Suffix) then
Suffix_Nam := Chars (Suffix);
end if;
return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
end Get_Qualified_Name;
function Get_Qualified_Name
(Nam : Name_Id;
Suffix : Name_Id := No_Name;
Scop : Entity_Id := Current_Scope) return Name_Id
is
procedure Add_Scope (S : Entity_Id);
-- Add the fully qualified form of scope S to the name buffer. The
-- format is:
-- s-1__s__
---------------
-- Add_Scope --
---------------
procedure Add_Scope (S : Entity_Id) is
begin
if S = Empty then
null;
elsif S = Standard_Standard then
null;
else
Add_Scope (Scope (S));
Get_Name_String_And_Append (Chars (S));
Add_Str_To_Name_Buffer ("__");
end if;
end Add_Scope;
-- Start of processing for Get_Qualified_Name
begin
Name_Len := 0;
Add_Scope (Scop);
-- Append the base name after all scopes have been chained
Get_Name_String_And_Append (Nam);
-- Append the suffix (if present)
if Suffix /= No_Name then
Add_Str_To_Name_Buffer ("__");
Get_Name_String_And_Append (Suffix);
end if;
return Name_Find;
end Get_Qualified_Name;
-----------------------
-- Get_Reason_String --
-----------------------
procedure Get_Reason_String (N : Node_Id) is
begin
if Nkind (N) = N_String_Literal then
Store_String_Chars (Strval (N));
elsif Nkind (N) = N_Op_Concat then
Get_Reason_String (Left_Opnd (N));
Get_Reason_String (Right_Opnd (N));
-- If not of required form, error
else
Error_Msg_N
("Reason for pragma Warnings has wrong form", N);
Error_Msg_N
("\must be string literal or concatenation of string literals", N);
return;
end if;
end Get_Reason_String;
--------------------------------
-- Get_Reference_Discriminant --
--------------------------------
function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
D : Entity_Id;
begin
D := First_Discriminant (Typ);
while Present (D) loop
if Has_Implicit_Dereference (D) then
return D;
end if;
Next_Discriminant (D);
end loop;
return Empty;
end Get_Reference_Discriminant;
---------------------------
-- Get_Referenced_Object --
---------------------------
function Get_Referenced_Object (N : Node_Id) return Node_Id is
R : Node_Id;
begin
R := N;
while Is_Entity_Name (R)
and then Present (Renamed_Object (Entity (R)))
loop
R := Renamed_Object (Entity (R));
end loop;
return R;
end Get_Referenced_Object;
------------------------
-- Get_Renamed_Entity --
------------------------
function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
R : Entity_Id;
begin
R := E;
while Present (Renamed_Entity (R)) loop
R := Renamed_Entity (R);
end loop;
return R;
end Get_Renamed_Entity;
-----------------------
-- Get_Return_Object --
-----------------------
function Get_Return_Object (N : Node_Id) return Entity_Id is
Decl : Node_Id;
begin
Decl := First (Return_Object_Declarations (N));
while Present (Decl) loop
exit when Nkind (Decl) = N_Object_Declaration
and then Is_Return_Object (Defining_Identifier (Decl));
Next (Decl);
end loop;
pragma Assert (Present (Decl));
return Defining_Identifier (Decl);
end Get_Return_Object;
---------------------------
-- Get_Subprogram_Entity --
---------------------------
function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
Subp : Node_Id;
Subp_Id : Entity_Id;
begin
if Nkind (Nod) = N_Accept_Statement then
Subp := Entry_Direct_Name (Nod);
elsif Nkind (Nod) = N_Slice then
Subp := Prefix (Nod);
else
Subp := Name (Nod);
end if;
-- Strip the subprogram call
loop
if Nkind_In (Subp, N_Explicit_Dereference,
N_Indexed_Component,
N_Selected_Component)
then
Subp := Prefix (Subp);
elsif Nkind_In (Subp, N_Type_Conversion,
N_Unchecked_Type_Conversion)
then
Subp := Expression (Subp);
else
exit;
end if;
end loop;
-- Extract the entity of the subprogram call
if Is_Entity_Name (Subp) then
Subp_Id := Entity (Subp);
if Ekind (Subp_Id) = E_Access_Subprogram_Type then
Subp_Id := Directly_Designated_Type (Subp_Id);
end if;
if Is_Subprogram (Subp_Id) then
return Subp_Id;
else
return Empty;
end if;
-- The search did not find a construct that denotes a subprogram
else
return Empty;
end if;
end Get_Subprogram_Entity;
-----------------------------
-- Get_Task_Body_Procedure --
-----------------------------
function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
begin
-- Note: A task type may be the completion of a private type with
-- discriminants. When performing elaboration checks on a task
-- declaration, the current view of the type may be the private one,
-- and the procedure that holds the body of the task is held in its
-- underlying type.
-- This is an odd function, why not have Task_Body_Procedure do
-- the following digging???
return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
end Get_Task_Body_Procedure;
-------------------------
-- Get_User_Defined_Eq --
-------------------------
function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
Prim : Elmt_Id;
Op : Entity_Id;
begin
Prim := First_Elmt (Collect_Primitive_Operations (E));
while Present (Prim) loop
Op := Node (Prim);
if Chars (Op) = Name_Op_Eq
and then Etype (Op) = Standard_Boolean
and then Etype (First_Formal (Op)) = E
and then Etype (Next_Formal (First_Formal (Op))) = E
then
return Op;
end if;
Next_Elmt (Prim);
end loop;
return Empty;
end Get_User_Defined_Eq;
---------------
-- Get_Views --
---------------
procedure Get_Views
(Typ : Entity_Id;
Priv_Typ : out Entity_Id;
Full_Typ : out Entity_Id;
Full_Base : out Entity_Id;
CRec_Typ : out Entity_Id)
is
IP_View : Entity_Id;
begin
-- Assume that none of the views can be recovered
Priv_Typ := Empty;
Full_Typ := Empty;
Full_Base := Empty;
CRec_Typ := Empty;
-- The input type is the corresponding record type of a protected or a
-- task type.
if Ekind (Typ) = E_Record_Type
and then Is_Concurrent_Record_Type (Typ)
then
CRec_Typ := Typ;
Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
Full_Base := Base_Type (Full_Typ);
Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
-- Otherwise the input type denotes an arbitrary type
else
IP_View := Incomplete_Or_Partial_View (Typ);
-- The input type denotes the full view of a private type
if Present (IP_View) then
Priv_Typ := IP_View;
Full_Typ := Typ;
-- The input type is a private type
elsif Is_Private_Type (Typ) then
Priv_Typ := Typ;
Full_Typ := Full_View (Priv_Typ);
-- Otherwise the input type does not have any views
else
Full_Typ := Typ;
end if;
if Present (Full_Typ) then
Full_Base := Base_Type (Full_Typ);
if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
CRec_Typ := Corresponding_Record_Type (Full_Typ);
end if;
end if;
end if;
end Get_Views;
-----------------------
-- Has_Access_Values --
-----------------------
function Has_Access_Values (T : Entity_Id) return Boolean is
Typ : constant Entity_Id := Underlying_Type (T);
begin
-- Case of a private type which is not completed yet. This can only
-- happen in the case of a generic format type appearing directly, or
-- as a component of the type to which this function is being applied
-- at the top level. Return False in this case, since we certainly do
-- not know that the type contains access types.
if No (Typ) then
return False;
elsif Is_Access_Type (Typ) then
return True;
elsif Is_Array_Type (Typ) then
return Has_Access_Values (Component_Type (Typ));
elsif Is_Record_Type (Typ) then
declare
Comp : Entity_Id;
begin
-- Loop to Check components
Comp := First_Component_Or_Discriminant (Typ);
while Present (Comp) loop
-- Check for access component, tag field does not count, even
-- though it is implemented internally using an access type.
if Has_Access_Values (Etype (Comp))
and then Chars (Comp) /= Name_uTag
then
return True;
end if;
Next_Component_Or_Discriminant (Comp);
end loop;
end;
return False;
else
return False;
end if;
end Has_Access_Values;
------------------------------
-- Has_Compatible_Alignment --
------------------------------
function Has_Compatible_Alignment
(Obj : Entity_Id;
Expr : Node_Id;
Layout_Done : Boolean) return Alignment_Result
is
function Has_Compatible_Alignment_Internal
(Obj : Entity_Id;
Expr : Node_Id;
Layout_Done : Boolean;
Default : Alignment_Result) return Alignment_Result;
-- This is the internal recursive function that actually does the work.
-- There is one additional parameter, which says what the result should
-- be if no alignment information is found, and there is no definite
-- indication of compatible alignments. At the outer level, this is set
-- to Unknown, but for internal recursive calls in the case where types
-- are known to be correct, it is set to Known_Compatible.
---------------------------------------
-- Has_Compatible_Alignment_Internal --
---------------------------------------
function Has_Compatible_Alignment_Internal
(Obj : Entity_Id;
Expr : Node_Id;
Layout_Done : Boolean;
Default : Alignment_Result) return Alignment_Result
is
Result : Alignment_Result := Known_Compatible;
-- Holds the current status of the result. Note that once a value of
-- Known_Incompatible is set, it is sticky and does not get changed
-- to Unknown (the value in Result only gets worse as we go along,
-- never better).
Offs : Uint := No_Uint;
-- Set to a factor of the offset from the base object when Expr is a
-- selected or indexed component, based on Component_Bit_Offset and
-- Component_Size respectively. A negative value is used to represent
-- a value which is not known at compile time.
procedure Check_Prefix;
-- Checks the prefix recursively in the case where the expression
-- is an indexed or selected component.
procedure Set_Result (R : Alignment_Result);
-- If R represents a worse outcome (unknown instead of known
-- compatible, or known incompatible), then set Result to R.
------------------
-- Check_Prefix --
------------------
procedure Check_Prefix is
begin
-- The subtlety here is that in doing a recursive call to check
-- the prefix, we have to decide what to do in the case where we
-- don't find any specific indication of an alignment problem.
-- At the outer level, we normally set Unknown as the result in
-- this case, since we can only set Known_Compatible if we really
-- know that the alignment value is OK, but for the recursive
-- call, in the case where the types match, and we have not
-- specified a peculiar alignment for the object, we are only
-- concerned about suspicious rep clauses, the default case does
-- not affect us, since the compiler will, in the absence of such
-- rep clauses, ensure that the alignment is correct.
if Default = Known_Compatible
or else
(Etype (Obj) = Etype (Expr)
and then (Unknown_Alignment (Obj)
or else
Alignment (Obj) = Alignment (Etype (Obj))))
then
Set_Result
(Has_Compatible_Alignment_Internal
(Obj, Prefix (Expr), Layout_Done, Known_Compatible));
-- In all other cases, we need a full check on the prefix
else
Set_Result
(Has_Compatible_Alignment_Internal
(Obj, Prefix (Expr), Layout_Done, Unknown));
end if;
end Check_Prefix;
----------------
-- Set_Result --
----------------
procedure Set_Result (R : Alignment_Result) is
begin
if R > Result then
Result := R;
end if;
end Set_Result;
-- Start of processing for Has_Compatible_Alignment_Internal
begin
-- If Expr is a selected component, we must make sure there is no
-- potentially troublesome component clause and that the record is
-- not packed if the layout is not done.
if Nkind (Expr) = N_Selected_Component then
-- Packing generates unknown alignment if layout is not done
if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
Set_Result (Unknown);
end if;
-- Check prefix and component offset
Check_Prefix;
Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
-- If Expr is an indexed component, we must make sure there is no
-- potentially troublesome Component_Size clause and that the array
-- is not bit-packed if the layout is not done.
elsif Nkind (Expr) = N_Indexed_Component then
declare
Typ : constant Entity_Id := Etype (Prefix (Expr));
begin
-- Packing generates unknown alignment if layout is not done
if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
Set_Result (Unknown);
end if;
-- Check prefix and component offset (or at least size)
Check_Prefix;
Offs := Indexed_Component_Bit_Offset (Expr);
if Offs = No_Uint then
Offs := Component_Size (Typ);
end if;
end;
end if;
-- If we have a null offset, the result is entirely determined by
-- the base object and has already been computed recursively.
if Offs = Uint_0 then
null;
-- Case where we know the alignment of the object
elsif Known_Alignment (Obj) then
declare
ObjA : constant Uint := Alignment (Obj);
ExpA : Uint := No_Uint;
SizA : Uint := No_Uint;
begin
-- If alignment of Obj is 1, then we are always OK
if ObjA = 1 then
Set_Result (Known_Compatible);
-- Alignment of Obj is greater than 1, so we need to check
else
-- If we have an offset, see if it is compatible
if Offs /= No_Uint and Offs > Uint_0 then
if Offs mod (System_Storage_Unit * ObjA) /= 0 then
Set_Result (Known_Incompatible);
end if;
-- See if Expr is an object with known alignment
elsif Is_Entity_Name (Expr)
and then Known_Alignment (Entity (Expr))
then
ExpA := Alignment (Entity (Expr));
-- Otherwise, we can use the alignment of the type of
-- Expr given that we already checked for
-- discombobulating rep clauses for the cases of indexed
-- and selected components above.
elsif Known_Alignment (Etype (Expr)) then
ExpA := Alignment (Etype (Expr));
-- Otherwise the alignment is unknown
else
Set_Result (Default);
end if;
-- If we got an alignment, see if it is acceptable
if ExpA /= No_Uint and then ExpA < ObjA then
Set_Result (Known_Incompatible);
end if;
-- If Expr is not a piece of a larger object, see if size
-- is given. If so, check that it is not too small for the
-- required alignment.
if Offs /= No_Uint then
null;
-- See if Expr is an object with known size
elsif Is_Entity_Name (Expr)
and then Known_Static_Esize (Entity (Expr))
then
SizA := Esize (Entity (Expr));
-- Otherwise, we check the object size of the Expr type
elsif Known_Static_Esize (Etype (Expr)) then
SizA := Esize (Etype (Expr));
end if;
-- If we got a size, see if it is a multiple of the Obj
-- alignment, if not, then the alignment cannot be
-- acceptable, since the size is always a multiple of the
-- alignment.
if SizA /= No_Uint then
if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
Set_Result (Known_Incompatible);
end if;
end if;
end if;
end;
-- If we do not know required alignment, any non-zero offset is a
-- potential problem (but certainly may be OK, so result is unknown).
elsif Offs /= No_Uint then
Set_Result (Unknown);
-- If we can't find the result by direct comparison of alignment
-- values, then there is still one case that we can determine known
-- result, and that is when we can determine that the types are the
-- same, and no alignments are specified. Then we known that the
-- alignments are compatible, even if we don't know the alignment
-- value in the front end.
elsif Etype (Obj) = Etype (Expr) then
-- Types are the same, but we have to check for possible size
-- and alignments on the Expr object that may make the alignment
-- different, even though the types are the same.
if Is_Entity_Name (Expr) then
-- First check alignment of the Expr object. Any alignment less
-- than Maximum_Alignment is worrisome since this is the case
-- where we do not know the alignment of Obj.
if Known_Alignment (Entity (Expr))
and then UI_To_Int (Alignment (Entity (Expr))) <
Ttypes.Maximum_Alignment
then
Set_Result (Unknown);
-- Now check size of Expr object. Any size that is not an
-- even multiple of Maximum_Alignment is also worrisome
-- since it may cause the alignment of the object to be less
-- than the alignment of the type.
elsif Known_Static_Esize (Entity (Expr))
and then
(UI_To_Int (Esize (Entity (Expr))) mod
(Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
/= 0
then
Set_Result (Unknown);
-- Otherwise same type is decisive
else
Set_Result (Known_Compatible);
end if;
end if;
-- Another case to deal with is when there is an explicit size or
-- alignment clause when the types are not the same. If so, then the
-- result is Unknown. We don't need to do this test if the Default is
-- Unknown, since that result will be set in any case.
elsif Default /= Unknown
and then (Has_Size_Clause (Etype (Expr))
or else
Has_Alignment_Clause (Etype (Expr)))
then
Set_Result (Unknown);
-- If no indication found, set default
else
Set_Result (Default);
end if;
-- Return worst result found
return Result;
end Has_Compatible_Alignment_Internal;
-- Start of processing for Has_Compatible_Alignment
begin
-- If Obj has no specified alignment, then set alignment from the type
-- alignment. Perhaps we should always do this, but for sure we should
-- do it when there is an address clause since we can do more if the
-- alignment is known.
if Unknown_Alignment (Obj) then
Set_Alignment (Obj, Alignment (Etype (Obj)));
end if;
-- Now do the internal call that does all the work
return
Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
end Has_Compatible_Alignment;
----------------------
-- Has_Declarations --
----------------------
function Has_Declarations (N : Node_Id) return Boolean is
begin
return Nkind_In (Nkind (N), N_Accept_Statement,
N_Block_Statement,
N_Compilation_Unit_Aux,
N_Entry_Body,
N_Package_Body,
N_Protected_Body,
N_Subprogram_Body,
N_Task_Body,
N_Package_Specification);
end Has_Declarations;
---------------------------------
-- Has_Defaulted_Discriminants --
---------------------------------
function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
begin
return Has_Discriminants (Typ)
and then Present (First_Discriminant (Typ))
and then Present (Discriminant_Default_Value
(First_Discriminant (Typ)));
end Has_Defaulted_Discriminants;
-------------------
-- Has_Denormals --
-------------------
function Has_Denormals (E : Entity_Id) return Boolean is
begin
return Is_Floating_Point_Type (E) and then Denorm_On_Target;
end Has_Denormals;
-------------------------------------------
-- Has_Discriminant_Dependent_Constraint --
-------------------------------------------
function Has_Discriminant_Dependent_Constraint
(Comp : Entity_Id) return Boolean
is
Comp_Decl : constant Node_Id := Parent (Comp);
Subt_Indic : Node_Id;
Constr : Node_Id;
Assn : Node_Id;
begin
-- Discriminants can't depend on discriminants
if Ekind (Comp) = E_Discriminant then
return False;
else
Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
if Nkind (Subt_Indic) = N_Subtype_Indication then
Constr := Constraint (Subt_Indic);
if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
Assn := First (Constraints (Constr));
while Present (Assn) loop
case Nkind (Assn) is
when N_Identifier
| N_Range
| N_Subtype_Indication
=>
if Depends_On_Discriminant (Assn) then
return True;
end if;
when N_Discriminant_Association =>
if Depends_On_Discriminant (Expression (Assn)) then
return True;
end if;
when others =>
null;
end case;
Next (Assn);
end loop;
end if;
end if;
end if;
return False;
end Has_Discriminant_Dependent_Constraint;
--------------------------------------
-- Has_Effectively_Volatile_Profile --
--------------------------------------
function Has_Effectively_Volatile_Profile
(Subp_Id : Entity_Id) return Boolean
is
Formal : Entity_Id;
begin
-- Inspect the formal parameters looking for an effectively volatile
-- type.
Formal := First_Formal (Subp_Id);
while Present (Formal) loop
if Is_Effectively_Volatile (Etype (Formal)) then
return True;
end if;
Next_Formal (Formal);
end loop;
-- Inspect the return type of functions
if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
and then Is_Effectively_Volatile (Etype (Subp_Id))
then
return True;
end if;
return False;
end Has_Effectively_Volatile_Profile;
--------------------------
-- Has_Enabled_Property --
--------------------------
function Has_Enabled_Property
(Item_Id : Entity_Id;
Property : Name_Id) return Boolean
is
function Protected_Object_Has_Enabled_Property return Boolean;
-- Determine whether a protected object denoted by Item_Id has the
-- property enabled.
function State_Has_Enabled_Property return Boolean;
-- Determine whether a state denoted by Item_Id has the property enabled
function Variable_Has_Enabled_Property return Boolean;
-- Determine whether a variable denoted by Item_Id has the property
-- enabled.
-------------------------------------------
-- Protected_Object_Has_Enabled_Property --
-------------------------------------------
function Protected_Object_Has_Enabled_Property return Boolean is
Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
Constit_Elmt : Elmt_Id;
Constit_Id : Entity_Id;
begin
-- Protected objects always have the properties Async_Readers and
-- Async_Writers (SPARK RM 7.1.2(16)).
if Property = Name_Async_Readers
or else Property = Name_Async_Writers
then
return True;
-- Protected objects that have Part_Of components also inherit their
-- properties Effective_Reads and Effective_Writes
-- (SPARK RM 7.1.2(16)).
elsif Present (Constits) then
Constit_Elmt := First_Elmt (Constits);
while Present (Constit_Elmt) loop
Constit_Id := Node (Constit_Elmt);
if Has_Enabled_Property (Constit_Id, Property) then
return True;
end if;
Next_Elmt (Constit_Elmt);
end loop;
end if;
return False;
end Protected_Object_Has_Enabled_Property;
--------------------------------
-- State_Has_Enabled_Property --
--------------------------------
function State_Has_Enabled_Property return Boolean is
Decl : constant Node_Id := Parent (Item_Id);
Opt : Node_Id;
Opt_Nam : Node_Id;
Prop : Node_Id;
Prop_Nam : Node_Id;
Props : Node_Id;
begin
-- The declaration of an external abstract state appears as an
-- extension aggregate. If this is not the case, properties can never
-- be set.
if Nkind (Decl) /= N_Extension_Aggregate then
return False;
end if;
-- When External appears as a simple option, it automatically enables
-- all properties.
Opt := First (Expressions (Decl));
while Present (Opt) loop
if Nkind (Opt) = N_Identifier
and then Chars (Opt) = Name_External
then
return True;
end if;
Next (Opt);
end loop;
-- When External specifies particular properties, inspect those and
-- find the desired one (if any).
Opt := First (Component_Associations (Decl));
while Present (Opt) loop
Opt_Nam := First (Choices (Opt));
if Nkind (Opt_Nam) = N_Identifier
and then Chars (Opt_Nam) = Name_External
then
Props := Expression (Opt);
-- Multiple properties appear as an aggregate
if Nkind (Props) = N_Aggregate then
-- Simple property form
Prop := First (Expressions (Props));
while Present (Prop) loop
if Chars (Prop) = Property then
return True;
end if;
Next (Prop);
end loop;
-- Property with expression form
Prop := First (Component_Associations (Props));
while Present (Prop) loop
Prop_Nam := First (Choices (Prop));
-- The property can be represented in two ways:
-- others => <value>
-- <property> => <value>
if Nkind (Prop_Nam) = N_Others_Choice
or else (Nkind (Prop_Nam) = N_Identifier
and then Chars (Prop_Nam) = Property)
then
return Is_True (Expr_Value (Expression (Prop)));
end if;
Next (Prop);
end loop;
-- Single property
else
return Chars (Props) = Property;
end if;
end if;
Next (Opt);
end loop;
return False;
end State_Has_Enabled_Property;
-----------------------------------
-- Variable_Has_Enabled_Property --
-----------------------------------
function Variable_Has_Enabled_Property return Boolean is
function Is_Enabled (Prag : Node_Id) return Boolean;
-- Determine whether property pragma Prag (if present) denotes an
-- enabled property.
----------------
-- Is_Enabled --
----------------
function Is_Enabled (Prag : Node_Id) return Boolean is
Arg1 : Node_Id;
begin
if Present (Prag) then
Arg1 := First (Pragma_Argument_Associations (Prag));
-- The pragma has an optional Boolean expression, the related
-- property is enabled only when the expression evaluates to
-- True.
if Present (Arg1) then
return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
-- Otherwise the lack of expression enables the property by
-- default.
else
return True;
end if;
-- The property was never set in the first place
else
return False;
end if;
end Is_Enabled;
-- Local variables
AR : constant Node_Id :=
Get_Pragma (Item_Id, Pragma_Async_Readers);
AW : constant Node_Id :=
Get_Pragma (Item_Id, Pragma_Async_Writers);
ER : constant Node_Id :=
Get_Pragma (Item_Id, Pragma_Effective_Reads);
EW : constant Node_Id :=
Get_Pragma (Item_Id, Pragma_Effective_Writes);
-- Start of processing for Variable_Has_Enabled_Property
begin
-- A non-effectively volatile object can never possess external
-- properties.
if not Is_Effectively_Volatile (Item_Id) then
return False;
-- External properties related to variables come in two flavors -
-- explicit and implicit. The explicit case is characterized by the
-- presence of a property pragma with an optional Boolean flag. The
-- property is enabled when the flag evaluates to True or the flag is
-- missing altogether.
elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
return True;
elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
return True;
elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
return True;
elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
return True;
-- The implicit case lacks all property pragmas
elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
if Is_Protected_Type (Etype (Item_Id)) then
return Protected_Object_Has_Enabled_Property;
else
return True;
end if;
else
return False;
end if;
end Variable_Has_Enabled_Property;
-- Start of processing for Has_Enabled_Property
begin
-- Abstract states and variables have a flexible scheme of specifying
-- external properties.
if Ekind (Item_Id) = E_Abstract_State then
return State_Has_Enabled_Property;
elsif Ekind (Item_Id) = E_Variable then
return Variable_Has_Enabled_Property;
-- By default, protected objects only have the properties Async_Readers
-- and Async_Writers. If they have Part_Of components, they also inherit
-- their properties Effective_Reads and Effective_Writes
-- (SPARK RM 7.1.2(16)).
elsif Ekind (Item_Id) = E_Protected_Object then
return Protected_Object_Has_Enabled_Property;
-- Otherwise a property is enabled when the related item is effectively
-- volatile.
else
return Is_Effectively_Volatile (Item_Id);
end if;
end Has_Enabled_Property;
-------------------------------------
-- Has_Full_Default_Initialization --
-------------------------------------
function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
Comp : Entity_Id;
Prag : Node_Id;
begin
-- A type subject to pragma Default_Initial_Condition is fully default
-- initialized when the pragma appears with a non-null argument. Since
-- any type may act as the full view of a private type, this check must
-- be performed prior to the specialized tests below.
if Has_DIC (Typ) then
Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
pragma Assert (Present (Prag));
return Is_Verifiable_DIC_Pragma (Prag);
end if;
-- A scalar type is fully default initialized if it is subject to aspect
-- Default_Value.
if Is_Scalar_Type (Typ) then
return Has_Default_Aspect (Typ);
-- An array type is fully default initialized if its element type is
-- scalar and the array type carries aspect Default_Component_Value or
-- the element type is fully default initialized.
elsif Is_Array_Type (Typ) then
return
Has_Default_Aspect (Typ)
or else Has_Full_Default_Initialization (Component_Type (Typ));
-- A protected type, record type, or type extension is fully default
-- initialized if all its components either carry an initialization
-- expression or have a type that is fully default initialized. The
-- parent type of a type extension must be fully default initialized.
elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
-- Inspect all entities defined in the scope of the type, looking for
-- uninitialized components.
Comp := First_Entity (Typ);
while Present (Comp) loop
if Ekind (Comp) = E_Component
and then Comes_From_Source (Comp)
and then No (Expression (Parent (Comp)))
and then not Has_Full_Default_Initialization (Etype (Comp))
then
return False;
end if;
Next_Entity (Comp);
end loop;
-- Ensure that the parent type of a type extension is fully default
-- initialized.
if Etype (Typ) /= Typ
and then not Has_Full_Default_Initialization (Etype (Typ))
then
return False;
end if;
-- If we get here, then all components and parent portion are fully
-- default initialized.
return True;
-- A task type is fully default initialized by default
elsif Is_Task_Type (Typ) then
return True;
-- Otherwise the type is not fully default initialized
else
return False;
end if;
end Has_Full_Default_Initialization;
--------------------
-- Has_Infinities --
--------------------
function Has_Infinities (E : Entity_Id) return Boolean is
begin
return
Is_Floating_Point_Type (E)
and then Nkind (Scalar_Range (E)) = N_Range
and then Includes_Infinities (Scalar_Range (E));
end Has_Infinities;
--------------------
-- Has_Interfaces --
--------------------
function Has_Interfaces
(T : Entity_Id;
Use_Full_View : Boolean := True) return Boolean
is
Typ : Entity_Id := Base_Type (T);
begin
-- Handle concurrent types
if Is_Concurrent_Type (Typ) then
Typ := Corresponding_Record_Type (Typ);
end if;
if not Present (Typ)
or else not Is_Record_Type (Typ)
or else not Is_Tagged_Type (Typ)
then
return False;
end if;
-- Handle private types
if Use_Full_View and then Present (Full_View (Typ)) then
Typ := Full_View (Typ);
end if;
-- Handle concurrent record types
if Is_Concurrent_Record_Type (Typ)
and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
then
return True;
end if;
loop
if Is_Interface (Typ)
or else
(Is_Record_Type (Typ)
and then Present (Interfaces (Typ))
and then not Is_Empty_Elmt_List (Interfaces (Typ)))
then
return True;
end if;
exit when Etype (Typ) = Typ
-- Handle private types
or else (Present (Full_View (Etype (Typ)))
and then Full_View (Etype (Typ)) = Typ)
-- Protect frontend against wrong sources with cyclic derivations
or else Etype (Typ) = T;
-- Climb to the ancestor type handling private types
if Present (Full_View (Etype (Typ))) then
Typ := Full_View (Etype (Typ));
else
Typ := Etype (Typ);
end if;
end loop;
return False;
end Has_Interfaces;
--------------------------
-- Has_Max_Queue_Length --
--------------------------
function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
begin
return
Ekind (Id) = E_Entry
and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
end Has_Max_Queue_Length;
---------------------------------
-- Has_No_Obvious_Side_Effects --
---------------------------------
function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
begin
-- For now handle literals, constants, and non-volatile variables and
-- expressions combining these with operators or short circuit forms.
if Nkind (N) in N_Numeric_Or_String_Literal then
return True;
elsif Nkind (N) = N_Character_Literal then
return True;
elsif Nkind (N) in N_Unary_Op then
return Has_No_Obvious_Side_Effects (Right_Opnd (N));
elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
return Has_No_Obvious_Side_Effects (Left_Opnd (N))
and then
Has_No_Obvious_Side_Effects (Right_Opnd (N));
elsif Nkind (N) = N_Expression_With_Actions
and then Is_Empty_List (Actions (N))
then
return Has_No_Obvious_Side_Effects (Expression (N));
elsif Nkind (N) in N_Has_Entity then
return Present (Entity (N))
and then Ekind_In (Entity (N), E_Variable,
E_Constant,
E_Enumeration_Literal,
E_In_Parameter,
E_Out_Parameter,
E_In_Out_Parameter)
and then not Is_Volatile (Entity (N));
else
return False;
end if;
end Has_No_Obvious_Side_Effects;
-----------------------------
-- Has_Non_Null_Refinement --
-----------------------------
function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
Constits : Elist_Id;
begin
pragma Assert (Ekind (Id) = E_Abstract_State);
Constits := Refinement_Constituents (Id);
-- For a refinement to be non-null, the first constituent must be
-- anything other than null.
return
Present (Constits)
and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
end Has_Non_Null_Refinement;
-------------------
-- Has_Null_Body --
-------------------
function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
Body_Id : Entity_Id;
Decl : Node_Id;
Spec : Node_Id;
Stmt1 : Node_Id;
Stmt2 : Node_Id;
begin
Spec := Parent (Proc_Id);
Decl := Parent (Spec);
-- Retrieve the entity of the procedure body (e.g. invariant proc).
if Nkind (Spec) = N_Procedure_Specification
and then Nkind (Decl) = N_Subprogram_Declaration
then
Body_Id := Corresponding_Body (Decl);
-- The body acts as a spec
else
Body_Id := Proc_Id;
end if;
-- The body will be generated later
if No (Body_Id) then
return False;
end if;
Spec := Parent (Body_Id);
Decl := Parent (Spec);
pragma Assert
(Nkind (Spec) = N_Procedure_Specification
and then Nkind (Decl) = N_Subprogram_Body);
Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
-- Look for a null statement followed by an optional return
-- statement.
if Nkind (Stmt1) = N_Null_Statement then
Stmt2 := Next (Stmt1);
if Present (Stmt2) then
return Nkind (Stmt2) = N_Simple_Return_Statement;
else
return True;
end if;
end if;
return False;
end Has_Null_Body;
------------------------
-- Has_Null_Exclusion --
------------------------
function Has_Null_Exclusion (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Access_Definition
| N_Access_Function_Definition
| N_Access_Procedure_Definition
| N_Access_To_Object_Definition
| N_Allocator
| N_Derived_Type_Definition
| N_Function_Specification
| N_Subtype_Declaration
=>
return Null_Exclusion_Present (N);
when N_Component_Definition
| N_Formal_Object_Declaration
| N_Object_Renaming_Declaration
=>
if Present (Subtype_Mark (N)) then
return Null_Exclusion_Present (N);
else pragma Assert (Present (Access_Definition (N)));
return Null_Exclusion_Present (Access_Definition (N));
end if;
when N_Discriminant_Specification =>
if Nkind (Discriminant_Type (N)) = N_Access_Definition then
return Null_Exclusion_Present (Discriminant_Type (N));
else
return Null_Exclusion_Present (N);
end if;
when N_Object_Declaration =>
if Nkind (Object_Definition (N)) = N_Access_Definition then
return Null_Exclusion_Present (Object_Definition (N));
else
return Null_Exclusion_Present (N);
end if;
when N_Parameter_Specification =>
if Nkind (Parameter_Type (N)) = N_Access_Definition then
return Null_Exclusion_Present (Parameter_Type (N));
else
return Null_Exclusion_Present (N);
end if;
when others =>
return False;
end case;
end Has_Null_Exclusion;
------------------------
-- Has_Null_Extension --
------------------------
function Has_Null_Extension (T : Entity_Id) return Boolean is
B : constant Entity_Id := Base_Type (T);
Comps : Node_Id;
Ext : Node_Id;
begin
if Nkind (Parent (B)) = N_Full_Type_Declaration
and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
then
Ext := Record_Extension_Part (Type_Definition (Parent (B)));
if Present (Ext) then
if Null_Present (Ext) then
return True;
else
Comps := Component_List (Ext);
-- The null component list is rewritten during analysis to
-- include the parent component. Any other component indicates
-- that the extension was not originally null.
return Null_Present (Comps)
or else No (Next (First (Component_Items (Comps))));
end if;
else
return False;
end if;
else
return False;
end if;
end Has_Null_Extension;
-------------------------
-- Has_Null_Refinement --
-------------------------
function Has_Null_Refinement (Id : Entity_Id) return Boolean is
Constits : Elist_Id;
begin
pragma Assert (Ekind (Id) = E_Abstract_State);
Constits := Refinement_Constituents (Id);
-- For a refinement to be null, the state's sole constituent must be a
-- null.
return
Present (Constits)
and then Nkind (Node (First_Elmt (Constits))) = N_Null;
end Has_Null_Refinement;
-------------------------------
-- Has_Overriding_Initialize --
-------------------------------
function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
BT : constant Entity_Id := Base_Type (T);
P : Elmt_Id;
begin
if Is_Controlled (BT) then
if Is_RTU (Scope (BT), Ada_Finalization) then
return False;
elsif Present (Primitive_Operations (BT)) then
P := First_Elmt (Primitive_Operations (BT));
while Present (P) loop
declare
Init : constant Entity_Id := Node (P);
Formal : constant Entity_Id := First_Formal (Init);
begin
if Ekind (Init) = E_Procedure
and then Chars (Init) = Name_Initialize
and then Comes_From_Source (Init)
and then Present (Formal)
and then Etype (Formal) = BT
and then No (Next_Formal (Formal))
and then (Ada_Version < Ada_2012
or else not Null_Present (Parent (Init)))
then
return True;
end if;
end;
Next_Elmt (P);
end loop;
end if;
-- Here if type itself does not have a non-null Initialize operation:
-- check immediate ancestor.
if Is_Derived_Type (BT)
and then Has_Overriding_Initialize (Etype (BT))
then
return True;
end if;
end if;
return False;
end Has_Overriding_Initialize;
--------------------------------------
-- Has_Preelaborable_Initialization --
--------------------------------------
function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
Has_PE : Boolean;
procedure Check_Components (E : Entity_Id);
-- Check component/discriminant chain, sets Has_PE False if a component
-- or discriminant does not meet the preelaborable initialization rules.
----------------------
-- Check_Components --
----------------------
procedure Check_Components (E : Entity_Id) is
Ent : Entity_Id;
Exp : Node_Id;
function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
-- Returns True if and only if the expression denoted by N does not
-- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
---------------------------------
-- Is_Preelaborable_Expression --
---------------------------------
function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
Exp : Node_Id;
Assn : Node_Id;
Choice : Node_Id;
Comp_Type : Entity_Id;
Is_Array_Aggr : Boolean;
begin
if Is_OK_Static_Expression (N) then
return True;
elsif Nkind (N) = N_Null then
return True;
-- Attributes are allowed in general, even if their prefix is a
-- formal type. (It seems that certain attributes known not to be
-- static might not be allowed, but there are no rules to prevent
-- them.)
elsif Nkind (N) = N_Attribute_Reference then
return True;
-- The name of a discriminant evaluated within its parent type is
-- defined to be preelaborable (10.2.1(8)). Note that we test for
-- names that denote discriminals as well as discriminants to
-- catch references occurring within init procs.
elsif Is_Entity_Name (N)
and then
(Ekind (Entity (N)) = E_Discriminant
or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
and then Present (Discriminal_Link (Entity (N)))))
then
return True;
elsif Nkind (N) = N_Qualified_Expression then
return Is_Preelaborable_Expression (Expression (N));
-- For aggregates we have to check that each of the associations
-- is preelaborable.
elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
Is_Array_Aggr := Is_Array_Type (Etype (N));
if Is_Array_Aggr then
Comp_Type := Component_Type (Etype (N));
end if;
-- Check the ancestor part of extension aggregates, which must
-- be either the name of a type that has preelaborable init or
-- an expression that is preelaborable.
if Nkind (N) = N_Extension_Aggregate then
declare
Anc_Part : constant Node_Id := Ancestor_Part (N);
begin
if Is_Entity_Name (Anc_Part)
and then Is_Type (Entity (Anc_Part))
then
if not Has_Preelaborable_Initialization
(Entity (Anc_Part))
then
return False;
end if;
elsif not Is_Preelaborable_Expression (Anc_Part) then
return False;
end if;
end;
end if;
-- Check positional associations
Exp := First (Expressions (N));
while Present (Exp) loop
if not Is_Preelaborable_Expression (Exp) then
return False;
end if;
Next (Exp);
end loop;
-- Check named associations
Assn := First (Component_Associations (N));
while Present (Assn) loop
Choice := First (Choices (Assn));
while Present (Choice) loop
if Is_Array_Aggr then
if Nkind (Choice) = N_Others_Choice then
null;
elsif Nkind (Choice) = N_Range then
if not Is_OK_Static_Range (Choice) then
return False;
end if;
elsif not Is_OK_Static_Expression (Choice) then
return False;
end if;
else
Comp_Type := Etype (Choice);
end if;
Next (Choice);
end loop;
-- If the association has a <> at this point, then we have
-- to check whether the component's type has preelaborable
-- initialization. Note that this only occurs when the
-- association's corresponding component does not have a
-- default expression, the latter case having already been
-- expanded as an expression for the association.
if Box_Present (Assn) then
if not Has_Preelaborable_Initialization (Comp_Type) then
return False;
end if;
-- In the expression case we check whether the expression
-- is preelaborable.
elsif
not Is_Preelaborable_Expression (Expression (Assn))
then
return False;
end if;
Next (Assn);
end loop;
-- If we get here then aggregate as a whole is preelaborable
return True;
-- All other cases are not preelaborable
else
return False;
end if;
end Is_Preelaborable_Expression;
-- Start of processing for Check_Components
begin
-- Loop through entities of record or protected type
Ent := E;
while Present (Ent) loop
-- We are interested only in components and discriminants
Exp := Empty;
case Ekind (Ent) is
when E_Component =>
-- Get default expression if any. If there is no declaration
-- node, it means we have an internal entity. The parent and
-- tag fields are examples of such entities. For such cases,
-- we just test the type of the entity.
if Present (Declaration_Node (Ent)) then
Exp := Expression (Declaration_Node (Ent));
end if;
when E_Discriminant =>
-- Note: for a renamed discriminant, the Declaration_Node
-- may point to the one from the ancestor, and have a
-- different expression, so use the proper attribute to
-- retrieve the expression from the derived constraint.
Exp := Discriminant_Default_Value (Ent);
when others =>
goto Check_Next_Entity;
end case;
-- A component has PI if it has no default expression and the
-- component type has PI.
if No (Exp) then
if not Has_Preelaborable_Initialization (Etype (Ent)) then
Has_PE := False;
exit;
end if;
-- Require the default expression to be preelaborable
elsif not Is_Preelaborable_Expression (Exp) then
Has_PE := False;
exit;
end if;
<<Check_Next_Entity>>
Next_Entity (Ent);
end loop;
end Check_Components;
-- Start of processing for Has_Preelaborable_Initialization
begin
-- Immediate return if already marked as known preelaborable init. This
-- covers types for which this function has already been called once
-- and returned True (in which case the result is cached), and also
-- types to which a pragma Preelaborable_Initialization applies.
if Known_To_Have_Preelab_Init (E) then
return True;
end if;
-- If the type is a subtype representing a generic actual type, then
-- test whether its base type has preelaborable initialization since
-- the subtype representing the actual does not inherit this attribute
-- from the actual or formal. (but maybe it should???)
if Is_Generic_Actual_Type (E) then
return Has_Preelaborable_Initialization (Base_Type (E));
end if;
-- All elementary types have preelaborable initialization
if Is_Elementary_Type (E) then
Has_PE := True;
-- Array types have PI if the component type has PI
elsif Is_Array_Type (E) then
Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
-- A derived type has preelaborable initialization if its parent type
-- has preelaborable initialization and (in the case of a derived record
-- extension) if the non-inherited components all have preelaborable
-- initialization. However, a user-defined controlled type with an
-- overriding Initialize procedure does not have preelaborable
-- initialization.
elsif Is_Derived_Type (E) then
-- If the derived type is a private extension then it doesn't have
-- preelaborable initialization.
if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
return False;
end if;
-- First check whether ancestor type has preelaborable initialization
Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
-- If OK, check extension components (if any)
if Has_PE and then Is_Record_Type (E) then
Check_Components (First_Entity (E));
end if;
-- Check specifically for 10.2.1(11.4/2) exception: a controlled type
-- with a user defined Initialize procedure does not have PI. If
-- the type is untagged, the control primitives come from a component
-- that has already been checked.
if Has_PE
and then Is_Controlled (E)
and then Is_Tagged_Type (E)
and then Has_Overriding_Initialize (E)
then
Has_PE := False;
end if;
-- Private types not derived from a type having preelaborable init and
-- that are not marked with pragma Preelaborable_Initialization do not
-- have preelaborable initialization.
elsif Is_Private_Type (E) then
return False;
-- Record type has PI if it is non private and all components have PI
elsif Is_Record_Type (E) then
Has_PE := True;
Check_Components (First_Entity (E));
-- Protected types must not have entries, and components must meet
-- same set of rules as for record components.
elsif Is_Protected_Type (E) then
if Has_Entries (E) then
Has_PE := False;
else
Has_PE := True;
Check_Components (First_Entity (E));
Check_Components (First_Private_Entity (E));
end if;
-- Type System.Address always has preelaborable initialization
elsif Is_RTE (E, RE_Address) then
Has_PE := True;
-- In all other cases, type does not have preelaborable initialization
else
return False;
end if;
-- If type has preelaborable initialization, cache result
if Has_PE then
Set_Known_To_Have_Preelab_Init (E);
end if;
return Has_PE;
end Has_Preelaborable_Initialization;
---------------------------
-- Has_Private_Component --
---------------------------
function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
Btype : Entity_Id := Base_Type (Type_Id);
Component : Entity_Id;
begin
if Error_Posted (Type_Id)
or else Error_Posted (Btype)
then
return False;
end if;
if Is_Class_Wide_Type (Btype) then
Btype := Root_Type (Btype);
end if;
if Is_Private_Type (Btype) then
declare
UT : constant Entity_Id := Underlying_Type (Btype);
begin
if No (UT) then
if No (Full_View (Btype)) then
return not Is_Generic_Type (Btype)
and then
not Is_Generic_Type (Root_Type (Btype));
else
return not Is_Generic_Type (Root_Type (Full_View (Btype)));
end if;
else
return not Is_Frozen (UT) and then Has_Private_Component (UT);
end if;
end;
elsif Is_Array_Type (Btype) then
return Has_Private_Component (Component_Type (Btype));
elsif Is_Record_Type (Btype) then
Component := First_Component (Btype);
while Present (Component) loop
if Has_Private_Component (Etype (Component)) then
return True;
end if;
Next_Component (Component);
end loop;
return False;
elsif Is_Protected_Type (Btype)
and then Present (Corresponding_Record_Type (Btype))
then
return Has_Private_Component (Corresponding_Record_Type (Btype));
else
return False;
end if;
end Has_Private_Component;
----------------------
-- Has_Signed_Zeros --
----------------------
function Has_Signed_Zeros (E : Entity_Id) return Boolean is
begin
return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
end Has_Signed_Zeros;
------------------------------
-- Has_Significant_Contract --
------------------------------
function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
Subp_Nam : constant Name_Id := Chars (Subp_Id);
begin
-- _Finalizer procedure
if Subp_Nam = Name_uFinalizer then
return False;
-- _Postconditions procedure
elsif Subp_Nam = Name_uPostconditions then
return False;
-- Predicate function
elsif Ekind (Subp_Id) = E_Function
and then Is_Predicate_Function (Subp_Id)
then
return False;
-- TSS subprogram
elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
return False;
else
return True;
end if;
end Has_Significant_Contract;
-----------------------------
-- Has_Static_Array_Bounds --
-----------------------------
function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
Ndims : constant Nat := Number_Dimensions (Typ);
Index : Node_Id;
Low : Node_Id;
High : Node_Id;
begin
-- Unconstrained types do not have static bounds
if not Is_Constrained (Typ) then
return False;
end if;
-- First treat string literals specially, as the lower bound and length
-- of string literals are not stored like those of arrays.
-- A string literal always has static bounds
if Ekind (Typ) = E_String_Literal_Subtype then
return True;
end if;
-- Treat all dimensions in turn
Index := First_Index (Typ);
for Indx in 1 .. Ndims loop
-- In case of an illegal index which is not a discrete type, return
-- that the type is not static.
if not Is_Discrete_Type (Etype (Index))
or else Etype (Index) = Any_Type
then
return False;
end if;
Get_Index_Bounds (Index, Low, High);
if Error_Posted (Low) or else Error_Posted (High) then
return False;
end if;
if Is_OK_Static_Expression (Low)
and then
Is_OK_Static_Expression (High)
then
null;
else
return False;
end if;
Next (Index);
end loop;
-- If we fall through the loop, all indexes matched
return True;
end Has_Static_Array_Bounds;
----------------
-- Has_Stream --
----------------
function Has_Stream (T : Entity_Id) return Boolean is
E : Entity_Id;
begin
if No (T) then
return False;
elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
return True;
elsif Is_Array_Type (T) then
return Has_Stream (Component_Type (T));
elsif Is_Record_Type (T) then
E := First_Component (T);
while Present (E) loop
if Has_Stream (Etype (E)) then
return True;
else
Next_Component (E);
end if;
end loop;
return False;
elsif Is_Private_Type (T) then
return Has_Stream (Underlying_Type (T));
else
return False;
end if;
end Has_Stream;
----------------
-- Has_Suffix --
----------------
function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
begin
Get_Name_String (Chars (E));
return Name_Buffer (Name_Len) = Suffix;
end Has_Suffix;
----------------
-- Add_Suffix --
----------------
function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
begin
Get_Name_String (Chars (E));
Add_Char_To_Name_Buffer (Suffix);
return Name_Find;
end Add_Suffix;
-------------------
-- Remove_Suffix --
-------------------
function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
begin
pragma Assert (Has_Suffix (E, Suffix));
Get_Name_String (Chars (E));
Name_Len := Name_Len - 1;
return Name_Find;
end Remove_Suffix;
----------------------------------
-- Replace_Null_By_Null_Address --
----------------------------------
procedure Replace_Null_By_Null_Address (N : Node_Id) is
procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
-- Replace operand Op with a reference to Null_Address when the operand
-- denotes a null Address. Other_Op denotes the other operand.
--------------------------
-- Replace_Null_Operand --
--------------------------
procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
begin
-- Check the type of the complementary operand since the N_Null node
-- has not been decorated yet.
if Nkind (Op) = N_Null
and then Is_Descendant_Of_Address (Etype (Other_Op))
then
Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
end if;
end Replace_Null_Operand;
-- Start of processing for Replace_Null_By_Null_Address
begin
pragma Assert (Relaxed_RM_Semantics);
pragma Assert (Nkind_In (N, N_Null,
N_Op_Eq,
N_Op_Ge,
N_Op_Gt,
N_Op_Le,
N_Op_Lt,
N_Op_Ne));
if Nkind (N) = N_Null then
Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
else
declare
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
begin
Replace_Null_Operand (L, Other_Op => R);
Replace_Null_Operand (R, Other_Op => L);
end;
end if;
end Replace_Null_By_Null_Address;
--------------------------
-- Has_Tagged_Component --
--------------------------
function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
Comp : Entity_Id;
begin
if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
return Has_Tagged_Component (Underlying_Type (Typ));
elsif Is_Array_Type (Typ) then
return Has_Tagged_Component (Component_Type (Typ));
elsif Is_Tagged_Type (Typ) then
return True;
elsif Is_Record_Type (Typ) then
Comp := First_Component (Typ);
while Present (Comp) loop
if Has_Tagged_Component (Etype (Comp)) then
return True;
end if;
Next_Component (Comp);
end loop;
return False;
else
return False;
end if;
end Has_Tagged_Component;
-----------------------------
-- Has_Undefined_Reference --
-----------------------------
function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
Has_Undef_Ref : Boolean := False;
-- Flag set when expression Expr contains at least one undefined
-- reference.
function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
-- Determine whether N denotes a reference and if it does, whether it is
-- undefined.
----------------------------
-- Is_Undefined_Reference --
----------------------------
function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
begin
if Is_Entity_Name (N)
and then Present (Entity (N))
and then Entity (N) = Any_Id
then
Has_Undef_Ref := True;
return Abandon;
end if;
return OK;
end Is_Undefined_Reference;
procedure Find_Undefined_References is
new Traverse_Proc (Is_Undefined_Reference);
-- Start of processing for Has_Undefined_Reference
begin
Find_Undefined_References (Expr);
return Has_Undef_Ref;
end Has_Undefined_Reference;
----------------------------
-- Has_Volatile_Component --
----------------------------
function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
Comp : Entity_Id;
begin
if Has_Volatile_Components (Typ) then
return True;
elsif Is_Array_Type (Typ) then
return Is_Volatile (Component_Type (Typ));
elsif Is_Record_Type (Typ) then
Comp := First_Component (Typ);
while Present (Comp) loop
if Is_Volatile_Object (Comp) then
return True;
end if;
Comp := Next_Component (Comp);
end loop;
end if;
return False;
end Has_Volatile_Component;
-------------------------
-- Implementation_Kind --
-------------------------
function Implementation_Kind (Subp : Entity_Id) return Name_Id is
Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
Arg : Node_Id;
begin
pragma Assert (Present (Impl_Prag));
Arg := Last (Pragma_Argument_Associations (Impl_Prag));
return Chars (Get_Pragma_Arg (Arg));
end Implementation_Kind;
--------------------------
-- Implements_Interface --
--------------------------
function Implements_Interface
(Typ_Ent : Entity_Id;
Iface_Ent : Entity_Id;
Exclude_Parents : Boolean := False) return Boolean
is
Ifaces_List : Elist_Id;
Elmt : Elmt_Id;
Iface : Entity_Id := Base_Type (Iface_Ent);
Typ : Entity_Id := Base_Type (Typ_Ent);
begin
if Is_Class_Wide_Type (Typ) then
Typ := Root_Type (Typ);
end if;
if not Has_Interfaces (Typ) then
return False;
end if;
if Is_Class_Wide_Type (Iface) then
Iface := Root_Type (Iface);
end if;
Collect_Interfaces (Typ, Ifaces_List);
Elmt := First_Elmt (Ifaces_List);
while Present (Elmt) loop
if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
and then Exclude_Parents
then
null;
elsif Node (Elmt) = Iface then
return True;
end if;
Next_Elmt (Elmt);
end loop;
return False;
end Implements_Interface;
------------------------------------
-- In_Assertion_Expression_Pragma --
------------------------------------
function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
Par : Node_Id;
Prag : Node_Id := Empty;
begin
-- Climb the parent chain looking for an enclosing pragma
Par := N;
while Present (Par) loop
if Nkind (Par) = N_Pragma then
Prag := Par;
exit;
-- Precondition-like pragmas are expanded into if statements, check
-- the original node instead.
elsif Nkind (Original_Node (Par)) = N_Pragma then
Prag := Original_Node (Par);
exit;
-- The expansion of attribute 'Old generates a constant to capture
-- the result of the prefix. If the parent traversal reaches
-- one of these constants, then the node technically came from a
-- postcondition-like pragma. Note that the Ekind is not tested here
-- because N may be the expression of an object declaration which is
-- currently being analyzed. Such objects carry Ekind of E_Void.
elsif Nkind (Par) = N_Object_Declaration
and then Constant_Present (Par)
and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
return False;
end if;
Par := Parent (Par);
end loop;
return
Present (Prag)
and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
end In_Assertion_Expression_Pragma;
----------------------
-- In_Generic_Scope --
----------------------
function In_Generic_Scope (E : Entity_Id) return Boolean is
S : Entity_Id;
begin
S := Scope (E);
while Present (S) and then S /= Standard_Standard loop
if Is_Generic_Unit (S) then
return True;
end if;
S := Scope (S);
end loop;
return False;
end In_Generic_Scope;
-----------------
-- In_Instance --
-----------------
function In_Instance return Boolean is
Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
S : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind_In (S, E_Function, E_Package, E_Procedure)
and then Is_Generic_Instance (S)
then
-- A child instance is always compiled in the context of a parent
-- instance. Nevertheless, the actuals are not analyzed in an
-- instance context. We detect this case by examining the current
-- compilation unit, which must be a child instance, and checking
-- that it is not currently on the scope stack.
if Is_Child_Unit (Curr_Unit)
and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
N_Package_Instantiation
and then not In_Open_Scopes (Curr_Unit)
then
return False;
else
return True;
end if;
end if;
S := Scope (S);
end loop;
return False;
end In_Instance;
----------------------
-- In_Instance_Body --
----------------------
function In_Instance_Body return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind_In (S, E_Function, E_Procedure)
and then Is_Generic_Instance (S)
then
return True;
elsif Ekind (S) = E_Package
and then In_Package_Body (S)
and then Is_Generic_Instance (S)
then
return True;
end if;
S := Scope (S);
end loop;
return False;
end In_Instance_Body;
-----------------------------
-- In_Instance_Not_Visible --
-----------------------------
function In_Instance_Not_Visible return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind_In (S, E_Function, E_Procedure)
and then Is_Generic_Instance (S)
then
return True;
elsif Ekind (S) = E_Package
and then (In_Package_Body (S) or else In_Private_Part (S))
and then Is_Generic_Instance (S)
then
return True;
end if;
S := Scope (S);
end loop;
return False;
end In_Instance_Not_Visible;
------------------------------
-- In_Instance_Visible_Part --
------------------------------
function In_Instance_Visible_Part return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind (S) = E_Package
and then Is_Generic_Instance (S)
and then not In_Package_Body (S)
and then not In_Private_Part (S)
then
return True;
end if;
S := Scope (S);
end loop;
return False;
end In_Instance_Visible_Part;
---------------------
-- In_Package_Body --
---------------------
function In_Package_Body return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
if Ekind (S) = E_Package and then In_Package_Body (S) then
return True;
else
S := Scope (S);
end if;
end loop;
return False;
end In_Package_Body;
--------------------------------
-- In_Parameter_Specification --
--------------------------------
function In_Parameter_Specification (N : Node_Id) return Boolean is
PN : Node_Id;
begin
PN := Parent (N);
while Present (PN) loop
if Nkind (PN) = N_Parameter_Specification then
return True;
end if;
PN := Parent (PN);
end loop;
return False;
end In_Parameter_Specification;
--------------------------
-- In_Pragma_Expression --
--------------------------
function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
P : Node_Id;
begin
P := Parent (N);
loop
if No (P) then
return False;
elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
return True;
else
P := Parent (P);
end if;
end loop;
end In_Pragma_Expression;
---------------------------
-- In_Pre_Post_Condition --
---------------------------
function In_Pre_Post_Condition (N : Node_Id) return Boolean is
Par : Node_Id;
Prag : Node_Id := Empty;
Prag_Id : Pragma_Id;
begin
-- Climb the parent chain looking for an enclosing pragma
Par := N;
while Present (Par) loop
if Nkind (Par) = N_Pragma then
Prag := Par;
exit;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
if Present (Prag) then
Prag_Id := Get_Pragma_Id (Prag);
return
Prag_Id = Pragma_Post
or else Prag_Id = Pragma_Post_Class
or else Prag_Id = Pragma_Postcondition
or else Prag_Id = Pragma_Pre
or else Prag_Id = Pragma_Pre_Class
or else Prag_Id = Pragma_Precondition;
-- Otherwise the node is not enclosed by a pre/postcondition pragma
else
return False;
end if;
end In_Pre_Post_Condition;
-------------------------------------
-- In_Reverse_Storage_Order_Object --
-------------------------------------
function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
Pref : Node_Id;
Btyp : Entity_Id := Empty;
begin
-- Climb up indexed components
Pref := N;
loop
case Nkind (Pref) is
when N_Selected_Component =>
Pref := Prefix (Pref);
exit;
when N_Indexed_Component =>
Pref := Prefix (Pref);
when others =>
Pref := Empty;
exit;
end case;
end loop;
if Present (Pref) then
Btyp := Base_Type (Etype (Pref));
end if;
return Present (Btyp)
and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
and then Reverse_Storage_Order (Btyp);
end In_Reverse_Storage_Order_Object;
--------------------------------------
-- In_Subprogram_Or_Concurrent_Unit --
--------------------------------------
function In_Subprogram_Or_Concurrent_Unit return Boolean is
E : Entity_Id;
K : Entity_Kind;
begin
-- Use scope chain to check successively outer scopes
E := Current_Scope;
loop
K := Ekind (E);
if K in Subprogram_Kind
or else K in Concurrent_Kind
or else K in Generic_Subprogram_Kind
then
return True;
elsif E = Standard_Standard then
return False;
end if;
E := Scope (E);
end loop;
end In_Subprogram_Or_Concurrent_Unit;
---------------------
-- In_Visible_Part --
---------------------
function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
begin
return Is_Package_Or_Generic_Package (Scope_Id)
and then In_Open_Scopes (Scope_Id)
and then not In_Package_Body (Scope_Id)
and then not In_Private_Part (Scope_Id);
end In_Visible_Part;
--------------------------------
-- Incomplete_Or_Partial_View --
--------------------------------
function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
function Inspect_Decls
(Decls : List_Id;
Taft : Boolean := False) return Entity_Id;
-- Check whether a declarative region contains the incomplete or partial
-- view of Id.
-------------------
-- Inspect_Decls --
-------------------
function Inspect_Decls
(Decls : List_Id;
Taft : Boolean := False) return Entity_Id
is
Decl : Node_Id;
Match : Node_Id;
begin
Decl := First (Decls);
while Present (Decl) loop
Match := Empty;
-- The partial view of a Taft-amendment type is an incomplete
-- type.
if Taft then
if Nkind (Decl) = N_Incomplete_Type_Declaration then
Match := Defining_Identifier (Decl);
end if;
-- Otherwise look for a private type whose full view matches the
-- input type. Note that this checks full_type_declaration nodes
-- to account for derivations from a private type where the type
-- declaration hold the partial view and the full view is an
-- itype.
elsif Nkind_In (Decl, N_Full_Type_Declaration,
N_Private_Extension_Declaration,
N_Private_Type_Declaration)
then
Match := Defining_Identifier (Decl);
end if;
-- Guard against unanalyzed entities
if Present (Match)
and then Is_Type (Match)
and then Present (Full_View (Match))
and then Full_View (Match) = Id
then
return Match;
end if;
Next (Decl);
end loop;
return Empty;
end Inspect_Decls;
-- Local variables
Prev : Entity_Id;
-- Start of processing for Incomplete_Or_Partial_View
begin
-- Deferred constant or incomplete type case
Prev := Current_Entity_In_Scope (Id);
if Present (Prev)
and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
and then Present (Full_View (Prev))
and then Full_View (Prev) = Id
then
return Prev;
end if;
-- Private or Taft amendment type case
declare
Pkg : constant Entity_Id := Scope (Id);
Pkg_Decl : Node_Id := Pkg;
begin
if Present (Pkg)
and then Ekind_In (Pkg, E_Generic_Package, E_Package)
then
while Nkind (Pkg_Decl) /= N_Package_Specification loop
Pkg_Decl := Parent (Pkg_Decl);
end loop;
-- It is knows that Typ has a private view, look for it in the
-- visible declarations of the enclosing scope. A special case
-- of this is when the two views have been exchanged - the full
-- appears earlier than the private.
if Has_Private_Declaration (Id) then
Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
-- Exchanged view case, look in the private declarations
if No (Prev) then
Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
end if;
return Prev;
-- Otherwise if this is the package body, then Typ is a potential
-- Taft amendment type. The incomplete view should be located in
-- the private declarations of the enclosing scope.
elsif In_Package_Body (Pkg) then
return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
end if;
end if;
end;
-- The type has no incomplete or private view
return Empty;
end Incomplete_Or_Partial_View;
----------------------------------
-- Indexed_Component_Bit_Offset --
----------------------------------
function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
Exp : constant Node_Id := First (Expressions (N));
Typ : constant Entity_Id := Etype (Prefix (N));
Off : constant Uint := Component_Size (Typ);
Ind : Node_Id;
begin
-- Return early if the component size is not known or variable
if Off = No_Uint or else Off < Uint_0 then
return No_Uint;
end if;
-- Deal with the degenerate case of an empty component
if Off = Uint_0 then
return Off;
end if;
-- Check that both the index value and the low bound are known
if not Compile_Time_Known_Value (Exp) then
return No_Uint;
end if;
Ind := First_Index (Typ);
if No (Ind) then
return No_Uint;
end if;
if Nkind (Ind) = N_Subtype_Indication then
Ind := Constraint (Ind);
if Nkind (Ind) = N_Range_Constraint then
Ind := Range_Expression (Ind);
end if;
end if;
if Nkind (Ind) /= N_Range
or else not Compile_Time_Known_Value (Low_Bound (Ind))
then
return No_Uint;
end if;
-- Return the scaled offset
return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
end Indexed_Component_Bit_Offset;
----------------------------
-- Inherit_Rep_Item_Chain --
----------------------------
procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
Item : Node_Id;
Next_Item : Node_Id;
begin
-- There are several inheritance scenarios to consider depending on
-- whether both types have rep item chains and whether the destination
-- type already inherits part of the source type's rep item chain.
-- 1) The source type lacks a rep item chain
-- From_Typ ---> Empty
--
-- Typ --------> Item (or Empty)
-- In this case inheritance cannot take place because there are no items
-- to inherit.
-- 2) The destination type lacks a rep item chain
-- From_Typ ---> Item ---> ...
--
-- Typ --------> Empty
-- Inheritance takes place by setting the First_Rep_Item of the
-- destination type to the First_Rep_Item of the source type.
-- From_Typ ---> Item ---> ...
-- ^
-- Typ -----------+
-- 3.1) Both source and destination types have at least one rep item.
-- The destination type does NOT inherit a rep item from the source
-- type.
-- From_Typ ---> Item ---> Item
--
-- Typ --------> Item ---> Item
-- Inheritance takes place by setting the Next_Rep_Item of the last item
-- of the destination type to the First_Rep_Item of the source type.
-- From_Typ -------------------> Item ---> Item
-- ^
-- Typ --------> Item ---> Item --+
-- 3.2) Both source and destination types have at least one rep item.
-- The destination type DOES inherit part of the rep item chain of the
-- source type.
-- From_Typ ---> Item ---> Item ---> Item
-- ^
-- Typ --------> Item ------+
-- This rare case arises when the full view of a private extension must
-- inherit the rep item chain from the full view of its parent type and
-- the full view of the parent type contains extra rep items. Currently
-- only invariants may lead to such form of inheritance.
-- type From_Typ is tagged private
-- with Type_Invariant'Class => Item_2;
-- type Typ is new From_Typ with private
-- with Type_Invariant => Item_4;
-- At this point the rep item chains contain the following items
-- From_Typ -----------> Item_2 ---> Item_3
-- ^
-- Typ --------> Item_4 --+
-- The full views of both types may introduce extra invariants
-- type From_Typ is tagged null record
-- with Type_Invariant => Item_1;
-- type Typ is new From_Typ with null record;
-- The full view of Typ would have to inherit any new rep items added to
-- the full view of From_Typ.
-- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
-- ^
-- Typ --------> Item_4 --+
-- To achieve this form of inheritance, the destination type must first
-- sever the link between its own rep chain and that of the source type,
-- then inheritance 3.1 takes place.
-- Case 1: The source type lacks a rep item chain
if No (First_Rep_Item (From_Typ)) then
return;
-- Case 2: The destination type lacks a rep item chain
elsif No (First_Rep_Item (Typ)) then
Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
-- Case 3: Both the source and destination types have at least one rep
-- item. Traverse the rep item chain of the destination type to find the
-- last rep item.
else
Item := Empty;
Next_Item := First_Rep_Item (Typ);
while Present (Next_Item) loop
-- Detect a link between the destination type's rep chain and that
-- of the source type. There are two possibilities:
-- Variant 1
-- Next_Item
-- V
-- From_Typ ---> Item_1 --->
-- ^
-- Typ -----------+
--
-- Item is Empty
-- Variant 2
-- Next_Item
-- V
-- From_Typ ---> Item_1 ---> Item_2 --->
-- ^
-- Typ --------> Item_3 ------+
-- ^
-- Item
if Has_Rep_Item (From_Typ, Next_Item) then
exit;
end if;
Item := Next_Item;
Next_Item := Next_Rep_Item (Next_Item);
end loop;
-- Inherit the source type's rep item chain
if Present (Item) then
Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
else
Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
end if;
end if;
end Inherit_Rep_Item_Chain;
---------------------------------
-- Insert_Explicit_Dereference --
---------------------------------
procedure Insert_Explicit_Dereference (N : Node_Id) is
New_Prefix : constant Node_Id := Relocate_Node (N);
Ent : Entity_Id := Empty;
Pref : Node_Id;
I : Interp_Index;
It : Interp;
T : Entity_Id;
begin
Save_Interps (N, New_Prefix);
Rewrite (N,
Make_Explicit_Dereference (Sloc (Parent (N)),
Prefix => New_Prefix));
Set_Etype (N, Designated_Type (Etype (New_Prefix)));
if Is_Overloaded (New_Prefix) then
-- The dereference is also overloaded, and its interpretations are
-- the designated types of the interpretations of the original node.
Set_Etype (N, Any_Type);
Get_First_Interp (New_Prefix, I, It);
while Present (It.Nam) loop
T := It.Typ;
if Is_Access_Type (T) then
Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
end if;
Get_Next_Interp (I, It);
end loop;
End_Interp_List;
else
-- Prefix is unambiguous: mark the original prefix (which might
-- Come_From_Source) as a reference, since the new (relocated) one
-- won't be taken into account.
if Is_Entity_Name (New_Prefix) then
Ent := Entity (New_Prefix);
Pref := New_Prefix;
-- For a retrieval of a subcomponent of some composite object,
-- retrieve the ultimate entity if there is one.
elsif Nkind_In (New_Prefix, N_Selected_Component,
N_Indexed_Component)
then
Pref := Prefix (New_Prefix);
while Present (Pref)
and then Nkind_In (Pref, N_Selected_Component,
N_Indexed_Component)
loop
Pref := Prefix (Pref);
end loop;
if Present (Pref) and then Is_Entity_Name (Pref) then
Ent := Entity (Pref);
end if;
end if;
-- Place the reference on the entity node
if Present (Ent) then
Generate_Reference (Ent, Pref);
end if;
end if;
end Insert_Explicit_Dereference;
------------------------------------------
-- Inspect_Deferred_Constant_Completion --
------------------------------------------
procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
Decl : Node_Id;
begin
Decl := First (Decls);
while Present (Decl) loop
-- Deferred constant signature
if Nkind (Decl) = N_Object_Declaration
and then Constant_Present (Decl)
and then No (Expression (Decl))
-- No need to check internally generated constants
and then Comes_From_Source (Decl)
-- The constant is not completed. A full object declaration or a
-- pragma Import complete a deferred constant.
and then not Has_Completion (Defining_Identifier (Decl))
then
Error_Msg_N
("constant declaration requires initialization expression",
Defining_Identifier (Decl));
end if;
Decl := Next (Decl);
end loop;
end Inspect_Deferred_Constant_Completion;
-----------------------------
-- Install_Generic_Formals --
-----------------------------
procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
E : Entity_Id;
begin
pragma Assert (Is_Generic_Subprogram (Subp_Id));
E := First_Entity (Subp_Id);
while Present (E) loop
Install_Entity (E);
Next_Entity (E);
end loop;
end Install_Generic_Formals;
-----------------------------
-- Is_Actual_Out_Parameter --
-----------------------------
function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
Formal : Entity_Id;
Call : Node_Id;
begin
Find_Actual (N, Formal, Call);
return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
end Is_Actual_Out_Parameter;
-------------------------
-- Is_Actual_Parameter --
-------------------------
function Is_Actual_Parameter (N : Node_Id) return Boolean is
PK : constant Node_Kind := Nkind (Parent (N));
begin
case PK is
when N_Parameter_Association =>
return N = Explicit_Actual_Parameter (Parent (N));
when N_Subprogram_Call =>
return Is_List_Member (N)
and then
List_Containing (N) = Parameter_Associations (Parent (N));
when others =>
return False;
end case;
end Is_Actual_Parameter;
--------------------------------
-- Is_Actual_Tagged_Parameter --
--------------------------------
function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
Formal : Entity_Id;
Call : Node_Id;
begin
Find_Actual (N, Formal, Call);
return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
end Is_Actual_Tagged_Parameter;
---------------------
-- Is_Aliased_View --
---------------------
function Is_Aliased_View (Obj : Node_Id) return Boolean is
E : Entity_Id;
begin
if Is_Entity_Name (Obj) then
E := Entity (Obj);
return
(Is_Object (E)
and then
(Is_Aliased (E)
or else (Present (Renamed_Object (E))
and then Is_Aliased_View (Renamed_Object (E)))))
or else ((Is_Formal (E)
or else Ekind_In (E, E_Generic_In_Out_Parameter,
E_Generic_In_Parameter))
and then Is_Tagged_Type (Etype (E)))
or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
-- Current instance of type, either directly or as rewritten
-- reference to the current object.
or else (Is_Entity_Name (Original_Node (Obj))
and then Present (Entity (Original_Node (Obj)))
and then Is_Type (Entity (Original_Node (Obj))))
or else (Is_Type (E) and then E = Current_Scope)
or else (Is_Incomplete_Or_Private_Type (E)
and then Full_View (E) = Current_Scope)
-- Ada 2012 AI05-0053: the return object of an extended return
-- statement is aliased if its type is immutably limited.
or else (Is_Return_Object (E)
and then Is_Limited_View (Etype (E)));
elsif Nkind (Obj) = N_Selected_Component then
return Is_Aliased (Entity (Selector_Name (Obj)));
elsif Nkind (Obj) = N_Indexed_Component then
return Has_Aliased_Components (Etype (Prefix (Obj)))
or else
(Is_Access_Type (Etype (Prefix (Obj)))
and then Has_Aliased_Components
(Designated_Type (Etype (Prefix (Obj)))));
elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
return Is_Tagged_Type (Etype (Obj))
and then Is_Aliased_View (Expression (Obj));
elsif Nkind (Obj) = N_Explicit_Dereference then
return Nkind (Original_Node (Obj)) /= N_Function_Call;
else
return False;
end if;
end Is_Aliased_View;
-------------------------
-- Is_Ancestor_Package --
-------------------------
function Is_Ancestor_Package
(E1 : Entity_Id;
E2 : Entity_Id) return Boolean
is
Par : Entity_Id;
begin
Par := E2;
while Present (Par) and then Par /= Standard_Standard loop
if Par = E1 then
return True;
end if;
Par := Scope (Par);
end loop;
return False;
end Is_Ancestor_Package;
----------------------
-- Is_Atomic_Object --
----------------------
function Is_Atomic_Object (N : Node_Id) return Boolean is
function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
-- Determines if given object has atomic components
function Is_Atomic_Prefix (N : Node_Id) return Boolean;
-- If prefix is an implicit dereference, examine designated type
----------------------
-- Is_Atomic_Prefix --
----------------------
function Is_Atomic_Prefix (N : Node_Id) return Boolean is
begin
if Is_Access_Type (Etype (N)) then
return
Has_Atomic_Components (Designated_Type (Etype (N)));
else
return Object_Has_Atomic_Components (N);
end if;
end Is_Atomic_Prefix;
----------------------------------
-- Object_Has_Atomic_Components --
----------------------------------
function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
begin
if Has_Atomic_Components (Etype (N))
or else Is_Atomic (Etype (N))
then
return True;
elsif Is_Entity_Name (N)
and then (Has_Atomic_Components (Entity (N))
or else Is_Atomic (Entity (N)))
then
return True;
elsif Nkind (N) = N_Selected_Component
and then Is_Atomic (Entity (Selector_Name (N)))
then
return True;
elsif Nkind (N) = N_Indexed_Component
or else Nkind (N) = N_Selected_Component
then
return Is_Atomic_Prefix (Prefix (N));
else
return False;
end if;
end Object_Has_Atomic_Components;
-- Start of processing for Is_Atomic_Object
begin
-- Predicate is not relevant to subprograms
if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
return False;
elsif Is_Atomic (Etype (N))
or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
then
return True;
elsif Nkind (N) = N_Selected_Component
and then Is_Atomic (Entity (Selector_Name (N)))
then
return True;
elsif Nkind (N) = N_Indexed_Component
or else Nkind (N) = N_Selected_Component
then
return Is_Atomic_Prefix (Prefix (N));
else
return False;
end if;
end Is_Atomic_Object;
-----------------------------
-- Is_Atomic_Or_VFA_Object --
-----------------------------
function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
begin
return Is_Atomic_Object (N)
or else (Is_Object_Reference (N)
and then Is_Entity_Name (N)
and then (Is_Volatile_Full_Access (Entity (N))
or else
Is_Volatile_Full_Access (Etype (Entity (N)))));
end Is_Atomic_Or_VFA_Object;
-------------------------
-- Is_Attribute_Result --
-------------------------
function Is_Attribute_Result (N : Node_Id) return Boolean is
begin
return Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Result;
end Is_Attribute_Result;
-------------------------
-- Is_Attribute_Update --
-------------------------
function Is_Attribute_Update (N : Node_Id) return Boolean is
begin
return Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Update;
end Is_Attribute_Update;
------------------------------------
-- Is_Body_Or_Package_Declaration --
------------------------------------
function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
begin
return Nkind_In (N, N_Entry_Body,
N_Package_Body,
N_Package_Declaration,
N_Protected_Body,
N_Subprogram_Body,
N_Task_Body);
end Is_Body_Or_Package_Declaration;
-----------------------
-- Is_Bounded_String --
-----------------------
function Is_Bounded_String (T : Entity_Id) return Boolean is
Under : constant Entity_Id := Underlying_Type (Root_Type (T));
begin
-- Check whether T is ultimately derived from Ada.Strings.Superbounded.
-- Super_String, or one of the [Wide_]Wide_ versions. This will
-- be True for all the Bounded_String types in instances of the
-- Generic_Bounded_Length generics, and for types derived from those.
return Present (Under)
and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
Is_RTE (Root_Type (Under), RO_WW_Super_String));
end Is_Bounded_String;
-------------------------
-- Is_Child_Or_Sibling --
-------------------------
function Is_Child_Or_Sibling
(Pack_1 : Entity_Id;
Pack_2 : Entity_Id) return Boolean
is
function Distance_From_Standard (Pack : Entity_Id) return Nat;
-- Given an arbitrary package, return the number of "climbs" necessary
-- to reach scope Standard_Standard.
procedure Equalize_Depths
(Pack : in out Entity_Id;
Depth : in out Nat;
Depth_To_Reach : Nat);
-- Given an arbitrary package, its depth and a target depth to reach,
-- climb the scope chain until the said depth is reached. The pointer
-- to the package and its depth a modified during the climb.
----------------------------
-- Distance_From_Standard --
----------------------------
function Distance_From_Standard (Pack : Entity_Id) return Nat is
Dist : Nat;
Scop : Entity_Id;
begin
Dist := 0;
Scop := Pack;
while Present (Scop) and then Scop /= Standard_Standard loop
Dist := Dist + 1;
Scop := Scope (Scop);
end loop;
return Dist;
end Distance_From_Standard;
---------------------
-- Equalize_Depths --
---------------------
procedure Equalize_Depths
(Pack : in out Entity_Id;
Depth : in out Nat;
Depth_To_Reach : Nat)
is
begin
-- The package must be at a greater or equal depth
if Depth < Depth_To_Reach then
raise Program_Error;
end if;
-- Climb the scope chain until the desired depth is reached
while Present (Pack) and then Depth /= Depth_To_Reach loop
Pack := Scope (Pack);
Depth := Depth - 1;
end loop;
end Equalize_Depths;
-- Local variables
P_1 : Entity_Id := Pack_1;
P_1_Child : Boolean := False;
P_1_Depth : Nat := Distance_From_Standard (P_1);
P_2 : Entity_Id := Pack_2;
P_2_Child : Boolean := False;
P_2_Depth : Nat := Distance_From_Standard (P_2);
-- Start of processing for Is_Child_Or_Sibling
begin
pragma Assert
(Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
-- Both packages denote the same entity, therefore they cannot be
-- children or siblings.
if P_1 = P_2 then
return False;
-- One of the packages is at a deeper level than the other. Note that
-- both may still come from differen hierarchies.
-- (root) P_2
-- / \ :
-- X P_2 or X
-- : :
-- P_1 P_1
elsif P_1_Depth > P_2_Depth then
Equalize_Depths
(Pack => P_1,
Depth => P_1_Depth,
Depth_To_Reach => P_2_Depth);
P_1_Child := True;
-- (root) P_1
-- / \ :
-- P_1 X or X
-- : :
-- P_2 P_2
elsif P_2_Depth > P_1_Depth then
Equalize_Depths
(Pack => P_2,
Depth => P_2_Depth,
Depth_To_Reach => P_1_Depth);
P_2_Child := True;
end if;
-- At this stage the package pointers have been elevated to the same
-- depth. If the related entities are the same, then one package is a
-- potential child of the other:
-- P_1
-- :
-- X became P_1 P_2 or vica versa
-- :
-- P_2
if P_1 = P_2 then
if P_1_Child then
return Is_Child_Unit (Pack_1);
else pragma Assert (P_2_Child);
return Is_Child_Unit (Pack_2);
end if;
-- The packages may come from the same package chain or from entirely
-- different hierarcies. To determine this, climb the scope stack until
-- a common root is found.
-- (root) (root 1) (root 2)
-- / \ | |
-- P_1 P_2 P_1 P_2
else
while Present (P_1) and then Present (P_2) loop
-- The two packages may be siblings
if P_1 = P_2 then
return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
end if;
P_1 := Scope (P_1);
P_2 := Scope (P_2);
end loop;
end if;
return False;
end Is_Child_Or_Sibling;
-----------------------------
-- Is_Concurrent_Interface --
-----------------------------
function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
begin
return Is_Interface (T)
and then
(Is_Protected_Interface (T)
or else Is_Synchronized_Interface (T)
or else Is_Task_Interface (T));
end Is_Concurrent_Interface;
-----------------------
-- Is_Constant_Bound --
-----------------------
function Is_Constant_Bound (Exp : Node_Id) return Boolean is
begin
if Compile_Time_Known_Value (Exp) then
return True;
elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
return Is_Constant_Object (Entity (Exp))
or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
elsif Nkind (Exp) in N_Binary_Op then
return Is_Constant_Bound (Left_Opnd (Exp))
and then Is_Constant_Bound (Right_Opnd (Exp))
and then Scope (Entity (Exp)) = Standard_Standard;
else
return False;
end if;
end Is_Constant_Bound;
---------------------------
-- Is_Container_Element --
---------------------------
function Is_Container_Element (Exp : Node_Id) return Boolean is
Loc : constant Source_Ptr := Sloc (Exp);
Pref : constant Node_Id := Prefix (Exp);
Call : Node_Id;
-- Call to an indexing aspect
Cont_Typ : Entity_Id;
-- The type of the container being accessed
Elem_Typ : Entity_Id;
-- Its element type
Indexing : Entity_Id;
Is_Const : Boolean;
-- Indicates that constant indexing is used, and the element is thus
-- a constant.
Ref_Typ : Entity_Id;
-- The reference type returned by the indexing operation
begin
-- If C is a container, in a context that imposes the element type of
-- that container, the indexing notation C (X) is rewritten as:
-- Indexing (C, X).Discr.all
-- where Indexing is one of the indexing aspects of the container.
-- If the context does not require a reference, the construct can be
-- rewritten as
-- Element (C, X)
-- First, verify that the construct has the proper form
if not Expander_Active then
return False;
elsif Nkind (Pref) /= N_Selected_Component then
return False;
elsif Nkind (Prefix (Pref)) /= N_Function_Call then
return False;
else
Call := Prefix (Pref);
Ref_Typ := Etype (Call);
end if;
if not Has_Implicit_Dereference (Ref_Typ)
or else No (First (Parameter_Associations (Call)))
or else not Is_Entity_Name (Name (Call))
then
return False;
end if;
-- Retrieve type of container object, and its iterator aspects
Cont_Typ := Etype (First (Parameter_Associations (Call)));
Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
Is_Const := False;
if No (Indexing) then
-- Container should have at least one indexing operation
return False;
elsif Entity (Name (Call)) /= Entity (Indexing) then
-- This may be a variable indexing operation
Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
if No (Indexing)
or else Entity (Name (Call)) /= Entity (Indexing)
then
return False;
end if;
else
Is_Const := True;
end if;
Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
return False;
end if;
-- Check that the expression is not the target of an assignment, in
-- which case the rewriting is not possible.
if not Is_Const then
declare
Par : Node_Id;
begin
Par := Exp;
while Present (Par)
loop
if Nkind (Parent (Par)) = N_Assignment_Statement
and then Par = Name (Parent (Par))
then
return False;
-- A renaming produces a reference, and the transformation
-- does not apply.
elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
return False;
elsif Nkind_In
(Nkind (Parent (Par)), N_Function_Call,
N_Procedure_Call_Statement,
N_Entry_Call_Statement)
then
-- Check that the element is not part of an actual for an
-- in-out parameter.
declare
F : Entity_Id;
A : Node_Id;
begin
F := First_Formal (Entity (Name (Parent (Par))));
A := First (Parameter_Associations (Parent (Par)));
while Present (F) loop
if A = Par and then Ekind (F) /= E_In_Parameter then
return False;
end if;
Next_Formal (F);
Next (A);
end loop;
end;
-- E_In_Parameter in a call: element is not modified.
exit;
end if;
Par := Parent (Par);
end loop;
end;
end if;
-- The expression has the proper form and the context requires the
-- element type. Retrieve the Element function of the container and
-- rewrite the construct as a call to it.
declare
Op : Elmt_Id;
begin
Op := First_Elmt (Primitive_Operations (Cont_Typ));
while Present (Op) loop
exit when Chars (Node (Op)) = Name_Element;
Next_Elmt (Op);
end loop;
if No (Op) then
return False;
else
Rewrite (Exp,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Node (Op), Loc),
Parameter_Associations => Parameter_Associations (Call)));
Analyze_And_Resolve (Exp, Entity (Elem_Typ));
return True;
end if;
end;
end Is_Container_Element;
----------------------------
-- Is_Contract_Annotation --
----------------------------
function Is_Contract_Annotation (Item : Node_Id) return Boolean is
begin
return Is_Package_Contract_Annotation (Item)
or else
Is_Subprogram_Contract_Annotation (Item);
end Is_Contract_Annotation;
--------------------------------------
-- Is_Controlling_Limited_Procedure --
--------------------------------------
function Is_Controlling_Limited_Procedure
(Proc_Nam : Entity_Id) return Boolean
is
Param_Typ : Entity_Id := Empty;
begin
if Ekind (Proc_Nam) = E_Procedure
and then Present (Parameter_Specifications (Parent (Proc_Nam)))
then
Param_Typ := Etype (Parameter_Type (First (
Parameter_Specifications (Parent (Proc_Nam)))));
-- In this case where an Itype was created, the procedure call has been
-- rewritten.
elsif Present (Associated_Node_For_Itype (Proc_Nam))
and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
and then
Present (Parameter_Associations
(Associated_Node_For_Itype (Proc_Nam)))
then
Param_Typ :=
Etype (First (Parameter_Associations
(Associated_Node_For_Itype (Proc_Nam))));
end if;
if Present (Param_Typ) then
return
Is_Interface (Param_Typ)
and then Is_Limited_Record (Param_Typ);
end if;
return False;
end Is_Controlling_Limited_Procedure;
-----------------------------
-- Is_CPP_Constructor_Call --
-----------------------------
function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
begin
return Nkind (N) = N_Function_Call
and then Is_CPP_Class (Etype (Etype (N)))
and then Is_Constructor (Entity (Name (N)))
and then Is_Imported (Entity (Name (N)));
end Is_CPP_Constructor_Call;
-------------------------
-- Is_Current_Instance --
-------------------------
function Is_Current_Instance (N : Node_Id) return Boolean is
Typ : constant Entity_Id := Entity (N);
P : Node_Id;
begin
-- Simplest case: entity is a concurrent type and we are currently
-- inside the body. This will eventually be expanded into a
-- call to Self (for tasks) or _object (for protected objects).
if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
return True;
else
-- Check whether the context is a (sub)type declaration for the
-- type entity.
P := Parent (N);
while Present (P) loop
if Nkind_In (P, N_Full_Type_Declaration,
N_Private_Type_Declaration,
N_Subtype_Declaration)
and then Comes_From_Source (P)
and then Defining_Entity (P) = Typ
then
return True;
-- A subtype name may appear in an aspect specification for a
-- Predicate_Failure aspect, for which we do not construct a
-- wrapper procedure. The subtype will be replaced by the
-- expression being tested when the corresponding predicate
-- check is expanded.
elsif Nkind (P) = N_Aspect_Specification
and then Nkind (Parent (P)) = N_Subtype_Declaration
then
return True;
elsif Nkind (P) = N_Pragma
and then
Get_Pragma_Id (P) = Pragma_Predicate_Failure
then
return True;
end if;
P := Parent (P);
end loop;
end if;
-- In any other context this is not a current occurrence
return False;
end Is_Current_Instance;
--------------------
-- Is_Declaration --
--------------------
function Is_Declaration (N : Node_Id) return Boolean is
begin
return
Is_Declaration_Other_Than_Renaming (N)
or else Is_Renaming_Declaration (N);
end Is_Declaration;
----------------------------------------
-- Is_Declaration_Other_Than_Renaming --
----------------------------------------
function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Abstract_Subprogram_Declaration
| N_Exception_Declaration
| N_Expression_Function
| N_Full_Type_Declaration
| N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Number_Declaration
| N_Object_Declaration
| N_Package_Declaration
| N_Private_Extension_Declaration
| N_Private_Type_Declaration
| N_Subprogram_Declaration
| N_Subtype_Declaration
=>
return True;
when others =>
return False;
end case;
end Is_Declaration_Other_Than_Renaming;
--------------------------------
-- Is_Declared_Within_Variant --
--------------------------------
function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
Comp_Decl : constant Node_Id := Parent (Comp);
Comp_List : constant Node_Id := Parent (Comp_Decl);
begin
return Nkind (Parent (Comp_List)) = N_Variant;
end Is_Declared_Within_Variant;
----------------------------------------------
-- Is_Dependent_Component_Of_Mutable_Object --
----------------------------------------------
function Is_Dependent_Component_Of_Mutable_Object
(Object : Node_Id) return Boolean
is
P : Node_Id;
Prefix_Type : Entity_Id;
P_Aliased : Boolean := False;
Comp : Entity_Id;
Deref : Node_Id := Object;
-- Dereference node, in something like X.all.Y(2)
-- Start of processing for Is_Dependent_Component_Of_Mutable_Object
begin
-- Find the dereference node if any
while Nkind_In (Deref, N_Indexed_Component,
N_Selected_Component,
N_Slice)
loop
Deref := Prefix (Deref);
end loop;
-- Ada 2005: If we have a component or slice of a dereference,
-- something like X.all.Y (2), and the type of X is access-to-constant,
-- Is_Variable will return False, because it is indeed a constant
-- view. But it might be a view of a variable object, so we want the
-- following condition to be True in that case.
if Is_Variable (Object)
or else (Ada_Version >= Ada_2005
and then Nkind (Deref) = N_Explicit_Dereference)
then
if Nkind (Object) = N_Selected_Component then
P := Prefix (Object);
Prefix_Type := Etype (P);
if Is_Entity_Name (P) then
if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
Prefix_Type := Base_Type (Prefix_Type);
end if;
if Is_Aliased (Entity (P)) then
P_Aliased := True;
end if;
-- A discriminant check on a selected component may be expanded
-- into a dereference when removing side-effects. Recover the
-- original node and its type, which may be unconstrained.
elsif Nkind (P) = N_Explicit_Dereference
and then not (Comes_From_Source (P))
then
P := Original_Node (P);
Prefix_Type := Etype (P);
else
-- Check for prefix being an aliased component???
null;
end if;
-- A heap object is constrained by its initial value
-- Ada 2005 (AI-363): Always assume the object could be mutable in
-- the dereferenced case, since the access value might denote an
-- unconstrained aliased object, whereas in Ada 95 the designated
-- object is guaranteed to be constrained. A worst-case assumption
-- has to apply in Ada 2005 because we can't tell at compile
-- time whether the object is "constrained by its initial value"
-- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
-- rules (these rules are acknowledged to need fixing).
if Ada_Version < Ada_2005 then
if Is_Access_Type (Prefix_Type)
or else Nkind (P) = N_Explicit_Dereference
then
return False;
end if;
else pragma Assert (Ada_Version >= Ada_2005);
if Is_Access_Type (Prefix_Type) then
-- If the access type is pool-specific, and there is no
-- constrained partial view of the designated type, then the
-- designated object is known to be constrained.
if Ekind (Prefix_Type) = E_Access_Type
and then not Object_Type_Has_Constrained_Partial_View
(Typ => Designated_Type (Prefix_Type),
Scop => Current_Scope)
then
return False;
-- Otherwise (general access type, or there is a constrained
-- partial view of the designated type), we need to check
-- based on the designated type.
else
Prefix_Type := Designated_Type (Prefix_Type);
end if;
end if;
end if;
Comp :=
Original_Record_Component (Entity (Selector_Name (Object)));
-- As per AI-0017, the renaming is illegal in a generic body, even
-- if the subtype is indefinite.
-- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
if not Is_Constrained (Prefix_Type)
and then (Is_Definite_Subtype (Prefix_Type)
or else
(Is_Generic_Type (Prefix_Type)
and then Ekind (Current_Scope) = E_Generic_Package
and then In_Package_Body (Current_Scope)))
and then (Is_Declared_Within_Variant (Comp)
or else Has_Discriminant_Dependent_Constraint (Comp))
and then (not P_Aliased or else Ada_Version >= Ada_2005)
then
return True;
-- If the prefix is of an access type at this point, then we want
-- to return False, rather than calling this function recursively
-- on the access object (which itself might be a discriminant-
-- dependent component of some other object, but that isn't
-- relevant to checking the object passed to us). This avoids
-- issuing wrong errors when compiling with -gnatc, where there
-- can be implicit dereferences that have not been expanded.
elsif Is_Access_Type (Etype (Prefix (Object))) then
return False;
else
return
Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
end if;
elsif Nkind (Object) = N_Indexed_Component
or else Nkind (Object) = N_Slice
then
return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
-- A type conversion that Is_Variable is a view conversion:
-- go back to the denoted object.
elsif Nkind (Object) = N_Type_Conversion then
return
Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
end if;
end if;
return False;
end Is_Dependent_Component_Of_Mutable_Object;
---------------------
-- Is_Dereferenced --
---------------------
function Is_Dereferenced (N : Node_Id) return Boolean is
P : constant Node_Id := Parent (N);
begin
return Nkind_In (P, N_Selected_Component,
N_Explicit_Dereference,
N_Indexed_Component,
N_Slice)
and then Prefix (P) = N;
end Is_Dereferenced;
----------------------
-- Is_Descendant_Of --
----------------------
function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
T : Entity_Id;
Etyp : Entity_Id;
begin
pragma Assert (Nkind (T1) in N_Entity);
pragma Assert (Nkind (T2) in N_Entity);
T := Base_Type (T1);
-- Immediate return if the types match
if T = T2 then
return True;
-- Comment needed here ???
elsif Ekind (T) = E_Class_Wide_Type then
return Etype (T) = T2;
-- All other cases
else
loop
Etyp := Etype (T);
-- Done if we found the type we are looking for
if Etyp = T2 then
return True;
-- Done if no more derivations to check
elsif T = T1
or else T = Etyp
then
return False;
-- Following test catches error cases resulting from prev errors
elsif No (Etyp) then
return False;
elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
return False;
elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
return False;
end if;
T := Base_Type (Etyp);
end loop;
end if;
end Is_Descendant_Of;
----------------------------------------
-- Is_Descendant_Of_Suspension_Object --
----------------------------------------
function Is_Descendant_Of_Suspension_Object
(Typ : Entity_Id) return Boolean
is
Cur_Typ : Entity_Id;
Par_Typ : Entity_Id;
begin
-- Climb the type derivation chain checking each parent type against
-- Suspension_Object.
Cur_Typ := Base_Type (Typ);
while Present (Cur_Typ) loop
Par_Typ := Etype (Cur_Typ);
-- The current type is a match
if Is_Suspension_Object (Cur_Typ) then
return True;
-- Stop the traversal once the root of the derivation chain has been
-- reached. In that case the current type is its own base type.
elsif Cur_Typ = Par_Typ then
exit;
end if;
Cur_Typ := Base_Type (Par_Typ);
end loop;
return False;
end Is_Descendant_Of_Suspension_Object;
---------------------------------------------
-- Is_Double_Precision_Floating_Point_Type --
---------------------------------------------
function Is_Double_Precision_Floating_Point_Type
(E : Entity_Id) return Boolean is
begin
return Is_Floating_Point_Type (E)
and then Machine_Radix_Value (E) = Uint_2
and then Machine_Mantissa_Value (E) = UI_From_Int (53)
and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
end Is_Double_Precision_Floating_Point_Type;
-----------------------------
-- Is_Effectively_Volatile --
-----------------------------
function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
begin
if Is_Type (Id) then
-- An arbitrary type is effectively volatile when it is subject to
-- pragma Atomic or Volatile.
if Is_Volatile (Id) then
return True;
-- An array type is effectively volatile when it is subject to pragma
-- Atomic_Components or Volatile_Components or its component type is
-- effectively volatile.
elsif Is_Array_Type (Id) then
return
Has_Volatile_Components (Id)
or else
Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
-- A protected type is always volatile
elsif Is_Protected_Type (Id) then
return True;
-- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
-- automatically volatile.
elsif Is_Descendant_Of_Suspension_Object (Id) then
return True;
-- Otherwise the type is not effectively volatile
else
return False;
end if;
-- Otherwise Id denotes an object
else
return
Is_Volatile (Id)
or else Has_Volatile_Components (Id)
or else Is_Effectively_Volatile (Etype (Id));
end if;
end Is_Effectively_Volatile;
------------------------------------
-- Is_Effectively_Volatile_Object --
------------------------------------
function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
begin
if Is_Entity_Name (N) then
return Is_Effectively_Volatile (Entity (N));
elsif Nkind (N) = N_Indexed_Component then
return Is_Effectively_Volatile_Object (Prefix (N));
elsif Nkind (N) = N_Selected_Component then
return
Is_Effectively_Volatile_Object (Prefix (N))
or else
Is_Effectively_Volatile_Object (Selector_Name (N));
else
return False;
end if;
end Is_Effectively_Volatile_Object;
-------------------
-- Is_Entry_Body --
-------------------
function Is_Entry_Body (Id : Entity_Id) return Boolean is
begin
return
Ekind_In (Id, E_Entry, E_Entry_Family)
and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
end Is_Entry_Body;
--------------------------
-- Is_Entry_Declaration --
--------------------------
function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
begin
return
Ekind_In (Id, E_Entry, E_Entry_Family)
and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
end Is_Entry_Declaration;
------------------------------------
-- Is_Expanded_Priority_Attribute --
------------------------------------
function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
begin
return
Nkind (E) = N_Function_Call
and then not Configurable_Run_Time_Mode
and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
end Is_Expanded_Priority_Attribute;
----------------------------
-- Is_Expression_Function --
----------------------------
function Is_Expression_Function (Subp : Entity_Id) return Boolean is
begin
if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
return
Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
N_Expression_Function;
else
return False;
end if;
end Is_Expression_Function;
------------------------------------------
-- Is_Expression_Function_Or_Completion --
------------------------------------------
function Is_Expression_Function_Or_Completion
(Subp : Entity_Id) return Boolean
is
Subp_Decl : Node_Id;
begin
if Ekind (Subp) = E_Function then
Subp_Decl := Unit_Declaration_Node (Subp);
-- The function declaration is either an expression function or is
-- completed by an expression function body.
return
Is_Expression_Function (Subp)
or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
and then Present (Corresponding_Body (Subp_Decl))
and then Is_Expression_Function
(Corresponding_Body (Subp_Decl)));
elsif Ekind (Subp) = E_Subprogram_Body then
return Is_Expression_Function (Subp);
else
return False;
end if;
end Is_Expression_Function_Or_Completion;
-----------------------
-- Is_EVF_Expression --
-----------------------
function Is_EVF_Expression (N : Node_Id) return Boolean is
Orig_N : constant Node_Id := Original_Node (N);
Alt : Node_Id;
Expr : Node_Id;
Id : Entity_Id;
begin
-- Detect a reference to a formal parameter of a specific tagged type
-- whose related subprogram is subject to pragma Expresions_Visible with
-- value "False".
if Is_Entity_Name (N) and then Present (Entity (N)) then
Id := Entity (N);
return
Is_Formal (Id)
and then Is_Specific_Tagged_Type (Etype (Id))
and then Extensions_Visible_Status (Id) =
Extensions_Visible_False;
-- A case expression is an EVF expression when it contains at least one
-- EVF dependent_expression. Note that a case expression may have been
-- expanded, hence the use of Original_Node.
elsif Nkind (Orig_N) = N_Case_Expression then
Alt := First (Alternatives (Orig_N));
while Present (Alt) loop
if Is_EVF_Expression (Expression (Alt)) then
return True;
end if;
Next (Alt);
end loop;
-- An if expression is an EVF expression when it contains at least one
-- EVF dependent_expression. Note that an if expression may have been
-- expanded, hence the use of Original_Node.
elsif Nkind (Orig_N) = N_If_Expression then
Expr := Next (First (Expressions (Orig_N)));
while Present (Expr) loop
if Is_EVF_Expression (Expr) then
return True;
end if;
Next (Expr);
end loop;
-- A qualified expression or a type conversion is an EVF expression when
-- its operand is an EVF expression.
elsif Nkind_In (N, N_Qualified_Expression,
N_Unchecked_Type_Conversion,
N_Type_Conversion)
then
return Is_EVF_Expression (Expression (N));
-- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
-- their prefix denotes an EVF expression.
elsif Nkind (N) = N_Attribute_Reference
and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
Name_Old,
Name_Update)
then
return Is_EVF_Expression (Prefix (N));
end if;
return False;
end Is_EVF_Expression;
--------------
-- Is_False --
--------------
function Is_False (U : Uint) return Boolean is
begin
return (U = 0);
end Is_False;
---------------------------
-- Is_Fixed_Model_Number --
---------------------------
function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
S : constant Ureal := Small_Value (T);
M : Urealp.Save_Mark;
R : Boolean;
begin
M := Urealp.Mark;
R := (U = UR_Trunc (U / S) * S);
Urealp.Release (M);
return R;
end Is_Fixed_Model_Number;
-------------------------------
-- Is_Fully_Initialized_Type --
-------------------------------
function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
begin
-- Scalar types
if Is_Scalar_Type (Typ) then
-- A scalar type with an aspect Default_Value is fully initialized
-- Note: Iniitalize/Normalize_Scalars also ensure full initialization
-- of a scalar type, but we don't take that into account here, since
-- we don't want these to affect warnings.
return Has_Default_Aspect (Typ);
elsif Is_Access_Type (Typ) then
return True;
elsif Is_Array_Type (Typ) then
if Is_Fully_Initialized_Type (Component_Type (Typ))
or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
then
return True;
end if;
-- An interesting case, if we have a constrained type one of whose
-- bounds is known to be null, then there are no elements to be
-- initialized, so all the elements are initialized.
if Is_Constrained (Typ) then
declare
Indx : Node_Id;
Indx_Typ : Entity_Id;
Lbd, Hbd : Node_Id;
begin
Indx := First_Index (Typ);
while Present (Indx) loop
if Etype (Indx) = Any_Type then
return False;
-- If index is a range, use directly
elsif Nkind (Indx) = N_Range then
Lbd := Low_Bound (Indx);
Hbd := High_Bound (Indx);
else
Indx_Typ := Etype (Indx);
if Is_Private_Type (Indx_Typ) then
Indx_Typ := Full_View (Indx_Typ);
end if;
if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
return False;
else
Lbd := Type_Low_Bound (Indx_Typ);
Hbd := Type_High_Bound (Indx_Typ);
end if;
end if;
if Compile_Time_Known_Value (Lbd)
and then
Compile_Time_Known_Value (Hbd)
then
if Expr_Value (Hbd) < Expr_Value (Lbd) then
return True;
end if;
end if;
Next_Index (Indx);
end loop;
end;
end if;
-- If no null indexes, then type is not fully initialized
return False;
-- Record types
elsif Is_Record_Type (Typ) then
if Has_Discriminants (Typ)
and then
Present (Discriminant_Default_Value (First_Discriminant (Typ)))
and then Is_Fully_Initialized_Variant (Typ)
then
return True;
end if;
-- We consider bounded string types to be fully initialized, because
-- otherwise we get false alarms when the Data component is not
-- default-initialized.
if Is_Bounded_String (Typ) then
return True;
end if;
-- Controlled records are considered to be fully initialized if
-- there is a user defined Initialize routine. This may not be
-- entirely correct, but as the spec notes, we are guessing here
-- what is best from the point of view of issuing warnings.
if Is_Controlled (Typ) then
declare
Utyp : constant Entity_Id := Underlying_Type (Typ);
begin
if Present (Utyp) then
declare
Init : constant Entity_Id :=
(Find_Optional_Prim_Op
(Underlying_Type (Typ), Name_Initialize));
begin
if Present (Init)
and then Comes_From_Source (Init)
and then not
Is_Predefined_File_Name
(File_Name (Get_Source_File_Index (Sloc (Init))))
then
return True;
elsif Has_Null_Extension (Typ)
and then
Is_Fully_Initialized_Type
(Etype (Base_Type (Typ)))
then
return True;
end if;
end;
end if;
end;
end if;
-- Otherwise see if all record components are initialized
declare
Ent : Entity_Id;
begin
Ent := First_Entity (Typ);
while Present (Ent) loop
if Ekind (Ent) = E_Component
and then (No (Parent (Ent))
or else No (Expression (Parent (Ent))))
and then not Is_Fully_Initialized_Type (Etype (Ent))
-- Special VM case for tag components, which need to be
-- defined in this case, but are never initialized as VMs
-- are using other dispatching mechanisms. Ignore this
-- uninitialized case. Note that this applies both to the
-- uTag entry and the main vtable pointer (CPP_Class case).
and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
then
return False;
end if;
Next_Entity (Ent);
end loop;
end;
-- No uninitialized components, so type is fully initialized.
-- Note that this catches the case of no components as well.
return True;
elsif Is_Concurrent_Type (Typ) then
return True;
elsif Is_Private_Type (Typ) then
declare
U : constant Entity_Id := Underlying_Type (Typ);
begin
if No (U) then
return False;
else
return Is_Fully_Initialized_Type (U);
end if;
end;
else
return False;
end if;
end Is_Fully_Initialized_Type;
----------------------------------
-- Is_Fully_Initialized_Variant --
----------------------------------
function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
Loc : constant Source_Ptr := Sloc (Typ);
Constraints : constant List_Id := New_List;
Components : constant Elist_Id := New_Elmt_List;
Comp_Elmt : Elmt_Id;
Comp_Id : Node_Id;
Comp_List : Node_Id;
Discr : Entity_Id;
Discr_Val : Node_Id;
Report_Errors : Boolean;
pragma Warnings (Off, Report_Errors);
begin
if Serious_Errors_Detected > 0 then
return False;
end if;
if Is_Record_Type (Typ)
and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
then
Comp_List := Component_List (Type_Definition (Parent (Typ)));
Discr := First_Discriminant (Typ);
while Present (Discr) loop
if Nkind (Parent (Discr)) = N_Discriminant_Specification then
Discr_Val := Expression (Parent (Discr));
if Present (Discr_Val)
and then Is_OK_Static_Expression (Discr_Val)
then
Append_To (Constraints,
Make_Component_Association (Loc,
Choices => New_List (New_Occurrence_Of (Discr, Loc)),
Expression => New_Copy (Discr_Val)));
else
return False;
end if;
else
return False;
end if;
Next_Discriminant (Discr);
end loop;
Gather_Components
(Typ => Typ,
Comp_List => Comp_List,
Governed_By => Constraints,
Into => Components,
Report_Errors => Report_Errors);
-- Check that each component present is fully initialized
Comp_Elmt := First_Elmt (Components);
while Present (Comp_Elmt) loop
Comp_Id := Node (Comp_Elmt);
if Ekind (Comp_Id) = E_Component
and then (No (Parent (Comp_Id))
or else No (Expression (Parent (Comp_Id))))
and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
then
return False;
end if;
Next_Elmt (Comp_Elmt);
end loop;
return True;
elsif Is_Private_Type (Typ) then
declare
U : constant Entity_Id := Underlying_Type (Typ);
begin
if No (U) then
return False;
else
return Is_Fully_Initialized_Variant (U);
end if;
end;
else
return False;
end if;
end Is_Fully_Initialized_Variant;
------------------------------------
-- Is_Generic_Declaration_Or_Body --
------------------------------------
function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
Spec_Decl : Node_Id;
begin
-- Package/subprogram body
if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
and then Present (Corresponding_Spec (Decl))
then
Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
-- Package/subprogram body stub
elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
and then Present (Corresponding_Spec_Of_Stub (Decl))
then
Spec_Decl :=
Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
-- All other cases
else
Spec_Decl := Decl;
end if;
-- Rather than inspecting the defining entity of the spec declaration,
-- look at its Nkind. This takes care of the case where the analysis of
-- a generic body modifies the Ekind of its spec to allow for recursive
-- calls.
return
Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
N_Generic_Subprogram_Declaration);
end Is_Generic_Declaration_Or_Body;
----------------------------
-- Is_Inherited_Operation --
----------------------------
function Is_Inherited_Operation (E : Entity_Id) return Boolean is
pragma Assert (Is_Overloadable (E));
Kind : constant Node_Kind := Nkind (Parent (E));
begin
return Kind = N_Full_Type_Declaration
or else Kind = N_Private_Extension_Declaration
or else Kind = N_Subtype_Declaration
or else (Ekind (E) = E_Enumeration_Literal
and then Is_Derived_Type (Etype (E)));
end Is_Inherited_Operation;
-------------------------------------
-- Is_Inherited_Operation_For_Type --
-------------------------------------
function Is_Inherited_Operation_For_Type
(E : Entity_Id;
Typ : Entity_Id) return Boolean
is
begin
-- Check that the operation has been created by the type declaration
return Is_Inherited_Operation (E)
and then Defining_Identifier (Parent (E)) = Typ;
end Is_Inherited_Operation_For_Type;
--------------------------------------
-- Is_Inlinable_Expression_Function --
--------------------------------------
function Is_Inlinable_Expression_Function
(Subp : Entity_Id) return Boolean
is
Return_Expr : Node_Id;
begin
if Is_Expression_Function_Or_Completion (Subp)
and then Has_Pragma_Inline_Always (Subp)
and then Needs_No_Actuals (Subp)
and then No (Contract (Subp))
and then not Is_Dispatching_Operation (Subp)
and then Needs_Finalization (Etype (Subp))
and then not Is_Class_Wide_Type (Etype (Subp))
and then not (Has_Invariants (Etype (Subp)))
and then Present (Subprogram_Body (Subp))
and then Was_Expression_Function (Subprogram_Body (Subp))
then
Return_Expr := Expression_Of_Expression_Function (Subp);
-- The returned object must not have a qualified expression and its
-- nominal subtype must be statically compatible with the result
-- subtype of the expression function.
return
Nkind (Return_Expr) = N_Identifier
and then Etype (Return_Expr) = Etype (Subp);
end if;
return False;
end Is_Inlinable_Expression_Function;
-----------------
-- Is_Iterator --
-----------------
function Is_Iterator (Typ : Entity_Id) return Boolean is
function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
-- Determine whether type Iter_Typ is a predefined forward or reversible
-- iterator.
----------------------
-- Denotes_Iterator --
----------------------
function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
begin
-- Check that the name matches, and that the ultimate ancestor is in
-- a predefined unit, i.e the one that declares iterator interfaces.
return
Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
Name_Reversible_Iterator)
and then Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Root_Type (Iter_Typ))));
end Denotes_Iterator;
-- Local variables
Iface_Elmt : Elmt_Id;
Ifaces : Elist_Id;
-- Start of processing for Is_Iterator
begin
-- The type may be a subtype of a descendant of the proper instance of
-- the predefined interface type, so we must use the root type of the
-- given type. The same is done for Is_Reversible_Iterator.
if Is_Class_Wide_Type (Typ)
and then Denotes_Iterator (Root_Type (Typ))
then
return True;
elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
return False;
elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
return True;
else
Collect_Interfaces (Typ, Ifaces);
Iface_Elmt := First_Elmt (Ifaces);
while Present (Iface_Elmt) loop
if Denotes_Iterator (Node (Iface_Elmt)) then
return True;
end if;
Next_Elmt (Iface_Elmt);
end loop;
return False;
end if;
end Is_Iterator;
----------------------------
-- Is_Iterator_Over_Array --
----------------------------
function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
Container : constant Node_Id := Name (N);
Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
begin
return Is_Array_Type (Container_Typ);
end Is_Iterator_Over_Array;
------------
-- Is_LHS --
------------
-- We seem to have a lot of overlapping functions that do similar things
-- (testing for left hand sides or lvalues???).
function Is_LHS (N : Node_Id) return Is_LHS_Result is
P : constant Node_Id := Parent (N);
begin
-- Return True if we are the left hand side of an assignment statement
if Nkind (P) = N_Assignment_Statement then
if Name (P) = N then
return Yes;
else
return No;
end if;
-- Case of prefix of indexed or selected component or slice
elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
and then N = Prefix (P)
then
-- Here we have the case where the parent P is N.Q or N(Q .. R).
-- If P is an LHS, then N is also effectively an LHS, but there
-- is an important exception. If N is of an access type, then
-- what we really have is N.all.Q (or N.all(Q .. R)). In either
-- case this makes N.all a left hand side but not N itself.
-- If we don't know the type yet, this is the case where we return
-- Unknown, since the answer depends on the type which is unknown.
if No (Etype (N)) then
return Unknown;
-- We have an Etype set, so we can check it
elsif Is_Access_Type (Etype (N)) then
return No;
-- OK, not access type case, so just test whole expression
else
return Is_LHS (P);
end if;
-- All other cases are not left hand sides
else
return No;
end if;
end Is_LHS;
-----------------------------
-- Is_Library_Level_Entity --
-----------------------------
function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
begin
-- The following is a small optimization, and it also properly handles
-- discriminals, which in task bodies might appear in expressions before
-- the corresponding procedure has been created, and which therefore do
-- not have an assigned scope.
if Is_Formal (E) then
return False;
end if;
-- Normal test is simply that the enclosing dynamic scope is Standard
return Enclosing_Dynamic_Scope (E) = Standard_Standard;
end Is_Library_Level_Entity;
--------------------------------
-- Is_Limited_Class_Wide_Type --
--------------------------------
function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
begin
return
Is_Class_Wide_Type (Typ)
and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
end Is_Limited_Class_Wide_Type;
---------------------------------
-- Is_Local_Variable_Reference --
---------------------------------
function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
begin
if not Is_Entity_Name (Expr) then
return False;
else
declare
Ent : constant Entity_Id := Entity (Expr);
Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
begin
if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
return False;
else
return Present (Sub) and then Sub = Current_Subprogram;
end if;
end;
end if;
end Is_Local_Variable_Reference;
-----------------------
-- Is_Name_Reference --
-----------------------
function Is_Name_Reference (N : Node_Id) return Boolean is
begin
if Is_Entity_Name (N) then
return Present (Entity (N)) and then Is_Object (Entity (N));
end if;
case Nkind (N) is
when N_Indexed_Component
| N_Slice
=>
return
Is_Name_Reference (Prefix (N))
or else Is_Access_Type (Etype (Prefix (N)));
-- Attributes 'Input, 'Old and 'Result produce objects
when N_Attribute_Reference =>
return
Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
when N_Selected_Component =>
return
Is_Name_Reference (Selector_Name (N))
and then
(Is_Name_Reference (Prefix (N))
or else Is_Access_Type (Etype (Prefix (N))));
when N_Explicit_Dereference =>
return True;
-- A view conversion of a tagged name is a name reference
when N_Type_Conversion =>
return
Is_Tagged_Type (Etype (Subtype_Mark (N)))
and then Is_Tagged_Type (Etype (Expression (N)))
and then Is_Name_Reference (Expression (N));
-- An unchecked type conversion is considered to be a name if the
-- operand is a name (this construction arises only as a result of
-- expansion activities).
when N_Unchecked_Type_Conversion =>
return Is_Name_Reference (Expression (N));
when others =>
return False;
end case;
end Is_Name_Reference;
---------------------------------
-- Is_Nontrivial_DIC_Procedure --
---------------------------------
function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
Body_Decl : Node_Id;
Stmt : Node_Id;
begin
if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
Body_Decl :=
Unit_Declaration_Node
(Corresponding_Body (Unit_Declaration_Node (Id)));
-- The body of the Default_Initial_Condition procedure must contain
-- at least one statement, otherwise the generation of the subprogram
-- body failed.
pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
-- To qualify as nontrivial, the first statement of the procedure
-- must be a check in the form of an if statement. If the original
-- Default_Initial_Condition expression was folded, then the first
-- statement is not a check.
Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
return
Nkind (Stmt) = N_If_Statement
and then Nkind (Original_Node (Stmt)) = N_Pragma;
end if;
return False;
end Is_Nontrivial_DIC_Procedure;
-------------------------
-- Is_Null_Record_Type --
-------------------------
function Is_Null_Record_Type (T : Entity_Id) return Boolean is
Decl : constant Node_Id := Parent (T);
begin
return Nkind (Decl) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Decl)) = N_Record_Definition
and then
(No (Component_List (Type_Definition (Decl)))
or else Null_Present (Component_List (Type_Definition (Decl))));
end Is_Null_Record_Type;
-------------------------
-- Is_Object_Reference --
-------------------------
function Is_Object_Reference (N : Node_Id) return Boolean is
function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
-- Determine whether N is the name of an internally-generated renaming
--------------------------------------
-- Is_Internally_Generated_Renaming --
--------------------------------------
function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
P : Node_Id;
begin
P := N;
while Present (P) loop
if Nkind (P) = N_Object_Renaming_Declaration then
return not Comes_From_Source (P);
elsif Is_List_Member (P) then
return False;
end if;
P := Parent (P);
end loop;
return False;
end Is_Internally_Generated_Renaming;
-- Start of processing for Is_Object_Reference
begin
if Is_Entity_Name (N) then
return Present (Entity (N)) and then Is_Object (Entity (N));
else
case Nkind (N) is
when N_Indexed_Component
| N_Slice
=>
return
Is_Object_Reference (Prefix (N))
or else Is_Access_Type (Etype (Prefix (N)));
-- In Ada 95, a function call is a constant object; a procedure
-- call is not.
when N_Function_Call =>
return Etype (N) /= Standard_Void_Type;
-- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
-- objects.
when N_Attribute_Reference =>
return
Nam_In (Attribute_Name (N), Name_Input,
Name_Loop_Entry,
Name_Old,
Name_Result);
when N_Selected_Component =>
return
Is_Object_Reference (Selector_Name (N))
and then
(Is_Object_Reference (Prefix (N))
or else Is_Access_Type (Etype (Prefix (N))));
when N_Explicit_Dereference =>
return True;
-- A view conversion of a tagged object is an object reference
when N_Type_Conversion =>
return Is_Tagged_Type (Etype (Subtype_Mark (N)))
and then Is_Tagged_Type (Etype (Expression (N)))
and then Is_Object_Reference (Expression (N));
-- An unchecked type conversion is considered to be an object if
-- the operand is an object (this construction arises only as a
-- result of expansion activities).
when N_Unchecked_Type_Conversion =>
return True;
-- Allow string literals to act as objects as long as they appear
-- in internally-generated renamings. The expansion of iterators
-- may generate such renamings when the range involves a string
-- literal.
when N_String_Literal =>
return Is_Internally_Generated_Renaming (Parent (N));
-- AI05-0003: In Ada 2012 a qualified expression is a name.
-- This allows disambiguation of function calls and the use
-- of aggregates in more contexts.
when N_Qualified_Expression =>
if Ada_Version < Ada_2012 then
return False;
else
return Is_Object_Reference (Expression (N))
or else Nkind (Expression (N)) = N_Aggregate;
end if;
when others =>
return False;
end case;
end if;
end Is_Object_Reference;
-----------------------------------
-- Is_OK_Variable_For_Out_Formal --
-----------------------------------
function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
begin
Note_Possible_Modification (AV, Sure => True);
-- We must reject parenthesized variable names. Comes_From_Source is
-- checked because there are currently cases where the compiler violates
-- this rule (e.g. passing a task object to its controlled Initialize
-- routine). This should be properly documented in sinfo???
if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
return False;
-- A variable is always allowed
elsif Is_Variable (AV) then
return True;
-- Generalized indexing operations are rewritten as explicit
-- dereferences, and it is only during resolution that we can
-- check whether the context requires an access_to_variable type.
elsif Nkind (AV) = N_Explicit_Dereference
and then Ada_Version >= Ada_2012
and then Nkind (Original_Node (AV)) = N_Indexed_Component
and then Present (Etype (Original_Node (AV)))
and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
then
return not Is_Access_Constant (Etype (Prefix (AV)));
-- Unchecked conversions are allowed only if they come from the
-- generated code, which sometimes uses unchecked conversions for out
-- parameters in cases where code generation is unaffected. We tell
-- source unchecked conversions by seeing if they are rewrites of
-- an original Unchecked_Conversion function call, or of an explicit
-- conversion of a function call or an aggregate (as may happen in the
-- expansion of a packed array aggregate).
elsif Nkind (AV) = N_Unchecked_Type_Conversion then
if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
return False;
elsif Comes_From_Source (AV)
and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
then
return False;
elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
return Is_OK_Variable_For_Out_Formal (Expression (AV));
else
return True;
end if;
-- Normal type conversions are allowed if argument is a variable
elsif Nkind (AV) = N_Type_Conversion then
if Is_Variable (Expression (AV))
and then Paren_Count (Expression (AV)) = 0
then
Note_Possible_Modification (Expression (AV), Sure => True);
return True;
-- We also allow a non-parenthesized expression that raises
-- constraint error if it rewrites what used to be a variable
elsif Raises_Constraint_Error (Expression (AV))
and then Paren_Count (Expression (AV)) = 0
and then Is_Variable (Original_Node (Expression (AV)))
then
return True;
-- Type conversion of something other than a variable
else
return False;
end if;
-- If this node is rewritten, then test the original form, if that is
-- OK, then we consider the rewritten node OK (for example, if the
-- original node is a conversion, then Is_Variable will not be true
-- but we still want to allow the conversion if it converts a variable).
elsif Original_Node (AV) /= AV then
-- In Ada 2012, the explicit dereference may be a rewritten call to a
-- Reference function.
if Ada_Version >= Ada_2012
and then Nkind (Original_Node (AV)) = N_Function_Call
and then
Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
then
-- Check that this is not a constant reference.
return not Is_Access_Constant (Etype (Prefix (AV)));
elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
return
not Is_Access_Constant (Etype
(Get_Reference_Discriminant (Etype (Original_Node (AV)))));
else
return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
end if;
-- All other non-variables are rejected
else
return False;
end if;
end Is_OK_Variable_For_Out_Formal;
----------------------------
-- Is_OK_Volatile_Context --
----------------------------
function Is_OK_Volatile_Context
(Context : Node_Id;
Obj_Ref : Node_Id) return Boolean
is
function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
-- Determine whether an arbitrary node denotes a call to a protected
-- entry, function, or procedure in prefixed form where the prefix is
-- Obj_Ref.
function Within_Check (Nod : Node_Id) return Boolean;
-- Determine whether an arbitrary node appears in a check node
function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
-- Determine whether an arbitrary node appears in an entry, function, or
-- procedure call.
function Within_Volatile_Function (Id : Entity_Id) return Boolean;
-- Determine whether an arbitrary entity appears in a volatile function
---------------------------------
-- Is_Protected_Operation_Call --
---------------------------------
function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
Pref : Node_Id;
Subp : Node_Id;
begin
-- A call to a protected operations retains its selected component
-- form as opposed to other prefixed calls that are transformed in
-- expanded names.
if Nkind (Nod) = N_Selected_Component then
Pref := Prefix (Nod);
Subp := Selector_Name (Nod);
return
Pref = Obj_Ref
and then Present (Etype (Pref))
and then Is_Protected_Type (Etype (Pref))
and then Is_Entity_Name (Subp)
and then Present (Entity (Subp))
and then Ekind_In (Entity (Subp), E_Entry,
E_Entry_Family,
E_Function,
E_Procedure);
else
return False;
end if;
end Is_Protected_Operation_Call;
------------------
-- Within_Check --
------------------
function Within_Check (Nod : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a check node
Par := Nod;
while Present (Par) loop
if Nkind (Par) in N_Raise_xxx_Error then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end Within_Check;
----------------------------
-- Within_Subprogram_Call --
----------------------------
function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a function or procedure call
Par := Nod;
while Present (Par) loop
if Nkind_In (Par, N_Entry_Call_Statement,
N_Function_Call,
N_Procedure_Call_Statement)
then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end Within_Subprogram_Call;
------------------------------
-- Within_Volatile_Function --
------------------------------
function Within_Volatile_Function (Id : Entity_Id) return Boolean is
Func_Id : Entity_Id;
begin
-- Traverse the scope stack looking for a [generic] function
Func_Id := Id;
while Present (Func_Id) and then Func_Id /= Standard_Standard loop
if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
return Is_Volatile_Function (Func_Id);
end if;
Func_Id := Scope (Func_Id);
end loop;
return False;
end Within_Volatile_Function;
-- Local variables
Obj_Id : Entity_Id;
-- Start of processing for Is_OK_Volatile_Context
begin
-- The volatile object appears on either side of an assignment
if Nkind (Context) = N_Assignment_Statement then
return True;
-- The volatile object is part of the initialization expression of
-- another object.
elsif Nkind (Context) = N_Object_Declaration
and then Present (Expression (Context))
and then Expression (Context) = Obj_Ref
then
Obj_Id := Defining_Entity (Context);
-- The volatile object acts as the initialization expression of an
-- extended return statement. This is valid context as long as the
-- function is volatile.
if Is_Return_Object (Obj_Id) then
return Within_Volatile_Function (Obj_Id);
-- Otherwise this is a normal object initialization
else
return True;
end if;
-- The volatile object acts as the name of a renaming declaration
elsif Nkind (Context) = N_Object_Renaming_Declaration
and then Name (Context) = Obj_Ref
then
return True;
-- The volatile object appears as an actual parameter in a call to an
-- instance of Unchecked_Conversion whose result is renamed.
elsif Nkind (Context) = N_Function_Call
and then Is_Entity_Name (Name (Context))
and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
then
return True;
-- The volatile object is actually the prefix in a protected entry,
-- function, or procedure call.
elsif Is_Protected_Operation_Call (Context) then
return True;
-- The volatile object appears as the expression of a simple return
-- statement that applies to a volatile function.
elsif Nkind (Context) = N_Simple_Return_Statement
and then Expression (Context) = Obj_Ref
then
return
Within_Volatile_Function (Return_Statement_Entity (Context));
-- The volatile object appears as the prefix of a name occurring in a
-- non-interfering context.
elsif Nkind_In (Context, N_Attribute_Reference,
N_Explicit_Dereference,
N_Indexed_Component,
N_Selected_Component,
N_Slice)
and then Prefix (Context) = Obj_Ref
and then Is_OK_Volatile_Context
(Context => Parent (Context),
Obj_Ref => Context)
then
return True;
-- The volatile object appears as the prefix of attributes Address,
-- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
-- Storage_Size.
elsif Nkind (Context) = N_Attribute_Reference
and then Prefix (Context) = Obj_Ref
and then Nam_In (Attribute_Name (Context), Name_Address,
Name_Alignment,
Name_Component_Size,
Name_First_Bit,
Name_Last_Bit,
Name_Position,
Name_Size,
Name_Storage_Size)
then
return True;
-- The volatile object appears as the expression of a type conversion
-- occurring in a non-interfering context.
elsif Nkind_In (Context, N_Type_Conversion,
N_Unchecked_Type_Conversion)
and then Expression (Context) = Obj_Ref
and then Is_OK_Volatile_Context
(Context => Parent (Context),
Obj_Ref => Context)
then
return True;
-- The volatile object appears as the expression in a delay statement
elsif Nkind (Context) in N_Delay_Statement then
return True;
-- Allow references to volatile objects in various checks. This is not a
-- direct SPARK 2014 requirement.
elsif Within_Check (Context) then
return True;
-- Assume that references to effectively volatile objects that appear
-- as actual parameters in a subprogram call are always legal. A full
-- legality check is done when the actuals are resolved (see routine
-- Resolve_Actuals).
elsif Within_Subprogram_Call (Context) then
return True;
-- Otherwise the context is not suitable for an effectively volatile
-- object.
else
return False;
end if;
end Is_OK_Volatile_Context;
------------------------------------
-- Is_Package_Contract_Annotation --
------------------------------------
function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
Nam : Name_Id;
begin
if Nkind (Item) = N_Aspect_Specification then
Nam := Chars (Identifier (Item));
else pragma Assert (Nkind (Item) = N_Pragma);
Nam := Pragma_Name (Item);
end if;
return Nam = Name_Abstract_State
or else Nam = Name_Initial_Condition
or else Nam = Name_Initializes
or else Nam = Name_Refined_State;
end Is_Package_Contract_Annotation;
-----------------------------------
-- Is_Partially_Initialized_Type --
-----------------------------------
function Is_Partially_Initialized_Type
(Typ : Entity_Id;
Include_Implicit : Boolean := True) return Boolean
is
begin
if Is_Scalar_Type (Typ) then
return False;
elsif Is_Access_Type (Typ) then
return Include_Implicit;
elsif Is_Array_Type (Typ) then
-- If component type is partially initialized, so is array type
if Is_Partially_Initialized_Type
(Component_Type (Typ), Include_Implicit)
then
return True;
-- Otherwise we are only partially initialized if we are fully
-- initialized (this is the empty array case, no point in us
-- duplicating that code here).
else
return Is_Fully_Initialized_Type (Typ);
end if;
elsif Is_Record_Type (Typ) then
-- A discriminated type is always partially initialized if in
-- all mode
if Has_Discriminants (Typ) and then Include_Implicit then
return True;
-- A tagged type is always partially initialized
elsif Is_Tagged_Type (Typ) then
return True;
-- Case of non-discriminated record
else
declare
Ent : Entity_Id;
Component_Present : Boolean := False;
-- Set True if at least one component is present. If no
-- components are present, then record type is fully
-- initialized (another odd case, like the null array).
begin
-- Loop through components
Ent := First_Entity (Typ);
while Present (Ent) loop
if Ekind (Ent) = E_Component then
Component_Present := True;
-- If a component has an initialization expression then
-- the enclosing record type is partially initialized
if Present (Parent (Ent))
and then Present (Expression (Parent (Ent)))
then
return True;
-- If a component is of a type which is itself partially
-- initialized, then the enclosing record type is also.
elsif Is_Partially_Initialized_Type
(Etype (Ent), Include_Implicit)
then
return True;
end if;
end if;
Next_Entity (Ent);
end loop;
-- No initialized components found. If we found any components
-- they were all uninitialized so the result is false.
if Component_Present then
return False;
-- But if we found no components, then all the components are
-- initialized so we consider the type to be initialized.
else
return True;
end if;
end;
end if;
-- Concurrent types are always fully initialized
elsif Is_Concurrent_Type (Typ) then
return True;
-- For a private type, go to underlying type. If there is no underlying
-- type then just assume this partially initialized. Not clear if this
-- can happen in a non-error case, but no harm in testing for this.
elsif Is_Private_Type (Typ) then
declare
U : constant Entity_Id := Underlying_Type (Typ);
begin
if No (U) then
return True;
else
return Is_Partially_Initialized_Type (U, Include_Implicit);
end if;
end;
-- For any other type (are there any?) assume partially initialized
else
return True;
end if;
end Is_Partially_Initialized_Type;
------------------------------------
-- Is_Potentially_Persistent_Type --
------------------------------------
function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
Comp : Entity_Id;
Indx : Node_Id;
begin
-- For private type, test corresponding full type
if Is_Private_Type (T) then
return Is_Potentially_Persistent_Type (Full_View (T));
-- Scalar types are potentially persistent
elsif Is_Scalar_Type (T) then
return True;
-- Record type is potentially persistent if not tagged and the types of
-- all it components are potentially persistent, and no component has
-- an initialization expression.
elsif Is_Record_Type (T)
and then not Is_Tagged_Type (T)
and then not Is_Partially_Initialized_Type (T)
then
Comp := First_Component (T);
while Present (Comp) loop
if not Is_Potentially_Persistent_Type (Etype (Comp)) then
return False;
else
Next_Entity (Comp);
end if;
end loop;
return True;
-- Array type is potentially persistent if its component type is
-- potentially persistent and if all its constraints are static.
elsif Is_Array_Type (T) then
if not Is_Potentially_Persistent_Type (Component_Type (T)) then
return False;
end if;
Indx := First_Index (T);
while Present (Indx) loop
if not Is_OK_Static_Subtype (Etype (Indx)) then
return False;
else
Next_Index (Indx);
end if;
end loop;
return True;
-- All other types are not potentially persistent
else
return False;
end if;
end Is_Potentially_Persistent_Type;
--------------------------------
-- Is_Potentially_Unevaluated --
--------------------------------
function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
Par : Node_Id;
Expr : Node_Id;
begin
Expr := N;
Par := Parent (N);
-- A postcondition whose expression is a short-circuit is broken down
-- into individual aspects for better exception reporting. The original
-- short-circuit expression is rewritten as the second operand, and an
-- occurrence of 'Old in that operand is potentially unevaluated.
-- See Sem_ch13.adb for details of this transformation.
if Nkind (Original_Node (Par)) = N_And_Then then
return True;
end if;
while not Nkind_In (Par, N_If_Expression,
N_Case_Expression,
N_And_Then,
N_Or_Else,
N_In,
N_Not_In)
loop
Expr := Par;
Par := Parent (Par);
-- If the context is not an expression, or if is the result of
-- expansion of an enclosing construct (such as another attribute)
-- the predicate does not apply.
if Nkind (Par) not in N_Subexpr
or else not Comes_From_Source (Par)
then
return False;
end if;
end loop;
if Nkind (Par) = N_If_Expression then
return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
elsif Nkind (Par) = N_Case_Expression then
return Expr /= Expression (Par);
elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
return Expr = Right_Opnd (Par);
elsif Nkind_In (Par, N_In, N_Not_In) then
return Expr /= Left_Opnd (Par);
else
return False;
end if;
end Is_Potentially_Unevaluated;
---------------------------------
-- Is_Protected_Self_Reference --
---------------------------------
function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
function In_Access_Definition (N : Node_Id) return Boolean;
-- Returns true if N belongs to an access definition
--------------------------
-- In_Access_Definition --
--------------------------
function In_Access_Definition (N : Node_Id) return Boolean is
P : Node_Id;
begin
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_Access_Definition then
return True;
end if;
P := Parent (P);
end loop;
return False;
end In_Access_Definition;
-- Start of processing for Is_Protected_Self_Reference
begin
-- Verify that prefix is analyzed and has the proper form. Note that
-- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
-- produce the address of an entity, do not analyze their prefix
-- because they denote entities that are not necessarily visible.
-- Neither of them can apply to a protected type.
return Ada_Version >= Ada_2005
and then Is_Entity_Name (N)
and then Present (Entity (N))
and then Is_Protected_Type (Entity (N))
and then In_Open_Scopes (Entity (N))
and then not In_Access_Definition (N);
end Is_Protected_Self_Reference;
-----------------------------
-- Is_RCI_Pkg_Spec_Or_Body --
-----------------------------
function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
-- Return True if the unit of Cunit is an RCI package declaration
---------------------------
-- Is_RCI_Pkg_Decl_Cunit --
---------------------------
function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
The_Unit : constant Node_Id := Unit (Cunit);
begin
if Nkind (The_Unit) /= N_Package_Declaration then
return False;
end if;
return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
end Is_RCI_Pkg_Decl_Cunit;
-- Start of processing for Is_RCI_Pkg_Spec_Or_Body
begin
return Is_RCI_Pkg_Decl_Cunit (Cunit)
or else
(Nkind (Unit (Cunit)) = N_Package_Body
and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
end Is_RCI_Pkg_Spec_Or_Body;
-----------------------------------------
-- Is_Remote_Access_To_Class_Wide_Type --
-----------------------------------------
function Is_Remote_Access_To_Class_Wide_Type
(E : Entity_Id) return Boolean
is
begin
-- A remote access to class-wide type is a general access to object type
-- declared in the visible part of a Remote_Types or Remote_Call_
-- Interface unit.
return Ekind (E) = E_General_Access_Type
and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
end Is_Remote_Access_To_Class_Wide_Type;
-----------------------------------------
-- Is_Remote_Access_To_Subprogram_Type --
-----------------------------------------
function Is_Remote_Access_To_Subprogram_Type
(E : Entity_Id) return Boolean
is
begin
return (Ekind (E) = E_Access_Subprogram_Type
or else (Ekind (E) = E_Record_Type
and then Present (Corresponding_Remote_Type (E))))
and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
end Is_Remote_Access_To_Subprogram_Type;
--------------------
-- Is_Remote_Call --
--------------------
function Is_Remote_Call (N : Node_Id) return Boolean is
begin
if Nkind (N) not in N_Subprogram_Call then
-- An entry call cannot be remote
return False;
elsif Nkind (Name (N)) in N_Has_Entity
and then Is_Remote_Call_Interface (Entity (Name (N)))
then
-- A subprogram declared in the spec of a RCI package is remote
return True;
elsif Nkind (Name (N)) = N_Explicit_Dereference
and then Is_Remote_Access_To_Subprogram_Type
(Etype (Prefix (Name (N))))
then
-- The dereference of a RAS is a remote call
return True;
elsif Present (Controlling_Argument (N))
and then Is_Remote_Access_To_Class_Wide_Type
(Etype (Controlling_Argument (N)))
then
-- Any primitive operation call with a controlling argument of
-- a RACW type is a remote call.
return True;
end if;
-- All other calls are local calls
return False;
end Is_Remote_Call;
----------------------
-- Is_Renamed_Entry --
----------------------
function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
Orig_Node : Node_Id := Empty;
Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
function Is_Entry (Nam : Node_Id) return Boolean;
-- Determine whether Nam is an entry. Traverse selectors if there are
-- nested selected components.
--------------
-- Is_Entry --
--------------
function Is_Entry (Nam : Node_Id) return Boolean is
begin
if Nkind (Nam) = N_Selected_Component then
return Is_Entry (Selector_Name (Nam));
end if;
return Ekind (Entity (Nam)) = E_Entry;
end Is_Entry;
-- Start of processing for Is_Renamed_Entry
begin
if Present (Alias (Proc_Nam)) then
Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
end if;
-- Look for a rewritten subprogram renaming declaration
if Nkind (Subp_Decl) = N_Subprogram_Declaration
and then Present (Original_Node (Subp_Decl))
then
Orig_Node := Original_Node (Subp_Decl);
end if;
-- The rewritten subprogram is actually an entry
if Present (Orig_Node)
and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
and then Is_Entry (Name (Orig_Node))
then
return True;
end if;
return False;
end Is_Renamed_Entry;
-----------------------------
-- Is_Renaming_Declaration --
-----------------------------
function Is_Renaming_Declaration (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Exception_Renaming_Declaration
| N_Generic_Function_Renaming_Declaration
| N_Generic_Package_Renaming_Declaration
| N_Generic_Procedure_Renaming_Declaration
| N_Object_Renaming_Declaration
| N_Package_Renaming_Declaration
| N_Subprogram_Renaming_Declaration
=>
return True;
when others =>
return False;
end case;
end Is_Renaming_Declaration;
----------------------------
-- Is_Reversible_Iterator --
----------------------------
function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
Ifaces_List : Elist_Id;
Iface_Elmt : Elmt_Id;
Iface : Entity_Id;
begin
if Is_Class_Wide_Type (Typ)
and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
and then Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
then
return True;
elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
return False;
else
Collect_Interfaces (Typ, Ifaces_List);
Iface_Elmt := First_Elmt (Ifaces_List);
while Present (Iface_Elmt) loop
Iface := Node (Iface_Elmt);
if Chars (Iface) = Name_Reversible_Iterator
and then
Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Iface)))
then
return True;
end if;
Next_Elmt (Iface_Elmt);
end loop;
end if;
return False;
end Is_Reversible_Iterator;
----------------------
-- Is_Selector_Name --
----------------------
function Is_Selector_Name (N : Node_Id) return Boolean is
begin
if not Is_List_Member (N) then
declare
P : constant Node_Id := Parent (N);
begin
return Nkind_In (P, N_Expanded_Name,
N_Generic_Association,
N_Parameter_Association,
N_Selected_Component)
and then Selector_Name (P) = N;
end;
else
declare
L : constant List_Id := List_Containing (N);
P : constant Node_Id := Parent (L);
begin
return (Nkind (P) = N_Discriminant_Association
and then Selector_Names (P) = L)
or else
(Nkind (P) = N_Component_Association
and then Choices (P) = L);
end;
end if;
end Is_Selector_Name;
---------------------------------
-- Is_Single_Concurrent_Object --
---------------------------------
function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
begin
return
Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
end Is_Single_Concurrent_Object;
-------------------------------
-- Is_Single_Concurrent_Type --
-------------------------------
function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
begin
return
Ekind_In (Id, E_Protected_Type, E_Task_Type)
and then Is_Single_Concurrent_Type_Declaration
(Declaration_Node (Id));
end Is_Single_Concurrent_Type;
-------------------------------------------
-- Is_Single_Concurrent_Type_Declaration --
-------------------------------------------
function Is_Single_Concurrent_Type_Declaration
(N : Node_Id) return Boolean
is
begin
return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
N_Single_Task_Declaration);
end Is_Single_Concurrent_Type_Declaration;
---------------------------------------------
-- Is_Single_Precision_Floating_Point_Type --
---------------------------------------------
function Is_Single_Precision_Floating_Point_Type
(E : Entity_Id) return Boolean is
begin
return Is_Floating_Point_Type (E)
and then Machine_Radix_Value (E) = Uint_2
and then Machine_Mantissa_Value (E) = Uint_24
and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
end Is_Single_Precision_Floating_Point_Type;
--------------------------------
-- Is_Single_Protected_Object --
--------------------------------
function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
begin
return
Ekind (Id) = E_Variable
and then Ekind (Etype (Id)) = E_Protected_Type
and then Is_Single_Concurrent_Type (Etype (Id));
end Is_Single_Protected_Object;
---------------------------
-- Is_Single_Task_Object --
---------------------------
function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
begin
return
Ekind (Id) = E_Variable
and then Ekind (Etype (Id)) = E_Task_Type
and then Is_Single_Concurrent_Type (Etype (Id));
end Is_Single_Task_Object;
-------------------------------------
-- Is_SPARK_05_Initialization_Expr --
-------------------------------------
function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
Is_Ok : Boolean;
Expr : Node_Id;
Comp_Assn : Node_Id;
Orig_N : constant Node_Id := Original_Node (N);
begin
Is_Ok := True;
if not Comes_From_Source (Orig_N) then
goto Done;
end if;
pragma Assert (Nkind (Orig_N) in N_Subexpr);
case Nkind (Orig_N) is
when N_Character_Literal
| N_Integer_Literal
| N_Real_Literal
| N_String_Literal
=>
null;
when N_Expanded_Name
| N_Identifier
=>
if Is_Entity_Name (Orig_N)
and then Present (Entity (Orig_N)) -- needed in some cases
then
case Ekind (Entity (Orig_N)) is
when E_Constant
| E_Enumeration_Literal
| E_Named_Integer
| E_Named_Real
=>
null;
when others =>
if Is_Type (Entity (Orig_N)) then
null;
else
Is_Ok := False;
end if;
end case;
end if;
when N_Qualified_Expression
| N_Type_Conversion
=>
Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
when N_Unary_Op =>
Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
when N_Binary_Op
| N_Membership_Test
| N_Short_Circuit
=>
Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
and then
Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
when N_Aggregate
| N_Extension_Aggregate
=>
if Nkind (Orig_N) = N_Extension_Aggregate then
Is_Ok :=
Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
end if;
Expr := First (Expressions (Orig_N));
while Present (Expr) loop
if not Is_SPARK_05_Initialization_Expr (Expr) then
Is_Ok := False;
goto Done;
end if;
Next (Expr);
end loop;
Comp_Assn := First (Component_Associations (Orig_N));
while Present (Comp_Assn) loop
Expr := Expression (Comp_Assn);
-- Note: test for Present here needed for box assocation
if Present (Expr)
and then not Is_SPARK_05_Initialization_Expr (Expr)
then
Is_Ok := False;
goto Done;
end if;
Next (Comp_Assn);
end loop;
when N_Attribute_Reference =>
if Nkind (Prefix (Orig_N)) in N_Subexpr then
Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
end if;
Expr := First (Expressions (Orig_N));
while Present (Expr) loop
if not Is_SPARK_05_Initialization_Expr (Expr) then
Is_Ok := False;
goto Done;
end if;
Next (Expr);
end loop;
-- Selected components might be expanded named not yet resolved, so
-- default on the safe side. (Eg on sparklex.ads)
when N_Selected_Component =>
null;
when others =>
Is_Ok := False;
end case;
<<Done>>
return Is_Ok;
end Is_SPARK_05_Initialization_Expr;
----------------------------------
-- Is_SPARK_05_Object_Reference --
----------------------------------
function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
begin
if Is_Entity_Name (N) then
return Present (Entity (N))
and then
(Ekind_In (Entity (N), E_Constant, E_Variable)
or else Ekind (Entity (N)) in Formal_Kind);
else
case Nkind (N) is
when N_Selected_Component =>
return Is_SPARK_05_Object_Reference (Prefix (N));
when others =>
return False;
end case;
end if;
end Is_SPARK_05_Object_Reference;
-----------------------------
-- Is_Specific_Tagged_Type --
-----------------------------
function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
Full_Typ : Entity_Id;
begin
-- Handle private types
if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
Full_Typ := Full_View (Typ);
else
Full_Typ := Typ;
end if;
-- A specific tagged type is a non-class-wide tagged type
return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
end Is_Specific_Tagged_Type;
------------------
-- Is_Statement --
------------------
function Is_Statement (N : Node_Id) return Boolean is
begin
return
Nkind (N) in N_Statement_Other_Than_Procedure_Call
or else Nkind (N) = N_Procedure_Call_Statement;
end Is_Statement;
---------------------------------------
-- Is_Subprogram_Contract_Annotation --
---------------------------------------
function Is_Subprogram_Contract_Annotation
(Item : Node_Id) return Boolean
is
Nam : Name_Id;
begin
if Nkind (Item) = N_Aspect_Specification then
Nam := Chars (Identifier (Item));
else pragma Assert (Nkind (Item) = N_Pragma);
Nam := Pragma_Name (Item);
end if;
return Nam = Name_Contract_Cases
or else Nam = Name_Depends
or else Nam = Name_Extensions_Visible
or else Nam = Name_Global
or else Nam = Name_Post
or else Nam = Name_Post_Class
or else Nam = Name_Postcondition
or else Nam = Name_Pre
or else Nam = Name_Pre_Class
or else Nam = Name_Precondition
or else Nam = Name_Refined_Depends
or else Nam = Name_Refined_Global
or else Nam = Name_Refined_Post
or else Nam = Name_Test_Case;
end Is_Subprogram_Contract_Annotation;
--------------------------------------------------
-- Is_Subprogram_Stub_Without_Prior_Declaration --
--------------------------------------------------
function Is_Subprogram_Stub_Without_Prior_Declaration
(N : Node_Id) return Boolean
is
begin
-- A subprogram stub without prior declaration serves as declaration for
-- the actual subprogram body. As such, it has an attached defining
-- entity of E_[Generic_]Function or E_[Generic_]Procedure.
return Nkind (N) = N_Subprogram_Body_Stub
and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
end Is_Subprogram_Stub_Without_Prior_Declaration;
--------------------------
-- Is_Suspension_Object --
--------------------------
function Is_Suspension_Object (Id : Entity_Id) return Boolean is
begin
-- This approach does an exact name match rather than to rely on
-- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
-- front end at point where all auxiliary tables are locked and any
-- modifications to them are treated as violations. Do not tamper with
-- the tables, instead examine the Chars fields of all the scopes of Id.
return
Chars (Id) = Name_Suspension_Object
and then Present (Scope (Id))
and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
and then Present (Scope (Scope (Id)))
and then Chars (Scope (Scope (Id))) = Name_Ada
and then Present (Scope (Scope (Scope (Id))))
and then Scope (Scope (Scope (Id))) = Standard_Standard;
end Is_Suspension_Object;
----------------------------
-- Is_Synchronized_Object --
----------------------------
function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
Prag : Node_Id;
begin
if Is_Object (Id) then
-- The object is synchronized if it is of a type that yields a
-- synchronized object.
if Yields_Synchronized_Object (Etype (Id)) then
return True;
-- The object is synchronized if it is atomic and Async_Writers is
-- enabled.
elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
return True;
-- A constant is a synchronized object by default
elsif Ekind (Id) = E_Constant then
return True;
-- A variable is a synchronized object if it is subject to pragma
-- Constant_After_Elaboration.
elsif Ekind (Id) = E_Variable then
Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
return Present (Prag) and then Is_Enabled_Pragma (Prag);
end if;
end if;
-- Otherwise the input is not an object or it does not qualify as a
-- synchronized object.
return False;
end Is_Synchronized_Object;
---------------------------------
-- Is_Synchronized_Tagged_Type --
---------------------------------
function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
Kind : constant Entity_Kind := Ekind (Base_Type (E));
begin
-- A task or protected type derived from an interface is a tagged type.
-- Such a tagged type is called a synchronized tagged type, as are
-- synchronized interfaces and private extensions whose declaration
-- includes the reserved word synchronized.
return (Is_Tagged_Type (E)
and then (Kind = E_Task_Type
or else
Kind = E_Protected_Type))
or else
(Is_Interface (E)
and then Is_Synchronized_Interface (E))
or else
(Ekind (E) = E_Record_Type_With_Private
and then Nkind (Parent (E)) = N_Private_Extension_Declaration
and then (Synchronized_Present (Parent (E))
or else Is_Synchronized_Interface (Etype (E))));
end Is_Synchronized_Tagged_Type;
-----------------
-- Is_Transfer --
-----------------
function Is_Transfer (N : Node_Id) return Boolean is
Kind : constant Node_Kind := Nkind (N);
begin
if Kind = N_Simple_Return_Statement
or else
Kind = N_Extended_Return_Statement
or else
Kind = N_Goto_Statement
or else
Kind = N_Raise_Statement
or else
Kind = N_Requeue_Statement
then
return True;
elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
and then No (Condition (N))
then
return True;
elsif Kind = N_Procedure_Call_Statement
and then Is_Entity_Name (Name (N))
and then Present (Entity (Name (N)))
and then No_Return (Entity (Name (N)))
then
return True;
elsif Nkind (Original_Node (N)) = N_Raise_Statement then
return True;
else
return False;
end if;
end Is_Transfer;
-------------
-- Is_True --
-------------
function Is_True (U : Uint) return Boolean is
begin
return (U /= 0);
end Is_True;
--------------------------------------
-- Is_Unchecked_Conversion_Instance --
--------------------------------------
function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
Par : Node_Id;
begin
-- Look for a function whose generic parent is the predefined intrinsic
-- function Unchecked_Conversion, or for one that renames such an
-- instance.
if Ekind (Id) = E_Function then
Par := Parent (Id);
if Nkind (Par) = N_Function_Specification then
Par := Generic_Parent (Par);
if Present (Par) then
return
Chars (Par) = Name_Unchecked_Conversion
and then Is_Intrinsic_Subprogram (Par)
and then Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Par)));
else
return
Present (Alias (Id))
and then Is_Unchecked_Conversion_Instance (Alias (Id));
end if;
end if;
end if;
return False;
end Is_Unchecked_Conversion_Instance;
-------------------------------
-- Is_Universal_Numeric_Type --
-------------------------------
function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
begin
return T = Universal_Integer or else T = Universal_Real;
end Is_Universal_Numeric_Type;
----------------------------
-- Is_Variable_Size_Array --
----------------------------
function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
Idx : Node_Id;
begin
pragma Assert (Is_Array_Type (E));
-- Check if some index is initialized with a non-constant value
Idx := First_Index (E);
while Present (Idx) loop
if Nkind (Idx) = N_Range then
if not Is_Constant_Bound (Low_Bound (Idx))
or else not Is_Constant_Bound (High_Bound (Idx))
then
return True;
end if;
end if;
Idx := Next_Index (Idx);
end loop;
return False;
end Is_Variable_Size_Array;
-----------------------------
-- Is_Variable_Size_Record --
-----------------------------
function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
Comp : Entity_Id;
Comp_Typ : Entity_Id;
begin
pragma Assert (Is_Record_Type (E));
Comp := First_Entity (E);
while Present (Comp) loop
Comp_Typ := Etype (Comp);
-- Recursive call if the record type has discriminants
if Is_Record_Type (Comp_Typ)
and then Has_Discriminants (Comp_Typ)
and then Is_Variable_Size_Record (Comp_Typ)
then
return True;
elsif Is_Array_Type (Comp_Typ)
and then Is_Variable_Size_Array (Comp_Typ)
then
return True;
end if;
Next_Entity (Comp);
end loop;
return False;
end Is_Variable_Size_Record;
-----------------
-- Is_Variable --
-----------------
function Is_Variable
(N : Node_Id;
Use_Original_Node : Boolean := True) return Boolean
is
Orig_Node : Node_Id;
function In_Protected_Function (E : Entity_Id) return Boolean;
-- Within a protected function, the private components of the enclosing
-- protected type are constants. A function nested within a (protected)
-- procedure is not itself protected. Within the body of a protected
-- function the current instance of the protected type is a constant.
function Is_Variable_Prefix (P : Node_Id) return Boolean;
-- Prefixes can involve implicit dereferences, in which case we must
-- test for the case of a reference of a constant access type, which can
-- can never be a variable.
---------------------------
-- In_Protected_Function --
---------------------------
function In_Protected_Function (E : Entity_Id) return Boolean is
Prot : Entity_Id;
S : Entity_Id;
begin
-- E is the current instance of a type
if Is_Type (E) then
Prot := E;
-- E is an object
else
Prot := Scope (E);
end if;
if not Is_Protected_Type (Prot) then
return False;
else
S := Current_Scope;
while Present (S) and then S /= Prot loop
if Ekind (S) = E_Function and then Scope (S) = Prot then
return True;
end if;
S := Scope (S);
end loop;
return False;
end if;
end In_Protected_Function;
------------------------
-- Is_Variable_Prefix --
------------------------
function Is_Variable_Prefix (P : Node_Id) return Boolean is
begin
if Is_Access_Type (Etype (P)) then
return not Is_Access_Constant (Root_Type (Etype (P)));
-- For the case of an indexed component whose prefix has a packed
-- array type, the prefix has been rewritten into a type conversion.
-- Determine variable-ness from the converted expression.
elsif Nkind (P) = N_Type_Conversion
and then not Comes_From_Source (P)
and then Is_Array_Type (Etype (P))
and then Is_Packed (Etype (P))
then
return Is_Variable (Expression (P));
else
return Is_Variable (P);
end if;
end Is_Variable_Prefix;
-- Start of processing for Is_Variable
begin
-- Special check, allow x'Deref(expr) as a variable
if Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Deref
then
return True;
end if;
-- Check if we perform the test on the original node since this may be a
-- test of syntactic categories which must not be disturbed by whatever
-- rewriting might have occurred. For example, an aggregate, which is
-- certainly NOT a variable, could be turned into a variable by
-- expansion.
if Use_Original_Node then
Orig_Node := Original_Node (N);
else
Orig_Node := N;
end if;
-- Definitely OK if Assignment_OK is set. Since this is something that
-- only gets set for expanded nodes, the test is on N, not Orig_Node.
if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
return True;
-- Normally we go to the original node, but there is one exception where
-- we use the rewritten node, namely when it is an explicit dereference.
-- The generated code may rewrite a prefix which is an access type with
-- an explicit dereference. The dereference is a variable, even though
-- the original node may not be (since it could be a constant of the
-- access type).
-- In Ada 2005 we have a further case to consider: the prefix may be a
-- function call given in prefix notation. The original node appears to
-- be a selected component, but we need to examine the call.
elsif Nkind (N) = N_Explicit_Dereference
and then Nkind (Orig_Node) /= N_Explicit_Dereference
and then Present (Etype (Orig_Node))
and then Is_Access_Type (Etype (Orig_Node))
then
-- Note that if the prefix is an explicit dereference that does not
-- come from source, we must check for a rewritten function call in
-- prefixed notation before other forms of rewriting, to prevent a
-- compiler crash.
return
(Nkind (Orig_Node) = N_Function_Call
and then not Is_Access_Constant (Etype (Prefix (N))))
or else
Is_Variable_Prefix (Original_Node (Prefix (N)));
-- in Ada 2012, the dereference may have been added for a type with
-- a declared implicit dereference aspect. Check that it is not an
-- access to constant.
elsif Nkind (N) = N_Explicit_Dereference
and then Present (Etype (Orig_Node))
and then Ada_Version >= Ada_2012
and then Has_Implicit_Dereference (Etype (Orig_Node))
then
return not Is_Access_Constant (Etype (Prefix (N)));
-- A function call is never a variable
elsif Nkind (N) = N_Function_Call then
return False;
-- All remaining checks use the original node
elsif Is_Entity_Name (Orig_Node)
and then Present (Entity (Orig_Node))
then
declare
E : constant Entity_Id := Entity (Orig_Node);
K : constant Entity_Kind := Ekind (E);
begin
return (K = E_Variable
and then Nkind (Parent (E)) /= N_Exception_Handler)
or else (K = E_Component
and then not In_Protected_Function (E))
or else K = E_Out_Parameter
or else K = E_In_Out_Parameter
or else K = E_Generic_In_Out_Parameter
-- Current instance of type. If this is a protected type, check
-- we are not within the body of one of its protected functions.
or else (Is_Type (E)
and then In_Open_Scopes (E)
and then not In_Protected_Function (E))
or else (Is_Incomplete_Or_Private_Type (E)
and then In_Open_Scopes (Full_View (E)));
end;
else
case Nkind (Orig_Node) is
when N_Indexed_Component
| N_Slice
=>
return Is_Variable_Prefix (Prefix (Orig_Node));
when N_Selected_Component =>
return (Is_Variable (Selector_Name (Orig_Node))
and then Is_Variable_Prefix (Prefix (Orig_Node)))
or else
(Nkind (N) = N_Expanded_Name
and then Scope (Entity (N)) = Entity (Prefix (N)));
-- For an explicit dereference, the type of the prefix cannot
-- be an access to constant or an access to subprogram.
when N_Explicit_Dereference =>
declare
Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
begin
return Is_Access_Type (Typ)
and then not Is_Access_Constant (Root_Type (Typ))
and then Ekind (Typ) /= E_Access_Subprogram_Type;
end;
-- The type conversion is the case where we do not deal with the
-- context dependent special case of an actual parameter. Thus
-- the type conversion is only considered a variable for the
-- purposes of this routine if the target type is tagged. However,
-- a type conversion is considered to be a variable if it does not
-- come from source (this deals for example with the conversions
-- of expressions to their actual subtypes).
when N_Type_Conversion =>
return Is_Variable (Expression (Orig_Node))
and then
(not Comes_From_Source (Orig_Node)
or else
(Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
and then
Is_Tagged_Type (Etype (Expression (Orig_Node)))));
-- GNAT allows an unchecked type conversion as a variable. This
-- only affects the generation of internal expanded code, since
-- calls to instantiations of Unchecked_Conversion are never
-- considered variables (since they are function calls).
when N_Unchecked_Type_Conversion =>
return Is_Variable (Expression (Orig_Node));
when others =>
return False;
end case;
end if;
end Is_Variable;
------------------------------
-- Is_Verifiable_DIC_Pragma --
------------------------------
function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
Args : constant List_Id := Pragma_Argument_Associations (Prag);
begin
-- To qualify as verifiable, a DIC pragma must have a non-null argument
return
Present (Args)
and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
end Is_Verifiable_DIC_Pragma;
---------------------------
-- Is_Visibly_Controlled --
---------------------------
function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
Root : constant Entity_Id := Root_Type (T);
begin
return Chars (Scope (Root)) = Name_Finalization
and then Chars (Scope (Scope (Root))) = Name_Ada
and then Scope (Scope (Scope (Root))) = Standard_Standard;
end Is_Visibly_Controlled;
--------------------------
-- Is_Volatile_Function --
--------------------------
function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
begin
pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
-- A function declared within a protected type is volatile
if Is_Protected_Type (Scope (Func_Id)) then
return True;
-- An instance of Ada.Unchecked_Conversion is a volatile function if
-- either the source or the target are effectively volatile.
elsif Is_Unchecked_Conversion_Instance (Func_Id)
and then Has_Effectively_Volatile_Profile (Func_Id)
then
return True;
-- Otherwise the function is treated as volatile if it is subject to
-- enabled pragma Volatile_Function.
else
return
Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
end if;
end Is_Volatile_Function;
------------------------
-- Is_Volatile_Object --
------------------------
function Is_Volatile_Object (N : Node_Id) return Boolean is
function Is_Volatile_Prefix (N : Node_Id) return Boolean;
-- If prefix is an implicit dereference, examine designated type
function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
-- Determines if given object has volatile components
------------------------
-- Is_Volatile_Prefix --
------------------------
function Is_Volatile_Prefix (N : Node_Id) return Boolean is
Typ : constant Entity_Id := Etype (N);
begin
if Is_Access_Type (Typ) then
declare
Dtyp : constant Entity_Id := Designated_Type (Typ);
begin
return Is_Volatile (Dtyp)
or else Has_Volatile_Components (Dtyp);
end;
else
return Object_Has_Volatile_Components (N);
end if;
end Is_Volatile_Prefix;
------------------------------------
-- Object_Has_Volatile_Components --
------------------------------------
function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
Typ : constant Entity_Id := Etype (N);
begin
if Is_Volatile (Typ)
or else Has_Volatile_Components (Typ)
then
return True;
elsif Is_Entity_Name (N)
and then (Has_Volatile_Components (Entity (N))
or else Is_Volatile (Entity (N)))
then
return True;
elsif Nkind (N) = N_Indexed_Component
or else Nkind (N) = N_Selected_Component
then
return Is_Volatile_Prefix (Prefix (N));
else
return False;
end if;
end Object_Has_Volatile_Components;
-- Start of processing for Is_Volatile_Object
begin
if Nkind (N) = N_Defining_Identifier then
return Is_Volatile (N) or else Is_Volatile (Etype (N));
elsif Nkind (N) = N_Expanded_Name then
return Is_Volatile_Object (Entity (N));
elsif Is_Volatile (Etype (N))
or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
then
return True;
elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
and then Is_Volatile_Prefix (Prefix (N))
then
return True;
elsif Nkind (N) = N_Selected_Component
and then Is_Volatile (Entity (Selector_Name (N)))
then
return True;
else
return False;
end if;
end Is_Volatile_Object;
---------------------------
-- Itype_Has_Declaration --
---------------------------
function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
begin
pragma Assert (Is_Itype (Id));
return Present (Parent (Id))
and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
N_Subtype_Declaration)
and then Defining_Entity (Parent (Id)) = Id;
end Itype_Has_Declaration;
-------------------------
-- Kill_Current_Values --
-------------------------
procedure Kill_Current_Values
(Ent : Entity_Id;
Last_Assignment_Only : Boolean := False)
is
begin
if Is_Assignable (Ent) then
Set_Last_Assignment (Ent, Empty);
end if;
if Is_Object (Ent) then
if not Last_Assignment_Only then
Kill_Checks (Ent);
Set_Current_Value (Ent, Empty);
-- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
-- for a constant. Once the constant is elaborated, its value is
-- not changed, therefore the associated flags that describe the
-- value should not be modified either.
if Ekind (Ent) = E_Constant then
null;
-- Non-constant entities
else
if not Can_Never_Be_Null (Ent) then
Set_Is_Known_Non_Null (Ent, False);
end if;
Set_Is_Known_Null (Ent, False);
-- Reset the Is_Known_Valid flag unless the type is always
-- valid. This does not apply to a loop parameter because its
-- bounds are defined by the loop header and therefore always
-- valid.
if not Is_Known_Valid (Etype (Ent))
and then Ekind (Ent) /= E_Loop_Parameter
then
Set_Is_Known_Valid (Ent, False);
end if;
end if;
end if;
end if;
end Kill_Current_Values;
procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
S : Entity_Id;
procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
-- Clear current value for entity E and all entities chained to E
------------------------------------------
-- Kill_Current_Values_For_Entity_Chain --
------------------------------------------
procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
Ent : Entity_Id;
begin
Ent := E;
while Present (Ent) loop
Kill_Current_Values (Ent, Last_Assignment_Only);
Next_Entity (Ent);
end loop;
end Kill_Current_Values_For_Entity_Chain;
-- Start of processing for Kill_Current_Values
begin
-- Kill all saved checks, a special case of killing saved values
if not Last_Assignment_Only then
Kill_All_Checks;
end if;
-- Loop through relevant scopes, which includes the current scope and
-- any parent scopes if the current scope is a block or a package.
S := Current_Scope;
Scope_Loop : loop
-- Clear current values of all entities in current scope
Kill_Current_Values_For_Entity_Chain (First_Entity (S));
-- If scope is a package, also clear current values of all private
-- entities in the scope.
if Is_Package_Or_Generic_Package (S)
or else Is_Concurrent_Type (S)
then
Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
end if;
-- If this is a not a subprogram, deal with parents
if not Is_Subprogram (S) then
S := Scope (S);
exit Scope_Loop when S = Standard_Standard;
else
exit Scope_Loop;
end if;
end loop Scope_Loop;
end Kill_Current_Values;
--------------------------
-- Kill_Size_Check_Code --
--------------------------
procedure Kill_Size_Check_Code (E : Entity_Id) is
begin
if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
and then Present (Size_Check_Code (E))
then
Remove (Size_Check_Code (E));
Set_Size_Check_Code (E, Empty);
end if;
end Kill_Size_Check_Code;
--------------------------
-- Known_To_Be_Assigned --
--------------------------
function Known_To_Be_Assigned (N : Node_Id) return Boolean is
P : constant Node_Id := Parent (N);
begin
case Nkind (P) is
-- Test left side of assignment
when N_Assignment_Statement =>
return N = Name (P);
-- Function call arguments are never lvalues
when N_Function_Call =>
return False;
-- Positional parameter for procedure or accept call
when N_Accept_Statement
| N_Procedure_Call_Statement
=>
declare
Proc : Entity_Id;
Form : Entity_Id;
Act : Node_Id;
begin
Proc := Get_Subprogram_Entity (P);
if No (Proc) then
return False;
end if;
-- If we are not a list member, something is strange, so
-- be conservative and return False.
if not Is_List_Member (N) then
return False;
end if;
-- We are going to find the right formal by stepping forward
-- through the formals, as we step backwards in the actuals.
Form := First_Formal (Proc);
Act := N;
loop
-- If no formal, something is weird, so be conservative
-- and return False.
if No (Form) then
return False;
end if;
Prev (Act);
exit when No (Act);
Next_Formal (Form);
end loop;
return Ekind (Form) /= E_In_Parameter;
end;
-- Named parameter for procedure or accept call
when N_Parameter_Association =>
declare
Proc : Entity_Id;
Form : Entity_Id;
begin
Proc := Get_Subprogram_Entity (Parent (P));
if No (Proc) then
return False;
end if;
-- Loop through formals to find the one that matches
Form := First_Formal (Proc);
loop
-- If no matching formal, that's peculiar, some kind of
-- previous error, so return False to be conservative.
-- Actually this also happens in legal code in the case
-- where P is a parameter association for an Extra_Formal???
if No (Form) then
return False;
end if;
-- Else test for match
if Chars (Form) = Chars (Selector_Name (P)) then
return Ekind (Form) /= E_In_Parameter;
end if;
Next_Formal (Form);
end loop;
end;
-- Test for appearing in a conversion that itself appears
-- in an lvalue context, since this should be an lvalue.
when N_Type_Conversion =>
return Known_To_Be_Assigned (P);
-- All other references are definitely not known to be modifications
when others =>
return False;
end case;
end Known_To_Be_Assigned;
---------------------------
-- Last_Source_Statement --
---------------------------
function Last_Source_Statement (HSS : Node_Id) return Node_Id is
N : Node_Id;
begin
N := Last (Statements (HSS));
while Present (N) loop
exit when Comes_From_Source (N);
Prev (N);
end loop;
return N;
end Last_Source_Statement;
----------------------------------
-- Matching_Static_Array_Bounds --
----------------------------------
function Matching_Static_Array_Bounds
(L_Typ : Node_Id;
R_Typ : Node_Id) return Boolean
is
L_Ndims : constant Nat := Number_Dimensions (L_Typ);
R_Ndims : constant Nat := Number_Dimensions (R_Typ);
L_Index : Node_Id;
R_Index : Node_Id;
L_Low : Node_Id;
L_High : Node_Id;
L_Len : Uint;
R_Low : Node_Id;
R_High : Node_Id;
R_Len : Uint;
begin
if L_Ndims /= R_Ndims then
return False;
end if;
-- Unconstrained types do not have static bounds
if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
return False;
end if;
-- First treat specially the first dimension, as the lower bound and
-- length of string literals are not stored like those of arrays.
if Ekind (L_Typ) = E_String_Literal_Subtype then
L_Low := String_Literal_Low_Bound (L_Typ);
L_Len := String_Literal_Length (L_Typ);
else
L_Index := First_Index (L_Typ);
Get_Index_Bounds (L_Index, L_Low, L_High);
if Is_OK_Static_Expression (L_Low)
and then
Is_OK_Static_Expression (L_High)
then
if Expr_Value (L_High) < Expr_Value (L_Low) then
L_Len := Uint_0;
else
L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
end if;
else
return False;
end if;
end if;
if Ekind (R_Typ) = E_String_Literal_Subtype then
R_Low := String_Literal_Low_Bound (R_Typ);
R_Len := String_Literal_Length (R_Typ);
else
R_Index := First_Index (R_Typ);
Get_Index_Bounds (R_Index, R_Low, R_High);
if Is_OK_Static_Expression (R_Low)
and then
Is_OK_Static_Expression (R_High)
then
if Expr_Value (R_High) < Expr_Value (R_Low) then
R_Len := Uint_0;
else
R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
end if;
else
return False;
end if;
end if;
if (Is_OK_Static_Expression (L_Low)
and then
Is_OK_Static_Expression (R_Low))
and then Expr_Value (L_Low) = Expr_Value (R_Low)
and then L_Len = R_Len
then
null;
else
return False;
end if;
-- Then treat all other dimensions
for Indx in 2 .. L_Ndims loop
Next (L_Index);
Next (R_Index);
Get_Index_Bounds (L_Index, L_Low, L_High);
Get_Index_Bounds (R_Index, R_Low, R_High);
if (Is_OK_Static_Expression (L_Low) and then
Is_OK_Static_Expression (L_High) and then
Is_OK_Static_Expression (R_Low) and then
Is_OK_Static_Expression (R_High))
and then (Expr_Value (L_Low) = Expr_Value (R_Low)
and then
Expr_Value (L_High) = Expr_Value (R_High))
then
null;
else
return False;
end if;
end loop;
-- If we fall through the loop, all indexes matched
return True;
end Matching_Static_Array_Bounds;
-------------------
-- May_Be_Lvalue --
-------------------
function May_Be_Lvalue (N : Node_Id) return Boolean is
P : constant Node_Id := Parent (N);
begin
case Nkind (P) is
-- Test left side of assignment
when N_Assignment_Statement =>
return N = Name (P);
-- Test prefix of component or attribute. Note that the prefix of an
-- explicit or implicit dereference cannot be an l-value. In the case
-- of a 'Read attribute, the reference can be an actual in the
-- argument list of the attribute.
when N_Attribute_Reference =>
return (N = Prefix (P)
and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
or else
Attribute_Name (P) = Name_Read;
-- For an expanded name, the name is an lvalue if the expanded name
-- is an lvalue, but the prefix is never an lvalue, since it is just
-- the scope where the name is found.
when N_Expanded_Name =>
if N = Prefix (P) then
return May_Be_Lvalue (P);
else
return False;
end if;
-- For a selected component A.B, A is certainly an lvalue if A.B is.
-- B is a little interesting, if we have A.B := 3, there is some
-- discussion as to whether B is an lvalue or not, we choose to say
-- it is. Note however that A is not an lvalue if it is of an access
-- type since this is an implicit dereference.
when N_Selected_Component =>
if N = Prefix (P)
and then Present (Etype (N))
and then Is_Access_Type (Etype (N))
then
return False;
else
return May_Be_Lvalue (P);
end if;
-- For an indexed component or slice, the index or slice bounds is
-- never an lvalue. The prefix is an lvalue if the indexed component
-- or slice is an lvalue, except if it is an access type, where we
-- have an implicit dereference.
when N_Indexed_Component
| N_Slice
=>
if N /= Prefix (P)
or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
then
return False;
else
return May_Be_Lvalue (P);
end if;
-- Prefix of a reference is an lvalue if the reference is an lvalue
when N_Reference =>
return May_Be_Lvalue (P);
-- Prefix of explicit dereference is never an lvalue
when N_Explicit_Dereference =>
return False;
-- Positional parameter for subprogram, entry, or accept call.
-- In older versions of Ada function call arguments are never
-- lvalues. In Ada 2012 functions can have in-out parameters.
when N_Accept_Statement
| N_Entry_Call_Statement
| N_Subprogram_Call
=>
if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
return False;
end if;
-- The following mechanism is clumsy and fragile. A single flag
-- set in Resolve_Actuals would be preferable ???
declare
Proc : Entity_Id;
Form : Entity_Id;
Act : Node_Id;
begin
Proc := Get_Subprogram_Entity (P);
if No (Proc) then
return True;
end if;
-- If we are not a list member, something is strange, so be
-- conservative and return True.
if not Is_List_Member (N) then
return True;
end if;
-- We are going to find the right formal by stepping forward
-- through the formals, as we step backwards in the actuals.
Form := First_Formal (Proc);
Act := N;
loop
-- If no formal, something is weird, so be conservative and
-- return True.
if No (Form) then
return True;
end if;
Prev (Act);
exit when No (Act);
Next_Formal (Form);
end loop;
return Ekind (Form) /= E_In_Parameter;
end;
-- Named parameter for procedure or accept call
when N_Parameter_Association =>
declare
Proc : Entity_Id;
Form : Entity_Id;
begin
Proc := Get_Subprogram_Entity (Parent (P));
if No (Proc) then
return True;
end if;
-- Loop through formals to find the one that matches
Form := First_Formal (Proc);
loop
-- If no matching formal, that's peculiar, some kind of
-- previous error, so return True to be conservative.
-- Actually happens with legal code for an unresolved call
-- where we may get the wrong homonym???
if No (Form) then
return True;
end if;
-- Else test for match
if Chars (Form) = Chars (Selector_Name (P)) then
return Ekind (Form) /= E_In_Parameter;
end if;
Next_Formal (Form);
end loop;
end;
-- Test for appearing in a conversion that itself appears in an
-- lvalue context, since this should be an lvalue.
when N_Type_Conversion =>
return May_Be_Lvalue (P);
-- Test for appearance in object renaming declaration
when N_Object_Renaming_Declaration =>
return True;
-- All other references are definitely not lvalues
when others =>
return False;
end case;
end May_Be_Lvalue;
-----------------------
-- Mark_Coextensions --
-----------------------
procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
Is_Dynamic : Boolean;
-- Indicates whether the context causes nested coextensions to be
-- dynamic or static
function Mark_Allocator (N : Node_Id) return Traverse_Result;
-- Recognize an allocator node and label it as a dynamic coextension
--------------------
-- Mark_Allocator --
--------------------
function Mark_Allocator (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) = N_Allocator then
if Is_Dynamic then
Set_Is_Dynamic_Coextension (N);
-- If the allocator expression is potentially dynamic, it may
-- be expanded out of order and require dynamic allocation
-- anyway, so we treat the coextension itself as dynamic.
-- Potential optimization ???
elsif Nkind (Expression (N)) = N_Qualified_Expression
and then Nkind (Expression (Expression (N))) = N_Op_Concat
then
Set_Is_Dynamic_Coextension (N);
else
Set_Is_Static_Coextension (N);
end if;
end if;
return OK;
end Mark_Allocator;
procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
-- Start of processing for Mark_Coextensions
begin
-- An allocator that appears on the right-hand side of an assignment is
-- treated as a potentially dynamic coextension when the right-hand side
-- is an allocator or a qualified expression.
-- Obj := new ...'(new Coextension ...);
if Nkind (Context_Nod) = N_Assignment_Statement then
Is_Dynamic :=
Nkind_In (Expression (Context_Nod), N_Allocator,
N_Qualified_Expression);
-- An allocator that appears within the expression of a simple return
-- statement is treated as a potentially dynamic coextension when the
-- expression is either aggregate, allocator, or qualified expression.
-- return (new Coextension ...);
-- return new ...'(new Coextension ...);
elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
Is_Dynamic :=
Nkind_In (Expression (Context_Nod), N_Aggregate,
N_Allocator,
N_Qualified_Expression);
-- An allocator that appears within the initialization expression of an
-- object declaration is considered a potentially dynamic coextension
-- when the initialization expression is an allocator or a qualified
-- expression.
-- Obj : ... := new ...'(new Coextension ...);
-- A similar case arises when the object declaration is part of an
-- extended return statement.
-- return Obj : ... := new ...'(new Coextension ...);
-- return Obj : ... := (new Coextension ...);
elsif Nkind (Context_Nod) = N_Object_Declaration then
Is_Dynamic :=
Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
or else
Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
-- This routine should not be called with constructs that cannot contain
-- coextensions.
else
raise Program_Error;
end if;
Mark_Allocators (Root_Nod);
end Mark_Coextensions;
----------------------
-- Needs_One_Actual --
----------------------
function Needs_One_Actual (E : Entity_Id) return Boolean is
Formal : Entity_Id;
begin
-- Ada 2005 or later, and formals present
if Ada_Version >= Ada_2005
and then Present (First_Formal (E))
and then No (Default_Value (First_Formal (E)))
then
Formal := Next_Formal (First_Formal (E));
while Present (Formal) loop
if No (Default_Value (Formal)) then
return False;
end if;
Next_Formal (Formal);
end loop;
return True;
-- Ada 83/95 or no formals
else
return False;
end if;
end Needs_One_Actual;
------------------------
-- New_Copy_List_Tree --
------------------------
function New_Copy_List_Tree (List : List_Id) return List_Id is
NL : List_Id;
E : Node_Id;
begin
if List = No_List then
return No_List;
else
NL := New_List;
E := First (List);
while Present (E) loop
Append (New_Copy_Tree (E), NL);
E := Next (E);
end loop;
return NL;
end if;
end New_Copy_List_Tree;
-------------------
-- New_Copy_Tree --
-------------------
function New_Copy_Tree
(Source : Node_Id;
Map : Elist_Id := No_Elist;
New_Sloc : Source_Ptr := No_Location;
New_Scope : Entity_Id := Empty) return Node_Id
is
------------------------------------
-- Auxiliary Data and Subprograms --
------------------------------------
use Atree.Unchecked_Access;
use Atree_Private_Part;
-- Our approach here requires a two pass traversal of the tree. The
-- first pass visits all nodes that eventually will be copied looking
-- for defining Itypes. If any defining Itypes are found, then they are
-- copied, and an entry is added to the replacement map. In the second
-- phase, the tree is copied, using the replacement map to replace any
-- Itype references within the copied tree.
-- The following hash tables are used if the Map supplied has more than
-- hash threshold entries to speed up access to the map. If there are
-- fewer entries, then the map is searched sequentially (because setting
-- up a hash table for only a few entries takes more time than it saves.
subtype NCT_Header_Num is Int range 0 .. 511;
-- Defines range of headers in hash tables (512 headers)
function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
-- Hash function used for hash operations
---------------
-- NCT_Assoc --
---------------
-- The hash table NCT_Assoc associates old entities in the table with
-- their corresponding new entities (i.e. the pairs of entries presented
-- in the original Map argument are Key-Element pairs).
package NCT_Assoc is new Simple_HTable (
Header_Num => NCT_Header_Num,
Element => Entity_Id,
No_Element => Empty,
Key => Entity_Id,
Hash => New_Copy_Hash,
Equal => Types."=");
---------------------
-- NCT_Itype_Assoc --
---------------------
-- The hash table NCT_Itype_Assoc contains entries only for those old
-- nodes which have a non-empty Associated_Node_For_Itype set. The key
-- is the associated node, and the element is the new node itself (NOT
-- the associated node for the new node).
package NCT_Itype_Assoc is new Simple_HTable (
Header_Num => NCT_Header_Num,
Element => Entity_Id,
No_Element => Empty,
Key => Entity_Id,
Hash => New_Copy_Hash,
Equal => Types."=");
function Assoc (N : Node_Or_Entity_Id) return Node_Id;
-- Called during second phase to map entities into their corresponding
-- copies using the hash table. If the argument is not an entity, or is
-- not in the hash table, then it is returned unchanged.
procedure Build_NCT_Hash_Tables;
-- Builds hash tables.
function Copy_Elist_With_Replacement
(Old_Elist : Elist_Id) return Elist_Id;
-- Called during second phase to copy element list doing replacements
procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
-- Called during the second phase to process a copied Itype. The actual
-- copy happened during the first phase (so that we could make the entry
-- in the mapping), but we still have to deal with the descendants of
-- the copied Itype and copy them where necessary.
function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
-- Called during second phase to copy list doing replacements
function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
-- Called during second phase to copy node doing replacements
procedure Visit_Elist (E : Elist_Id);
-- Called during first phase to visit all elements of an Elist
procedure Visit_Field (F : Union_Id; N : Node_Id);
-- Visit a single field, recursing to call Visit_Node or Visit_List if
-- the field is a syntactic descendant of the current node (i.e. its
-- parent is Node N).
procedure Visit_Itype (Old_Itype : Entity_Id);
-- Called during first phase to visit subsidiary fields of a defining
-- Itype, and also create a copy and make an entry in the replacement
-- map for the new copy.
procedure Visit_List (L : List_Id);
-- Called during first phase to visit all elements of a List
procedure Visit_Node (N : Node_Or_Entity_Id);
-- Called during first phase to visit a node and all its subtrees
-----------
-- Assoc --
-----------
function Assoc (N : Node_Or_Entity_Id) return Node_Id is
Ent : Entity_Id;
begin
if Nkind (N) not in N_Entity then
return N;
else
Ent := NCT_Assoc.Get (Entity_Id (N));
if Present (Ent) then
return Ent;
end if;
end if;
return N;
end Assoc;
---------------------------
-- Build_NCT_Hash_Tables --
---------------------------
procedure Build_NCT_Hash_Tables is
Elmt : Elmt_Id;
Ent : Entity_Id;
begin
if No (Map) then
return;
end if;
Elmt := First_Elmt (Map);
while Present (Elmt) loop
Ent := Node (Elmt);
-- Get new entity, and associate old and new
Next_Elmt (Elmt);
NCT_Assoc.Set (Ent, Node (Elmt));
if Is_Type (Ent) then
declare
Anode : constant Entity_Id :=
Associated_Node_For_Itype (Ent);
begin
if Present (Anode) then
-- Enter a link between the associated node of the old
-- Itype and the new Itype, for updating later when node
-- is copied.
NCT_Itype_Assoc.Set (Anode, Node (Elmt));
end if;
end;
end if;
Next_Elmt (Elmt);
end loop;
end Build_NCT_Hash_Tables;
---------------------------------
-- Copy_Elist_With_Replacement --
---------------------------------
function Copy_Elist_With_Replacement
(Old_Elist : Elist_Id) return Elist_Id
is
M : Elmt_Id;
New_Elist : Elist_Id;
begin
if No (Old_Elist) then
return No_Elist;
else
New_Elist := New_Elmt_List;
M := First_Elmt (Old_Elist);
while Present (M) loop
Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
Next_Elmt (M);
end loop;
end if;
return New_Elist;
end Copy_Elist_With_Replacement;
---------------------------------
-- Copy_Itype_With_Replacement --
---------------------------------
-- This routine exactly parallels its phase one analog Visit_Itype,
procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
begin
-- Translate Next_Entity, Scope, and Etype fields, in case they
-- reference entities that have been mapped into copies.
Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
if Present (New_Scope) then
Set_Scope (New_Itype, New_Scope);
else
Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
end if;
-- Copy referenced fields
if Is_Discrete_Type (New_Itype) then
Set_Scalar_Range (New_Itype,
Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
elsif Has_Discriminants (Base_Type (New_Itype)) then
Set_Discriminant_Constraint (New_Itype,
Copy_Elist_With_Replacement
(Discriminant_Constraint (New_Itype)));
elsif Is_Array_Type (New_Itype) then
if Present (First_Index (New_Itype)) then
Set_First_Index (New_Itype,
First (Copy_List_With_Replacement
(List_Containing (First_Index (New_Itype)))));
end if;
if Is_Packed (New_Itype) then
Set_Packed_Array_Impl_Type (New_Itype,
Copy_Node_With_Replacement
(Packed_Array_Impl_Type (New_Itype)));
end if;
end if;
end Copy_Itype_With_Replacement;
--------------------------------
-- Copy_List_With_Replacement --
--------------------------------
function Copy_List_With_Replacement
(Old_List : List_Id) return List_Id
is
New_List : List_Id;
E : Node_Id;
begin
if Old_List = No_List then
return No_List;
else
New_List := Empty_List;
E := First (Old_List);
while Present (E) loop
Append (Copy_Node_With_Replacement (E), New_List);
Next (E);
end loop;
return New_List;
end if;
end Copy_List_With_Replacement;
--------------------------------
-- Copy_Node_With_Replacement --
--------------------------------
function Copy_Node_With_Replacement
(Old_Node : Node_Id) return Node_Id
is
New_Node : Node_Id;
procedure Adjust_Named_Associations
(Old_Node : Node_Id;
New_Node : Node_Id);
-- If a call node has named associations, these are chained through
-- the First_Named_Actual, Next_Named_Actual links. These must be
-- propagated separately to the new parameter list, because these
-- are not syntactic fields.
function Copy_Field_With_Replacement
(Field : Union_Id) return Union_Id;
-- Given Field, which is a field of Old_Node, return a copy of it
-- if it is a syntactic field (i.e. its parent is Node), setting
-- the parent of the copy to poit to New_Node. Otherwise returns
-- the field (possibly mapped if it is an entity).
-------------------------------
-- Adjust_Named_Associations --
-------------------------------
procedure Adjust_Named_Associations
(Old_Node : Node_Id;
New_Node : Node_Id)
is
Old_E : Node_Id;
New_E : Node_Id;
Old_Next : Node_Id;
New_Next : Node_Id;
begin
Old_E := First (Parameter_Associations (Old_Node));
New_E := First (Parameter_Associations (New_Node));
while Present (Old_E) loop
if Nkind (Old_E) = N_Parameter_Association
and then Present (Next_Named_Actual (Old_E))
then
if First_Named_Actual (Old_Node) =
Explicit_Actual_Parameter (Old_E)
then
Set_First_Named_Actual
(New_Node, Explicit_Actual_Parameter (New_E));
end if;
-- Now scan parameter list from the beginning, to locate
-- next named actual, which can be out of order.
Old_Next := First (Parameter_Associations (Old_Node));
New_Next := First (Parameter_Associations (New_Node));
while Nkind (Old_Next) /= N_Parameter_Association
or else Explicit_Actual_Parameter (Old_Next) /=
Next_Named_Actual (Old_E)
loop
Next (Old_Next);
Next (New_Next);
end loop;
Set_Next_Named_Actual
(New_E, Explicit_Actual_Parameter (New_Next));
end if;
Next (Old_E);
Next (New_E);
end loop;
end Adjust_Named_Associations;
---------------------------------
-- Copy_Field_With_Replacement --
---------------------------------
function Copy_Field_With_Replacement
(Field : Union_Id) return Union_Id
is
begin
if Field = Union_Id (Empty) then
return Field;
elsif Field in Node_Range then
declare
Old_N : constant Node_Id := Node_Id (Field);
New_N : Node_Id;
begin
-- If syntactic field, as indicated by the parent pointer
-- being set, then copy the referenced node recursively.
if Parent (Old_N) = Old_Node then
New_N := Copy_Node_With_Replacement (Old_N);
if New_N /= Old_N then
Set_Parent (New_N, New_Node);
end if;
-- For semantic fields, update possible entity reference
-- from the replacement map.
else
New_N := Assoc (Old_N);
end if;
return Union_Id (New_N);
end;
elsif Field in List_Range then
declare
Old_L : constant List_Id := List_Id (Field);
New_L : List_Id;
begin
-- If syntactic field, as indicated by the parent pointer,
-- then recursively copy the entire referenced list.
if Parent (Old_L) = Old_Node then
New_L := Copy_List_With_Replacement (Old_L);
Set_Parent (New_L, New_Node);
-- For semantic list, just returned unchanged
else
New_L := Old_L;
end if;
return Union_Id (New_L);
end;
-- Anything other than a list or a node is returned unchanged
else
return Field;
end if;
end Copy_Field_With_Replacement;
-- Start of processing for Copy_Node_With_Replacement
begin
if Old_Node <= Empty_Or_Error then
return Old_Node;
elsif Nkind (Old_Node) in N_Entity then
return Assoc (Old_Node);
else
New_Node := New_Copy (Old_Node);
-- If the node we are copying is the associated node of a
-- previously copied Itype, then adjust the associated node
-- of the copy of that Itype accordingly.
declare
Ent : constant Entity_Id := NCT_Itype_Assoc.Get (Old_Node);
begin
if Present (Ent) then
Set_Associated_Node_For_Itype (Ent, New_Node);
end if;
end;
-- Recursively copy descendants
Set_Field1
(New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
Set_Field2
(New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
Set_Field3
(New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
Set_Field4
(New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
Set_Field5
(New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
-- Adjust Sloc of new node if necessary
if New_Sloc /= No_Location then
Set_Sloc (New_Node, New_Sloc);
-- If we adjust the Sloc, then we are essentially making a
-- completely new node, so the Comes_From_Source flag should
-- be reset to the proper default value.
Set_Comes_From_Source
(New_Node, Default_Node.Comes_From_Source);
end if;
-- If the node is a call and has named associations, set the
-- corresponding links in the copy.
if Nkind_In (Old_Node, N_Entry_Call_Statement,
N_Function_Call,
N_Procedure_Call_Statement)
and then Present (First_Named_Actual (Old_Node))
then
Adjust_Named_Associations (Old_Node, New_Node);
end if;
-- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
-- The replacement mechanism applies to entities, and is not used
-- here. Eventually we may need a more general graph-copying
-- routine. For now, do a sequential search to find desired node.
if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
and then Present (First_Real_Statement (Old_Node))
then
declare
Old_F : constant Node_Id := First_Real_Statement (Old_Node);
N1, N2 : Node_Id;
begin
N1 := First (Statements (Old_Node));
N2 := First (Statements (New_Node));
while N1 /= Old_F loop
Next (N1);
Next (N2);
end loop;
Set_First_Real_Statement (New_Node, N2);
end;
end if;
end if;
-- All done, return copied node
return New_Node;
end Copy_Node_With_Replacement;
-------------------
-- New_Copy_Hash --
-------------------
function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
begin
return Nat (E) mod (NCT_Header_Num'Last + 1);
end New_Copy_Hash;
-----------------
-- Visit_Elist --
-----------------
procedure Visit_Elist (E : Elist_Id) is
Elmt : Elmt_Id;
begin
if Present (E) then
Elmt := First_Elmt (E);
while Elmt /= No_Elmt loop
Visit_Node (Node (Elmt));
Next_Elmt (Elmt);
end loop;
end if;
end Visit_Elist;
-----------------
-- Visit_Field --
-----------------
procedure Visit_Field (F : Union_Id; N : Node_Id) is
begin
if F = Union_Id (Empty) then
return;
elsif F in Node_Range then
-- Copy node if it is syntactic, i.e. its parent pointer is
-- set to point to the field that referenced it (certain
-- Itypes will also meet this criterion, which is fine, since
-- these are clearly Itypes that do need to be copied, since
-- we are copying their parent.)
if Parent (Node_Id (F)) = N then
Visit_Node (Node_Id (F));
return;
-- Another case, if we are pointing to an Itype, then we want
-- to copy it if its associated node is somewhere in the tree
-- being copied.
-- Note: the exclusion of self-referential copies is just an
-- optimization, since the search of the already copied list
-- would catch it, but it is a common case (Etype pointing to
-- itself for an Itype that is a base type).
elsif Nkind (Node_Id (F)) in N_Entity
and then Is_Itype (Entity_Id (F))
and then Node_Id (F) /= N
then
declare
P : Node_Id;
begin
P := Associated_Node_For_Itype (Node_Id (F));
while Present (P) loop
if P = Source then
Visit_Node (Node_Id (F));
return;
else
P := Parent (P);
end if;
end loop;
-- An Itype whose parent is not being copied definitely
-- should NOT be copied, since it does not belong in any
-- sense to the copied subtree.
return;
end;
end if;
elsif F in List_Range and then Parent (List_Id (F)) = N then
Visit_List (List_Id (F));
return;
end if;
end Visit_Field;
-----------------
-- Visit_Itype --
-----------------
procedure Visit_Itype (Old_Itype : Entity_Id) is
New_Itype : Entity_Id;
Ent : Entity_Id;
begin
-- Itypes that describe the designated type of access to subprograms
-- have the structure of subprogram declarations, with signatures,
-- etc. Either we duplicate the signatures completely, or choose to
-- share such itypes, which is fine because their elaboration will
-- have no side effects.
if Ekind (Old_Itype) = E_Subprogram_Type then
return;
end if;
New_Itype := New_Copy (Old_Itype);
-- The new Itype has all the attributes of the old one, and we
-- just copy the contents of the entity. However, the back-end
-- needs different names for debugging purposes, so we create a
-- new internal name for it in all cases.
Set_Chars (New_Itype, New_Internal_Name ('T'));
-- If our associated node is an entity that has already been copied,
-- then set the associated node of the copy to point to the right
-- copy. If we have copied an Itype that is itself the associated
-- node of some previously copied Itype, then we set the right
-- pointer in the other direction.
Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
if Present (Ent) then
Set_Associated_Node_For_Itype (New_Itype, Ent);
end if;
Ent := NCT_Itype_Assoc.Get (Old_Itype);
if Present (Ent) then
Set_Associated_Node_For_Itype (Ent, New_Itype);
-- If the hash table has no association for this Itype and its
-- associated node, enter one now.
else
NCT_Itype_Assoc.Set
(Associated_Node_For_Itype (Old_Itype), New_Itype);
end if;
if Present (Freeze_Node (New_Itype)) then
Set_Is_Frozen (New_Itype, False);
Set_Freeze_Node (New_Itype, Empty);
end if;
-- Add new association to map
NCT_Assoc.Set (Old_Itype, New_Itype);
-- If a record subtype is simply copied, the entity list will be
-- shared. Thus cloned_Subtype must be set to indicate the sharing.
if Ekind_In (Old_Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
Set_Cloned_Subtype (New_Itype, Old_Itype);
end if;
-- Visit descendants that eventually get copied
Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
if Is_Discrete_Type (Old_Itype) then
Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
elsif Has_Discriminants (Base_Type (Old_Itype)) then
-- ??? This should involve call to Visit_Field
Visit_Elist (Discriminant_Constraint (Old_Itype));
elsif Is_Array_Type (Old_Itype) then
if Present (First_Index (Old_Itype)) then
Visit_Field
(Union_Id (List_Containing (First_Index (Old_Itype))),
Old_Itype);
end if;
if Is_Packed (Old_Itype) then
Visit_Field
(Union_Id (Packed_Array_Impl_Type (Old_Itype)), Old_Itype);
end if;
end if;
end Visit_Itype;
----------------
-- Visit_List --
----------------
procedure Visit_List (L : List_Id) is
N : Node_Id;
begin
if L /= No_List then
N := First (L);
while Present (N) loop
Visit_Node (N);
Next (N);
end loop;
end if;
end Visit_List;
----------------
-- Visit_Node --
----------------
procedure Visit_Node (N : Node_Or_Entity_Id) is
begin
-- Handle case of an Itype, which must be copied
if Nkind (N) in N_Entity and then Is_Itype (N) then
-- Nothing to do if already in the list. This can happen with an
-- Itype entity that appears more than once in the tree. Note that
-- we do not want to visit descendants in this case.
if Present (NCT_Assoc.Get (Entity_Id (N))) then
return;
end if;
Visit_Itype (N);
end if;
-- Visit descendants
Visit_Field (Field1 (N), N);
Visit_Field (Field2 (N), N);
Visit_Field (Field3 (N), N);
Visit_Field (Field4 (N), N);
Visit_Field (Field5 (N), N);
end Visit_Node;
-- Start of processing for New_Copy_Tree
begin
Build_NCT_Hash_Tables;
-- Hash table set up if required, now start phase one by visiting top
-- node (we will recursively visit the descendants).
Visit_Node (Source);
-- Now the second phase of the copy can start. First we process all the
-- mapped entities, copying their descendants.
declare
Old_E : Entity_Id := Empty;
New_E : Entity_Id;
begin
NCT_Assoc.Get_First (Old_E, New_E);
while Present (New_E) loop
if Is_Itype (New_E) then
Copy_Itype_With_Replacement (New_E);
end if;
NCT_Assoc.Get_Next (Old_E, New_E);
end loop;
end;
-- Now we can copy the actual tree
declare
Result : constant Node_Id := Copy_Node_With_Replacement (Source);
begin
NCT_Assoc.Reset;
NCT_Itype_Assoc.Reset;
return Result;
end;
end New_Copy_Tree;
-------------------------
-- New_External_Entity --
-------------------------
function New_External_Entity
(Kind : Entity_Kind;
Scope_Id : Entity_Id;
Sloc_Value : Source_Ptr;
Related_Id : Entity_Id;
Suffix : Character;
Suffix_Index : Nat := 0;
Prefix : Character := ' ') return Entity_Id
is
N : constant Entity_Id :=
Make_Defining_Identifier (Sloc_Value,
New_External_Name
(Chars (Related_Id), Suffix, Suffix_Index, Prefix));
begin
Set_Ekind (N, Kind);
Set_Is_Internal (N, True);
Append_Entity (N, Scope_Id);
Set_Public_Status (N);
if Kind in Type_Kind then
Init_Size_Align (N);
end if;
return N;
end New_External_Entity;
-------------------------
-- New_Internal_Entity --
-------------------------
function New_Internal_Entity
(Kind : Entity_Kind;
Scope_Id : Entity_Id;
Sloc_Value : Source_Ptr;
Id_Char : Character) return Entity_Id
is
N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
begin
Set_Ekind (N, Kind);
Set_Is_Internal (N, True);
Append_Entity (N, Scope_Id);
if Kind in Type_Kind then
Init_Size_Align (N);
end if;
return N;
end New_Internal_Entity;
-----------------
-- Next_Actual --
-----------------
function Next_Actual (Actual_Id : Node_Id) return Node_Id is
N : Node_Id;
begin
-- If we are pointing at a positional parameter, it is a member of a
-- node list (the list of parameters), and the next parameter is the
-- next node on the list, unless we hit a parameter association, then
-- we shift to using the chain whose head is the First_Named_Actual in
-- the parent, and then is threaded using the Next_Named_Actual of the
-- Parameter_Association. All this fiddling is because the original node
-- list is in the textual call order, and what we need is the
-- declaration order.
if Is_List_Member (Actual_Id) then
N := Next (Actual_Id);
if Nkind (N) = N_Parameter_Association then
return First_Named_Actual (Parent (Actual_Id));
else
return N;
end if;
else
return Next_Named_Actual (Parent (Actual_Id));
end if;
end Next_Actual;
procedure Next_Actual (Actual_Id : in out Node_Id) is
begin
Actual_Id := Next_Actual (Actual_Id);
end Next_Actual;
----------------------------------
-- New_Requires_Transient_Scope --
----------------------------------
function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
-- This is called for untagged records and protected types, with
-- nondefaulted discriminants. Returns True if the size of function
-- results is known at the call site, False otherwise. Returns False
-- if there is a variant part that depends on the discriminants of
-- this type, or if there is an array constrained by the discriminants
-- of this type. ???Currently, this is overly conservative (the array
-- could be nested inside some other record that is constrained by
-- nondiscriminants). That is, the recursive calls are too conservative.
function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
-- Returns True if Typ is a nonlimited record with defaulted
-- discriminants whose max size makes it unsuitable for allocating on
-- the primary stack.
------------------------------
-- Caller_Known_Size_Record --
------------------------------
function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
pragma Assert (Typ = Underlying_Type (Typ));
begin
if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
return False;
end if;
declare
Comp : Entity_Id;
begin
Comp := First_Entity (Typ);
while Present (Comp) loop
-- Only look at E_Component entities. No need to look at
-- E_Discriminant entities, and we must ignore internal
-- subtypes generated for constrained components.
if Ekind (Comp) = E_Component then
declare
Comp_Type : constant Entity_Id :=
Underlying_Type (Etype (Comp));
begin
if Is_Record_Type (Comp_Type)
or else
Is_Protected_Type (Comp_Type)
then
if not Caller_Known_Size_Record (Comp_Type) then
return False;
end if;
elsif Is_Array_Type (Comp_Type) then
if Size_Depends_On_Discriminant (Comp_Type) then
return False;
end if;
end if;
end;
end if;
Next_Entity (Comp);
end loop;
end;
return True;
end Caller_Known_Size_Record;
------------------------------
-- Large_Max_Size_Mutable --
------------------------------
function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
pragma Assert (Typ = Underlying_Type (Typ));
function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
-- Returns true if the discrete type T has a large range
----------------------------
-- Is_Large_Discrete_Type --
----------------------------
function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
Threshold : constant Int := 16;
-- Arbitrary threshold above which we consider it "large". We want
-- a fairly large threshold, because these large types really
-- shouldn't have default discriminants in the first place, in
-- most cases.
begin
return UI_To_Int (RM_Size (T)) > Threshold;
end Is_Large_Discrete_Type;
-- Start of processing for Large_Max_Size_Mutable
begin
if Is_Record_Type (Typ)
and then not Is_Limited_View (Typ)
and then Has_Defaulted_Discriminants (Typ)
then
-- Loop through the components, looking for an array whose upper
-- bound(s) depends on discriminants, where both the subtype of
-- the discriminant and the index subtype are too large.
declare
Comp : Entity_Id;
begin
Comp := First_Entity (Typ);
while Present (Comp) loop
if Ekind (Comp) = E_Component then
declare
Comp_Type : constant Entity_Id :=
Underlying_Type (Etype (Comp));
Hi : Node_Id;
Indx : Node_Id;
Ityp : Entity_Id;
begin
if Is_Array_Type (Comp_Type) then
Indx := First_Index (Comp_Type);
while Present (Indx) loop
Ityp := Etype (Indx);
Hi := Type_High_Bound (Ityp);
if Nkind (Hi) = N_Identifier
and then Ekind (Entity (Hi)) = E_Discriminant
and then Is_Large_Discrete_Type (Ityp)
and then Is_Large_Discrete_Type
(Etype (Entity (Hi)))
then
return True;
end if;
Next_Index (Indx);
end loop;
end if;
end;
end if;
Next_Entity (Comp);
end loop;
end;
end if;
return False;
end Large_Max_Size_Mutable;
-- Local declarations
Typ : constant Entity_Id := Underlying_Type (Id);
-- Start of processing for New_Requires_Transient_Scope
begin
-- This is a private type which is not completed yet. This can only
-- happen in a default expression (of a formal parameter or of a
-- record component). Do not expand transient scope in this case.
if No (Typ) then
return False;
-- Do not expand transient scope for non-existent procedure return or
-- string literal types.
elsif Typ = Standard_Void_Type
or else Ekind (Typ) = E_String_Literal_Subtype
then
return False;
-- If Typ is a generic formal incomplete type, then we want to look at
-- the actual type.
elsif Ekind (Typ) = E_Record_Subtype
and then Present (Cloned_Subtype (Typ))
then
return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
-- Functions returning specific tagged types may dispatch on result, so
-- their returned value is allocated on the secondary stack, even in the
-- definite case. We must treat nondispatching functions the same way,
-- because access-to-function types can point at both, so the calling
-- conventions must be compatible. Is_Tagged_Type includes controlled
-- types and class-wide types. Controlled type temporaries need
-- finalization.
-- ???It's not clear why we need to return noncontrolled types with
-- controlled components on the secondary stack.
elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
return True;
-- Untagged definite subtypes are known size. This includes all
-- elementary [sub]types. Tasks are known size even if they have
-- discriminants. So we return False here, with one exception:
-- For a type like:
-- type T (Last : Natural := 0) is
-- X : String (1 .. Last);
-- end record;
-- we return True. That's because for "P(F(...));", where F returns T,
-- we don't know the size of the result at the call site, so if we
-- allocated it on the primary stack, we would have to allocate the
-- maximum size, which is way too big.
elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
return Large_Max_Size_Mutable (Typ);
-- Indefinite (discriminated) untagged record or protected type
elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
return not Caller_Known_Size_Record (Typ);
-- Unconstrained array
else
pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
return True;
end if;
end New_Requires_Transient_Scope;
-----------------------
-- Normalize_Actuals --
-----------------------
-- Chain actuals according to formals of subprogram. If there are no named
-- associations, the chain is simply the list of Parameter Associations,
-- since the order is the same as the declaration order. If there are named
-- associations, then the First_Named_Actual field in the N_Function_Call
-- or N_Procedure_Call_Statement node points to the Parameter_Association
-- node for the parameter that comes first in declaration order. The
-- remaining named parameters are then chained in declaration order using
-- Next_Named_Actual.
-- This routine also verifies that the number of actuals is compatible with
-- the number and default values of formals, but performs no type checking
-- (type checking is done by the caller).
-- If the matching succeeds, Success is set to True and the caller proceeds
-- with type-checking. If the match is unsuccessful, then Success is set to
-- False, and the caller attempts a different interpretation, if there is
-- one.
-- If the flag Report is on, the call is not overloaded, and a failure to
-- match can be reported here, rather than in the caller.
procedure Normalize_Actuals
(N : Node_Id;
S : Entity_Id;
Report : Boolean;
Success : out Boolean)
is
Actuals : constant List_Id := Parameter_Associations (N);
Actual : Node_Id := Empty;
Formal : Entity_Id;
Last : Node_Id := Empty;
First_Named : Node_Id := Empty;
Found : Boolean;
Formals_To_Match : Integer := 0;
Actuals_To_Match : Integer := 0;
procedure Chain (A : Node_Id);
-- Add named actual at the proper place in the list, using the
-- Next_Named_Actual link.
function Reporting return Boolean;
-- Determines if an error is to be reported. To report an error, we
-- need Report to be True, and also we do not report errors caused
-- by calls to init procs that occur within other init procs. Such
-- errors must always be cascaded errors, since if all the types are
-- declared correctly, the compiler will certainly build decent calls.
-----------
-- Chain --
-----------
procedure Chain (A : Node_Id) is
begin
if No (Last) then
-- Call node points to first actual in list
Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
else
Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
end if;
Last := A;
Set_Next_Named_Actual (Last, Empty);
end Chain;
---------------
-- Reporting --
---------------
function Reporting return Boolean is
begin
if not Report then
return False;
elsif not Within_Init_Proc then
return True;
elsif Is_Init_Proc (Entity (Name (N))) then
return False;
else
return True;
end if;
end Reporting;
-- Start of processing for Normalize_Actuals
begin
if Is_Access_Type (S) then
-- The name in the call is a function call that returns an access
-- to subprogram. The designated type has the list of formals.
Formal := First_Formal (Designated_Type (S));
else
Formal := First_Formal (S);
end if;
while Present (Formal) loop
Formals_To_Match := Formals_To_Match + 1;
Next_Formal (Formal);
end loop;
-- Find if there is a named association, and verify that no positional
-- associations appear after named ones.
if Present (Actuals) then
Actual := First (Actuals);
end if;
while Present (Actual)
and then Nkind (Actual) /= N_Parameter_Association
loop
Actuals_To_Match := Actuals_To_Match + 1;
Next (Actual);
end loop;
if No (Actual) and Actuals_To_Match = Formals_To_Match then
-- Most common case: positional notation, no defaults
Success := True;
return;
elsif Actuals_To_Match > Formals_To_Match then
-- Too many actuals: will not work
if Reporting then
if Is_Entity_Name (Name (N)) then
Error_Msg_N ("too many arguments in call to&", Name (N));
else
Error_Msg_N ("too many arguments in call", N);
end if;
end if;
Success := False;
return;
end if;
First_Named := Actual;
while Present (Actual) loop
if Nkind (Actual) /= N_Parameter_Association then
Error_Msg_N
("positional parameters not allowed after named ones", Actual);
Success := False;
return;
else
Actuals_To_Match := Actuals_To_Match + 1;
end if;
Next (Actual);
end loop;
if Present (Actuals) then
Actual := First (Actuals);
end if;
Formal := First_Formal (S);
while Present (Formal) loop
-- Match the formals in order. If the corresponding actual is
-- positional, nothing to do. Else scan the list of named actuals
-- to find the one with the right name.
if Present (Actual)
and then Nkind (Actual) /= N_Parameter_Association
then
Next (Actual);
Actuals_To_Match := Actuals_To_Match - 1;
Formals_To_Match := Formals_To_Match - 1;
else
-- For named parameters, search the list of actuals to find
-- one that matches the next formal name.
Actual := First_Named;
Found := False;
while Present (Actual) loop
if Chars (Selector_Name (Actual)) = Chars (Formal) then
Found := True;
Chain (Actual);
Actuals_To_Match := Actuals_To_Match - 1;
Formals_To_Match := Formals_To_Match - 1;
exit;
end if;
Next (Actual);
end loop;
if not Found then
if Ekind (Formal) /= E_In_Parameter
or else No (Default_Value (Formal))
then
if Reporting then
if (Comes_From_Source (S)
or else Sloc (S) = Standard_Location)
and then Is_Overloadable (S)
then
if No (Actuals)
and then
Nkind_In (Parent (N), N_Procedure_Call_Statement,
N_Function_Call,
N_Parameter_Association)
and then Ekind (S) /= E_Function
then
Set_Etype (N, Etype (S));
else
Error_Msg_Name_1 := Chars (S);
Error_Msg_Sloc := Sloc (S);
Error_Msg_NE
("missing argument for parameter & "
& "in call to % declared #", N, Formal);
end if;
elsif Is_Overloadable (S) then
Error_Msg_Name_1 := Chars (S);
-- Point to type derivation that generated the
-- operation.
Error_Msg_Sloc := Sloc (Parent (S));
Error_Msg_NE
("missing argument for parameter & "
& "in call to % (inherited) #", N, Formal);
else
Error_Msg_NE
("missing argument for parameter &", N, Formal);
end if;
end if;
Success := False;
return;
else
Formals_To_Match := Formals_To_Match - 1;
end if;
end if;
end if;
Next_Formal (Formal);
end loop;
if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
Success := True;
return;
else
if Reporting then
-- Find some superfluous named actual that did not get
-- attached to the list of associations.
Actual := First (Actuals);
while Present (Actual) loop
if Nkind (Actual) = N_Parameter_Association
and then Actual /= Last
and then No (Next_Named_Actual (Actual))
then
-- A validity check may introduce a copy of a call that
-- includes an extra actual (for example for an unrelated
-- accessibility check). Check that the extra actual matches
-- some extra formal, which must exist already because
-- subprogram must be frozen at this point.
if Present (Extra_Formals (S))
and then not Comes_From_Source (Actual)
and then Nkind (Actual) = N_Parameter_Association
and then Chars (Extra_Formals (S)) =
Chars (Selector_Name (Actual))
then
null;
else
Error_Msg_N
("unmatched actual & in call", Selector_Name (Actual));
exit;
end if;
end if;
Next (Actual);
end loop;
end if;
Success := False;
return;
end if;
end Normalize_Actuals;
--------------------------------
-- Note_Possible_Modification --
--------------------------------
procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
Modification_Comes_From_Source : constant Boolean :=
Comes_From_Source (Parent (N));
Ent : Entity_Id;
Exp : Node_Id;
begin
-- Loop to find referenced entity, if there is one
Exp := N;
loop
Ent := Empty;
if Is_Entity_Name (Exp) then
Ent := Entity (Exp);
-- If the entity is missing, it is an undeclared identifier,
-- and there is nothing to annotate.
if No (Ent) then
return;
end if;
elsif Nkind (Exp) = N_Explicit_Dereference then
declare
P : constant Node_Id := Prefix (Exp);
begin
-- In formal verification mode, keep track of all reads and
-- writes through explicit dereferences.
if GNATprove_Mode then
SPARK_Specific.Generate_Dereference (N, 'm');
end if;
if Nkind (P) = N_Selected_Component
and then Present (Entry_Formal (Entity (Selector_Name (P))))
then
-- Case of a reference to an entry formal
Ent := Entry_Formal (Entity (Selector_Name (P)));
elsif Nkind (P) = N_Identifier
and then Nkind (Parent (Entity (P))) = N_Object_Declaration
and then Present (Expression (Parent (Entity (P))))
and then Nkind (Expression (Parent (Entity (P)))) =
N_Reference
then
-- Case of a reference to a value on which side effects have
-- been removed.
Exp := Prefix (Expression (Parent (Entity (P))));
goto Continue;
else
return;
end if;
end;
elsif Nkind_In (Exp, N_Type_Conversion,
N_Unchecked_Type_Conversion)
then
Exp := Expression (Exp);
goto Continue;
elsif Nkind_In (Exp, N_Slice,
N_Indexed_Component,
N_Selected_Component)
then
-- Special check, if the prefix is an access type, then return
-- since we are modifying the thing pointed to, not the prefix.
-- When we are expanding, most usually the prefix is replaced
-- by an explicit dereference, and this test is not needed, but
-- in some cases (notably -gnatc mode and generics) when we do
-- not do full expansion, we need this special test.
if Is_Access_Type (Etype (Prefix (Exp))) then
return;
-- Otherwise go to prefix and keep going
else
Exp := Prefix (Exp);
goto Continue;
end if;
-- All other cases, not a modification
else
return;
end if;
-- Now look for entity being referenced
if Present (Ent) then
if Is_Object (Ent) then
if Comes_From_Source (Exp)
or else Modification_Comes_From_Source
then
-- Give warning if pragma unmodified is given and we are
-- sure this is a modification.
if Has_Pragma_Unmodified (Ent) and then Sure then
-- Note that the entity may be present only as a result
-- of pragma Unused.
if Has_Pragma_Unused (Ent) then
Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
else
Error_Msg_NE
("??pragma Unmodified given for &!", N, Ent);
end if;
end if;
Set_Never_Set_In_Source (Ent, False);
end if;
Set_Is_True_Constant (Ent, False);
Set_Current_Value (Ent, Empty);
Set_Is_Known_Null (Ent, False);
if not Can_Never_Be_Null (Ent) then
Set_Is_Known_Non_Null (Ent, False);
end if;
-- Follow renaming chain
if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
and then Present (Renamed_Object (Ent))
then
Exp := Renamed_Object (Ent);
-- If the entity is the loop variable in an iteration over
-- a container, retrieve container expression to indicate
-- possible modification.
if Present (Related_Expression (Ent))
and then Nkind (Parent (Related_Expression (Ent))) =
N_Iterator_Specification
then
Exp := Original_Node (Related_Expression (Ent));
end if;
goto Continue;
-- The expression may be the renaming of a subcomponent of an
-- array or container. The assignment to the subcomponent is
-- a modification of the container.
elsif Comes_From_Source (Original_Node (Exp))
and then Nkind_In (Original_Node (Exp), N_Selected_Component,
N_Indexed_Component)
then
Exp := Prefix (Original_Node (Exp));
goto Continue;
end if;
-- Generate a reference only if the assignment comes from
-- source. This excludes, for example, calls to a dispatching
-- assignment operation when the left-hand side is tagged. In
-- GNATprove mode, we need those references also on generated
-- code, as these are used to compute the local effects of
-- subprograms.
if Modification_Comes_From_Source or GNATprove_Mode then
Generate_Reference (Ent, Exp, 'm');
-- If the target of the assignment is the bound variable
-- in an iterator, indicate that the corresponding array
-- or container is also modified.
if Ada_Version >= Ada_2012
and then Nkind (Parent (Ent)) = N_Iterator_Specification
then
declare
Domain : constant Node_Id := Name (Parent (Ent));
begin
-- TBD : in the full version of the construct, the
-- domain of iteration can be given by an expression.
if Is_Entity_Name (Domain) then
Generate_Reference (Entity (Domain), Exp, 'm');
Set_Is_True_Constant (Entity (Domain), False);
Set_Never_Set_In_Source (Entity (Domain), False);
end if;
end;
end if;
end if;
end if;
Kill_Checks (Ent);
-- If we are sure this is a modification from source, and we know
-- this modifies a constant, then give an appropriate warning.
if Sure
and then Modification_Comes_From_Source
and then Overlays_Constant (Ent)
and then Address_Clause_Overlay_Warnings
then
declare
Addr : constant Node_Id := Address_Clause (Ent);
O_Ent : Entity_Id;
Off : Boolean;
begin
Find_Overlaid_Entity (Addr, O_Ent, Off);
Error_Msg_Sloc := Sloc (Addr);
Error_Msg_NE
("??constant& may be modified via address clause#",
N, O_Ent);
end;
end if;
return;
end if;
<<Continue>>
null;
end loop;
end Note_Possible_Modification;
--------------------------------------
-- Null_To_Null_Address_Convert_OK --
--------------------------------------
function Null_To_Null_Address_Convert_OK
(N : Node_Id;
Typ : Entity_Id := Empty) return Boolean
is
begin
if not Relaxed_RM_Semantics then
return False;
end if;
if Nkind (N) = N_Null then
return Present (Typ) and then Is_Descendant_Of_Address (Typ);
elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
then
declare
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
begin
-- We check the Etype of the complementary operand since the
-- N_Null node is not decorated at this stage.
return
((Nkind (L) = N_Null
and then Is_Descendant_Of_Address (Etype (R)))
or else
(Nkind (R) = N_Null
and then Is_Descendant_Of_Address (Etype (L))));
end;
end if;
return False;
end Null_To_Null_Address_Convert_OK;
-------------------------
-- Object_Access_Level --
-------------------------
-- Returns the static accessibility level of the view denoted by Obj. Note
-- that the value returned is the result of a call to Scope_Depth. Only
-- scope depths associated with dynamic scopes can actually be returned.
-- Since only relative levels matter for accessibility checking, the fact
-- that the distance between successive levels of accessibility is not
-- always one is immaterial (invariant: if level(E2) is deeper than
-- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
function Object_Access_Level (Obj : Node_Id) return Uint is
function Is_Interface_Conversion (N : Node_Id) return Boolean;
-- Determine whether N is a construct of the form
-- Some_Type (Operand._tag'Address)
-- This construct appears in the context of dispatching calls.
function Reference_To (Obj : Node_Id) return Node_Id;
-- An explicit dereference is created when removing side-effects from
-- expressions for constraint checking purposes. In this case a local
-- access type is created for it. The correct access level is that of
-- the original source node. We detect this case by noting that the
-- prefix of the dereference is created by an object declaration whose
-- initial expression is a reference.
-----------------------------
-- Is_Interface_Conversion --
-----------------------------
function Is_Interface_Conversion (N : Node_Id) return Boolean is
begin
return Nkind (N) = N_Unchecked_Type_Conversion
and then Nkind (Expression (N)) = N_Attribute_Reference
and then Attribute_Name (Expression (N)) = Name_Address;
end Is_Interface_Conversion;
------------------
-- Reference_To --
------------------
function Reference_To (Obj : Node_Id) return Node_Id is
Pref : constant Node_Id := Prefix (Obj);
begin
if Is_Entity_Name (Pref)
and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
and then Present (Expression (Parent (Entity (Pref))))
and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
then
return (Prefix (Expression (Parent (Entity (Pref)))));
else
return Empty;
end if;
end Reference_To;
-- Local variables
E : Entity_Id;
-- Start of processing for Object_Access_Level
begin
if Nkind (Obj) = N_Defining_Identifier
or else Is_Entity_Name (Obj)
then
if Nkind (Obj) = N_Defining_Identifier then
E := Obj;
else
E := Entity (Obj);
end if;
if Is_Prival (E) then
E := Prival_Link (E);
end if;
-- If E is a type then it denotes a current instance. For this case
-- we add one to the normal accessibility level of the type to ensure
-- that current instances are treated as always being deeper than
-- than the level of any visible named access type (see 3.10.2(21)).
if Is_Type (E) then
return Type_Access_Level (E) + 1;
elsif Present (Renamed_Object (E)) then
return Object_Access_Level (Renamed_Object (E));
-- Similarly, if E is a component of the current instance of a
-- protected type, any instance of it is assumed to be at a deeper
-- level than the type. For a protected object (whose type is an
-- anonymous protected type) its components are at the same level
-- as the type itself.
elsif not Is_Overloadable (E)
and then Ekind (Scope (E)) = E_Protected_Type
and then Comes_From_Source (Scope (E))
then
return Type_Access_Level (Scope (E)) + 1;
else
-- Aliased formals of functions take their access level from the
-- point of call, i.e. require a dynamic check. For static check
-- purposes, this is smaller than the level of the subprogram
-- itself. For procedures the aliased makes no difference.
if Is_Formal (E)
and then Is_Aliased (E)
and then Ekind (Scope (E)) = E_Function
then
return Type_Access_Level (Etype (E));
else
return Scope_Depth (Enclosing_Dynamic_Scope (E));
end if;
end if;
elsif Nkind (Obj) = N_Selected_Component then
if Is_Access_Type (Etype (Prefix (Obj))) then
return Type_Access_Level (Etype (Prefix (Obj)));
else
return Object_Access_Level (Prefix (Obj));
end if;
elsif Nkind (Obj) = N_Indexed_Component then
if Is_Access_Type (Etype (Prefix (Obj))) then
return Type_Access_Level (Etype (Prefix (Obj)));
else
return Object_Access_Level (Prefix (Obj));
end if;
elsif Nkind (Obj) = N_Explicit_Dereference then
-- If the prefix is a selected access discriminant then we make a
-- recursive call on the prefix, which will in turn check the level
-- of the prefix object of the selected discriminant.
-- In Ada 2012, if the discriminant has implicit dereference and
-- the context is a selected component, treat this as an object of
-- unknown scope (see below). This is necessary in compile-only mode;
-- otherwise expansion will already have transformed the prefix into
-- a temporary.
if Nkind (Prefix (Obj)) = N_Selected_Component
and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
and then
Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
and then
(not Has_Implicit_Dereference
(Entity (Selector_Name (Prefix (Obj))))
or else Nkind (Parent (Obj)) /= N_Selected_Component)
then
return Object_Access_Level (Prefix (Obj));
-- Detect an interface conversion in the context of a dispatching
-- call. Use the original form of the conversion to find the access
-- level of the operand.
elsif Is_Interface (Etype (Obj))
and then Is_Interface_Conversion (Prefix (Obj))
and then Nkind (Original_Node (Obj)) = N_Type_Conversion
then
return Object_Access_Level (Original_Node (Obj));
elsif not Comes_From_Source (Obj) then
declare
Ref : constant Node_Id := Reference_To (Obj);
begin
if Present (Ref) then
return Object_Access_Level (Ref);
else
return Type_Access_Level (Etype (Prefix (Obj)));
end if;
end;
else
return Type_Access_Level (Etype (Prefix (Obj)));
end if;
elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
return Object_Access_Level (Expression (Obj));
elsif Nkind (Obj) = N_Function_Call then
-- Function results are objects, so we get either the access level of
-- the function or, in the case of an indirect call, the level of the
-- access-to-subprogram type. (This code is used for Ada 95, but it
-- looks wrong, because it seems that we should be checking the level
-- of the call itself, even for Ada 95. However, using the Ada 2005
-- version of the code causes regressions in several tests that are
-- compiled with -gnat95. ???)
if Ada_Version < Ada_2005 then
if Is_Entity_Name (Name (Obj)) then
return Subprogram_Access_Level (Entity (Name (Obj)));
else
return Type_Access_Level (Etype (Prefix (Name (Obj))));
end if;
-- For Ada 2005, the level of the result object of a function call is
-- defined to be the level of the call's innermost enclosing master.
-- We determine that by querying the depth of the innermost enclosing
-- dynamic scope.
else
Return_Master_Scope_Depth_Of_Call : declare
function Innermost_Master_Scope_Depth
(N : Node_Id) return Uint;
-- Returns the scope depth of the given node's innermost
-- enclosing dynamic scope (effectively the accessibility
-- level of the innermost enclosing master).
----------------------------------
-- Innermost_Master_Scope_Depth --
----------------------------------
function Innermost_Master_Scope_Depth
(N : Node_Id) return Uint
is
Node_Par : Node_Id := Parent (N);
begin
-- Locate the nearest enclosing node (by traversing Parents)
-- that Defining_Entity can be applied to, and return the
-- depth of that entity's nearest enclosing dynamic scope.
while Present (Node_Par) loop
case Nkind (Node_Par) is
when N_Abstract_Subprogram_Declaration
| N_Block_Statement
| N_Body_Stub
| N_Component_Declaration
| N_Entry_Body
| N_Entry_Declaration
| N_Exception_Declaration
| N_Formal_Object_Declaration
| N_Formal_Package_Declaration
| N_Formal_Subprogram_Declaration
| N_Formal_Type_Declaration
| N_Full_Type_Declaration
| N_Function_Specification
| N_Generic_Declaration
| N_Generic_Instantiation
| N_Implicit_Label_Declaration
| N_Incomplete_Type_Declaration
| N_Loop_Parameter_Specification
| N_Number_Declaration
| N_Object_Declaration
| N_Package_Declaration
| N_Package_Specification
| N_Parameter_Specification
| N_Private_Extension_Declaration
| N_Private_Type_Declaration
| N_Procedure_Specification
| N_Proper_Body
| N_Protected_Type_Declaration
| N_Renaming_Declaration
| N_Single_Protected_Declaration
| N_Single_Task_Declaration
| N_Subprogram_Declaration
| N_Subtype_Declaration
| N_Subunit
| N_Task_Type_Declaration
=>
return Scope_Depth
(Nearest_Dynamic_Scope
(Defining_Entity (Node_Par)));
when others =>
null;
end case;
Node_Par := Parent (Node_Par);
end loop;
pragma Assert (False);
-- Should never reach the following return
return Scope_Depth (Current_Scope) + 1;
end Innermost_Master_Scope_Depth;
-- Start of processing for Return_Master_Scope_Depth_Of_Call
begin
return Innermost_Master_Scope_Depth (Obj);
end Return_Master_Scope_Depth_Of_Call;
end if;
-- For convenience we handle qualified expressions, even though they
-- aren't technically object names.
elsif Nkind (Obj) = N_Qualified_Expression then
return Object_Access_Level (Expression (Obj));
-- Ditto for aggregates. They have the level of the temporary that
-- will hold their value.
elsif Nkind (Obj) = N_Aggregate then
return Object_Access_Level (Current_Scope);
-- Otherwise return the scope level of Standard. (If there are cases
-- that fall through to this point they will be treated as having
-- global accessibility for now. ???)
else
return Scope_Depth (Standard_Standard);
end if;
end Object_Access_Level;
----------------------------------
-- Old_Requires_Transient_Scope --
----------------------------------
function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
Typ : constant Entity_Id := Underlying_Type (Id);
begin
-- This is a private type which is not completed yet. This can only
-- happen in a default expression (of a formal parameter or of a
-- record component). Do not expand transient scope in this case.
if No (Typ) then
return False;
-- Do not expand transient scope for non-existent procedure return
elsif Typ = Standard_Void_Type then
return False;
-- Elementary types do not require a transient scope
elsif Is_Elementary_Type (Typ) then
return False;
-- Generally, indefinite subtypes require a transient scope, since the
-- back end cannot generate temporaries, since this is not a valid type
-- for declaring an object. It might be possible to relax this in the
-- future, e.g. by declaring the maximum possible space for the type.
elsif not Is_Definite_Subtype (Typ) then
return True;
-- Functions returning tagged types may dispatch on result so their
-- returned value is allocated on the secondary stack. Controlled
-- type temporaries need finalization.
elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
return True;
-- Record type
elsif Is_Record_Type (Typ) then
declare
Comp : Entity_Id;
begin
Comp := First_Entity (Typ);
while Present (Comp) loop
if Ekind (Comp) = E_Component then
-- ???It's not clear we need a full recursive call to
-- Old_Requires_Transient_Scope here. Note that the
-- following can't happen.
pragma Assert (Is_Definite_Subtype (Etype (Comp)));
pragma Assert (not Has_Controlled_Component (Etype (Comp)));
if Old_Requires_Transient_Scope (Etype (Comp)) then
return True;
end if;
end if;
Next_Entity (Comp);
end loop;
end;
return False;
-- String literal types never require transient scope
elsif Ekind (Typ) = E_String_Literal_Subtype then
return False;
-- Array type. Note that we already know that this is a constrained
-- array, since unconstrained arrays will fail the indefinite test.
elsif Is_Array_Type (Typ) then
-- If component type requires a transient scope, the array does too
if Old_Requires_Transient_Scope (Component_Type (Typ)) then
return True;
-- Otherwise, we only need a transient scope if the size depends on
-- the value of one or more discriminants.
else
return Size_Depends_On_Discriminant (Typ);
end if;
-- All other cases do not require a transient scope
else
pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
return False;
end if;
end Old_Requires_Transient_Scope;
---------------------------------
-- Original_Aspect_Pragma_Name --
---------------------------------
function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
Item : Node_Id;
Item_Nam : Name_Id;
begin
pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
Item := N;
-- The pragma was generated to emulate an aspect, use the original
-- aspect specification.
if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
Item := Corresponding_Aspect (Item);
end if;
-- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
-- Post and Post_Class rewrite their pragma identifier to preserve the
-- original name.
-- ??? this is kludgey
if Nkind (Item) = N_Pragma then
Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
else
pragma Assert (Nkind (Item) = N_Aspect_Specification);
Item_Nam := Chars (Identifier (Item));
end if;
-- Deal with 'Class by converting the name to its _XXX form
if Class_Present (Item) then
if Item_Nam = Name_Invariant then
Item_Nam := Name_uInvariant;
elsif Item_Nam = Name_Post then
Item_Nam := Name_uPost;
elsif Item_Nam = Name_Pre then
Item_Nam := Name_uPre;
elsif Nam_In (Item_Nam, Name_Type_Invariant,
Name_Type_Invariant_Class)
then
Item_Nam := Name_uType_Invariant;
-- Nothing to do for other cases (e.g. a Check that derived from
-- Pre_Class and has the flag set). Also we do nothing if the name
-- is already in special _xxx form.
end if;
end if;
return Item_Nam;
end Original_Aspect_Pragma_Name;
--------------------------------------
-- Original_Corresponding_Operation --
--------------------------------------
function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
is
Typ : constant Entity_Id := Find_Dispatching_Type (S);
begin
-- If S is an inherited primitive S2 the original corresponding
-- operation of S is the original corresponding operation of S2
if Present (Alias (S))
and then Find_Dispatching_Type (Alias (S)) /= Typ
then
return Original_Corresponding_Operation (Alias (S));
-- If S overrides an inherited subprogram S2 the original corresponding
-- operation of S is the original corresponding operation of S2
elsif Present (Overridden_Operation (S)) then
return Original_Corresponding_Operation (Overridden_Operation (S));
-- otherwise it is S itself
else
return S;
end if;
end Original_Corresponding_Operation;
-------------------
-- Output_Entity --
-------------------
procedure Output_Entity (Id : Entity_Id) is
Scop : Entity_Id;
begin
Scop := Scope (Id);
-- The entity may lack a scope when it is in the process of being
-- analyzed. Use the current scope as an approximation.
if No (Scop) then
Scop := Current_Scope;
end if;
Output_Name (Chars (Id), Scop);
end Output_Entity;
-----------------
-- Output_Name --
-----------------
procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
begin
Write_Str
(Get_Name_String
(Get_Qualified_Name
(Nam => Nam,
Suffix => No_Name,
Scop => Scop)));
Write_Eol;
end Output_Name;
----------------------
-- Policy_In_Effect --
----------------------
function Policy_In_Effect (Policy : Name_Id) return Name_Id is
function Policy_In_List (List : Node_Id) return Name_Id;
-- Determine the mode of a policy in a N_Pragma list
--------------------
-- Policy_In_List --
--------------------
function Policy_In_List (List : Node_Id) return Name_Id is
Arg1 : Node_Id;
Arg2 : Node_Id;
Prag : Node_Id;
begin
Prag := List;
while Present (Prag) loop
Arg1 := First (Pragma_Argument_Associations (Prag));
Arg2 := Next (Arg1);
Arg1 := Get_Pragma_Arg (Arg1);
Arg2 := Get_Pragma_Arg (Arg2);
-- The current Check_Policy pragma matches the requested policy or
-- appears in the single argument form (Assertion, policy_id).
if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
return Chars (Arg2);
end if;
Prag := Next_Pragma (Prag);
end loop;
return No_Name;
end Policy_In_List;
-- Local variables
Kind : Name_Id;
-- Start of processing for Policy_In_Effect
begin
if not Is_Valid_Assertion_Kind (Policy) then
raise Program_Error;
end if;
-- Inspect all policy pragmas that appear within scopes (if any)
Kind := Policy_In_List (Check_Policy_List);
-- Inspect all configuration policy pragmas (if any)
if Kind = No_Name then
Kind := Policy_In_List (Check_Policy_List_Config);
end if;
-- The context lacks policy pragmas, determine the mode based on whether
-- assertions are enabled at the configuration level. This ensures that
-- the policy is preserved when analyzing generics.
if Kind = No_Name then
if Assertions_Enabled_Config then
Kind := Name_Check;
else
Kind := Name_Ignore;
end if;
end if;
return Kind;
end Policy_In_Effect;
----------------------------------
-- Predicate_Tests_On_Arguments --
----------------------------------
function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
begin
-- Always test predicates on indirect call
if Ekind (Subp) = E_Subprogram_Type then
return True;
-- Do not test predicates on call to generated default Finalize, since
-- we are not interested in whether something we are finalizing (and
-- typically destroying) satisfies its predicates.
elsif Chars (Subp) = Name_Finalize
and then not Comes_From_Source (Subp)
then
return False;
-- Do not test predicates on any internally generated routines
elsif Is_Internal_Name (Chars (Subp)) then
return False;
-- Do not test predicates on call to Init_Proc, since if needed the
-- predicate test will occur at some other point.
elsif Is_Init_Proc (Subp) then
return False;
-- Do not test predicates on call to predicate function, since this
-- would cause infinite recursion.
elsif Ekind (Subp) = E_Function
and then (Is_Predicate_Function (Subp)
or else
Is_Predicate_Function_M (Subp))
then
return False;
-- For now, no other exceptions
else
return True;
end if;
end Predicate_Tests_On_Arguments;
-----------------------
-- Private_Component --
-----------------------
function Private_Component (Type_Id : Entity_Id) return Entity_Id is
Ancestor : constant Entity_Id := Base_Type (Type_Id);
function Trace_Components
(T : Entity_Id;
Check : Boolean) return Entity_Id;
-- Recursive function that does the work, and checks against circular
-- definition for each subcomponent type.
----------------------
-- Trace_Components --
----------------------
function Trace_Components
(T : Entity_Id;
Check : Boolean) return Entity_Id
is
Btype : constant Entity_Id := Base_Type (T);
Component : Entity_Id;
P : Entity_Id;
Candidate : Entity_Id := Empty;
begin
if Check and then Btype = Ancestor then
Error_Msg_N ("circular type definition", Type_Id);
return Any_Type;
end if;
if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
if Present (Full_View (Btype))
and then Is_Record_Type (Full_View (Btype))
and then not Is_Frozen (Btype)
then
-- To indicate that the ancestor depends on a private type, the
-- current Btype is sufficient. However, to check for circular
-- definition we must recurse on the full view.
Candidate := Trace_Components (Full_View (Btype), True);
if Candidate = Any_Type then
return Any_Type;
else
return Btype;
end if;
else
return Btype;
end if;
elsif Is_Array_Type (Btype) then
return Trace_Components (Component_Type (Btype), True);
elsif Is_Record_Type (Btype) then
Component := First_Entity (Btype);
while Present (Component)
and then Comes_From_Source (Component)
loop
-- Skip anonymous types generated by constrained components
if not Is_Type (Component) then
P := Trace_Components (Etype (Component), True);
if Present (P) then
if P = Any_Type then
return P;
else
Candidate := P;
end if;
end if;
end if;
Next_Entity (Component);
end loop;
return Candidate;
else
return Empty;
end if;
end Trace_Components;
-- Start of processing for Private_Component
begin
return Trace_Components (Type_Id, False);
end Private_Component;
---------------------------
-- Primitive_Names_Match --
---------------------------
function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
function Non_Internal_Name (E : Entity_Id) return Name_Id;
-- Given an internal name, returns the corresponding non-internal name
------------------------
-- Non_Internal_Name --
------------------------
function Non_Internal_Name (E : Entity_Id) return Name_Id is
begin
Get_Name_String (Chars (E));
Name_Len := Name_Len - 1;
return Name_Find;
end Non_Internal_Name;
-- Start of processing for Primitive_Names_Match
begin
pragma Assert (Present (E1) and then Present (E2));
return Chars (E1) = Chars (E2)
or else
(not Is_Internal_Name (Chars (E1))
and then Is_Internal_Name (Chars (E2))
and then Non_Internal_Name (E2) = Chars (E1))
or else
(not Is_Internal_Name (Chars (E2))
and then Is_Internal_Name (Chars (E1))
and then Non_Internal_Name (E1) = Chars (E2))
or else
(Is_Predefined_Dispatching_Operation (E1)
and then Is_Predefined_Dispatching_Operation (E2)
and then Same_TSS (E1, E2))
or else
(Is_Init_Proc (E1) and then Is_Init_Proc (E2));
end Primitive_Names_Match;
-----------------------
-- Process_End_Label --
-----------------------
procedure Process_End_Label
(N : Node_Id;
Typ : Character;
Ent : Entity_Id)
is
Loc : Source_Ptr;
Nam : Node_Id;
Scop : Entity_Id;
Label_Ref : Boolean;
-- Set True if reference to end label itself is required
Endl : Node_Id;
-- Gets set to the operator symbol or identifier that references the
-- entity Ent. For the child unit case, this is the identifier from the
-- designator. For other cases, this is simply Endl.
procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
-- N is an identifier node that appears as a parent unit reference in
-- the case where Ent is a child unit. This procedure generates an
-- appropriate cross-reference entry. E is the corresponding entity.
-------------------------
-- Generate_Parent_Ref --
-------------------------
procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
begin
-- If names do not match, something weird, skip reference
if Chars (E) = Chars (N) then
-- Generate the reference. We do NOT consider this as a reference
-- for unreferenced symbol purposes.
Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
if Style_Check then
Style.Check_Identifier (N, E);
end if;
end if;
end Generate_Parent_Ref;
-- Start of processing for Process_End_Label
begin
-- If no node, ignore. This happens in some error situations, and
-- also for some internally generated structures where no end label
-- references are required in any case.
if No (N) then
return;
end if;
-- Nothing to do if no End_Label, happens for internally generated
-- constructs where we don't want an end label reference anyway. Also
-- nothing to do if Endl is a string literal, which means there was
-- some prior error (bad operator symbol)
Endl := End_Label (N);
if No (Endl) or else Nkind (Endl) = N_String_Literal then
return;
end if;
-- Reference node is not in extended main source unit
if not In_Extended_Main_Source_Unit (N) then
-- Generally we do not collect references except for the extended
-- main source unit. The one exception is the 'e' entry for a
-- package spec, where it is useful for a client to have the
-- ending information to define scopes.
if Typ /= 'e' then
return;
else
Label_Ref := False;
-- For this case, we can ignore any parent references, but we
-- need the package name itself for the 'e' entry.
if Nkind (Endl) = N_Designator then
Endl := Identifier (Endl);
end if;
end if;
-- Reference is in extended main source unit
else
Label_Ref := True;
-- For designator, generate references for the parent entries
if Nkind (Endl) = N_Designator then
-- Generate references for the prefix if the END line comes from
-- source (otherwise we do not need these references) We climb the
-- scope stack to find the expected entities.
if Comes_From_Source (Endl) then
Nam := Name (Endl);
Scop := Current_Scope;
while Nkind (Nam) = N_Selected_Component loop
Scop := Scope (Scop);
exit when No (Scop);
Generate_Parent_Ref (Selector_Name (Nam), Scop);
Nam := Prefix (Nam);
end loop;
if Present (Scop) then
Generate_Parent_Ref (Nam, Scope (Scop));
end if;
end if;
Endl := Identifier (Endl);
end if;
end if;
-- If the end label is not for the given entity, then either we have
-- some previous error, or this is a generic instantiation for which
-- we do not need to make a cross-reference in this case anyway. In
-- either case we simply ignore the call.
if Chars (Ent) /= Chars (Endl) then
return;
end if;
-- If label was really there, then generate a normal reference and then
-- adjust the location in the end label to point past the name (which
-- should almost always be the semicolon).
Loc := Sloc (Endl);
if Comes_From_Source (Endl) then
-- If a label reference is required, then do the style check and
-- generate an l-type cross-reference entry for the label
if Label_Ref then
if Style_Check then
Style.Check_Identifier (Endl, Ent);
end if;
Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
end if;
-- Set the location to point past the label (normally this will
-- mean the semicolon immediately following the label). This is
-- done for the sake of the 'e' or 't' entry generated below.
Get_Decoded_Name_String (Chars (Endl));
Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
else
-- In SPARK mode, no missing label is allowed for packages and
-- subprogram bodies. Detect those cases by testing whether
-- Process_End_Label was called for a body (Typ = 't') or a package.
if Restriction_Check_Required (SPARK_05)
and then (Typ = 't' or else Ekind (Ent) = E_Package)
then
Error_Msg_Node_1 := Endl;
Check_SPARK_05_Restriction
("`END &` required", Endl, Force => True);
end if;
end if;
-- Now generate the e/t reference
Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
-- Restore Sloc, in case modified above, since we have an identifier
-- and the normal Sloc should be left set in the tree.
Set_Sloc (Endl, Loc);
end Process_End_Label;
--------------------------------
-- Propagate_Concurrent_Flags --
--------------------------------
procedure Propagate_Concurrent_Flags
(Typ : Entity_Id;
Comp_Typ : Entity_Id)
is
begin
if Has_Task (Comp_Typ) then
Set_Has_Task (Typ);
end if;
if Has_Protected (Comp_Typ) then
Set_Has_Protected (Typ);
end if;
if Has_Timing_Event (Comp_Typ) then
Set_Has_Timing_Event (Typ);
end if;
end Propagate_Concurrent_Flags;
------------------------------
-- Propagate_DIC_Attributes --
------------------------------
procedure Propagate_DIC_Attributes
(Typ : Entity_Id;
From_Typ : Entity_Id)
is
DIC_Proc : Entity_Id;
begin
if Present (Typ) and then Present (From_Typ) then
pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
-- Nothing to do if both the source and the destination denote the
-- same type.
if From_Typ = Typ then
return;
end if;
DIC_Proc := DIC_Procedure (From_Typ);
-- The setting of the attributes is intentionally conservative. This
-- prevents accidental clobbering of enabled attributes.
if Has_Inherited_DIC (From_Typ)
and then not Has_Inherited_DIC (Typ)
then
Set_Has_Inherited_DIC (Typ);
end if;
if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
Set_Has_Own_DIC (Typ);
end if;
if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
Set_DIC_Procedure (Typ, DIC_Proc);
end if;
end if;
end Propagate_DIC_Attributes;
------------------------------------
-- Propagate_Invariant_Attributes --
------------------------------------
procedure Propagate_Invariant_Attributes
(Typ : Entity_Id;
From_Typ : Entity_Id)
is
Full_IP : Entity_Id;
Part_IP : Entity_Id;
begin
if Present (Typ) and then Present (From_Typ) then
pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
-- Nothing to do if both the source and the destination denote the
-- same type.
if From_Typ = Typ then
return;
end if;
Full_IP := Invariant_Procedure (From_Typ);
Part_IP := Partial_Invariant_Procedure (From_Typ);
-- The setting of the attributes is intentionally conservative. This
-- prevents accidental clobbering of enabled attributes.
if Has_Inheritable_Invariants (From_Typ)
and then not Has_Inheritable_Invariants (Typ)
then
Set_Has_Inheritable_Invariants (Typ, True);
end if;
if Has_Inherited_Invariants (From_Typ)
and then not Has_Inherited_Invariants (Typ)
then
Set_Has_Inherited_Invariants (Typ, True);
end if;
if Has_Own_Invariants (From_Typ)
and then not Has_Own_Invariants (Typ)
then
Set_Has_Own_Invariants (Typ, True);
end if;
if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
Set_Invariant_Procedure (Typ, Full_IP);
end if;
if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
then
Set_Partial_Invariant_Procedure (Typ, Part_IP);
end if;
end if;
end Propagate_Invariant_Attributes;
---------------------------------------
-- Record_Possible_Part_Of_Reference --
---------------------------------------
procedure Record_Possible_Part_Of_Reference
(Var_Id : Entity_Id;
Ref : Node_Id)
is
Encap : constant Entity_Id := Encapsulating_State (Var_Id);
Refs : Elist_Id;
begin
-- The variable is a constituent of a single protected/task type. Such
-- a variable acts as a component of the type and must appear within a
-- specific region (SPARK RM 9.3). Instead of recording the reference,
-- verify its legality now.
if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
Check_Part_Of_Reference (Var_Id, Ref);
-- The variable is subject to pragma Part_Of and may eventually become a
-- constituent of a single protected/task type. Record the reference to
-- verify its placement when the contract of the variable is analyzed.
elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
Refs := Part_Of_References (Var_Id);
if No (Refs) then
Refs := New_Elmt_List;
Set_Part_Of_References (Var_Id, Refs);
end if;
Append_Elmt (Ref, Refs);
end if;
end Record_Possible_Part_Of_Reference;
----------------
-- Referenced --
----------------
function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
Seen : Boolean := False;
function Is_Reference (N : Node_Id) return Traverse_Result;
-- Determine whether node N denotes a reference to Id. If this is the
-- case, set global flag Seen to True and stop the traversal.
------------------
-- Is_Reference --
------------------
function Is_Reference (N : Node_Id) return Traverse_Result is
begin
if Is_Entity_Name (N)
and then Present (Entity (N))
and then Entity (N) = Id
then
Seen := True;
return Abandon;
else
return OK;
end if;
end Is_Reference;
procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
-- Start of processing for Referenced
begin
Inspect_Expression (Expr);
return Seen;
end Referenced;
------------------------------------
-- References_Generic_Formal_Type --
------------------------------------
function References_Generic_Formal_Type (N : Node_Id) return Boolean is
function Process (N : Node_Id) return Traverse_Result;
-- Process one node in search for generic formal type
-------------
-- Process --
-------------
function Process (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) in N_Has_Entity then
declare
E : constant Entity_Id := Entity (N);
begin
if Present (E) then
if Is_Generic_Type (E) then
return Abandon;
elsif Present (Etype (E))
and then Is_Generic_Type (Etype (E))
then
return Abandon;
end if;
end if;
end;
end if;
return Atree.OK;
end Process;
function Traverse is new Traverse_Func (Process);
-- Traverse tree to look for generic type
begin
if Inside_A_Generic then
return Traverse (N) = Abandon;
else
return False;
end if;
end References_Generic_Formal_Type;
--------------------
-- Remove_Homonym --
--------------------
procedure Remove_Homonym (E : Entity_Id) is
Prev : Entity_Id := Empty;
H : Entity_Id;
begin
if E = Current_Entity (E) then
if Present (Homonym (E)) then
Set_Current_Entity (Homonym (E));
else
Set_Name_Entity_Id (Chars (E), Empty);
end if;
else
H := Current_Entity (E);
while Present (H) and then H /= E loop
Prev := H;
H := Homonym (H);
end loop;
-- If E is not on the homonym chain, nothing to do
if Present (H) then
Set_Homonym (Prev, Homonym (E));
end if;
end if;
end Remove_Homonym;
------------------------------
-- Remove_Overloaded_Entity --
------------------------------
procedure Remove_Overloaded_Entity (Id : Entity_Id) is
procedure Remove_Primitive_Of (Typ : Entity_Id);
-- Remove primitive subprogram Id from the list of primitives that
-- belong to type Typ.
-------------------------
-- Remove_Primitive_Of --
-------------------------
procedure Remove_Primitive_Of (Typ : Entity_Id) is
Prims : Elist_Id;
begin
if Is_Tagged_Type (Typ) then
Prims := Direct_Primitive_Operations (Typ);
if Present (Prims) then
Remove (Prims, Id);
end if;
end if;
end Remove_Primitive_Of;
-- Local variables
Scop : constant Entity_Id := Scope (Id);
Formal : Entity_Id;
Prev_Id : Entity_Id;
-- Start of processing for Remove_Overloaded_Entity
begin
-- Remove the entity from the homonym chain. When the entity is the
-- head of the chain, associate the entry in the name table with its
-- homonym effectively making it the new head of the chain.
if Current_Entity (Id) = Id then
Set_Name_Entity_Id (Chars (Id), Homonym (Id));
-- Otherwise link the previous and next homonyms
else
Prev_Id := Current_Entity (Id);
while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
Prev_Id := Homonym (Prev_Id);
end loop;
Set_Homonym (Prev_Id, Homonym (Id));
end if;
-- Remove the entity from the scope entity chain. When the entity is
-- the head of the chain, set the next entity as the new head of the
-- chain.
if First_Entity (Scop) = Id then
Prev_Id := Empty;
Set_First_Entity (Scop, Next_Entity (Id));
-- Otherwise the entity is either in the middle of the chain or it acts
-- as its tail. Traverse and link the previous and next entities.
else
Prev_Id := First_Entity (Scop);
while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
Next_Entity (Prev_Id);
end loop;
Set_Next_Entity (Prev_Id, Next_Entity (Id));
end if;
-- Handle the case where the entity acts as the tail of the scope entity
-- chain.
if Last_Entity (Scop) = Id then
Set_Last_Entity (Scop, Prev_Id);
end if;
-- The entity denotes a primitive subprogram. Remove it from the list of
-- primitives of the associated controlling type.
if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
Formal := First_Formal (Id);
while Present (Formal) loop
if Is_Controlling_Formal (Formal) then
Remove_Primitive_Of (Etype (Formal));
exit;
end if;
Next_Formal (Formal);
end loop;
if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
Remove_Primitive_Of (Etype (Id));
end if;
end if;
end Remove_Overloaded_Entity;
---------------------
-- Rep_To_Pos_Flag --
---------------------
function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
begin
return New_Occurrence_Of
(Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
end Rep_To_Pos_Flag;
--------------------
-- Require_Entity --
--------------------
procedure Require_Entity (N : Node_Id) is
begin
if Is_Entity_Name (N) and then No (Entity (N)) then
if Total_Errors_Detected /= 0 then
Set_Entity (N, Any_Id);
else
raise Program_Error;
end if;
end if;
end Require_Entity;
------------------------------
-- Requires_Transient_Scope --
------------------------------
-- A transient scope is required when variable-sized temporaries are
-- allocated on the secondary stack, or when finalization actions must be
-- generated before the next instruction.
function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
begin
if Debug_Flag_QQ then
return Old_Result;
end if;
declare
New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
begin
-- Assert that we're not putting things on the secondary stack if we
-- didn't before; we are trying to AVOID secondary stack when
-- possible.
if not Old_Result then
pragma Assert (not New_Result);
null;
end if;
if New_Result /= Old_Result then
Results_Differ (Id, Old_Result, New_Result);
end if;
return New_Result;
end;
end Requires_Transient_Scope;
--------------------
-- Results_Differ --
--------------------
procedure Results_Differ
(Id : Entity_Id;
Old_Val : Boolean;
New_Val : Boolean)
is
begin
if False then -- False to disable; True for debugging
Treepr.Print_Tree_Node (Id);
if Old_Val = New_Val then
raise Program_Error;
end if;
end if;
end Results_Differ;
--------------------------
-- Reset_Analyzed_Flags --
--------------------------
procedure Reset_Analyzed_Flags (N : Node_Id) is
function Clear_Analyzed (N : Node_Id) return Traverse_Result;
-- Function used to reset Analyzed flags in tree. Note that we do
-- not reset Analyzed flags in entities, since there is no need to
-- reanalyze entities, and indeed, it is wrong to do so, since it
-- can result in generating auxiliary stuff more than once.
--------------------
-- Clear_Analyzed --
--------------------
function Clear_Analyzed (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) not in N_Entity then
Set_Analyzed (N, False);
end if;
return OK;
end Clear_Analyzed;
procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
-- Start of processing for Reset_Analyzed_Flags
begin
Reset_Analyzed (N);
end Reset_Analyzed_Flags;
------------------------
-- Restore_SPARK_Mode --
------------------------
procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
begin
SPARK_Mode := Mode;
end Restore_SPARK_Mode;
--------------------------------
-- Returns_Unconstrained_Type --
--------------------------------
function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
begin
return Ekind (Subp) = E_Function
and then not Is_Scalar_Type (Etype (Subp))
and then not Is_Access_Type (Etype (Subp))
and then not Is_Constrained (Etype (Subp));
end Returns_Unconstrained_Type;
----------------------------
-- Root_Type_Of_Full_View --
----------------------------
function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
Rtyp : constant Entity_Id := Root_Type (T);
begin
-- The root type of the full view may itself be a private type. Keep
-- looking for the ultimate derivation parent.
if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
return Root_Type_Of_Full_View (Full_View (Rtyp));
else
return Rtyp;
end if;
end Root_Type_Of_Full_View;
---------------------------
-- Safe_To_Capture_Value --
---------------------------
function Safe_To_Capture_Value
(N : Node_Id;
Ent : Entity_Id;
Cond : Boolean := False) return Boolean
is
begin
-- The only entities for which we track constant values are variables
-- which are not renamings, constants, out parameters, and in out
-- parameters, so check if we have this case.
-- Note: it may seem odd to track constant values for constants, but in
-- fact this routine is used for other purposes than simply capturing
-- the value. In particular, the setting of Known[_Non]_Null.
if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
or else
Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
then
null;
-- For conditionals, we also allow loop parameters and all formals,
-- including in parameters.
elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
null;
-- For all other cases, not just unsafe, but impossible to capture
-- Current_Value, since the above are the only entities which have
-- Current_Value fields.
else
return False;
end if;
-- Skip if volatile or aliased, since funny things might be going on in
-- these cases which we cannot necessarily track. Also skip any variable
-- for which an address clause is given, or whose address is taken. Also
-- never capture value of library level variables (an attempt to do so
-- can occur in the case of package elaboration code).
if Treat_As_Volatile (Ent)
or else Is_Aliased (Ent)
or else Present (Address_Clause (Ent))
or else Address_Taken (Ent)
or else (Is_Library_Level_Entity (Ent)
and then Ekind (Ent) = E_Variable)
then
return False;
end if;
-- OK, all above conditions are met. We also require that the scope of
-- the reference be the same as the scope of the entity, not counting
-- packages and blocks and loops.
declare
E_Scope : constant Entity_Id := Scope (Ent);
R_Scope : Entity_Id;
begin
R_Scope := Current_Scope;
while R_Scope /= Standard_Standard loop
exit when R_Scope = E_Scope;
if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
return False;
else
R_Scope := Scope (R_Scope);
end if;
end loop;
end;
-- We also require that the reference does not appear in a context
-- where it is not sure to be executed (i.e. a conditional context
-- or an exception handler). We skip this if Cond is True, since the
-- capturing of values from conditional tests handles this ok.
if Cond then
return True;
end if;
declare
Desc : Node_Id;
P : Node_Id;
begin
Desc := N;
-- Seems dubious that case expressions are not handled here ???
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_If_Statement
or else Nkind (P) = N_Case_Statement
or else (Nkind (P) in N_Short_Circuit
and then Desc = Right_Opnd (P))
or else (Nkind (P) = N_If_Expression
and then Desc /= First (Expressions (P)))
or else Nkind (P) = N_Exception_Handler
or else Nkind (P) = N_Selective_Accept
or else Nkind (P) = N_Conditional_Entry_Call
or else Nkind (P) = N_Timed_Entry_Call
or else Nkind (P) = N_Asynchronous_Select
then
return False;
else
Desc := P;
P := Parent (P);
-- A special Ada 2012 case: the original node may be part
-- of the else_actions of a conditional expression, in which
-- case it might not have been expanded yet, and appears in
-- a non-syntactic list of actions. In that case it is clearly
-- not safe to save a value.
if No (P)
and then Is_List_Member (Desc)
and then No (Parent (List_Containing (Desc)))
then
return False;
end if;
end if;
end loop;
end;
-- OK, looks safe to set value
return True;
end Safe_To_Capture_Value;
---------------
-- Same_Name --
---------------
function Same_Name (N1, N2 : Node_Id) return Boolean is
K1 : constant Node_Kind := Nkind (N1);
K2 : constant Node_Kind := Nkind (N2);
begin
if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
then
return Chars (N1) = Chars (N2);
elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
then
return Same_Name (Selector_Name (N1), Selector_Name (N2))
and then Same_Name (Prefix (N1), Prefix (N2));
else
return False;
end if;
end Same_Name;
-----------------
-- Same_Object --
-----------------
function Same_Object (Node1, Node2 : Node_Id) return Boolean is
N1 : constant Node_Id := Original_Node (Node1);
N2 : constant Node_Id := Original_Node (Node2);
-- We do the tests on original nodes, since we are most interested
-- in the original source, not any expansion that got in the way.
K1 : constant Node_Kind := Nkind (N1);
K2 : constant Node_Kind := Nkind (N2);
begin
-- First case, both are entities with same entity
if K1 in N_Has_Entity and then K2 in N_Has_Entity then
declare
EN1 : constant Entity_Id := Entity (N1);
EN2 : constant Entity_Id := Entity (N2);
begin
if Present (EN1) and then Present (EN2)
and then (Ekind_In (EN1, E_Variable, E_Constant)
or else Is_Formal (EN1))
and then EN1 = EN2
then
return True;
end if;
end;
end if;
-- Second case, selected component with same selector, same record
if K1 = N_Selected_Component
and then K2 = N_Selected_Component
and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
then
return Same_Object (Prefix (N1), Prefix (N2));
-- Third case, indexed component with same subscripts, same array
elsif K1 = N_Indexed_Component
and then K2 = N_Indexed_Component
and then Same_Object (Prefix (N1), Prefix (N2))
then
declare
E1, E2 : Node_Id;
begin
E1 := First (Expressions (N1));
E2 := First (Expressions (N2));
while Present (E1) loop
if not Same_Value (E1, E2) then
return False;
else
Next (E1);
Next (E2);
end if;
end loop;
return True;
end;
-- Fourth case, slice of same array with same bounds
elsif K1 = N_Slice
and then K2 = N_Slice
and then Nkind (Discrete_Range (N1)) = N_Range
and then Nkind (Discrete_Range (N2)) = N_Range
and then Same_Value (Low_Bound (Discrete_Range (N1)),
Low_Bound (Discrete_Range (N2)))
and then Same_Value (High_Bound (Discrete_Range (N1)),
High_Bound (Discrete_Range (N2)))
then
return Same_Name (Prefix (N1), Prefix (N2));
-- All other cases, not clearly the same object
else
return False;
end if;
end Same_Object;
---------------
-- Same_Type --
---------------
function Same_Type (T1, T2 : Entity_Id) return Boolean is
begin
if T1 = T2 then
return True;
elsif not Is_Constrained (T1)
and then not Is_Constrained (T2)
and then Base_Type (T1) = Base_Type (T2)
then
return True;
-- For now don't bother with case of identical constraints, to be
-- fiddled with later on perhaps (this is only used for optimization
-- purposes, so it is not critical to do a best possible job)
else
return False;
end if;
end Same_Type;
----------------
-- Same_Value --
----------------
function Same_Value (Node1, Node2 : Node_Id) return Boolean is
begin
if Compile_Time_Known_Value (Node1)
and then Compile_Time_Known_Value (Node2)
and then Expr_Value (Node1) = Expr_Value (Node2)
then
return True;
elsif Same_Object (Node1, Node2) then
return True;
else
return False;
end if;
end Same_Value;
-----------------------------
-- Save_SPARK_Mode_And_Set --
-----------------------------
procedure Save_SPARK_Mode_And_Set
(Context : Entity_Id;
Mode : out SPARK_Mode_Type)
is
begin
-- Save the current mode in effect
Mode := SPARK_Mode;
-- Do not consider illegal or partially decorated constructs
if Ekind (Context) = E_Void or else Error_Posted (Context) then
null;
elsif Present (SPARK_Pragma (Context)) then
SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
end if;
end Save_SPARK_Mode_And_Set;
-------------------------
-- Scalar_Part_Present --
-------------------------
function Scalar_Part_Present (T : Entity_Id) return Boolean is
C : Entity_Id;
begin
if Is_Scalar_Type (T) then
return True;
elsif Is_Array_Type (T) then
return Scalar_Part_Present (Component_Type (T));
elsif Is_Record_Type (T) or else Has_Discriminants (T) then
C := First_Component_Or_Discriminant (T);
while Present (C) loop
if Scalar_Part_Present (Etype (C)) then
return True;
else
Next_Component_Or_Discriminant (C);
end if;
end loop;
end if;
return False;
end Scalar_Part_Present;
------------------------
-- Scope_Is_Transient --
------------------------
function Scope_Is_Transient return Boolean is
begin
return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
end Scope_Is_Transient;
------------------
-- Scope_Within --
------------------
function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := Scope1;
while Scop /= Standard_Standard loop
Scop := Scope (Scop);
if Scop = Scope2 then
return True;
end if;
end loop;
return False;
end Scope_Within;
--------------------------
-- Scope_Within_Or_Same --
--------------------------
function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := Scope1;
while Scop /= Standard_Standard loop
if Scop = Scope2 then
return True;
else
Scop := Scope (Scop);
end if;
end loop;
return False;
end Scope_Within_Or_Same;
--------------------
-- Set_Convention --
--------------------
procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
begin
Basic_Set_Convention (E, Val);
if Is_Type (E)
and then Is_Access_Subprogram_Type (Base_Type (E))
and then Has_Foreign_Convention (E)
then
-- A pragma Convention in an instance may apply to the subtype
-- created for a formal, in which case we have already verified
-- that conventions of actual and formal match and there is nothing
-- to flag on the subtype.
if In_Instance then
null;
else
Set_Can_Use_Internal_Rep (E, False);
end if;
end if;
-- If E is an object or component, and the type of E is an anonymous
-- access type with no convention set, then also set the convention of
-- the anonymous access type. We do not do this for anonymous protected
-- types, since protected types always have the default convention.
if Present (Etype (E))
and then (Is_Object (E)
or else Ekind (E) = E_Component
-- Allow E_Void (happens for pragma Convention appearing
-- in the middle of a record applying to a component)
or else Ekind (E) = E_Void)
then
declare
Typ : constant Entity_Id := Etype (E);
begin
if Ekind_In (Typ, E_Anonymous_Access_Type,
E_Anonymous_Access_Subprogram_Type)
and then not Has_Convention_Pragma (Typ)
then
Basic_Set_Convention (Typ, Val);
Set_Has_Convention_Pragma (Typ);
-- And for the access subprogram type, deal similarly with the
-- designated E_Subprogram_Type if it is also internal (which
-- it always is?)
if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
declare
Dtype : constant Entity_Id := Designated_Type (Typ);
begin
if Ekind (Dtype) = E_Subprogram_Type
and then Is_Itype (Dtype)
and then not Has_Convention_Pragma (Dtype)
then
Basic_Set_Convention (Dtype, Val);
Set_Has_Convention_Pragma (Dtype);
end if;
end;
end if;
end if;
end;
end if;
end Set_Convention;
------------------------
-- Set_Current_Entity --
------------------------
-- The given entity is to be set as the currently visible definition of its
-- associated name (i.e. the Node_Id associated with its name). All we have
-- to do is to get the name from the identifier, and then set the
-- associated Node_Id to point to the given entity.
procedure Set_Current_Entity (E : Entity_Id) is
begin
Set_Name_Entity_Id (Chars (E), E);
end Set_Current_Entity;
---------------------------
-- Set_Debug_Info_Needed --
---------------------------
procedure Set_Debug_Info_Needed (T : Entity_Id) is
procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
-- Used to set debug info in a related node if not set already
--------------------------------------
-- Set_Debug_Info_Needed_If_Not_Set --
--------------------------------------
procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
begin
if Present (E) and then not Needs_Debug_Info (E) then
Set_Debug_Info_Needed (E);
-- For a private type, indicate that the full view also needs
-- debug information.
if Is_Type (E)
and then Is_Private_Type (E)
and then Present (Full_View (E))
then
Set_Debug_Info_Needed (Full_View (E));
end if;
end if;
end Set_Debug_Info_Needed_If_Not_Set;
-- Start of processing for Set_Debug_Info_Needed
begin
-- Nothing to do if argument is Empty or has Debug_Info_Off set, which
-- indicates that Debug_Info_Needed is never required for the entity.
-- Nothing to do if entity comes from a predefined file. Library files
-- are compiled without debug information, but inlined bodies of these
-- routines may appear in user code, and debug information on them ends
-- up complicating debugging the user code.
if No (T)
or else Debug_Info_Off (T)
then
return;
elsif In_Inlined_Body
and then Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Sloc (T))))
then
Set_Needs_Debug_Info (T, False);
end if;
-- Set flag in entity itself. Note that we will go through the following
-- circuitry even if the flag is already set on T. That's intentional,
-- it makes sure that the flag will be set in subsidiary entities.
Set_Needs_Debug_Info (T);
-- Set flag on subsidiary entities if not set already
if Is_Object (T) then
Set_Debug_Info_Needed_If_Not_Set (Etype (T));
elsif Is_Type (T) then
Set_Debug_Info_Needed_If_Not_Set (Etype (T));
if Is_Record_Type (T) then
declare
Ent : Entity_Id := First_Entity (T);
begin
while Present (Ent) loop
Set_Debug_Info_Needed_If_Not_Set (Ent);
Next_Entity (Ent);
end loop;
end;
-- For a class wide subtype, we also need debug information
-- for the equivalent type.
if Ekind (T) = E_Class_Wide_Subtype then
Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
end if;
elsif Is_Array_Type (T) then
Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
declare
Indx : Node_Id := First_Index (T);
begin
while Present (Indx) loop
Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
Indx := Next_Index (Indx);
end loop;
end;
-- For a packed array type, we also need debug information for
-- the type used to represent the packed array. Conversely, we
-- also need it for the former if we need it for the latter.
if Is_Packed (T) then
Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
end if;
if Is_Packed_Array_Impl_Type (T) then
Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
end if;
elsif Is_Access_Type (T) then
Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
elsif Is_Private_Type (T) then
declare
FV : constant Entity_Id := Full_View (T);
begin
Set_Debug_Info_Needed_If_Not_Set (FV);
-- If the full view is itself a derived private type, we need
-- debug information on its underlying type.
if Present (FV)
and then Is_Private_Type (FV)
and then Present (Underlying_Full_View (FV))
then
Set_Needs_Debug_Info (Underlying_Full_View (FV));
end if;
end;
elsif Is_Protected_Type (T) then
Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
elsif Is_Scalar_Type (T) then
-- If the subrange bounds are materialized by dedicated constant
-- objects, also include them in the debug info to make sure the
-- debugger can properly use them.
if Present (Scalar_Range (T))
and then Nkind (Scalar_Range (T)) = N_Range
then
declare
Low_Bnd : constant Node_Id := Type_Low_Bound (T);
High_Bnd : constant Node_Id := Type_High_Bound (T);
begin
if Is_Entity_Name (Low_Bnd) then
Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
end if;
if Is_Entity_Name (High_Bnd) then
Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
end if;
end;
end if;
end if;
end if;
end Set_Debug_Info_Needed;
----------------------------
-- Set_Entity_With_Checks --
----------------------------
procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
Val_Actual : Entity_Id;
Nod : Node_Id;
Post_Node : Node_Id;
begin
-- Unconditionally set the entity
Set_Entity (N, Val);
-- The node to post on is the selector in the case of an expanded name,
-- and otherwise the node itself.
if Nkind (N) = N_Expanded_Name then
Post_Node := Selector_Name (N);
else
Post_Node := N;
end if;
-- Check for violation of No_Fixed_IO
if Restriction_Check_Required (No_Fixed_IO)
and then
((RTU_Loaded (Ada_Text_IO)
and then (Is_RTE (Val, RE_Decimal_IO)
or else
Is_RTE (Val, RE_Fixed_IO)))
or else
(RTU_Loaded (Ada_Wide_Text_IO)
and then (Is_RTE (Val, RO_WT_Decimal_IO)
or else
Is_RTE (Val, RO_WT_Fixed_IO)))
or else
(RTU_Loaded (Ada_Wide_Wide_Text_IO)
and then (Is_RTE (Val, RO_WW_Decimal_IO)
or else
Is_RTE (Val, RO_WW_Fixed_IO))))
-- A special extra check, don't complain about a reference from within
-- the Ada.Interrupts package itself!
and then not In_Same_Extended_Unit (N, Val)
then
Check_Restriction (No_Fixed_IO, Post_Node);
end if;
-- Remaining checks are only done on source nodes. Note that we test
-- for violation of No_Fixed_IO even on non-source nodes, because the
-- cases for checking violations of this restriction are instantiations
-- where the reference in the instance has Comes_From_Source False.
if not Comes_From_Source (N) then
return;
end if;
-- Check for violation of No_Abort_Statements, which is triggered by
-- call to Ada.Task_Identification.Abort_Task.
if Restriction_Check_Required (No_Abort_Statements)
and then (Is_RTE (Val, RE_Abort_Task))
-- A special extra check, don't complain about a reference from within
-- the Ada.Task_Identification package itself!
and then not In_Same_Extended_Unit (N, Val)
then
Check_Restriction (No_Abort_Statements, Post_Node);
end if;
if Val = Standard_Long_Long_Integer then
Check_Restriction (No_Long_Long_Integers, Post_Node);
end if;
-- Check for violation of No_Dynamic_Attachment
if Restriction_Check_Required (No_Dynamic_Attachment)
and then RTU_Loaded (Ada_Interrupts)
and then (Is_RTE (Val, RE_Is_Reserved) or else
Is_RTE (Val, RE_Is_Attached) or else
Is_RTE (Val, RE_Current_Handler) or else
Is_RTE (Val, RE_Attach_Handler) or else
Is_RTE (Val, RE_Exchange_Handler) or else
Is_RTE (Val, RE_Detach_Handler) or else
Is_RTE (Val, RE_Reference))
-- A special extra check, don't complain about a reference from within
-- the Ada.Interrupts package itself!
and then not In_Same_Extended_Unit (N, Val)
then
Check_Restriction (No_Dynamic_Attachment, Post_Node);
end if;
-- Check for No_Implementation_Identifiers
if Restriction_Check_Required (No_Implementation_Identifiers) then
-- We have an implementation defined entity if it is marked as
-- implementation defined, or is defined in a package marked as
-- implementation defined. However, library packages themselves
-- are excluded (we don't want to flag Interfaces itself, just
-- the entities within it).
if (Is_Implementation_Defined (Val)
or else
(Present (Scope (Val))
and then Is_Implementation_Defined (Scope (Val))))
and then not (Ekind_In (Val, E_Package, E_Generic_Package)
and then Is_Library_Level_Entity (Val))
then
Check_Restriction (No_Implementation_Identifiers, Post_Node);
end if;
end if;
-- Do the style check
if Style_Check
and then not Suppress_Style_Checks (Val)
and then not In_Instance
then
if Nkind (N) = N_Identifier then
Nod := N;
elsif Nkind (N) = N_Expanded_Name then
Nod := Selector_Name (N);
else
return;
end if;
-- A special situation arises for derived operations, where we want
-- to do the check against the parent (since the Sloc of the derived
-- operation points to the derived type declaration itself).
Val_Actual := Val;
while not Comes_From_Source (Val_Actual)
and then Nkind (Val_Actual) in N_Entity
and then (Ekind (Val_Actual) = E_Enumeration_Literal
or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
and then Present (Alias (Val_Actual))
loop
Val_Actual := Alias (Val_Actual);
end loop;
-- Renaming declarations for generic actuals do not come from source,
-- and have a different name from that of the entity they rename, so
-- there is no style check to perform here.
if Chars (Nod) = Chars (Val_Actual) then
Style.Check_Identifier (Nod, Val_Actual);
end if;
end if;
Set_Entity (N, Val);
end Set_Entity_With_Checks;
------------------------
-- Set_Name_Entity_Id --
------------------------
procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
begin
Set_Name_Table_Int (Id, Int (Val));
end Set_Name_Entity_Id;
---------------------
-- Set_Next_Actual --
---------------------
procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
begin
if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
end if;
end Set_Next_Actual;
----------------------------------
-- Set_Optimize_Alignment_Flags --
----------------------------------
procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
begin
if Optimize_Alignment = 'S' then
Set_Optimize_Alignment_Space (E);
elsif Optimize_Alignment = 'T' then
Set_Optimize_Alignment_Time (E);
end if;
end Set_Optimize_Alignment_Flags;
-----------------------
-- Set_Public_Status --
-----------------------
procedure Set_Public_Status (Id : Entity_Id) is
S : constant Entity_Id := Current_Scope;
function Within_HSS_Or_If (E : Entity_Id) return Boolean;
-- Determines if E is defined within handled statement sequence or
-- an if statement, returns True if so, False otherwise.
----------------------
-- Within_HSS_Or_If --
----------------------
function Within_HSS_Or_If (E : Entity_Id) return Boolean is
N : Node_Id;
begin
N := Declaration_Node (E);
loop
N := Parent (N);
if No (N) then
return False;
elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
N_If_Statement)
then
return True;
end if;
end loop;
end Within_HSS_Or_If;
-- Start of processing for Set_Public_Status
begin
-- Everything in the scope of Standard is public
if S = Standard_Standard then
Set_Is_Public (Id);
-- Entity is definitely not public if enclosing scope is not public
elsif not Is_Public (S) then
return;
-- An object or function declaration that occurs in a handled sequence
-- of statements or within an if statement is the declaration for a
-- temporary object or local subprogram generated by the expander. It
-- never needs to be made public and furthermore, making it public can
-- cause back end problems.
elsif Nkind_In (Parent (Id), N_Object_Declaration,
N_Function_Specification)
and then Within_HSS_Or_If (Id)
then
return;
-- Entities in public packages or records are public
elsif Ekind (S) = E_Package or Is_Record_Type (S) then
Set_Is_Public (Id);
-- The bounds of an entry family declaration can generate object
-- declarations that are visible to the back-end, e.g. in the
-- the declaration of a composite type that contains tasks.
elsif Is_Concurrent_Type (S)
and then not Has_Completion (S)
and then Nkind (Parent (Id)) = N_Object_Declaration
then
Set_Is_Public (Id);
end if;
end Set_Public_Status;
-----------------------------
-- Set_Referenced_Modified --
-----------------------------
procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
Pref : Node_Id;
begin
-- Deal with indexed or selected component where prefix is modified
if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
Pref := Prefix (N);
-- If prefix is access type, then it is the designated object that is
-- being modified, which means we have no entity to set the flag on.
if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
return;
-- Otherwise chase the prefix
else
Set_Referenced_Modified (Pref, Out_Param);
end if;
-- Otherwise see if we have an entity name (only other case to process)
elsif Is_Entity_Name (N) and then Present (Entity (N)) then
Set_Referenced_As_LHS (Entity (N), not Out_Param);
Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
end if;
end Set_Referenced_Modified;
------------------
-- Set_Rep_Info --
------------------
procedure Set_Rep_Info (T1, T2 : Entity_Id) is
begin
Set_Is_Atomic (T1, Is_Atomic (T2));
Set_Is_Independent (T1, Is_Independent (T2));
Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
if Is_Base_Type (T1) then
Set_Is_Volatile (T1, Is_Volatile (T2));
end if;
end Set_Rep_Info;
----------------------------
-- Set_Scope_Is_Transient --
----------------------------
procedure Set_Scope_Is_Transient (V : Boolean := True) is
begin
Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
end Set_Scope_Is_Transient;
-------------------
-- Set_Size_Info --
-------------------
procedure Set_Size_Info (T1, T2 : Entity_Id) is
begin
-- We copy Esize, but not RM_Size, since in general RM_Size is
-- subtype specific and does not get inherited by all subtypes.
Set_Esize (T1, Esize (T2));
Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
if Is_Discrete_Or_Fixed_Point_Type (T1)
and then
Is_Discrete_Or_Fixed_Point_Type (T2)
then
Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
end if;
Set_Alignment (T1, Alignment (T2));
end Set_Size_Info;
--------------------
-- Static_Boolean --
--------------------
function Static_Boolean (N : Node_Id) return Uint is
begin
Analyze_And_Resolve (N, Standard_Boolean);
if N = Error
or else Error_Posted (N)
or else Etype (N) = Any_Type
then
return No_Uint;
end if;
if Is_OK_Static_Expression (N) then
if not Raises_Constraint_Error (N) then
return Expr_Value (N);
else
return No_Uint;
end if;
elsif Etype (N) = Any_Type then
return No_Uint;
else
Flag_Non_Static_Expr
("static boolean expression required here", N);
return No_Uint;
end if;
end Static_Boolean;
--------------------
-- Static_Integer --
--------------------
function Static_Integer (N : Node_Id) return Uint is
begin
Analyze_And_Resolve (N, Any_Integer);
if N = Error
or else Error_Posted (N)
or else Etype (N) = Any_Type
then
return No_Uint;
end if;
if Is_OK_Static_Expression (N) then
if not Raises_Constraint_Error (N) then
return Expr_Value (N);
else
return No_Uint;
end if;
elsif Etype (N) = Any_Type then
return No_Uint;
else
Flag_Non_Static_Expr
("static integer expression required here", N);
return No_Uint;
end if;
end Static_Integer;
--------------------------
-- Statically_Different --
--------------------------
function Statically_Different (E1, E2 : Node_Id) return Boolean is
R1 : constant Node_Id := Get_Referenced_Object (E1);
R2 : constant Node_Id := Get_Referenced_Object (E2);
begin
return Is_Entity_Name (R1)
and then Is_Entity_Name (R2)
and then Entity (R1) /= Entity (R2)
and then not Is_Formal (Entity (R1))
and then not Is_Formal (Entity (R2));
end Statically_Different;
--------------------------------------
-- Subject_To_Loop_Entry_Attributes --
--------------------------------------
function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
Stmt : Node_Id;
begin
Stmt := N;
-- The expansion mechanism transform a loop subject to at least one
-- 'Loop_Entry attribute into a conditional block. Infinite loops lack
-- the conditional part.
if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
and then Nkind (Original_Node (N)) = N_Loop_Statement
then
Stmt := Original_Node (N);
end if;
return
Nkind (Stmt) = N_Loop_Statement
and then Present (Identifier (Stmt))
and then Present (Entity (Identifier (Stmt)))
and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
end Subject_To_Loop_Entry_Attributes;
-----------------------------
-- Subprogram_Access_Level --
-----------------------------
function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
begin
if Present (Alias (Subp)) then
return Subprogram_Access_Level (Alias (Subp));
else
return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
end if;
end Subprogram_Access_Level;
-------------------------------
-- Support_Atomic_Primitives --
-------------------------------
function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
Size : Int;
begin
-- Verify the alignment of Typ is known
if not Known_Alignment (Typ) then
return False;
end if;
if Known_Static_Esize (Typ) then
Size := UI_To_Int (Esize (Typ));
-- If the Esize (Object_Size) is unknown at compile time, look at the
-- RM_Size (Value_Size) which may have been set by an explicit rep item.
elsif Known_Static_RM_Size (Typ) then
Size := UI_To_Int (RM_Size (Typ));
-- Otherwise, the size is considered to be unknown.
else
return False;
end if;
-- Check that the size of the component is 8, 16, 32, or 64 bits and
-- that Typ is properly aligned.
case Size is
when 8 | 16 | 32 | 64 =>
return Size = UI_To_Int (Alignment (Typ)) * 8;
when others =>
return False;
end case;
end Support_Atomic_Primitives;
-----------------
-- Trace_Scope --
-----------------
procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
begin
if Debug_Flag_W then
for J in 0 .. Scope_Stack.Last loop
Write_Str (" ");
end loop;
Write_Str (Msg);
Write_Name (Chars (E));
Write_Str (" from ");
Write_Location (Sloc (N));
Write_Eol;
end if;
end Trace_Scope;
-----------------------
-- Transfer_Entities --
-----------------------
procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
procedure Set_Public_Status_Of (Id : Entity_Id);
-- Set the Is_Public attribute of arbitrary entity Id by calling routine
-- Set_Public_Status. If successfull and Id denotes a record type, set
-- the Is_Public attribute of its fields.
--------------------------
-- Set_Public_Status_Of --
--------------------------
procedure Set_Public_Status_Of (Id : Entity_Id) is
Field : Entity_Id;
begin
if not Is_Public (Id) then
Set_Public_Status (Id);
-- When the input entity is a public record type, ensure that all
-- its internal fields are also exposed to the linker. The fields
-- of a class-wide type are never made public.
if Is_Public (Id)
and then Is_Record_Type (Id)
and then not Is_Class_Wide_Type (Id)
then
Field := First_Entity (Id);
while Present (Field) loop
Set_Is_Public (Field);
Next_Entity (Field);
end loop;
end if;
end if;
end Set_Public_Status_Of;
-- Local variables
Full_Id : Entity_Id;
Id : Entity_Id;
-- Start of processing for Transfer_Entities
begin
Id := First_Entity (From);
if Present (Id) then
-- Merge the entity chain of the source scope with that of the
-- destination scope.
if Present (Last_Entity (To)) then
Set_Next_Entity (Last_Entity (To), Id);
else
Set_First_Entity (To, Id);
end if;
Set_Last_Entity (To, Last_Entity (From));
-- Inspect the entities of the source scope and update their Scope
-- attribute.
while Present (Id) loop
Set_Scope (Id, To);
Set_Public_Status_Of (Id);
-- Handle an internally generated full view for a private type
if Is_Private_Type (Id)
and then Present (Full_View (Id))
and then Is_Itype (Full_View (Id))
then
Full_Id := Full_View (Id);
Set_Scope (Full_Id, To);
Set_Public_Status_Of (Full_Id);
end if;
Next_Entity (Id);
end loop;
Set_First_Entity (From, Empty);
Set_Last_Entity (From, Empty);
end if;
end Transfer_Entities;
-----------------------
-- Type_Access_Level --
-----------------------
function Type_Access_Level (Typ : Entity_Id) return Uint is
Btyp : Entity_Id;
begin
Btyp := Base_Type (Typ);
-- Ada 2005 (AI-230): For most cases of anonymous access types, we
-- simply use the level where the type is declared. This is true for
-- stand-alone object declarations, and for anonymous access types
-- associated with components the level is the same as that of the
-- enclosing composite type. However, special treatment is needed for
-- the cases of access parameters, return objects of an anonymous access
-- type, and, in Ada 95, access discriminants of limited types.
if Is_Access_Type (Btyp) then
if Ekind (Btyp) = E_Anonymous_Access_Type then
-- If the type is a nonlocal anonymous access type (such as for
-- an access parameter) we treat it as being declared at the
-- library level to ensure that names such as X.all'access don't
-- fail static accessibility checks.
if not Is_Local_Anonymous_Access (Typ) then
return Scope_Depth (Standard_Standard);
-- If this is a return object, the accessibility level is that of
-- the result subtype of the enclosing function. The test here is
-- little complicated, because we have to account for extended
-- return statements that have been rewritten as blocks, in which
-- case we have to find and the Is_Return_Object attribute of the
-- itype's associated object. It would be nice to find a way to
-- simplify this test, but it doesn't seem worthwhile to add a new
-- flag just for purposes of this test. ???
elsif Ekind (Scope (Btyp)) = E_Return_Statement
or else
(Is_Itype (Btyp)
and then Nkind (Associated_Node_For_Itype (Btyp)) =
N_Object_Declaration
and then Is_Return_Object
(Defining_Identifier
(Associated_Node_For_Itype (Btyp))))
then
declare
Scop : Entity_Id;
begin
Scop := Scope (Scope (Btyp));
while Present (Scop) loop
exit when Ekind (Scop) = E_Function;
Scop := Scope (Scop);
end loop;
-- Treat the return object's type as having the level of the
-- function's result subtype (as per RM05-6.5(5.3/2)).
return Type_Access_Level (Etype (Scop));
end;
end if;
end if;
Btyp := Root_Type (Btyp);
-- The accessibility level of anonymous access types associated with
-- discriminants is that of the current instance of the type, and
-- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
-- AI-402: access discriminants have accessibility based on the
-- object rather than the type in Ada 2005, so the above paragraph
-- doesn't apply.
-- ??? Needs completion with rules from AI-416
if Ada_Version <= Ada_95
and then Ekind (Typ) = E_Anonymous_Access_Type
and then Present (Associated_Node_For_Itype (Typ))
and then Nkind (Associated_Node_For_Itype (Typ)) =
N_Discriminant_Specification
then
return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
end if;
end if;
-- Return library level for a generic formal type. This is done because
-- RM(10.3.2) says that "The statically deeper relationship does not
-- apply to ... a descendant of a generic formal type". Rather than
-- checking at each point where a static accessibility check is
-- performed to see if we are dealing with a formal type, this rule is
-- implemented by having Type_Access_Level and Deepest_Type_Access_Level
-- return extreme values for a formal type; Deepest_Type_Access_Level
-- returns Int'Last. By calling the appropriate function from among the
-- two, we ensure that the static accessibility check will pass if we
-- happen to run into a formal type. More specifically, we should call
-- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
-- call occurs as part of a static accessibility check and the error
-- case is the case where the type's level is too shallow (as opposed
-- to too deep).
if Is_Generic_Type (Root_Type (Btyp)) then
return Scope_Depth (Standard_Standard);
end if;
return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
end Type_Access_Level;
------------------------------------
-- Type_Without_Stream_Operation --
------------------------------------
function Type_Without_Stream_Operation
(T : Entity_Id;
Op : TSS_Name_Type := TSS_Null) return Entity_Id
is
BT : constant Entity_Id := Base_Type (T);
Op_Missing : Boolean;
begin
if not Restriction_Active (No_Default_Stream_Attributes) then
return Empty;
end if;
if Is_Elementary_Type (T) then
if Op = TSS_Null then
Op_Missing :=
No (TSS (BT, TSS_Stream_Read))
or else No (TSS (BT, TSS_Stream_Write));
else
Op_Missing := No (TSS (BT, Op));
end if;
if Op_Missing then
return T;
else
return Empty;
end if;
elsif Is_Array_Type (T) then
return Type_Without_Stream_Operation (Component_Type (T), Op);
elsif Is_Record_Type (T) then
declare
Comp : Entity_Id;
C_Typ : Entity_Id;
begin
Comp := First_Component (T);
while Present (Comp) loop
C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
if Present (C_Typ) then
return C_Typ;
end if;
Next_Component (Comp);
end loop;
return Empty;
end;
elsif Is_Private_Type (T) and then Present (Full_View (T)) then
return Type_Without_Stream_Operation (Full_View (T), Op);
else
return Empty;
end if;
end Type_Without_Stream_Operation;
----------------------------
-- Unique_Defining_Entity --
----------------------------
function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
begin
return Unique_Entity (Defining_Entity (N));
end Unique_Defining_Entity;
-------------------
-- Unique_Entity --
-------------------
function Unique_Entity (E : Entity_Id) return Entity_Id is
U : Entity_Id := E;
P : Node_Id;
begin
case Ekind (E) is
when E_Constant =>
if Present (Full_View (E)) then
U := Full_View (E);
end if;
when Entry_Kind =>
if Nkind (Parent (E)) = N_Entry_Body then
declare
Prot_Item : Entity_Id;
Prot_Type : Entity_Id;
begin
if Ekind (E) = E_Entry then
Prot_Type := Scope (E);
-- Bodies of entry families are nested within an extra scope
-- that contains an entry index declaration
else
Prot_Type := Scope (Scope (E));
end if;
pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
-- Traverse the entity list of the protected type and locate
-- an entry declaration which matches the entry body.
Prot_Item := First_Entity (Prot_Type);
while Present (Prot_Item) loop
if Ekind (Prot_Item) in Entry_Kind
and then Corresponding_Body (Parent (Prot_Item)) = E
then
U := Prot_Item;
exit;
end if;
Next_Entity (Prot_Item);
end loop;
end;
end if;
when Formal_Kind =>
if Present (Spec_Entity (E)) then
U := Spec_Entity (E);
end if;
when E_Package_Body =>
P := Parent (E);
if Nkind (P) = N_Defining_Program_Unit_Name then
P := Parent (P);
end if;
if Nkind (P) = N_Package_Body
and then Present (Corresponding_Spec (P))
then
U := Corresponding_Spec (P);
elsif Nkind (P) = N_Package_Body_Stub
and then Present (Corresponding_Spec_Of_Stub (P))
then
U := Corresponding_Spec_Of_Stub (P);
end if;
when E_Protected_Body =>
P := Parent (E);
if Nkind (P) = N_Protected_Body
and then Present (Corresponding_Spec (P))
then
U := Corresponding_Spec (P);
elsif Nkind (P) = N_Protected_Body_Stub
and then Present (Corresponding_Spec_Of_Stub (P))
then
U := Corresponding_Spec_Of_Stub (P);
if Is_Single_Protected_Object (U) then
U := Etype (U);
end if;
end if;
when E_Subprogram_Body =>
P := Parent (E);
if Nkind (P) = N_Defining_Program_Unit_Name then
P := Parent (P);
end if;
P := Parent (P);
if Nkind (P) = N_Subprogram_Body
and then Present (Corresponding_Spec (P))
then
U := Corresponding_Spec (P);
elsif Nkind (P) = N_Subprogram_Body_Stub
and then Present (Corresponding_Spec_Of_Stub (P))
then
U := Corresponding_Spec_Of_Stub (P);
elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
U := Corresponding_Spec (P);
end if;
when E_Task_Body =>
P := Parent (E);
if Nkind (P) = N_Task_Body
and then Present (Corresponding_Spec (P))
then
U := Corresponding_Spec (P);
elsif Nkind (P) = N_Task_Body_Stub
and then Present (Corresponding_Spec_Of_Stub (P))
then
U := Corresponding_Spec_Of_Stub (P);
if Is_Single_Task_Object (U) then
U := Etype (U);
end if;
end if;
when Type_Kind =>
if Present (Full_View (E)) then
U := Full_View (E);
end if;
when others =>
null;
end case;
return U;
end Unique_Entity;
-----------------
-- Unique_Name --
-----------------
function Unique_Name (E : Entity_Id) return String is
-- Names in E_Subprogram_Body or E_Package_Body entities are not
-- reliable, as they may not include the overloading suffix. Instead,
-- when looking for the name of E or one of its enclosing scope, we get
-- the name of the corresponding Unique_Entity.
U : constant Entity_Id := Unique_Entity (E);
function This_Name return String;
---------------
-- This_Name --
---------------
function This_Name return String is
begin
return Get_Name_String (Chars (U));
end This_Name;
-- Start of processing for Unique_Name
begin
if E = Standard_Standard
or else Has_Fully_Qualified_Name (E)
then
return This_Name;
elsif Ekind (E) = E_Enumeration_Literal then
return Unique_Name (Etype (E)) & "__" & This_Name;
else
declare
S : constant Entity_Id := Scope (U);
pragma Assert (Present (S));
begin
-- Prefix names of predefined types with standard__, but leave
-- names of user-defined packages and subprograms without prefix
-- (even if technically they are nested in the Standard package).
if S = Standard_Standard then
if Ekind (U) = E_Package or else Is_Subprogram (U) then
return This_Name;
else
return Unique_Name (S) & "__" & This_Name;
end if;
-- For intances of generic subprograms use the name of the related
-- instace and skip the scope of its wrapper package.
elsif Is_Wrapper_Package (S) then
pragma Assert (Scope (S) = Scope (Related_Instance (S)));
-- Wrapper package and the instantiation are in the same scope
declare
Enclosing_Name : constant String :=
Unique_Name (Scope (S)) & "__" &
Get_Name_String (Chars (Related_Instance (S)));
begin
if Is_Subprogram (U)
and then not Is_Generic_Actual_Subprogram (U)
then
return Enclosing_Name;
else
return Enclosing_Name & "__" & This_Name;
end if;
end;
else
return Unique_Name (S) & "__" & This_Name;
end if;
end;
end if;
end Unique_Name;
---------------------
-- Unit_Is_Visible --
---------------------
function Unit_Is_Visible (U : Entity_Id) return Boolean is
Curr : constant Node_Id := Cunit (Current_Sem_Unit);
Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
-- For a child unit, check whether unit appears in a with_clause
-- of a parent.
function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
-- Scan the context clause of one compilation unit looking for a
-- with_clause for the unit in question.
----------------------------
-- Unit_In_Parent_Context --
----------------------------
function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
begin
if Unit_In_Context (Par_Unit) then
return True;
elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
else
return False;
end if;
end Unit_In_Parent_Context;
---------------------
-- Unit_In_Context --
---------------------
function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
Clause : Node_Id;
begin
Clause := First (Context_Items (Comp_Unit));
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause then
if Library_Unit (Clause) = U then
return True;
-- The with_clause may denote a renaming of the unit we are
-- looking for, eg. Text_IO which renames Ada.Text_IO.
elsif
Renamed_Entity (Entity (Name (Clause))) =
Defining_Entity (Unit (U))
then
return True;
end if;
end if;
Next (Clause);
end loop;
return False;
end Unit_In_Context;
-- Start of processing for Unit_Is_Visible
begin
-- The currrent unit is directly visible
if Curr = U then
return True;
elsif Unit_In_Context (Curr) then
return True;
-- If the current unit is a body, check the context of the spec
elsif Nkind (Unit (Curr)) = N_Package_Body
or else
(Nkind (Unit (Curr)) = N_Subprogram_Body
and then not Acts_As_Spec (Unit (Curr)))
then
if Unit_In_Context (Library_Unit (Curr)) then
return True;
end if;
end if;
-- If the spec is a child unit, examine the parents
if Is_Child_Unit (Curr_Entity) then
if Nkind (Unit (Curr)) in N_Unit_Body then
return
Unit_In_Parent_Context
(Parent_Spec (Unit (Library_Unit (Curr))));
else
return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
end if;
else
return False;
end if;
end Unit_Is_Visible;
------------------------------
-- Universal_Interpretation --
------------------------------
function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
Index : Interp_Index;
It : Interp;
begin
-- The argument may be a formal parameter of an operator or subprogram
-- with multiple interpretations, or else an expression for an actual.
if Nkind (Opnd) = N_Defining_Identifier
or else not Is_Overloaded (Opnd)
then
if Etype (Opnd) = Universal_Integer
or else Etype (Opnd) = Universal_Real
then
return Etype (Opnd);
else
return Empty;
end if;
else
Get_First_Interp (Opnd, Index, It);
while Present (It.Typ) loop
if It.Typ = Universal_Integer
or else It.Typ = Universal_Real
then
return It.Typ;
end if;
Get_Next_Interp (Index, It);
end loop;
return Empty;
end if;
end Universal_Interpretation;
---------------
-- Unqualify --
---------------
function Unqualify (Expr : Node_Id) return Node_Id is
begin
-- Recurse to handle unlikely case of multiple levels of qualification
if Nkind (Expr) = N_Qualified_Expression then
return Unqualify (Expression (Expr));
-- Normal case, not a qualified expression
else
return Expr;
end if;
end Unqualify;
-----------------------
-- Visible_Ancestors --
-----------------------
function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
List_1 : Elist_Id;
List_2 : Elist_Id;
Elmt : Elmt_Id;
begin
pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
-- Collect all the parents and progenitors of Typ. If the full-view of
-- private parents and progenitors is available then it is used to
-- generate the list of visible ancestors; otherwise their partial
-- view is added to the resulting list.
Collect_Parents
(T => Typ,
List => List_1,
Use_Full_View => True);
Collect_Interfaces
(T => Typ,
Ifaces_List => List_2,
Exclude_Parents => True,
Use_Full_View => True);
-- Join the two lists. Avoid duplications because an interface may
-- simultaneously be parent and progenitor of a type.
Elmt := First_Elmt (List_2);
while Present (Elmt) loop
Append_Unique_Elmt (Node (Elmt), List_1);
Next_Elmt (Elmt);
end loop;
return List_1;
end Visible_Ancestors;
----------------------
-- Within_Init_Proc --
----------------------
function Within_Init_Proc return Boolean is
S : Entity_Id;
begin
S := Current_Scope;
while not Is_Overloadable (S) loop
if S = Standard_Standard then
return False;
else
S := Scope (S);
end if;
end loop;
return Is_Init_Proc (S);
end Within_Init_Proc;
------------------
-- Within_Scope --
------------------
function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
begin
return Scope_Within_Or_Same (Scope (E), S);
end Within_Scope;
----------------
-- Wrong_Type --
----------------
procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
Matching_Field : Entity_Id;
-- Entity to give a more precise suggestion on how to write a one-
-- element positional aggregate.
function Has_One_Matching_Field return Boolean;
-- Determines if Expec_Type is a record type with a single component or
-- discriminant whose type matches the found type or is one dimensional
-- array whose component type matches the found type. In the case of
-- one discriminant, we ignore the variant parts. That's not accurate,
-- but good enough for the warning.
----------------------------
-- Has_One_Matching_Field --
----------------------------
function Has_One_Matching_Field return Boolean is
E : Entity_Id;
begin
Matching_Field := Empty;
if Is_Array_Type (Expec_Type)
and then Number_Dimensions (Expec_Type) = 1
and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
then
-- Use type name if available. This excludes multidimensional
-- arrays and anonymous arrays.
if Comes_From_Source (Expec_Type) then
Matching_Field := Expec_Type;
-- For an assignment, use name of target
elsif Nkind (Parent (Expr)) = N_Assignment_Statement
and then Is_Entity_Name (Name (Parent (Expr)))
then
Matching_Field := Entity (Name (Parent (Expr)));
end if;
return True;
elsif not Is_Record_Type (Expec_Type) then
return False;
else
E := First_Entity (Expec_Type);
loop
if No (E) then
return False;
elsif not Ekind_In (E, E_Discriminant, E_Component)
or else Nam_In (Chars (E), Name_uTag, Name_uParent)
then
Next_Entity (E);
else
exit;
end if;
end loop;
if not Covers (Etype (E), Found_Type) then
return False;
elsif Present (Next_Entity (E))
and then (Ekind (E) = E_Component
or else Ekind (Next_Entity (E)) = E_Discriminant)
then
return False;
else
Matching_Field := E;
return True;
end if;
end if;
end Has_One_Matching_Field;
-- Start of processing for Wrong_Type
begin
-- Don't output message if either type is Any_Type, or if a message
-- has already been posted for this node. We need to do the latter
-- check explicitly (it is ordinarily done in Errout), because we
-- are using ! to force the output of the error messages.
if Expec_Type = Any_Type
or else Found_Type = Any_Type
or else Error_Posted (Expr)
then
return;
-- If one of the types is a Taft-Amendment type and the other it its
-- completion, it must be an illegal use of a TAT in the spec, for
-- which an error was already emitted. Avoid cascaded errors.
elsif Is_Incomplete_Type (Expec_Type)
and then Has_Completion_In_Body (Expec_Type)
and then Full_View (Expec_Type) = Etype (Expr)
then
return;
elsif Is_Incomplete_Type (Etype (Expr))
and then Has_Completion_In_Body (Etype (Expr))
and then Full_View (Etype (Expr)) = Expec_Type
then
return;
-- In an instance, there is an ongoing problem with completion of
-- type derived from private types. Their structure is what Gigi
-- expects, but the Etype is the parent type rather than the
-- derived private type itself. Do not flag error in this case. The
-- private completion is an entity without a parent, like an Itype.
-- Similarly, full and partial views may be incorrect in the instance.
-- There is no simple way to insure that it is consistent ???
-- A similar view discrepancy can happen in an inlined body, for the
-- same reason: inserted body may be outside of the original package
-- and only partial views are visible at the point of insertion.
elsif In_Instance or else In_Inlined_Body then
if Etype (Etype (Expr)) = Etype (Expected_Type)
and then
(Has_Private_Declaration (Expected_Type)
or else Has_Private_Declaration (Etype (Expr)))
and then No (Parent (Expected_Type))
then
return;
elsif Nkind (Parent (Expr)) = N_Qualified_Expression
and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
then
return;
elsif Is_Private_Type (Expected_Type)
and then Present (Full_View (Expected_Type))
and then Covers (Full_View (Expected_Type), Etype (Expr))
then
return;
-- Conversely, type of expression may be the private one
elsif Is_Private_Type (Base_Type (Etype (Expr)))
and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
then
return;
end if;
end if;
-- An interesting special check. If the expression is parenthesized
-- and its type corresponds to the type of the sole component of the
-- expected record type, or to the component type of the expected one
-- dimensional array type, then assume we have a bad aggregate attempt.
if Nkind (Expr) in N_Subexpr
and then Paren_Count (Expr) /= 0
and then Has_One_Matching_Field
then
Error_Msg_N ("positional aggregate cannot have one component", Expr);
if Present (Matching_Field) then
if Is_Array_Type (Expec_Type) then
Error_Msg_NE
("\write instead `&''First ='> ...`", Expr, Matching_Field);
else
Error_Msg_NE
("\write instead `& ='> ...`", Expr, Matching_Field);
end if;
end if;
-- Another special check, if we are looking for a pool-specific access
-- type and we found an E_Access_Attribute_Type, then we have the case
-- of an Access attribute being used in a context which needs a pool-
-- specific type, which is never allowed. The one extra check we make
-- is that the expected designated type covers the Found_Type.
elsif Is_Access_Type (Expec_Type)
and then Ekind (Found_Type) = E_Access_Attribute_Type
and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
and then Covers
(Designated_Type (Expec_Type), Designated_Type (Found_Type))
then
Error_Msg_N -- CODEFIX
("result must be general access type!", Expr);
Error_Msg_NE -- CODEFIX
("add ALL to }!", Expr, Expec_Type);
-- Another special check, if the expected type is an integer type,
-- but the expression is of type System.Address, and the parent is
-- an addition or subtraction operation whose left operand is the
-- expression in question and whose right operand is of an integral
-- type, then this is an attempt at address arithmetic, so give
-- appropriate message.
elsif Is_Integer_Type (Expec_Type)
and then Is_RTE (Found_Type, RE_Address)
and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
and then Expr = Left_Opnd (Parent (Expr))
and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
then
Error_Msg_N
("address arithmetic not predefined in package System",
Parent (Expr));
Error_Msg_N
("\possible missing with/use of System.Storage_Elements",
Parent (Expr));
return;
-- If the expected type is an anonymous access type, as for access
-- parameters and discriminants, the error is on the designated types.
elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
if Comes_From_Source (Expec_Type) then
Error_Msg_NE ("expected}!", Expr, Expec_Type);
else
Error_Msg_NE
("expected an access type with designated}",
Expr, Designated_Type (Expec_Type));
end if;
if Is_Access_Type (Found_Type)
and then not Comes_From_Source (Found_Type)
then
Error_Msg_NE
("\\found an access type with designated}!",
Expr, Designated_Type (Found_Type));
else
if From_Limited_With (Found_Type) then
Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
Error_Msg_Qual_Level := 99;
Error_Msg_NE -- CODEFIX
("\\missing `WITH &;", Expr, Scope (Found_Type));
Error_Msg_Qual_Level := 0;
else
Error_Msg_NE ("found}!", Expr, Found_Type);
end if;
end if;
-- Normal case of one type found, some other type expected
else
-- If the names of the two types are the same, see if some number
-- of levels of qualification will help. Don't try more than three
-- levels, and if we get to standard, it's no use (and probably
-- represents an error in the compiler) Also do not bother with
-- internal scope names.
declare
Expec_Scope : Entity_Id;
Found_Scope : Entity_Id;
begin
Expec_Scope := Expec_Type;
Found_Scope := Found_Type;
for Levels in Nat range 0 .. 3 loop
if Chars (Expec_Scope) /= Chars (Found_Scope) then
Error_Msg_Qual_Level := Levels;
exit;
end if;
Expec_Scope := Scope (Expec_Scope);
Found_Scope := Scope (Found_Scope);
exit when Expec_Scope = Standard_Standard
or else Found_Scope = Standard_Standard
or else not Comes_From_Source (Expec_Scope)
or else not Comes_From_Source (Found_Scope);
end loop;
end;
if Is_Record_Type (Expec_Type)
and then Present (Corresponding_Remote_Type (Expec_Type))
then
Error_Msg_NE ("expected}!", Expr,
Corresponding_Remote_Type (Expec_Type));
else
Error_Msg_NE ("expected}!", Expr, Expec_Type);
end if;
if Is_Entity_Name (Expr)
and then Is_Package_Or_Generic_Package (Entity (Expr))
then
Error_Msg_N ("\\found package name!", Expr);
elsif Is_Entity_Name (Expr)
and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
then
if Ekind (Expec_Type) = E_Access_Subprogram_Type then
Error_Msg_N
("found procedure name, possibly missing Access attribute!",
Expr);
else
Error_Msg_N
("\\found procedure name instead of function!", Expr);
end if;
elsif Nkind (Expr) = N_Function_Call
and then Ekind (Expec_Type) = E_Access_Subprogram_Type
and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
and then No (Parameter_Associations (Expr))
then
Error_Msg_N
("found function name, possibly missing Access attribute!",
Expr);
-- Catch common error: a prefix or infix operator which is not
-- directly visible because the type isn't.
elsif Nkind (Expr) in N_Op
and then Is_Overloaded (Expr)
and then not Is_Immediately_Visible (Expec_Type)
and then not Is_Potentially_Use_Visible (Expec_Type)
and then not In_Use (Expec_Type)
and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
then
Error_Msg_N
("operator of the type is not directly visible!", Expr);
elsif Ekind (Found_Type) = E_Void
and then Present (Parent (Found_Type))
and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
then
Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
else
Error_Msg_NE ("\\found}!", Expr, Found_Type);
end if;
-- A special check for cases like M1 and M2 = 0 where M1 and M2 are
-- of the same modular type, and (M1 and M2) = 0 was intended.
if Expec_Type = Standard_Boolean
and then Is_Modular_Integer_Type (Found_Type)
and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
then
declare
Op : constant Node_Id := Right_Opnd (Parent (Expr));
L : constant Node_Id := Left_Opnd (Op);
R : constant Node_Id := Right_Opnd (Op);
begin
-- The case for the message is when the left operand of the
-- comparison is the same modular type, or when it is an
-- integer literal (or other universal integer expression),
-- which would have been typed as the modular type if the
-- parens had been there.
if (Etype (L) = Found_Type
or else
Etype (L) = Universal_Integer)
and then Is_Integer_Type (Etype (R))
then
Error_Msg_N
("\\possible missing parens for modular operation", Expr);
end if;
end;
end if;
-- Reset error message qualification indication
Error_Msg_Qual_Level := 0;
end if;
end Wrong_Type;
--------------------------------
-- Yields_Synchronized_Object --
--------------------------------
function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
Has_Sync_Comp : Boolean := False;
Id : Entity_Id;
begin
-- An array type yields a synchronized object if its component type
-- yields a synchronized object.
if Is_Array_Type (Typ) then
return Yields_Synchronized_Object (Component_Type (Typ));
-- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
-- yields a synchronized object by default.
elsif Is_Descendant_Of_Suspension_Object (Typ) then
return True;
-- A protected type yields a synchronized object by default
elsif Is_Protected_Type (Typ) then
return True;
-- A record type or type extension yields a synchronized object when its
-- discriminants (if any) lack default values and all components are of
-- a type that yelds a synchronized object.
elsif Is_Record_Type (Typ) then
-- Inspect all entities defined in the scope of the type, looking for
-- components of a type that does not yeld a synchronized object or
-- for discriminants with default values.
Id := First_Entity (Typ);
while Present (Id) loop
if Comes_From_Source (Id) then
if Ekind (Id) = E_Component then
if Yields_Synchronized_Object (Etype (Id)) then
Has_Sync_Comp := True;
-- The component does not yield a synchronized object
else
return False;
end if;
elsif Ekind (Id) = E_Discriminant
and then Present (Expression (Parent (Id)))
then
return False;
end if;
end if;
Next_Entity (Id);
end loop;
-- Ensure that the parent type of a type extension yields a
-- synchronized object.
if Etype (Typ) /= Typ
and then not Yields_Synchronized_Object (Etype (Typ))
then
return False;
end if;
-- If we get here, then all discriminants lack default values and all
-- components are of a type that yields a synchronized object.
return Has_Sync_Comp;
-- A synchronized interface type yields a synchronized object by default
elsif Is_Synchronized_Interface (Typ) then
return True;
-- A task type yelds a synchronized object by default
elsif Is_Task_Type (Typ) then
return True;
-- Otherwise the type does not yield a synchronized object
else
return False;
end if;
end Yields_Synchronized_Object;
---------------------------
-- Yields_Universal_Type --
---------------------------
function Yields_Universal_Type (N : Node_Id) return Boolean is
begin
-- Integer and real literals are of a universal type
if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
return True;
-- The values of certain attributes are of a universal type
elsif Nkind (N) = N_Attribute_Reference then
return
Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
-- ??? There are possibly other cases to consider
else
return False;
end if;
end Yields_Universal_Type;
end Sem_Util;
|
-- This spec has been automatically generated from STM32L0x3.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.Firewall is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype FIREWALL_CSSA_ADD_Field is HAL.UInt16;
-- Code segment start address
type FIREWALL_CSSA_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- code segment start address
ADD : FIREWALL_CSSA_ADD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for FIREWALL_CSSA_Register use record
Reserved_0_7 at 0 range 0 .. 7;
ADD at 0 range 8 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype FIREWALL_CSL_LENG_Field is HAL.UInt14;
-- Code segment length
type FIREWALL_CSL_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- code segment length
LENG : FIREWALL_CSL_LENG_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 FIREWALL_CSL_Register use record
Reserved_0_7 at 0 range 0 .. 7;
LENG at 0 range 8 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
subtype FIREWALL_NVDSSA_ADD_Field is HAL.UInt16;
-- Non-volatile data segment start address
type FIREWALL_NVDSSA_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Non-volatile data segment start address
ADD : FIREWALL_NVDSSA_ADD_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for FIREWALL_NVDSSA_Register use record
Reserved_0_7 at 0 range 0 .. 7;
ADD at 0 range 8 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype FIREWALL_NVDSL_LENG_Field is HAL.UInt14;
-- Non-volatile data segment length
type FIREWALL_NVDSL_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Non-volatile data segment length
LENG : FIREWALL_NVDSL_LENG_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 FIREWALL_NVDSL_Register use record
Reserved_0_7 at 0 range 0 .. 7;
LENG at 0 range 8 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
subtype FIREWALL_VDSSA_ADD_Field is HAL.UInt10;
-- Volatile data segment start address
type FIREWALL_VDSSA_Register is record
-- unspecified
Reserved_0_5 : HAL.UInt6 := 16#0#;
-- Volatile data segment start address
ADD : FIREWALL_VDSSA_ADD_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 FIREWALL_VDSSA_Register use record
Reserved_0_5 at 0 range 0 .. 5;
ADD at 0 range 6 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype FIREWALL_VDSL_LENG_Field is HAL.UInt10;
-- Volatile data segment length
type FIREWALL_VDSL_Register is record
-- unspecified
Reserved_0_5 : HAL.UInt6 := 16#0#;
-- Non-volatile data segment length
LENG : FIREWALL_VDSL_LENG_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 FIREWALL_VDSL_Register use record
Reserved_0_5 at 0 range 0 .. 5;
LENG at 0 range 6 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- Configuration register
type FIREWALL_CR_Register is record
-- Firewall pre alarm
FPA : Boolean := False;
-- Volatile data shared
VDS : Boolean := False;
-- Volatile data execution
VDE : 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 FIREWALL_CR_Register use record
FPA at 0 range 0 .. 0;
VDS at 0 range 1 .. 1;
VDE at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Firewall
type Firewall_Peripheral is record
-- Code segment start address
FIREWALL_CSSA : aliased FIREWALL_CSSA_Register;
-- Code segment length
FIREWALL_CSL : aliased FIREWALL_CSL_Register;
-- Non-volatile data segment start address
FIREWALL_NVDSSA : aliased FIREWALL_NVDSSA_Register;
-- Non-volatile data segment length
FIREWALL_NVDSL : aliased FIREWALL_NVDSL_Register;
-- Volatile data segment start address
FIREWALL_VDSSA : aliased FIREWALL_VDSSA_Register;
-- Volatile data segment length
FIREWALL_VDSL : aliased FIREWALL_VDSL_Register;
-- Configuration register
FIREWALL_CR : aliased FIREWALL_CR_Register;
end record
with Volatile;
for Firewall_Peripheral use record
FIREWALL_CSSA at 16#0# range 0 .. 31;
FIREWALL_CSL at 16#4# range 0 .. 31;
FIREWALL_NVDSSA at 16#8# range 0 .. 31;
FIREWALL_NVDSL at 16#C# range 0 .. 31;
FIREWALL_VDSSA at 16#10# range 0 .. 31;
FIREWALL_VDSL at 16#14# range 0 .. 31;
FIREWALL_CR at 16#20# range 0 .. 31;
end record;
-- Firewall
Firewall_Periph : aliased Firewall_Peripheral
with Import, Address => System'To_Address (16#40011C00#);
end STM32_SVD.Firewall;
|
-----------------------------------------------------------------------
-- security-filters-oauth -- OAuth Security filter
-- Copyright (C) 2017, 2018 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 Servlet.Security.Filters.OAuth;
-- The <b>ASF.Security.Filters.OAuth</b> package provides a servlet filter that
-- implements the RFC 6749 "Accessing Protected Resources" part: it extracts the OAuth
-- access token, verifies the grant and the permission. The servlet filter implements
-- the RFC 6750 "OAuth 2.0 Bearer Token Usage".
--
package ASF.Security.Filters.OAuth renames Servlet.Security.Filters.OAuth;
|
-- Copyright 2008-2017 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ident;
procedure Assign is
Q: array (1..5) of Integer := (2, 3, 5, 7, 11);
begin
Q(1) := Ident (Q(3)); -- START
end Assign;
|
------------------------------------------------------------------------------
-- --
-- GNAT SYSTEM UTILITIES --
-- --
-- X N M A K E --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Program to construct the spec and body of the Nmake package
-- Input files:
-- sinfo.ads Spec of Sinfo package
-- nmake.adt Template for Nmake package
-- Output files:
-- nmake.ads Spec of Nmake package
-- nmake.adb Body of Nmake package
-- Note: this program assumes that sinfo.ads has passed the error checks that
-- are carried out by the csinfo utility, so it does not duplicate these
-- checks and assumes that sinfo.ads has the correct form.
-- In the absence of any switches, both the ads and adb files are output.
-- The switch -s or /s indicates that only the ads file is to be output.
-- The switch -b or /b indicates that only the adb file is to be output.
-- If a file name argument is given, then the output is written to this file
-- rather than to nmake.ads or nmake.adb. A file name can only be given if
-- exactly one of the -s or -b options is present.
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Spitbol; use GNAT.Spitbol;
with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
procedure XNmake is
Err : exception;
-- Raised to terminate execution
A : VString := Nul;
Arg : VString := Nul;
Arg_List : VString := Nul;
Comment : VString := Nul;
Default : VString := Nul;
Field : VString := Nul;
Line : VString := Nul;
Node : VString := Nul;
Op_Name : VString := Nul;
Prevl : VString := Nul;
Sinfo_Rev : VString := Nul;
Synonym : VString := Nul;
Temp_Rev : VString := Nul;
X : VString := Nul;
XNmake_Rev : VString := Nul;
Lineno : Natural;
NWidth : Natural;
FileS : VString := V ("nmake.ads");
FileB : VString := V ("nmake.adb");
-- Set to null if corresponding file not to be generated
Given_File : VString := Nul;
-- File name given by command line argument
InS, InT : File_Type;
OutS, OutB : File_Type;
wsp : Pattern := Span (' ' & ASCII.HT);
-- Note: in following patterns, we break up the word revision to
-- avoid RCS getting enthusiastic about updating the reference!
Get_SRev : Pattern := BreakX ('$') & "$Rev" & "ision: " &
Break (' ') * Sinfo_Rev;
GetT_Rev : Pattern := BreakX ('$') & "$Rev" & "ision: " &
Break (' ') * Temp_Rev;
Body_Only : Pattern := BreakX (' ') * X & Span (' ') & "-- body only";
Spec_Only : Pattern := BreakX (' ') * X & Span (' ') & "-- spec only";
Node_Hdr : Pattern := wsp & "-- N_" & Rest * Node;
Punc : Pattern := BreakX (" .,");
Binop : Pattern := wsp & "-- plus fields for binary operator";
Unop : Pattern := wsp & "-- plus fields for unary operator";
Syn : Pattern := wsp & "-- " & Break (' ') * Synonym
& " (" & Break (')') * Field & Rest * Comment;
Templ : Pattern := BreakX ('T') * A & "T e m p l a t e";
Spec : Pattern := BreakX ('S') * A & "S p e c";
Sem_Field : Pattern := BreakX ('-') & "-Sem";
Lib_Field : Pattern := BreakX ('-') & "-Lib";
Get_Field : Pattern := BreakX (Decimal_Digit_Set) * Field;
Get_Dflt : Pattern := BreakX ('(') & "(set to "
& Break (" ") * Default & " if";
Next_Arg : Pattern := Break (',') * Arg & ',';
Op_Node : Pattern := "Op_" & Rest * Op_Name;
Shft_Rot : Pattern := "Shift_" or "Rotate_";
No_Ent : Pattern := "Or_Else" or "And_Then" or "In" or "Not_In";
M : Match_Result;
V_String_Id : constant VString := V ("String_Id");
V_Node_Id : constant VString := V ("Node_Id");
V_Name_Id : constant VString := V ("Name_Id");
V_List_Id : constant VString := V ("List_Id");
V_Elist_Id : constant VString := V ("Elist_Id");
V_Boolean : constant VString := V ("Boolean");
procedure WriteS (S : String);
procedure WriteB (S : String);
procedure WriteBS (S : String);
procedure WriteS (S : VString);
procedure WriteB (S : VString);
procedure WriteBS (S : VString);
-- Write given line to spec or body file or both if active
procedure WriteB (S : String) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
end WriteB;
procedure WriteB (S : VString) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
end WriteB;
procedure WriteBS (S : String) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteBS;
procedure WriteBS (S : VString) is
begin
if FileB /= Nul then
Put_Line (OutB, S);
end if;
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteBS;
procedure WriteS (S : String) is
begin
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteS;
procedure WriteS (S : VString) is
begin
if FileS /= Nul then
Put_Line (OutS, S);
end if;
end WriteS;
-- Start of processing for XNmake
begin
-- Capture our revision (following line updated by RCS)
Match ("$Revision$",
"$Rev" & "ision: " & Break (' ') * XNmake_Rev);
Lineno := 0;
NWidth := 28;
Anchored_Mode := True;
for ArgN in 1 .. Argument_Count loop
declare
Arg : constant String := Argument (ArgN);
begin
if Arg (1) = '-' then
if Arg'Length = 2
and then (Arg (2) = 'b' or else Arg (2) = 'B')
then
FileS := Nul;
elsif Arg'Length = 2
and then (Arg (2) = 's' or else Arg (2) = 'S')
then
FileB := Nul;
else
raise Err;
end if;
else
if Given_File /= Nul then
raise Err;
else
Given_File := V (Arg);
end if;
end if;
end;
end loop;
if FileS = Nul and then FileB = Nul then
raise Err;
elsif Given_File /= Nul then
if FileB = Nul then
FileS := Given_File;
elsif FileS = Nul then
FileB := Given_File;
else
raise Err;
end if;
end if;
Open (InS, In_File, "sinfo.ads");
Open (InT, In_File, "nmake.adt");
if FileS /= Nul then
Create (OutS, Out_File, S (FileS));
end if;
if FileB /= Nul then
Create (OutB, Out_File, S (FileB));
end if;
Anchored_Mode := True;
-- Get Sinfo revision number
loop
Line := Get_Line (InS);
exit when Match (Line, Get_SRev);
end loop;
-- Copy initial part of template to spec and body
loop
Line := Get_Line (InT);
if Match (Line, GetT_Rev) then
WriteBS
("-- Generated by xnmake revision " &
XNmake_Rev & " using");
WriteBS
("-- sinfo.ads revision " &
Sinfo_Rev);
WriteBS
("-- nmake.adt revision " &
Temp_Rev);
else
-- Skip lines describing the template
if Match (Line, "-- This file is a template") then
loop
Line := Get_Line (InT);
exit when Line = "";
end loop;
end if;
exit when Match (Line, "package");
if Match (Line, Body_Only, M) then
Replace (M, X);
WriteB (Line);
elsif Match (Line, Spec_Only, M) then
Replace (M, X);
WriteS (Line);
else
if Match (Line, Templ, M) then
Replace (M, A & " S p e c ");
end if;
WriteS (Line);
if Match (Line, Spec, M) then
Replace (M, A & "B o d y");
end if;
WriteB (Line);
end if;
end if;
end loop;
-- Package line reached
WriteS ("package Nmake is");
WriteB ("package body Nmake is");
WriteB ("");
-- Copy rest of lines up to template insert point to spec only
loop
Line := Get_Line (InT);
exit when Match (Line, "!!TEMPLATE INSERTION POINT");
WriteS (Line);
end loop;
-- Here we are doing the actual insertions, loop through node types
loop
Line := Get_Line (InS);
if Match (Line, Node_Hdr)
and then not Match (Node, Punc)
and then Node /= "Unused"
then
exit when Node = "Empty";
Prevl := " function Make_" & Node & " (Sloc : Source_Ptr";
Arg_List := Nul;
-- Loop through fields of one node
loop
Line := Get_Line (InS);
exit when Line = "";
if Match (Line, Binop) then
WriteBS (Prevl & ';');
Append (Arg_List, "Left_Opnd,Right_Opnd,");
WriteBS (
" " & Rpad ("Left_Opnd", NWidth) & " : Node_Id;");
Prevl :=
" " & Rpad ("Right_Opnd", NWidth) & " : Node_Id";
elsif Match (Line, Unop) then
WriteBS (Prevl & ';');
Append (Arg_List, "Right_Opnd,");
Prevl := " " & Rpad ("Right_Opnd", NWidth) & " : Node_Id";
elsif Match (Line, Syn) then
if Synonym /= "Prev_Ids"
and then Synonym /= "More_Ids"
and then Synonym /= "Comes_From_Source"
and then Synonym /= "Paren_Count"
and then not Match (Field, Sem_Field)
and then not Match (Field, Lib_Field)
then
Match (Field, Get_Field);
if Field = "Str" then Field := V_String_Id;
elsif Field = "Node" then Field := V_Node_Id;
elsif Field = "Name" then Field := V_Name_Id;
elsif Field = "List" then Field := V_List_Id;
elsif Field = "Elist" then Field := V_Elist_Id;
elsif Field = "Flag" then Field := V_Boolean;
end if;
if Field = "Boolean" then
Default := V ("False");
else
Default := Nul;
end if;
Match (Comment, Get_Dflt);
WriteBS (Prevl & ';');
Append (Arg_List, Synonym & ',');
Rpad (Synonym, NWidth);
if Default = "" then
Prevl := " " & Synonym & " : " & Field;
else
Prevl :=
" " & Synonym & " : " & Field & " := " & Default;
end if;
end if;
end if;
end loop;
WriteBS (Prevl & ')');
WriteS (" return Node_Id;");
WriteS (" pragma Inline (Make_" & Node & ");");
WriteB (" return Node_Id");
WriteB (" is");
WriteB (" N : constant Node_Id :=");
if Match (Node, "Defining_Identifier") or else
Match (Node, "Defining_Character") or else
Match (Node, "Defining_Operator")
then
WriteB (" New_Entity (N_" & Node & ", Sloc);");
else
WriteB (" New_Node (N_" & Node & ", Sloc);");
end if;
WriteB (" begin");
while Match (Arg_List, Next_Arg, "") loop
if Length (Arg) < NWidth then
WriteB (" Set_" & Arg & " (N, " & Arg & ");");
else
WriteB (" Set_" & Arg);
WriteB (" (N, " & Arg & ");");
end if;
end loop;
if Match (Node, Op_Node) then
if Node = "Op_Plus" then
WriteB (" Set_Chars (N, Name_Op_Add);");
elsif Node = "Op_Minus" then
WriteB (" Set_Chars (N, Name_Op_Subtract);");
elsif Match (Op_Name, Shft_Rot) then
WriteB (" Set_Chars (N, Name_" & Op_Name & ");");
else
WriteB (" Set_Chars (N, Name_" & Node & ");");
end if;
if not Match (Op_Name, No_Ent) then
WriteB (" Set_Entity (N, Standard_" & Node & ");");
end if;
end if;
WriteB (" return N;");
WriteB (" end Make_" & Node & ';');
WriteBS ("");
end if;
end loop;
WriteBS ("end Nmake;");
exception
when Err =>
Put_Line (Standard_Error, "usage: xnmake [-b] [-s] [filename]");
Set_Exit_Status (1);
end XNmake;
|
with Radar_Internals;
procedure Main is
-- You are in charge of developping a rotating radar for the new T-1000
-- Some of the radar code is already in place, it is just missing the
-- high-level interface to handle incoming objects.
type Object_Status_T is (Out_Of_Range, Tracked, Cleared, Selected);
-- QUESTION 1 - Part A
--
-- Define a type Angle_Degrees_T that is modulo 360
type Angle_Degrees_T is mod 360;
-- Define a subtype Object_Distance_Km_T as a Float with values
-- between 10cm and 100km
subtype Object_Distance_Km_T is Float range 0.000_01 .. 100.0;
-- Define a subtype Speed_Kph_T that is a Float between 0 and 50 km/h
subtype Speed_Kph_T is Float range 0.0 .. 50.0;
John_Connor : Object_Status_T := Out_Of_Range;
-- QUESTION 1 - Part B
--
-- Set Radar_Angle to be an Angle_Degrees_T with a starting value
Radar_Angle : Angle_Degrees_T := 180;
-- Declare an Object_Distance_Km_T named Distance_Closest_Object, set to 10km
Distance_Closest_Object : Object_Distance_Km_T := 10.0;
-- Declare a Speed_Kph_T named Running_Speed, set to 25km/h
Running_Speed : Speed_Kph_T := 25.0;
-- Assign Time_To_Arrival to
-- Distance_Closest_Object divided by Running_Speed * 3600
Time_To_Arrival : Float := Distance_Closest_Object / Running_Speed * 3600.0;
begin
-- This line will compile if the declarations are OK
Radar_Internals.Time_Step (Float (Radar_Angle), Time_To_Arrival,
Object_Status_T'Image (John_Connor));
-- QUESTION 2 - Part A
--
-- Some time has passed since setup, set variables as follow to reflect that.
--
-- Rotate the radar 200 degrees by incrementing its value
Radar_Angle := Radar_Angle + 200;
-- Set the status of John_Connor to Tracked
John_Connor := Tracked;
-- Set distance to closest object to 4km
Distance_Closest_Object := 4.0;
-- Update Running_Time accordingly
Time_To_Arrival := Distance_Closest_Object / Running_Speed * 3600.0;
-- This line will compile if the declarations are OK
Radar_Internals.Time_Step (Float (Radar_Angle), Time_To_Arrival,
Object_Status_T'Image (John_Connor));
-- QUESTION 2 - Part B
--
-- Some more time has passed since setup.
--
-- Rotate the radar 180 degrees
Radar_Angle := Radar_Angle + 180;
-- Set the status of John_Connor to Selected
John_Connor := Selected;
-- This line will compile if the declarations are OK
Radar_Internals.Time_Step (Float (Radar_Angle), Time_To_Arrival,
Object_Status_T'Image (John_Connor));
-- QUESTION 3 - Quiz
--
-- a. What happens if we want to rotate the radar by 361 degrees?
-- This won't compile: 361 is not a valid `Angle_Degrees_T`
-- Radar_Angle := Radar_Angle + 361;
-- This will work though, end result is identical to adding 1 degree
Radar_Angle := Radar_Angle + 359;
Radar_Angle := Radar_Angle + 2;
-- b. There is a last minute change in the spec: John Connor is now in
-- the "Friend" status, make changes to the code to allow for that.
-- Simply add a Friend value to Object_Status_T and call
-- John_Connor := Friend;
-- Notice that Time_Step handles the new enumeral without issue
-- c. What happens to the E.T.A. if Running_Speed is 0? Try it.
-- Running speed is used as a divisor, so there will be a division
-- by 0. This will either return a NaN or raise a Constraint_Error
-- depending on value of Real'Machine_Overflows.
-- QUESTION 4 - Advanced
--
-- Redefine Object_Distance_Km_T as a type instead of subtype.
-- Modify the two division to make it work, using explicit casting.
end Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- Sample.Menu_Demo.Handler --
-- --
-- S P E C --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell --
-- copies of the Software, and to permit persons to whom the Software is --
-- furnished to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
-- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control
-- $Revision: 1.9 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Terminal_Interface.Curses;
use Terminal_Interface.Curses;
with Terminal_Interface.Curses.Panels;
use Terminal_Interface.Curses.Panels;
with Terminal_Interface.Curses.Menus;
use Terminal_Interface.Curses.Menus;
generic
with function My_Driver (Men : Menu;
K : Key_Code;
Pan : Panel) return Boolean;
package Sample.Menu_Demo.Handler is
procedure Drive_Me (M : in Menu;
Lin : in Line_Position;
Col : in Column_Position;
Title : in String := "");
-- Position the menu at the given point and drive it.
procedure Drive_Me (M : in Menu;
Title : in String := "");
-- Center menu and drive it.
end Sample.Menu_Demo.Handler;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
procedure Timer_Test
with Linker_Section => ".iwram", No_Inline;
pragma Machine_Attribute (Timer_Test, "target", "arm"); |
with Ada.Numerics.Generic_Real_Arrays;
with OpenGL.Thin;
package OpenGL.Types is
subtype Integer_t is Thin.Integer_t;
subtype Float_t is Thin.Float_t;
subtype Double_t is Thin.Double_t;
subtype Clamped_Double_t is Double_t range 0.0 .. 1.0;
subtype Clamped_Float_t is Float_t range 0.0 .. 1.0;
package Float_Arrays is new Ada.Numerics.Generic_Real_Arrays (Types.Float_t);
package Double_Arrays is new Ada.Numerics.Generic_Real_Arrays (Types.Double_t);
type Vector_2i_t is array (1 .. 2) of aliased Integer_t;
type Vector_3i_t is array (1 .. 3) of aliased Integer_t;
type Vector_4i_t is array (1 .. 4) of aliased Integer_t;
type Vector_2f_t is new Float_Arrays.Real_Vector (1 .. 2);
type Vector_3f_t is new Float_Arrays.Real_Vector (1 .. 3);
type Vector_4f_t is new Float_Arrays.Real_Vector (1 .. 4);
end OpenGL.Types;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2021 POK team
pragma No_Run_Time;
with Interfaces.C;
package Compute is
procedure Compute;
pragma Export (C, Compute, "compute");
end Compute;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Web API Definition --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014-2018, 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 System;
with WebAPI.HTML.Canvas_Elements;
with WebAPI.HTML.Rendering_Contexts;
with WebAPI.WebGL.Buffers;
with WebAPI.WebGL.Framebuffers;
with WebAPI.WebGL.Programs;
with WebAPI.WebGL.Renderbuffers;
with WebAPI.WebGL.Shaders;
with WebAPI.WebGL.Textures;
with WebAPI.WebGL.Uniform_Locations;
package WebAPI.WebGL.Rendering_Contexts is
pragma Preelaborate;
type WebGL_Rendering_Context is limited interface
and WebAPI.HTML.Rendering_Contexts.Rendering_Context;
type WebGL_Rendering_Context_Access is
access all WebGL_Rendering_Context'Class
with Storage_Size => 0;
---------------------
-- ClearBufferMask --
---------------------
DEPTH_BUFFER_BIT : constant := 16#00000100#;
STENCIL_BUFFER_BIT : constant := 16#00000400#;
COLOR_BUFFER_BIT : constant := 16#00004000#;
---------------
-- BeginMode --
---------------
POINTS : constant := 16#0000#;
LINES : constant := 16#0001#;
LINE_LOOP : constant := 16#0002#;
LINE_STRIP : constant := 16#0003#;
TRIANGLES : constant := 16#0004#;
TRIANGLE_STRIP : constant := 16#0005#;
TRIANGLE_FAN : constant := 16#0006#;
-- /* AlphaFunction (not supported in ES20) */
-- /* NEVER */
-- /* LESS */
-- /* EQUAL */
-- /* LEQUAL */
-- /* GREATER */
-- /* NOTEQUAL */
-- /* GEQUAL */
-- /* ALWAYS */
------------------------
-- BlendingFactorDest --
------------------------
ZERO : constant := 16#0000#;
ONE : constant := 16#0001#;
SRC_COLOR : constant := 16#0300#;
ONE_MINUS_SRC_COLOR : constant := 16#0301#;
SRC_ALPHA : constant := 16#0302#;
ONE_MINUS_SRC_ALPHA : constant := 16#0303#;
DST_ALPHA : constant := 16#0304#;
ONE_MINUS_DST_ALPHA : constant := 16#0305#;
-----------------------
-- BlendingFactorSrc --
-----------------------
DST_COLOR : constant := 16#0306#;
ONE_MINUS_DST_COLOR : constant := 16#0307#;
SRC_ALPHA_SATURATE : constant := 16#0308#;
-- /* BlendEquationSeparate */
-- const GLenum FUNC_ADD = 0x8006;
-- const GLenum BLEND_EQUATION = 0x8009;
-- const GLenum BLEND_EQUATION_RGB = 0x8009; /* same as BLEND_EQUATION */
-- const GLenum BLEND_EQUATION_ALPHA = 0x883D;
--
-- /* BlendSubtract */
-- const GLenum FUNC_SUBTRACT = 0x800A;
-- const GLenum FUNC_REVERSE_SUBTRACT = 0x800B;
--
-- /* Separate Blend Functions */
-- const GLenum BLEND_DST_RGB = 0x80C8;
-- const GLenum BLEND_SRC_RGB = 0x80C9;
-- const GLenum BLEND_DST_ALPHA = 0x80CA;
-- const GLenum BLEND_SRC_ALPHA = 0x80CB;
CONSTANT_COLOR : constant := 16#8001#;
ONE_MINUS_CONSTANT_COLOR : constant := 16#8002#;
CONSTANT_ALPHA : constant := 16#8003#;
ONE_MINUS_CONSTANT_ALPHA : constant := 16#8004#;
-- const GLenum BLEND_COLOR = 0x8005;
--------------------
-- Buffer Objects --
--------------------
ARRAY_BUFFER : constant := 16#8892#;
ELEMENT_ARRAY_BUFFER : constant := 16#8893#;
-- const GLenum ARRAY_BUFFER_BINDING = 0x8894;
-- const GLenum ELEMENT_ARRAY_BUFFER_BINDING = 0x8895;
STREAM_DRAW : constant := 16#88E0#;
STATIC_DRAW : constant := 16#88E4#;
DYNAMIC_DRAW : constant := 16#88E8#;
-- const GLenum BUFFER_SIZE = 0x8764;
-- const GLenum BUFFER_USAGE = 0x8765;
--
-- const GLenum CURRENT_VERTEX_ATTRIB = 0x8626;
--
-- /* CullFaceMode */
-- const GLenum FRONT = 0x0404;
-- const GLenum BACK = 0x0405;
-- const GLenum FRONT_AND_BACK = 0x0408;
---------------
-- EnableCap --
---------------
-- /* TEXTURE_2D */
CULL_FACE : constant := 16#0B44#;
BLEND : constant := 16#0BE2#;
DITHER : constant := 16#0BD0#;
STENCIL_TEST : constant := 16#0B90#;
DEPTH_TEST : constant := 16#0B71#;
SCISSOR_TEST : constant := 16#0C11#;
POLYGON_OFFSET_FILL : constant := 16#8037#;
SAMPLE_ALPHA_TO_COVERAGE : constant := 16#809E#;
SAMPLE_COVERAGE : constant := 16#80A0#;
-- /* ErrorCode */
-- const GLenum NO_ERROR = 0;
-- const GLenum INVALID_ENUM = 0x0500;
-- const GLenum INVALID_VALUE = 0x0501;
-- const GLenum INVALID_OPERATION = 0x0502;
-- const GLenum OUT_OF_MEMORY = 0x0505;
--
-- /* FrontFaceDirection */
-- const GLenum CW = 0x0900;
-- const GLenum CCW = 0x0901;
--
-- /* GetPName */
-- const GLenum LINE_WIDTH = 0x0B21;
-- const GLenum ALIASED_POINT_SIZE_RANGE = 0x846D;
-- const GLenum ALIASED_LINE_WIDTH_RANGE = 0x846E;
-- const GLenum CULL_FACE_MODE = 0x0B45;
-- const GLenum FRONT_FACE = 0x0B46;
-- const GLenum DEPTH_RANGE = 0x0B70;
-- const GLenum DEPTH_WRITEMASK = 0x0B72;
-- const GLenum DEPTH_CLEAR_VALUE = 0x0B73;
-- const GLenum DEPTH_FUNC = 0x0B74;
-- const GLenum STENCIL_CLEAR_VALUE = 0x0B91;
-- const GLenum STENCIL_FUNC = 0x0B92;
-- const GLenum STENCIL_FAIL = 0x0B94;
-- const GLenum STENCIL_PASS_DEPTH_FAIL = 0x0B95;
-- const GLenum STENCIL_PASS_DEPTH_PASS = 0x0B96;
-- const GLenum STENCIL_REF = 0x0B97;
-- const GLenum STENCIL_VALUE_MASK = 0x0B93;
-- const GLenum STENCIL_WRITEMASK = 0x0B98;
-- const GLenum STENCIL_BACK_FUNC = 0x8800;
-- const GLenum STENCIL_BACK_FAIL = 0x8801;
-- const GLenum STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802;
-- const GLenum STENCIL_BACK_PASS_DEPTH_PASS = 0x8803;
-- const GLenum STENCIL_BACK_REF = 0x8CA3;
-- const GLenum STENCIL_BACK_VALUE_MASK = 0x8CA4;
-- const GLenum STENCIL_BACK_WRITEMASK = 0x8CA5;
-- const GLenum VIEWPORT = 0x0BA2;
-- const GLenum SCISSOR_BOX = 0x0C10;
-- /* SCISSOR_TEST */
-- const GLenum COLOR_CLEAR_VALUE = 0x0C22;
-- const GLenum COLOR_WRITEMASK = 0x0C23;
-- const GLenum UNPACK_ALIGNMENT = 0x0CF5;
-- const GLenum PACK_ALIGNMENT = 0x0D05;
-- const GLenum MAX_TEXTURE_SIZE = 0x0D33;
-- const GLenum MAX_VIEWPORT_DIMS = 0x0D3A;
-- const GLenum SUBPIXEL_BITS = 0x0D50;
-- const GLenum RED_BITS = 0x0D52;
-- const GLenum GREEN_BITS = 0x0D53;
-- const GLenum BLUE_BITS = 0x0D54;
-- const GLenum ALPHA_BITS = 0x0D55;
-- const GLenum DEPTH_BITS = 0x0D56;
-- const GLenum STENCIL_BITS = 0x0D57;
-- const GLenum POLYGON_OFFSET_UNITS = 0x2A00;
-- /* POLYGON_OFFSET_FILL */
-- const GLenum POLYGON_OFFSET_FACTOR = 0x8038;
-- const GLenum TEXTURE_BINDING_2D = 0x8069;
-- const GLenum SAMPLE_BUFFERS = 0x80A8;
-- const GLenum SAMPLES = 0x80A9;
-- const GLenum SAMPLE_COVERAGE_VALUE = 0x80AA;
-- const GLenum SAMPLE_COVERAGE_INVERT = 0x80AB;
--
-- /* GetTextureParameter */
-- /* TEXTURE_MAG_FILTER */
-- /* TEXTURE_MIN_FILTER */
-- /* TEXTURE_WRAP_S */
-- /* TEXTURE_WRAP_T */
--
-- const GLenum COMPRESSED_TEXTURE_FORMATS = 0x86A3;
--
-- /* HintMode */
-- const GLenum DONT_CARE = 0x1100;
-- const GLenum FASTEST = 0x1101;
-- const GLenum NICEST = 0x1102;
--
-- /* HintTarget */
-- const GLenum GENERATE_MIPMAP_HINT = 0x8192;
--------------
-- DataType --
--------------
-- const GLenum INT = 0x1404;
-- const GLenum UNSIGNED_INT = 0x1405;
BYTE : constant := 16#1400#;
UNSIGNED_BYTE : constant := 16#1401#;
SHORT : constant := 16#1402#;
UNSIGNED_SHORT : constant := 16#1403#;
FLOAT : constant := 16#1406#;
-----------------
-- PixelFormat --
-----------------
ALPHA : constant := 16#1906#;
RGB : constant := 16#1907#;
RGBA : constant := 16#1908#;
LUMINANCE : constant := 16#1909#;
LUMINANCE_ALPHA : constant := 16#190A#;
-- const GLenum DEPTH_COMPONENT = 0x1902;
---------------
-- PixelType --
---------------
-- /* UNSIGNED_BYTE */
UNSIGNED_SHORT_4_4_4_4 : constant := 16#8033#;
UNSIGNED_SHORT_5_5_5_1 : constant := 16#8034#;
UNSIGNED_SHORT_5_6_5 : constant := 16#8363#;
-------------
-- Shaders --
-------------
FRAGMENT_SHADER : constant := 16#8B30#;
VERTEX_SHADER : constant := 16#8B31#;
-- const GLenum MAX_VERTEX_ATTRIBS = 0x8869;
-- const GLenum MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB;
-- const GLenum MAX_VARYING_VECTORS = 0x8DFC;
-- const GLenum MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D;
-- const GLenum MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C;
-- const GLenum MAX_TEXTURE_IMAGE_UNITS = 0x8872;
-- const GLenum MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD;
SHADER_TYPE : constant := 16#8B4F#;
DELETE_STATUS : constant := 16#8B80#;
LINK_STATUS : constant := 16#8B82#;
VALIDATE_STATUS : constant := 16#8B83#;
ATTACHED_SHADERS : constant := 16#8B85#;
ACTIVE_UNIFORMS : constant := 16#8B86#;
ACTIVE_ATTRIBUTES : constant := 16#8B89#;
-- const GLenum SHADING_LANGUAGE_VERSION = 0x8B8C;
-- const GLenum CURRENT_PROGRAM = 0x8B8D;
-------------------------------------
-- StencilFunction / DepthFunction --
-------------------------------------
NEVER : constant := 16#0200#;
LESS : constant := 16#0201#;
EQUAL : constant := 16#0202#;
LEQUAL : constant := 16#0203#;
GREATER : constant := 16#0204#;
NOTEQUAL : constant := 16#0205#;
GEQUAL : constant := 16#0206#;
ALWAYS : constant := 16#0207#;
-- /* StencilOp */
-- /* ZERO */
-- const GLenum KEEP = 0x1E00;
-- const GLenum REPLACE = 0x1E01;
-- const GLenum INCR = 0x1E02;
-- const GLenum DECR = 0x1E03;
-- const GLenum INVERT = 0x150A;
-- const GLenum INCR_WRAP = 0x8507;
-- const GLenum DECR_WRAP = 0x8508;
--
-- /* StringName */
-- const GLenum VENDOR = 0x1F00;
-- const GLenum RENDERER = 0x1F01;
-- const GLenum VERSION = 0x1F02;
----------------------
-- TextureMagFilter --
----------------------
NEAREST : constant := 16#2600#;
LINEAR : constant := 16#2601#;
----------------------
-- TextureMinFilter --
----------------------
-- NEAREST
-- LINEAR
NEAREST_MIPMAP_NEAREST : constant := 16#2700#;
LINEAR_MIPMAP_NEAREST : constant := 16#2701#;
NEAREST_MIPMAP_LINEAR : constant := 16#2702#;
LINEAR_MIPMAP_LINEAR : constant := 16#2703#;
--------------------------
-- TextureParameterName --
--------------------------
TEXTURE_MAG_FILTER : constant := 16#2800#;
TEXTURE_MIN_FILTER : constant := 16#2801#;
TEXTURE_WRAP_S : constant := 16#2802#;
TEXTURE_WRAP_T : constant := 16#2803#;
-------------------
-- TextureTarget --
-------------------
TEXTURE_2D : constant := 16#0DE1#;
-- const GLenum TEXTURE = 0x1702;
TEXTURE_CUBE_MAP : constant := 16#8513#;
-- const GLenum TEXTURE_BINDING_CUBE_MAP = 0x8514;
TEXTURE_CUBE_MAP_POSITIVE_X : constant := 16#8515#;
TEXTURE_CUBE_MAP_NEGATIVE_X : constant := 16#8516#;
TEXTURE_CUBE_MAP_POSITIVE_Y : constant := 16#8517#;
TEXTURE_CUBE_MAP_NEGATIVE_Y : constant := 16#8518#;
TEXTURE_CUBE_MAP_POSITIVE_Z : constant := 16#8519#;
TEXTURE_CUBE_MAP_NEGATIVE_Z : constant := 16#851A#;
-- const GLenum MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C;
-----------------
-- TextureUnit --
-----------------
TEXTURE0 : constant := 16#84C0#;
TEXTURE1 : constant := 16#84C1#;
TEXTURE2 : constant := 16#84C2#;
TEXTURE3 : constant := 16#84C3#;
TEXTURE4 : constant := 16#84C4#;
TEXTURE5 : constant := 16#84C5#;
TEXTURE6 : constant := 16#84C6#;
TEXTURE7 : constant := 16#84C7#;
TEXTURE8 : constant := 16#84C8#;
TEXTURE9 : constant := 16#84C9#;
TEXTURE10 : constant := 16#84CA#;
TEXTURE11 : constant := 16#84CB#;
TEXTURE12 : constant := 16#84CC#;
TEXTURE13 : constant := 16#84CD#;
TEXTURE14 : constant := 16#84CE#;
TEXTURE15 : constant := 16#84CF#;
TEXTURE16 : constant := 16#84D0#;
TEXTURE17 : constant := 16#84D1#;
TEXTURE18 : constant := 16#84D2#;
TEXTURE19 : constant := 16#84D3#;
TEXTURE20 : constant := 16#84D4#;
TEXTURE21 : constant := 16#84D5#;
TEXTURE22 : constant := 16#84D6#;
TEXTURE23 : constant := 16#84D7#;
TEXTURE24 : constant := 16#84D8#;
TEXTURE25 : constant := 16#84D9#;
TEXTURE26 : constant := 16#84DA#;
TEXTURE27 : constant := 16#84DB#;
TEXTURE28 : constant := 16#84DC#;
TEXTURE29 : constant := 16#84DD#;
TEXTURE30 : constant := 16#84DE#;
TEXTURE31 : constant := 16#84DF#;
-- const GLenum ACTIVE_TEXTURE = 0x84E0;
---------------------
-- TextureWrapMode --
---------------------
REPEAT : constant := 16#2901#;
CLAMP_TO_EDGE : constant := 16#812F#;
MIRRORED_REPEAT : constant := 16#8370#;
-- /* Uniform Types */
-- const GLenum FLOAT_VEC2 = 0x8B50;
-- const GLenum FLOAT_VEC3 = 0x8B51;
-- const GLenum FLOAT_VEC4 = 0x8B52;
-- const GLenum INT_VEC2 = 0x8B53;
-- const GLenum INT_VEC3 = 0x8B54;
-- const GLenum INT_VEC4 = 0x8B55;
-- const GLenum BOOL = 0x8B56;
-- const GLenum BOOL_VEC2 = 0x8B57;
-- const GLenum BOOL_VEC3 = 0x8B58;
-- const GLenum BOOL_VEC4 = 0x8B59;
-- const GLenum FLOAT_MAT2 = 0x8B5A;
-- const GLenum FLOAT_MAT3 = 0x8B5B;
-- const GLenum FLOAT_MAT4 = 0x8B5C;
-- const GLenum SAMPLER_2D = 0x8B5E;
-- const GLenum SAMPLER_CUBE = 0x8B60;
--
-- /* Vertex Arrays */
-- const GLenum VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622;
-- const GLenum VERTEX_ATTRIB_ARRAY_SIZE = 0x8623;
-- const GLenum VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624;
-- const GLenum VERTEX_ATTRIB_ARRAY_TYPE = 0x8625;
-- const GLenum VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A;
-- const GLenum VERTEX_ATTRIB_ARRAY_POINTER = 0x8645;
-- const GLenum VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F;
--
-- /* Read Format */
-- const GLenum IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A;
-- const GLenum IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B;
-------------------
-- Shader Source --
-------------------
COMPILE_STATUS : constant := 16#8B81#;
-- /* Shader Precision-Specified Types */
-- const GLenum LOW_FLOAT = 0x8DF0;
-- const GLenum MEDIUM_FLOAT = 0x8DF1;
-- const GLenum HIGH_FLOAT = 0x8DF2;
-- const GLenum LOW_INT = 0x8DF3;
-- const GLenum MEDIUM_INT = 0x8DF4;
-- const GLenum HIGH_INT = 0x8DF5;
------------------------
-- Framebuffer Object --
------------------------
FRAMEBUFFER : constant := 16#8D40#;
RENDERBUFFER : constant := 16#8D41#;
RGBA4 : constant := 16#8056#;
RGB5_A1 : constant := 16#8057#;
RGB565 : constant := 16#8D62#;
DEPTH_COMPONENT16 : constant := 16#81A5#;
STENCIL_INDEX8 : constant := 16#8D48#;
-- const GLenum STENCIL_INDEX = 0x1901;
-- const GLenum DEPTH_STENCIL = 0x84F9;
-- const GLenum RENDERBUFFER_WIDTH = 0x8D42;
-- const GLenum RENDERBUFFER_HEIGHT = 0x8D43;
-- const GLenum RENDERBUFFER_INTERNAL_FORMAT = 0x8D44;
-- const GLenum RENDERBUFFER_RED_SIZE = 0x8D50;
-- const GLenum RENDERBUFFER_GREEN_SIZE = 0x8D51;
-- const GLenum RENDERBUFFER_BLUE_SIZE = 0x8D52;
-- const GLenum RENDERBUFFER_ALPHA_SIZE = 0x8D53;
-- const GLenum RENDERBUFFER_DEPTH_SIZE = 0x8D54;
-- const GLenum RENDERBUFFER_STENCIL_SIZE = 0x8D55;
--
-- const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0;
-- const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1;
-- const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2;
-- const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3;
COLOR_ATTACHMENT0 : constant := 16#8CE0#;
DEPTH_ATTACHMENT : constant := 16#8D00#;
STENCIL_ATTACHMENT : constant := 16#8D20#;
-- const GLenum DEPTH_STENCIL_ATTACHMENT = 0x821A;
-- const GLenum NONE = 0;
--
-- const GLenum FRAMEBUFFER_COMPLETE = 0x8CD5;
-- const GLenum FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6;
-- const GLenum FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7;
-- const GLenum FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9;
-- const GLenum FRAMEBUFFER_UNSUPPORTED = 0x8CDD;
--
-- const GLenum FRAMEBUFFER_BINDING = 0x8CA6;
-- const GLenum RENDERBUFFER_BINDING = 0x8CA7;
-- const GLenum MAX_RENDERBUFFER_SIZE = 0x84E8;
--
-- const GLenum INVALID_FRAMEBUFFER_OPERATION = 0x0506;
--
-- /* WebGL-specific enums */
-- const GLenum UNPACK_FLIP_Y_WEBGL = 0x9240;
-- const GLenum UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
-- const GLenum CONTEXT_LOST_WEBGL = 0x9242;
-- const GLenum UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
-- const GLenum BROWSER_DEFAULT_WEBGL = 0x9244;
not overriding function Get_Canvas
(Self : not null access WebGL_Rendering_Context)
return WebAPI.HTML.Canvas_Elements.HTML_Canvas_Element_Access
is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "canvas";
-- readonly attribute GLsizei drawingBufferWidth;
-- readonly attribute GLsizei drawingBufferHeight;
--
-- [WebGLHandlesContextLoss] WebGLContextAttributes? getContextAttributes();
-- [WebGLHandlesContextLoss] boolean isContextLost();
--
-- sequence<DOMString>? getSupportedExtensions();
-- object? getExtension(DOMString name);
not overriding procedure Active_Texture
(Self : not null access WebGL_Rendering_Context;
Texture : GLenum) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "activeTexture";
not overriding procedure Attach_Shader
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "attachShader";
-- void bindAttribLocation(WebGLProgram? program, GLuint index, DOMString name);
not overriding procedure Bind_Buffer
(Self : not null access WebGL_Rendering_Context;
Target : GLenum;
Buffer : access WebAPI.WebGL.Buffers.WebGL_Buffer'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "bindBuffer";
-- Pre'Class => Target in ARRAY_BUFFER | ELEMENT_ARRAY_BUFFER;
not overriding procedure Bind_Framebuffer
(Self : not null access WebGL_Rendering_Context;
Target : GLenum;
Framebuffer : access WebAPI.WebGL.Framebuffers.WebGL_Framebuffer'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "bindFramebuffer";
-- Pre'Class => Target in FRAMEBUFFER;
not overriding procedure Bind_Renderbuffer
(Self : not null access WebGL_Rendering_Context;
Target : GLenum;
Renderbuffer : access WebAPI.WebGL.Renderbuffers.WebGL_Renderbuffer'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "bindRenderbuffer";
-- Pre'Class => Target in RENDERBUFFER;
not overriding procedure Bind_Texture
(Self : not null access WebGL_Rendering_Context;
Target : GLenum;
Texture : access WebAPI.WebGL.Textures.WebGL_Texture'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "bindTexture";
-- Pre'Class => Target in TEXTURE_2D | TEXTURE_CUBE_MAP;
-- void blendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-- void blendEquation(GLenum mode);
-- void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
not overriding procedure Blend_Func
(Self : not null access WebGL_Rendering_Context;
Source_Factor : GLenum;
Destination_Factor : GLenum)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "blendFunc";
-- void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
-- GLenum srcAlpha, GLenum dstAlpha);
--
-- typedef (ArrayBuffer or ArrayBufferView) BufferDataSource;
-- void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
-- void bufferData(GLenum target, BufferDataSource? data, GLenum usage);
not overriding procedure Buffer_Data
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Data : System.Address;
Usage : WebAPI.WebGL.GLenum) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "bufferData";
-- void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data);
--
-- [WebGLHandlesContextLoss] GLenum checkFramebufferStatus(GLenum target);
not overriding procedure Clear
(Self : not null access WebGL_Rendering_Context;
Mask : GLbitfield) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "clear";
not overriding procedure Clear_Color
(Self : not null access WebGL_Rendering_Context;
Red : GLclampf;
Green : GLclampf;
Blue : GLclampf;
Alpha : GLclampf) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "clearColor";
-- void clearDepth(GLclampf depth);
-- void clearStencil(GLint s);
-- void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
not overriding procedure Compile_Shader
(Self : not null access WebGL_Rendering_Context;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "compileShader";
-- void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
-- GLsizei width, GLsizei height, GLint border,
-- ArrayBufferView data);
-- void compressedTexSubImage2D(GLenum target, GLint level,
-- GLint xoffset, GLint yoffset,
-- GLsizei width, GLsizei height, GLenum format,
-- ArrayBufferView data);
--
-- void copyTexImage2D(GLenum target, GLint level, GLenum internalformat,
-- GLint x, GLint y, GLsizei width, GLsizei height,
-- GLint border);
-- void copyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
-- GLint x, GLint y, GLsizei width, GLsizei height);
not overriding function Create_Buffer
(Self : not null access WebGL_Rendering_Context)
return WebAPI.WebGL.Buffers.WebGL_Buffer_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createBuffer";
not overriding function Create_Framebuffer
(Self : not null access WebGL_Rendering_Context)
return WebAPI.WebGL.Framebuffers.WebGL_Framebuffer_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createFramebuffer";
not overriding function Create_Program
(Self : not null access WebGL_Rendering_Context)
return WebAPI.WebGL.Programs.WebGL_Program_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createProgram";
not overriding function Create_Renderbuffer
(Self : not null access WebGL_Rendering_Context)
return WebAPI.WebGL.Renderbuffers.WebGL_Renderbuffer_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createRenderbuffer";
not overriding function Create_Shader
(Self : not null access WebGL_Rendering_Context;
The_Type : GLenum)
return WebAPI.WebGL.Shaders.WebGL_Shader_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createShader";
not overriding function Create_Texture
(Self : not null access WebGL_Rendering_Context)
return WebAPI.WebGL.Textures.WebGL_Texture_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "createTexture";
-- void cullFace(GLenum mode);
not overriding procedure Delete_Buffer
(Self : not null access WebGL_Rendering_Context;
Buffer : access WebAPI.WebGL.Buffers.WebGL_Buffer'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteBuffer";
not overriding procedure Delete_Framebuffer
(Self : not null access WebGL_Rendering_Context;
Framebuffer : access WebAPI.WebGL.Framebuffers.WebGL_Framebuffer'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteFramebuffer";
not overriding procedure Delete_Program
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteProgram";
not overriding procedure Delete_Renderbuffer
(Self : not null access WebGL_Rendering_Context;
Renderbuffer : access WebAPI.WebGL.Renderbuffers.WebGL_Renderbuffer'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteRenderbuffer";
not overriding procedure Delete_Shader
(Self : not null access WebGL_Rendering_Context;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteShader";
not overriding procedure Delete_Texture
(Self : not null access WebGL_Rendering_Context;
Texture : access WebAPI.WebGL.Textures.WebGL_Texture'Class)
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "deleteTexture";
not overriding procedure Depth_Func
(Self : not null access WebGL_Rendering_Context;
Func : GLenum) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "depthFunc";
-- void depthMask(GLboolean flag);
-- void depthRange(GLclampf zNear, GLclampf zFar);
-- void detachShader(WebGLProgram? program, WebGLShader? shader);
not overriding procedure Disable
(Self : not null access WebGL_Rendering_Context;
Capability : GLenum) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "disable";
not overriding procedure Disable_Vertex_Attrib_Array
(Self : not null access WebGL_Rendering_Context;
Index : GLuint) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "disableVertexAttribArray";
not overriding procedure Draw_Arrays
(Self : not null access WebGL_Rendering_Context;
Mode : GLenum;
First : GLint;
Count : GLsizei) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "drawArrays";
-- void drawElements(GLenum mode, GLsizei count, GLenum type, GLintptr offset);
not overriding procedure Enable
(Self : not null access WebGL_Rendering_Context;
Capability : GLenum) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "enable";
not overriding procedure Enable_Vertex_Attrib_Array
(Self : not null access WebGL_Rendering_Context;
Index : GLuint) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "enableVertexAttribArray";
not overriding procedure Finish
(Self : not null access WebGL_Rendering_Context) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "finish";
not overriding procedure Flush
(Self : not null access WebGL_Rendering_Context) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "flush";
not overriding procedure Framebuffer_Renderbuffer
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Attachment : WebAPI.WebGL.GLenum;
Renderbuffer_Target : WebAPI.WebGL.GLenum;
Renderbuffer :
WebAPI.WebGL.Renderbuffers.WebGL_Renderbuffer_Access) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "framebufferRenderbuffer";
not overriding procedure Framebuffer_Texture_2D
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Attachment : WebAPI.WebGL.GLenum;
Texture_Target : WebAPI.WebGL.GLenum;
Texture : WebAPI.WebGL.Textures.WebGL_Texture_Access;
Level : WebAPI.WebGL.GLint) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "framebufferTexture2D";
-- void frontFace(GLenum mode);
--
-- void generateMipmap(GLenum target);
--
-- WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
-- WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);
-- sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
not overriding function Get_Attrib_Location
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class;
Name : League.Strings.Universal_String) return GLint is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getAttribLocation";
-- any getBufferParameter(GLenum target, GLenum pname);
-- any getParameter(GLenum pname);
--
-- [WebGLHandlesContextLoss] GLenum getError();
--
-- any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
-- GLenum pname);
not overriding function Get_Program_Parameter
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class;
Pname : GLenum) return GLint is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getProgramParameter";
-- Pre'Class => Pname in ATTACHED_SHADERS | ACTIVE_ATTRIBUTES
-- | ACTIVE_UNIFORMS;
not overriding function Get_Program_Parameter
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class;
Pname : GLenum) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getProgramParameter";
-- Pre'Class => Pname in DELETE_STATUS | LINK_STATUS
-- | VALIDATE_STATUS;
-- DOMString? getProgramInfoLog(WebGLProgram? program);
-- any getRenderbufferParameter(GLenum target, GLenum pname);
not overriding function Get_Shader_Parameter
(Self : not null access WebGL_Rendering_Context;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class;
Pname : GLenum) return GLenum is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getShaderParameter";
-- Pre'Class => Pname = SHADER_TYPE;
not overriding function Get_Shader_Parameter
(Self : not null access WebGL_Rendering_Context;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class;
Pname : GLenum) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getShaderParameter";
-- Pre'Class => Pname in DELETE_STATUS | COMPILE_STATUS;
-- WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
-- DOMString? getShaderInfoLog(WebGLShader? shader);
--
-- DOMString? getShaderSource(WebGLShader? shader);
--
-- any getTexParameter(GLenum target, GLenum pname);
--
-- any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
not overriding function Get_Uniform_Location
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class;
Name : League.Strings.Universal_String)
return WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access
is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "getUniformLocation";
-- any getVertexAttrib(GLuint index, GLenum pname);
--
-- [WebGLHandlesContextLoss] GLintptr getVertexAttribOffset(GLuint index, GLenum pname);
--
-- void hint(GLenum target, GLenum mode);
-- [WebGLHandlesContextLoss] GLboolean isBuffer(WebGLBuffer? buffer);
-- [WebGLHandlesContextLoss] GLboolean isEnabled(GLenum cap);
-- [WebGLHandlesContextLoss] GLboolean isFramebuffer(WebGLFramebuffer? framebuffer);
-- [WebGLHandlesContextLoss] GLboolean isProgram(WebGLProgram? program);
-- [WebGLHandlesContextLoss] GLboolean isRenderbuffer(WebGLRenderbuffer? renderbuffer);
-- [WebGLHandlesContextLoss] GLboolean isShader(WebGLShader? shader);
-- [WebGLHandlesContextLoss] GLboolean isTexture(WebGLTexture? texture);
-- void lineWidth(GLfloat width);
not overriding procedure Link_Program
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "linkProgram";
-- void pixelStorei(GLenum pname, GLint param);
-- void polygonOffset(GLfloat factor, GLfloat units);
not overriding procedure Read_Pixels
(Self : not null access WebGL_Rendering_Context;
X : WebAPI.WebGL.Glint;
Y : WebAPI.WebGL.Glint;
Width : WebAPI.WebGL.Glsizei;
Height : WebAPI.WebGL.Glsizei;
Format : WebAPI.WebGL.GLenum;
Data_Type : WebAPI.WebGL.GLenum;
Pixels : System.Address) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "readPixels";
not overriding procedure Renderbuffer_Storage
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Format : WebAPI.WebGL.GLenum;
Width : WebAPI.WebGL.Glsizei;
Height : WebAPI.WebGL.Glsizei) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "renderbufferStorage";
-- void sampleCoverage(GLclampf value, GLboolean invert);
-- void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
not overriding procedure Shader_Source
(Self : not null access WebGL_Rendering_Context;
Shader : access WebAPI.WebGL.Shaders.WebGL_Shader'Class;
Source : League.Strings.Universal_String) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "shaderSource";
-- void stencilFunc(GLenum func, GLint ref, GLuint mask);
-- void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
-- void stencilMask(GLuint mask);
-- void stencilMaskSeparate(GLenum face, GLuint mask);
-- void stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
-- void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
--
-- typedef (ImageBitmap or
-- ImageData or
-- HTMLImageElement or
-- HTMLCanvasElement or
-- HTMLVideoElement) TexImageSource;
not overriding procedure Tex_Image_2D
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Level : WebAPI.WebGL.GLint;
Internal_Format : WebAPI.WebGL.GLint;
Width : WebAPI.WebGL.GLsizei;
Height : WebAPI.WebGL.GLsizei;
Border : WebAPI.WebGL.GLint;
Format : WebAPI.WebGL.GLenum;
Data_Type : WebAPI.WebGL.GLenum;
Pixels : System.Address) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "texImage2D";
-- void texImage2D(GLenum target, GLint level, GLint internalformat,
-- GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
not overriding procedure Tex_Parameterf
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Pname : WebAPI.WebGL.GLenum;
Value : WebAPI.WebGL.GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "texParameterf";
not overriding procedure Tex_Parameteri
(Self : not null access WebGL_Rendering_Context;
Target : WebAPI.WebGL.GLenum;
Pname : WebAPI.WebGL.GLenum;
Value : WebAPI.WebGL.GLint) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "texParameteri";
-- void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
-- GLsizei width, GLsizei height,
-- GLenum format, GLenum type, ArrayBufferView? pixels);
-- void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
-- GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
not overriding procedure Uniform_1f
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
X : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform1f";
-- void uniform1fv(WebGLUniformLocation? location, Float32Array v);
-- void uniform1fv(WebGLUniformLocation? location, sequence<GLfloat> v);
not overriding procedure Uniform_1i
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
X : GLint) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform1i";
-- void uniform1iv(WebGLUniformLocation? location, Int32Array v);
-- void uniform1iv(WebGLUniformLocation? location, sequence<long> v);
not overriding procedure Uniform_2f
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
X : GLfloat;
Y : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform2f";
not overriding procedure Uniform_2fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Value : GLfloat_Vector_2) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform2fv";
-- void uniform2fv(WebGLUniformLocation? location, sequence<GLfloat> v);
-- void uniform2i(WebGLUniformLocation? location, GLint x, GLint y);
-- void uniform2iv(WebGLUniformLocation? location, Int32Array v);
-- void uniform2iv(WebGLUniformLocation? location, sequence<long> v);
not overriding procedure Uniform_3f
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
X : GLfloat;
Y : GLfloat;
Z : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform3f";
not overriding procedure Uniform_3fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Value : GLfloat_Vector_3) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform3fv";
-- void uniform3fv(WebGLUniformLocation? location, sequence<GLfloat> v);
-- void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z);
-- void uniform3iv(WebGLUniformLocation? location, Int32Array v);
-- void uniform3iv(WebGLUniformLocation? location, sequence<long> v);
not overriding procedure Uniform_4f
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
X : GLfloat;
Y : GLfloat;
Z : GLfloat;
W : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform4f";
not overriding procedure Uniform_4fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Value : GLfloat_Vector_4) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniform4fv";
-- void uniform4fv(WebGLUniformLocation? location, sequence<GLfloat> v);
-- void uniform4i(WebGLUniformLocation? location, GLint x, GLint y, GLint z, GLint w);
-- void uniform4iv(WebGLUniformLocation? location, Int32Array v);
-- void uniform4iv(WebGLUniformLocation? location, sequence<long> v);
not overriding procedure Uniform_Matrix_2fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Transpose : Boolean;
Value : GLfloat_Matrix_2x2) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniformMatrix2fv";
-- void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose,
-- sequence<GLfloat> value);
not overriding procedure Uniform_Matrix_3fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Transpose : Boolean;
Value : GLfloat_Matrix_3x3) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniformMatrix3fv";
-- void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose,
-- sequence<GLfloat> value);
not overriding procedure Uniform_Matrix_4fv
(Self : not null access WebGL_Rendering_Context;
Location : WebAPI.WebGL.Uniform_Locations.WebGL_Uniform_Location_Access;
Transpose : Boolean;
Value : GLfloat_Matrix_4x4) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "uniformMatrix4fv";
-- void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose,
-- sequence<GLfloat> value);
not overriding procedure Use_Program
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "useProgram";
not overriding procedure Validate_Program
(Self : not null access WebGL_Rendering_Context;
Program : access WebAPI.WebGL.Programs.WebGL_Program'Class) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "validateProgram";
not overriding procedure Vertex_Attrib_1f
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
X : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib1f";
-- typedef (Float32Array or sequence<GLfloat>) VertexAttribFVSource;
-- void vertexAttrib1fv(GLuint indx, VertexAttribFVSource values);
not overriding procedure Vertex_Attrib_2f
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
X : GLfloat;
Y : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib2f";
not overriding procedure Vertex_Attrib_2fv
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
Value : GLfloat_Matrix_2x2) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib2fv";
not overriding procedure Vertex_Attrib_3f
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
X : GLfloat;
Y : GLfloat;
Z : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib3f";
not overriding procedure Vertex_Attrib_3fv
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
Value : GLfloat_Matrix_3x3) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib3fv";
not overriding procedure Vertex_Attrib_4f
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
X : GLfloat;
Y : GLfloat;
Z : GLfloat;
W : GLfloat) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib4f";
not overriding procedure Vertex_Attrib_4fv
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
Value : GLfloat_Matrix_4x4) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttrib4fv";
not overriding procedure Vertex_Attrib_Pointer
(Self : not null access WebGL_Rendering_Context;
Index : GLuint;
Size : GLint;
Data_Type : GLenum;
Normalized : Boolean;
Stride : GLsizei;
Offset : GLintptr) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "vertexAttribPointer";
not overriding procedure Viewport
(Self : not null access WebGL_Rendering_Context;
X : GLint;
Y : GLint;
Width : GLsizei;
Height : GLsizei) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "viewport";
end WebAPI.WebGL.Rendering_Contexts;
|
procedure First is
begin
null;
end First;
|
-- Copyright 2010-2020 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Mixed;
procedure A is
begin
Mixed.Start_Test;
end A;
|
package body System.Interrupt_Numbers is
function Is_Reserved (Interrupt : C.signed_int) return Boolean is
begin
return Interrupt not in First_Interrupt_Id .. Last_Interrupt_Id;
-- SIGKILL and SIGSTOP are not declared in mingw
end Is_Reserved;
end System.Interrupt_Numbers;
|
-----------------------------------------------------------------------
-- util-streams-aes -- AES encoding and decoding streams
-- Copyright (C) 2019 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Encoders.AES;
with Util.Streams.Buffered.Encoders;
-- == AES Encoding Streams ==
-- The `Util.Streams.AES` package define the `Encoding_Stream` and `Decoding_Stream` types to
-- encrypt and decrypt using the AES cipher. Before using these streams, you must use
-- the `Set_Key` procedure to setup the encryption or decryption key and define the AES
-- encryption mode to be used. The following encryption modes are supported:
--
-- * AES-ECB
-- * AES-CBC
-- * AES-PCBC
-- * AES-CFB
-- * AES-OFB
-- * AES-CTR
--
-- The encryption and decryption keys are represented by the `Util.Encoders.Secret_Key` limited
-- type. The key cannot be copied, has its content protected and will erase the memory once
-- the instance is deleted. The size of the encryption key defines the AES encryption level
-- to be used:
--
-- * Use 16 bytes, or `Util.Encoders.AES.AES_128_Length` for AES-128,
-- * Use 24 bytes, or `Util.Encoders.AES.AES_192_Length` for AES-192,
-- * Use 32 bytes, or `Util.Encoders.AES.AES_256_Length` for AES-256.
--
-- Other key sizes will raise a pre-condition or constraint error exception.
-- The recommended key size is 32 bytes to use AES-256. The key could be declared as follows:
--
-- Key : Util.Encoders.Secret_Key
-- (Length => Util.Encoders.AES.AES_256_Length);
--
-- The encryption and decryption key are initialized by using the `Util.Encoders.Create`
-- operations or by using one of the key derivative functions provided by the
-- `Util.Encoders.KDF` package. A simple string password is created by using:
--
-- Password_Key : constant Util.Encoders.Secret_Key
-- := Util.Encoders.Create ("mysecret");
--
-- Using a password key like this is not the good practice and it may be useful to generate
-- a stronger key by using one of the key derivative function. We will use the
-- PBKDF2 HMAC-SHA256 with 20000 loops (see RFC 8018):
--
-- Util.Encoders.KDF.PBKDF2_HMAC_SHA256 (Password => Password_Key,
-- Salt => Password_Key,
-- Counter => 20000,
-- Result => Key);
--
-- To write a text, encrypt the content and save the file, we can chain several stream objects
-- together. Because they are chained, the last stream object in the chain must be declared
-- first and the first element of the chain will be declared last. The following declaration
-- is used:
--
-- Out_Stream : aliased Util.Streams.Files.File_Stream;
-- Cipher : aliased Util.Streams.AES.Encoding_Stream;
-- Printer : Util.Streams.Texts.Print_Stream;
--
-- The stream objects are chained together by using their `Initialize` procedure.
-- The `Out_Stream` is configured to write on the `encrypted.aes` file.
-- The `Cipher` is configured to write in the `Out_Stream` with a 32Kb buffer.
-- The `Printer` is configured to write in the `Cipher` with a 4Kb buffer.
--
-- Out_Stream.Initialize (Mode => Ada.Streams.Stream_IO.In_File,
-- Name => "encrypted.aes");
-- Cipher.Initialize (Output => Out_Stream'Access,
-- Size => 32768);
-- Printer.Initialize (Output => Cipher'Access,
-- Size => 4096);
--
-- The last step before using the cipher is to configure the encryption key and modes:
--
-- Cipher.Set_Key (Secret => Key, Mode => Util.Encoders.AES.ECB);
--
-- It is now possible to write the text by using the `Printer` object:
--
-- Printer.Write ("Hello world!");
--
--
package Util.Streams.AES is
package Encoding is
new Util.Streams.Buffered.Encoders (Encoder => Util.Encoders.AES.Encoder);
package Decoding is
new Util.Streams.Buffered.Encoders (Encoder => Util.Encoders.AES.Decoder);
type Encoding_Stream is new Encoding.Encoder_Stream with null record;
-- Set the encryption key and mode to be used.
procedure Set_Key (Stream : in out Encoding_Stream;
Secret : in Util.Encoders.Secret_Key;
Mode : in Util.Encoders.AES.AES_Mode := Util.Encoders.AES.CBC);
-- Set the encryption initialization vector before starting the encryption.
procedure Set_IV (Stream : in out Encoding_Stream;
IV : in Util.Encoders.AES.Word_Block_Type);
type Decoding_Stream is new Decoding.Encoder_Stream with null record;
-- Set the encryption key and mode to be used.
procedure Set_Key (Stream : in out Decoding_Stream;
Secret : in Util.Encoders.Secret_Key;
Mode : in Util.Encoders.AES.AES_Mode := Util.Encoders.AES.CBC);
-- Set the encryption initialization vector before starting the encryption.
procedure Set_IV (Stream : in out Decoding_Stream;
IV : in Util.Encoders.AES.Word_Block_Type);
end Util.Streams.AES;
|
-----------------------------------------------------------------------
-- util-encoders-quoted_printable -- Encode/Decode a stream in quoted-printable
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package Util.Encoders.Quoted_Printable is
pragma Preelaborate;
-- Decode the Quoted-Printable string and return the result.
-- When Strict is true, raises the Encoding_Error exception if the
-- format is invalid. Otherwise, ignore invalid encoding.
function Decode (Content : in String;
Strict : in Boolean := True) return String;
-- Decode the "Q" encoding, similar to Quoted-Printable but with
-- spaces that can be replaced by '_'.
-- See RFC 2047.
function Q_Decode (Content : in String) return String;
end Util.Encoders.Quoted_Printable;
|
-- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_window_iterator_t is
-- Item
--
type Item is record
data : access xcb.xcb_window_t;
the_rem : aliased Interfaces.C.int;
index : aliased Interfaces.C.int;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_window_iterator_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_window_iterator_t.Item,
Element_Array => xcb.xcb_window_iterator_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_window_iterator_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_window_iterator_t.Pointer,
Element_Array => xcb.xcb_window_iterator_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_window_iterator_t;
|
package Asis_Adapter.Element.Associations is
procedure Do_Pre_Child_Processing
(Element : in Asis.Element;
State : in out Class);
private
-- For debuggng:
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name & "Associations";
end Asis_Adapter.Element.Associations;
|
with Ada.Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Characters.Handling;
use Ada.Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Characters.Handling;
procedure Hello is
Name : Unbounded_String;
Input : Character;
function Title_Case (Str : in String) return String is
Result : String(Str'Range);
LastCharacterWasSpace : Boolean := True;
begin
for C in Str'Range loop
if Str(C) = ' ' then
LastCharacterWasSpace := True;
Result(C) := Str(C);
elsif LastCharacterWasSpace then
Result(C) := To_Upper(Str(C));
LastCharacterWasSpace := False;
else
Result(C) := To_Lower(Str(C));
LastCharacterWasSpace := False;
end if;
end loop;
return Result;
end Title_Case;
begin
Put_Line("It's the Hello World example.");
loop
Put_Line("What's your name?");
Get_Line(Name);
Put_Line("Hello " & Title_Case(To_String(Name)) & "!");
Put_Line("It's a me, Mario!");
Put_Line("Again? (Y/N)");
Get(Input); Skip_Line;
exit when Input /= 'y' and Input /= 'Y';
end loop;
end Hello;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32H743x.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package STM32_SVD.GPIO is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- MODER_MODE array element
subtype MODER_MODE_Element is HAL.UInt2;
-- MODER_MODE array
type MODER_MODE_Field_Array is array (0 .. 15) of MODER_MODE_Element
with Component_Size => 2, Size => 32;
-- GPIO port mode register
type MODER_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- MODE as a value
Val : HAL.UInt32;
when True =>
-- MODE as an array
Arr : MODER_MODE_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MODER_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- OTYPER_OT array
type OTYPER_OT_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for OTYPER_OT
type OTYPER_OT_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OT as a value
Val : HAL.UInt16;
when True =>
-- OT as an array
Arr : OTYPER_OT_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for OTYPER_OT_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- GPIO port output type register
type OTYPER_Register is record
-- Port x configuration bits (y = 0..15) These bits are written by
-- software to configure the I/O output type.
OT : OTYPER_OT_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for OTYPER_Register use record
OT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- OSPEEDR_OSPEED array element
subtype OSPEEDR_OSPEED_Element is HAL.UInt2;
-- OSPEEDR_OSPEED array
type OSPEEDR_OSPEED_Field_Array is array (0 .. 15)
of OSPEEDR_OSPEED_Element
with Component_Size => 2, Size => 32;
-- GPIO port output speed register
type OSPEEDR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OSPEED as a value
Val : HAL.UInt32;
when True =>
-- OSPEED as an array
Arr : OSPEEDR_OSPEED_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for OSPEEDR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- PUPDR_PUPD array element
subtype PUPDR_PUPD_Element is HAL.UInt2;
-- PUPDR_PUPD array
type PUPDR_PUPD_Field_Array is array (0 .. 15) of PUPDR_PUPD_Element
with Component_Size => 2, Size => 32;
-- GPIO port pull-up/pull-down register
type PUPDR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- PUPD as a value
Val : HAL.UInt32;
when True =>
-- PUPD as an array
Arr : PUPDR_PUPD_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PUPDR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- IDR array
type IDR_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for IDR
type IDR_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- IDR as a value
Val : HAL.UInt16;
when True =>
-- IDR as an array
Arr : IDR_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for IDR_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- GPIO port input data register
type IDR_Register is record
-- Read-only. Port input data bit (y = 0..15) These bits are read-only.
-- They contain the input value of the corresponding I/O port.
IDR : IDR_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IDR_Register use record
IDR at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- ODR array
type ODR_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for ODR
type ODR_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- ODR as a value
Val : HAL.UInt16;
when True =>
-- ODR as an array
Arr : ODR_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for ODR_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- GPIO port output data register
type ODR_Register is record
-- Port output data bit These bits can be read and written by software.
-- Note: For atomic bit set/reset, the OD bits can be individually set
-- and/or reset by writing to the GPIOx_BSRR or GPIOx_BRR registers (x =
-- A..F).
ODR : ODR_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ODR_Register use record
ODR at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- BSRR_BS array
type BSRR_BS_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for BSRR_BS
type BSRR_BS_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- BS as a value
Val : HAL.UInt16;
when True =>
-- BS as an array
Arr : BSRR_BS_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for BSRR_BS_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- BSRR_BR array
type BSRR_BR_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for BSRR_BR
type BSRR_BR_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- BR as a value
Val : HAL.UInt16;
when True =>
-- BR as an array
Arr : BSRR_BR_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for BSRR_BR_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- GPIO port bit set/reset register
type BSRR_Register is record
-- Write-only. Port x set bit y (y= 0..15) These bits are write-only. A
-- read to these bits returns the value 0x0000.
BS : BSRR_BS_Field := (As_Array => False, Val => 16#0#);
-- Write-only. Port x reset bit y (y = 0..15) These bits are write-only.
-- A read to these bits returns the value 0x0000. Note: If both BSx and
-- BRx are set, BSx has priority.
BR : BSRR_BR_Field := (As_Array => False, Val => 16#0#);
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for BSRR_Register use record
BS at 0 range 0 .. 15;
BR at 0 range 16 .. 31;
end record;
-- LCKR_LCK array
type LCKR_LCK_Field_Array is array (0 .. 15) of Boolean
with Component_Size => 1, Size => 16;
-- Type definition for LCKR_LCK
type LCKR_LCK_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- LCK as a value
Val : HAL.UInt16;
when True =>
-- LCK as an array
Arr : LCKR_LCK_Field_Array;
end case;
end record
with Unchecked_Union, Size => 16;
for LCKR_LCK_Field use record
Val at 0 range 0 .. 15;
Arr at 0 range 0 .. 15;
end record;
-- This register is used to lock the configuration of the port bits when a
-- correct write sequence is applied to bit 16 (LCKK). The value of bits
-- [15:0] is used to lock the configuration of the GPIO. During the write
-- sequence, the value of LCKR[15:0] must not change. When the LOCK
-- sequence has been applied on a port bit, the value of this port bit can
-- no longer be modified until the next MCU reset or peripheral reset.A
-- specific write sequence is used to write to the GPIOx_LCKR register.
-- Only word access (32-bit long) is allowed during this locking
-- sequence.Each lock bit freezes a specific configuration register
-- (control and alternate function registers).
type LCKR_Register is record
-- Port x lock bit y (y= 0..15) These bits are read/write but can only
-- be written when the LCKK bit is 0.
LCK : LCKR_LCK_Field := (As_Array => False, Val => 16#0#);
-- Lock key This bit can be read any time. It can only be modified using
-- the lock key write sequence. LOCK key write sequence: WR LCKR[16] = 1
-- + LCKR[15:0] WR LCKR[16] = 0 + LCKR[15:0] WR LCKR[16] = 1 +
-- LCKR[15:0] RD LCKR RD LCKR[16] = 1 (this read operation is optional
-- but it confirms that the lock is active) Note: During the LOCK key
-- write sequence, the value of LCK[15:0] must not change. Any error in
-- the lock sequence aborts the lock. After the first lock sequence on
-- any bit of the port, any read access on the LCKK bit will return 1
-- until the next MCU reset or peripheral reset.
LCKK : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for LCKR_Register use record
LCK at 0 range 0 .. 15;
LCKK at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- AFRL_AFSEL array element
subtype AFRL_AFSEL_Element is HAL.UInt4;
-- AFRL_AFSEL array
type AFRL_AFSEL_Field_Array is array (0 .. 7) of AFRL_AFSEL_Element
with Component_Size => 4, Size => 32;
-- GPIO alternate function low register
type AFRL_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- AFSEL as a value
Val : HAL.UInt32;
when True =>
-- AFSEL as an array
Arr : AFRL_AFSEL_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AFRL_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- AFRH_AFSEL array element
subtype AFRH_AFSEL_Element is HAL.UInt4;
-- AFRH_AFSEL array
type AFRH_AFSEL_Field_Array is array (8 .. 15) of AFRH_AFSEL_Element
with Component_Size => 4, Size => 32;
-- GPIO alternate function high register
type AFRH_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- AFSEL as a value
Val : HAL.UInt32;
when True =>
-- AFSEL as an array
Arr : AFRH_AFSEL_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AFRH_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- GPIO
type GPIO_Peripheral is record
-- GPIO port mode register
MODER : aliased MODER_Register;
-- GPIO port output type register
OTYPER : aliased OTYPER_Register;
-- GPIO port output speed register
OSPEEDR : aliased OSPEEDR_Register;
-- GPIO port pull-up/pull-down register
PUPDR : aliased PUPDR_Register;
-- GPIO port input data register
IDR : aliased IDR_Register;
-- GPIO port output data register
ODR : aliased ODR_Register;
-- GPIO port bit set/reset register
BSRR : aliased BSRR_Register;
-- This register is used to lock the configuration of the port bits when
-- a correct write sequence is applied to bit 16 (LCKK). The value of
-- bits [15:0] is used to lock the configuration of the GPIO. During the
-- write sequence, the value of LCKR[15:0] must not change. When the
-- LOCK sequence has been applied on a port bit, the value of this port
-- bit can no longer be modified until the next MCU reset or peripheral
-- reset.A specific write sequence is used to write to the GPIOx_LCKR
-- register. Only word access (32-bit long) is allowed during this
-- locking sequence.Each lock bit freezes a specific configuration
-- register (control and alternate function registers).
LCKR : aliased LCKR_Register;
-- GPIO alternate function low register
AFRL : aliased AFRL_Register;
-- GPIO alternate function high register
AFRH : aliased AFRH_Register;
end record
with Volatile;
for GPIO_Peripheral use record
MODER at 16#0# range 0 .. 31;
OTYPER at 16#4# range 0 .. 31;
OSPEEDR at 16#8# range 0 .. 31;
PUPDR at 16#C# range 0 .. 31;
IDR at 16#10# range 0 .. 31;
ODR at 16#14# range 0 .. 31;
BSRR at 16#18# range 0 .. 31;
LCKR at 16#1C# range 0 .. 31;
AFRL at 16#20# range 0 .. 31;
AFRH at 16#24# range 0 .. 31;
end record;
-- GPIO
GPIOA_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOA_Base;
-- GPIO
GPIOB_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOB_Base;
-- GPIO
GPIOC_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOC_Base;
-- GPIO
GPIOD_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOD_Base;
-- GPIO
GPIOE_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOE_Base;
-- GPIO
GPIOF_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOF_Base;
-- GPIO
GPIOG_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOG_Base;
-- GPIO
GPIOH_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOH_Base;
-- GPIO
GPIOI_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOI_Base;
-- GPIO
GPIOJ_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOJ_Base;
-- GPIO
GPIOK_Periph : aliased GPIO_Peripheral
with Import, Address => GPIOK_Base;
end STM32_SVD.GPIO;
|
------------------------------------------------------------------------------
-- --
-- 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;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 5 6 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Storage_Elements;
with System.Unsigned_Types;
package body System.Pack_56 is
subtype Bit_Order is System.Bit_Order;
Reverse_Bit_Order : constant Bit_Order :=
Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
subtype Ofs is System.Storage_Elements.Storage_Offset;
subtype Uns is System.Unsigned_Types.Unsigned;
subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
use type System.Storage_Elements.Storage_Offset;
use type System.Unsigned_Types.Unsigned;
type Cluster is record
E0, E1, E2, E3, E4, E5, E6, E7 : Bits_56;
end record;
for Cluster use record
E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
end record;
for Cluster'Size use Bits * 8;
for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
1 +
1 * Boolean'Pos (Bits mod 2 = 0) +
2 * Boolean'Pos (Bits mod 4 = 0));
-- Use maximum possible alignment, given the bit field size, since this
-- will result in the most efficient code possible for the field.
type Cluster_Ref is access Cluster;
type Rev_Cluster is new Cluster
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_Cluster_Ref is access Rev_Cluster;
-- The following declarations are for the case where the address
-- passed to GetU_56 or SetU_56 is not guaranteed to be aligned.
-- These routines are used when the packed array is itself a
-- component of a packed record, and therefore may not be aligned.
type ClusterU is new Cluster;
for ClusterU'Alignment use 1;
type ClusterU_Ref is access ClusterU;
type Rev_ClusterU is new ClusterU
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_ClusterU_Ref is access Rev_ClusterU;
------------
-- Get_56 --
------------
function Get_56
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_56
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end Get_56;
-------------
-- GetU_56 --
-------------
function GetU_56
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_56
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : ClusterU_Ref with Address => A'Address, Import;
RC : Rev_ClusterU_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end GetU_56;
------------
-- Set_56 --
------------
procedure Set_56
(Arr : System.Address;
N : Natural;
E : Bits_56;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end Set_56;
-------------
-- SetU_56 --
-------------
procedure SetU_56
(Arr : System.Address;
N : Natural;
E : Bits_56;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : ClusterU_Ref with Address => A'Address, Import;
RC : Rev_ClusterU_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end SetU_56;
end System.Pack_56;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 9 --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2014, 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 Table;
with Types; use Types;
package Sem_Ch9 is
procedure Analyze_Abort_Statement (N : Node_Id);
procedure Analyze_Accept_Alternative (N : Node_Id);
procedure Analyze_Accept_Statement (N : Node_Id);
procedure Analyze_Asynchronous_Select (N : Node_Id);
procedure Analyze_Conditional_Entry_Call (N : Node_Id);
procedure Analyze_Delay_Alternative (N : Node_Id);
procedure Analyze_Delay_Relative (N : Node_Id);
procedure Analyze_Delay_Until (N : Node_Id);
procedure Analyze_Entry_Body (N : Node_Id);
procedure Analyze_Entry_Body_Formal_Part (N : Node_Id);
procedure Analyze_Entry_Call_Alternative (N : Node_Id);
procedure Analyze_Entry_Declaration (N : Node_Id);
procedure Analyze_Entry_Index_Specification (N : Node_Id);
procedure Analyze_Protected_Body (N : Node_Id);
procedure Analyze_Protected_Definition (N : Node_Id);
procedure Analyze_Protected_Type_Declaration (N : Node_Id);
procedure Analyze_Requeue (N : Node_Id);
procedure Analyze_Selective_Accept (N : Node_Id);
procedure Analyze_Single_Protected_Declaration (N : Node_Id);
procedure Analyze_Single_Task_Declaration (N : Node_Id);
procedure Analyze_Task_Body (N : Node_Id);
procedure Analyze_Task_Definition (N : Node_Id);
procedure Analyze_Task_Type_Declaration (N : Node_Id);
procedure Analyze_Terminate_Alternative (N : Node_Id);
procedure Analyze_Timed_Entry_Call (N : Node_Id);
procedure Analyze_Triggering_Alternative (N : Node_Id);
procedure Install_Declarations (Spec : Entity_Id);
-- Make visible in corresponding body the entities defined in a task,
-- protected type declaration, or entry declaration.
------------------------------
-- Lock Free Data Structure --
------------------------------
-- A lock-free subprogram is a protected routine which references a unique
-- protected scalar component and does not contain statements that cause
-- side effects. Due to this restricted behavior, all references to shared
-- data from within the subprogram can be synchronized through the use of
-- atomic operations rather than relying on locks.
type Lock_Free_Subprogram is record
Sub_Body : Node_Id;
-- Reference to the body of a protected subprogram which meets the lock-
-- free requirements.
Comp_Id : Entity_Id;
-- Reference to the scalar component referenced from within Sub_Body
end record;
-- This table establishes a relation between a protected subprogram body
-- and a unique component it references. The table is used when building
-- the lock-free versions of a protected subprogram body.
package Lock_Free_Subprogram_Table is new Table.Table (
Table_Component_Type => Lock_Free_Subprogram,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => 5,
Table_Increment => 5,
Table_Name => "Lock_Free_Subprogram_Table");
end Sem_Ch9;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- G N A T . E X P E C T . T T Y --
-- --
-- S p e c --
-- --
-- Copyright (C) 2000-2019, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with GNAT.OS_Lib; use GNAT.OS_Lib;
with System; use System;
package body GNAT.Expect.TTY is
On_Windows : constant Boolean := Directory_Separator = '\';
-- True when on Windows
-----------
-- Close --
-----------
overriding procedure Close
(Descriptor : in out TTY_Process_Descriptor;
Status : out Integer)
is
procedure Terminate_Process (Process : System.Address);
pragma Import (C, Terminate_Process, "__gnat_terminate_process");
function Waitpid (Process : System.Address) return Integer;
pragma Import (C, Waitpid, "__gnat_tty_waitpid");
-- Wait for a specific process id, and return its exit code
procedure Free_Process (Process : System.Address);
pragma Import (C, Free_Process, "__gnat_free_process");
procedure Close_TTY (Process : System.Address);
pragma Import (C, Close_TTY, "__gnat_close_tty");
begin
-- If we haven't already closed the process
if Descriptor.Process = System.Null_Address then
Status := -1;
else
-- Send a Ctrl-C to the process first. This way, if the launched
-- process is a "sh" or "cmd", the child processes will get
-- terminated as well. Otherwise, terminating the main process
-- brutally will leave the children running.
-- Note: special characters are sent to the terminal to generate the
-- signal, so this needs to be done while the file descriptors are
-- still open (it used to be after the closes and that was wrong).
Interrupt (Descriptor);
delay (0.05);
if Descriptor.Input_Fd /= Invalid_FD then
Close (Descriptor.Input_Fd);
end if;
if Descriptor.Error_Fd /= Descriptor.Output_Fd
and then Descriptor.Error_Fd /= Invalid_FD
then
Close (Descriptor.Error_Fd);
end if;
if Descriptor.Output_Fd /= Invalid_FD then
Close (Descriptor.Output_Fd);
end if;
Terminate_Process (Descriptor.Process);
Status := Waitpid (Descriptor.Process);
if not On_Windows then
Close_TTY (Descriptor.Process);
end if;
Free_Process (Descriptor.Process'Address);
Descriptor.Process := System.Null_Address;
GNAT.OS_Lib.Free (Descriptor.Buffer);
Descriptor.Buffer_Size := 0;
end if;
end Close;
overriding procedure Close (Descriptor : in out TTY_Process_Descriptor) is
Status : Integer;
begin
Close (Descriptor, Status);
end Close;
-----------------------------
-- Close_Pseudo_Descriptor --
-----------------------------
procedure Close_Pseudo_Descriptor
(Descriptor : in out TTY_Process_Descriptor)
is
begin
Descriptor.Buffer_Size := 0;
GNAT.OS_Lib.Free (Descriptor.Buffer);
end Close_Pseudo_Descriptor;
---------------
-- Interrupt --
---------------
overriding procedure Interrupt
(Descriptor : in out TTY_Process_Descriptor)
is
procedure Internal (Process : System.Address);
pragma Import (C, Internal, "__gnat_interrupt_process");
begin
if Descriptor.Process /= System.Null_Address then
Internal (Descriptor.Process);
end if;
end Interrupt;
procedure Interrupt (Pid : Integer) is
procedure Internal (Pid : Integer);
pragma Import (C, Internal, "__gnat_interrupt_pid");
begin
Internal (Pid);
end Interrupt;
-----------------------
-- Terminate_Process --
-----------------------
procedure Terminate_Process (Pid : Integer) is
procedure Internal (Pid : Integer);
pragma Import (C, Internal, "__gnat_terminate_pid");
begin
Internal (Pid);
end Terminate_Process;
-----------------------
-- Pseudo_Descriptor --
-----------------------
procedure Pseudo_Descriptor
(Descriptor : out TTY_Process_Descriptor'Class;
TTY : GNAT.TTY.TTY_Handle;
Buffer_Size : Natural := 4096) is
begin
Descriptor.Input_Fd := GNAT.TTY.TTY_Descriptor (TTY);
Descriptor.Output_Fd := Descriptor.Input_Fd;
-- Create the buffer
Descriptor.Buffer_Size := Buffer_Size;
if Buffer_Size /= 0 then
Descriptor.Buffer := new String (1 .. Positive (Buffer_Size));
end if;
end Pseudo_Descriptor;
----------
-- Send --
----------
overriding procedure Send
(Descriptor : in out TTY_Process_Descriptor;
Str : String;
Add_LF : Boolean := True;
Empty_Buffer : Boolean := False)
is
Header : String (1 .. 5);
Length : Natural;
Ret : Natural;
procedure Internal
(Process : System.Address;
S : in out String;
Length : Natural;
Ret : out Natural);
pragma Import (C, Internal, "__gnat_send_header");
begin
Length := Str'Length;
if Add_LF then
Length := Length + 1;
end if;
Internal (Descriptor.Process, Header, Length, Ret);
if Ret = 1 then
-- Need to use the header
GNAT.Expect.Send
(Process_Descriptor (Descriptor),
Header & Str, Add_LF, Empty_Buffer);
else
GNAT.Expect.Send
(Process_Descriptor (Descriptor),
Str, Add_LF, Empty_Buffer);
end if;
end Send;
--------------
-- Set_Size --
--------------
procedure Set_Size
(Descriptor : in out TTY_Process_Descriptor'Class;
Rows : Natural;
Columns : Natural)
is
procedure Internal (Process : System.Address; R, C : Integer);
pragma Import (C, Internal, "__gnat_setup_winsize");
begin
if Descriptor.Process /= System.Null_Address then
Internal (Descriptor.Process, Rows, Columns);
end if;
end Set_Size;
---------------------------
-- Set_Up_Communications --
---------------------------
overriding procedure Set_Up_Communications
(Pid : in out TTY_Process_Descriptor;
Err_To_Out : Boolean;
Pipe1 : access Pipe_Type;
Pipe2 : access Pipe_Type;
Pipe3 : access Pipe_Type)
is
pragma Unreferenced (Err_To_Out, Pipe1, Pipe2, Pipe3);
function Internal (Process : System.Address) return Integer;
pragma Import (C, Internal, "__gnat_setup_communication");
begin
if Internal (Pid.Process'Address) /= 0 then
raise Invalid_Process with "cannot setup communication.";
end if;
end Set_Up_Communications;
---------------------------------
-- Set_Up_Child_Communications --
---------------------------------
overriding procedure Set_Up_Child_Communications
(Pid : in out TTY_Process_Descriptor;
Pipe1 : in out Pipe_Type;
Pipe2 : in out Pipe_Type;
Pipe3 : in out Pipe_Type;
Cmd : String;
Args : System.Address)
is
pragma Unreferenced (Pipe1, Pipe2, Pipe3, Cmd);
function Internal
(Process : System.Address; Argv : System.Address; Use_Pipes : Integer)
return Process_Id;
pragma Import (C, Internal, "__gnat_setup_child_communication");
begin
Pid.Pid := Internal (Pid.Process, Args, Boolean'Pos (Pid.Use_Pipes));
end Set_Up_Child_Communications;
----------------------------------
-- Set_Up_Parent_Communications --
----------------------------------
overriding procedure Set_Up_Parent_Communications
(Pid : in out TTY_Process_Descriptor;
Pipe1 : in out Pipe_Type;
Pipe2 : in out Pipe_Type;
Pipe3 : in out Pipe_Type)
is
pragma Unreferenced (Pipe1, Pipe2, Pipe3);
procedure Internal
(Process : System.Address;
Inputfp : out File_Descriptor;
Outputfp : out File_Descriptor;
Errorfp : out File_Descriptor;
Pid : out Process_Id);
pragma Import (C, Internal, "__gnat_setup_parent_communication");
begin
Internal
(Pid.Process, Pid.Input_Fd, Pid.Output_Fd, Pid.Error_Fd, Pid.Pid);
end Set_Up_Parent_Communications;
-------------------
-- Set_Use_Pipes --
-------------------
procedure Set_Use_Pipes
(Descriptor : in out TTY_Process_Descriptor;
Use_Pipes : Boolean) is
begin
Descriptor.Use_Pipes := Use_Pipes;
end Set_Use_Pipes;
end GNAT.Expect.TTY;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . F A T _ L F L T --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992,1993,1994,1995,1996 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 package contains an instantiation of the floating-point attribute
-- runtime routines for the type Long_Float.
with System.Fat_Gen;
package System.Fat_LFlt is
pragma Pure (Fat_LFlt);
-- Note the only entity from this package that is accessed by Rtsfind
-- is the name of the package instantiation. Entities within this package
-- (i.e. the individual floating-point attribute routines) are accessed
-- by name using selected notation.
package Fat_Long_Float is new System.Fat_Gen (Long_Float);
end System.Fat_LFlt;
|
package p5 is
end p5;
|
-----------------------------------------------------------------------
-- servlet-servlets-mappers -- Read servlet configuration files
-- Copyright (C) 2011, 2012, 2013, 2015, 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 Ada.Containers;
with EL.Utils;
package body Servlet.Core.Mappers is
-- ------------------------------
-- Save in the servlet config object the value associated with the given field.
-- When the <b>FILTER_MAPPING</b>, <b>SERVLET_MAPPING</b> or <b>CONTEXT_PARAM</b> field
-- is reached, insert the new configuration rule in the servlet registry.
-- ------------------------------
procedure Set_Member (N : in out Servlet_Config;
Field : in Servlet_Fields;
Value : in Util.Beans.Objects.Object) is
use Util.Beans.Objects;
use type Ada.Containers.Count_Type;
procedure Add_Filter (Pattern : in Util.Beans.Objects.Object);
procedure Add_Mapping (Pattern : in Util.Beans.Objects.Object);
procedure Add_Mapping (Handler : access procedure (Pattern : in Util.Beans.Objects.Object);
Message : in String);
procedure Add_Filter (Pattern : in Util.Beans.Objects.Object) is
begin
N.Handler.Add_Filter_Mapping (Pattern => To_String (Pattern),
Name => To_String (N.Filter_Name));
end Add_Filter;
procedure Add_Mapping (Pattern : in Util.Beans.Objects.Object) is
begin
N.Handler.Add_Mapping (Pattern => To_String (Pattern),
Name => To_String (N.Servlet_Name));
end Add_Mapping;
procedure Add_Mapping (Handler : access procedure (Pattern : in Util.Beans.Objects.Object);
Message : in String) is
Last : constant Ada.Containers.Count_Type := N.URL_Patterns.Length;
begin
if Last = 0 then
raise Util.Serialize.Mappers.Field_Error with Message;
end if;
for I in 1 .. Last loop
N.URL_Patterns.Query_Element (Positive (I), Handler);
end loop;
N.URL_Patterns.Clear;
end Add_Mapping;
begin
-- <context-param>
-- <param-name>property</param-name>
-- <param-value>false</param-value>
-- </context-param>
-- <filter-mapping>
-- <filter-name>Dump Filter</filter-name>
-- <servlet-name>Faces Servlet</servlet-name>
-- </filter-mapping>
case Field is
when FILTER_NAME =>
N.Filter_Name := Value;
when SERVLET_NAME =>
N.Servlet_Name := Value;
when URL_PATTERN =>
N.URL_Patterns.Append (Value);
when PARAM_NAME =>
N.Param_Name := Value;
when PARAM_VALUE =>
N.Param_Value := EL.Utils.Eval (To_String (Value), N.Context.all);
when MIME_TYPE =>
N.Mime_Type := Value;
when EXTENSION =>
N.Extension := Value;
when ERROR_CODE =>
N.Error_Code := Value;
when LOCATION =>
N.Location := Value;
when FILTER_MAPPING =>
Add_Mapping (Add_Filter'Access, "Missing url-pattern for the filter mapping");
when SERVLET_MAPPING =>
Add_Mapping (Add_Mapping'Access, "Missing url-pattern for the servlet mapping");
when CONTEXT_PARAM =>
declare
Name : constant String := To_String (N.Param_Name);
begin
-- If the context parameter already has a value, do not set it again.
-- The value comes from an application setting and we want to keep it.
if N.Override_Context
or else String '(N.Handler.all.Get_Init_Parameter (Name)) = ""
then
if Util.Beans.Objects.Is_Null (N.Param_Value) then
N.Handler.Set_Init_Parameter (Name => Name,
Value => "");
else
N.Handler.Set_Init_Parameter (Name => Name,
Value => To_String (N.Param_Value));
end if;
end if;
end;
when MIME_MAPPING =>
null;
when ERROR_PAGE =>
N.Handler.Set_Error_Page (Error => To_Integer (N.Error_Code),
Page => To_String (N.Location));
end case;
end Set_Member;
SMapper : aliased Servlet_Mapper.Mapper;
-- ------------------------------
-- Setup the XML parser to read the servlet and mapping rules <b>context-param</b>,
-- <b>filter-mapping</b> and <b>servlet-mapping</b>.
-- ------------------------------
package body Reader_Config is
begin
Mapper.Add_Mapping ("faces-config", SMapper'Access);
Mapper.Add_Mapping ("module", SMapper'Access);
Mapper.Add_Mapping ("web-app", SMapper'Access);
Config.Handler := Handler;
Config.Context := Context;
Servlet_Mapper.Set_Context (Mapper, Config'Unchecked_Access);
end Reader_Config;
begin
SMapper.Add_Mapping ("filter-mapping", FILTER_MAPPING);
SMapper.Add_Mapping ("filter-mapping/filter-name", FILTER_NAME);
SMapper.Add_Mapping ("filter-mapping/servlet-name", SERVLET_NAME);
SMapper.Add_Mapping ("filter-mapping/url-pattern", URL_PATTERN);
SMapper.Add_Mapping ("servlet-mapping", SERVLET_MAPPING);
SMapper.Add_Mapping ("servlet-mapping/servlet-name", SERVLET_NAME);
SMapper.Add_Mapping ("servlet-mapping/url-pattern", URL_PATTERN);
SMapper.Add_Mapping ("context-param", CONTEXT_PARAM);
SMapper.Add_Mapping ("context-param/param-name", PARAM_NAME);
SMapper.Add_Mapping ("context-param/param-value", PARAM_VALUE);
SMapper.Add_Mapping ("error-page", ERROR_PAGE);
SMapper.Add_Mapping ("error-page/error-code", ERROR_CODE);
SMapper.Add_Mapping ("error-page/location", LOCATION);
end Servlet.Core.Mappers;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T 1 D R V --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Back_End; use Back_End;
with Checks;
with Comperr;
with Csets;
with Debug; use Debug;
with Elists;
with Errout; use Errout;
with Exp_CG;
with Fmap;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
with Frontend;
with Ghost; use Ghost;
with Gnatvsn; use Gnatvsn;
with Inline;
with Lib; use Lib;
with Lib.Writ; use Lib.Writ;
with Lib.Xref;
with Namet; use Namet;
with Nlists;
with Opt; use Opt;
with Osint; use Osint;
with Osint.C; use Osint.C;
with Output; use Output;
with Par_SCO;
with Prepcomp;
with Repinfo;
with Repinfo.Input;
with Restrict;
with Rident; use Rident;
with Rtsfind;
with SCOs;
with Sem;
with Sem_Ch8;
with Sem_Ch12;
with Sem_Ch13;
with Sem_Elim;
with Sem_Eval;
with Sem_Prag;
with Sem_Type;
with Set_Targ;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Sinput.L; use Sinput.L;
with Snames; use Snames;
with Sprint; use Sprint;
with Stringt;
with Stylesw; use Stylesw;
with Targparm; use Targparm;
with Tbuild;
with Treepr; use Treepr;
with Ttypes;
with Types; use Types;
with Uintp;
with Uname; use Uname;
with Urealp;
with Usage;
with Validsw; use Validsw;
with Warnsw; use Warnsw;
with System.Assertions;
with System.OS_Lib;
--------------
-- Gnat1drv --
--------------
procedure Gnat1drv is
procedure Adjust_Global_Switches;
-- There are various interactions between front-end switch settings,
-- including debug switch settings and target dependent parameters.
-- This procedure takes care of properly handling these interactions.
-- We do it after scanning out all the switches, so that we are not
-- depending on the order in which switches appear.
procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind);
-- Called to check whether a unit described by its compilation unit node
-- and kind has a bad body.
procedure Check_Rep_Info;
-- Called when we are not generating code, to check if -gnatR was requested
-- and if so, explain that we will not be honoring the request.
procedure Post_Compilation_Validation_Checks;
-- This procedure performs various validation checks that have to be left
-- to the end of the compilation process, after generating code but before
-- issuing error messages. In particular, these checks generally require
-- the information provided by the back end in back annotation of declared
-- entities (e.g. actual size and alignment values chosen by the back end).
procedure Read_JSON_Files_For_Repinfo;
-- This procedure exercises the JSON parser of Repinfo by reading back the
-- JSON files generated by -gnatRjs in a previous compilation session. It
-- is intended to make sure that the JSON generator and the JSON parser are
-- kept synchronized when the JSON format evolves.
----------------------------
-- Adjust_Global_Switches --
----------------------------
procedure Adjust_Global_Switches is
procedure SPARK_Library_Warning (Kind : String);
-- Issue a warning in GNATprove mode if the run-time library does not
-- fully support IEEE-754 floating-point semantics.
---------------------------
-- SPARK_Library_Warning --
---------------------------
procedure SPARK_Library_Warning (Kind : String) is
begin
Write_Line
("warning: run-time library may be configured incorrectly");
Write_Line
("warning: (SPARK analysis requires support for " & Kind & ')');
end SPARK_Library_Warning;
-- Start of processing for Adjust_Global_Switches
begin
-- Define pragma GNAT_Annotate as an alias of pragma Annotate, to be
-- able to work around bootstrap limitations with the old syntax of
-- pragma Annotate, and use pragma GNAT_Annotate in compiler sources
-- when needed.
Map_Pragma_Name (From => Name_Gnat_Annotate, To => Name_Annotate);
-- -gnatd.M enables Relaxed_RM_Semantics
if Debug_Flag_Dot_MM then
Relaxed_RM_Semantics := True;
end if;
-- -gnatd.1 enables unnesting of subprograms
if Debug_Flag_Dot_1 then
Unnest_Subprogram_Mode := True;
end if;
-- -gnatd.u enables special C expansion mode
if Debug_Flag_Dot_U then
Modify_Tree_For_C := True;
end if;
-- -gnatd_A disables generation of ALI files
if Debug_Flag_Underscore_AA then
Disable_ALI_File := True;
end if;
-- Set all flags required when generating C code
if Generate_C_Code then
Modify_Tree_For_C := True;
Unnest_Subprogram_Mode := True;
Building_Static_Dispatch_Tables := False;
Minimize_Expression_With_Actions := True;
Expand_Nonbinary_Modular_Ops := True;
-- Set operating mode to Generate_Code to benefit from full front-end
-- expansion (e.g. generics).
Operating_Mode := Generate_Code;
-- Suppress alignment checks since we do not have access to alignment
-- info on the target.
Suppress_Options.Suppress (Alignment_Check) := False;
end if;
-- -gnatd.E sets Error_To_Warning mode, causing selected error messages
-- to be treated as warnings instead of errors.
if Debug_Flag_Dot_EE then
Error_To_Warning := True;
end if;
-- -gnatdJ sets Include_Subprogram_In_Messages, adding the related
-- subprogram as part of the error and warning messages.
if Debug_Flag_JJ then
Include_Subprogram_In_Messages := True;
end if;
-- Disable CodePeer_Mode in Check_Syntax, since we need front-end
-- expansion.
if Operating_Mode = Check_Syntax then
CodePeer_Mode := False;
end if;
-- SCIL mode needs to disable front-end inlining since the generated
-- trees (in particular order and consistency between specs compiled
-- as part of a main unit or as part of a with-clause) are causing
-- troubles.
if Generate_SCIL then
Front_End_Inlining := False;
end if;
-- Tune settings for optimal SCIL generation in CodePeer mode
if CodePeer_Mode then
-- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
-- compatible with CodePeer mode.
GNATprove_Mode := False;
Debug_Flag_Dot_FF := False;
-- Turn off length expansion. CodePeer has its own mechanism to
-- handle length attribute.
Debug_Flag_Dot_PP := True;
-- Turn off C tree generation, not compatible with CodePeer mode. We
-- do not expect this to happen in normal use, since both modes are
-- enabled by special tools, but it is useful to turn off these flags
-- this way when we are doing CodePeer tests on existing test suites
-- that may have -gnateg set, to avoid the need for special casing.
Modify_Tree_For_C := False;
Generate_C_Code := False;
Unnest_Subprogram_Mode := False;
-- Turn off inlining, confuses CodePeer output and gains nothing
Front_End_Inlining := False;
Inline_Active := False;
-- Disable front-end optimizations, to keep the tree as close to the
-- source code as possible, and also to avoid inconsistencies between
-- trees when using different optimization switches.
Optimization_Level := 0;
-- Enable some restrictions systematically to simplify the generated
-- code (and ease analysis). Note that restriction checks are also
-- disabled in CodePeer mode, see Restrict.Check_Restriction, and
-- user specified Restrictions pragmas are ignored, see
-- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
Restrict.Restrictions.Set (No_Exception_Registration) := True;
Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
Restrict.Restrictions.Set (No_Task_Hierarchy) := True;
Restrict.Restrictions.Set (No_Abort_Statements) := True;
Restrict.Restrictions.Set (Max_Asynchronous_Select_Nesting) := True;
Restrict.Restrictions.Value (Max_Asynchronous_Select_Nesting) := 0;
-- Enable pragma Ignore_Pragma (Global) to support legacy code. As a
-- consequence, Refined_Global pragma should be ignored as well, as
-- it is only allowed on a body when pragma Global is given for the
-- spec.
Set_Name_Table_Boolean3 (Name_Global, True);
Set_Name_Table_Boolean3 (Name_Refined_Global, True);
-- Suppress division by zero checks since they are handled
-- implicitly by CodePeer.
-- Turn off dynamic elaboration checks: generates inconsistencies in
-- trees between specs compiled as part of a main unit or as part of
-- a with-clause.
-- Turn off alignment checks: these cannot be proved statically by
-- CodePeer and generate false positives.
-- Enable all other language checks
Suppress_Options.Suppress :=
(Alignment_Check => True,
Division_Check => True,
Elaboration_Check => True,
others => False);
-- Need to enable dynamic elaboration checks to disable strict
-- static checking performed by gnatbind. We are at the same time
-- suppressing actual compile time elaboration checks to simplify
-- the generated code.
Dynamic_Elaboration_Checks := True;
-- Set STRICT mode for overflow checks if not set explicitly. This
-- prevents suppressing of overflow checks by default, in code down
-- below.
if Suppress_Options.Overflow_Mode_General = Not_Set then
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
end if;
-- CodePeer handles division and overflow checks directly, based on
-- the marks set by the frontend, hence no special expansion should
-- be performed in the frontend for division and overflow checks.
Backend_Divide_Checks_On_Target := True;
Backend_Overflow_Checks_On_Target := True;
-- Kill debug of generated code, since it messes up sloc values
Debug_Generated_Code := False;
-- Ditto for -gnateG which interacts badly with handling of pragma
-- Annotate in gnat2scil.
Generate_Processed_File := False;
-- Disable Exception_Extra_Info (-gnateE) which generates more
-- complex trees with no added value, and may confuse CodePeer.
Exception_Extra_Info := False;
-- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
-- to support source navigation.
Xref_Active := True;
-- Set operating mode to Generate_Code to benefit from full front-end
-- expansion (e.g. generics).
Operating_Mode := Generate_Code;
-- We need SCIL generation of course
Generate_SCIL := True;
-- Enable assertions, since they give CodePeer valuable extra info
Assertions_Enabled := True;
-- Set normal RM validity checking and checking of copies (to catch
-- e.g. wrong values used in unchecked conversions).
-- All other validity checking is turned off, since this can generate
-- very complex trees that only confuse CodePeer and do not bring
-- enough useful info.
Reset_Validity_Check_Options;
Set_Validity_Check_Options ("dc");
Check_Validity_Of_Parameters := False;
-- Turn off style check options and ignore any style check pragmas
-- since we are not interested in any front-end warnings when we are
-- getting CodePeer output.
Reset_Style_Check_Options;
Ignore_Style_Checks_Pragmas := True;
-- Always perform semantics and generate ali files in CodePeer mode,
-- so that a gnatmake -c -k will proceed further when possible.
Force_ALI_File := True;
Try_Semantics := True;
-- Make the Ada front end more liberal so that the compiler will
-- allow illegal code that is allowed by other compilers. CodePeer
-- is in the business of finding problems, not enforcing rules.
-- This is useful when using CodePeer mode with other compilers.
Relaxed_RM_Semantics := True;
if Generate_CodePeer_Messages then
-- We do want to emit GNAT warnings when using -gnateC. But,
-- in CodePeer mode, warnings about memory representation are not
-- meaningful, thus, suppress them.
Warn_On_Biased_Representation := False; -- -gnatw.b
Warn_On_Unrepped_Components := False; -- -gnatw.c
Warn_On_Record_Holes := False; -- -gnatw.h
Warn_On_Unchecked_Conversion := False; -- -gnatwz
Warn_On_Size_Alignment := False; -- -gnatw.z
Warn_On_Questionable_Layout := False; -- -gnatw.q
Warn_On_Overridden_Size := False; -- -gnatw.s
Warn_On_Reverse_Bit_Order := False; -- -gnatw.v
else
-- Suppress compiler warnings by default when generating SCIL for
-- CodePeer, except when combined with -gnateC where we do want to
-- emit GNAT warnings.
Warning_Mode := Suppress;
end if;
-- Disable all simple value propagation. This is an optimization
-- which is valuable for code optimization, and also for generation
-- of compiler warnings, but these are being turned off by default,
-- and CodePeer generates better messages (referencing original
-- variables) this way.
-- Do this only if -gnatws is set (the default with -gnatcC), so that
-- if warnings are enabled, we'll get better messages from GNAT.
if Warning_Mode = Suppress then
Debug_Flag_MM := True;
end if;
end if;
-- Enable some individual switches that are implied by relaxed RM
-- semantics mode.
if Relaxed_RM_Semantics then
Opt.Allow_Integer_Address := True;
Overriding_Renamings := True;
Treat_Categorization_Errors_As_Warnings := True;
end if;
-- Enable GNATprove_Mode when using -gnatd.F switch
if Debug_Flag_Dot_FF then
GNATprove_Mode := True;
end if;
-- GNATprove_Mode is also activated by default in the gnat2why
-- executable.
if GNATprove_Mode then
-- Turn off CodePeer mode (which can be set via e.g. -gnatC or
-- -gnateC), not compatible with GNATprove mode.
CodePeer_Mode := False;
Generate_SCIL := False;
-- Turn off C tree generation, not compatible with GNATprove mode. We
-- do not expect this to happen in normal use, since both modes are
-- enabled by special tools, but it is useful to turn off these flags
-- this way when we are doing GNATprove tests on existing test suites
-- that may have -gnateg set, to avoid the need for special casing.
Modify_Tree_For_C := False;
Generate_C_Code := False;
Unnest_Subprogram_Mode := False;
-- Turn off inlining, which would confuse formal verification output
-- and gain nothing.
Front_End_Inlining := False;
Inline_Active := False;
-- Issue warnings for failure to inline subprograms, as otherwise
-- expected in GNATprove mode for the local subprograms without
-- contracts.
Ineffective_Inline_Warnings := True;
-- Do not issue warnings for possible propagation of exception.
-- GNATprove already issues messages about possible exceptions.
No_Warn_On_Non_Local_Exception := True;
Warn_On_Non_Local_Exception := False;
-- Disable front-end optimizations, to keep the tree as close to the
-- source code as possible, and also to avoid inconsistencies between
-- trees when using different optimization switches.
Optimization_Level := 0;
-- Enable some restrictions systematically to simplify the generated
-- code (and ease analysis).
Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
-- Note: at this point we used to suppress various checks, but that
-- is not what we want. We need the semantic processing for these
-- checks (which will set flags like Do_Overflow_Check, showing the
-- points at which potential checks are required semantically). We
-- don't want the expansion associated with these checks, but that
-- happens anyway because this expansion is simply not done in the
-- SPARK version of the expander.
-- On the contrary, we need to enable explicitly all language checks,
-- as they may have been suppressed by the use of switch -gnatp.
Suppress_Options.Suppress := (others => False);
-- Detect overflow on unconstrained floating-point types, such as
-- the predefined types Float, Long_Float and Long_Long_Float from
-- package Standard. Not necessary if float overflows are checked
-- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
-- will be set in any case.
Check_Float_Overflow := not Machine_Overflows_On_Target;
-- Set STRICT mode for overflow checks if not set explicitly. This
-- prevents suppressing of overflow checks by default, in code down
-- below.
if Suppress_Options.Overflow_Mode_General = Not_Set then
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
end if;
-- Kill debug of generated code, since it messes up sloc values
Debug_Generated_Code := False;
-- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
-- as it is needed for computing effects of subprograms in the formal
-- verification backend.
Xref_Active := True;
-- Set operating mode to Check_Semantics, but a light front-end
-- expansion is still performed.
Operating_Mode := Check_Semantics;
-- Enable assertions, since they give valuable extra information for
-- formal verification.
Assertions_Enabled := True;
-- Disable validity checks, since it generates code raising
-- exceptions for invalid data, which confuses GNATprove. Invalid
-- data is directly detected by GNATprove's flow analysis.
Validity_Checks_On := False;
Check_Validity_Of_Parameters := False;
-- Turn off style check options since we are not interested in any
-- front-end warnings when we are getting SPARK output.
Reset_Style_Check_Options;
-- Suppress the generation of name tables for enumerations, which are
-- not needed for formal verification, and fall outside the SPARK
-- subset (use of pointers).
Global_Discard_Names := True;
-- Suppress the expansion of tagged types and dispatching calls,
-- which lead to the generation of non-SPARK code (use of pointers),
-- which is more complex to formally verify than the original source.
Tagged_Type_Expansion := False;
-- Detect that the runtime library support for floating-point numbers
-- may not be compatible with SPARK analysis of IEEE-754 floats.
if Denorm_On_Target = False then
SPARK_Library_Warning ("float subnormals");
elsif Machine_Rounds_On_Target = False then
SPARK_Library_Warning ("float rounding");
elsif Signed_Zeros_On_Target = False then
SPARK_Library_Warning ("signed zeros");
end if;
end if;
-- Set Configurable_Run_Time mode if system.ads flag set or if the
-- special debug flag -gnatdY is set.
if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
Configurable_Run_Time_Mode := True;
end if;
-- Set -gnatRm mode if debug flag A set
if Debug_Flag_AA then
Back_Annotate_Rep_Info := True;
List_Representation_Info := 1;
List_Representation_Info_Mechanisms := True;
end if;
-- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
if Debug_Flag_Dot_A then
Ttypes.Target_Strict_Alignment := True;
end if;
-- Increase size of allocated entities if debug flag -gnatd.N is set
if Debug_Flag_Dot_NN then
Atree.Num_Extension_Nodes := Atree.Num_Extension_Nodes + 1;
end if;
-- Disable static allocation of dispatch tables if -gnatd.t is enabled.
-- The front end's layout phase currently treats types that have
-- discriminant-dependent arrays as not being static even when a
-- discriminant constraint on the type is static, and this leads to
-- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
if Debug_Flag_Dot_T then
Building_Static_Dispatch_Tables := False;
end if;
-- Flip endian mode if -gnatd8 set
if Debug_Flag_8 then
Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
end if;
-- Set and check exception mechanism. This is only meaningful when
-- compiling, and in particular not meaningful for special modes used
-- for program analysis rather than compilation: CodePeer mode and
-- GNATprove mode.
if Operating_Mode = Generate_Code
and then not (CodePeer_Mode or GNATprove_Mode)
then
case Targparm.Frontend_Exceptions_On_Target is
when True =>
case Targparm.ZCX_By_Default_On_Target is
when True =>
Write_Line
("Run-time library configured incorrectly");
Write_Line
("(requesting support for Frontend ZCX exceptions)");
raise Unrecoverable_Error;
when False =>
Exception_Mechanism := Front_End_SJLJ;
end case;
when False =>
case Targparm.ZCX_By_Default_On_Target is
when True =>
Exception_Mechanism := Back_End_ZCX;
when False =>
Exception_Mechanism := Back_End_SJLJ;
end case;
end case;
end if;
-- Set proper status for overflow check mechanism
-- If already set (by -gnato or above in SPARK or CodePeer mode) then we
-- have nothing to do.
if Opt.Suppress_Options.Overflow_Mode_General /= Not_Set then
null;
-- Otherwise set overflow mode defaults
else
-- Overflow checks are on by default (Suppress set False) except in
-- GNAT_Mode, where we want them off by default (we are not ready to
-- enable overflow checks in the compiler yet, for one thing the case
-- of 64-bit checks needs System.Arith_64 which is not a compiler
-- unit and it is a pain to try to include it in the compiler.
Suppress_Options.Suppress (Overflow_Check) := GNAT_Mode;
-- Set appropriate default overflow handling mode. Note: at present
-- we set STRICT in all three of the following cases. They are
-- separated because in the future we may make different choices.
-- By default set STRICT mode if -gnatg in effect
if GNAT_Mode then
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
-- If we have backend divide and overflow checks, then by default
-- overflow checks are STRICT. Historically this code used to also
-- activate overflow checks, although no target currently has these
-- flags set, so this was dead code anyway.
elsif Targparm.Backend_Divide_Checks_On_Target
and
Targparm.Backend_Overflow_Checks_On_Target
then
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
-- Otherwise for now, default is STRICT mode. This may change in the
-- future, but for now this is the compatible behavior with previous
-- versions of GNAT.
else
Suppress_Options.Overflow_Mode_General := Strict;
Suppress_Options.Overflow_Mode_Assertions := Strict;
end if;
end if;
-- Set default for atomic synchronization. As this synchronization
-- between atomic accesses can be expensive, and not typically needed
-- on some targets, an optional target parameter can turn the option
-- off. Note Atomic Synchronization is implemented as check.
Suppress_Options.Suppress (Atomic_Synchronization) :=
not Atomic_Sync_Default_On_Target;
-- Set default for Alignment_Check, if we are on a machine with non-
-- strict alignment, then we suppress this check, since it is over-
-- zealous for such machines.
if not Ttypes.Target_Strict_Alignment then
Suppress_Options.Suppress (Alignment_Check) := True;
end if;
-- Set switch indicating if back end can handle limited types, and
-- guarantee that no incorrect copies are made (e.g. in the context
-- of an if or case expression).
-- Debug flag -gnatd.L decisively sets usage on
if Debug_Flag_Dot_LL then
Back_End_Handles_Limited_Types := True;
-- If no debug flag, usage off for SCIL cases
elsif Generate_SCIL then
Back_End_Handles_Limited_Types := False;
-- Otherwise normal gcc back end, for now still turn flag off by
-- default, since there are unresolved problems in the front end.
else
Back_End_Handles_Limited_Types := False;
end if;
-- If the inlining level has not been set by the user, compute it from
-- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
if Inline_Level = 0 then
if Optimization_Level < 3 then
Inline_Level := 1;
else
Inline_Level := 2;
end if;
end if;
-- Treat -gnatn as equivalent to -gnatN for non-GCC targets
if Inline_Active and not Front_End_Inlining then
-- We really should have a tag for this, what if we added a new
-- back end some day, it would not be true for this test, but it
-- would be non-GCC, so this is a bit troublesome ???
Front_End_Inlining := Generate_C_Code;
end if;
-- Set back-end inlining indication
Back_End_Inlining :=
-- No back-end inlining available on C generation
not Generate_C_Code
-- No back-end inlining in GNATprove mode, since it just confuses
-- the formal verification process.
and then not GNATprove_Mode
-- No back-end inlining if front-end inlining explicitly enabled.
-- Done to minimize the output differences to customers still using
-- this deprecated switch; in addition, this behavior reduces the
-- output differences in old tests.
and then not Front_End_Inlining
-- Back-end inlining is disabled if debug flag .z is set
and then not Debug_Flag_Dot_Z;
-- Output warning if -gnateE specified and cannot be supported
if Exception_Extra_Info
and then Restrict.No_Exception_Handlers_Set
then
Set_Standard_Error;
Write_Str
("warning: extra exception information (-gnateE) was specified");
Write_Eol;
Write_Str
("warning: this capability is not available in this configuration");
Write_Eol;
Set_Standard_Output;
end if;
-- Finally capture adjusted value of Suppress_Options as the initial
-- value for Scope_Suppress, which will be modified as we move from
-- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
Sem.Scope_Suppress := Opt.Suppress_Options;
end Adjust_Global_Switches;
--------------------
-- Check_Bad_Body --
--------------------
procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind) is
Fname : File_Name_Type;
procedure Bad_Body_Error (Msg : String);
-- Issue message for bad body found
--------------------
-- Bad_Body_Error --
--------------------
procedure Bad_Body_Error (Msg : String) is
begin
Error_Msg_N (Msg, Unit_Node);
Error_Msg_File_1 := Fname;
Error_Msg_N ("remove incorrect body in file{!", Unit_Node);
end Bad_Body_Error;
-- Local variables
Sname : Unit_Name_Type;
Src_Ind : Source_File_Index;
-- Start of processing for Check_Bad_Body
begin
-- Nothing to do if we are only checking syntax, because we don't know
-- enough to know if we require or forbid a body in this case.
if Operating_Mode = Check_Syntax then
return;
end if;
-- Check for body not allowed
if (Unit_Kind = N_Package_Declaration
and then not Body_Required (Unit_Node))
or else (Unit_Kind = N_Generic_Package_Declaration
and then not Body_Required (Unit_Node))
or else Unit_Kind = N_Package_Renaming_Declaration
or else Unit_Kind = N_Subprogram_Renaming_Declaration
or else Nkind (Original_Node (Unit (Unit_Node)))
in N_Generic_Instantiation
then
Sname := Unit_Name (Main_Unit);
-- If we do not already have a body name, then get the body name
if not Is_Body_Name (Sname) then
Sname := Get_Body_Name (Sname);
end if;
Fname := Get_File_Name (Sname, Subunit => False);
Src_Ind := Load_Source_File (Fname);
-- Case where body is present and it is not a subunit. Exclude the
-- subunit case, because it has nothing to do with the package we are
-- compiling. It is illegal for a child unit and a subunit with the
-- same expanded name (RM 10.2(9)) to appear together in a partition,
-- but there is nothing to stop a compilation environment from having
-- both, and the test here simply allows that. If there is an attempt
-- to include both in a partition, this is diagnosed at bind time. In
-- Ada 83 mode this is not a warning case.
-- Note that in general we do not give the message if the file in
-- question does not look like a body. This includes weird cases,
-- but in particular means that if the file is just a No_Body pragma,
-- then we won't give the message (that's the whole point of this
-- pragma, to be used this way and to cause the body file to be
-- ignored in this context).
if Src_Ind > No_Source_File
and then Source_File_Is_Body (Src_Ind)
then
Errout.Finalize (Last_Call => False);
Error_Msg_Unit_1 := Sname;
-- Ada 83 case of a package body being ignored. This is not an
-- error as far as the Ada 83 RM is concerned, but it is almost
-- certainly not what is wanted so output a warning. Give this
-- message only if there were no errors, since otherwise it may
-- be incorrect (we may have misinterpreted a junk spec as not
-- needing a body when it really does).
if Unit_Kind = N_Package_Declaration
and then Ada_Version = Ada_83
and then Operating_Mode = Generate_Code
and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
and then not Compilation_Errors
then
Error_Msg_N
("package $$ does not require a body??", Unit_Node);
Error_Msg_File_1 := Fname;
Error_Msg_N ("body in file{ will be ignored??", Unit_Node);
-- Ada 95 cases of a body file present when no body is
-- permitted. This we consider to be an error.
else
-- For generic instantiations, we never allow a body
if Nkind (Original_Node (Unit (Unit_Node))) in
N_Generic_Instantiation
then
Bad_Body_Error
("generic instantiation for $$ does not allow a body");
-- A library unit that is a renaming never allows a body
elsif Unit_Kind in N_Renaming_Declaration then
Bad_Body_Error
("renaming declaration for $$ does not allow a body!");
-- Remaining cases are packages and generic packages. Here
-- we only do the test if there are no previous errors,
-- because if there are errors, they may lead us to
-- incorrectly believe that a package does not allow a
-- body when in fact it does.
elsif not Compilation_Errors then
if Unit_Kind = N_Package_Declaration then
Bad_Body_Error
("package $$ does not allow a body!");
elsif Unit_Kind = N_Generic_Package_Declaration then
Bad_Body_Error
("generic package $$ does not allow a body!");
end if;
end if;
end if;
end if;
end if;
end Check_Bad_Body;
--------------------
-- Check_Rep_Info --
--------------------
procedure Check_Rep_Info is
begin
if List_Representation_Info /= 0
or else List_Representation_Info_Mechanisms
then
Set_Standard_Error;
Write_Eol;
Write_Str
("cannot generate representation information, no code generated");
Write_Eol;
Write_Eol;
Set_Standard_Output;
end if;
end Check_Rep_Info;
----------------------------------------
-- Post_Compilation_Validation_Checks --
----------------------------------------
procedure Post_Compilation_Validation_Checks is
begin
-- Validate alignment check warnings. In some cases we generate warnings
-- about possible alignment errors because we don't know the alignment
-- that will be chosen by the back end. This routine is in charge of
-- getting rid of those warnings if we can tell they are not needed.
Checks.Validate_Alignment_Check_Warnings;
-- Validate compile time warnings and errors (using the values for size
-- and alignment annotated by the backend where possible). We need to
-- unlock temporarily these tables to reanalyze their expression.
Atree.Unlock;
Nlists.Unlock;
Elists.Unlock;
Sem.Unlock;
Sem_Prag.Validate_Compile_Time_Warning_Errors;
Sem.Lock;
Elists.Lock;
Nlists.Lock;
Atree.Lock;
-- Validate unchecked conversions (using the values for size and
-- alignment annotated by the backend where possible).
Sem_Ch13.Validate_Unchecked_Conversions;
-- Validate address clauses (again using alignment values annotated
-- by the backend where possible).
Sem_Ch13.Validate_Address_Clauses;
-- Validate independence pragmas (again using values annotated by the
-- back end for component layout where possible) but only for non-GCC
-- back ends, as this is done a priori for GCC back ends.
-- ??? We use to test for AAMP_On_Target which is now gone, consider
--
-- if AAMP_On_Target then
-- Sem_Ch13.Validate_Independence;
-- end if;
end Post_Compilation_Validation_Checks;
-----------------------------------
-- Read_JSON_Files_For_Repinfo --
-----------------------------------
procedure Read_JSON_Files_For_Repinfo is
begin
-- This is the same loop construct as in Repinfo.List_Rep_Info
for U in Main_Unit .. Last_Unit loop
if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
declare
Nam : constant String :=
Get_Name_String
(File_Name (Source_Index (U))) & ".json";
Namid : constant File_Name_Type := Name_Enter (Nam);
Index : constant Source_File_Index := Load_Config_File (Namid);
begin
if Index = No_Source_File then
Write_Str ("cannot locate ");
Write_Line (Nam);
raise Unrecoverable_Error;
end if;
Repinfo.Input.Read_JSON_Stream (Source_Text (Index).all, Nam);
exception
when Repinfo.Input.Invalid_JSON_Stream =>
raise Unrecoverable_Error;
end;
end if;
end loop;
end Read_JSON_Files_For_Repinfo;
-- Local variables
Back_End_Mode : Back_End.Back_End_Mode_Type;
Ecode : Exit_Code_Type;
Main_Unit_Kind : Node_Kind;
-- Kind of main compilation unit node
Main_Unit_Node : Node_Id;
-- Compilation unit node for main unit
-- Start of processing for Gnat1drv
begin
-- This inner block is set up to catch assertion errors and constraint
-- errors. Since the code for handling these errors can cause another
-- exception to be raised (namely Unrecoverable_Error), we need two
-- nested blocks, so that the outer one handles unrecoverable error.
begin
-- Initialize all packages. For the most part, these initialization
-- calls can be made in any order. Exceptions are as follows:
-- Lib.Initialize needs to be called before Scan_Compiler_Arguments,
-- because it initializes a table filled by Scan_Compiler_Arguments.
-- Atree.Initialize needs to be called after Scan_Compiler_Arguments,
-- because the value specified by the -gnaten switch is used by
-- Atree.Initialize.
Osint.Initialize;
Fmap.Reset_Tables;
Lib.Initialize;
Lib.Xref.Initialize;
Scan_Compiler_Arguments;
Osint.Add_Default_Search_Dirs;
Atree.Initialize;
Nlists.Initialize;
Sinput.Initialize;
Sem.Initialize;
Exp_CG.Initialize;
Csets.Initialize;
Uintp.Initialize;
Urealp.Initialize;
Errout.Initialize;
SCOs.Initialize;
Snames.Initialize;
Stringt.Initialize;
Ghost.Initialize;
Inline.Initialize;
Par_SCO.Initialize;
Sem_Ch8.Initialize;
Sem_Ch12.Initialize;
Sem_Ch13.Initialize;
Sem_Elim.Initialize;
Sem_Eval.Initialize;
Sem_Type.Init_Interp_Tables;
-- Capture compilation date and time
Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
-- Get the target parameters only when -gnats is not used, to avoid
-- failing when there is no default runtime.
if Operating_Mode /= Check_Syntax then
-- Acquire target parameters from system.ads (package System source)
Targparm_Acquire : declare
S : Source_File_Index;
N : File_Name_Type;
begin
Name_Buffer (1 .. 10) := "system.ads";
Name_Len := 10;
N := Name_Find;
S := Load_Source_File (N);
-- Failed to read system.ads, fatal error
if S = No_Source_File then
Write_Line
("fatal error, run-time library not installed correctly");
Write_Line ("cannot locate file system.ads");
raise Unrecoverable_Error;
elsif S = No_Access_To_Source_File then
Write_Line
("fatal error, run-time library not installed correctly");
Write_Line ("no read access for file system.ads");
raise Unrecoverable_Error;
-- Read system.ads successfully, remember its source index
else
System_Source_File_Index := S;
end if;
-- Call to get target parameters. Note that the actual interface
-- routines are in Tbuild. They can't be in this procedure because
-- of accessibility issues.
Targparm.Get_Target_Parameters
(System_Text => Source_Text (S),
Source_First => Source_First (S),
Source_Last => Source_Last (S),
Make_Id => Tbuild.Make_Id'Access,
Make_SC => Tbuild.Make_SC'Access,
Set_NOD => Tbuild.Set_NOD'Access,
Set_NSA => Tbuild.Set_NSA'Access,
Set_NUA => Tbuild.Set_NUA'Access,
Set_NUP => Tbuild.Set_NUP'Access);
-- Acquire configuration pragma information from Targparm
Restrict.Restrictions := Targparm.Restrictions_On_Target;
end Targparm_Acquire;
end if;
-- Perform various adjustments and settings of global switches
Adjust_Global_Switches;
-- Output copyright notice if full list mode unless we have a list
-- file, in which case we defer this so that it is output in the file.
if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
-- Debug flag gnatd7 suppresses this copyright notice
and then not Debug_Flag_7
then
Write_Eol;
Write_Str ("GNAT ");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 1992-" & Current_Year
& ", Free Software Foundation, Inc.");
Write_Eol;
end if;
-- Check we do not have more than one source file, this happens only in
-- the case where the driver is called directly, it cannot happen when
-- gnat1 is invoked from gcc in the normal case.
if Osint.Number_Of_Files /= 1 then
-- In GNATprove mode, gcc is not called, so we may end up with
-- switches wrongly interpreted as source file names when they are
-- written by mistake without a starting hyphen. Issue a specific
-- error message but do not print the internal 'usage' message.
if GNATprove_Mode then
Write_Str
("one of the following is not a valid switch or source file "
& "name: ");
Osint.Dump_Command_Line_Source_File_Names;
else
Usage;
Write_Eol;
end if;
Osint.Fail ("you must provide one source file");
elsif Usage_Requested then
Usage;
end if;
-- Generate target dependent output file if requested
if Target_Dependent_Info_Write_Name /= null then
Set_Targ.Write_Target_Dependent_Values;
end if;
-- Call the front end
Original_Operating_Mode := Operating_Mode;
Frontend;
-- Exit with errors if the main source could not be parsed
if Sinput.Main_Source_File <= No_Source_File then
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Exit_Program (E_Errors);
end if;
Main_Unit_Node := Cunit (Main_Unit);
Main_Unit_Kind := Nkind (Unit (Main_Unit_Node));
Check_Bad_Body (Main_Unit_Node, Main_Unit_Kind);
-- In CodePeer mode we always delete old SCIL files before regenerating
-- new ones, in case of e.g. errors, and also to remove obsolete scilx
-- files generated by CodePeer itself.
if CodePeer_Mode then
Comperr.Delete_SCIL_Files;
end if;
-- Ditto for old C files before regenerating new ones
if Generate_C_Code then
Delete_C_File;
Delete_H_File;
end if;
-- Exit if compilation errors detected
Errout.Finalize (Last_Call => False);
if Compilation_Errors then
Treepr.Tree_Dump;
Post_Compilation_Validation_Checks;
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Namet.Finalize;
-- Generate ALI file if specially requested
if Opt.Force_ALI_File then
Write_ALI (Object => False);
end if;
Exit_Program (E_Errors);
end if;
-- Set Generate_Code on main unit and its spec. We do this even if are
-- not generating code, since Lib-Writ uses this to determine which
-- units get written in the ali file.
Set_Generate_Code (Main_Unit);
-- If we have a corresponding spec, and it comes from source or it is
-- not a generated spec for a child subprogram body, then we need object
-- code for the spec unit as well.
if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
and then not Acts_As_Spec (Main_Unit_Node)
then
if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body
and then not Comes_From_Source (Library_Unit (Main_Unit_Node))
then
null;
else
Set_Generate_Code
(Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
end if;
end if;
-- Case of no code required to be generated, exit indicating no error
if Original_Operating_Mode = Check_Syntax then
Treepr.Tree_Dump;
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Namet.Finalize;
Check_Rep_Info;
-- Use a goto instead of calling Exit_Program so that finalization
-- occurs normally.
goto End_Of_Program;
elsif Original_Operating_Mode = Check_Semantics then
Back_End_Mode := Declarations_Only;
-- All remaining cases are cases in which the user requested that code
-- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
-- can in fact satisfy this request.
-- Cannot generate code if someone has turned off code generation for
-- any reason at all. We will try to figure out a reason below.
elsif Operating_Mode /= Generate_Code then
Back_End_Mode := Skip;
-- We can generate code for a subprogram body unless there were missing
-- subunits. Note that we always generate code for all generic units (a
-- change from some previous versions of GNAT).
elsif Main_Unit_Kind = N_Subprogram_Body
and then not Subunits_Missing
then
Back_End_Mode := Generate_Object;
-- We can generate code for a package body unless there are subunits
-- missing (note that we always generate code for generic units, which
-- is a change from some earlier versions of GNAT).
elsif Main_Unit_Kind = N_Package_Body and then not Subunits_Missing then
Back_End_Mode := Generate_Object;
-- We can generate code for a package declaration or a subprogram
-- declaration only if it does not required a body.
elsif Main_Unit_Kind in N_Package_Declaration | N_Subprogram_Declaration
and then
(not Body_Required (Main_Unit_Node)
or else Distribution_Stub_Mode = Generate_Caller_Stub_Body)
then
Back_End_Mode := Generate_Object;
-- We can generate code for a generic package declaration of a generic
-- subprogram declaration only if does not require a body.
elsif Main_Unit_Kind in
N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration
and then not Body_Required (Main_Unit_Node)
then
Back_End_Mode := Generate_Object;
-- Compilation units that are renamings do not require bodies, so we can
-- generate code for them.
elsif Main_Unit_Kind in N_Package_Renaming_Declaration |
N_Subprogram_Renaming_Declaration
then
Back_End_Mode := Generate_Object;
-- Compilation units that are generic renamings do not require bodies
-- so we can generate code for them.
elsif Main_Unit_Kind in N_Generic_Renaming_Declaration then
Back_End_Mode := Generate_Object;
-- It is not an error to analyze in CodePeer mode a spec which requires
-- a body, in order to generate SCIL for this spec.
elsif CodePeer_Mode then
Back_End_Mode := Generate_Object;
-- Differentiate use of -gnatceg to generate a C header from an Ada spec
-- to the CCG case (standard.h found) where C code generation should
-- only be performed on full units.
elsif Generate_C_Code then
Name_Len := 10;
Name_Buffer (1 .. Name_Len) := "standard.h";
if Find_File (Name_Find, Osint.Source, Full_Name => True) = No_File
then
Back_End_Mode := Generate_Object;
else
Back_End_Mode := Skip;
end if;
-- It is not an error to analyze in GNATprove mode a spec which requires
-- a body, when the body is not available. During frame condition
-- generation, the corresponding ALI file is generated. During
-- analysis, the spec is analyzed.
elsif GNATprove_Mode then
Back_End_Mode := Declarations_Only;
-- In all other cases (specs which have bodies, generics, and bodies
-- where subunits are missing), we cannot generate code and we generate
-- a warning message. Note that generic instantiations are gone at this
-- stage since they have been replaced by their instances.
else
Back_End_Mode := Skip;
end if;
-- At this stage Back_End_Mode is set to indicate if the backend should
-- be called to generate code. If it is Skip, then code generation has
-- been turned off, even though code was requested by the original
-- command. This is not an error from the user point of view, but it is
-- an error from the point of view of the gcc driver, so we must exit
-- with an error status.
-- We generate an informative message (from the gcc point of view, it
-- is an error message, but from the users point of view this is not an
-- error, just a consequence of compiling something that cannot
-- generate code).
if Back_End_Mode = Skip then
-- An ignored Ghost unit is rewritten into a null statement because
-- it must not produce an ALI or object file. Do not emit any errors
-- related to code generation because the unit does not exist.
if Is_Ignored_Ghost_Unit (Main_Unit_Node) then
-- Exit the gnat driver with success, otherwise external builders
-- such as gnatmake and gprbuild will treat the compilation of an
-- ignored Ghost unit as a failure. Note that this will produce
-- an empty object file for the unit.
Ecode := E_Success;
-- Otherwise the unit is missing a crucial piece that prevents code
-- generation.
else
Ecode := E_No_Code;
Set_Standard_Error;
Write_Str ("cannot generate code for file ");
Write_Name (Unit_File_Name (Main_Unit));
if Subunits_Missing then
Write_Str (" (missing subunits)");
Write_Eol;
-- Force generation of ALI file, for backward compatibility
Opt.Force_ALI_File := True;
elsif Main_Unit_Kind = N_Subunit then
Write_Str (" (subunit)");
Write_Eol;
-- Do not generate an ALI file in this case, because it would
-- become obsolete when the parent is compiled, and thus
-- confuse tools such as gnatfind.
elsif Main_Unit_Kind = N_Subprogram_Declaration then
Write_Str (" (subprogram spec)");
Write_Eol;
-- Generic package body in GNAT implementation mode
elsif Main_Unit_Kind = N_Package_Body and then GNAT_Mode then
Write_Str (" (predefined generic)");
Write_Eol;
-- Force generation of ALI file, for backward compatibility
Opt.Force_ALI_File := True;
-- Only other case is a package spec
else
Write_Str (" (package spec)");
Write_Eol;
end if;
end if;
Set_Standard_Output;
Post_Compilation_Validation_Checks;
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Treepr.Tree_Dump;
-- Generate ALI file if specially requested, or for missing subunits,
-- subunits or predefined generic. For ignored ghost code, the object
-- file IS generated, so Object should be True, and since the object
-- file is generated, we need to generate the ALI file. We never want
-- an object file without an ALI file.
if Is_Ignored_Ghost_Unit (Main_Unit_Node)
or else Opt.Force_ALI_File
then
Write_ALI (Object => Is_Ignored_Ghost_Unit (Main_Unit_Node));
end if;
Namet.Finalize;
Check_Rep_Info;
-- Exit the driver with an appropriate status indicator. This will
-- generate an empty object file for ignored Ghost units, otherwise
-- no object file will be generated.
Exit_Program (Ecode);
end if;
-- In -gnatc mode we only do annotation if -gnatR is also set, or if
-- -gnatwz is enabled (default setting) and there is an unchecked
-- conversion that involves a type whose size is not statically known,
-- as indicated by Back_Annotate_Rep_Info being set to True.
-- We don't call for annotations on a subunit, because to process those
-- the back end requires that the parent(s) be properly compiled.
-- Annotation is suppressed for targets where front-end layout is
-- enabled, because the front end determines representations.
-- A special back end is always called in CodePeer and GNATprove modes,
-- unless this is a subunit.
if Back_End_Mode = Declarations_Only
and then
(not (Back_Annotate_Rep_Info or Generate_SCIL or GNATprove_Mode)
or else Main_Unit_Kind = N_Subunit)
then
Post_Compilation_Validation_Checks;
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Write_ALI (Object => False);
Tree_Dump;
Namet.Finalize;
if not (Generate_SCIL or GNATprove_Mode) then
Check_Rep_Info;
end if;
return;
end if;
-- Ensure that we properly register a dependency on system.ads, since
-- even if we do not semantically depend on this, Targparm has read
-- system parameters from the system.ads file.
Lib.Writ.Ensure_System_Dependency;
-- Add dependencies, if any, on preprocessing data file and on
-- preprocessing definition file(s).
Prepcomp.Add_Dependencies;
if GNATprove_Mode then
-- In GNATprove mode we're writing the ALI much earlier than usual
-- as flow analysis needs the file present in order to append its
-- own globals to it.
-- Note: In GNATprove mode, an "object" file is always generated as
-- the result of calling gnat1 or gnat2why, although this is not the
-- same as the object file produced for compilation.
Write_ALI (Object => True);
end if;
-- Some back ends (for instance Gigi) are known to rely on SCOs for code
-- generation. Make sure they are available.
if Generate_SCO then
Par_SCO.SCO_Record_Filtered;
end if;
-- If -gnatd_j is specified, exercise the JSON parser of Repinfo
if Debug_Flag_Underscore_J then
Read_JSON_Files_For_Repinfo;
end if;
-- Back end needs to explicitly unlock tables it needs to touch
Atree.Lock;
Elists.Lock;
Fname.UF.Lock;
Ghost.Lock;
Inline.Lock;
Lib.Lock;
Namet.Lock;
Nlists.Lock;
Sem.Lock;
Sinput.Lock;
Stringt.Lock;
-- Here we call the back end to generate the output code
Generating_Code := True;
Back_End.Call_Back_End (Back_End_Mode);
-- Once the backend is complete, we unlock the names table. This call
-- allows a few extra entries, needed for example for the file name
-- for the library file output.
Namet.Unlock;
-- Generate the call-graph output of dispatching calls
Exp_CG.Generate_CG_Output;
-- Perform post compilation validation checks
Post_Compilation_Validation_Checks;
-- Now we complete output of errors, rep info and the tree info. These
-- are delayed till now, since it is perfectly possible for gigi to
-- generate errors, modify the tree (in particular by setting flags
-- indicating that elaboration is required, and also to back annotate
-- representation information for List_Rep_Info).
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Repinfo.List_Rep_Info (Ttypes.Bytes_Big_Endian);
Inline.List_Inlining_Info;
-- Only write the library if the backend did not generate any error
-- messages. Otherwise signal errors to the driver program so that
-- there will be no attempt to generate an object file.
if Compilation_Errors then
Treepr.Tree_Dump;
Exit_Program (E_Errors);
end if;
if not GNATprove_Mode then
Write_ALI (Object => (Back_End_Mode = Generate_Object));
end if;
if not Compilation_Errors then
-- In case of ada backends, we need to make sure that the generated
-- object file has a timestamp greater than the ALI file. We do this
-- to make gnatmake happy when checking the ALI and obj timestamps,
-- where it expects the object file being written after the ali file.
-- Gnatmake's assumption is true for gcc platforms where the gcc
-- wrapper needs to call the assembler after calling gnat1, but is
-- not true for ada backends, where the object files are created
-- directly by gnat1 (so are created before the ali file).
Back_End.Gen_Or_Update_Object_File;
end if;
-- Generate tree after writing the ALI file, since Write_ALI may in
-- fact result in further tree decoration from the original tree file.
-- Note that we dump the tree just before generating it, so that the
-- dump will exactly reflect what is written out.
Treepr.Tree_Dump;
-- Finalize name table and we are all done
Namet.Finalize;
exception
-- Handle fatal internal compiler errors
when Rtsfind.RE_Not_Available =>
Comperr.Compiler_Abort ("RE_Not_Available");
when System.Assertions.Assert_Failure =>
Comperr.Compiler_Abort ("Assert_Failure");
when Constraint_Error =>
Comperr.Compiler_Abort ("Constraint_Error");
when Program_Error =>
Comperr.Compiler_Abort ("Program_Error");
-- Assume this is a bug. If it is real, the message will in any case
-- say Storage_Error, giving a strong hint.
when Storage_Error =>
Comperr.Compiler_Abort ("Storage_Error");
when Unrecoverable_Error =>
raise;
when others =>
Comperr.Compiler_Abort ("exception");
end;
<<End_Of_Program>>
if Debug_Flag_Dot_AA then
Atree.Print_Statistics;
end if;
-- The outer exception handler handles an unrecoverable error
exception
when Unrecoverable_Error =>
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
Set_Standard_Error;
Write_Str ("compilation abandoned");
Write_Eol;
Set_Standard_Output;
Source_Dump;
Tree_Dump;
Exit_Program (E_Errors);
end Gnat1drv;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.