aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Desplanques <desplanques@adacore.com>2024-10-24 14:56:15 +0200
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-12 14:00:52 +0100
commitf0a2e57d0525b3372d5de543c77c5e1d7f830c69 (patch)
treefbcb8229ea9e168085108593d31c179fc93a0fad
parent78b52a0aadddbf7de47d686e7c28da3b5ecf4364 (diff)
downloadgcc-f0a2e57d0525b3372d5de543c77c5e1d7f830c69.zip
gcc-f0a2e57d0525b3372d5de543c77c5e1d7f830c69.tar.gz
gcc-f0a2e57d0525b3372d5de543c77c5e1d7f830c69.tar.bz2
ada: Allow file mapping for System's spec
Before this patch, it was never allowed to use pragma Source_File_Name for the spec of System, allegedly because Targparm.Get_Target_Parameters is called before configuration pragmas are processed. Using a mapping file was allowed but did not work correctly. This patch makes mapping files loading happen before the call to Get_Target_Parameters so mapping file can set the file name of System. Also, pragma Source_File_Name is allowed if it confirms a mapping that was previously given in a mapping file, to accommodate GPRbuild that uses both pragmas and mapping files. gcc/ada/ChangeLog: * frontend.adb (Frontend): Move call to Fmap.Initialize ... * gnat1drv.adb (Gnat1drv): ... here. Look up Fmap when loading System. * par-prag.adb (Prag): Allow pragma Source_File_Name for System when it confirms an existing mapping.
-rw-r--r--gcc/ada/frontend.adb7
-rw-r--r--gcc/ada/gnat1drv.adb16
-rw-r--r--gcc/ada/par-prag.adb30
3 files changed, 34 insertions, 19 deletions
diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
index ece0e72..ea0c7b1 100644
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -286,13 +286,6 @@ begin
Save_Config_Cunit_Boolean_Restrictions;
- -- If there was a -gnatem switch, initialize the mappings of unit names
- -- to file names and of file names to path names from the mapping file.
-
- if Mapping_File_Name /= null then
- Fmap.Initialize (Mapping_File_Name.all);
- end if;
-
-- Adjust Optimize_Alignment mode from debug switches if necessary
if Debug_Flag_Dot_SS then
diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb
index b532aef..acc6491 100644
--- a/gcc/ada/gnat1drv.adb
+++ b/gcc/ada/gnat1drv.adb
@@ -1034,6 +1034,13 @@ begin
Sem_Eval.Initialize;
Sem_Type.Init_Interp_Tables;
+ -- If there was a -gnatem switch, initialize the mappings of unit names
+ -- to file names and of file names to path names from the mapping file.
+
+ if Mapping_File_Name /= null then
+ Fmap.Initialize (Mapping_File_Name.all);
+ end if;
+
-- Capture compilation date and time
Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
@@ -1051,9 +1058,12 @@ begin
N : File_Name_Type;
begin
- Name_Buffer (1 .. 10) := "system.ads";
- Name_Len := 10;
- N := Name_Find;
+ N := Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System));
+
+ if N = No_File then
+ N := Name_Find ("system.ads");
+ end if;
+
S := Load_Source_File (N);
-- Failed to read system.ads, fatal error
diff --git a/gcc/ada/par-prag.adb b/gcc/ada/par-prag.adb
index 1a2a7b6..8ea94a3 100644
--- a/gcc/ada/par-prag.adb
+++ b/gcc/ada/par-prag.adb
@@ -29,6 +29,7 @@
-- which require recognition and either partial or complete processing
-- during parsing, and this unit performs this required processing.
+with Fmap;
with Fname.UF; use Fname.UF;
with Osint; use Osint;
with Rident; use Rident;
@@ -754,15 +755,6 @@ begin
and then
Nkind (Selector_Name (Expr1)) = N_Identifier)
then
- if Nkind (Expr1) = N_Identifier
- and then Chars (Expr1) = Name_System
- then
- Error_Msg_N
- ("pragma Source_File_Name may not be used for System",
- Arg1);
- return Error;
- end if;
-
-- Process index argument if present
if Arg_Count = 3 then
@@ -793,6 +785,26 @@ begin
Check_Arg_Is_String_Literal (Arg2);
+ if Nkind (Expr1) = N_Identifier
+ and then Chars (Expr1) = Name_System
+ then
+ -- We allow pragma Source_File_Name on System if it confirms
+ -- a mapping that already exists in Fmap. The goal is to
+ -- accommodate GPRbuild, which uses both a map file and
+ -- a pragma, while at the same time preventing users from
+ -- using just a pragma. Using just a pragma is a problem
+ -- because those are not registered yet when
+ -- Get_Target_Parameters is called.
+ if Fmap.Mapped_File_Name (Name_To_Unit_Name (Name_System))
+ /= Get_Fname (Arg2)
+ then
+ Error_Msg_N
+ ("pragma Source_File_Name may not be used for System",
+ Arg1);
+ return Error;
+ end if;
+ end if;
+
if Chars (Arg2) = Name_Spec_File_Name then
Set_File_Name
(Get_Spec_Name (Unam), Get_Fname (Arg2), Index);