@@ -150,6 +150,8 @@ package body Instrument.C is
150
150
-- Convert low level SCOs in each scope for each file to high-level SCOs
151
151
-- using the mapping in SCO_Map. Set the file's SCO range to cover all of
152
152
-- its scopes' SCO ranges.
153
+ --
154
+ -- Also remove from the Scopes map empty file scopes.
153
155
154
156
overriding procedure Append_SCO
155
157
(Pass : Instrument_Pass_Kind;
@@ -491,10 +493,6 @@ package body Instrument.C is
491
493
UIC : in out C_Unit_Inst_Context'Class;
492
494
N : Cursor_T)
493
495
is
494
- Inserted : Boolean;
495
-
496
- File_Scope_Position : Scopes_In_Files_Map.Cursor;
497
-
498
496
procedure Enter_File_Scope
499
497
(UIC : in out C_Unit_Inst_Context'Class;
500
498
SFI : Source_File_Index)
@@ -508,7 +506,11 @@ package body Instrument.C is
508
506
509
507
procedure Enter_File_Scope
510
508
(UIC : in out C_Unit_Inst_Context'Class;
511
- SFI : Source_File_Index) is
509
+ SFI : Source_File_Index)
510
+ is
511
+ File_Scope_Position : Scopes_In_Files_Map.Cursor;
512
+
513
+ Inserted : Boolean;
512
514
begin
513
515
if not UIC.Scopes.Contains (SFI) then
514
516
@@ -629,24 +631,26 @@ package body Instrument.C is
629
631
630
632
procedure Remap_Scopes
631
633
(Scopes : in out Scopes_In_Files_Map.Map;
632
- SCO_Map : LL_HL_SCO_Map) is
634
+ SCO_Map : LL_HL_SCO_Map)
635
+ is
636
+ Res : Scopes_In_Files_Map.Map;
633
637
begin
634
638
for Cur in Scopes.Iterate loop
635
639
declare
636
- Ref : constant Scopes_In_Files_Map.Reference_Type :=
637
- Scopes.Reference (Cur);
638
- File_Scope : Scope_Entity renames
639
- Scope_Entities_Trees.Element (Ref .File_Scope_Entity);
640
+ File_Scope : File_Scope_Type :=
641
+ Scopes_In_Files_Map.Element (Cur);
642
+ File_Scope_Entity : Scope_Entity renames
643
+ Scope_Entities_Trees.Element (File_Scope .File_Scope_Entity);
640
644
begin
641
- -- If the file scope is empty, remove it
645
+ -- If the file scope is empty, do not add it to the resulting map
642
646
643
- if File_Scope.To < File_Scope.From then
644
- Ref.Scope_Entities.Delete_Subtree (Ref.File_Scope_Entity);
645
- else
646
- Remap_Scope_Entities (Ref.Scope_Entities, SCO_Map);
647
+ if File_Scope_Entity.To >= File_Scope_Entity.From then
648
+ Remap_Scope_Entities (File_Scope.Scope_Entities, SCO_Map);
649
+ Res.Insert (Scopes_In_Files_Map.Key (Cur), File_Scope);
647
650
end if ;
648
651
end ;
649
652
end loop ;
653
+ Scopes := Res;
650
654
end Remap_Scopes ;
651
655
652
656
-- --------------
@@ -3290,23 +3294,23 @@ package body Instrument.C is
3290
3294
-- Associate these bit maps to the corresponding CU
3291
3295
3292
3296
Set_Bit_Maps (UIC.CUs.Element (SFI), Bit_Maps);
3297
+ end ;
3298
+ end loop ;
3293
3299
3294
- -- Iterate through the package level body entities
3300
+ -- Iterate through the package level body entities
3295
3301
3296
- Remap_Scopes (UIC.Scopes, SCO_Map);
3302
+ Remap_Scopes (UIC.Scopes, SCO_Map);
3297
3303
3298
- for C in UIC.Scopes.Iterate loop
3299
- declare
3300
- CU : constant Created_Unit_Maps.Cursor :=
3301
- UIC.CUs.Find (Scopes_In_Files_Map.Key (C));
3302
- begin
3303
- if Created_Unit_Maps.Has_Element (CU) then
3304
- Set_Scope_Entities
3305
- (Created_Unit_Maps.Element (CU),
3306
- Scopes_In_Files_Map.Element (C).Scope_Entities);
3307
- end if ;
3308
- end ;
3309
- end loop ;
3304
+ for C in UIC.Scopes.Iterate loop
3305
+ declare
3306
+ CU : constant Created_Unit_Maps.Cursor :=
3307
+ UIC.CUs.Find (Scopes_In_Files_Map.Key (C));
3308
+ begin
3309
+ if Created_Unit_Maps.Has_Element (CU) then
3310
+ Set_Scope_Entities
3311
+ (Created_Unit_Maps.Element (CU),
3312
+ Scopes_In_Files_Map.Element (C).Scope_Entities);
3313
+ end if ;
3310
3314
end ;
3311
3315
end loop ;
3312
3316
end ;
0 commit comments