OSDN Git Service

2005-03-29 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / scn.adb
index b1e5707..b83be64 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2004 Free Software Foundation, Inc.          --
+--          Copyright (C) 1992-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- --
 
 with Atree;    use Atree;
 with Csets;    use Csets;
-with Hostparm;
 with Namet;    use Namet;
 with Opt;      use Opt;
+with Restrict; use Restrict;
+with Rident;   use Rident;
 with Scans;    use Scans;
 with Sinfo;    use Sinfo;
 with Sinput;   use Sinput;
+with Uintp;    use Uintp;
 
 package body Scn is
 
@@ -63,7 +65,7 @@ package body Scn is
       case Token is
          when Tok_Char_Literal =>
             Token_Node := New_Node (N_Character_Literal, Token_Ptr);
-            Set_Char_Literal_Value (Token_Node, Character_Code);
+            Set_Char_Literal_Value (Token_Node, UI_From_CC (Character_Code));
             Set_Chars (Token_Node, Token_Name);
 
          when Tok_Identifier =>
@@ -99,13 +101,11 @@ package body Scn is
 
    procedure Check_End_Of_Line is
       Len : constant Int := Int (Scan_Ptr) - Int (Current_Line_Start);
-
    begin
-      if Len > Hostparm.Max_Line_Length then
-         Error_Long_Line;
-
-      elsif Style_Check then
+      if Style_Check then
          Style.Check_Line_Terminator (Len);
+      elsif Len > Opt.Max_Line_Length then
+         Error_Long_Line;
       end if;
    end Check_End_Of_Line;
 
@@ -115,6 +115,7 @@ package body Scn is
 
    function Determine_License return License_Type is
       GPL_Found : Boolean := False;
+      Result    : License_Type;
 
       function Contains (S : String) return Boolean;
       --  See if current comment contains successive non-blank characters
@@ -134,8 +135,15 @@ package body Scn is
          SS : Source_Ptr;
 
       begin
+         --  Loop to check characters. This loop is terminated by end of
+         --  line, and also we need to check for the EOF case, to take
+         --  care of files containing only comments.
+
          SP := Scan_Ptr;
-         while Source (SP) /= CR and then Source (SP) /= LF loop
+         while Source (SP) /= CR and then
+               Source (SP) /= LF and then
+               Source (SP) /= EOF
+         loop
             if Source (SP) = S (S'First) then
                SS := SP;
                CP := S'First;
@@ -184,14 +192,17 @@ package body Scn is
            or else Source (Scan_Ptr + 1) /= '-'
          then
             if GPL_Found then
-               return GPL;
+               Result := GPL;
+               exit;
             else
-               return Unknown;
+               Result := Unknown;
+               exit;
             end if;
 
          elsif Contains ("Asaspecialexception") then
             if GPL_Found then
-               return Modified_GPL;
+               Result := Modified_GPL;
+               exit;
             end if;
 
          elsif Contains ("GNUGeneralPublicLicense") then
@@ -204,7 +215,8 @@ package body Scn is
              Contains
               ("ThisspecificationisderivedfromtheAdaReferenceManual")
          then
-            return Unrestricted;
+            Result := Unrestricted;
+            exit;
          end if;
 
          Skip_EOL;
@@ -233,6 +245,8 @@ package body Scn is
             end;
          end if;
       end loop;
+
+      return Result;
    end Determine_License;
 
    ----------------------------
@@ -252,7 +266,7 @@ package body Scn is
    begin
       Error_Msg
         ("this line is too long",
-         Current_Line_Start + Hostparm.Max_Line_Length);
+         Current_Line_Start + Source_Ptr (Opt.Max_Line_Length));
    end Error_Long_Line;
 
    ------------------------
@@ -310,6 +324,20 @@ package body Scn is
       end loop;
    end Initialize_Scanner;
 
+   -----------------------
+   -- Obsolescent_Check --
+   -----------------------
+
+   procedure Obsolescent_Check (S : Source_Ptr) is
+   begin
+      --  This is a pain in the neck case, since we normally need a node to
+      --  call Check_Restrictions, and all we have is a source pointer. The
+      --  easiest thing is to construct a dummy node. A bit kludgy, but this
+      --  is a marginal case. It's not worth trying to do things more cleanly.
+
+      Check_Restriction (No_Obsolescent_Features, New_Node (N_Empty, S));
+   end Obsolescent_Check;
+
    ------------------------------
    -- Scan_Reserved_Identifier --
    ------------------------------