Commit bd434b3f by Yannick Moy Committed by Arnaud Charlet

sem_aggr.adb (Resolve_Aggregate): disable incorrectly placed check in formal mode

2011-08-02  Yannick Moy  <moy@adacore.com>

	* sem_aggr.adb (Resolve_Aggregate): disable incorrectly placed check in
	formal mode
	* sem_util.adb (Matching_Static_Array_Bounds): proper detection of
	matching static array bounds, taking into account the special case of
	string literals
	* sem_ch3.adb: Typo in comment.

From-SVN: r177100
parent fe5d3068
2011-08-02 Yannick Moy <moy@adacore.com> 2011-08-02 Yannick Moy <moy@adacore.com>
* sem_aggr.adb (Resolve_Aggregate): disable incorrectly placed check in
formal mode
* sem_util.adb (Matching_Static_Array_Bounds): proper detection of
matching static array bounds, taking into account the special case of
string literals
* sem_ch3.adb: Typo in comment.
2011-08-02 Yannick Moy <moy@adacore.com>
* errout.adb, errout.ads (Check_Formal_Restriction): new procedure * errout.adb, errout.ads (Check_Formal_Restriction): new procedure
which issues an error in formal mode if its argument node is originally which issues an error in formal mode if its argument node is originally
from source from source
......
...@@ -1112,12 +1112,16 @@ package body Sem_Aggr is ...@@ -1112,12 +1112,16 @@ package body Sem_Aggr is
Check_Formal_Restriction Check_Formal_Restriction
("array aggregate should have only OTHERS", N); ("array aggregate should have only OTHERS", N);
end if; end if;
elsif not (Nkind (Parent (N)) = N_Aggregate
and then Is_Array_Type (Etype (Parent (N))) -- The following check is disabled until a proper place is
and then Number_Dimensions (Etype (Parent (N))) > 1) -- found where the type of the parent node can be inspected.
then
Check_Formal_Restriction -- elsif not (Nkind (Parent (N)) = N_Aggregate
("array aggregate should be qualified", N); -- and then Is_Array_Type (Etype (Parent (N)))
-- and then Number_Dimensions (Etype (Parent (N))) > 1)
-- then
-- Check_Formal_Restriction
-- ("array aggregate should be qualified", N);
else else
null; null;
end if; end if;
......
...@@ -11515,7 +11515,7 @@ package body Sem_Ch3 is ...@@ -11515,7 +11515,7 @@ package body Sem_Ch3 is
(Nkind (S) = N_Attribute_Reference (Nkind (S) = N_Attribute_Reference
and then Attribute_Name (S) = Name_Range) and then Attribute_Name (S) = Name_Range)
then then
-- A Range attribute will transformed into N_Range by Resolve -- A Range attribute will be transformed into N_Range by Resolve
Analyze (S); Analyze (S);
Set_Etype (S, T); Set_Etype (S, T);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU Genconflieral Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- -- -- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
...@@ -8013,8 +8013,10 @@ package body Sem_Util is ...@@ -8013,8 +8013,10 @@ package body Sem_Util is
R_Index : Node_Id; R_Index : Node_Id;
L_Low : Node_Id; L_Low : Node_Id;
L_High : Node_Id; L_High : Node_Id;
L_Len : Uint;
R_Low : Node_Id; R_Low : Node_Id;
R_High : Node_Id; R_High : Node_Id;
R_Len : Uint;
begin begin
if L_Ndims /= R_Ndims then if L_Ndims /= R_Ndims then
...@@ -8027,18 +8029,65 @@ package body Sem_Util is ...@@ -8027,18 +8029,65 @@ package body Sem_Util is
return False; return False;
end if; end if;
L_Index := First_Index (L_Typ); -- First treat specially the first dimension, as the lower bound and
R_Index := First_Index (R_Typ); -- length of string literals are not stored like those of arrays.
-- There may not be an index available even if the type is constrained, if Ekind (L_Typ) = E_String_Literal_Subtype then
-- see for example 0100-C23 when this function is called from L_Low := String_Literal_Low_Bound (L_Typ);
-- Resolve_Qualified_Expression. Temporarily return False in that case. L_Len := String_Literal_Length (L_Typ);
else
L_Index := First_Index (L_Typ);
Get_Index_Bounds (L_Index, L_Low, L_High);
if Is_OK_Static_Expression (L_Low)
and then Is_OK_Static_Expression (L_High)
then
if Expr_Value (L_High) < Expr_Value (L_Low) then
L_Len := Uint_0;
else
L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
end if;
else
return False;
end if;
end if;
if No (L_Index) or else No (R_Index) then if Ekind (R_Typ) = E_String_Literal_Subtype then
R_Low := String_Literal_Low_Bound (R_Typ);
R_Len := String_Literal_Length (R_Typ);
else
R_Index := First_Index (R_Typ);
Get_Index_Bounds (R_Index, R_Low, R_High);
if Is_OK_Static_Expression (R_Low)
and then Is_OK_Static_Expression (R_High)
then
if Expr_Value (R_High) < Expr_Value (R_Low) then
R_Len := Uint_0;
else
R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
end if;
else
return False;
end if;
end if;
if Is_OK_Static_Expression (L_Low)
and then Is_OK_Static_Expression (R_Low)
and then Expr_Value (L_Low) = Expr_Value (R_Low)
and then L_Len = R_Len
then
null;
else
return False; return False;
end if; end if;
for Indx in 1 .. L_Ndims loop -- Then treat all other dimensions
for Indx in 2 .. L_Ndims loop
Next (L_Index);
Next (R_Index);
Get_Index_Bounds (L_Index, L_Low, L_High); Get_Index_Bounds (L_Index, L_Low, L_High);
Get_Index_Bounds (R_Index, R_Low, R_High); Get_Index_Bounds (R_Index, R_Low, R_High);
...@@ -8049,9 +8098,7 @@ package body Sem_Util is ...@@ -8049,9 +8098,7 @@ package body Sem_Util is
and then Expr_Value (L_Low) = Expr_Value (R_Low) and then Expr_Value (L_Low) = Expr_Value (R_Low)
and then Expr_Value (L_High) = Expr_Value (R_High) and then Expr_Value (L_High) = Expr_Value (R_High)
then then
Next (L_Index); null;
Next (R_Index);
else else
return False; return False;
end if; end if;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment