aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/styleg.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2010-09-09 11:44:34 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2010-09-09 11:44:34 +0200
commit498d1b808eea93dc9e08db1e8a7f9af4dc3bcb90 (patch)
tree076b2e23e245fd1f10b39412c01d91d898d23801 /gcc/ada/styleg.adb
parent821b8ef47bc9cd196526e61b9426be24ffdd6eca (diff)
downloadgcc-498d1b808eea93dc9e08db1e8a7f9af4dc3bcb90.zip
gcc-498d1b808eea93dc9e08db1e8a7f9af4dc3bcb90.tar.gz
gcc-498d1b808eea93dc9e08db1e8a7f9af4dc3bcb90.tar.bz2
[multiple changes]
2010-09-09 Robert Dewar <dewar@adacore.com> * a-calfor.adb, sem_ch3.adb: Minor reformatting. 2010-09-09 Robert Dewar <dewar@adacore.com> * bindgen.adb (Gen_Restrictions_Ada): Avoid explicit enumeration ranges (Gen_Restrictions_C): Avoid explicit enumeration ranges (Set_String_Replace): New procedure * casing.ads (Known_Casing): New subtype declaration * prj-attr.ads (All_Case_Insensitive_Associative_Array): New subtype declaration * prj-dect.adb (Parse_Attribute_Declaration): Avoid enumeration range * prj-nmsc.adb (Check_Naming): Avoid unnecessary enumeration range * prj-strt.adb (Attribute_Reference): Avoid enumeration range test * prj.adb (Known_Casing): Moved to Casing spec (avoid enum range) * sem_ch13.adb (Adjust_Record_For_Reverse_Bit_Order): Avoid enumeration ranges * sem_res.adb (Resolve_Range): Check for enumeration subrange style rule * sem_type.adb (Is_Array_Class_Record_Type): New. * style.ads (Check_Enumeration_Subrange): New procedure * styleg.adb (Check_Enumeration_Subrange): New procedure * styleg.ads (Check_Enumeration_Subrange): New procedure * stylesw.adb Add handling for Style_Check_Enumeration_Subranges * stylesw.ads (Style_Check_Enumeration_Subranges): New flag * usage.adb: Add line for -gnatyE * vms_data.ads: Add entries for [NO]ENUMERATION_RANGES Add missing entry for NOBOOLEAN_OPERATORS * gnat_ugn.texi: Add documentation for -gnatyE 2010-09-09 Robert Dewar <dewar@adacore.com> * namet.adb (Initialize): Is now a dummy procedure (Reinitialize): New procedure Call Reinitialize from package initialization * namet.ads (Initialize): Is now a dummy procedure (Reinitialize): New procedure * clean.adb, gnat1drv.adb, gnatbind.adb, gnatcmd.adb, gnatlink.adb, gnatls.adb, gprep.adb, make.adb, prj-makr.adb: Remove obsolete call to Namet.Initialize. 2010-09-09 Bob Duff <duff@adacore.com> * sem_elab.adb, s-os_lib.ads: Minor comment fixes. 2010-09-09 Robert Dewar <dewar@adacore.com> * s-bitops.adb (Raise_Error): Add exception message From-SVN: r164058
Diffstat (limited to 'gcc/ada/styleg.adb')
-rw-r--r--gcc/ada/styleg.adb79
1 files changed, 79 insertions, 0 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb
index 1c22dbc..c19a096 100644
--- a/gcc/ada/styleg.adb
+++ b/gcc/ada/styleg.adb
@@ -32,10 +32,13 @@ with Casing; use Casing;
with Csets; use Csets;
with Einfo; use Einfo;
with Err_Vars; use Err_Vars;
+with Lib; use Lib;
+with Namet; use Namet;
with Opt; use Opt;
with Scans; use Scans;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
+with Snames; use Snames;
with Stylesw; use Stylesw;
package body Styleg is
@@ -550,6 +553,82 @@ package body Styleg is
end if;
end Check_Dot_Dot;
+ --------------------------------
+ -- Check_Enumeration_Subrange --
+ --------------------------------
+
+ procedure Check_Enumeration_Subrange (N : Node_Id) is
+ function First_Last_Ref return Boolean;
+ -- Returns True if N is of the form X'First .. X'Last where X is the
+ -- same entity for both attributes. N is already known to be N_Range.
+
+ --------------------
+ -- First_Last_Ref --
+ --------------------
+
+ function First_Last_Ref return Boolean is
+ L : constant Node_Id := Low_Bound (N);
+ H : constant Node_Id := High_Bound (N);
+
+ begin
+ if Nkind (L) = N_Attribute_Reference
+ and then Nkind (H) = N_Attribute_Reference
+ and then Attribute_Name (L) = Name_First
+ and then Attribute_Name (H) = Name_Last
+ then
+ declare
+ PL : constant Node_Id := Prefix (L);
+ PH : constant Node_Id := Prefix (H);
+ begin
+ if Is_Entity_Name (PL)
+ and then Is_Entity_Name (PH)
+ and then Entity (PL) = Entity (PH)
+ then
+ return True;
+ end if;
+ end;
+ end if;
+
+ return False;
+ end First_Last_Ref;
+
+ -- Start of processing for Check_Enumeration_Subrange
+
+ begin
+ if Style_Check_Enumeration_Subranges then
+
+ if Nkind (N) = N_Range
+
+ -- Only consider ranges that are explicit in the source
+
+ and then Comes_From_Source (N)
+
+ -- Only consider enumeration types
+
+ and then Is_Enumeration_Type (Etype (N))
+
+ -- Exclude standard types. Most importantly we want to exclude the
+ -- standard character types, since we want to allow ranges like
+ -- '0' .. '9'. But also exclude Boolean since False .. True is OK.
+
+ and then Sloc (Root_Type (Etype (N))) /= Standard_Location
+
+ -- Exclude X'First .. X'Last if X is the same entity for both
+
+ and then not First_Last_Ref
+
+ -- Allow the range if in same unit as type declaration (or the
+ -- corresponding body or any of its subunits).
+
+ and then not In_Same_Extended_Unit (N, Etype (N))
+ then
+ Error_Msg
+ ("(style) explicit enumeration subrange not allowed",
+ Sloc (N));
+ end if;
+ end if;
+ end Check_Enumeration_Subrange;
+
---------------
-- Check_EOF --
---------------