From patchwork Wed Nov 23 10:54:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 127261 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 DA2951007D2 for ; Wed, 23 Nov 2011 21:54:47 +1100 (EST) Received: (qmail 2508 invoked by alias); 23 Nov 2011 10:54:44 -0000 Received: (qmail 2500 invoked by uid 22791); 23 Nov 2011 10:54:42 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 Nov 2011 10:54:29 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B18892BAEE7; Wed, 23 Nov 2011 05:54:28 -0500 (EST) 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 0DSveFI1l0cJ; Wed, 23 Nov 2011 05:54:28 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 948832BAED6; Wed, 23 Nov 2011 05:54:28 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 932AB3FEE8; Wed, 23 Nov 2011 05:54:28 -0500 (EST) Date: Wed, 23 Nov 2011 05:54:28 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Locate error message on the first line of a pre/post/invariant aspect Message-ID: <20111123105428.GA28018@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 The source location of an expression may not be the best place to put a mess in the case of a failed precondition/postcondition/invariant. For example, it gets located on the last "and" keyword in a chain of boolean expressiond and'ed together. It is best put the message on the first character of an assertion, which is done here. This is a follow-up of a previous patch that did the same for pragmas. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-11-23 Yannick Moy * sem_ch13.adb (Analyze_Aspect_Specifications): Place error on line of precondition/ postcondition/invariant. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 181654) +++ sem_ch13.adb (working copy) @@ -728,8 +728,9 @@ A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); Anod : Node_Id; - Eloc : Source_Ptr := Sloc (Expr); - -- Source location of expression, modified when we split PPC's + Eloc : Source_Ptr := No_Location; + -- Source location of expression, modified when we split PPC's. It + -- is set below when Expr is present. procedure Check_False_Aspect_For_Derived_Type; -- This procedure checks for the case of a false aspect for a @@ -804,6 +805,18 @@ goto Continue; end if; + -- Set the source location of expression, used in the case of + -- a failed precondition/postcondition or invariant. Note that + -- the source location of the expression is not usually the best + -- choice here. For example, it gets located on the last AND + -- keyword in a chain of boolean expressiond AND'ed together. + -- It is best to put the message on the first character of the + -- assertion, which is the effect of the First_Node call here. + + if Present (Expr) then + Eloc := Sloc (First_Node (Expr)); + end if; + -- Check restriction No_Implementation_Aspect_Specifications if Impl_Defined_Aspects (A_Id) then