From patchwork Thu Jun 17 22:22:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 56095 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 A4C81B7D8B for ; Fri, 18 Jun 2010 08:23:23 +1000 (EST) Received: (qmail 5390 invoked by alias); 17 Jun 2010 22:23:22 -0000 Received: (qmail 5381 invoked by uid 22791); 17 Jun 2010 22:23:21 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_TM 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, 17 Jun 2010 22:23:17 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 12E78CB02C2; Fri, 18 Jun 2010 00:23:23 +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 tvLUSNZavDtb; Fri, 18 Jun 2010 00:23:23 +0200 (CEST) Received: from [192.168.1.2] (91-163-136-98.rev.libertysurf.net [91.163.136.98]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id B2EB7CB01E2; Fri, 18 Jun 2010 00:23:22 +0200 (CEST) From: Eric Botcazou To: Arnaud Charlet Subject: Re: [Ada] Implement new Expression_With_Actions node Date: Fri, 18 Jun 2010 00:22:21 +0200 User-Agent: KMail/1.9.9 Cc: gcc-patches@gcc.gnu.org, Robert Dewar References: <20100617155451.GA26562@adacore.com> In-Reply-To: <20100617155451.GA26562@adacore.com> MIME-Version: 1.0 Message-Id: <201006180022.21647.ebotcazou@adacore.com> 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 does not include the required gigi adjustments to process > this new node (which is why it is under a debug flag for now), so with > only this patch, the above test compiled with -gnatd.X will blowup > in gigi. Eric will commit the corresponding support for > N_Expression_With_Actions in gigi later. Here it is. Tested on i586-suse-linux, applied on the mainline. 2010-06-17 Eric Botcazou * gcc-interfaces/trans.c (set_gnu_expr_location_from_node): New static function. (gnat_to_gnu) : New case. Use set_gnu_expr_location_from_node to set location information on the final result. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 160936) +++ gcc-interface/trans.c (working copy) @@ -204,6 +204,7 @@ static tree extract_values (tree, tree); static tree pos_to_constructor (Node_Id, tree, Entity_Id); static tree maybe_implicit_deref (tree); static void set_expr_location_from_node (tree, Node_Id); +static void set_gnu_expr_location_from_node (tree, Node_Id); static int lvalue_required_p (Node_Id, tree, bool, bool, bool); /* Hooks for debug info back-ends, only supported and used in a restricted set @@ -5317,6 +5318,19 @@ gnat_to_gnu (Node_Id gnat_node) /* Added Nodes */ /****************/ + case N_Expression_With_Actions: + gnu_result_type = get_unpadded_type (Etype (gnat_node)); + /* This construct doesn't define a scope so we don't wrap the statement + list in a BIND_EXPR; however, we wrap it in a SAVE_EXPR to protect it + from unsharing. */ + gnu_result = build_stmt_group (Actions (gnat_node), false); + gnu_result = build1 (SAVE_EXPR, void_type_node, gnu_result); + TREE_SIDE_EFFECTS (gnu_result) = 1; + gnu_expr = gnat_to_gnu (Expression (gnat_node)); + gnu_result + = build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr), gnu_result, gnu_expr); + break; + case N_Freeze_Entity: start_stmt_group (); process_freeze_entity (gnat_node); @@ -5536,17 +5550,11 @@ gnat_to_gnu (Node_Id gnat_node) convert (gnu_result_type, boolean_false_node)); - /* Set the location information on the result if it is a real expression. - References can be reused for multiple GNAT nodes and they would get - the location information of their last use. Note that we may have + /* Set the location information on the result. Note that we may have no result if we tried to build a CALL_EXPR node to a procedure with no side-effects and optimization is enabled. */ - if (gnu_result - && EXPR_P (gnu_result) - && TREE_CODE (gnu_result) != NOP_EXPR - && !REFERENCE_CLASS_P (gnu_result) - && !EXPR_HAS_LOCATION (gnu_result)) - set_expr_location_from_node (gnu_result, gnat_node); + if (gnu_result && EXPR_P (gnu_result)) + set_gnu_expr_location_from_node (gnu_result, gnat_node); /* If we're supposed to return something of void_type, it means we have something we're elaborating for effect, so just return. */ @@ -7450,6 +7458,37 @@ set_expr_location_from_node (tree node, SET_EXPR_LOCATION (node, locus); } + +/* More elaborate version of set_expr_location_from_node to be used in more + general contexts, for example the result of the translation of a generic + GNAT node. */ + +static void +set_gnu_expr_location_from_node (tree node, Node_Id gnat_node) +{ + /* Set the location information on the node if it is a real expression. + References can be reused for multiple GNAT nodes and they would get + the location information of their last use. Also make sure not to + overwrite an existing location as it is probably more precise. */ + + switch (TREE_CODE (node)) + { + CASE_CONVERT: + case NON_LVALUE_EXPR: + break; + + case COMPOUND_EXPR: + if (EXPR_P (TREE_OPERAND (node, 1))) + set_gnu_expr_location_from_node (TREE_OPERAND (node, 1), gnat_node); + + /* ... fall through ... */ + + default: + if (!REFERENCE_CLASS_P (node) && !EXPR_HAS_LOCATION (node)) + set_expr_location_from_node (node, gnat_node); + break; + } +} /* Return a colon-separated list of encodings contained in encoded Ada name. */