@@ -1000,6 +1000,8 @@ package body Tree_Walk is
10001000 return Symbol
10011001 is
10021002 U : constant Node_Id := Unit (N);
1003+ Unit_Name : constant Symbol_Id :=
1004+ Intern (Unique_Name (Unique_Defining_Entity (U)));
10031005 Unit_Symbol : Symbol;
10041006 begin
10051007 -- Insert all all specifications of all withed units including the
@@ -1008,29 +1010,26 @@ package body Tree_Walk is
10081010
10091011 case Nkind (U) is
10101012 when N_Subprogram_Body =>
1011- declare
1012- Unit_Name : constant Symbol_Id :=
1013- Intern (Unique_Name (Unique_Defining_Entity (U)));
1014- begin
1015- -- The specification of the subprogram body has already
1016- -- been inserted into the symbol table by the call to
1017- -- Do_Withed_Unit_Specs.
1018- pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1019- Unit_Symbol := Global_Symbol_Table (Unit_Name);
1013+ -- The specification of the subprogram body has already
1014+ -- been inserted into the symbol table by the call to
1015+ -- Do_Withed_Unit_Specs.
1016+ pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1017+ Unit_Symbol := Global_Symbol_Table (Unit_Name);
10201018
1021- -- Now compile the body of the subprogram
1022- Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1019+ -- Now compile the body of the subprogram
1020+ Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
10231021
1024- -- and update the symbol table entry for this subprogram.
1025- Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1026- Unit_Is_Subprogram := True;
1027- end ;
1022+ -- and update the symbol table entry for this subprogram.
1023+ Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1024+ Unit_Is_Subprogram := True;
10281025
10291026 when N_Package_Body =>
10301027 declare
10311028 Dummy : constant Irep := Do_Subprogram_Or_Block (U);
10321029 pragma Unreferenced (Dummy);
10331030 begin
1031+ pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1032+ Unit_Symbol := Global_Symbol_Table (Unit_Name);
10341033 Unit_Is_Subprogram := False;
10351034 end ;
10361035
@@ -3575,7 +3574,35 @@ package body Tree_Walk is
35753574
35763575 procedure Do_Package_Specification (N : Node_Id) is
35773576 Package_Decs : constant Irep := New_Irep (I_Code_Block);
3577+ Package_Name : Symbol_Id;
3578+ Package_Symbol : Symbol;
3579+ Def_Unit_Name : Node_Id;
3580+ Entity_Node : Node_Id;
3581+
35783582 begin
3583+ Def_Unit_Name := Defining_Unit_Name (N);
3584+
3585+ -- Defining_Unit_Name will return a N_Defining_Identifier
3586+ -- for non-child package but a N_Package_Specification when it is a
3587+ -- child package.
3588+ -- To obtain the Entity N_Defining_Identifier is required.
3589+ -- The actual parameter for Unique_Name must be an Entity node.
3590+ if Nkind (Def_Unit_Name) = N_Defining_Identifier then
3591+ Entity_Node := Def_Unit_Name;
3592+ else
3593+ Entity_Node := Defining_Identifier (Def_Unit_Name);
3594+ end if ;
3595+
3596+ Package_Name := Intern (Unique_Name (Entity_Node));
3597+ Package_Symbol.Name := Package_Name;
3598+ Package_Symbol.BaseName := Package_Name;
3599+ Package_Symbol.PrettyName := Package_Name;
3600+ Package_Symbol.SymType := New_Irep (I_Void_Type);
3601+ Package_Symbol.Mode := Intern (" C" );
3602+ Package_Symbol.Value := Make_Nil (Sloc (N));
3603+
3604+ Global_Symbol_Table.Insert (Package_Name, Package_Symbol);
3605+
35793606 Set_Source_Location (Package_Decs, Sloc (N));
35803607 if Present (Visible_Declarations (N)) then
35813608 Process_Declarations (Visible_Declarations (N), Package_Decs);
@@ -4373,8 +4400,9 @@ package body Tree_Walk is
43734400 when N_Package_Body =>
43744401 null ;
43754402 when others =>
4376- Put_Line (Standard_Error,
4377- " This type of library_unit is not yet handled" );
4403+ Report_Unhandled_Node_Empty
4404+ (N, " Do_Withed_Unit_Spec" ,
4405+ " This type of library_unit is not yet handled" );
43784406 end case ;
43794407
43804408 end if ;
0 commit comments