public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Small cleanup in body of System.Value_R
Date: Mon, 5 Sep 2022 09:26:08 +0200	[thread overview]
Message-ID: <20220905072608.GA1174745@poulhies-Precision-5550> (raw)

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

This is mostly stylistic but also adds a couple of missing comments.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/s-valuer.adb (Scan_Decimal_Digits): Consistently avoid
	initializing local variables.
	(Scan_Integral_Digits): Likewise.
	(Scan_Raw_Real): Likewise and add a couple of comments.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2934 bytes --]

diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -184,7 +184,7 @@ package body System.Value_R is
       UmaxB : constant Uns := Precision_Limit / Uns (Base);
       --  Numbers bigger than UmaxB overflow if multiplied by base
 
-      Precision_Limit_Reached : Boolean := False;
+      Precision_Limit_Reached : Boolean;
       --  Set to True if addition of a digit will cause Value to be superior
       --  to Precision_Limit.
 
@@ -198,7 +198,7 @@ package body System.Value_R is
       Temp : Uns;
       --  Temporary
 
-      Trailing_Zeros : Natural := 0;
+      Trailing_Zeros : Natural;
       --  Number of trailing zeros at a given point
 
    begin
@@ -209,12 +209,17 @@ package body System.Value_R is
          Precision_Limit_Reached := True;
       else
          Extra := 0;
+         Precision_Limit_Reached := False;
       end if;
 
       if Round then
          Precision_Limit_Just_Reached := False;
       end if;
 
+      --  Initialize trailing zero counter
+
+      Trailing_Zeros := 0;
+
       --  The function precondition is that the first character is a valid
       --  digit.
 
@@ -362,7 +367,7 @@ package body System.Value_R is
       UmaxB : constant Uns := Precision_Limit / Uns (Base);
       --  Numbers bigger than UmaxB overflow if multiplied by base
 
-      Precision_Limit_Reached : Boolean := False;
+      Precision_Limit_Reached : Boolean;
       --  Set to True if addition of a digit will cause Value to be superior
       --  to Precision_Limit.
 
@@ -383,6 +388,8 @@ package body System.Value_R is
       Scale := 0;
       Extra := 0;
 
+      Precision_Limit_Reached := False;
+
       if Round then
          Precision_Limit_Just_Reached := False;
       end if;
@@ -494,28 +501,32 @@ package body System.Value_R is
       After_Point : Boolean;
       --  True if a decimal should be parsed
 
-      Base_Char : Character := ASCII.NUL;
-      --  Character used to set the base. If Nul this means that default
+      Base_Char : Character;
+      --  Character used to set the base. If it is Nul, this means that default
       --  base is used.
 
-      Base_Violation : Boolean := False;
+      Base_Violation : Boolean;
       --  If True some digits where not in the base. The real is still scanned
       --  till the end even if an error will be raised.
 
+      Expon : Integer;
+      --  Exponent as an Integer
+
       Index : Integer;
       --  Local copy of string pointer
 
       Start : Positive;
+      --  Index of the first non-blank character
 
       Value : Uns;
       --  Mantissa as an Integer
 
-      Expon : Integer;
-
    begin
       --  The default base is 10
 
-      Base := 10;
+      Base           := 10;
+      Base_Char      := ASCII.NUL;
+      Base_Violation := False;
 
       --  We do not tolerate strings with Str'Last = Positive'Last
 



                 reply	other threads:[~2022-09-05  7:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220905072608.GA1174745@poulhies-Precision-5550 \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).