From: Bob Duff Date: Fri, 22 Oct 2021 16:00:38 +0000 (-0400) Subject: [Ada] Follow-on cleanups for Uint fields X-Git-Tag: basepoints/gcc-13~3626 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42b39995546a63fe7d9313744cdab21f356346b2;p=thirdparty%2Fgcc.git [Ada] Follow-on cleanups for Uint fields gcc/ada/ * freeze.adb (Freeze_Fixed_Point_Type): Remove previously-inserted test for Uint_0; no longer needed. * gen_il-gen.ads: Improve comments. * repinfo.adb (Rep_Value): Use Ubool type for B. * repinfo.ads (Node_Ref): Use Unegative type. (Node_Ref_Or_Val): Document that values of this type can be No_Uint. * exp_disp.adb (Make_Disp_Requeue_Body): Minor comment fix. * sem_ch3.adb: Likewise. * sem_ch8.adb: Likewise. * sinfo-utils.adb (End_Location): End_Span can never be No_Uint, so remove the "if No (L)" test. * uintp.adb (Image_String): Use "for ... of" loop. * uintp.ads (Unegative): New type for negative integers. We give it a long name (unlike Unat and Upos) because it is rarely used. --- diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 6ade54be177b..88f11b28dd52 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -3037,7 +3037,7 @@ package body Exp_Disp is begin pragma Assert (not Restriction_Active (No_Dispatching_Calls)); - -- Null body is generated for interface types and non-concurrent + -- Null body is generated for interface types and nonconcurrent -- tagged types. if Is_Interface (Typ) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index d57f6d50312a..97a51db9d4b5 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -9500,9 +9500,7 @@ package body Freeze is Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ)); begin - if Known_RM_Size (Typ) - and then RM_Size (Typ) /= Uint_0 - then + if Known_RM_Size (Typ) then if RM_Size (Typ) < Minsiz then Error_Msg_Uint_1 := RM_Size (Typ); Error_Msg_Uint_2 := Minsiz; diff --git a/gcc/ada/gen_il-gen.ads b/gcc/ada/gen_il-gen.ads index 1d24ebf10928..56b06064f3e2 100644 --- a/gcc/ada/gen_il-gen.ads +++ b/gcc/ada/gen_il-gen.ads @@ -204,9 +204,22 @@ package Gen_IL.Gen is -- Gen_IL.Fields, and delete all occurrences from Gen_IL.Gen.Gen_Entities. -- If a field is not set, it is initialized by default to whatever value is - -- represented by all-zero bits, with two exceptions: Elist fields default - -- to No_Elist, and Uint fields default to Uint_0. In retrospect, it would - -- have been better to use No_Uint instead of Uint_0. + -- represented by all-zero bits, with some exceptions. This means Flags are + -- initialized to False, Node_Ids and List_Ids are initialized to Empty, + -- and enumeration fields are initialized to 'First of the type (assuming + -- there is no representation clause). + -- + -- Elists default to No_Elist. + -- + -- Fields of type Uint (but not its subtypes) are initialized to No_Uint. + -- Fields of subtypes Valid_Uint, Unat, Upos, Nonzero_Uint, and Ureal have + -- no default; it is an error to call a getter before calling the setter. + -- Likewise, other types whose range does not include zero have no default + -- (see package Types for the ranges). + -- + -- If a node is created by a function in Nmake, then the defaults are + -- different from what is specified above. The parameters of Make_... + -- functions can have defaults specified; see Create_Syntactic_Field. procedure Create_Node_Union_Type (T : Abstract_Node; Children : Type_Array); diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index f1ab718baf0b..b86885cec6c0 100644 --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -2120,7 +2120,7 @@ package body Repinfo is function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is - function B (Val : Boolean) return Uint; + function B (Val : Boolean) return Ubool; -- Returns Uint_0 for False, Uint_1 for True function T (Val : Node_Ref_Or_Val) return Boolean; @@ -2141,7 +2141,7 @@ package body Repinfo is -- B -- ------- - function B (Val : Boolean) return Uint is + function B (Val : Boolean) return Ubool is begin if Val then return Uint_1; diff --git a/gcc/ada/repinfo.ads b/gcc/ada/repinfo.ads index 606bba45cd1a..d07208ed8a35 100644 --- a/gcc/ada/repinfo.ads +++ b/gcc/ada/repinfo.ads @@ -118,12 +118,12 @@ package Repinfo is -- this field is done only in -gnatR3 mode, and in other modes, the value -- is set to Uint_Minus_1. - subtype Node_Ref is Uint; + subtype Node_Ref is Unegative; -- Subtype used for negative Uint values used to represent nodes subtype Node_Ref_Or_Val is Uint; - -- Subtype used for values that can either be a Node_Ref (negative) - -- or a value (non-negative) + -- Subtype used for values that can be a Node_Ref (negative) or a value + -- (non-negative) or No_Uint. type TCode is range 0 .. 27; -- Type used on Ada side to represent DEFTREECODE values defined in @@ -306,7 +306,7 @@ package Repinfo is -- In the case of components, if the location of the component is static, -- then all four fields (Component_Bit_Offset, Normalized_Position, Esize, -- and Normalized_First_Bit) are set to appropriate values. In the case of - -- a non-static component location, Component_Bit_Offset is not used and + -- a nonstatic component location, Component_Bit_Offset is not used and -- is left set to Unknown. Normalized_Position and Normalized_First_Bit -- are set appropriately. diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index b8ff3ce6ab4c..152ef83387dc 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -21301,7 +21301,7 @@ package body Sem_Ch3 is goto Leave; end; - -- For non-concurrent types, transfer explicit primitives, but + -- For nonconcurrent types, transfer explicit primitives, but -- omit those inherited from the parent of the private view -- since they will be re-inherited later on. diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 3590e5557c5c..686d4378f8cc 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -9236,7 +9236,7 @@ package body Sem_Ch8 is if Ekind (S) = E_Void then null; - -- Set scope depth if not a non-concurrent type, and we have not yet set + -- Set scope depth if not a nonconcurrent type, and we have not yet set -- the scope depth. This means that we have the first occurrence of the -- scope, and this is where the depth is set. diff --git a/gcc/ada/sinfo-utils.adb b/gcc/ada/sinfo-utils.adb index 33247e21ca74..ad8606fd3ed2 100644 --- a/gcc/ada/sinfo-utils.adb +++ b/gcc/ada/sinfo-utils.adb @@ -189,13 +189,9 @@ package body Sinfo.Utils is ------------------ function End_Location (N : Node_Id) return Source_Ptr is - L : constant Uint := End_Span (N); + L : constant Valid_Uint := End_Span (N); begin - if No (L) then - return No_Location; - else - return Source_Ptr (Int (Sloc (N)) + UI_To_Int (L)); - end if; + return Source_Ptr (Int (Sloc (N)) + UI_To_Int (L)); end End_Location; -------------------- diff --git a/gcc/ada/uintp.adb b/gcc/ada/uintp.adb index 5d1dec1e1bdc..06f668067024 100644 --- a/gcc/ada/uintp.adb +++ b/gcc/ada/uintp.adb @@ -380,8 +380,8 @@ package body Uintp is procedure Image_String (S : String) is begin - for X in S'Range loop - Image_Char (S (X)); + for X of S loop + Image_Char (X); end loop; end Image_String; diff --git a/gcc/ada/uintp.ads b/gcc/ada/uintp.ads index d9f1f8f70fbb..08f673879b82 100644 --- a/gcc/ada/uintp.ads +++ b/gcc/ada/uintp.ads @@ -104,6 +104,7 @@ package Uintp is subtype Unat is Valid_Uint with Predicate => Unat >= Uint_0; -- natural subtype Upos is Valid_Uint with Predicate => Upos >= Uint_1; -- positive subtype Nonzero_Uint is Valid_Uint with Predicate => Nonzero_Uint /= Uint_0; + subtype Unegative is Valid_Uint with Predicate => Unegative < Uint_0; subtype Ubool is Valid_Uint with Predicate => Ubool in Uint_0 | Uint_1; subtype Opt_Ubool is Uint with Predicate => No (Opt_Ubool) or else Opt_Ubool in Ubool;