From patchwork Thu Apr 25 10:31:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 239473 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id B7A1C2C00F5 for ; Thu, 25 Apr 2013 20:32:12 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=EgT1SrqKfhKgQp1yOq0oWfPWimvQUYaKblgfPCZf2LAJYOhOqy 0q25NjtJ+ICzL74WTPol4zJLD2ix4eiXhVOUIYxwK5/Hf5x2qk2fKRiZ74UwGsbT qjQYDRFWSuNg196Za0W87DL28BA/yHctIhBdsizCL/G8DZq70tme+rbWM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=msizIEu67dqqui0F9eDxgM5Q8dc=; b=tljwJCcFgjcpSW6FfKod 9LT75EICi6kPLA4ygHTJ+R2DQIgA2LT80Dj4Yogtdm5SxdJywtQ97gp7emitf+go eY4OlEYJbKL0toxY40WaL0fuE7KZObr9VXOo/t0ZRi8QzhdaWUdX+CifGt3oVIFL P56rCDwYdP1jzUpvaqGtGcQ= Received: (qmail 31732 invoked by alias); 25 Apr 2013 10:31:56 -0000 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 Received: (qmail 31708 invoked by uid 89); 25 Apr 2013 10:31:56 -0000 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO autolearn=ham version=3.3.1 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 25 Apr 2013 10:31:55 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F33222EA28; Thu, 25 Apr 2013 06:31:53 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id NTdPa7BuJi2m; Thu, 25 Apr 2013 06:31:53 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id DC03E2E7DC; Thu, 25 Apr 2013 06:31:53 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id DB0143FF09; Thu, 25 Apr 2013 06:31:53 -0400 (EDT) Date: Thu, 25 Apr 2013 06:31:53 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Improve error message on static vs non-static predicate use Message-ID: <20130425103153.GA18710@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Found: No This patch enhances the error message related to the use of a bad predicate. The compiler now advises on how to remedy the issue if the context warrants it. ------------ -- Source -- ------------ -- main.adb with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Main is subtype Even is Integer range 1 .. 10 with Dynamic_Predicate => Even in 2 | 4 | 6 | 8 | 10; begin for E in Even loop Put (E, 3); end loop; end Main; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c -gnat12 main.adb main.adb:7:13: cannot use subtype "Even" with non-static predicate for loop iteration main.adb:7:13: predicate of "Even" should be marked static Tested on x86_64-pc-linux-gnu, committed on trunk 2013-04-25 Hristian Kirtchev * sem_case.adb (Analyze_Choices): Enhance the error message given on a bad use of subtype predicate. * sem_ch5.adb (Analyze_Loop_Parameter_Specification): Enhance the error message given on a bad use of subtype predicate. * sem_util.adb (Bad_Predicated_Subtype_Use): Add formal parameter Suggest_Static. Emit an extra error message advising how to remedy the bad use of the predicate if the context warrants it. * sem_util.ads (Bad_Predicated_Subtype_Use): Add formal parameter Suggest_Static along with a comment explaining its usage. Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 198243) +++ sem_ch5.adb (working copy) @@ -2310,7 +2310,7 @@ then Bad_Predicated_Subtype_Use ("cannot use subtype& with non-static predicate for loop " & - "iteration", DS, Entity (DS)); + "iteration", DS, Entity (DS), Suggest_Static => True); end if; end if; Index: sem_util.adb =================================================================== --- sem_util.adb (revision 198287) +++ sem_util.adb (working copy) @@ -449,9 +449,10 @@ -------------------------------- procedure Bad_Predicated_Subtype_Use - (Msg : String; - N : Node_Id; - Typ : Entity_Id) + (Msg : String; + N : Node_Id; + Typ : Entity_Id; + Suggest_Static : Boolean := False) is begin if Has_Predicates (Typ) then @@ -465,6 +466,13 @@ else Error_Msg_FE (Msg, N, Typ); end if; + + -- Emit an optional suggestion on how to remedy the error if the + -- context warrants it. + + if Suggest_Static and then Present (Static_Predicate (Typ)) then + Error_Msg_FE ("\predicate of & should be marked static", N, Typ); + end if; end if; end Bad_Predicated_Subtype_Use; Index: sem_util.ads =================================================================== --- sem_util.ads (revision 198287) +++ sem_util.ads (working copy) @@ -122,19 +122,21 @@ -- is an error. procedure Bad_Predicated_Subtype_Use - (Msg : String; - N : Node_Id; - Typ : Entity_Id); + (Msg : String; + N : Node_Id; + Typ : Entity_Id; + Suggest_Static : Boolean := False); -- This is called when Typ, a predicated subtype, is used in a context - -- which does not allow the use of a predicated subtype. Msg is passed - -- to Error_Msg_FE to output an appropriate message using N as the - -- location, and Typ as the entity. The caller must set up any insertions - -- other than the & for the type itself. Note that if Typ is a generic - -- actual type, then the message will be output as a warning, and a - -- raise Program_Error is inserted using Insert_Action with node N as - -- the insertion point. Node N also supplies the source location for - -- construction of the raise node. If Typ is NOT a type with predicates - -- this call has no effect. + -- which does not allow the use of a predicated subtype. Msg is passed to + -- Error_Msg_FE to output an appropriate message using N as the location, + -- and Typ as the entity. The caller must set up any insertions other than + -- the & for the type itself. Note that if Typ is a generic actual type, + -- then the message will be output as a warning, and a raise Program_Error + -- is inserted using Insert_Action with node N as the insertion point. Node + -- N also supplies the source location for construction of the raise node. + -- If Typ does not have any predicates, the call has no effect. Set flag + -- Suggest_Static when the context warrants an advice on how to avoid the + -- use error. function Build_Actual_Subtype (T : Entity_Id; Index: sem_case.adb =================================================================== --- sem_case.adb (revision 198221) +++ sem_case.adb (working copy) @@ -1260,7 +1260,8 @@ then Bad_Predicated_Subtype_Use ("cannot use subtype& with non-static " - & "predicate as case alternative", Choice, E); + & "predicate as case alternative", Choice, E, + Suggest_Static => True); -- Static predicate case