diff options
Diffstat (limited to 'gcc/ada/a-stwisu.adb')
-rw-r--r-- | gcc/ada/a-stwisu.adb | 350 |
1 files changed, 225 insertions, 125 deletions
diff --git a/gcc/ada/a-stwisu.adb b/gcc/ada/a-stwisu.adb index ebf15f71264..bdaac0b64df 100644 --- a/gcc/ada/a-stwisu.adb +++ b/gcc/ada/a-stwisu.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2003 Free Software Foundation, Inc. -- +-- Copyright (C) 2003-2005 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -42,8 +42,7 @@ package body Ada.Strings.Wide_Superbounded is function Concat (Left : Super_String; - Right : Super_String) - return Super_String + Right : Super_String) return Super_String is Result : Super_String (Left.Max_Length); Llen : constant Natural := Left.Current_Length; @@ -64,8 +63,7 @@ package body Ada.Strings.Wide_Superbounded is function Concat (Left : Super_String; - Right : Wide_String) - return Super_String + Right : Wide_String) return Super_String is Result : Super_String (Left.Max_Length); Llen : constant Natural := Left.Current_Length; @@ -85,8 +83,7 @@ package body Ada.Strings.Wide_Superbounded is function Concat (Left : Wide_String; - Right : Super_String) - return Super_String + Right : Super_String) return Super_String is Result : Super_String (Right.Max_Length); Llen : constant Natural := Left'Length; @@ -107,8 +104,7 @@ package body Ada.Strings.Wide_Superbounded is function Concat (Left : Super_String; - Right : Wide_Character) - return Super_String + Right : Wide_Character) return Super_String is Result : Super_String (Left.Max_Length); Llen : constant Natural := Left.Current_Length; @@ -127,8 +123,7 @@ package body Ada.Strings.Wide_Superbounded is function Concat (Left : Wide_Character; - Right : Super_String) - return Super_String + Right : Super_String) return Super_String is Result : Super_String (Right.Max_Length); Rlen : constant Natural := Right.Current_Length; @@ -149,22 +144,29 @@ package body Ada.Strings.Wide_Superbounded is -- Equal -- ----------- - function "=" (Left, Right : Super_String) return Boolean is + function "=" + (Left : Super_String; + Right : Super_String) return Boolean + is begin return Left.Current_Length = Right.Current_Length and then Left.Data (1 .. Left.Current_Length) = Right.Data (1 .. Right.Current_Length); end "="; - function Equal (Left : Super_String; Right : Wide_String) - return Boolean is + function Equal + (Left : Super_String; + Right : Wide_String) return Boolean + is begin return Left.Current_Length = Right'Length and then Left.Data (1 .. Left.Current_Length) = Right; end Equal; - function Equal (Left : Wide_String; Right : Super_String) - return Boolean is + function Equal + (Left : Wide_String; + Right : Super_String) return Boolean + is begin return Left'Length = Right.Current_Length and then Left = Right.Data (1 .. Right.Current_Length); @@ -174,7 +176,10 @@ package body Ada.Strings.Wide_Superbounded is -- Greater -- ------------- - function Greater (Left, Right : Super_String) return Boolean is + function Greater + (Left : Super_String; + Right : Super_String) return Boolean + is begin return Left.Data (1 .. Left.Current_Length) > Right.Data (1 .. Right.Current_Length); @@ -182,8 +187,7 @@ package body Ada.Strings.Wide_Superbounded is function Greater (Left : Super_String; - Right : Wide_String) - return Boolean + Right : Wide_String) return Boolean is begin return Left.Data (1 .. Left.Current_Length) > Right; @@ -191,8 +195,7 @@ package body Ada.Strings.Wide_Superbounded is function Greater (Left : Wide_String; - Right : Super_String) - return Boolean + Right : Super_String) return Boolean is begin return Left > Right.Data (1 .. Right.Current_Length); @@ -202,7 +205,10 @@ package body Ada.Strings.Wide_Superbounded is -- Greater_Or_Equal -- ---------------------- - function Greater_Or_Equal (Left, Right : Super_String) return Boolean is + function Greater_Or_Equal + (Left : Super_String; + Right : Super_String) return Boolean + is begin return Left.Data (1 .. Left.Current_Length) >= Right.Data (1 .. Right.Current_Length); @@ -210,8 +216,7 @@ package body Ada.Strings.Wide_Superbounded is function Greater_Or_Equal (Left : Super_String; - Right : Wide_String) - return Boolean + Right : Wide_String) return Boolean is begin return Left.Data (1 .. Left.Current_Length) >= Right; @@ -219,8 +224,7 @@ package body Ada.Strings.Wide_Superbounded is function Greater_Or_Equal (Left : Wide_String; - Right : Super_String) - return Boolean + Right : Super_String) return Boolean is begin return Left >= Right.Data (1 .. Right.Current_Length); @@ -230,7 +234,10 @@ package body Ada.Strings.Wide_Superbounded is -- Less -- ---------- - function Less (Left, Right : Super_String) return Boolean is + function Less + (Left : Super_String; + Right : Super_String) return Boolean + is begin return Left.Data (1 .. Left.Current_Length) < Right.Data (1 .. Right.Current_Length); @@ -238,8 +245,7 @@ package body Ada.Strings.Wide_Superbounded is function Less (Left : Super_String; - Right : Wide_String) - return Boolean + Right : Wide_String) return Boolean is begin return Left.Data (1 .. Left.Current_Length) < Right; @@ -247,8 +253,7 @@ package body Ada.Strings.Wide_Superbounded is function Less (Left : Wide_String; - Right : Super_String) - return Boolean + Right : Super_String) return Boolean is begin return Left < Right.Data (1 .. Right.Current_Length); @@ -258,7 +263,10 @@ package body Ada.Strings.Wide_Superbounded is -- Less_Or_Equal -- ------------------- - function Less_Or_Equal (Left, Right : Super_String) return Boolean is + function Less_Or_Equal + (Left : Super_String; + Right : Super_String) return Boolean + is begin return Left.Data (1 .. Left.Current_Length) <= Right.Data (1 .. Right.Current_Length); @@ -266,8 +274,7 @@ package body Ada.Strings.Wide_Superbounded is function Less_Or_Equal (Left : Super_String; - Right : Wide_String) - return Boolean + Right : Wide_String) return Boolean is begin return Left.Data (1 .. Left.Current_Length) <= Right; @@ -275,13 +282,47 @@ package body Ada.Strings.Wide_Superbounded is function Less_Or_Equal (Left : Wide_String; - Right : Super_String) - return Boolean + Right : Super_String) return Boolean is begin return Left <= Right.Data (1 .. Right.Current_Length); end Less_Or_Equal; + ---------------------- + -- Set_Super_String -- + ---------------------- + + procedure Set_Super_String + (Target : out Super_String; + Source : Wide_String; + Drop : Truncation := Error) + is + Slen : constant Natural := Source'Length; + Max_Length : constant Positive := Target.Max_Length; + + begin + if Slen <= Max_Length then + Target.Current_Length := Slen; + Target.Data (1 .. Slen) := Source; + + else + case Drop is + when Strings.Right => + Target.Current_Length := Max_Length; + Target.Data (1 .. Max_Length) := + Source (Source'First .. Source'First - 1 + Max_Length); + + when Strings.Left => + Target.Current_Length := Max_Length; + Target.Data (1 .. Max_Length) := + Source (Source'Last - (Max_Length - 1) .. Source'Last); + + when Strings.Error => + raise Ada.Strings.Length_Error; + end case; + end if; + end Set_Super_String; + ------------------ -- Super_Append -- ------------------ @@ -289,9 +330,9 @@ package body Ada.Strings.Wide_Superbounded is -- Case of Super_String and Super_String function Super_Append - (Left, Right : Super_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + (Left : Super_String; + Right : Super_String; + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Left.Max_Length; Result : Super_String (Max_Length); @@ -386,8 +427,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Append (Left : Super_String; Right : Wide_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Left.Max_Length; Result : Super_String (Max_Length); @@ -488,8 +528,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Append (Left : Wide_String; Right : Super_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Right.Max_Length; Result : Super_String (Max_Length); @@ -543,8 +582,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Append (Left : Super_String; Right : Wide_Character; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Left.Max_Length; Result : Super_String (Max_Length); @@ -612,8 +650,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Append (Left : Wide_Character; Right : Super_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Right.Max_Length; Result : Super_String (Max_Length); @@ -649,10 +686,10 @@ package body Ada.Strings.Wide_Superbounded is ----------------- function Super_Count - (Source : Super_String; - Pattern : Wide_String; - Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) - return Natural + (Source : Super_String; + Pattern : Wide_String; + Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) + return Natural is begin return @@ -661,10 +698,9 @@ package body Ada.Strings.Wide_Superbounded is end Super_Count; function Super_Count - (Source : Super_String; - Pattern : Wide_String; - Mapping : Wide_Maps.Wide_Character_Mapping_Function) - return Natural + (Source : Super_String; + Pattern : Wide_String; + Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural is begin return @@ -674,8 +710,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Count (Source : Super_String; - Set : Wide_Maps.Wide_Character_Set) - return Natural + Set : Wide_Maps.Wide_Character_Set) return Natural is begin return Wide_Search.Count (Source.Data (1 .. Source.Current_Length), Set); @@ -688,8 +723,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Delete (Source : Super_String; From : Positive; - Through : Natural) - return Super_String + Through : Natural) return Super_String is Result : Super_String (Source.Max_Length); Slen : constant Natural := Source.Current_Length; @@ -747,8 +781,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Element (Source : Super_String; - Index : Positive) - return Wide_Character + Index : Positive) return Wide_Character is begin if Index in 1 .. Source.Current_Length then @@ -782,8 +815,7 @@ package body Ada.Strings.Wide_Superbounded is (Source : Super_String; Count : Natural; Pad : Wide_Character := Wide_Space; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Source.Max_Length; Result : Super_String (Max_Length); @@ -830,7 +862,7 @@ package body Ada.Strings.Wide_Superbounded is procedure Super_Head (Source : in out Super_String; Count : Natural; - Pad : Wide_Character := Wide_Space; + Pad : Wide_Character := Wide_Space; Drop : Truncation := Error) is Max_Length : constant Positive := Source.Max_Length; @@ -878,11 +910,11 @@ package body Ada.Strings.Wide_Superbounded is ----------------- function Super_Index - (Source : Super_String; - Pattern : Wide_String; - Going : Strings.Direction := Strings.Forward; - Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) - return Natural + (Source : Super_String; + Pattern : Wide_String; + Going : Strings.Direction := Strings.Forward; + Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) + return Natural is begin return Wide_Search.Index @@ -890,11 +922,10 @@ package body Ada.Strings.Wide_Superbounded is end Super_Index; function Super_Index - (Source : Super_String; - Pattern : Wide_String; - Going : Direction := Forward; - Mapping : Wide_Maps.Wide_Character_Mapping_Function) - return Natural + (Source : Super_String; + Pattern : Wide_String; + Going : Direction := Forward; + Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural is begin return Wide_Search.Index @@ -905,22 +936,59 @@ package body Ada.Strings.Wide_Superbounded is (Source : Super_String; Set : Wide_Maps.Wide_Character_Set; Test : Strings.Membership := Strings.Inside; - Going : Strings.Direction := Strings.Forward) - return Natural + Going : Strings.Direction := Strings.Forward) return Natural is begin return Wide_Search.Index (Source.Data (1 .. Source.Current_Length), Set, Test, Going); end Super_Index; + function Super_Index + (Source : Super_String; + Pattern : Wide_String; + From : Positive; + Going : Direction := Forward; + Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) + return Natural + is + begin + return Wide_Search.Index + (Source.Data (1 .. Source.Current_Length), + Pattern, From, Going, Mapping); + end Super_Index; + + function Super_Index + (Source : Super_String; + Pattern : Wide_String; + From : Positive; + Going : Direction := Forward; + Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural + is + begin + return Wide_Search.Index + (Source.Data (1 .. Source.Current_Length), + Pattern, From, Going, Mapping); + end Super_Index; + + function Super_Index + (Source : Super_String; + Set : Wide_Maps.Wide_Character_Set; + From : Positive; + Test : Membership := Inside; + Going : Direction := Forward) return Natural + is + begin + return Wide_Search.Index + (Source.Data (1 .. Source.Current_Length), Set, From, Test, Going); + end Super_Index; + --------------------------- -- Super_Index_Non_Blank -- --------------------------- function Super_Index_Non_Blank (Source : Super_String; - Going : Strings.Direction := Strings.Forward) - return Natural + Going : Strings.Direction := Strings.Forward) return Natural is begin return @@ -928,6 +996,17 @@ package body Ada.Strings.Wide_Superbounded is (Source.Data (1 .. Source.Current_Length), Going); end Super_Index_Non_Blank; + function Super_Index_Non_Blank + (Source : Super_String; + From : Positive; + Going : Direction := Forward) return Natural + is + begin + return + Wide_Search.Index_Non_Blank + (Source.Data (1 .. Source.Current_Length), From, Going); + end Super_Index_Non_Blank; + ------------------ -- Super_Insert -- ------------------ @@ -936,8 +1015,7 @@ package body Ada.Strings.Wide_Superbounded is (Source : Super_String; Before : Positive; New_Item : Wide_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Source.Max_Length; Result : Super_String (Max_Length); @@ -948,9 +1026,9 @@ package body Ada.Strings.Wide_Superbounded is Alen : constant Integer := Slen - Blen; Droplen : constant Integer := Tlen - Max_Length; - -- Tlen is the length of the total Wide_String before possible - -- truncation. Blen, Alen are the lengths of the before and after - -- pieces of the source Wide_String. + -- Tlen is the length of the total string before possible truncation. + -- Blen, Alen are the lengths of the before and after pieces of the + -- source string. begin if Alen < 0 then @@ -1032,11 +1110,10 @@ package body Ada.Strings.Wide_Superbounded is --------------------- function Super_Overwrite - (Source : Super_String; - Position : Positive; - New_Item : Wide_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + (Source : Super_String; + Position : Positive; + New_Item : Wide_String; + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Source.Max_Length; Result : Super_String (Max_Length); @@ -1172,12 +1249,11 @@ package body Ada.Strings.Wide_Superbounded is ------------------------- function Super_Replace_Slice - (Source : Super_String; - Low : Positive; - High : Natural; - By : Wide_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + (Source : Super_String; + Low : Positive; + High : Natural; + By : Wide_String; + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Source.Max_Length; Slen : constant Natural := Source.Current_Length; @@ -1197,10 +1273,10 @@ package body Ada.Strings.Wide_Superbounded is Droplen : constant Integer := Tlen - Max_Length; Result : Super_String (Max_Length); - -- Tlen is the total length of the result Wide_String before any + -- Tlen is the total length of the result string before any -- truncation. Blen and Alen are the lengths of the pieces - -- of the original Wide_String that end up in the result - -- Wide_String before and after the replaced slice. + -- of the original string that end up in the result string + -- before and after the replaced slice. begin if Droplen <= 0 then @@ -1273,8 +1349,7 @@ package body Ada.Strings.Wide_Superbounded is (Count : Natural; Item : Wide_Character; Drop : Truncation := Error; - Max_Length : Positive) - return Super_String + Max_Length : Positive) return Super_String is Result : Super_String (Max_Length); @@ -1297,8 +1372,7 @@ package body Ada.Strings.Wide_Superbounded is (Count : Natural; Item : Wide_String; Drop : Truncation := Error; - Max_Length : Positive) - return Super_String + Max_Length : Positive) return Super_String is Length : constant Integer := Count * Item'Length; Result : Super_String (Max_Length); @@ -1354,8 +1428,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Replicate (Count : Natural; Item : Super_String; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is begin return @@ -1373,8 +1446,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Slice (Source : Super_String; Low : Positive; - High : Natural) - return Wide_String + High : Natural) return Wide_String is begin -- Note: test of High > Length is in accordance with AI95-00128 @@ -1388,6 +1460,43 @@ package body Ada.Strings.Wide_Superbounded is end if; end Super_Slice; + function Super_Slice + (Source : Super_String; + Low : Positive; + High : Natural) return Super_String + is + Result : Super_String (Source.Max_Length); + + begin + if Low > Source.Current_Length + 1 + or else High > Source.Current_Length + then + raise Index_Error; + else + Result.Current_Length := High - Low + 1; + Result.Data (1 .. Source.Current_Length) := Source.Data (Low .. High); + end if; + + return Result; + end Super_Slice; + + procedure Super_Slice + (Source : Super_String; + Target : out Super_String; + Low : Positive; + High : Natural) + is + begin + if Low > Source.Current_Length + 1 + or else High > Source.Current_Length + then + raise Index_Error; + else + Target.Current_Length := High - Low + 1; + Target.Data (1 .. Source.Current_Length) := Source.Data (Low .. High); + end if; + end Super_Slice; + ---------------- -- Super_Tail -- ---------------- @@ -1396,8 +1505,7 @@ package body Ada.Strings.Wide_Superbounded is (Source : Super_String; Count : Natural; Pad : Wide_Character := Wide_Space; - Drop : Strings.Truncation := Strings.Error) - return Super_String + Drop : Strings.Truncation := Strings.Error) return Super_String is Max_Length : constant Positive := Source.Max_Length; Result : Super_String (Max_Length); @@ -1445,7 +1553,7 @@ package body Ada.Strings.Wide_Superbounded is procedure Super_Tail (Source : in out Super_String; Count : Natural; - Pad : Wide_Character := Wide_Space; + Pad : Wide_Character := Wide_Space; Drop : Truncation := Error) is Max_Length : constant Positive := Source.Max_Length; @@ -1497,7 +1605,7 @@ package body Ada.Strings.Wide_Superbounded is -- Super_To_String -- --------------------- - function Super_To_String (Source : in Super_String) return Wide_String is + function Super_To_String (Source : Super_String) return Wide_String is begin return Source.Data (1 .. Source.Current_Length); end Super_To_String; @@ -1508,8 +1616,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Translate (Source : Super_String; - Mapping : Wide_Maps.Wide_Character_Mapping) - return Super_String + Mapping : Wide_Maps.Wide_Character_Mapping) return Super_String is Result : Super_String (Source.Max_Length); @@ -1535,8 +1642,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Translate (Source : Super_String; - Mapping : Wide_Maps.Wide_Character_Mapping_Function) - return Super_String + Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Super_String is Result : Super_String (Source.Max_Length); @@ -1566,8 +1672,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Trim (Source : Super_String; - Side : Trim_End) - return Super_String + Side : Trim_End) return Super_String is Result : Super_String (Source.Max_Length); Last : Natural := Source.Current_Length; @@ -1623,8 +1728,7 @@ package body Ada.Strings.Wide_Superbounded is function Super_Trim (Source : Super_String; Left : Wide_Maps.Wide_Character_Set; - Right : Wide_Maps.Wide_Character_Set) - return Super_String + Right : Wide_Maps.Wide_Character_Set) return Super_String is Result : Super_String (Source.Max_Length); @@ -1690,8 +1794,7 @@ package body Ada.Strings.Wide_Superbounded is function Times (Left : Natural; Right : Wide_Character; - Max_Length : Positive) - return Super_String + Max_Length : Positive) return Super_String is Result : Super_String (Max_Length); @@ -1713,8 +1816,7 @@ package body Ada.Strings.Wide_Superbounded is function Times (Left : Natural; Right : Wide_String; - Max_Length : Positive) - return Super_String + Max_Length : Positive) return Super_String is Result : Super_String (Max_Length); Pos : Positive := 1; @@ -1741,8 +1843,7 @@ package body Ada.Strings.Wide_Superbounded is function Times (Left : Natural; - Right : Super_String) - return Super_String + Right : Super_String) return Super_String is Result : Super_String (Right.Max_Length); Pos : Positive := 1; @@ -1775,8 +1876,7 @@ package body Ada.Strings.Wide_Superbounded is function To_Super_String (Source : Wide_String; Max_Length : Natural; - Drop : Truncation := Error) - return Super_String + Drop : Truncation := Error) return Super_String is Result : Super_String (Max_Length); Slen : constant Natural := Source'Length; |