From d985daf8d54419f00adde0292cbf5a2cf0376609 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 22 May 2019 18:38:12 +0200 Subject: vhdl: add hook on free_node, automatically free --- src/vhdl/vhdl-elocations.adb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/vhdl/vhdl-elocations.adb') diff --git a/src/vhdl/vhdl-elocations.adb b/src/vhdl/vhdl-elocations.adb index 0ba3d0b0e..8bc68245c 100644 --- a/src/vhdl/vhdl-elocations.adb +++ b/src/vhdl/vhdl-elocations.adb @@ -130,14 +130,31 @@ package body Vhdl.Elocations is Elocations_Table.Table (Idx .. Idx + Len - 1) := (others => No_Location); end Create_Elocations; - procedure Delete_Elocations (N : Iir) is + procedure Delete_Elocations (N : Iir) + is + use Vhdl.Nodes_Priv; + Old : Location_Index_Type; begin + -- Cannot delete an already deleted location. + if N > Elocations_Index_Table.Last then + return; + end if; + Old := Elocations_Index_Table.Table (N); + if Old = No_Location_Index then + return; + end if; + -- Clear the corresponding index. Elocations_Index_Table.Table (N) := No_Location_Index; -- FIXME: keep free slots in chained list ? end Delete_Elocations; + procedure Free_Hook (N : Iir) is + begin + Delete_Elocations (N); + end Free_Hook; + generic Off : Location_Index_Type; function Get_FieldX (N : Iir) return Location_Type; @@ -707,4 +724,7 @@ package body Vhdl.Elocations is Set_Field3 (N, Loc); end Set_Assign_Location; + +begin + Vhdl.Nodes.Register_Free_Hook (Free_Hook'Access); end Vhdl.Elocations; -- cgit v1.2.3