]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Ada 2022 Image attribute bugs
authorSteve Baird <baird@adacore.com>
Fri, 11 Nov 2022 01:15:33 +0000 (17:15 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 21 Nov 2022 10:10:33 +0000 (11:10 +0100)
Two issues. First, the two procedures
Ada.Strings.Text_Buffers.Output_Mapping.[Wide_]Wide_Put each correctly
call Encode, but that call was missing from the corresponding Put procedure.
Second, if a record type contains an array-valued Data component as well as
both a Max_Length and Current_Length component, then the slice
Data (Current_Length + 1 .. Max_Length) should usually be treated like
uninitialized data. It should not participate in things like equality
comparisons. In particular, it should not participate in 'Image results.
To accomplish this, such a type usually ought to have a Put_Image aspect
specification. This Put_Image aspect specification was missing for the
three Super_String types declared in the
Ada.Strings.[Wide_[Wide_]]Superbounded packages.

gcc/ada/
* libgnat/a-sttebu.adb (Put): Add missing call to Encode.
* libgnat/a-strsup.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-strsup.adb (Put_Image): New procedure.
* libgnat/a-stwisu.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-stwisu.adb (Put_Image): New procedure.
* libgnat/a-stzsup.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-stzsup.adb (Put_Image): New procedure.

gcc/ada/libgnat/a-strsup.adb
gcc/ada/libgnat/a-strsup.ads
gcc/ada/libgnat/a-sttebu.adb
gcc/ada/libgnat/a-stwisu.adb
gcc/ada/libgnat/a-stwisu.ads
gcc/ada/libgnat/a-stzsup.adb
gcc/ada/libgnat/a-stzsup.ads

index 831a18e1e19a4e1602108d325e3afbc82f713a59..0210b45c4c7c7edc91586206fd8a752a70995362 100644 (file)
@@ -303,6 +303,17 @@ package body Ada.Strings.Superbounded with SPARK_Mode is
       return Left <= Super_To_String (Right);
    end Less_Or_Equal;
 
+   ---------------
+   -- Put_Image --
+   ---------------
+
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String) is
+   begin
+      String'Put_Image (S, Super_To_String (Source));
+   end Put_Image;
+
    ----------------------
    -- Set_Super_String --
    ----------------------
index 416fa7bb06a98b1acf218ee0a8ef1cb778a1b78b..600f097c2bfe7e2060f55e78439ccd26184f7e14 100644 (file)
@@ -49,6 +49,7 @@ pragma Assertion_Policy (Pre            => Ignore,
 
 with Ada.Strings.Maps; use type Ada.Strings.Maps.Character_Mapping_Function;
 with Ada.Strings.Search;
+with Ada.Strings.Text_Buffers;
 
 package Ada.Strings.Superbounded with SPARK_Mode is
    pragma Preelaborate;
@@ -69,7 +70,8 @@ package Ada.Strings.Superbounded with SPARK_Mode is
    with
      Predicate =>
        Current_Length <= Max_Length
-         and then Data (1 .. Current_Length)'Initialized;
+         and then Data (1 .. Current_Length)'Initialized,
+     Put_Image => Put_Image;
 
    --  The subprograms defined for Super_String are similar to those
    --  defined for Bounded_String, except that they have different names, so
@@ -2695,6 +2697,10 @@ package Ada.Strings.Superbounded with SPARK_Mode is
                        - (Item.Max_Length - K) mod Super_Length (Item)))),
      Global         => null;
 
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String);
+
 private
       --  Pragma Inline declarations
 
index d992fee9f045a42ed561766db5020d4cf1bae018..acca2923443ac8e4b1895e0833fb84da48e07874 100644 (file)
@@ -29,6 +29,7 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with Ada.Strings.UTF_Encoding.Strings;
 with Ada.Strings.UTF_Encoding.Wide_Strings;
 with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
 
@@ -59,7 +60,7 @@ package body Ada.Strings.Text_Buffers is
 
       procedure Put (Buffer : in out Buffer_Type; Item : String) is
       begin
-         Put_UTF_8 (Buffer, Item);
+         Put_UTF_8 (Buffer, UTF_Encoding.Strings.Encode (Item));
       end Put;
 
       procedure Wide_Put (Buffer : in out Buffer_Type; Item : Wide_String) is
index d325676edf9333e278eb6f4312d9968c293decaf..cf27ca9f190d1fd7d76029cf1f4389d735d5fb5e 100644 (file)
@@ -297,6 +297,17 @@ package body Ada.Strings.Wide_Superbounded is
       return Left <= Right.Data (1 .. Right.Current_Length);
    end Less_Or_Equal;
 
+   ---------------
+   -- Put_Image --
+   ---------------
+
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String) is
+   begin
+      Wide_String'Put_Image (S, Super_To_String (Source));
+   end Put_Image;
+
    ----------------------
    -- Set_Super_String --
    ----------------------
index c22c2a238500954e2f6af8f72998a890fc088687..7437cbda22423860f7b56eeca094c22b8e4f5bb0 100644 (file)
@@ -37,6 +37,7 @@
 --  Strings.Wide_Bounded.Generic_Bounded_Length use this type with
 --  an appropriate discriminant value set.
 
+with Ada.Strings.Text_Buffers;
 with Ada.Strings.Wide_Maps;
 
 package Ada.Strings.Wide_Superbounded is
@@ -54,7 +55,8 @@ package Ada.Strings.Wide_Superbounded is
       --  no longer necessary, because we now special-case this type in the
       --  compiler, so "=" composes properly for descendants of this type.
       --  Leaving it out is more efficient.
-   end record;
+   end record
+   with Put_Image => Put_Image;
 
    --  The subprograms defined for Super_String are similar to those defined
    --  for Bounded_Wide_String, except that they have different names, so that
@@ -477,6 +479,10 @@ package Ada.Strings.Wide_Superbounded is
       Item  : Super_String;
       Drop  : Truncation := Error) return Super_String;
 
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String);
+
 private
       --  Pragma Inline declarations
 
index 6153bbe392f8d69a56a25ebcc41796979baf2de7..a4fa9968befe8d49502afb989cf7d18580a3863e 100644 (file)
@@ -297,6 +297,17 @@ package body Ada.Strings.Wide_Wide_Superbounded is
       return Left <= Right.Data (1 .. Right.Current_Length);
    end Less_Or_Equal;
 
+   ---------------
+   -- Put_Image --
+   ---------------
+
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String) is
+   begin
+      Wide_Wide_String'Put_Image (S, Super_To_String (Source));
+   end Put_Image;
+
    ----------------------
    -- Set_Super_String --
    ----------------------
index 148b972b30d0b3f54b597953fe22a0b581c009b5..b50d21ad6ae8b54a8be642408a1831b3fcb3e7c2 100644 (file)
@@ -37,6 +37,7 @@
 --  Strings.Wide_Wide_Bounded.Generic_Bounded_Length use this type with
 --  an appropriate discriminant value set.
 
+with Ada.Strings.Text_Buffers;
 with Ada.Strings.Wide_Wide_Maps;
 
 package Ada.Strings.Wide_Wide_Superbounded is
@@ -55,7 +56,8 @@ package Ada.Strings.Wide_Wide_Superbounded is
       --  no longer necessary, because we now special-case this type in the
       --  compiler, so "=" composes properly for descendants of this type.
       --  Leaving it out is more efficient.
-   end record;
+   end record
+   with Put_Image => Put_Image;
 
    --  The subprograms defined for Super_String are similar to those defined
    --  for Bounded_Wide_Wide_String, except that they have different names, so
@@ -486,6 +488,10 @@ package Ada.Strings.Wide_Wide_Superbounded is
       Item  : Super_String;
       Drop  : Truncation := Error) return Super_String;
 
+   procedure Put_Image
+     (S      : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
+      Source : Super_String);
+
 private
       --  Pragma Inline declarations
 
This page took 0.075614 seconds and 5 git commands to generate.