Commit e379beb5 by Arnaud Charlet

[multiple changes]

2016-04-21  Javier Miranda  <miranda@adacore.com>

	* frontend.adb: Remove call to initialize Exp_Ch6.
	* exp_ch6.ads, exp_ch6.adb (Initialize): removed.
	(Unest_Entry/Unest_Bodies): Removed.
	(Unnest_Subprograms): Code cleanup.

2016-04-21  Arnaud Charlet  <charlet@adacore.com>

	* set_targ.adb (Read_Target_Dependent_Values):
	close target description file once its contents is read.
	* s-os_lib.adb (Non_Blocking_Spawn, version with Stdout_File
	and Stderr_File): Close local file descriptors before spawning
	child process.
	* exp_util.adb (Containing_Package_With_Ext_Axioms): Limit scope of
	local variables to make the code easier to understand and avoid
	duplicated calls to Parent and Generic_Parent.

From-SVN: r235302
parent 2e9bd657
2016-04-21 Javier Miranda <miranda@adacore.com>
* frontend.adb: Remove call to initialize Exp_Ch6.
* exp_ch6.ads, exp_ch6.adb (Initialize): removed.
(Unest_Entry/Unest_Bodies): Removed.
(Unnest_Subprograms): Code cleanup.
2016-04-21 Arnaud Charlet <charlet@adacore.com>
* set_targ.adb (Read_Target_Dependent_Values):
close target description file once its contents is read.
* s-os_lib.adb (Non_Blocking_Spawn, version with Stdout_File
and Stderr_File): Close local file descriptors before spawning
child process.
* exp_util.adb (Containing_Package_With_Ext_Axioms): Limit scope of
local variables to make the code easier to understand and avoid
duplicated calls to Parent and Generic_Parent.
2016-04-20 Bob Duff <duff@adacore.com> 2016-04-20 Bob Duff <duff@adacore.com>
* s-os_lib.ads: Minor comment fix. * s-os_lib.ads: Minor comment fix.
......
...@@ -72,7 +72,6 @@ with Sem_Util; use Sem_Util; ...@@ -72,7 +72,6 @@ with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo; with Sinfo; use Sinfo;
with Snames; use Snames; with Snames; use Snames;
with Stand; use Stand; with Stand; use Stand;
with Table;
with Targparm; use Targparm; with Targparm; use Targparm;
with Tbuild; use Tbuild; with Tbuild; use Tbuild;
with Uintp; use Uintp; with Uintp; use Uintp;
...@@ -80,33 +79,6 @@ with Validsw; use Validsw; ...@@ -80,33 +79,6 @@ with Validsw; use Validsw;
package body Exp_Ch6 is package body Exp_Ch6 is
-------------------------------------
-- Table for Unnesting Subprograms --
-------------------------------------
-- When we expand a subprogram body, if it has nested subprograms and if
-- we are in Unnest_Subprogram_Mode, then we record the subprogram entity
-- and the body in this table, to later be passed to Unnest_Subprogram.
-- We need this delaying mechanism, because we have to wait until all
-- instantiated bodies have been inserted before doing the unnesting.
type Unest_Entry is record
Ent : Entity_Id;
-- Entity for subprogram to be unnested
Bod : Node_Id;
-- Subprogram body to be unnested
end record;
package Unest_Bodies is new Table.Table (
Table_Component_Type => Unest_Entry,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => 100,
Table_Increment => 200,
Table_Name => "Unest_Bodies");
----------------------- -----------------------
-- Local Subprograms -- -- Local Subprograms --
----------------------- -----------------------
...@@ -6803,15 +6775,6 @@ package body Exp_Ch6 is ...@@ -6803,15 +6775,6 @@ package body Exp_Ch6 is
return False; return False;
end Has_Unconstrained_Access_Discriminants; end Has_Unconstrained_Access_Discriminants;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Unest_Bodies.Init;
end Initialize;
-------------------------------- --------------------------------
-- Is_Build_In_Place_Function -- -- Is_Build_In_Place_Function --
-------------------------------- --------------------------------
...@@ -8477,62 +8440,44 @@ package body Exp_Ch6 is ...@@ -8477,62 +8440,44 @@ package body Exp_Ch6 is
procedure Unnest_Subprograms (N : Node_Id) is procedure Unnest_Subprograms (N : Node_Id) is
procedure Search_Unnesting_Subprograms (N : Node_Id); function Search_Subprograms (N : Node_Id) return Traverse_Result;
-- Search for outer level procedures with nested subprograms and append -- Tree visitor that search for outer level procedures with nested
-- them to the Unnest table. -- subprograms and invokes Unnest_Subprogram()
---------------------------------- ------------------------
-- Search_Unnesting_Subprograms -- -- Search_Subprograms --
---------------------------------- ------------------------
procedure Search_Unnesting_Subprograms (N : Node_Id) is
function Search_Subprograms (N : Node_Id) return Traverse_Result;
-- Tree visitor that search for outer level procedures with nested
-- subprograms and adds them to the Unnest table.
------------------------
-- Search_Subprograms --
------------------------
function Search_Subprograms (N : Node_Id) return Traverse_Result is
begin
if Nkind_In (N, N_Subprogram_Body,
N_Subprogram_Body_Stub)
then
declare
Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
begin
-- We are only interested in subprograms (not generic
-- subprograms), that have nested subprograms.
if Is_Subprogram (Spec_Id) function Search_Subprograms (N : Node_Id) return Traverse_Result is
and then Has_Nested_Subprogram (Spec_Id) begin
and then Is_Library_Level_Entity (Spec_Id) if Nkind_In (N, N_Subprogram_Body,
then N_Subprogram_Body_Stub)
Unest_Bodies.Append ((Spec_Id, N)); then
end if; declare
end; Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
end if;
return OK; begin
end Search_Subprograms; -- We are only interested in subprograms (not generic
-- subprograms), that have nested subprograms.
--------------- if Is_Subprogram (Spec_Id)
-- Do_Search -- and then Has_Nested_Subprogram (Spec_Id)
--------------- and then Is_Library_Level_Entity (Spec_Id)
then
Unnest_Subprogram (Spec_Id, N);
end if;
end;
end if;
procedure Do_Search is new Traverse_Proc (Search_Subprograms); return OK;
-- Subtree visitor instantiation end Search_Subprograms;
-- Start of processing for Search_Unnesting_Subprograms ---------------
-- Do_Search --
---------------
begin procedure Do_Search is new Traverse_Proc (Search_Subprograms);
if Opt.Unnest_Subprogram_Mode then -- Subtree visitor instantiation
Do_Search (N);
end if;
end Search_Unnesting_Subprograms;
-- Start of processing for Unnest_Subprograms -- Start of processing for Unnest_Subprograms
...@@ -8541,15 +8486,7 @@ package body Exp_Ch6 is ...@@ -8541,15 +8486,7 @@ package body Exp_Ch6 is
return; return;
end if; end if;
Search_Unnesting_Subprograms (N); Do_Search (N);
for J in Unest_Bodies.First .. Unest_Bodies.Last loop
declare
UBJ : Unest_Entry renames Unest_Bodies.Table (J);
begin
Unnest_Subprogram (UBJ.Ent, UBJ.Bod);
end;
end loop;
end Unnest_Subprograms; end Unnest_Subprograms;
end Exp_Ch6; end Exp_Ch6;
...@@ -117,9 +117,6 @@ package Exp_Ch6 is ...@@ -117,9 +117,6 @@ package Exp_Ch6 is
-- The returned node is the root of the procedure body which will replace -- The returned node is the root of the procedure body which will replace
-- the original function body, which is not needed for the C program. -- the original function body, which is not needed for the C program.
procedure Initialize;
-- Initialize internal tables
function Is_Build_In_Place_Function (E : Entity_Id) return Boolean; function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
-- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
-- function, or access-to-function type whose result must be built in -- function, or access-to-function type whose result must be built in
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1728,11 +1728,7 @@ package body Exp_Util is ...@@ -1728,11 +1728,7 @@ package body Exp_Util is
---------------------------------------- ----------------------------------------
function Containing_Package_With_Ext_Axioms function Containing_Package_With_Ext_Axioms
(E : Entity_Id) return Entity_Id (E : Entity_Id) return Entity_Id is
is
Decl : Node_Id;
First_Ax_Parent_Scope : Entity_Id;
begin begin
-- E is the package or generic package which is externally axiomatized -- E is the package or generic package which is externally axiomatized
...@@ -1745,29 +1741,35 @@ package body Exp_Util is ...@@ -1745,29 +1741,35 @@ package body Exp_Util is
-- If E's scope is axiomatized, E is axiomatized -- If E's scope is axiomatized, E is axiomatized
if Present (Scope (E)) then if Present (Scope (E)) then
First_Ax_Parent_Scope := declare
Containing_Package_With_Ext_Axioms (Scope (E)); First_Ax_Parent_Scope : constant Entity_Id :=
Containing_Package_With_Ext_Axioms (Scope (E));
if Present (First_Ax_Parent_Scope) then begin
return First_Ax_Parent_Scope; if Present (First_Ax_Parent_Scope) then
end if; return First_Ax_Parent_Scope;
end if;
end;
end if; end if;
-- Otherwise, if E is a package instance, it is axiomatized if the -- Otherwise, if E is a package instance, it is axiomatized if the
-- corresponding generic package is axiomatized. -- corresponding generic package is axiomatized.
if Ekind (E) = E_Package then if Ekind (E) = E_Package then
if Nkind (Parent (E)) = N_Defining_Program_Unit_Name then declare
Decl := Parent (Parent (E)); Par : constant Node_Id := Parent (E);
else Decl : Node_Id;
Decl := Parent (E); begin
end if; if Nkind (Par) = N_Defining_Program_Unit_Name then
Decl := Parent (Par);
else
Decl := Par;
end if;
if Present (Generic_Parent (Decl)) then if Present (Generic_Parent (Decl)) then
return return
Containing_Package_With_Ext_Axioms (Generic_Parent (Decl)); Containing_Package_With_Ext_Axioms (Generic_Parent (Decl));
end if; end if;
end;
end if; end if;
return Empty; return Empty;
......
...@@ -90,7 +90,6 @@ begin ...@@ -90,7 +90,6 @@ begin
Checks.Initialize; Checks.Initialize;
Sem_Warn.Initialize; Sem_Warn.Initialize;
Prep.Initialize; Prep.Initialize;
Exp_Ch6.Initialize;
if Generate_SCIL then if Generate_SCIL then
SCIL_LL.Initialize; SCIL_LL.Initialize;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1995-2015, AdaCore -- -- Copyright (C) 1995-2016, AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1848,6 +1848,8 @@ package body System.OS_Lib is ...@@ -1848,6 +1848,8 @@ package body System.OS_Lib is
Saved_Error : File_Descriptor; Saved_Error : File_Descriptor;
Saved_Output : File_Descriptor; Saved_Output : File_Descriptor;
Dummy_Status : Boolean;
begin begin
-- Do not attempt to spawn if the output files could not be created -- Do not attempt to spawn if the output files could not be created
...@@ -1863,9 +1865,8 @@ package body System.OS_Lib is ...@@ -1863,9 +1865,8 @@ package body System.OS_Lib is
Saved_Error := Dup (Standerr); Saved_Error := Dup (Standerr);
Dup2 (Stderr_FD, Standerr); Dup2 (Stderr_FD, Standerr);
-- Spawn the program Set_Close_On_Exec (Saved_Output, True, Dummy_Status);
Set_Close_On_Exec (Saved_Error, True, Dummy_Status);
Result := Non_Blocking_Spawn (Program_Name, Args);
-- Close the files just created for the output, as the file descriptors -- Close the files just created for the output, as the file descriptors
-- cannot be used anywhere, being local values. It is safe to do that, -- cannot be used anywhere, being local values. It is safe to do that,
...@@ -1875,6 +1876,10 @@ package body System.OS_Lib is ...@@ -1875,6 +1876,10 @@ package body System.OS_Lib is
Close (Stdout_FD); Close (Stdout_FD);
Close (Stderr_FD); Close (Stderr_FD);
-- Spawn the program
Result := Non_Blocking_Spawn (Program_Name, Args);
-- Restore the standard output and error -- Restore the standard output and error
Dup2 (Saved_Output, Standout); Dup2 (Saved_Output, Standout);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2013-2015, Free Software Foundation, Inc. -- -- Copyright (C) 2013-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -698,6 +698,8 @@ package body Set_Targ is ...@@ -698,6 +698,8 @@ package body Set_Targ is
Buflen := Read (File_Desc, Buffer'Address, Buffer'Length); Buflen := Read (File_Desc, Buffer'Address, Buffer'Length);
Close (File_Desc);
if Buflen = Buffer'Length then if Buflen = Buffer'Length then
Fail ("file is too long: " & File_Name); Fail ("file is too long: " & File_Name);
end if; end if;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment