text
stringlengths
0
234
Body_Path : constant String := Output_Dir & "/"
& Ada.Characters.Handling.To_Lower (Base_Name) & "s.adb";
Spec_File, Body_File : IO.File_Type;
Handle_Name : constant String := Base_Name & "_Handle";
begin
IO.Create (File => Spec_File, Name => Spec_Path);
IO.Create (File => Body_File, Name => Body_Path);
IO.Put_Line (Spec_File, "with Ada.Containers.Formal_Indefinite_Vectors;");
IO.Put_Line (Spec_File, "with L_Strings; use L_Strings;");
IO.Put_Line (Spec_File, "with Tokens; use Tokens;");
IO.New_Line (Spec_File);
IO.Put_Line (Spec_File, "package " & Base_Name & "s with");
IO.Put_Line (Spec_File, " Abstract_State => State is");
IO.Put_Line (Body_File, "package body " & Base_Name & "s with");
IO.Put_Line (Body_File, " Refined_State => (State => Container) is");
IO.Put_Line (Spec_File, " type " & Base_Name & " is abstract tagged private;");
IO.Put_Line (Spec_File, " type " & Handle_Name & " is new Positive;");
IO.Put_Line (Spec_File, " function Is_Valid (Handle : " & Handle_Name & ") return Boolean;");
IO.Put_Line (Body_File, " function Is_Valid (Handle : Expr_Handle) return Boolean with");
IO.Put_Line (Body_File, " Refined_Post => (if Is_Valid'Result then " &
"Handle in Storage.First_Index (Container) .. Storage.Last_Index (Container)) is");
IO.Put_Line (Body_File, " begin");
IO.Put_Line (Body_File, " return Handle in Storage.First_Index (Container) .. Storage.Last_Index (Container);");
IO.Put_Line (Body_File, " end Is_Valid;");
IO.New_Line (Body_File);
IO.Put_Line (Spec_File, " procedure Store (The_" & Base_Name & " : " & Base_Name & "'Class;");
IO.Put_Line (Spec_File, " Result : out " & Handle_Name & ";");
IO.Put_Line (Spec_File, " Success : out Boolean) with");
IO.Put_Line (Spec_File, " Post => (if Success then Is_Valid (Result));");
IO.Put_Line (Spec_File, " function Retrieve (Handle : " & Handle_Name
& ") return " & Base_Name & "'Class with");
IO.Put_Line (Spec_File, " Pre => Is_Valid (Handle);");
IO.Put_Line (Body_File, " function Retrieve (Handle : Expr_Handle) return Expr'Class is");
IO.Put_Line (Body_File, " begin");
IO.Put_Line (Body_File, " return Storage.Element (Container, Handle);");
IO.Put_Line (Body_File, " end Retrieve;");
IO.Put_Line (Body_File, " procedure Store (The_" & Base_Name & " : " & Base_Name & "'Class;");
IO.Put_Line (Body_File, " Result : out " & Handle_Name & ";");
IO.Put_Line (Body_File, " Success : out Boolean) is separate;");
-- The AST classes.
for The_Type of Types loop
declare
Class_Name : constant String := Substring (The_Type.all, ":", 1);
Fields : constant String := Substring (The_Type.all, ":", 2);
begin
Define_Type (Spec_File, Body_File, Base_Name, Class_Name, Fields);
Function Definition: IO.Put_Line (Spec_File, " procedure Accept_Visitor (Self : Expr; V : "
Function Body: & "in out Visitors.Visitor'Class) with "
& "Global => (Input => State);");
IO.Put_Line (Body_File, " procedure Accept_Visitor (Self : Expr; V : "
& "in out Visitors.Visitor'Class) is ");
IO.Put_Line (Body_File, " begin");
IO.Put_Line (Body_File, " null; -- maybe raise an exception here");
IO.Put_Line (Body_File, " end Accept_Visitor;");
IO.New_Line (Body_File);
IO.Put_Line (Spec_File, "private");
IO.Put_Line (Spec_File, " type " & Base_Name & " is abstract tagged null record;");
Define_Storage (Spec_File, Base_Name);
for The_Type of Types loop
declare
Class_Name : constant String := Substring (The_Type.all, ":", 1);
Fields : constant String := Substring (The_Type.all, ":", 2);
begin
Define_Full_Type (Spec_File, Body_File, Base_Name, Class_Name, Fields);
Function Definition: procedure Iterate_Types is new Iterate_Fields (Define_One_Type);
Function Body: begin
IO.Put (Spec_File, " type " & Class_Name & " is new " & Base_Name & " with ");
if Field_List'Length > 0 then
IO.Put_Line (Spec_File, "record");
Iterate_Types (Field_List);
IO.Put_Line (Spec_File, " end record;");
else
IO.Put_Line (Spec_File, "null record;");
end if;
end Define_Full_Type;
procedure Define_Storage (Spec_File : IO.File_Type; Base_Name : String) is
Handle_Name : constant String := Base_Name & "_Handle";
begin
IO.Put_Line (Spec_File, " Max_Element_Size : constant Natural := 2272;");
IO.Put_Line (Spec_File, " package Storage is new Ada.Containers.Formal_Indefinite_Vectors");
IO.Put_Line (Spec_File, " (Index_Type => " & Handle_Name & ",");
IO.Put_Line (Spec_File, " Element_Type => " & Base_Name & "'Class,");
IO.Put_Line (Spec_File, " Max_Size_In_Storage_Elements => Max_Element_Size);");
IO.Put_Line (Spec_File, " -- Should be Bounded => False, but that triggers a prover bug");
IO.Put_Line (Spec_File, " pragma Compile_Time_Warning (True, ""gnatprove bug workaround"");");
IO.New_Line (Spec_File);
IO.Put_Line (Spec_File, " Container : Storage.Vector (5) with Part_Of => State;");
IO.New_Line (Spec_File);
end Define_Storage;
procedure Define_Subprogram (Spec_File, Body_File : IO.File_Type;
Base_Name, Class_Name, Field_List : String) is