From patchwork Thu Sep 9 08:51:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 64261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 5F238B6F0D for ; Thu, 9 Sep 2010 18:51:34 +1000 (EST) Received: (qmail 17806 invoked by alias); 9 Sep 2010 08:51:30 -0000 Received: (qmail 17795 invoked by uid 22791); 9 Sep 2010 08:51:28 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL, BAYES_50, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Sep 2010 08:51:22 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 2F472CB021E; Thu, 9 Sep 2010 10:51:20 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5T2f7w8rS26P; Thu, 9 Sep 2010 10:51:20 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 1C450CB01D8; Thu, 9 Sep 2010 10:51:20 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id AC007D9BA8; Thu, 9 Sep 2010 10:51:19 +0200 (CEST) Date: Thu, 9 Sep 2010 10:51:19 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Improved error recovery for positional box Message-ID: <20100909085119.GA8591@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch improves the error recovery for a box used in positional notation in an aggregate (named notation is required for this case). The following test is shown twice -- compiled with -gnat05 1. package badbox is 2. x : string := (<>, 'a', 'b'); | >>> (Ada 2005) box only allowed with named notation 3. y : string := ('a', <>, 'b'); | >>> (Ada 2005) box only allowed with named notation 4. end badbox; -- compiled with -gnat95 1. package badbox is 2. x : string := (<>, 'a', 'b'); | >>> box in aggregate is an Ada 2005 extension >>> (Ada 2005) box only allowed with named notation 3. y : string := ('a', <>, 'b'); | >>> box in aggregate is an Ada 2005 extension >>> (Ada 2005) box only allowed with named notation 4. end badbox; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-09-09 Robert Dewar * par-ch4.adb (Box_Error): New procedure. Index: par-ch4.adb =================================================================== --- par-ch4.adb (revision 164000) +++ par-ch4.adb (working copy) @@ -1153,6 +1153,33 @@ package body Ch4 is Lparen_Sloc : Source_Ptr; Scan_State : Saved_Scan_State; + procedure Box_Error; + -- Called if <> is encountered as positional aggregate element. Issues + -- error message and sets Expr_Node to Error. + + --------------- + -- Box_Error -- + --------------- + + procedure Box_Error is + begin + if Ada_Version < Ada_2005 then + Error_Msg_SC ("box in aggregate is an Ada 2005 extension"); + end if; + + -- Ada 2005 (AI-287): The box notation is allowed only with named + -- notation because positional notation might be error prone. For + -- example, in "(X, <>, Y, <>)", there is no type associated with + -- the boxes, so you might not be leaving out the components you + -- thought you were leaving out. + + Error_Msg_SC ("(Ada 2005) box only allowed with named notation"); + Scan; -- past box + Expr_Node := Error; + end Box_Error; + + -- Start of processsing for P_Aggregate_Or_Paren_Expr + begin Lparen_Sloc := Token_Ptr; T_Left_Paren; @@ -1196,26 +1223,17 @@ package body Ch4 is end if; end if; - -- Ada 2005 (AI-287): The box notation is allowed only with named - -- notation because positional notation might be error prone. For - -- example, in "(X, <>, Y, <>)", there is no type associated with - -- the boxes, so you might not be leaving out the components you - -- thought you were leaving out. + -- Scan expression, handling box appearing as positional argument - if Ada_Version >= Ada_05 and then Token = Tok_Box then - Error_Msg_SC ("(Ada 2005) box notation only allowed with " - & "named notation"); - Scan; -- past BOX - Aggregate_Node := New_Node (N_Aggregate, Lparen_Sloc); - return Aggregate_Node; + if Token = Tok_Box then + Box_Error; + else + Expr_Node := P_Expression_Or_Range_Attribute_If_OK; end if; - Expr_Node := P_Expression_Or_Range_Attribute_If_OK; - -- Extension aggregate case if Token = Tok_With then - if Nkind (Expr_Node) = N_Attribute_Reference and then Attribute_Name (Expr_Node) = Name_Range then @@ -1316,8 +1334,7 @@ package body Ch4 is "extension aggregate"); raise Error_Resync; - -- A range attribute can only appear as part of a discrete choice - -- list. + -- Range attribute can only appear as part of a discrete choice list elsif Nkind (Expr_Node) = N_Attribute_Reference and then Attribute_Name (Expr_Node) = Name_Range @@ -1386,11 +1403,17 @@ package body Ch4 is exit; end if; + -- Deal with misused box + + if Token = Tok_Box then + Box_Error; + -- Otherwise initiate for reentry to top of loop by scanning an -- initial expression, unless the first token is OTHERS. - if Token = Tok_Others then + elsif Token = Tok_Others then Expr_Node := Empty; + else Save_Scan_State (Scan_State); -- at start of expression Expr_Node := P_Expression_Or_Range_Attribute_If_OK;