summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_aggr.adb
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-02 19:22:40 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-02 19:22:40 +0000
commite18a8ca20bda043a85e95113e7288b4170023785 (patch)
tree5903f739377a9d23396281e6491570f3103529de /gcc/ada/sem_aggr.adb
parentdabe786b59ca225bc2389fbfa5616e5ddd85d2fa (diff)
downloadgcc-e18a8ca20bda043a85e95113e7288b4170023785.tar.gz
2012-10-02 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 191993 using svnmerge.py git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@191994 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_aggr.adb')
-rw-r--r--gcc/ada/sem_aggr.adb131
1 files changed, 116 insertions, 15 deletions
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 993235210bb..e73b8758386 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -47,6 +47,7 @@ with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
+with Sem_Dim; use Sem_Dim;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
@@ -1726,6 +1727,9 @@ package body Sem_Aggr is
Discard : Node_Id;
pragma Warnings (Off, Discard);
+ Delete_Choice : Boolean;
+ -- Used when replacing a subtype choice with predicate by a list
+
Aggr_Low : Node_Id := Empty;
Aggr_High : Node_Id := Empty;
-- The actual low and high bounds of this sub-aggregate
@@ -1766,6 +1770,8 @@ package body Sem_Aggr is
Assoc := First (Component_Associations (N));
while Present (Assoc) loop
Choice := First (Choices (Assoc));
+ Delete_Choice := False;
+
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Others_Present := True;
@@ -1792,10 +1798,56 @@ package body Sem_Aggr is
Error_Msg_N
("(Ada 83) illegal context for OTHERS choice", N);
end if;
+
+ elsif Is_Entity_Name (Choice) then
+ Analyze (Choice);
+
+ declare
+ E : constant Entity_Id := Entity (Choice);
+ New_Cs : List_Id;
+ P : Node_Id;
+ C : Node_Id;
+
+ begin
+ if Is_Type (E) and then Has_Predicates (E) then
+ Freeze_Before (N, E);
+
+ -- If the subtype has a static predicate, replace the
+ -- original choice with the list of individual values
+ -- covered by the predicate.
+
+ if Present (Static_Predicate (E)) then
+ Delete_Choice := True;
+
+ New_Cs := New_List;
+ P := First (Static_Predicate (E));
+ while Present (P) loop
+ C := New_Copy (P);
+ Set_Sloc (C, Sloc (Choice));
+ Append_To (New_Cs, C);
+ Next (P);
+ end loop;
+
+ Insert_List_After (Choice, New_Cs);
+ end if;
+ end if;
+ end;
end if;
Nb_Choices := Nb_Choices + 1;
- Next (Choice);
+
+ declare
+ C : constant Node_Id := Choice;
+
+ begin
+ Next (Choice);
+
+ if Delete_Choice then
+ Remove (C);
+ Nb_Choices := Nb_Choices - 1;
+ Delete_Choice := False;
+ end if;
+ end;
end loop;
Next (Assoc);
@@ -1998,6 +2050,7 @@ package body Sem_Aggr is
Nb_Discrete_Choices := Nb_Discrete_Choices + 1;
Table (Nb_Discrete_Choices).Choice_Lo := Low;
Table (Nb_Discrete_Choices).Choice_Hi := High;
+ Table (Nb_Discrete_Choices).Choice_Node := Choice;
Next (Choice);
@@ -2115,7 +2168,7 @@ package body Sem_Aggr is
then
Error_Msg_N
("duplicate choice values in array aggregate",
- Table (J).Choice_Hi);
+ Table (J).Choice_Node);
return Failure;
elsif not Others_Present then
@@ -2497,6 +2550,10 @@ package body Sem_Aggr is
Duplicate_Subexpr (High_Bound (Aggregate_Bounds (N))));
end if;
+ -- Check the dimensions of each component in the array aggregate
+
+ Analyze_Dimension_Array_Aggregate (N, Component_Typ);
+
return Success;
end Resolve_Array_Aggregate;
@@ -2876,6 +2933,14 @@ package body Sem_Aggr is
-- An error message is emitted if the components taking their value from
-- the others choice do not have same type.
+ function New_Copy_Tree_And_Copy_Dimensions
+ (Source : Node_Id;
+ Map : Elist_Id := No_Elist;
+ New_Sloc : Source_Ptr := No_Location;
+ New_Scope : Entity_Id := Empty) return Node_Id;
+ -- Same as New_Copy_Tree (defined in Sem_Util), except that this routine
+ -- also copies the dimensions of Source to the returned node.
+
procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Node_Id);
-- Analyzes and resolves expression Expr against the Etype of the
-- Component. This routine also applies all appropriate checks to Expr.
@@ -3077,7 +3142,7 @@ package body Sem_Aggr is
if Expander_Active then
return
- New_Copy_Tree
+ New_Copy_Tree_And_Copy_Dimensions
(Expression (Parent (Compon)),
New_Sloc => Sloc (Assoc));
else
@@ -3096,7 +3161,9 @@ package body Sem_Aggr is
Others_Etype := Etype (Compon);
if Expander_Active then
- return New_Copy_Tree (Expression (Assoc));
+ return
+ New_Copy_Tree_And_Copy_Dimensions
+ (Expression (Assoc));
else
return Expression (Assoc);
end if;
@@ -3132,18 +3199,20 @@ package body Sem_Aggr is
-- order to create a proper association for the
-- expanded aggregate.
- Expr := New_Copy_Tree (Expression (Parent (Compon)));
-
-- Component may have no default, in which case the
-- expression is empty and the component is default-
-- initialized, but an association for the component
-- exists, and it is not covered by an others clause.
- return Expr;
+ return
+ New_Copy_Tree_And_Copy_Dimensions
+ (Expression (Parent (Compon)));
else
if Present (Next (Selector_Name)) then
- Expr := New_Copy_Tree (Expression (Assoc));
+ Expr :=
+ New_Copy_Tree_And_Copy_Dimensions
+ (Expression (Assoc));
else
Expr := Expression (Assoc);
end if;
@@ -3168,13 +3237,33 @@ package body Sem_Aggr is
return Expr;
end Get_Value;
+ ---------------------------------------
+ -- New_Copy_Tree_And_Copy_Dimensions --
+ ---------------------------------------
+
+ function New_Copy_Tree_And_Copy_Dimensions
+ (Source : Node_Id;
+ Map : Elist_Id := No_Elist;
+ New_Sloc : Source_Ptr := No_Location;
+ New_Scope : Entity_Id := Empty) return Node_Id
+ is
+ New_Copy : constant Node_Id :=
+ New_Copy_Tree (Source, Map, New_Sloc, New_Scope);
+ begin
+ -- Move the dimensions of Source to New_Copy
+
+ Copy_Dimensions (Source, New_Copy);
+ return New_Copy;
+ end New_Copy_Tree_And_Copy_Dimensions;
+
-----------------------
-- Resolve_Aggr_Expr --
-----------------------
procedure Resolve_Aggr_Expr (Expr : Node_Id; Component : Node_Id) is
- New_C : Entity_Id := Component;
Expr_Type : Entity_Id := Empty;
+ New_C : Entity_Id := Component;
+ New_Expr : Node_Id;
function Has_Expansion_Delayed (Expr : Node_Id) return Boolean;
-- If the expression is an aggregate (possibly qualified) then its
@@ -3328,10 +3417,18 @@ package body Sem_Aggr is
end if;
if Relocate then
- Add_Association (New_C, Relocate_Node (Expr), New_Assoc_List);
+ New_Expr := Relocate_Node (Expr);
+
+ -- Since New_Expr is not gonna be analyzed later on, we need to
+ -- propagate here the dimensions form Expr to New_Expr.
+
+ Copy_Dimensions (Expr, New_Expr);
+
else
- Add_Association (New_C, Expr, New_Assoc_List);
+ New_Expr := Expr;
end if;
+
+ Add_Association (New_C, New_Expr, New_Assoc_List);
end Resolve_Aggr_Expr;
-- Start of processing for Resolve_Record_Aggregate
@@ -3920,7 +4017,7 @@ package body Sem_Aggr is
and then Present (Expression (Parent (Component)))
then
Expr :=
- New_Copy_Tree
+ New_Copy_Tree_And_Copy_Dimensions
(Expression (Parent (Component)),
New_Scope => Current_Scope,
New_Sloc => Sloc (N));
@@ -3983,6 +4080,7 @@ package body Sem_Aggr is
-- We build a partially initialized aggregate with the
-- values of the discriminants and box initialization
-- for the rest, if other components are present.
+
-- The type of the aggregate is the known subtype of
-- the component. The capture of discriminants must
-- be recursive because subcomponents may be constrained
@@ -4337,9 +4435,8 @@ package body Sem_Aggr is
Next (New_Assoc);
end loop;
- -- If no association, this is not a legal component of
- -- of the type in question, except if its association
- -- is provided with a box.
+ -- If no association, this is not a legal component of the type
+ -- in question, unless its association is provided with a box.
if No (New_Assoc) then
if Box_Present (Parent (Selectr)) then
@@ -4438,6 +4535,10 @@ package body Sem_Aggr is
Rewrite (N, New_Aggregate);
end Step_8;
+
+ -- Check the dimensions of the components in the record aggregate
+
+ Analyze_Dimension_Extension_Or_Record_Aggregate (N);
end Resolve_Record_Aggregate;
-----------------------------