From patchwork Tue Jun 22 08:36:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56411 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 84802B6F10 for ; Tue, 22 Jun 2010 18:36:59 +1000 (EST) Received: (qmail 24033 invoked by alias); 22 Jun 2010 08:36:54 -0000 Received: (qmail 24022 invoked by uid 22791); 22 Jun 2010 08:36:51 -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; Tue, 22 Jun 2010 08:36:45 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B2810CB024F; Tue, 22 Jun 2010 10:36:46 +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 8xb2LqVdA+bF; Tue, 22 Jun 2010 10:36:46 +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 9EE72CB022F; Tue, 22 Jun 2010 10:36:46 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 94A13D9B31; Tue, 22 Jun 2010 10:36:46 +0200 (CEST) Date: Tue, 22 Jun 2010 10:36:46 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Fix missing style checks on entity name casing Message-ID: <20100622083646.GA28882@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 fixes some missed cases of checking proper spelling (capitalization) of references to entities as follows: Non overloaded enumeration literals Parent package names in subunits Field names in record component references The following example, compiled with -gnatyaknpr shows four messages that were previously missed. 1. -- gnatmake -gnatyaknpr casing.adb 2. procedure Casing is 3. 4. package S is 5. type T is (abc, xyz); 6. end S; 7. 8. package Sep is 9. type T is (Abc, Xyz); 10. function F return Boolean; 11. end Sep; 12. 13. package body Sep is separate; 14. 15. begin 16. null; 17. end Casing; 1. separate (CASING) -- Casing | >>> (style) bad casing of "Casing" declared at casing.adb:2 2. package body Sep is 3. Global_Var : T := Abc; 4. 5. type Record_Var_T is record 6. Field : Integer; 7. end record; 8. 9. Record_Var : Record_Var_T; 10. 11. function F return Boolean is 12. begin 13. Record_Var := Record_Var_T'(FIELD => 1); -- Field | >>> (style) bad casing of "Field" declared at line 6 14. case Global_Var is 15. when ABC => -- Abc | >>> (style) bad casing of "Abc" declared at casing.adb:9 16. return True; 17. when XYZ => -- Xyz | >>> (style) bad casing of "Xyz" declared at casing.adb:9 18. return False; 19. end case; 20. end F; 21. end Sep; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-22 Robert Dewar * sem_aggr.adb (Resolve_Record_Aggregate): Do style check on component name. * sem_ch10.adb (Analyze_Subunit): Do style check on parent unit name. * sem_ch8.adb (Find_Direct_Name): For non-overloadable entities, do style check. * sem_res.adb (Resolve_Entity_Name): Do style check for enumeration literals. Index: sem_aggr.adb =================================================================== --- sem_aggr.adb (revision 161142) +++ sem_aggr.adb (working copy) @@ -54,6 +54,7 @@ with Sinfo; use Sinfo; with Snames; use Snames; with Stringt; use Stringt; with Stand; use Stand; +with Style; use Style; with Targparm; use Targparm; with Tbuild; use Tbuild; with Uintp; use Uintp; @@ -3779,7 +3780,15 @@ package body Sem_Aggr is New_Assoc := First (New_Assoc_List); while Present (New_Assoc) loop Component := First (Choices (New_Assoc)); - exit when Chars (Selectr) = Chars (Component); + + if Chars (Selectr) = Chars (Component) then + if Style_Check then + Check_Identifier (Selectr, Entity (Component)); + end if; + + exit; + end if; + Next (New_Assoc); end loop; Index: sem_ch10.adb =================================================================== --- sem_ch10.adb (revision 161142) +++ sem_ch10.adb (working copy) @@ -2140,6 +2140,19 @@ package body Sem_Ch10 is -- Start of processing for Analyze_Subunit begin + if Style_Check then + declare + Nam : Node_Id := Name (Unit (N)); + + begin + if Nkind (Nam) = N_Selected_Component then + Nam := Selector_Name (Nam); + end if; + + Check_Identifier (Nam, Par_Unit); + end; + end if; + if not Is_Empty_List (Context_Items (N)) then -- Save current use clauses Index: sem_res.adb =================================================================== --- sem_res.adb (revision 161143) +++ sem_res.adb (working copy) @@ -5793,6 +5793,14 @@ package body Sem_Res is Set_Etype (N, Typ); Eval_Named_Real (N); + -- For enumeration literals, we need to make sure that a proper style + -- check is done, since such literals are overloaded, and thus we did + -- not do a style check during the first phase of analysis. + + elsif Ekind (E) = E_Enumeration_Literal then + Set_Entity_With_Style_Check (N, E); + Eval_Entity_Name (N); + -- Allow use of subtype only if it is a concurrent type where we are -- currently inside the body. This will eventually be expanded into a -- call to Self (for tasks) or _object (for protected objects). Any @@ -5847,7 +5855,6 @@ package body Sem_Res is and then not In_Spec_Expression and then not Is_Imported (E) then - if No_Initialization (Parent (E)) or else (Present (Full_View (E)) and then No_Initialization (Parent (Full_View (E)))) Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 161143) +++ sem_ch8.adb (working copy) @@ -4377,13 +4377,18 @@ package body Sem_Ch8 is return; end if; - -- Set the entity. Note that the reason we call Set_Entity here, as - -- opposed to Set_Entity_With_Style_Check is that in the overloaded - -- case, the initial call can set the wrong homonym. The call that - -- sets the right homonym is in Sem_Res and that call does use - -- Set_Entity_With_Style_Check, so we don't miss a style check. + -- Set the entity. Note that the reason we call Set_Entity for the + -- overloadable case, as opposed to Set_Entity_With_Style_Check is + -- that in the overloaded case, the initial call can set the wrong + -- homonym. The call that sets the right homonym is in Sem_Res and + -- that call does use Set_Entity_With_Style_Check, so we don't miss + -- a style check. - Set_Entity (N, E); + if Is_Overloadable (E) then + Set_Entity (N, E); + else + Set_Entity_With_Style_Check (N, E); + end if; if Is_Type (E) then Set_Etype (N, E);