[multiple changes]

2010-08-05  Robert Dewar  <dewar@adacore.com>

	* a-suezse.adb, a-suezse.ads, a-suezen.adb, a-suezen.ads: Removed.
	* a-suewse.adb, a-suewse.ads, a-suesen.adb, a-suesen.ads,
	a-suewen.adb, a-suewen.ads: New files.
	* Makefile.rtl, impunit.adb: Update implementation of Ada 2012 string
	encoding packages.
	* sem_elab.adb: Minor reformatting.

2010-08-05  Arnaud Charlet  <charlet@adacore.com>

	* sem_ch8.adb (Use_One_Type): Protect against empty scopes.
	* exp_util.adb (Component_May_Be_Bit_Aligned): Prevent assert failure
	in case of null Comp.

From-SVN: r162904
This commit is contained in:
Arnaud Charlet 2010-08-05 11:08:50 +02:00
parent b94e425dc2
commit c97c0163bc
12 changed files with 473 additions and 51 deletions

View File

@ -1,3 +1,18 @@
2010-08-05 Robert Dewar <dewar@adacore.com>
* a-suezse.adb, a-suezse.ads, a-suezen.adb, a-suezen.ads: Removed.
* a-suewse.adb, a-suewse.ads, a-suesen.adb, a-suesen.ads,
a-suewen.adb, a-suewen.ads: New files.
* Makefile.rtl, impunit.adb: Update implementation of Ada 2012 string
encoding packages.
* sem_elab.adb: Minor reformatting.
2010-08-05 Arnaud Charlet <charlet@adacore.com>
* sem_ch8.adb (Use_One_Type): Protect against empty scopes.
* exp_util.adb (Component_May_Be_Bit_Aligned): Prevent assert failure
in case of null Comp.
2010-08-05 Robert Dewar <dewar@adacore.com>
* errout.adb, a-suewen.adb, a-suezen.adb: Minor reformatting.

View File

@ -227,8 +227,9 @@ GNATRTL_NONTASKING_OBJS= \
a-stzsup$(objext) \
a-stzunb$(objext) \
a-suenco$(objext) \
a-suewen$(objext) \
a-suezen$(objext) \
a-suesen$(objext) \
a-suewse$(objext) \
a-suezse$(objext) \
a-suteio$(objext) \
a-swbwha$(objext) \
a-swfwha$(objext) \

341
gcc/ada/a-suesen.adb Executable file
View File

