sem_aggr.adb (Valid_Ancestor_Type): Add support for C++ constructors.
authorJavier Miranda <miranda@adacore.com>
Wed, 6 May 2009 09:23:53 +0000 (09:23 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 6 May 2009 09:23:53 +0000 (11:23 +0200)
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

gcc/ada/ChangeLog
gcc/ada/exp_aggr.adb
gcc/ada/sem_aggr.adb

index bb3f3a3453fb688db55c7b9b58917e72387539d3..2376b82bdf82a800f8f38760a3ad3304d6edc61a 100644 (file)
@@ -1,3 +1,14 @@
+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>
 
        * freeze.adb (Freeze_Record_Type): Improve error msg for bad size
index 6645bea388d92b949f1fb50c180a4955970d919a..90473b77547be380de21547d3f212d9a0c096fd4 100644 (file)
@@ -2519,22 +2519,14 @@ package body Exp_Aggr is
                Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
                Set_Assignment_OK (Ref);
 
-               if Has_Default_Init_Comps (N)
-                 or else Has_Task (Base_Type (Init_Typ))
-               then
-                  Append_List_To (L,
-                    Build_Initialization_Call (Loc,
-                      Id_Ref       => Ref,
-                      Typ          => Init_Typ,
-                      In_Init_Proc => Within_Init_Proc,
-                      With_Default_Init => True));
-               else
-                  Append_List_To (L,
-                    Build_Initialization_Call (Loc,
-                      Id_Ref       => Ref,
-                      Typ          => Init_Typ,
-                      In_Init_Proc => Within_Init_Proc));
-               end if;
+               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)
+                                          or else
+                                        Has_Task (Base_Type (Init_Typ))));
 
                if Is_Constrained (Entity (A))
                  and then Has_Discriminants (Entity (A))
@@ -2542,6 +2534,21 @@ package body Exp_Aggr is
                   Check_Ancestor_Discriminants (Entity (A));
                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
             --  limited type, a recursive call expands the ancestor. Note that
             --  in the limited case, the ancestor part must be either a
index 974e01fe0513a6886b6fe43f7bec48f59dbf0c37..8837e8c0347cad7ce389cbe40accec68b04c131d 100644 (file)
@@ -2175,6 +2175,11 @@ package body Sem_Aggr is
             if Etype (Imm_Type) = Base_Type (A_Type) then
                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
             --  extension if it is declared as such in a parent unit of
             --  the current one. For consistency of the subsequent analysis
@@ -2290,6 +2295,7 @@ package body Sem_Aggr is
 
             if Is_Class_Wide_Type (Etype (A))
               and then Nkind (Original_Node (A)) = N_Function_Call
+              and then not Is_CPP_Constructor_Call (Original_Node (A))
             then
                --  If the ancestor part is a dispatching call, it appears
                --  statically to be a legal ancestor, but it yields any
@@ -3070,7 +3076,13 @@ package body Sem_Aggr is
             --  of all ancestors, starting with the root.
 
             if Nkind (N) = N_Extension_Aggregate then
-               Root_Typ := Base_Type (Etype (Ancestor_Part (N)));
+               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)));
+               end if;
             else
                Root_Typ := Root_Type (Typ);