From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix the -gnatyr switch so it works in record rep clauses
Date: Wed, 30 Jun 2021 05:30:46 -0400 [thread overview]
Message-ID: <20210630093046.GA2247@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 569 bytes --]
The -gnatyr switch is supposed to generate a style warning if the case
of a usage name does not match that of the defining_identifier it
denotes. The warning was missing for component names appearing in record
representation clauses; this patch fixes that bug.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_ch13.adb (Analyze_Record_Representation_Clause): Call
Set_Entity_With_Checks instead of Set_Entity, so we perform the
check for correct casing.
* style.adb (Check_Identifier): Minor comment improvement.
Cleanup overly complicated code.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 3290 bytes --]
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -8561,7 +8561,7 @@ package body Sem_Ch13 is
Generate_Reference
(Comp, Component_Name (CC), Set_Ref => False);
- Set_Entity (Component_Name (CC), Comp);
+ Set_Entity_With_Checks (Component_Name (CC), Comp);
-- Update Fbit and Lbit to the actual bit number
diff --git a/gcc/ada/style.adb b/gcc/ada/style.adb
--- a/gcc/ada/style.adb
+++ b/gcc/ada/style.adb
@@ -136,48 +136,42 @@ package body Style is
Tref := Source_Text (Get_Source_File_Index (Sref));
Tdef := Source_Text (Get_Source_File_Index (Sdef));
- -- Ignore operator name case completely. This also catches the
- -- case of where one is an operator and the other is not. This
- -- is a phenomenon from rewriting of operators as functions,
- -- and is to be ignored.
+ -- Ignore case of operator names. This also catches the case
+ -- where one is an operator and the other is not. This is a
+ -- phenomenon from rewriting of operators as functions, and is
+ -- to be ignored.
if Tref (Sref) = '"' or else Tdef (Sdef) = '"' then
return;
else
- while Tref (Sref) = Tdef (Sdef) loop
+ loop
+ -- If end of identifiers, all done. Note that they are the
+ -- same length.
- -- If end of identifier, all done
+ pragma Assert
+ (Identifier_Char (Tref (Sref)) =
+ Identifier_Char (Tdef (Sdef)));
if not Identifier_Char (Tref (Sref)) then
return;
-
- -- Otherwise loop continues
-
- else
- Sref := Sref + 1;
- Sdef := Sdef + 1;
end if;
- end loop;
- -- Fall through loop when mismatch between identifiers
- -- If either identifier is not terminated, error.
+ -- Case mismatch
- if Identifier_Char (Tref (Sref))
- or else
- Identifier_Char (Tdef (Sdef))
- then
- Error_Msg_Node_1 := Def;
- Error_Msg_Sloc := Sloc (Def);
- Error_Msg -- CODEFIX
- ("(style) bad casing of & declared#", Sref, Ref);
- return;
+ if Tref (Sref) /= Tdef (Sdef) then
+ Error_Msg_Node_1 := Def;
+ Error_Msg_Sloc := Sloc (Def);
+ Error_Msg -- CODEFIX
+ ("(style) bad casing of & declared#", Sref, Ref);
+ return;
+ end if;
- -- Else end of identifiers, and they match
+ Sref := Sref + 1;
+ Sdef := Sdef + 1;
+ end loop;
- else
- return;
- end if;
+ pragma Assert (False);
end if;
end if;
reply other threads:[~2021-06-30 9:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210630093046.GA2247@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).