|
| 1 | +with Uname; use Uname; |
| 2 | + |
1 | 3 | with Einfo; use Einfo;
|
2 | 4 | with Namet; use Namet;
|
3 | 5 | with Nlists; use Nlists;
|
| 6 | +with Sem; |
4 | 7 | with Sem_Util; use Sem_Util;
|
5 | 8 | with Sem_Aux; use Sem_Aux;
|
6 | 9 | with Snames; use Snames;
|
@@ -207,6 +210,12 @@ package body Tree_Walk is
|
207 | 210 | function Do_Op_Not (N : Node_Id) return Irep
|
208 | 211 | with Pre => Nkind (N) in N_Op;
|
209 | 212 |
|
| 213 | + procedure Do_Package_Declaration (N : Node_Id) |
| 214 | + with Pre => Nkind (N) = N_Package_Declaration; |
| 215 | + |
| 216 | + procedure Do_Package_Specification (N : Node_Id) |
| 217 | + with Pre => Nkind (N) = N_Package_Specification; |
| 218 | + |
210 | 219 | function Do_Procedure_Call_Statement (N : Node_Id) return Irep
|
211 | 220 | with Pre => Nkind (N) = N_Procedure_Call_Statement,
|
212 | 221 | Post => Kind (Do_Procedure_Call_Statement'Result) =
|
@@ -279,6 +288,16 @@ package body Tree_Walk is
|
279 | 288 | Post => Kind (Do_Unconstrained_Array_Definition'Result) =
|
280 | 289 | I_Struct_Type;
|
281 | 290 |
|
| 291 | + procedure Do_Withed_Unit_Spec (N : Node_Id); |
| 292 | + -- Enters the specification of the withed unit, N, into the symbol table |
| 293 | + |
| 294 | + procedure Do_Withed_Units_Specs is new Sem.Walk_Library_Items |
| 295 | + (Action => Do_Withed_Unit_Spec); |
| 296 | + -- Traverses tree applying the procedure Do_With_Unit_Spec to all nodes |
| 297 | + -- which are specifications of library units withed by the GNAT_Root unit |
| 298 | + -- (that is, the body being compiled). |
| 299 | + -- It starts with the unit Standard and finishes with GNAT_Root |
| 300 | + |
282 | 301 | function Find_Record_Variant (Variant_Part : Node_Id;
|
283 | 302 | Actual_Disc : Node_Id) return Node_Id
|
284 | 303 | with Pre => Nkind (Variant_Part) = N_Variant_Part,
|
@@ -1271,24 +1290,26 @@ package body Tree_Walk is
|
1271 | 1290 | U : constant Node_Id := Unit (N);
|
1272 | 1291 | Unit_Symbol : Symbol;
|
1273 | 1292 | begin
|
| 1293 | + -- Insert all all specifications of all withed units including the |
| 1294 | + -- specification of the given compilation unit into the symbol table. |
| 1295 | + Do_Withed_Units_Specs; |
| 1296 | + |
1274 | 1297 | case Nkind (U) is
|
1275 | 1298 | when N_Subprogram_Body =>
|
1276 | 1299 | declare
|
1277 |
| - Unit_Type : constant Irep := |
1278 |
| - Do_Subprogram_Specification (Specification (U)); |
1279 | 1300 | Unit_Name : constant Symbol_Id :=
|
1280 | 1301 | Intern (Unique_Name (Unique_Defining_Entity (U)));
|
1281 | 1302 | begin
|
1282 |
| - -- Register the symbol *before* we compile the body, for |
1283 |
| - -- recursive calls. |
1284 |
| - Unit_Symbol.Name := Unit_Name; |
1285 |
| - Unit_Symbol.PrettyName := Unit_Name; |
1286 |
| - Unit_Symbol.BaseName := Unit_Name; |
1287 |
| - Unit_Symbol.Mode := Intern ("C"); |
1288 |
| - Unit_Symbol.SymType := Unit_Type; |
1289 |
| - Global_Symbol_Table.Insert (Unit_Name, Unit_Symbol); |
1290 |
| - |
1291 |
| - Unit_Symbol.Value := Do_Subprogram_Or_Block (U); |
| 1303 | + -- The specification of the subprogram body has already |
| 1304 | + -- been inserted into the symbol table by the call to |
| 1305 | + -- Do_Withed_Unit_Specs. |
| 1306 | + pragma Assert (Global_Symbol_Table.Contains (Unit_Name)); |
| 1307 | + Unit_Symbol := Global_Symbol_Table (Unit_Name); |
| 1308 | + |
| 1309 | + -- Now compile the body of the subprogram |
| 1310 | + Unit_Symbol.Value := Do_Subprogram_Or_Block (U); |
| 1311 | + |
| 1312 | + -- and update the symbol table entry for this subprogram. |
1292 | 1313 | Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
|
1293 | 1314 | Add_Start := True;
|
1294 | 1315 | end;
|
@@ -3528,6 +3549,31 @@ package body Tree_Walk is
|
3528 | 3549 | return Ret;
|
3529 | 3550 | end Do_Operator_Simple;
|
3530 | 3551 |
|
| 3552 | + ---------------------------- |
| 3553 | + -- Do_Package_Declaration -- |
| 3554 | + ---------------------------- |
| 3555 | + |
| 3556 | + procedure Do_Package_Declaration (N : Node_Id) is |
| 3557 | + begin |
| 3558 | + Do_Package_Specification (Specification (N)); |
| 3559 | + end Do_Package_Declaration; |
| 3560 | + |
| 3561 | + ---------------------------- |
| 3562 | + -- Do_Package_Specification -- |
| 3563 | + ---------------------------- |
| 3564 | + |
| 3565 | + procedure Do_Package_Specification (N : Node_Id) is |
| 3566 | + Package_Decs : constant Irep := New_Irep (I_Code_Block); |
| 3567 | + begin |
| 3568 | + Set_Source_Location (Package_Decs, Sloc (N)); |
| 3569 | + if Present (Visible_Declarations (N)) then |
| 3570 | + Process_Declarations (Visible_Declarations (N), Package_Decs); |
| 3571 | + end if; |
| 3572 | + if Present (Private_Declarations (N)) then |
| 3573 | + Process_Declarations (Private_Declarations (N), Package_Decs); |
| 3574 | + end if; |
| 3575 | + end Do_Package_Specification; |
| 3576 | + |
3531 | 3577 | ---------------------------------
|
3532 | 3578 | -- Do_Procedure_Call_Statement --
|
3533 | 3579 | ---------------------------------
|
@@ -4011,18 +4057,18 @@ package body Tree_Walk is
|
4011 | 4057 | function Do_Subprogram_Or_Block (N : Node_Id) return Irep is
|
4012 | 4058 | Decls : constant List_Id := Declarations (N);
|
4013 | 4059 | HSS : constant Node_Id := Handled_Statement_Sequence (N);
|
4014 |
| - Decls_Rep : Irep; |
| 4060 | + Reps : constant Irep := New_Irep (I_Code_Block); |
4015 | 4061 | begin
|
4016 |
| - Decls_Rep := (if Present (Decls) |
4017 |
| - then Process_Statements (Decls) |
4018 |
| - else New_Irep (I_Code_Block)); |
| 4062 | + if Present (Decls) then |
| 4063 | + Process_Declarations (Decls, Reps); |
| 4064 | + end if; |
4019 | 4065 |
|
4020 |
| - Set_Source_Location (Decls_Rep, Sloc (N)); |
| 4066 | + Set_Source_Location (Reps, Sloc (N)); |
4021 | 4067 | if Present (HSS) then
|
4022 |
| - Process_Statement (HSS, Decls_Rep); |
| 4068 | + Process_Statement (HSS, Reps); |
4023 | 4069 | end if;
|
4024 | 4070 |
|
4025 |
| - return Decls_Rep; |
| 4071 | + return Reps; |
4026 | 4072 | end Do_Subprogram_Or_Block;
|
4027 | 4073 |
|
4028 | 4074 | --------------------------------
|
@@ -4282,6 +4328,54 @@ package body Tree_Walk is
|
4282 | 4328 |
|
4283 | 4329 | end Do_Unconstrained_Array_Definition;
|
4284 | 4330 |
|
| 4331 | + ------------------------- |
| 4332 | + -- Do_Withed_Unit_Spec -- |
| 4333 | + ------------------------- |
| 4334 | + |
| 4335 | + procedure Do_Withed_Unit_Spec (N : Node_Id) is |
| 4336 | + Unit_Name : constant String := Get_Name_String (Get_Unit_Name (N)); |
| 4337 | + begin |
| 4338 | + if Defining_Entity (N) = Stand.Standard_Standard or else |
| 4339 | + Unit_Name = "system%s" |
| 4340 | + then |
| 4341 | + null; |
| 4342 | + -- At the moment Standard or System are not processed - to be done |
| 4343 | + else |
| 4344 | + |
| 4345 | + case Nkind (N) is |
| 4346 | + when N_Subprogram_Body => |
| 4347 | + if Acts_As_Spec (N) then |
| 4348 | + -- The unit is a withed library unit which subprogram body |
| 4349 | + -- that has no separate declaration, or, |
| 4350 | + -- it is the subprogram body of the compilation unit being |
| 4351 | + -- compiled and it has no separate declaration. |
| 4352 | + -- Obtain the subprogram specification from the body |
| 4353 | + -- and insert it into the symbol table. |
| 4354 | + Register_Subprogram_Specification (Specification (N)); |
| 4355 | + else |
| 4356 | + null; |
| 4357 | + end if; |
| 4358 | + when N_Subprogram_Declaration => |
| 4359 | + -- The unit is withed library unit that is a subprogram |
| 4360 | + -- declaration, or, |
| 4361 | + -- it is the declaration of the compilation unit body being |
| 4362 | + -- compiled. |
| 4363 | + -- Do_Subprogram_Declaration enters the specification of the |
| 4364 | + -- subprogram into the symbol table. |
| 4365 | + Do_Subprogram_Declaration (N); |
| 4366 | + when N_Package_Declaration => |
| 4367 | + Do_Package_Declaration (N); |
| 4368 | + when N_Package_Body => |
| 4369 | + null; |
| 4370 | + when others => |
| 4371 | + Put_Line (Standard_Error, |
| 4372 | + "This type of library_unit is not yet handled"); |
| 4373 | + end case; |
| 4374 | + |
| 4375 | + end if; |
| 4376 | + |
| 4377 | + end Do_Withed_Unit_Spec; |
| 4378 | + |
4285 | 4379 | -------------------------
|
4286 | 4380 | -- Find_Record_Variant --
|
4287 | 4381 | -------------------------
|
|
0 commit comments