]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Clarify numeric parsing code
authorRonan Desplanques <desplanques@adacore.com>
Mon, 5 May 2025 09:37:00 +0000 (11:37 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 1 Jul 2025 08:29:39 +0000 (10:29 +0200)
This patch rephrases some code in System.Value_R to make it easier to
read.

gcc/ada/ChangeLog:

* libgnat/s-valuer.adb (Scan_Decimal_Digits, Scan_Integral_Digits):
Minor rephrasing.

gcc/ada/libgnat/s-valuer.adb

index faedb884a6abd839f689302e1885846727347efd..25f54079bfec5a69f9e836b816006d2783e3119e 100644 (file)
@@ -236,18 +236,17 @@ package body System.Value_R is
       Digit := As_Digit (Str (Index));
 
       loop
-         --  Check if base is correct. If the base is not specified, the digit
-         --  E or e cannot be considered as a base violation as it can be used
-         --  for exponentiation.
+         --  If the base is not explicitly specified, 'e' or 'E' marks the
+         --  beginning of the exponent part.
+
+         if not Base_Specified and then Digit = E_Digit then
+            return;
+         end if;
+
+         --  Check that Digit is a valid digit with respect to Base
 
          if Digit >= Base then
-            if Base_Specified then
-               Base_Violation := True;
-            elsif Digit = E_Digit then
-               return;
-            else
-               Base_Violation := True;
-            end if;
+            Base_Violation := True;
          end if;
 
          --  If precision limit has been reached, just ignore any remaining
@@ -426,18 +425,17 @@ package body System.Value_R is
       Digit := As_Digit (Str (Index));
 
       loop
-         --  Check if base is correct. If the base is not specified, the digit
-         --  E or e cannot be considered as a base violation as it can be used
-         --  for exponentiation.
+         --  If the base is not explicitly specified, 'e' or 'E' marks the
+         --  beginning of the exponent part.
+
+         if not Base_Specified and then Digit = E_Digit then
+            return;
+         end if;
+
+         --  Check that Digit is a valid digit with respect to Base
 
          if Digit >= Base then
-            if Base_Specified then
-               Base_Violation := True;
-            elsif Digit = E_Digit then
-               return;
-            else
-               Base_Violation := True;
-            end if;
+            Base_Violation := True;
          end if;
 
          --  If precision limit has been reached, just ignore any remaining