@@ -150,6 +150,8 @@ package body Instrument.C is
150150 -- Convert low level SCOs in each scope for each file to high-level SCOs
151151 -- using the mapping in SCO_Map. Set the file's SCO range to cover all of
152152 -- its scopes' SCO ranges.
153+ --
154+ -- Also remove from the Scopes map empty file scopes.
153155
154156 overriding procedure Append_SCO
155157 (Pass : Instrument_Pass_Kind;
@@ -491,10 +493,6 @@ package body Instrument.C is
491493 UIC : in out C_Unit_Inst_Context'Class;
492494 N : Cursor_T)
493495 is
494- Inserted : Boolean;
495-
496- File_Scope_Position : Scopes_In_Files_Map.Cursor;
497-
498496 procedure Enter_File_Scope
499497 (UIC : in out C_Unit_Inst_Context'Class;
500498 SFI : Source_File_Index)
@@ -508,7 +506,11 @@ package body Instrument.C is
508506
509507 procedure Enter_File_Scope
510508 (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;
512514 begin
513515 if not UIC.Scopes.Contains (SFI) then
514516
@@ -629,24 +631,26 @@ package body Instrument.C is
629631
630632 procedure Remap_Scopes
631633 (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;
633637 begin
634638 for Cur in Scopes.Iterate loop
635639 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);
640644 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
642646
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);
647650 end if ;
648651 end ;
649652 end loop ;
653+ Scopes := Res;
650654 end Remap_Scopes ;
651655
652656 -- --------------
@@ -3290,23 +3294,23 @@ package body Instrument.C is
32903294 -- Associate these bit maps to the corresponding CU
32913295
32923296 Set_Bit_Maps (UIC.CUs.Element (SFI), Bit_Maps);
3297+ end ;
3298+ end loop ;
32933299
3294- -- Iterate through the package level body entities
3300+ -- Iterate through the package level body entities
32953301
3296- Remap_Scopes (UIC.Scopes, SCO_Map);
3302+ Remap_Scopes (UIC.Scopes, SCO_Map);
32973303
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 ;
33103314 end ;
33113315 end loop ;
33123316 end ;
0 commit comments