|
| 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;
|
@@ -204,6 +207,12 @@ package body Tree_Walk is
|
204 | 207 | function Do_Op_Not (N : Node_Id) return Irep
|
205 | 208 | with Pre => Nkind (N) in N_Op;
|
206 | 209 |
|
| 210 | + procedure Do_Package_Declaration (N : Node_Id) |
| 211 | + with Pre => Nkind (N) = N_Package_Declaration; |
| 212 | + |
| 213 | + procedure Do_Package_Specification (N : Node_Id) |
| 214 | + with Pre => Nkind (N) = N_Package_Specification; |
| 215 | + |
207 | 216 | function Do_Procedure_Call_Statement (N : Node_Id) return Irep
|
208 | 217 | with Pre => Nkind (N) = N_Procedure_Call_Statement,
|
209 | 218 | Post => Kind (Do_Procedure_Call_Statement'Result) =
|
@@ -276,6 +285,16 @@ package body Tree_Walk is
|
276 | 285 | Post => Kind (Do_Unconstrained_Array_Definition'Result) =
|
277 | 286 | I_Struct_Type;
|
278 | 287 |
|
| 288 | + procedure Do_Withed_Unit_Spec (N : Node_Id); |
| 289 | + -- Enters the specification of the withed unit, N, into the symbol table |
| 290 | + |
| 291 | + procedure Do_Withed_Units_Specs is new Sem.Walk_Library_Items |
| 292 | + (Action => Do_Withed_Unit_Spec); |
| 293 | + -- Traverses tree applying the procedure Do_With_Unit_Spec to all nodes |
| 294 | + -- which are specifications of library units withed by the GNAT_Root unit |
| 295 | + -- (that is, the body being compiled). |
| 296 | + -- It starts with the unit Standard and finishes with GNAT_Root |
| 297 | + |
279 | 298 | function Find_Record_Variant (Variant_Part : Node_Id;
|
280 | 299 | Actual_Disc : Node_Id) return Node_Id
|
281 | 300 | with Pre => Nkind (Variant_Part) = N_Variant_Part,
|
@@ -1245,24 +1264,26 @@ package body Tree_Walk is
|
1245 | 1264 | U : constant Node_Id := Unit (N);
|
1246 | 1265 | Unit_Symbol : Symbol;
|
1247 | 1266 | begin
|
| 1267 | + -- Insert all all specifications of all withed units including the |
| 1268 | + -- specification of the given compilation unit into the symbol table. |
| 1269 | + Do_Withed_Units_Specs; |
| 1270 | + |
1248 | 1271 | case Nkind (U) is
|
1249 | 1272 | when N_Subprogram_Body =>
|
1250 | 1273 | declare
|
1251 |
| - Unit_Type : constant Irep := |
1252 |
| - Do_Subprogram_Specification (Specification (U)); |
1253 | 1274 | Unit_Name : constant Symbol_Id :=
|
1254 | 1275 | Intern (Unique_Name (Unique_Defining_Entity (U)));
|
1255 | 1276 | begin
|
1256 |
| - -- Register the symbol *before* we compile the body, for |
1257 |
| - -- recursive calls. |
1258 |
| - Unit_Symbol.Name := Unit_Name; |
1259 |
| - Unit_Symbol.PrettyName := Unit_Name; |
1260 |
| - Unit_Symbol.BaseName := Unit_Name; |
1261 |
| - Unit_Symbol.Mode := Intern ("C"); |
1262 |
| - Unit_Symbol.SymType := Unit_Type; |
1263 |
| - Global_Symbol_Table.Insert (Unit_Name, Unit_Symbol); |
1264 |
| - |
1265 |
| - Unit_Symbol.Value := Do_Subprogram_Or_Block (U); |
| 1277 | + -- The specification of the subprogram body has already |
| 1278 | + -- been inserted into the symbol table by the call to |
| 1279 | + -- Do_Withed_Unit_Specs. |
| 1280 | + pragma Assert (Global_Symbol_Table.Contains (Unit_Name)); |
| 1281 | + Unit_Symbol := Global_Symbol_Table (Unit_Name); |
| 1282 | + |
| 1283 | + -- Now compile the body of the subprogram |
| 1284 | + Unit_Symbol.Value := Do_Subprogram_Or_Block (U); |
| 1285 | + |
| 1286 | + -- and update the symbol table entry for this subprogram. |
1266 | 1287 | Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
|
1267 | 1288 | Add_Start := True;
|
1268 | 1289 | end;
|
@@ -3502,6 +3523,31 @@ package body Tree_Walk is
|
3502 | 3523 | return Ret;
|
3503 | 3524 | end Do_Operator_Simple;
|
3504 | 3525 |
|
| 3526 | + ---------------------------- |
| 3527 | + -- Do_Package_Declaration -- |
| 3528 | + ---------------------------- |
| 3529 | + |
| 3530 | + procedure Do_Package_Declaration (N : Node_Id) is |
| 3531 | + begin |
| 3532 | + Do_Package_Specification (Specification (N)); |
| 3533 | + end Do_Package_Declaration; |
| 3534 | + |
| 3535 | + ---------------------------- |
| 3536 | + -- Do_Package_Specification -- |
| 3537 | + ---------------------------- |
| 3538 | + |
| 3539 | + procedure Do_Package_Specification (N : Node_Id) is |
| 3540 | + Package_Decs : constant Irep := New_Irep (I_Code_Block); |
| 3541 | + begin |
| 3542 | + Set_Source_Location (Package_Decs, Sloc (N)); |
| 3543 | + if Present (Visible_Declarations (N)) then |
| 3544 | + Process_Declarations (Visible_Declarations (N), Package_Decs); |
| 3545 | + end if; |
| 3546 | + if Present (Private_Declarations (N)) then |
| 3547 | + Process_Declarations (Private_Declarations (N), Package_Decs); |
| 3548 | + end if; |
| 3549 | + end Do_Package_Specification; |
| 3550 | + |
3505 | 3551 | ---------------------------------
|
3506 | 3552 | -- Do_Procedure_Call_Statement --
|
3507 | 3553 | ---------------------------------
|
@@ -3985,18 +4031,18 @@ package body Tree_Walk is
|
3985 | 4031 | function Do_Subprogram_Or_Block (N : Node_Id) return Irep is
|
3986 | 4032 | Decls : constant List_Id := Declarations (N);
|
3987 | 4033 | HSS : constant Node_Id := Handled_Statement_Sequence (N);
|
3988 |
| - Decls_Rep : Irep; |
| 4034 | + Reps : constant Irep := New_Irep (I_Code_Block); |
3989 | 4035 | begin
|
3990 |
| - Decls_Rep := (if Present (Decls) |
3991 |
| - then Process_Statements (Decls) |
3992 |
| - else New_Irep (I_Code_Block)); |
| 4036 | + if Present (Decls) then |
| 4037 | + Process_Declarations (Decls, Reps); |
| 4038 | + end if; |
3993 | 4039 |
|
3994 |
| - Set_Source_Location (Decls_Rep, Sloc (N)); |
| 4040 | + Set_Source_Location (Reps, Sloc (N)); |
3995 | 4041 | if Present (HSS) then
|
3996 |
| - Process_Statement (HSS, Decls_Rep); |
| 4042 | + Process_Statement (HSS, Reps); |
3997 | 4043 | end if;
|
3998 | 4044 |
|
3999 |
| - return Decls_Rep; |
| 4045 | + return Reps; |
4000 | 4046 | end Do_Subprogram_Or_Block;
|
4001 | 4047 |
|
4002 | 4048 | --------------------------------
|
@@ -4256,6 +4302,54 @@ package body Tree_Walk is
|
4256 | 4302 |
|
4257 | 4303 | end Do_Unconstrained_Array_Definition;
|
4258 | 4304 |
|
| 4305 | + ------------------------- |
| 4306 | + -- Do_Withed_Unit_Spec -- |
| 4307 | + ------------------------- |
| 4308 | + |
| 4309 | + procedure Do_Withed_Unit_Spec (N : Node_Id) is |
| 4310 | + Unit_Name : constant String := Get_Name_String (Get_Unit_Name (N)); |
| 4311 | + begin |
| 4312 | + if Defining_Entity (N) = Stand.Standard_Standard or else |
| 4313 | + Unit_Name = "system%s" |
| 4314 | + then |
| 4315 | + null; |
| 4316 | + -- At the moment Standard or System are not processed - to be done |
| 4317 | + else |
| 4318 | + |
| 4319 | + case Nkind (N) is |
| 4320 | + when N_Subprogram_Body => |
| 4321 | + if Acts_As_Spec (N) then |
| 4322 | + -- The unit is a withed library unit which subprogram body |
| 4323 | + -- that has no separate declaration, or, |
| 4324 | + -- it is the subprogram body of the compilation unit being |
| 4325 | + -- compiled and it has no separate declaration. |
| 4326 | + -- Obtain the subprogram specification from the body |
| 4327 | + -- and insert it into the symbol table. |
| 4328 | + Register_Subprogram_Specification (Specification (N)); |
| 4329 | + else |
| 4330 | + null; |
| 4331 | + end if; |
| 4332 | + when N_Subprogram_Declaration => |
| 4333 | + -- The unit is withed library unit that is a subprogram |
| 4334 | + -- declaration, or, |
| 4335 | + -- it is the declaration of the compilation unit body being |
| 4336 | + -- compiled. |
| 4337 | + -- Do_Subprogram_Declaration enters the specification of the |
| 4338 | + -- subprogram into the symbol table. |
| 4339 | + Do_Subprogram_Declaration (N); |
| 4340 | + when N_Package_Declaration => |
| 4341 | + Do_Package_Declaration (N); |
| 4342 | + when N_Package_Body => |
| 4343 | + null; |
| 4344 | + when others => |
| 4345 | + Put_Line (Standard_Error, |
| 4346 | + "This type of library_unit is not yet handled"); |
| 4347 | + end case; |
| 4348 | + |
| 4349 | + end if; |
| 4350 | + |
| 4351 | + end Do_Withed_Unit_Spec; |
| 4352 | + |
4259 | 4353 | -------------------------
|
4260 | 4354 | -- Find_Record_Variant --
|
4261 | 4355 | -------------------------
|
|
0 commit comments