From patchwork Mon Oct 4 13:43:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 66653 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 8C2B4B70D3 for ; Tue, 5 Oct 2010 00:43:44 +1100 (EST) Received: (qmail 24790 invoked by alias); 4 Oct 2010 13:43:42 -0000 Received: (qmail 24780 invoked by uid 22791); 4 Oct 2010 13:43:40 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, 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; Mon, 04 Oct 2010 13:43:34 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 0E6A8CB0245; Mon, 4 Oct 2010 15:43:32 +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 cleFDScq-gpD; Mon, 4 Oct 2010 15:43:31 +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 EC64FCB022B; Mon, 4 Oct 2010 15:43:31 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id CEED3D9BB4; Mon, 4 Oct 2010 15:43:31 +0200 (CEST) Date: Mon, 4 Oct 2010 15:43:31 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Factor duplicated code in expansion of record assignments Message-ID: <20101004134331.GA19663@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 change factors some duplicated code in the circuitry that handles record assignments. Code refactoring with no behaviour change, no test. Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-04 Thomas Quinot * exp_ch5.adb (Make_Field_Expr): New subprogram, to factor duplicated code between Make_Component_List_Assign and Make_Field_Assign. Index: exp_ch5.adb =================================================================== --- exp_ch5.adb (revision 164935) +++ exp_ch5.adb (working copy) @@ -1041,7 +1041,7 @@ package body Exp_Ch5 is -- Note that on the last iteration of the loop, the index is increased -- (or decreased) past the corresponding bound. This is consistent with -- the C semantics of the back-end, where such an off-by-one value on a - -- dead index variable is OK. However, in CodePeer mode this leads to + -- dead index variable is OK. However, in CodePeer mode this leads to -- spurious warnings, and thus we place a guard around the attribute -- reference. For obvious reasons we only do this for CodePeer. @@ -1223,6 +1223,13 @@ package body Exp_Ch5 is -- declaration for Typ. We need to use the actual entity because the -- type may be private and resolution by identifier alone would fail. + function Make_Field_Expr + (Comp_Ent : Entity_Id; + U_U : Boolean) return Node_Id; + -- Common processing for one component for Make_Component_List_Assign + -- and Make_Field_Assign. Return the expression to be assigned for + -- component Comp_Ent. + function Make_Component_List_Assign (CL : Node_Id; U_U : Boolean := False) return List_Id; @@ -1232,7 +1239,7 @@ package body Exp_Ch5 is -- part expression as the switch for the generated case statement. function Make_Field_Assign - (C : Entity_Id; + (C : Entity_Id; U_U : Boolean := False) return Node_Id; -- Given C, the entity for a discriminant or component, build an -- assignment for the corresponding field values. The flag U_U @@ -1282,7 +1289,6 @@ package body Exp_Ch5 is Alts : List_Id; DC : Node_Id; DCH : List_Id; - Expr : Node_Id; Result : List_Id; V : Node_Id; @@ -1308,28 +1314,9 @@ package body Exp_Ch5 is Next_Non_Pragma (V); end loop; - -- If we have an Unchecked_Union, use the value of the inferred - -- discriminant of the variant part expression as the switch - -- for the case statement. The case statement may later be - -- folded. - - if U_U then - Expr := - New_Copy (Get_Discriminant_Value ( - Entity (Name (VP)), - Etype (Rhs), - Discriminant_Constraint (Etype (Rhs)))); - else - Expr := - Make_Selected_Component (Loc, - Prefix => Duplicate_Subexpr (Rhs), - Selector_Name => - Make_Identifier (Loc, Chars (Name (VP)))); - end if; - Append_To (Result, Make_Case_Statement (Loc, - Expression => Expr, + Expression => Make_Field_Expr (Entity (Name (VP)), U_U), Alternatives => Alts)); end if; @@ -1341,36 +1328,23 @@ package body Exp_Ch5 is ----------------------- function Make_Field_Assign - (C : Entity_Id; + (C : Entity_Id; U_U : Boolean := False) return Node_Id is A : Node_Id; - Expr : Node_Id; begin -- In the case of an Unchecked_Union, use the discriminant -- constraint value as on the right hand side of the assignment. - if U_U then - Expr := - New_Copy (Get_Discriminant_Value (C, - Etype (Rhs), - Discriminant_Constraint (Etype (Rhs)))); - else - Expr := - Make_Selected_Component (Loc, - Prefix => Duplicate_Subexpr (Rhs), - Selector_Name => New_Occurrence_Of (C, Loc)); - end if; - A := Make_Assignment_Statement (Loc, - Name => + Name => Make_Selected_Component (Loc, - Prefix => Duplicate_Subexpr (Lhs), + Prefix => Duplicate_Subexpr (Lhs), Selector_Name => New_Occurrence_Of (Find_Component (L_Typ, C), Loc)), - Expression => Expr); + Expression => Make_Field_Expr (C, U_U)); -- Set Assignment_OK, so discriminants can be assigned @@ -1395,8 +1369,9 @@ package body Exp_Ch5 is Result : List_Id; begin - Item := First (CI); Result := New_List; + + Item := First (CI); while Present (Item) loop -- Look for components, but exclude _tag field assignment if @@ -1404,7 +1379,7 @@ package body Exp_Ch5 is if Nkind (Item) = N_Component_Declaration and then not (Is_Tag (Defining_Identifier (Item)) - and then Componentwise_Assignment (N)) + and then Componentwise_Assignment (N)) then Append_To (Result, Make_Field_Assign (Defining_Identifier (Item))); @@ -1416,6 +1391,32 @@ package body Exp_Ch5 is return Result; end Make_Field_Assigns; + --------------------- + -- Make_Field_Expr -- + --------------------- + + function Make_Field_Expr + (Comp_Ent : Entity_Id; + U_U : Boolean) return Node_Id + is + begin + -- If we have an Unchecked_Union, use the value of the inferred + -- discriminant of the variant part expression. + + if U_U then + return + New_Copy (Get_Discriminant_Value + (Comp_Ent, + Etype (Rhs), + Discriminant_Constraint (Etype (Rhs)))); + else + return + Make_Selected_Component (Loc, + Prefix => Duplicate_Subexpr (Rhs), + Selector_Name => New_Occurrence_Of (Comp_Ent, Loc)); + end if; + end Make_Field_Expr; + -- Start of processing for Expand_Assign_Record begin