No functionality modified. Tested on x86_64-pc-linux-gnu, committed on trunk
2012-02-08 Vincent Celier <cel...@adacore.com> * gcc-interface/Make-lang.in: Add g-byorma.o to gnatbind objects (g-buorma is now imported by sinput). Update dependencies. * scn.adb (Initialize_Scanner): Call Check_For_BOM * sinput-p.adb (Source_File_Is_Subunit): Call Check_For_BOM * sinput.adb: New procedure Check_For_BOM * sinput.ads: New procedure Check_For_BOM
Index: sinput.adb =================================================================== --- sinput.adb (revision 183996) +++ sinput.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2012, 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- -- @@ -36,11 +36,15 @@ with Debug; use Debug; with Opt; use Opt; with Output; use Output; +with Scans; use Scans; with Tree_IO; use Tree_IO; -with System; use System; with Widechar; use Widechar; +with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark; + +with System; use System; with System.Memory; +with System.WCh_Con; use System.WCh_Con; with Unchecked_Conversion; with Unchecked_Deallocation; @@ -246,6 +250,44 @@ return Name_Buffer (1 .. Name_Len); end Build_Location_String; + procedure Check_For_BOM is + BOM : BOM_Kind; + Len : Natural; + Tst : String (1 .. 5); + + begin + for J in 1 .. 5 loop + Tst (J) := Source (Scan_Ptr + Source_Ptr (J) - 1); + end loop; + + Read_BOM (Tst, Len, BOM, False); + + case BOM is + when UTF8_All => + Scan_Ptr := Scan_Ptr + Source_Ptr (Len); + Wide_Character_Encoding_Method := WCEM_UTF8; + Upper_Half_Encoding := True; + + when UTF16_LE | UTF16_BE => + Set_Standard_Error; + Write_Line ("UTF-16 encoding format not recognized"); + Set_Standard_Output; + raise Unrecoverable_Error; + + when UTF32_LE | UTF32_BE => + Set_Standard_Error; + Write_Line ("UTF-32 encoding format not recognized"); + Set_Standard_Output; + raise Unrecoverable_Error; + + when Unknown => + null; + + when others => + raise Program_Error; + end case; + end Check_For_BOM; + ----------------------- -- Get_Column_Number -- ----------------------- Index: sinput.ads =================================================================== --- sinput.ads (revision 183996) +++ sinput.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2012, 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- -- @@ -712,6 +712,16 @@ -- Writes out internal tables to current tree file using the relevant -- Table.Tree_Write routines. + procedure Check_For_BOM; + -- Check if the current source starts with a BOM. Scan_Ptr needs to be at + -- the start of the current source. + -- If the current source starts with a recognized BOM, then some flags + -- such as Wide_Character_Encoding_Method are set accordingly. + -- An exception is raised if a BOM is found that indicates an unrecognized + -- format. + -- This procedure has no effect if there is no BOM at the beginning of the + -- current source. + private pragma Inline (File_Name); pragma Inline (First_Mapped_Line); Index: sinput-p.adb =================================================================== --- sinput-p.adb (revision 184003) +++ sinput-p.adb (working copy) @@ -26,15 +26,10 @@ with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; -with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark; - -with Opt; use Opt; -with Output; use Output; with Prj.Err; with Sinput.C; with System; -with System.WCh_Con; use System.WCh_Con; package body Sinput.P is @@ -169,46 +164,8 @@ Prj.Err.Scanner.Set_Special_Character ('#'); Prj.Err.Scanner.Set_Special_Character ('$'); - -- Check for BOM + Check_For_BOM; - declare - BOM : BOM_Kind; - Len : Natural; - Tst : String (1 .. 5); - - begin - for J in 1 .. 5 loop - Tst (J) := Source (Scan_Ptr + Source_Ptr (J) - 1); - end loop; - - Read_BOM (Tst, Len, BOM, False); - - case BOM is - when UTF8_All => - Scan_Ptr := Scan_Ptr + Source_Ptr (Len); - Wide_Character_Encoding_Method := WCEM_UTF8; - Upper_Half_Encoding := True; - - when UTF16_LE | UTF16_BE => - Set_Standard_Error; - Write_Line ("UTF-16 encoding format not recognized"); - Set_Standard_Output; - raise Unrecoverable_Error; - - when UTF32_LE | UTF32_BE => - Set_Standard_Error; - Write_Line ("UTF-32 encoding format not recognized"); - Set_Standard_Output; - raise Unrecoverable_Error; - - when Unknown => - null; - - when others => - raise Program_Error; - end case; - end; - -- We scan past junk to the first interesting compilation unit token, to -- see if it is SEPARATE. We ignore WITH keywords during this and also -- PRIVATE. The reason for ignoring PRIVATE is that it handles some Index: scn.adb =================================================================== --- scn.adb (revision 183996) +++ scn.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2012, 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- -- @@ -28,7 +28,6 @@ with Hostparm; use Hostparm; with Namet; use Namet; with Opt; use Opt; -with Output; use Output; with Restrict; use Restrict; with Rident; use Rident; with Scans; use Scans; @@ -36,10 +35,6 @@ with Sinput; use Sinput; with Uintp; use Uintp; -with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark; - -with System.WCh_Con; use System.WCh_Con; - package body Scn is use ASCII; @@ -271,46 +266,8 @@ Set_License (Current_Source_File, Determine_License); end if; - -- Check for BOM + Check_For_BOM; - declare - BOM : BOM_Kind; - Len : Natural; - Tst : String (1 .. 5); - - begin - for J in 1 .. 5 loop - Tst (J) := Source (Scan_Ptr + Source_Ptr (J) - 1); - end loop; - - Read_BOM (Tst, Len, BOM, False); - - case BOM is - when UTF8_All => - Scan_Ptr := Scan_Ptr + Source_Ptr (Len); - Wide_Character_Encoding_Method := WCEM_UTF8; - Upper_Half_Encoding := True; - - when UTF16_LE | UTF16_BE => - Set_Standard_Error; - Write_Line ("UTF-16 encoding format not recognized"); - Set_Standard_Output; - raise Unrecoverable_Error; - - when UTF32_LE | UTF32_BE => - Set_Standard_Error; - Write_Line ("UTF-32 encoding format not recognized"); - Set_Standard_Output; - raise Unrecoverable_Error; - - when Unknown => - null; - - when others => - raise Program_Error; - end case; - end; - -- Because of the License stuff above, Scng.Initialize_Scanner cannot -- call Scan. Scan initial token (note this initializes Prev_Token, -- Prev_Token_Ptr). Index: gcc-interface/Make-lang.in =================================================================== --- gcc-interface/Make-lang.in (revision 183996) +++ gcc-interface/Make-lang.in (working copy) @@ -453,6 +453,7 @@ ada/fmap.o \ ada/fname.o \ ada/fname-uf.o \ + ada/g-byorma.o \ ada/g-hesora.o \ ada/g-htable.o \ ada/s-os_lib.o \ @@ -2435,31 +2436,33 @@ ada/errout.adb ada/erroutc.ads ada/erroutc.adb ada/eval_fat.ads \ ada/exp_aggr.ads ada/exp_atag.ads ada/exp_ch11.ads ada/exp_ch2.ads \ ada/exp_ch4.ads ada/exp_ch6.ads ada/exp_ch7.ads ada/exp_code.ads \ - ada/exp_fixd.ads ada/exp_intr.ads ada/exp_intr.adb ada/exp_pakd.ads \ - ada/exp_tss.ads ada/exp_util.ads ada/exp_util.adb ada/expander.ads \ - ada/fname.ads ada/fname-uf.ads ada/freeze.ads ada/get_targ.ads \ - ada/gnat.ads ada/g-htable.ads ada/gnatvsn.ads ada/hlo.ads \ - ada/hostparm.ads ada/inline.ads ada/interfac.ads ada/itypes.ads \ - ada/lib.ads ada/lib-load.ads ada/namet.ads ada/namet.adb ada/nlists.ads \ + ada/exp_disp.ads ada/exp_fixd.ads ada/exp_intr.ads ada/exp_intr.adb \ + ada/exp_pakd.ads ada/exp_tss.ads ada/exp_util.ads ada/exp_util.adb \ + ada/expander.ads ada/fname.ads ada/fname-uf.ads ada/freeze.ads \ + ada/get_targ.ads ada/gnat.ads ada/g-htable.ads ada/gnatvsn.ads \ + ada/hlo.ads ada/hostparm.ads ada/inline.ads ada/interfac.ads \ + ada/itypes.ads ada/lib.ads ada/lib-load.ads ada/lib-util.ads \ + ada/lib-xref.ads ada/namet.ads ada/namet.adb ada/nlists.ads \ ada/nlists.adb ada/nmake.ads ada/nmake.adb ada/opt.ads ada/output.ads \ - ada/restrict.ads ada/restrict.adb ada/rident.ads ada/rtsfind.ads \ - ada/scans.ads ada/sem.ads ada/sem.adb ada/sem_attr.ads ada/sem_aux.ads \ - ada/sem_ch10.ads ada/sem_ch11.ads ada/sem_ch12.ads ada/sem_ch13.ads \ - ada/sem_ch2.ads ada/sem_ch3.ads ada/sem_ch4.ads ada/sem_ch5.ads \ - ada/sem_ch6.ads ada/sem_ch7.ads ada/sem_ch8.ads ada/sem_ch9.ads \ - ada/sem_eval.ads ada/sem_prag.ads ada/sem_res.ads ada/sem_type.ads \ - ada/sem_util.ads ada/sem_warn.ads ada/sinfo.ads ada/sinfo.adb \ - ada/sinput.ads ada/sinput.adb ada/snames.ads ada/sprint.ads \ - ada/stand.ads ada/stringt.ads ada/stylesw.ads ada/system.ads \ - ada/s-exctab.ads ada/s-htable.ads ada/s-imenne.ads ada/s-memory.ads \ - ada/s-os_lib.ads ada/s-parame.ads ada/s-rident.ads ada/s-secsta.ads \ - ada/s-soflin.ads ada/s-stache.ads ada/s-stalib.ads ada/s-stoele.ads \ - ada/s-stoele.adb ada/s-string.ads ada/s-traent.ads ada/s-unstyp.ads \ - ada/s-wchcon.ads ada/table.ads ada/table.adb ada/targparm.ads \ - ada/tbuild.ads ada/tbuild.adb ada/tree_io.ads ada/ttypes.ads \ - ada/types.ads ada/uintp.ads ada/uintp.adb ada/uname.ads \ - ada/unchconv.ads ada/unchdeal.ads ada/urealp.ads ada/urealp.adb \ - ada/validsw.ads ada/widechar.ads + ada/put_alfa.ads ada/restrict.ads ada/restrict.adb ada/rident.ads \ + ada/rtsfind.ads ada/scans.ads ada/sem.ads ada/sem.adb ada/sem_attr.ads \ + ada/sem_aux.ads ada/sem_ch10.ads ada/sem_ch11.ads ada/sem_ch12.ads \ + ada/sem_ch13.ads ada/sem_ch2.ads ada/sem_ch3.ads ada/sem_ch4.ads \ + ada/sem_ch5.ads ada/sem_ch6.ads ada/sem_ch7.ads ada/sem_ch8.ads \ + ada/sem_ch9.ads ada/sem_disp.ads ada/sem_eval.ads ada/sem_prag.ads \ + ada/sem_res.ads ada/sem_type.ads ada/sem_util.ads ada/sem_util.adb \ + ada/sem_warn.ads ada/sinfo.ads ada/sinfo.adb ada/sinput.ads \ + ada/sinput.adb ada/snames.ads ada/sprint.ads ada/stand.ads \ + ada/stringt.ads ada/style.ads ada/styleg.ads ada/styleg.adb \ + ada/stylesw.ads ada/system.ads ada/s-exctab.ads ada/s-htable.ads \ + ada/s-imenne.ads ada/s-memory.ads ada/s-os_lib.ads ada/s-parame.ads \ + ada/s-rident.ads ada/s-secsta.ads ada/s-soflin.ads ada/s-stache.ads \ + ada/s-stalib.ads ada/s-stoele.ads ada/s-stoele.adb ada/s-string.ads \ + ada/s-traent.ads ada/s-unstyp.ads ada/s-wchcon.ads ada/table.ads \ + ada/table.adb ada/targparm.ads ada/tbuild.ads ada/tbuild.adb \ + ada/tree_io.ads ada/ttypes.ads ada/types.ads ada/uintp.ads \ + ada/uintp.adb ada/uname.ads ada/unchconv.ads ada/unchdeal.ads \ + ada/urealp.ads ada/urealp.adb ada/validsw.ads ada/widechar.ads ada/exp_pakd.o : ada/ada.ads ada/a-except.ads ada/a-unccon.ads \ ada/a-uncdea.ads ada/alloc.ads ada/aspects.ads ada/atree.ads \