aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2024-03-07 07:43:26 -0500
committerMarc Poulhiès <poulhies@adacore.com>2024-05-17 10:21:01 +0200
commita0c87f1bb76e8afa22e0b585441dff612b90e88f (patch)
tree4e37b9aca696d43ed23e78294992122384500560 /gcc/ada
parent14aef595f01707c54926788346960b909ebea3b7 (diff)
downloadgcc-a0c87f1bb76e8afa22e0b585441dff612b90e88f.zip
gcc-a0c87f1bb76e8afa22e0b585441dff612b90e88f.tar.gz
gcc-a0c87f1bb76e8afa22e0b585441dff612b90e88f.tar.bz2
ada: gnatbind-related cleanups
This patch cleans up some things noticed while working on gnatbind. No change in behavior yet. gcc/ada/ * ali-util.adb (Read_Withed_ALIs): Minor reformatting. * bindo-units.adb (Corresponding_Body): Add assert. (Corresponding_Spec): Likewise. * uname.adb: Clean up assertions, use available functions. Get_Spec_Name/Get_Body_Name can assert that N obeys the conventions for Unit_Name_Type (end in "%s" or "%b").
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ali-util.adb4
-rw-r--r--gcc/ada/bindo-units.adb8
-rw-r--r--gcc/ada/uname.adb61
3 files changed, 28 insertions, 45 deletions
diff --git a/gcc/ada/ali-util.adb b/gcc/ada/ali-util.adb
index fe0af74..61dddb9 100644
--- a/gcc/ada/ali-util.adb
+++ b/gcc/ada/ali-util.adb
@@ -161,9 +161,7 @@ package body ALI.Util is
-- Process all dependent units
for U in ALIs.Table (Id).First_Unit .. ALIs.Table (Id).Last_Unit loop
- for
- W in Units.Table (U).First_With .. Units.Table (U).Last_With
- loop
+ for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
Afile := Withs.Table (W).Afile;
-- Only process if not a generic (Afile /= No_File) and if
diff --git a/gcc/ada/bindo-units.adb b/gcc/ada/bindo-units.adb
index 0fbe8e9..0acc661 100644
--- a/gcc/ada/bindo-units.adb
+++ b/gcc/ada/bindo-units.adb
@@ -103,7 +103,9 @@ package body Bindo.Units is
begin
pragma Assert (U_Rec.Utype = Is_Spec);
- return U_Id - 1;
+ return Result : constant Unit_Id := U_Id - 1 do
+ pragma Assert (ALI.Units.Table (Result).Utype = Is_Body);
+ end return;
end Corresponding_Body;
------------------------
@@ -117,7 +119,9 @@ package body Bindo.Units is
begin
pragma Assert (U_Rec.Utype = Is_Body);
- return U_Id + 1;
+ return Result : constant Unit_Id := U_Id + 1 do
+ pragma Assert (ALI.Units.Table (Result).Utype = Is_Spec);
+ end return;
end Corresponding_Spec;
------------------------
diff --git a/gcc/ada/uname.adb b/gcc/ada/uname.adb
index 0857478..dbb08b8 100644
--- a/gcc/ada/uname.adb
+++ b/gcc/ada/uname.adb
@@ -50,14 +50,8 @@ package body Uname is
Buffer : Bounded_String;
begin
Append (Buffer, N);
-
- pragma Assert
- (Buffer.Length > 2
- and then Buffer.Chars (Buffer.Length - 1) = '%'
- and then Buffer.Chars (Buffer.Length) = 's');
-
+ pragma Assert (Is_Spec_Name (N));
Buffer.Chars (Buffer.Length) := 'b';
-
return Name_Find (Buffer);
end Get_Body_Name;
@@ -160,14 +154,8 @@ package body Uname is
Buffer : Bounded_String;
begin
Append (Buffer, N);
-
- pragma Assert
- (Buffer.Length > 2
- and then Buffer.Chars (Buffer.Length - 1) = '%'
- and then Buffer.Chars (Buffer.Length) = 'b');
-
+ pragma Assert (Is_Body_Name (N));
Buffer.Chars (Buffer.Length) := 's';
-
return Name_Find (Buffer);
end Get_Spec_Name;
@@ -416,6 +404,9 @@ package body Uname is
Suffix : Boolean := True)
is
begin
+ pragma Assert (Buf.Chars (1) /= '"');
+ pragma Assert (Is_Body_Name (N) or else Is_Spec_Name (N));
+
Buf.Length := 0;
Append_Decoded (Buf, N);
@@ -424,17 +415,11 @@ package body Uname is
-- (lower case) 's'/'b', and before appending (lower case) "spec" or
-- "body".
- pragma Assert (Buf.Length >= 3);
- pragma Assert (Buf.Chars (1) /= '"');
- pragma Assert (Buf.Chars (Buf.Length) in 's' | 'b');
-
declare
S : constant String :=
(if Buf.Chars (Buf.Length) = 's' then " (spec)" else " (body)");
begin
- Buf.Length := Buf.Length - 1; -- remove 's' or 'b'
- pragma Assert (Buf.Chars (Buf.Length) = '%');
- Buf.Length := Buf.Length - 1; -- remove '%'
+ Buf.Length := Buf.Length - 2; -- remove "%s" or "%b"
Set_Casing (Buf, Identifier_Casing (Source_Index (Main_Unit)));
if Suffix then
@@ -474,9 +459,9 @@ package body Uname is
Buffer : Bounded_String;
begin
Append (Buffer, N);
- return Buffer.Length > 2
- and then Buffer.Chars (Buffer.Length - 1) = '%'
- and then Buffer.Chars (Buffer.Length) = 'b';
+ pragma Assert
+ (Buffer.Length > 2 and then Buffer.Chars (Buffer.Length - 1) = '%');
+ return Buffer.Chars (Buffer.Length) = 'b';
end Is_Body_Name;
-------------------
@@ -535,10 +520,7 @@ package body Uname is
System : constant String := "system";
begin
- if Name = Ada
- or else Name = Interfaces
- or else Name = System
- then
+ if Name in Ada | Interfaces | System then
return True;
end if;
@@ -555,15 +537,14 @@ package body Uname is
-- The following are the predefined renamings
- return
- Name = "calendar"
- or else Name = "machine_code"
- or else Name = "unchecked_conversion"
- or else Name = "unchecked_deallocation"
- or else Name = "direct_io"
- or else Name = "io_exceptions"
- or else Name = "sequential_io"
- or else Name = "text_io";
+ return Name in "calendar"
+ | "machine_code"
+ | "unchecked_conversion"
+ | "unchecked_deallocation"
+ | "direct_io"
+ | "io_exceptions"
+ | "sequential_io"
+ | "text_io";
end Is_Predefined_Unit_Name;
------------------
@@ -574,9 +555,9 @@ package body Uname is
Buffer : Bounded_String;
begin
Append (Buffer, N);
- return Buffer.Length > 2
- and then Buffer.Chars (Buffer.Length - 1) = '%'
- and then Buffer.Chars (Buffer.Length) = 's';
+ pragma Assert
+ (Buffer.Length > 2 and then Buffer.Chars (Buffer.Length - 1) = '%');
+ return Buffer.Chars (Buffer.Length) = 's';
end Is_Spec_Name;
-----------------------