Commit 11795185 by Javier Miranda Committed by Arnaud Charlet

sem_aggr.adb (Valid_Ancestor_Type): Add support for C++ constructors.

2009-05-06  Javier Miranda  <miranda@adacore.com>

	* sem_aggr.adb (Valid_Ancestor_Type): Add support for C++ constructors.
	(Resolve_Extension_Aggregate): Do not reject C++ constructors in
	extension aggregates.
	(Resolve_Record_Aggregate): Add support for C++ constructors in
	extension aggregates.

	* exp_aggr.adb (Build_Record_Aggr_Code): Add support for C++
	constructors in extension aggregates.

From-SVN: r147160
parent 426d2717
2009-05-06 Javier Miranda <miranda@adacore.com>
* sem_aggr.adb (Valid_Ancestor_Type): Add support for C++ constructors.
(Resolve_Extension_Aggregate): Do not reject C++ constructors in
extension aggregates.
(Resolve_Record_Aggregate): Add support for C++ constructors in
extension aggregates.
* exp_aggr.adb (Build_Record_Aggr_Code): Add support for C++
constructors in extension aggregates.
2009-05-06 Robert Dewar <dewar@adacore.com> 2009-05-06 Robert Dewar <dewar@adacore.com>
* freeze.adb (Freeze_Record_Type): Improve error msg for bad size * freeze.adb (Freeze_Record_Type): Improve error msg for bad size
......
...@@ -2519,22 +2519,14 @@ package body Exp_Aggr is ...@@ -2519,22 +2519,14 @@ package body Exp_Aggr is
Ref := Convert_To (Init_Typ, New_Copy_Tree (Target)); Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
Set_Assignment_OK (Ref); Set_Assignment_OK (Ref);
if Has_Default_Init_Comps (N)
or else Has_Task (Base_Type (Init_Typ))
then
Append_List_To (L, Append_List_To (L,
Build_Initialization_Call (Loc, Build_Initialization_Call (Loc,
Id_Ref => Ref, Id_Ref => Ref,
Typ => Init_Typ, Typ => Init_Typ,
In_Init_Proc => Within_Init_Proc, In_Init_Proc => Within_Init_Proc,
With_Default_Init => True)); With_Default_Init => Has_Default_Init_Comps (N)
else or else
Append_List_To (L, Has_Task (Base_Type (Init_Typ))));
Build_Initialization_Call (Loc,
Id_Ref => Ref,
Typ => Init_Typ,
In_Init_Proc => Within_Init_Proc));
end if;
if Is_Constrained (Entity (A)) if Is_Constrained (Entity (A))
and then Has_Discriminants (Entity (A)) and then Has_Discriminants (Entity (A))
...@@ -2542,6 +2534,21 @@ package body Exp_Aggr is ...@@ -2542,6 +2534,21 @@ package body Exp_Aggr is
Check_Ancestor_Discriminants (Entity (A)); Check_Ancestor_Discriminants (Entity (A));
end if; end if;
-- Handle calls to C++ constructors
elsif Is_CPP_Constructor_Call (A) then
Init_Typ := Etype (Etype (A));
Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
Set_Assignment_OK (Ref);
Append_List_To (L,
Build_Initialization_Call (Loc,
Id_Ref => Ref,
Typ => Init_Typ,
In_Init_Proc => Within_Init_Proc,
With_Default_Init => Has_Default_Init_Comps (N),
Constructor_Ref => A));
-- Ada 2005 (AI-287): If the ancestor part is an aggregate of -- Ada 2005 (AI-287): If the ancestor part is an aggregate of
-- limited type, a recursive call expands the ancestor. Note that -- limited type, a recursive call expands the ancestor. Note that
-- in the limited case, the ancestor part must be either a -- in the limited case, the ancestor part must be either a
......
...@@ -2175,6 +2175,11 @@ package body Sem_Aggr is ...@@ -2175,6 +2175,11 @@ package body Sem_Aggr is
if Etype (Imm_Type) = Base_Type (A_Type) then if Etype (Imm_Type) = Base_Type (A_Type) then
return True; return True;
elsif Is_CPP_Constructor_Call (A)
and then Etype (Imm_Type) = Base_Type (Etype (A_Type))
then
return True;
-- The base type of the parent type may appear as a private -- The base type of the parent type may appear as a private
-- extension if it is declared as such in a parent unit of -- extension if it is declared as such in a parent unit of
-- the current one. For consistency of the subsequent analysis -- the current one. For consistency of the subsequent analysis
...@@ -2290,6 +2295,7 @@ package body Sem_Aggr is ...@@ -2290,6 +2295,7 @@ package body Sem_Aggr is
if Is_Class_Wide_Type (Etype (A)) if Is_Class_Wide_Type (Etype (A))
and then Nkind (Original_Node (A)) = N_Function_Call and then Nkind (Original_Node (A)) = N_Function_Call
and then not Is_CPP_Constructor_Call (Original_Node (A))
then then
-- If the ancestor part is a dispatching call, it appears -- If the ancestor part is a dispatching call, it appears
-- statically to be a legal ancestor, but it yields any -- statically to be a legal ancestor, but it yields any
...@@ -3070,7 +3076,13 @@ package body Sem_Aggr is ...@@ -3070,7 +3076,13 @@ package body Sem_Aggr is
-- of all ancestors, starting with the root. -- of all ancestors, starting with the root.
if Nkind (N) = N_Extension_Aggregate then if Nkind (N) = N_Extension_Aggregate then
if Is_CPP_Constructor_Call (Ancestor_Part (N)) then
pragma Assert
(Is_Class_Wide_Type (Etype (Ancestor_Part (N))));
Root_Typ := Base_Type (Etype (Etype (Ancestor_Part (N))));
else
Root_Typ := Base_Type (Etype (Ancestor_Part (N))); Root_Typ := Base_Type (Etype (Ancestor_Part (N)));
end if;
else else
Root_Typ := Root_Type (Typ); Root_Typ := Root_Type (Typ);
......
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