@ -0,0 +1,341 @@
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.STRING_ENCODING --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010, 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- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Strings.UTF_Encoding.String_Encoding is
use Interfaces;
------------
-- Decode --
------------
-- Decode UTF-8/UTF-16BE/UTF-16LE input to String
function Decode
(Item : UTF_String;
Input_Scheme : Encoding_Scheme) return String
is
begin
if Input_Scheme = UTF_8 then
return Decode (Item);
else
return Decode (To_UTF_16 (Item, Input_Scheme));
end if;
end Decode;
-- Decode UTF-8 input to String
function Decode (Item : UTF_8_String) return String is
Result : String (1 .. Item'Length);
-- Result string (worst case is same length as input)
Len : Natural := 0;
-- Length of result stored so far
Iptr : Natural;
-- Input Item pointer
C : Unsigned_8;
R : Unsigned_16;
procedure Get_Continuation;
-- Reads a continuation byte of the form 10xxxxxx, shifts R left
-- by 6 bits, and or's in the xxxxxx to the low order 6 bits. On
-- return Ptr is incremented. Raises exceptioon if continuation
-- byte does not exist or is invalid.
----------------------
-- Get_Continuation --
----------------------
procedure Get_Continuation is
begin
if Iptr > Item'Last then
Raise_Encoding_Error (Iptr - 1);
else
C := To_Unsigned_8 (Item (Iptr));
Iptr := Iptr + 1;
if C not in 2#10_000000# .. 2#10_111111# then
Raise_Encoding_Error (Iptr - 1);
else
R := Shift_Left (R, 6) or Unsigned_16 (C and 2#00_111111#);
end if;
end if;
end Get_Continuation;
-- Start of processing for Decode
begin
Iptr := Item'First;
-- Skip BOM at start
if Item'Length >= 3
and then Item (Iptr .. Iptr + 2) = BOM_8
then
Iptr := Iptr + 3;
-- Error if bad BOM
elsif Item'Length >= 2
and then (Item (Iptr .. Iptr + 1) = BOM_16BE
or else
Item (Iptr .. Iptr + 1) = BOM_16LE)
then
Raise_Encoding_Error (Iptr);
end if;
while Iptr <= Item'Last loop
C := To_Unsigned_8 (Item (Iptr));
Iptr := Iptr + 1;
-- Codes in the range 16#00# - 16#7F# are represented as
-- 0xxxxxxx
if C <= 16#7F# then
R := Unsigned_16 (C);
-- No initial code can be of the form 10xxxxxx. Such codes are used
-- only for continuations.
elsif C <= 2#10_111111# then
Raise_Encoding_Error (Iptr - 1);
-- Codes in the range 16#80# - 16#7FF# are represented as
-- 110yyyxx 10xxxxxx
elsif C <= 2#110_11111# then
R := Unsigned_16 (C and 2#000_11111#);
Get_Continuation;
-- Codes in the range 16#800# - 16#FFFF# are represented as
-- 1110yyyy 10yyyyxx 10xxxxxx
-- Such codes are out of range for type Character
-- Codes in the range 16#10000# - 16#10FFFF# are represented as
-- 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx
-- Such codes are out of range for Wide_String output
-- Thus all remaining cases raise Encoding_Error
else
Raise_Encoding_Error (Iptr - 1);
end if;
Len := Len + 1;
Result (Len) := Character'Val (R);
end loop;
return Result (1 .. Len);
end Decode;
-- Decode UTF-16 input to String
function Decode (Item : UTF_16_Wide_String) return String is
Result : String (1 .. Item'Length);
-- Result is same length as input (possibly minus 1 if BOM present)
Len : Natural := 0;
-- Length of result
Iptr : Natural;
-- Index of next Item element
C : Unsigned_16;
begin
-- Skip UTF-16 BOM at start
Iptr := Item'First;
if Item'Length > 0 and then Item (Iptr) = BOM_16 (1) then
Iptr := Iptr + 1;
end if;
-- Loop through input characters
while Iptr <= Item'Last loop
C := To_Unsigned_16 (Item (Iptr));
Iptr := Iptr + 1;
-- Codes in the range 16#0000#..16#00FF# represent their own value
if C <= 16#00FF# then
Len := Len + 1;
Result (Len) := Character'Val (C);
-- All other codes are invalid, either they are invalid UTF-16
-- encoding sequences, or they represent values that are out of
-- range for type Character.
else
Raise_Encoding_Error (Iptr - 1);
end if;
end loop;
return Result (1 .. Len);
end Decode;
------------
-- Encode --
------------
-- Encode String in UTF-8, UTF-16BE or UTF-16LE
function Encode
(Item : String;
Output_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False) return UTF_String
is
begin
-- Case of UTF_8
if Output_Scheme = UTF_8 then
return Encode (Item, Output_BOM);
-- Case of UTF_16LE or UTF_16BE, use UTF-16 intermediary
else
return From_UTF_16 (UTF_16_Wide_String'(Encode (Item)),
Output_Scheme, Output_BOM);
end if;
end Encode;
-- Encode String in UTF-8
function Encode
(Item : String;
Output_BOM : Boolean := False) return UTF_8_String
is
Result : UTF_8_String (1 .. 3 * Item'Length + 3);
-- Worst case is three bytes per input byte + space for BOM
Len : Natural;
-- Number of output codes stored in Result
C : Unsigned_8;
-- Single input character
procedure Store (C : Unsigned_8);
pragma Inline (Store);
-- Store one output code, C is in the range 0 .. 255
-----------
-- Store --
-----------
procedure Store (C : Unsigned_8) is
begin
Len := Len + 1;
Result (Len) := Character'Val (C);
end Store;
-- Start of processing for UTF8_Encode
begin
-- Output BOM if required
if Output_BOM then
Result (1 .. 3) := BOM_8;
Len := 3;
else
Len := 0;
end if;
-- Loop through characters of input
for J in Item'Range loop
C := To_Unsigned_8 (Item (J));
-- Codes in the range 16#00# - 16#7F# are represented as
-- 0xxxxxxx
if C <= 16#7F# then
Store (C);
-- Codes in the range 16#80# - 16#7FF# are represented as
-- 110yyyxx 10xxxxxx
-- For type character of course, the limit is 16#FF# in any case
else
Store (2#110_00000# or Shift_Right (C, 6));
Store (2#10_000000# or (C and 2#00_111111#));
end if;
end loop;
return Result (1 .. Len);
end Encode;
-- Encode String in UTF-16
function Encode
(Item : String;
Output_BOM : Boolean := False) return UTF_16_Wide_String
is
Result : UTF_16_Wide_String
(1 .. Item'Length + Boolean'Pos (Output_BOM));
-- Output is same length as input + possible BOM
Len : Integer;
-- Length of output string
C : Unsigned_8;
begin
-- Output BOM if required
if Output_BOM then
Result (1) := BOM_16 (1);
Len := 1;
else
Len := 0;
end if;
-- Loop through input characters encoding them
for Iptr in Item'Range loop
C := To_Unsigned_8 (Item (Iptr));
-- Codes in the range 16#0000#..16#00FF# are output unchanged. This
-- includes all possible cases of Character values.
Len := Len + 1;
Result (Len) := Wide_Character'Val (C);
end loop;
return Result;
end Encode;
end Ada.Strings.UTF_Encoding.String_Encoding;

65
gcc/ada/a-suesen.ads Executable file
View File

@ -0,0 +1,65 @@
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.STRING_ENCODING --
-- --
-- S p e c --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
-- This is an Ada 2012 package defined in AI05-0137-1. It is used for encoding
-- and decoding String values using UTF encodings. Note: this package is
-- consistent with Ada 95, and may be included in Ada 95 implementations.
package Ada.Strings.UTF_Encoding.String_Encoding is
pragma Pure (String_Encoding);
-- The encoding routines take a String as input and encode the result
-- using the specified UTF encoding method. The result includes a BOM if
-- the Output_BOM argument is set to True. All 256 values of type Character
-- are valid, so Encoding_Error cannot be raised for string input data.
function Encode
(Item : String;
Output_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False) return UTF_String;
-- Encode String using UTF-8, UTF-16LE or UTF-16BE encoding as specified by
-- the Output_Scheme parameter.
function Encode
(Item : String;
Output_BOM : Boolean := False) return UTF_8_String;
-- Encode String using UTF-8 encoding
function Encode
(Item : String;
Output_BOM : Boolean := False) return UTF_16_Wide_String;
-- Encode String using UTF_16 encoding
-- The decoding routines take a UTF String as input, and return a decoded
-- Wide_String. If the UTF String starts with a BOM that matches the
-- encoding method, it is ignored. An incorrect BOM raises Encoding_Error,
-- as does a code out of range of type Character.
function Decode
(Item : UTF_String;
Input_Scheme : Encoding_Scheme) return String;
-- The input is encoded in UTF_8, UTF_16LE or UTF_16BE as specified by the
-- Input_Scheme parameter. It is decoded and returned as a String value.
-- Note: a convenient form for scheme may be Encoding (UTF_String).
function Decode
(Item : UTF_8_String) return String;
-- The input is encoded in UTF-8 and returned as a String value
function Decode
(Item : UTF_16_Wide_String) return String;
-- The input is encoded in UTF-16 and returned as a String value
end Ada.Strings.UTF_Encoding.String_Encoding;

View File

@ -2,7 +2,7 @@
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.WIDE_ENCODING --
-- ADA.STRINGS.UTF_ENCODING.WIDE_STRING_ENCODING --
-- --
-- B o d y --
-- --
@ -10,28 +10,26 @@
-- --
-- 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- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Strings.UTF_Encoding.Wide_Encoding is
package body Ada.Strings.UTF_Encoding.Wide_String_Encoding is
use Interfaces;
------------
@ -369,4 +367,4 @@ package body Ada.Strings.UTF_Encoding.Wide_Encoding is
return Result;
end Encode;
end Ada.Strings.UTF_Encoding.Wide_Encoding;
end Ada.Strings.UTF_Encoding.Wide_String_Encoding;

View File

@ -2,7 +2,7 @@
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.WIDE_ENCODING --
-- ADA.STRINGS.UTF_ENCODING.WIDE_STRING_ENCODING --
-- --
-- S p e c --
-- --
@ -17,8 +17,8 @@
-- and decoding Wide_String values using UTF encodings. Note: this package is
-- consistent with Ada 95, and may be included in Ada 95 implementations.
package Ada.Strings.UTF_Encoding.Wide_Encoding is
pragma Pure (Wide_Encoding);
package Ada.Strings.UTF_Encoding.Wide_String_Encoding is
pragma Pure (Wide_String_Encoding);
-- The encoding routines take a Wide_String as input and encode the result
-- using the specified UTF encoding method. The result includes a BOM if
@ -64,4 +64,4 @@ package Ada.Strings.UTF_Encoding.Wide_Encoding is
(Item : UTF_16_Wide_String) return Wide_String;
-- The input is encoded in UTF-16 and returned as a Wide_String value
end Ada.Strings.UTF_Encoding.Wide_Encoding;
end Ada.Strings.UTF_Encoding.Wide_String_Encoding;

View File

@ -2,7 +2,7 @@
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.WIDE_WIDE_ENCODING --
-- ADA.STRINGS.UTF_ENCODING.WIDE_WIDE_STRING_ENCODING --
-- --
-- B o d y --
-- --
@ -10,28 +10,26 @@
-- --
-- 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- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Strings.UTF_Encoding.Wide_Wide_Encoding is
package body Ada.Strings.UTF_Encoding.Wide_Wide_String_Encoding is
use Interfaces;
------------
@ -428,4 +426,4 @@ package body Ada.Strings.UTF_Encoding.Wide_Wide_Encoding is
return Result (1 .. Len);
end Encode;
end Ada.Strings.UTF_Encoding.Wide_Wide_Encoding;
end Ada.Strings.UTF_Encoding.Wide_Wide_String_Encoding;

View File

@ -2,7 +2,7 @@
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.STRINGS.UTF_ENCODING.WIDE_WIDE_ENCODING --
-- ADA.STRINGS.UTF_ENCODING.WIDE_WIDE_STRING_ENCODING --
-- --
-- S p e c --
-- --
@ -18,8 +18,8 @@
-- consistent with Ada 2005, and may be used in Ada 2005 mode, but cannot be
-- used in Ada 95 mode, since Wide_Wide_Character is an Ada 2005 feature.
package Ada.Strings.UTF_Encoding.Wide_Wide_Encoding is
pragma Pure (Wide_Wide_Encoding);
package Ada.Strings.UTF_Encoding.Wide_Wide_String_Encoding is
pragma Pure (Wide_Wide_String_Encoding);
-- The encoding routines take a Wide_Wide_String as input and encode the
-- result using the specified UTF encoding method. The result includes a
@ -61,4 +61,4 @@ package Ada.Strings.UTF_Encoding.Wide_Wide_Encoding is
(Item : UTF_16_Wide_String) return Wide_Wide_String;
-- The input is encoded in UTF-16 and returned as a Wide_String value
end Ada.Strings.UTF_Encoding.Wide_Wide_Encoding;
end Ada.Strings.UTF_Encoding.Wide_Wide_String_Encoding;

View File

@ -904,17 +904,19 @@ package body Exp_Util is
----------------------------------
function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean is
UT : constant Entity_Id := Underlying_Type (Etype (Comp));
UT : Entity_Id;
begin
-- If no component clause, then everything is fine, since the back end
-- never bit-misaligns by default, even if there is a pragma Packed for
-- the record.
if No (Component_Clause (Comp)) then
if No (Comp) or else No (Component_Clause (Comp)) then
return False;
end if;
UT := Underlying_Type (Etype (Comp));
-- It is only array and record types that cause trouble
if not Is_Record_Type (UT)

View File

@ -173,13 +173,14 @@ package body Impunit is
"a-wichun", -- Ada.Wide_Characters.Unicode
"a-widcha", -- Ada.Wide_Characters
-- Note: strictly the next two should be Ada 2012 units, but it seems
-- Note: strictly the following should be Ada 2012 units, but it seems
-- harmless (and useful) to make then available in Ada 95 mode, since
-- they only deal with Wide_Character, not Wide_Wide_Character.
-- they do not deal with Wide_Wide_Character.
"a-stuten", -- Ada.Strings.UTF_Encoding
"a-suenco", -- Ada.Strings.UTF_Encoding.Conversions
"a-suewen", -- Ada.Strings.UTF_Encoding.Wide_Encoding
"a-suesen", -- Ada.Strings.UTF_Encoding.String_Encoding
"a-suewse", -- Ada.Strings.UTF_Encoding.Wide_String_Encoding
---------------------------
-- GNAT Special IO Units --
@ -470,7 +471,7 @@ package body Impunit is
-- Note: strictly the following should be Ada 2012 units, but it seems
-- harmless (and useful) to make then available in Ada 2005 mode.
"a-suezen", -- Ada.Strings.UTF_Encoding.Wide_Wide_Encoding
"a-suezse", -- Ada.Strings.UTF_Encoding.Wide_Wide_String_Encoding
---------------------------
-- GNAT Special IO Units --

View File

@ -7622,9 +7622,10 @@ package body Sem_Ch8 is
begin
S1 := Scope (Ent1);
S2 := Scope (Ent2);
while S1 /= Standard_Standard
and then
S2 /= Standard_Standard
while Present (S1)
and then Present (S2)
and then S1 /= Standard_Standard
and then S2 /= Standard_Standard
loop
S1 := Scope (S1);
S2 := Scope (S2);

View File

@ -2850,8 +2850,8 @@ package body Sem_Elab is
Typ : constant Entity_Id := Etype (N);
Chk : constant Boolean := Do_Range_Check (N);
R : constant Node_Id :=
Make_Raise_Program_Error (Loc,
R : constant Node_Id :=
Make_Raise_Program_Error (Loc,
Reason => PE_Access_Before_Elaboration);
Reloc_N : Node_Id;