------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- --
|
-- --
|
-- GNAT COMPILER COMPONENTS --
|
-- GNAT COMPILER COMPONENTS --
|
-- --
|
-- --
|
-- L I B --
|
-- L I B --
|
-- --
|
-- --
|
-- B o d y --
|
-- B o d y --
|
-- --
|
-- --
|
-- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
|
-- Copyright (C) 1992-2009, 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- --
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
-- 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- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
-- --
|
-- --
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
-- version 3.1, as published by the Free Software Foundation. --
|
-- version 3.1, as published by the Free Software Foundation. --
|
-- --
|
-- --
|
-- You should have received a copy of the GNU General Public License and --
|
-- 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; --
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
-- <http://www.gnu.org/licenses/>. --
|
-- <http://www.gnu.org/licenses/>. --
|
-- --
|
-- --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- --
|
-- --
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
|
|
pragma Style_Checks (All_Checks);
|
pragma Style_Checks (All_Checks);
|
-- Subprogram ordering not enforced in this unit
|
-- Subprogram ordering not enforced in this unit
|
-- (because of some logical groupings).
|
-- (because of some logical groupings).
|
|
|
with Atree; use Atree;
|
with Atree; use Atree;
|
with Einfo; use Einfo;
|
with Einfo; use Einfo;
|
with Fname; use Fname;
|
with Fname; use Fname;
|
with Output; use Output;
|
with Output; use Output;
|
with Sinfo; use Sinfo;
|
with Sinfo; use Sinfo;
|
with Sinput; use Sinput;
|
with Sinput; use Sinput;
|
with Stand; use Stand;
|
with Stand; use Stand;
|
with Stringt; use Stringt;
|
with Stringt; use Stringt;
|
with Tree_IO; use Tree_IO;
|
with Tree_IO; use Tree_IO;
|
with Uname; use Uname;
|
with Uname; use Uname;
|
|
|
package body Lib is
|
package body Lib is
|
|
|
Switch_Storing_Enabled : Boolean := True;
|
Switch_Storing_Enabled : Boolean := True;
|
-- Controlled by Enable_Switch_Storing/Disable_Switch_Storing
|
-- Controlled by Enable_Switch_Storing/Disable_Switch_Storing
|
|
|
-----------------------
|
-----------------------
|
-- Local Subprograms --
|
-- Local Subprograms --
|
-----------------------
|
-----------------------
|
|
|
type SEU_Result is (
|
type SEU_Result is (
|
Yes_Before, -- S1 is in same extended unit as S2 and appears before it
|
Yes_Before, -- S1 is in same extended unit as S2 and appears before it
|
Yes_Same, -- S1 is in same extended unit as S2, Slocs are the same
|
Yes_Same, -- S1 is in same extended unit as S2, Slocs are the same
|
Yes_After, -- S1 is in same extended unit as S2, and appears after it
|
Yes_After, -- S1 is in same extended unit as S2, and appears after it
|
No); -- S2 is not in same extended unit as S2
|
No); -- S2 is not in same extended unit as S2
|
|
|
function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result;
|
function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result;
|
-- Used by In_Same_Extended_Unit and Earlier_In_Extended_Unit. Returns
|
-- Used by In_Same_Extended_Unit and Earlier_In_Extended_Unit. Returns
|
-- value as described above.
|
-- value as described above.
|
|
|
function Get_Code_Or_Source_Unit
|
function Get_Code_Or_Source_Unit
|
(S : Source_Ptr;
|
(S : Source_Ptr;
|
Unwind_Instances : Boolean) return Unit_Number_Type;
|
Unwind_Instances : Boolean) return Unit_Number_Type;
|
-- Common code for Get_Code_Unit (get unit of instantiation for location)
|
-- Common code for Get_Code_Unit (get unit of instantiation for location)
|
-- and Get_Source_Unit (get unit of template for location).
|
-- and Get_Source_Unit (get unit of template for location).
|
|
|
--------------------------------------------
|
--------------------------------------------
|
-- Access Functions for Unit Table Fields --
|
-- Access Functions for Unit Table Fields --
|
--------------------------------------------
|
--------------------------------------------
|
|
|
function Cunit (U : Unit_Number_Type) return Node_Id is
|
function Cunit (U : Unit_Number_Type) return Node_Id is
|
begin
|
begin
|
return Units.Table (U).Cunit;
|
return Units.Table (U).Cunit;
|
end Cunit;
|
end Cunit;
|
|
|
function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
|
function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
|
begin
|
begin
|
return Units.Table (U).Cunit_Entity;
|
return Units.Table (U).Cunit_Entity;
|
end Cunit_Entity;
|
end Cunit_Entity;
|
|
|
function Dependency_Num (U : Unit_Number_Type) return Nat is
|
function Dependency_Num (U : Unit_Number_Type) return Nat is
|
begin
|
begin
|
return Units.Table (U).Dependency_Num;
|
return Units.Table (U).Dependency_Num;
|
end Dependency_Num;
|
end Dependency_Num;
|
|
|
function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
|
function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Dynamic_Elab;
|
return Units.Table (U).Dynamic_Elab;
|
end Dynamic_Elab;
|
end Dynamic_Elab;
|
|
|
function Error_Location (U : Unit_Number_Type) return Source_Ptr is
|
function Error_Location (U : Unit_Number_Type) return Source_Ptr is
|
begin
|
begin
|
return Units.Table (U).Error_Location;
|
return Units.Table (U).Error_Location;
|
end Error_Location;
|
end Error_Location;
|
|
|
function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
|
function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
|
begin
|
begin
|
return Units.Table (U).Expected_Unit;
|
return Units.Table (U).Expected_Unit;
|
end Expected_Unit;
|
end Expected_Unit;
|
|
|
function Fatal_Error (U : Unit_Number_Type) return Boolean is
|
function Fatal_Error (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Fatal_Error;
|
return Units.Table (U).Fatal_Error;
|
end Fatal_Error;
|
end Fatal_Error;
|
|
|
function Generate_Code (U : Unit_Number_Type) return Boolean is
|
function Generate_Code (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Generate_Code;
|
return Units.Table (U).Generate_Code;
|
end Generate_Code;
|
end Generate_Code;
|
|
|
function Has_RACW (U : Unit_Number_Type) return Boolean is
|
function Has_RACW (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Has_RACW;
|
return Units.Table (U).Has_RACW;
|
end Has_RACW;
|
end Has_RACW;
|
|
|
function Is_Compiler_Unit (U : Unit_Number_Type) return Boolean is
|
function Is_Compiler_Unit (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Is_Compiler_Unit;
|
return Units.Table (U).Is_Compiler_Unit;
|
end Is_Compiler_Unit;
|
end Is_Compiler_Unit;
|
|
|
function Ident_String (U : Unit_Number_Type) return Node_Id is
|
function Ident_String (U : Unit_Number_Type) return Node_Id is
|
begin
|
begin
|
return Units.Table (U).Ident_String;
|
return Units.Table (U).Ident_String;
|
end Ident_String;
|
end Ident_String;
|
|
|
function Loading (U : Unit_Number_Type) return Boolean is
|
function Loading (U : Unit_Number_Type) return Boolean is
|
begin
|
begin
|
return Units.Table (U).Loading;
|
return Units.Table (U).Loading;
|
end Loading;
|
end Loading;
|
|
|
function Main_Priority (U : Unit_Number_Type) return Int is
|
function Main_Priority (U : Unit_Number_Type) return Int is
|
begin
|
begin
|
return Units.Table (U).Main_Priority;
|
return Units.Table (U).Main_Priority;
|
end Main_Priority;
|
end Main_Priority;
|
|
|
function Munit_Index (U : Unit_Number_Type) return Nat is
|
function Munit_Index (U : Unit_Number_Type) return Nat is
|
begin
|
begin
|
return Units.Table (U).Munit_Index;
|
return Units.Table (U).Munit_Index;
|
end Munit_Index;
|
end Munit_Index;
|
|
|
function OA_Setting (U : Unit_Number_Type) return Character is
|
function OA_Setting (U : Unit_Number_Type) return Character is
|
begin
|
begin
|
return Units.Table (U).OA_Setting;
|
return Units.Table (U).OA_Setting;
|
end OA_Setting;
|
end OA_Setting;
|
|
|
function Source_Index (U : Unit_Number_Type) return Source_File_Index is
|
function Source_Index (U : Unit_Number_Type) return Source_File_Index is
|
begin
|
begin
|
return Units.Table (U).Source_Index;
|
return Units.Table (U).Source_Index;
|
end Source_Index;
|
end Source_Index;
|
|
|
function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
|
function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
|
begin
|
begin
|
return Units.Table (U).Unit_File_Name;
|
return Units.Table (U).Unit_File_Name;
|
end Unit_File_Name;
|
end Unit_File_Name;
|
|
|
function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
|
function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
|
begin
|
begin
|
return Units.Table (U).Unit_Name;
|
return Units.Table (U).Unit_Name;
|
end Unit_Name;
|
end Unit_Name;
|
|
|
------------------------------------------
|
------------------------------------------
|
-- Subprograms to Set Unit Table Fields --
|
-- Subprograms to Set Unit Table Fields --
|
------------------------------------------
|
------------------------------------------
|
|
|
procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
|
procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
|
begin
|
begin
|
Units.Table (U).Cunit := N;
|
Units.Table (U).Cunit := N;
|
end Set_Cunit;
|
end Set_Cunit;
|
|
|
procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
|
procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
|
begin
|
begin
|
Units.Table (U).Cunit_Entity := E;
|
Units.Table (U).Cunit_Entity := E;
|
Set_Is_Compilation_Unit (E);
|
Set_Is_Compilation_Unit (E);
|
end Set_Cunit_Entity;
|
end Set_Cunit_Entity;
|
|
|
procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
|
procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
|
begin
|
begin
|
Units.Table (U).Dynamic_Elab := B;
|
Units.Table (U).Dynamic_Elab := B;
|
end Set_Dynamic_Elab;
|
end Set_Dynamic_Elab;
|
|
|
procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
|
procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
|
begin
|
begin
|
Units.Table (U).Error_Location := W;
|
Units.Table (U).Error_Location := W;
|
end Set_Error_Location;
|
end Set_Error_Location;
|
|
|
procedure Set_Fatal_Error (U : Unit_Number_Type; B : Boolean := True) is
|
procedure Set_Fatal_Error (U : Unit_Number_Type; B : Boolean := True) is
|
begin
|
begin
|
Units.Table (U).Fatal_Error := B;
|
Units.Table (U).Fatal_Error := B;
|
end Set_Fatal_Error;
|
end Set_Fatal_Error;
|
|
|
procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
|
procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
|
begin
|
begin
|
Units.Table (U).Generate_Code := B;
|
Units.Table (U).Generate_Code := B;
|
end Set_Generate_Code;
|
end Set_Generate_Code;
|
|
|
procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
|
procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
|
begin
|
begin
|
Units.Table (U).Has_RACW := B;
|
Units.Table (U).Has_RACW := B;
|
end Set_Has_RACW;
|
end Set_Has_RACW;
|
|
|
procedure Set_Is_Compiler_Unit
|
procedure Set_Is_Compiler_Unit
|
(U : Unit_Number_Type;
|
(U : Unit_Number_Type;
|
B : Boolean := True)
|
B : Boolean := True)
|
is
|
is
|
begin
|
begin
|
Units.Table (U).Is_Compiler_Unit := B;
|
Units.Table (U).Is_Compiler_Unit := B;
|
end Set_Is_Compiler_Unit;
|
end Set_Is_Compiler_Unit;
|
|
|
procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
|
procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
|
begin
|
begin
|
Units.Table (U).Ident_String := N;
|
Units.Table (U).Ident_String := N;
|
end Set_Ident_String;
|
end Set_Ident_String;
|
|
|
procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
|
procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
|
begin
|
begin
|
Units.Table (U).Loading := B;
|
Units.Table (U).Loading := B;
|
end Set_Loading;
|
end Set_Loading;
|
|
|
procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
|
procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
|
begin
|
begin
|
Units.Table (U).Main_Priority := P;
|
Units.Table (U).Main_Priority := P;
|
end Set_Main_Priority;
|
end Set_Main_Priority;
|
|
|
procedure Set_OA_Setting (U : Unit_Number_Type; C : Character) is
|
procedure Set_OA_Setting (U : Unit_Number_Type; C : Character) is
|
begin
|
begin
|
Units.Table (U).OA_Setting := C;
|
Units.Table (U).OA_Setting := C;
|
end Set_OA_Setting;
|
end Set_OA_Setting;
|
|
|
procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
|
procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
|
begin
|
begin
|
Units.Table (U).Unit_Name := N;
|
Units.Table (U).Unit_Name := N;
|
end Set_Unit_Name;
|
end Set_Unit_Name;
|
|
|
------------------------------
|
------------------------------
|
-- Check_Same_Extended_Unit --
|
-- Check_Same_Extended_Unit --
|
------------------------------
|
------------------------------
|
|
|
function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result is
|
function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result is
|
Sloc1 : Source_Ptr;
|
Sloc1 : Source_Ptr;
|
Sloc2 : Source_Ptr;
|
Sloc2 : Source_Ptr;
|
Sind1 : Source_File_Index;
|
Sind1 : Source_File_Index;
|
Sind2 : Source_File_Index;
|
Sind2 : Source_File_Index;
|
Inst1 : Source_Ptr;
|
Inst1 : Source_Ptr;
|
Inst2 : Source_Ptr;
|
Inst2 : Source_Ptr;
|
Unum1 : Unit_Number_Type;
|
Unum1 : Unit_Number_Type;
|
Unum2 : Unit_Number_Type;
|
Unum2 : Unit_Number_Type;
|
Unit1 : Node_Id;
|
Unit1 : Node_Id;
|
Unit2 : Node_Id;
|
Unit2 : Node_Id;
|
Depth1 : Nat;
|
Depth1 : Nat;
|
Depth2 : Nat;
|
Depth2 : Nat;
|
|
|
begin
|
begin
|
if S1 = No_Location or else S2 = No_Location then
|
if S1 = No_Location or else S2 = No_Location then
|
return No;
|
return No;
|
|
|
elsif S1 = Standard_Location then
|
elsif S1 = Standard_Location then
|
if S2 = Standard_Location then
|
if S2 = Standard_Location then
|
return Yes_Same;
|
return Yes_Same;
|
else
|
else
|
return No;
|
return No;
|
end if;
|
end if;
|
|
|
elsif S2 = Standard_Location then
|
elsif S2 = Standard_Location then
|
return No;
|
return No;
|
end if;
|
end if;
|
|
|
Sloc1 := S1;
|
Sloc1 := S1;
|
Sloc2 := S2;
|
Sloc2 := S2;
|
Unum1 := Get_Code_Unit (Sloc1);
|
Unum1 := Get_Code_Unit (Sloc1);
|
Unum2 := Get_Code_Unit (Sloc2);
|
Unum2 := Get_Code_Unit (Sloc2);
|
|
|
loop
|
loop
|
Sind1 := Get_Source_File_Index (Sloc1);
|
Sind1 := Get_Source_File_Index (Sloc1);
|
Sind2 := Get_Source_File_Index (Sloc2);
|
Sind2 := Get_Source_File_Index (Sloc2);
|
|
|
if Sind1 = Sind2 then
|
if Sind1 = Sind2 then
|
if Sloc1 < Sloc2 then
|
if Sloc1 < Sloc2 then
|
return Yes_Before;
|
return Yes_Before;
|
elsif Sloc1 > Sloc2 then
|
elsif Sloc1 > Sloc2 then
|
return Yes_After;
|
return Yes_After;
|
else
|
else
|
return Yes_Same;
|
return Yes_Same;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- OK, the two nodes are in separate source elements, but this is not
|
-- OK, the two nodes are in separate source elements, but this is not
|
-- decisive, because of the issue of subunits and instantiations.
|
-- decisive, because of the issue of subunits and instantiations.
|
|
|
-- First we deal with subunits, since if the subunit is in an
|
-- First we deal with subunits, since if the subunit is in an
|
-- instantiation, we know that the parent is in the corresponding
|
-- instantiation, we know that the parent is in the corresponding
|
-- instantiation, since that is the only way we can have a subunit
|
-- instantiation, since that is the only way we can have a subunit
|
-- that is part of an instantiation.
|
-- that is part of an instantiation.
|
|
|
Unit1 := Unit (Cunit (Unum1));
|
Unit1 := Unit (Cunit (Unum1));
|
Unit2 := Unit (Cunit (Unum2));
|
Unit2 := Unit (Cunit (Unum2));
|
|
|
if Nkind (Unit1) = N_Subunit
|
if Nkind (Unit1) = N_Subunit
|
and then Present (Corresponding_Stub (Unit1))
|
and then Present (Corresponding_Stub (Unit1))
|
then
|
then
|
-- Both in subunits. They could have a common ancestor. If they
|
-- Both in subunits. They could have a common ancestor. If they
|
-- do, then the deeper one must have a longer unit name. Replace
|
-- do, then the deeper one must have a longer unit name. Replace
|
-- the deeper one with its corresponding stub, in order to find
|
-- the deeper one with its corresponding stub, in order to find
|
-- nearest common ancestor, if any.
|
-- nearest common ancestor, if any.
|
|
|
if Nkind (Unit2) = N_Subunit
|
if Nkind (Unit2) = N_Subunit
|
and then Present (Corresponding_Stub (Unit2))
|
and then Present (Corresponding_Stub (Unit2))
|
then
|
then
|
if Length_Of_Name (Unit_Name (Unum1)) <
|
if Length_Of_Name (Unit_Name (Unum1)) <
|
Length_Of_Name (Unit_Name (Unum2))
|
Length_Of_Name (Unit_Name (Unum2))
|
then
|
then
|
Sloc2 := Sloc (Corresponding_Stub (Unit2));
|
Sloc2 := Sloc (Corresponding_Stub (Unit2));
|
Unum2 := Get_Source_Unit (Sloc2);
|
Unum2 := Get_Source_Unit (Sloc2);
|
goto Continue;
|
goto Continue;
|
|
|
else
|
else
|
Sloc1 := Sloc (Corresponding_Stub (Unit1));
|
Sloc1 := Sloc (Corresponding_Stub (Unit1));
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum1 := Get_Source_Unit (Sloc1);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- Nod1 in subunit, Nod2 not
|
-- Nod1 in subunit, Nod2 not
|
|
|
else
|
else
|
Sloc1 := Sloc (Corresponding_Stub (Unit1));
|
Sloc1 := Sloc (Corresponding_Stub (Unit1));
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum1 := Get_Source_Unit (Sloc1);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- Nod2 in subunit, Nod1 not
|
-- Nod2 in subunit, Nod1 not
|
|
|
elsif Nkind (Unit2) = N_Subunit
|
elsif Nkind (Unit2) = N_Subunit
|
and then Present (Corresponding_Stub (Unit2))
|
and then Present (Corresponding_Stub (Unit2))
|
then
|
then
|
Sloc2 := Sloc (Corresponding_Stub (Unit2));
|
Sloc2 := Sloc (Corresponding_Stub (Unit2));
|
Unum2 := Get_Source_Unit (Sloc2);
|
Unum2 := Get_Source_Unit (Sloc2);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- At this stage we know that neither is a subunit, so we deal
|
-- At this stage we know that neither is a subunit, so we deal
|
-- with instantiations, since we could have a common ancestor
|
-- with instantiations, since we could have a common ancestor
|
|
|
Inst1 := Instantiation (Sind1);
|
Inst1 := Instantiation (Sind1);
|
Inst2 := Instantiation (Sind2);
|
Inst2 := Instantiation (Sind2);
|
|
|
if Inst1 /= No_Location then
|
if Inst1 /= No_Location then
|
|
|
-- Both are instantiations
|
-- Both are instantiations
|
|
|
if Inst2 /= No_Location then
|
if Inst2 /= No_Location then
|
|
|
Depth1 := Instantiation_Depth (Sloc1);
|
Depth1 := Instantiation_Depth (Sloc1);
|
Depth2 := Instantiation_Depth (Sloc2);
|
Depth2 := Instantiation_Depth (Sloc2);
|
|
|
if Depth1 < Depth2 then
|
if Depth1 < Depth2 then
|
Sloc2 := Inst2;
|
Sloc2 := Inst2;
|
Unum2 := Get_Source_Unit (Sloc2);
|
Unum2 := Get_Source_Unit (Sloc2);
|
goto Continue;
|
goto Continue;
|
|
|
elsif Depth1 > Depth2 then
|
elsif Depth1 > Depth2 then
|
Sloc1 := Inst1;
|
Sloc1 := Inst1;
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum1 := Get_Source_Unit (Sloc1);
|
goto Continue;
|
goto Continue;
|
|
|
else
|
else
|
Sloc1 := Inst1;
|
Sloc1 := Inst1;
|
Sloc2 := Inst2;
|
Sloc2 := Inst2;
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum2 := Get_Source_Unit (Sloc2);
|
Unum2 := Get_Source_Unit (Sloc2);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- Only first node is in instantiation
|
-- Only first node is in instantiation
|
|
|
else
|
else
|
Sloc1 := Inst1;
|
Sloc1 := Inst1;
|
Unum1 := Get_Source_Unit (Sloc1);
|
Unum1 := Get_Source_Unit (Sloc1);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- Only second node is instantiation
|
-- Only second node is instantiation
|
|
|
elsif Inst2 /= No_Location then
|
elsif Inst2 /= No_Location then
|
Sloc2 := Inst2;
|
Sloc2 := Inst2;
|
Unum2 := Get_Source_Unit (Sloc2);
|
Unum2 := Get_Source_Unit (Sloc2);
|
goto Continue;
|
goto Continue;
|
end if;
|
end if;
|
|
|
-- No instantiations involved, so we are not in the same unit
|
-- No instantiations involved, so we are not in the same unit
|
-- However, there is one case still to check, namely the case
|
-- However, there is one case still to check, namely the case
|
-- where one location is in the spec, and the other in the
|
-- where one location is in the spec, and the other in the
|
-- corresponding body (the spec location is earlier).
|
-- corresponding body (the spec location is earlier).
|
|
|
if Nkind (Unit1) = N_Subprogram_Body
|
if Nkind (Unit1) = N_Subprogram_Body
|
or else
|
or else
|
Nkind (Unit1) = N_Package_Body
|
Nkind (Unit1) = N_Package_Body
|
then
|
then
|
if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
|
if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
|
return Yes_After;
|
return Yes_After;
|
end if;
|
end if;
|
|
|
elsif Nkind (Unit2) = N_Subprogram_Body
|
elsif Nkind (Unit2) = N_Subprogram_Body
|
or else
|
or else
|
Nkind (Unit2) = N_Package_Body
|
Nkind (Unit2) = N_Package_Body
|
then
|
then
|
if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
|
if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
|
return Yes_Before;
|
return Yes_Before;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- If that special case does not occur, then we are certain that
|
-- If that special case does not occur, then we are certain that
|
-- the two locations are really in separate units.
|
-- the two locations are really in separate units.
|
|
|
return No;
|
return No;
|
|
|
<<Continue>>
|
<<Continue>>
|
null;
|
null;
|
end loop;
|
end loop;
|
end Check_Same_Extended_Unit;
|
end Check_Same_Extended_Unit;
|
|
|
-------------------------------
|
-------------------------------
|
-- Compilation_Switches_Last --
|
-- Compilation_Switches_Last --
|
-------------------------------
|
-------------------------------
|
|
|
function Compilation_Switches_Last return Nat is
|
function Compilation_Switches_Last return Nat is
|
begin
|
begin
|
return Compilation_Switches.Last;
|
return Compilation_Switches.Last;
|
end Compilation_Switches_Last;
|
end Compilation_Switches_Last;
|
|
|
---------------------------
|
---------------------------
|
-- Enable_Switch_Storing --
|
-- Enable_Switch_Storing --
|
---------------------------
|
---------------------------
|
|
|
procedure Enable_Switch_Storing is
|
procedure Enable_Switch_Storing is
|
begin
|
begin
|
Switch_Storing_Enabled := True;
|
Switch_Storing_Enabled := True;
|
end Enable_Switch_Storing;
|
end Enable_Switch_Storing;
|
|
|
----------------------------
|
----------------------------
|
-- Disable_Switch_Storing --
|
-- Disable_Switch_Storing --
|
----------------------------
|
----------------------------
|
|
|
procedure Disable_Switch_Storing is
|
procedure Disable_Switch_Storing is
|
begin
|
begin
|
Switch_Storing_Enabled := False;
|
Switch_Storing_Enabled := False;
|
end Disable_Switch_Storing;
|
end Disable_Switch_Storing;
|
|
|
------------------------------
|
------------------------------
|
-- Earlier_In_Extended_Unit --
|
-- Earlier_In_Extended_Unit --
|
------------------------------
|
------------------------------
|
|
|
function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
|
function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
|
begin
|
begin
|
return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
|
return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
|
end Earlier_In_Extended_Unit;
|
end Earlier_In_Extended_Unit;
|
|
|
----------------------------
|
----------------------------
|
-- Entity_Is_In_Main_Unit --
|
-- Entity_Is_In_Main_Unit --
|
----------------------------
|
----------------------------
|
|
|
function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
|
function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
|
S : Entity_Id;
|
S : Entity_Id;
|
|
|
begin
|
begin
|
S := Scope (E);
|
S := Scope (E);
|
|
|
while S /= Standard_Standard loop
|
while S /= Standard_Standard loop
|
if S = Main_Unit_Entity then
|
if S = Main_Unit_Entity then
|
return True;
|
return True;
|
elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
|
elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
|
return False;
|
return False;
|
else
|
else
|
S := Scope (S);
|
S := Scope (S);
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Entity_Is_In_Main_Unit;
|
end Entity_Is_In_Main_Unit;
|
|
|
--------------------------
|
--------------------------
|
-- Generic_May_Lack_ALI --
|
-- Generic_May_Lack_ALI --
|
--------------------------
|
--------------------------
|
|
|
function Generic_May_Lack_ALI (Sfile : File_Name_Type) return Boolean is
|
function Generic_May_Lack_ALI (Sfile : File_Name_Type) return Boolean is
|
begin
|
begin
|
-- We allow internal generic units to be used without having a
|
-- We allow internal generic units to be used without having a
|
-- corresponding ALI files to help bootstrapping with older compilers
|
-- corresponding ALI files to help bootstrapping with older compilers
|
-- that did not support generating ALIs for such generics. It is safe
|
-- that did not support generating ALIs for such generics. It is safe
|
-- to do so because the only thing the generated code would contain
|
-- to do so because the only thing the generated code would contain
|
-- is the elaboration boolean, and we are careful to elaborate all
|
-- is the elaboration boolean, and we are careful to elaborate all
|
-- predefined units first anyway.
|
-- predefined units first anyway.
|
|
|
return Is_Internal_File_Name
|
return Is_Internal_File_Name
|
(Fname => Sfile,
|
(Fname => Sfile,
|
Renamings_Included => True);
|
Renamings_Included => True);
|
end Generic_May_Lack_ALI;
|
end Generic_May_Lack_ALI;
|
|
|
-----------------------------
|
-----------------------------
|
-- Get_Code_Or_Source_Unit --
|
-- Get_Code_Or_Source_Unit --
|
-----------------------------
|
-----------------------------
|
|
|
function Get_Code_Or_Source_Unit
|
function Get_Code_Or_Source_Unit
|
(S : Source_Ptr;
|
(S : Source_Ptr;
|
Unwind_Instances : Boolean) return Unit_Number_Type
|
Unwind_Instances : Boolean) return Unit_Number_Type
|
is
|
is
|
begin
|
begin
|
-- Search table unless we have No_Location, which can happen if the
|
-- Search table unless we have No_Location, which can happen if the
|
-- relevant location has not been set yet. Happens for example when
|
-- relevant location has not been set yet. Happens for example when
|
-- we obtain Sloc (Cunit (Main_Unit)) before it is set.
|
-- we obtain Sloc (Cunit (Main_Unit)) before it is set.
|
|
|
if S /= No_Location then
|
if S /= No_Location then
|
declare
|
declare
|
Source_File : Source_File_Index;
|
Source_File : Source_File_Index;
|
Source_Unit : Unit_Number_Type;
|
Source_Unit : Unit_Number_Type;
|
|
|
begin
|
begin
|
Source_File := Get_Source_File_Index (S);
|
Source_File := Get_Source_File_Index (S);
|
|
|
if Unwind_Instances then
|
if Unwind_Instances then
|
while Template (Source_File) /= No_Source_File loop
|
while Template (Source_File) /= No_Source_File loop
|
Source_File := Template (Source_File);
|
Source_File := Template (Source_File);
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
Source_Unit := Unit (Source_File);
|
Source_Unit := Unit (Source_File);
|
|
|
if Source_Unit /= No_Unit then
|
if Source_Unit /= No_Unit then
|
return Source_Unit;
|
return Source_Unit;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
-- If S was No_Location, or was not in the table, we must be in the main
|
-- If S was No_Location, or was not in the table, we must be in the main
|
-- source unit (and the value has not been placed in the table yet),
|
-- source unit (and the value has not been placed in the table yet),
|
-- or in one of the configuration pragma files.
|
-- or in one of the configuration pragma files.
|
|
|
return Main_Unit;
|
return Main_Unit;
|
end Get_Code_Or_Source_Unit;
|
end Get_Code_Or_Source_Unit;
|
|
|
-------------------
|
-------------------
|
-- Get_Code_Unit --
|
-- Get_Code_Unit --
|
-------------------
|
-------------------
|
|
|
function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
|
function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
|
begin
|
begin
|
return Get_Code_Or_Source_Unit (Top_Level_Location (S),
|
return Get_Code_Or_Source_Unit (Top_Level_Location (S),
|
Unwind_Instances => False);
|
Unwind_Instances => False);
|
end Get_Code_Unit;
|
end Get_Code_Unit;
|
|
|
function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
|
function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
|
begin
|
begin
|
return Get_Code_Unit (Sloc (N));
|
return Get_Code_Unit (Sloc (N));
|
end Get_Code_Unit;
|
end Get_Code_Unit;
|
|
|
----------------------------
|
----------------------------
|
-- Get_Compilation_Switch --
|
-- Get_Compilation_Switch --
|
----------------------------
|
----------------------------
|
|
|
function Get_Compilation_Switch (N : Pos) return String_Ptr is
|
function Get_Compilation_Switch (N : Pos) return String_Ptr is
|
begin
|
begin
|
if N <= Compilation_Switches.Last then
|
if N <= Compilation_Switches.Last then
|
return Compilation_Switches.Table (N);
|
return Compilation_Switches.Table (N);
|
|
|
else
|
else
|
return null;
|
return null;
|
end if;
|
end if;
|
end Get_Compilation_Switch;
|
end Get_Compilation_Switch;
|
|
|
----------------------------------
|
----------------------------------
|
-- Get_Cunit_Entity_Unit_Number --
|
-- Get_Cunit_Entity_Unit_Number --
|
----------------------------------
|
----------------------------------
|
|
|
function Get_Cunit_Entity_Unit_Number
|
function Get_Cunit_Entity_Unit_Number
|
(E : Entity_Id) return Unit_Number_Type
|
(E : Entity_Id) return Unit_Number_Type
|
is
|
is
|
begin
|
begin
|
for U in Units.First .. Units.Last loop
|
for U in Units.First .. Units.Last loop
|
if Cunit_Entity (U) = E then
|
if Cunit_Entity (U) = E then
|
return U;
|
return U;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- If not in the table, must be the main source unit, and we just
|
-- If not in the table, must be the main source unit, and we just
|
-- have not got it put into the table yet.
|
-- have not got it put into the table yet.
|
|
|
return Main_Unit;
|
return Main_Unit;
|
end Get_Cunit_Entity_Unit_Number;
|
end Get_Cunit_Entity_Unit_Number;
|
|
|
---------------------------
|
---------------------------
|
-- Get_Cunit_Unit_Number --
|
-- Get_Cunit_Unit_Number --
|
---------------------------
|
---------------------------
|
|
|
function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
|
function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
|
begin
|
begin
|
for U in Units.First .. Units.Last loop
|
for U in Units.First .. Units.Last loop
|
if Cunit (U) = N then
|
if Cunit (U) = N then
|
return U;
|
return U;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- If not in the table, must be a spec created for a main unit that is a
|
-- If not in the table, must be a spec created for a main unit that is a
|
-- child subprogram body which we have not inserted into the table yet.
|
-- child subprogram body which we have not inserted into the table yet.
|
|
|
if N = Library_Unit (Cunit (Main_Unit)) then
|
if N = Library_Unit (Cunit (Main_Unit)) then
|
return Main_Unit;
|
return Main_Unit;
|
|
|
-- If it is anything else, something is seriously wrong, and we really
|
-- If it is anything else, something is seriously wrong, and we really
|
-- don't want to proceed, even if assertions are off, so we explicitly
|
-- don't want to proceed, even if assertions are off, so we explicitly
|
-- raise an exception in this case to terminate compilation.
|
-- raise an exception in this case to terminate compilation.
|
|
|
else
|
else
|
raise Program_Error;
|
raise Program_Error;
|
end if;
|
end if;
|
end Get_Cunit_Unit_Number;
|
end Get_Cunit_Unit_Number;
|
|
|
---------------------
|
---------------------
|
-- Get_Source_Unit --
|
-- Get_Source_Unit --
|
---------------------
|
---------------------
|
|
|
function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
|
function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
|
begin
|
begin
|
return Get_Code_Or_Source_Unit (S, Unwind_Instances => True);
|
return Get_Code_Or_Source_Unit (S, Unwind_Instances => True);
|
end Get_Source_Unit;
|
end Get_Source_Unit;
|
|
|
function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
|
function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
|
begin
|
begin
|
return Get_Source_Unit (Sloc (N));
|
return Get_Source_Unit (Sloc (N));
|
end Get_Source_Unit;
|
end Get_Source_Unit;
|
|
|
--------------------------------
|
--------------------------------
|
-- In_Extended_Main_Code_Unit --
|
-- In_Extended_Main_Code_Unit --
|
--------------------------------
|
--------------------------------
|
|
|
function In_Extended_Main_Code_Unit
|
function In_Extended_Main_Code_Unit
|
(N : Node_Or_Entity_Id) return Boolean
|
(N : Node_Or_Entity_Id) return Boolean
|
is
|
is
|
begin
|
begin
|
if Sloc (N) = Standard_Location then
|
if Sloc (N) = Standard_Location then
|
return True;
|
return True;
|
|
|
elsif Sloc (N) = No_Location then
|
elsif Sloc (N) = No_Location then
|
return False;
|
return False;
|
|
|
-- Special case Itypes to test the Sloc of the associated node. The
|
-- Special case Itypes to test the Sloc of the associated node. The
|
-- reason we do this is for possible calls from gigi after -gnatD
|
-- reason we do this is for possible calls from gigi after -gnatD
|
-- processing is complete in sprint. This processing updates the
|
-- processing is complete in sprint. This processing updates the
|
-- sloc fields of all nodes in the tree, but itypes are not in the
|
-- sloc fields of all nodes in the tree, but itypes are not in the
|
-- tree so their slocs do not get updated.
|
-- tree so their slocs do not get updated.
|
|
|
elsif Nkind (N) = N_Defining_Identifier
|
elsif Nkind (N) = N_Defining_Identifier
|
and then Is_Itype (N)
|
and then Is_Itype (N)
|
then
|
then
|
return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
|
return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
|
|
|
-- Otherwise see if we are in the main unit
|
-- Otherwise see if we are in the main unit
|
|
|
elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
|
elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
|
return True;
|
return True;
|
|
|
-- Node may be in spec (or subunit etc) of main unit
|
-- Node may be in spec (or subunit etc) of main unit
|
|
|
else
|
else
|
return
|
return
|
In_Same_Extended_Unit (N, Cunit (Main_Unit));
|
In_Same_Extended_Unit (N, Cunit (Main_Unit));
|
end if;
|
end if;
|
end In_Extended_Main_Code_Unit;
|
end In_Extended_Main_Code_Unit;
|
|
|
function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
|
function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
|
begin
|
begin
|
if Loc = Standard_Location then
|
if Loc = Standard_Location then
|
return True;
|
return True;
|
|
|
elsif Loc = No_Location then
|
elsif Loc = No_Location then
|
return False;
|
return False;
|
|
|
-- Otherwise see if we are in the main unit
|
-- Otherwise see if we are in the main unit
|
|
|
elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
|
elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
|
return True;
|
return True;
|
|
|
-- Location may be in spec (or subunit etc) of main unit
|
-- Location may be in spec (or subunit etc) of main unit
|
|
|
else
|
else
|
return
|
return
|
In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
|
In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
|
end if;
|
end if;
|
end In_Extended_Main_Code_Unit;
|
end In_Extended_Main_Code_Unit;
|
|
|
----------------------------------
|
----------------------------------
|
-- In_Extended_Main_Source_Unit --
|
-- In_Extended_Main_Source_Unit --
|
----------------------------------
|
----------------------------------
|
|
|
function In_Extended_Main_Source_Unit
|
function In_Extended_Main_Source_Unit
|
(N : Node_Or_Entity_Id) return Boolean
|
(N : Node_Or_Entity_Id) return Boolean
|
is
|
is
|
Nloc : constant Source_Ptr := Sloc (N);
|
Nloc : constant Source_Ptr := Sloc (N);
|
Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
|
Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
|
|
|
begin
|
begin
|
-- If Mloc is not set, it means we are still parsing the main unit,
|
-- If Mloc is not set, it means we are still parsing the main unit,
|
-- so everything so far is in the extended main source unit.
|
-- so everything so far is in the extended main source unit.
|
|
|
if Mloc = No_Location then
|
if Mloc = No_Location then
|
return True;
|
return True;
|
|
|
-- Special value cases
|
-- Special value cases
|
|
|
elsif Nloc = Standard_Location then
|
elsif Nloc = Standard_Location then
|
return True;
|
return True;
|
|
|
elsif Nloc = No_Location then
|
elsif Nloc = No_Location then
|
return False;
|
return False;
|
|
|
-- Special case Itypes to test the Sloc of the associated node. The
|
-- Special case Itypes to test the Sloc of the associated node. The
|
-- reason we do this is for possible calls from gigi after -gnatD
|
-- reason we do this is for possible calls from gigi after -gnatD
|
-- processing is complete in sprint. This processing updates the
|
-- processing is complete in sprint. This processing updates the
|
-- sloc fields of all nodes in the tree, but itypes are not in the
|
-- sloc fields of all nodes in the tree, but itypes are not in the
|
-- tree so their slocs do not get updated.
|
-- tree so their slocs do not get updated.
|
|
|
elsif Nkind (N) = N_Defining_Identifier
|
elsif Nkind (N) = N_Defining_Identifier
|
and then Is_Itype (N)
|
and then Is_Itype (N)
|
then
|
then
|
return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
|
return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
|
|
|
-- Otherwise compare original locations to see if in same unit
|
-- Otherwise compare original locations to see if in same unit
|
|
|
else
|
else
|
return
|
return
|
In_Same_Extended_Unit
|
In_Same_Extended_Unit
|
(Original_Location (Nloc), Original_Location (Mloc));
|
(Original_Location (Nloc), Original_Location (Mloc));
|
end if;
|
end if;
|
end In_Extended_Main_Source_Unit;
|
end In_Extended_Main_Source_Unit;
|
|
|
function In_Extended_Main_Source_Unit
|
function In_Extended_Main_Source_Unit
|
(Loc : Source_Ptr) return Boolean
|
(Loc : Source_Ptr) return Boolean
|
is
|
is
|
Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
|
Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
|
|
|
begin
|
begin
|
-- If Mloc is not set, it means we are still parsing the main unit,
|
-- If Mloc is not set, it means we are still parsing the main unit,
|
-- so everything so far is in the extended main source unit.
|
-- so everything so far is in the extended main source unit.
|
|
|
if Mloc = No_Location then
|
if Mloc = No_Location then
|
return True;
|
return True;
|
|
|
-- Special value cases
|
-- Special value cases
|
|
|
elsif Loc = Standard_Location then
|
elsif Loc = Standard_Location then
|
return True;
|
return True;
|
|
|
elsif Loc = No_Location then
|
elsif Loc = No_Location then
|
return False;
|
return False;
|
|
|
-- Otherwise compare original locations to see if in same unit
|
-- Otherwise compare original locations to see if in same unit
|
|
|
else
|
else
|
return
|
return
|
In_Same_Extended_Unit
|
In_Same_Extended_Unit
|
(Original_Location (Loc), Original_Location (Mloc));
|
(Original_Location (Loc), Original_Location (Mloc));
|
end if;
|
end if;
|
end In_Extended_Main_Source_Unit;
|
end In_Extended_Main_Source_Unit;
|
|
|
------------------------
|
------------------------
|
-- In_Predefined_Unit --
|
-- In_Predefined_Unit --
|
------------------------
|
------------------------
|
|
|
function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
|
function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
|
begin
|
begin
|
return In_Predefined_Unit (Sloc (N));
|
return In_Predefined_Unit (Sloc (N));
|
end In_Predefined_Unit;
|
end In_Predefined_Unit;
|
|
|
function In_Predefined_Unit (S : Source_Ptr) return Boolean is
|
function In_Predefined_Unit (S : Source_Ptr) return Boolean is
|
Unit : constant Unit_Number_Type := Get_Source_Unit (S);
|
Unit : constant Unit_Number_Type := Get_Source_Unit (S);
|
File : constant File_Name_Type := Unit_File_Name (Unit);
|
File : constant File_Name_Type := Unit_File_Name (Unit);
|
begin
|
begin
|
return Is_Predefined_File_Name (File);
|
return Is_Predefined_File_Name (File);
|
end In_Predefined_Unit;
|
end In_Predefined_Unit;
|
|
|
-----------------------
|
-----------------------
|
-- In_Same_Code_Unit --
|
-- In_Same_Code_Unit --
|
-----------------------
|
-----------------------
|
|
|
function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
|
function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
|
S1 : constant Source_Ptr := Sloc (N1);
|
S1 : constant Source_Ptr := Sloc (N1);
|
S2 : constant Source_Ptr := Sloc (N2);
|
S2 : constant Source_Ptr := Sloc (N2);
|
|
|
begin
|
begin
|
if S1 = No_Location or else S2 = No_Location then
|
if S1 = No_Location or else S2 = No_Location then
|
return False;
|
return False;
|
|
|
elsif S1 = Standard_Location then
|
elsif S1 = Standard_Location then
|
return S2 = Standard_Location;
|
return S2 = Standard_Location;
|
|
|
elsif S2 = Standard_Location then
|
elsif S2 = Standard_Location then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
return Get_Code_Unit (N1) = Get_Code_Unit (N2);
|
return Get_Code_Unit (N1) = Get_Code_Unit (N2);
|
end In_Same_Code_Unit;
|
end In_Same_Code_Unit;
|
|
|
---------------------------
|
---------------------------
|
-- In_Same_Extended_Unit --
|
-- In_Same_Extended_Unit --
|
---------------------------
|
---------------------------
|
|
|
function In_Same_Extended_Unit
|
function In_Same_Extended_Unit
|
(N1, N2 : Node_Or_Entity_Id) return Boolean
|
(N1, N2 : Node_Or_Entity_Id) return Boolean
|
is
|
is
|
begin
|
begin
|
return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
|
return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
|
end In_Same_Extended_Unit;
|
end In_Same_Extended_Unit;
|
|
|
function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
|
function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
|
begin
|
begin
|
return Check_Same_Extended_Unit (S1, S2) /= No;
|
return Check_Same_Extended_Unit (S1, S2) /= No;
|
end In_Same_Extended_Unit;
|
end In_Same_Extended_Unit;
|
|
|
-------------------------
|
-------------------------
|
-- In_Same_Source_Unit --
|
-- In_Same_Source_Unit --
|
-------------------------
|
-------------------------
|
|
|
function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
|
function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
|
S1 : constant Source_Ptr := Sloc (N1);
|
S1 : constant Source_Ptr := Sloc (N1);
|
S2 : constant Source_Ptr := Sloc (N2);
|
S2 : constant Source_Ptr := Sloc (N2);
|
|
|
begin
|
begin
|
if S1 = No_Location or else S2 = No_Location then
|
if S1 = No_Location or else S2 = No_Location then
|
return False;
|
return False;
|
|
|
elsif S1 = Standard_Location then
|
elsif S1 = Standard_Location then
|
return S2 = Standard_Location;
|
return S2 = Standard_Location;
|
|
|
elsif S2 = Standard_Location then
|
elsif S2 = Standard_Location then
|
return False;
|
return False;
|
end if;
|
end if;
|
|
|
return Get_Source_Unit (N1) = Get_Source_Unit (N2);
|
return Get_Source_Unit (N1) = Get_Source_Unit (N2);
|
end In_Same_Source_Unit;
|
end In_Same_Source_Unit;
|
|
|
-----------------------------
|
-----------------------------
|
-- Increment_Serial_Number --
|
-- Increment_Serial_Number --
|
-----------------------------
|
-----------------------------
|
|
|
function Increment_Serial_Number return Nat is
|
function Increment_Serial_Number return Nat is
|
TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
|
TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
|
begin
|
begin
|
TSN := TSN + 1;
|
TSN := TSN + 1;
|
return TSN;
|
return TSN;
|
end Increment_Serial_Number;
|
end Increment_Serial_Number;
|
|
|
----------------
|
----------------
|
-- Initialize --
|
-- Initialize --
|
----------------
|
----------------
|
|
|
procedure Initialize is
|
procedure Initialize is
|
begin
|
begin
|
Linker_Option_Lines.Init;
|
Linker_Option_Lines.Init;
|
Load_Stack.Init;
|
Load_Stack.Init;
|
Units.Init;
|
Units.Init;
|
Compilation_Switches.Init;
|
Compilation_Switches.Init;
|
end Initialize;
|
end Initialize;
|
|
|
---------------
|
---------------
|
-- Is_Loaded --
|
-- Is_Loaded --
|
---------------
|
---------------
|
|
|
function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
|
function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
|
begin
|
begin
|
for Unum in Units.First .. Units.Last loop
|
for Unum in Units.First .. Units.Last loop
|
if Uname = Unit_Name (Unum) then
|
if Uname = Unit_Name (Unum) then
|
return True;
|
return True;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Is_Loaded;
|
end Is_Loaded;
|
|
|
---------------
|
---------------
|
-- Last_Unit --
|
-- Last_Unit --
|
---------------
|
---------------
|
|
|
function Last_Unit return Unit_Number_Type is
|
function Last_Unit return Unit_Number_Type is
|
begin
|
begin
|
return Units.Last;
|
return Units.Last;
|
end Last_Unit;
|
end Last_Unit;
|
|
|
----------
|
----------
|
-- List --
|
-- List --
|
----------
|
----------
|
|
|
procedure List (File_Names_Only : Boolean := False) is separate;
|
procedure List (File_Names_Only : Boolean := False) is separate;
|
|
|
----------
|
----------
|
-- Lock --
|
-- Lock --
|
----------
|
----------
|
|
|
procedure Lock is
|
procedure Lock is
|
begin
|
begin
|
Linker_Option_Lines.Locked := True;
|
Linker_Option_Lines.Locked := True;
|
Load_Stack.Locked := True;
|
Load_Stack.Locked := True;
|
Units.Locked := True;
|
Units.Locked := True;
|
Linker_Option_Lines.Release;
|
Linker_Option_Lines.Release;
|
Load_Stack.Release;
|
Load_Stack.Release;
|
Units.Release;
|
Units.Release;
|
end Lock;
|
end Lock;
|
|
|
---------------
|
---------------
|
-- Num_Units --
|
-- Num_Units --
|
---------------
|
---------------
|
|
|
function Num_Units return Nat is
|
function Num_Units return Nat is
|
begin
|
begin
|
return Int (Units.Last) - Int (Main_Unit) + 1;
|
return Int (Units.Last) - Int (Main_Unit) + 1;
|
end Num_Units;
|
end Num_Units;
|
|
|
-----------------
|
-----------------
|
-- Remove_Unit --
|
-- Remove_Unit --
|
-----------------
|
-----------------
|
|
|
procedure Remove_Unit (U : Unit_Number_Type) is
|
procedure Remove_Unit (U : Unit_Number_Type) is
|
begin
|
begin
|
if U = Units.Last then
|
if U = Units.Last then
|
Units.Decrement_Last;
|
Units.Decrement_Last;
|
end if;
|
end if;
|
end Remove_Unit;
|
end Remove_Unit;
|
|
|
----------------------------------
|
----------------------------------
|
-- Replace_Linker_Option_String --
|
-- Replace_Linker_Option_String --
|
----------------------------------
|
----------------------------------
|
|
|
procedure Replace_Linker_Option_String
|
procedure Replace_Linker_Option_String
|
(S : String_Id; Match_String : String)
|
(S : String_Id; Match_String : String)
|
is
|
is
|
begin
|
begin
|
if Match_String'Length > 0 then
|
if Match_String'Length > 0 then
|
for J in 1 .. Linker_Option_Lines.Last loop
|
for J in 1 .. Linker_Option_Lines.Last loop
|
String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
|
String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
|
|
|
if Match_String = Name_Buffer (1 .. Match_String'Length) then
|
if Match_String = Name_Buffer (1 .. Match_String'Length) then
|
Linker_Option_Lines.Table (J).Option := S;
|
Linker_Option_Lines.Table (J).Option := S;
|
return;
|
return;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
Store_Linker_Option_String (S);
|
Store_Linker_Option_String (S);
|
end Replace_Linker_Option_String;
|
end Replace_Linker_Option_String;
|
|
|
----------
|
----------
|
-- Sort --
|
-- Sort --
|
----------
|
----------
|
|
|
procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
|
procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
|
|
|
------------------------------
|
------------------------------
|
-- Store_Compilation_Switch --
|
-- Store_Compilation_Switch --
|
------------------------------
|
------------------------------
|
|
|
procedure Store_Compilation_Switch (Switch : String) is
|
procedure Store_Compilation_Switch (Switch : String) is
|
begin
|
begin
|
if Switch_Storing_Enabled then
|
if Switch_Storing_Enabled then
|
Compilation_Switches.Increment_Last;
|
Compilation_Switches.Increment_Last;
|
Compilation_Switches.Table (Compilation_Switches.Last) :=
|
Compilation_Switches.Table (Compilation_Switches.Last) :=
|
new String'(Switch);
|
new String'(Switch);
|
|
|
-- Fix up --RTS flag which has been transformed by the gcc driver
|
-- Fix up --RTS flag which has been transformed by the gcc driver
|
-- into -fRTS
|
-- into -fRTS
|
|
|
if Switch'Last >= Switch'First + 4
|
if Switch'Last >= Switch'First + 4
|
and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
|
and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
|
then
|
then
|
Compilation_Switches.Table
|
Compilation_Switches.Table
|
(Compilation_Switches.Last) (Switch'First + 1) := '-';
|
(Compilation_Switches.Last) (Switch'First + 1) := '-';
|
end if;
|
end if;
|
end if;
|
end if;
|
end Store_Compilation_Switch;
|
end Store_Compilation_Switch;
|
|
|
--------------------------------
|
--------------------------------
|
-- Store_Linker_Option_String --
|
-- Store_Linker_Option_String --
|
--------------------------------
|
--------------------------------
|
|
|
procedure Store_Linker_Option_String (S : String_Id) is
|
procedure Store_Linker_Option_String (S : String_Id) is
|
begin
|
begin
|
Linker_Option_Lines.Increment_Last;
|
Linker_Option_Lines.Increment_Last;
|
Linker_Option_Lines.Table (Linker_Option_Lines.Last) :=
|
Linker_Option_Lines.Table (Linker_Option_Lines.Last) :=
|
(Option => S, Unit => Current_Sem_Unit);
|
(Option => S, Unit => Current_Sem_Unit);
|
end Store_Linker_Option_String;
|
end Store_Linker_Option_String;
|
|
|
-------------------------------
|
-------------------------------
|
-- Synchronize_Serial_Number --
|
-- Synchronize_Serial_Number --
|
-------------------------------
|
-------------------------------
|
|
|
procedure Synchronize_Serial_Number is
|
procedure Synchronize_Serial_Number is
|
TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
|
TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
|
begin
|
begin
|
TSN := TSN + 1;
|
TSN := TSN + 1;
|
end Synchronize_Serial_Number;
|
end Synchronize_Serial_Number;
|
|
|
---------------
|
---------------
|
-- Tree_Read --
|
-- Tree_Read --
|
---------------
|
---------------
|
|
|
procedure Tree_Read is
|
procedure Tree_Read is
|
N : Nat;
|
N : Nat;
|
S : String_Ptr;
|
S : String_Ptr;
|
|
|
begin
|
begin
|
Units.Tree_Read;
|
Units.Tree_Read;
|
|
|
-- Read Compilation_Switches table. First release the memory occupied
|
-- Read Compilation_Switches table. First release the memory occupied
|
-- by the previously loaded switches.
|
-- by the previously loaded switches.
|
|
|
for J in Compilation_Switches.First .. Compilation_Switches.Last loop
|
for J in Compilation_Switches.First .. Compilation_Switches.Last loop
|
Free (Compilation_Switches.Table (J));
|
Free (Compilation_Switches.Table (J));
|
end loop;
|
end loop;
|
|
|
Tree_Read_Int (N);
|
Tree_Read_Int (N);
|
Compilation_Switches.Set_Last (N);
|
Compilation_Switches.Set_Last (N);
|
|
|
for J in 1 .. N loop
|
for J in 1 .. N loop
|
Tree_Read_Str (S);
|
Tree_Read_Str (S);
|
Compilation_Switches.Table (J) := S;
|
Compilation_Switches.Table (J) := S;
|
end loop;
|
end loop;
|
end Tree_Read;
|
end Tree_Read;
|
|
|
----------------
|
----------------
|
-- Tree_Write --
|
-- Tree_Write --
|
----------------
|
----------------
|
|
|
procedure Tree_Write is
|
procedure Tree_Write is
|
begin
|
begin
|
Units.Tree_Write;
|
Units.Tree_Write;
|
|
|
-- Write Compilation_Switches table
|
-- Write Compilation_Switches table
|
|
|
Tree_Write_Int (Compilation_Switches.Last);
|
Tree_Write_Int (Compilation_Switches.Last);
|
|
|
for J in 1 .. Compilation_Switches.Last loop
|
for J in 1 .. Compilation_Switches.Last loop
|
Tree_Write_Str (Compilation_Switches.Table (J));
|
Tree_Write_Str (Compilation_Switches.Table (J));
|
end loop;
|
end loop;
|
end Tree_Write;
|
end Tree_Write;
|
|
|
------------
|
------------
|
-- Unlock --
|
-- Unlock --
|
------------
|
------------
|
|
|
procedure Unlock is
|
procedure Unlock is
|
begin
|
begin
|
Linker_Option_Lines.Locked := False;
|
Linker_Option_Lines.Locked := False;
|
Load_Stack.Locked := False;
|
Load_Stack.Locked := False;
|
Units.Locked := False;
|
Units.Locked := False;
|
end Unlock;
|
end Unlock;
|
|
|
-----------------
|
-----------------
|
-- Version_Get --
|
-- Version_Get --
|
-----------------
|
-----------------
|
|
|
function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
|
function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
|
begin
|
begin
|
return Get_Hex_String (Units.Table (U).Version);
|
return Get_Hex_String (Units.Table (U).Version);
|
end Version_Get;
|
end Version_Get;
|
|
|
------------------------
|
------------------------
|
-- Version_Referenced --
|
-- Version_Referenced --
|
------------------------
|
------------------------
|
|
|
procedure Version_Referenced (S : String_Id) is
|
procedure Version_Referenced (S : String_Id) is
|
begin
|
begin
|
Version_Ref.Append (S);
|
Version_Ref.Append (S);
|
end Version_Referenced;
|
end Version_Referenced;
|
|
|
end Lib;
|
end Lib;
|
|
|