diff options
author | Ed Schonberg <schonberg@adacore.com> | 2008-05-20 14:51:06 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2008-05-20 14:51:06 +0200 |
commit | cd2fb9207ace61a867ce118129cdb4ecc0d0a8f7 (patch) | |
tree | 58ffa095bc0a26a7fc70336e3aa0ee6d87556e53 | |
parent | 4b1c635450494b9aa044f355cb4fb87fcc0841eb (diff) | |
download | gcc-cd2fb9207ace61a867ce118129cdb4ecc0d0a8f7.zip gcc-cd2fb9207ace61a867ce118129cdb4ecc0d0a8f7.tar.gz gcc-cd2fb9207ace61a867ce118129cdb4ecc0d0a8f7.tar.bz2 |
2008-05-20 Ed Schonberg <schonberg@adacore.com>
* sem_eval.adb
(Eval_Slice): Warn when a slice whose discrete range is a subtype name
denotes the whole array of its prefix.
From-SVN: r135643
-rw-r--r-- | gcc/ada/sem_eval.adb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 9801df6..c03f11a 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -2678,6 +2678,35 @@ package body Sem_Eval is Check_Non_Static_Context (Low_Bound (Drange)); Check_Non_Static_Context (High_Bound (Drange)); end if; + + -- A slice of the form A (subtype), when the subtype is the index of + -- the type of A, is redundant, the slice can be replaced with A, and + -- this is worth a warning. + + if Is_Entity_Name (Prefix (N)) then + declare + E : constant Entity_Id := Entity (Prefix (N)); + T : constant Entity_Id := Etype (E); + begin + if Ekind (E) = E_Constant + and then Is_Array_Type (T) + and then Is_Entity_Name (Drange) + then + if Is_Entity_Name (Original_Node (First_Index (T))) + and then Entity (Original_Node (First_Index (T))) + = Entity (Drange) + then + if Warn_On_Redundant_Constructs then + Error_Msg_N ("redundant slice denotes whole array?", N); + end if; + + -- The following might be a useful optimization ???? + + -- Rewrite (N, New_Occurrence_Of (E, Sloc (N))); + end if; + end if; + end; + end if; end Eval_Slice; ------------------------- @@ -3309,9 +3338,12 @@ package body Sem_Eval is -- For a result of type integer, substitute an N_Integer_Literal node -- for the result of the compile time evaluation of the expression. + -- For ASIS use, set a link to the original named number when not in + -- a generic context. if Is_Integer_Type (Typ) then Rewrite (N, Make_Integer_Literal (Loc, Val)); + Set_Original_Entity (N, Ent); -- Otherwise we have an enumeration type, and we substitute either @@ -3355,6 +3387,9 @@ package body Sem_Eval is end if; Rewrite (N, Make_Real_Literal (Loc, Realval => Val)); + + -- Set link to original named number, for ASIS use. + Set_Original_Entity (N, Ent); -- Both the actual and expected type comes from the original expression |