OSDN Git Service

PR target/50678
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-ch2.adb
index 697cf86..4892c8c 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-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- --
@@ -118,7 +118,7 @@ package body Ch2 is
 
    --  DECIMAL_LITERAL ::= NUMERAL [.NUMERAL] [EXPONENT]
 
-   --  Handled by scanner as part of numeric lIteral handing (see 2.4)
+   --  Handled by scanner as part of numeric literal handing (see 2.4)
 
    --------------------
    -- 2.4.1  Numeral --
@@ -241,8 +241,8 @@ package body Ch2 is
       --  Set True if an identifier is encountered for a pragma argument. Used
       --  to check that there are no more arguments without identifiers.
 
-      Pragma_Node   : Node_Id;
-      Pragma_Name   : Name_Id;
+      Prag_Node     : Node_Id;
+      Prag_Name     : Name_Id;
       Semicolon_Loc : Source_Ptr;
       Ident_Node    : Node_Id;
       Assoc_Node    : Node_Id;
@@ -280,9 +280,9 @@ package body Ch2 is
    --  Start of processing for P_Pragma
 
    begin
-      Pragma_Node := New_Node (N_Pragma, Token_Ptr);
+      Prag_Node := New_Node (N_Pragma, Token_Ptr);
       Scan; -- past PRAGMA
-      Pragma_Name := Token_Name;
+      Prag_Name := Token_Name;
 
       if Style_Check then
          Style.Check_Pragma_Name;
@@ -291,24 +291,23 @@ package body Ch2 is
       --  Ada 2005 (AI-284): INTERFACE is a new reserved word but it is
       --  allowed as a pragma name.
 
-      if Ada_Version >= Ada_05
+      if Ada_Version >= Ada_2005
         and then Token = Tok_Interface
       then
-         Pragma_Name := Name_Interface;
+         Prag_Name := Name_Interface;
          Ident_Node  := Make_Identifier (Token_Ptr, Name_Interface);
          Scan; -- past INTERFACE
       else
          Ident_Node := P_Identifier;
       end if;
 
-      Set_Chars (Pragma_Node, Pragma_Name);
-      Set_Pragma_Identifier (Pragma_Node, Ident_Node);
+      Set_Pragma_Identifier (Prag_Node, Ident_Node);
 
       --  See if special INTERFACE/IMPORT check is required
 
       if SIS_Entry_Active then
-         Interface_Check_Required := (Pragma_Name = Name_Interface);
-         Import_Check_Required    := (Pragma_Name = Name_Import);
+         Interface_Check_Required := (Prag_Name = Name_Interface);
+         Import_Check_Required    := (Prag_Name = Name_Import);
       else
          Interface_Check_Required := False;
          Import_Check_Required    := False;
@@ -322,7 +321,7 @@ package body Ch2 is
         or else (Token /= Tok_Semicolon
                    and then not Token_Is_At_Start_Of_Line)
       then
-         Set_Pragma_Argument_Associations (Pragma_Node, New_List);
+         Set_Pragma_Argument_Associations (Prag_Node, New_List);
          T_Left_Paren;
 
          loop
@@ -342,7 +341,7 @@ package body Ch2 is
                end if;
             end if;
 
-            Append (Assoc_Node, Pragma_Argument_Associations (Pragma_Node));
+            Append (Assoc_Node, Pragma_Argument_Associations (Prag_Node));
             exit when Token /= Tok_Comma;
             Scan; -- past comma
          end loop;
@@ -352,7 +351,7 @@ package body Ch2 is
          --  statement, and an assignment statement is the most likely
          --  candidate for this error)
 
-         if Token = Tok_Colon_Equal and then Pragma_Name = Name_Debug then
+         if Token = Tok_Colon_Equal and then Prag_Name = Name_Debug then
             Error_Msg_SC ("argument for pragma Debug must be procedure call");
             Resync_To_Semicolon;
 
@@ -378,13 +377,13 @@ package body Ch2 is
       --  case of pragma Source_File_Name, which assume the semicolon
       --  is already scanned out.
 
-      if Chars (Pragma_Node) = Name_Style_Checks then
-         Result := Par.Prag (Pragma_Node, Semicolon_Loc);
+      if Prag_Name = Name_Style_Checks then
+         Result := Par.Prag (Prag_Node, Semicolon_Loc);
          Skip_Pragma_Semicolon;
          return Result;
       else
          Skip_Pragma_Semicolon;
-         return Par.Prag (Pragma_Node, Semicolon_Loc);
+         return Par.Prag (Prag_Node, Semicolon_Loc);
       end if;
 
    exception
@@ -434,14 +433,18 @@ package body Ch2 is
    --  Error recovery: Cannot raise Error_Resync
 
    procedure P_Pragmas_Opt (List : List_Id) is
-      P : Node_Id;
+      P     : Node_Id;
 
    begin
       while Token = Tok_Pragma loop
          P := P_Pragma;
 
-         if Chars (P) = Name_Assert or else Chars (P) = Name_Debug then
-            Error_Msg_Name_1 := Chars (P);
+         if Nkind (P) /= N_Error
+          and then (Pragma_Name (P) = Name_Assert
+                      or else
+                    Pragma_Name (P) = Name_Debug)
+         then
+            Error_Msg_Name_1 := Pragma_Name (P);
             Error_Msg_N
               ("pragma% must be in declaration/statement context", P);
          else
@@ -466,11 +469,14 @@ package body Ch2 is
    is
       Scan_State      : Saved_Scan_State;
       Identifier_Node : Node_Id;
+      Id_Present      : Boolean;
 
    begin
       Association := New_Node (N_Pragma_Argument_Association, Token_Ptr);
       Set_Chars (Association, No_Name);
 
+      --  Argument starts with identifier
+
       if Token = Tok_Identifier then
          Identifier_Node := Token_Node;
          Save_Scan_State (Scan_State); -- at Identifier
@@ -480,20 +486,38 @@ package body Ch2 is
             Identifier_Seen := True;
             Scan; -- past arrow
             Set_Chars (Association, Chars (Identifier_Node));
+            Id_Present := True;
 
-            --  Case of argument with no identifier
+         --  Case of argument with no identifier
 
          else
             Restore_Scan_State (Scan_State); -- to Identifier
-
-            if Identifier_Seen then
-               Error_Msg_SC
-                 ("|pragma argument identifier required here (RM 2.8(4))");
-            end if;
+            Id_Present := False;
          end if;
+
+      --  Argument does not start with identifier
+
+      else
+         Id_Present := False;
       end if;
 
-      Set_Expression (Association, P_Expression);
+      --  Diagnose error of "positional" argument for pragma appearing after
+      --  a "named" argument (quotes here are because that's not quite accurate
+      --  Ada RM terminology).
+
+      --  Since older GNAT versions did not generate this error, disable this
+      --  message in codepeer mode to help legacy code using codepeer.
+
+      if Identifier_Seen and not Id_Present and not CodePeer_Mode then
+         Error_Msg_SC ("|pragma argument identifier required here");
+         Error_Msg_SC ("\since previous argument had identifier (RM 2.8(4))");
+      end if;
+
+      if Id_Present then
+         Set_Expression (Association, P_Expression);
+      else
+         Set_Expression (Association, P_Expression_If_OK);
+      end if;
    end Scan_Pragma_Argument_Association;
 
 end Ch2;