From 58e6b24df6935dcd3d6e03c2a926fdc6529cec70 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 19 Apr 2020 20:36:57 +1000 Subject: Removal of manual memory management in favour of Holders --- src/packrat.ads | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'src/packrat.ads') diff --git a/src/packrat.ads b/src/packrat.ads index 4abdaec..b2b0144 100644 --- a/src/packrat.ads +++ b/src/packrat.ads @@ -2,8 +2,11 @@ with - Ada.Strings.Unbounded, - Ada.Finalization; + Ada.Strings.Unbounded; + +private with + + Ada.Containers.Indefinite_Holders; package Packrat is @@ -106,10 +109,13 @@ package Packrat is package Tokens is - type Token is new Ada.Finalization.Controlled with private; + type Token is private; type Token_Array is array (Positive range <>) of Token; + -- will probably have to remove the Finish field to accommodate graphs properly + + function Create (Ident : in Label_Enum; Start : in Positive; @@ -117,20 +123,12 @@ package Packrat is Value : in Element_Array) return Token; - function "=" - (Left, Right : in Token) - return Boolean; - -- Note: The Start and Finish indices indicate where the token was found -- in whatever array it was lexed from. The Value does *not* have -- to correspond with whatever is found in the Start .. Finish range. - function Initialized - (This : in Token) - return Boolean; - function Debug_String (This : in Token) return String; @@ -138,8 +136,7 @@ package Packrat is function Label (This : in Token) - return Label_Enum - with Pre => Initialized (This); + return Label_Enum; function Start (This : in Token) @@ -151,34 +148,23 @@ package Packrat is function Value (This : in Token) - return Element_Array - with Pre => Initialized (This); + return Element_Array; private - type Element_Array_Access is access Element_Array; + package Value_Holders is new Ada.Containers.Indefinite_Holders (Element_Array); - type Token is new Ada.Finalization.Controlled with record + type Token is record Identifier : Label_Enum; Start_At : Positive; Finish_At : Natural; - Token_Value : Element_Array_Access; + Token_Value : Value_Holders.Holder; end record; - overriding procedure Initialize - (This : in out Token); - - overriding procedure Adjust - (This : in out Token); - - overriding procedure Finalize - (This : in out Token); - - end Tokens; -- cgit