text stringlengths 0 234 |
|---|
pragma Unreferenced (Field_List); |
use Ada.Strings.Fixed; |
begin |
-- Visitor pattern. |
IO.New_Line (Spec_File); |
IO.Put_Line (Spec_File, " procedure Accept_Visitor (Self : " |
& Class_Name & "; V : in out Visitors.Visitor'Class) with"); |
IO.Put_Line (Spec_File, " Global => (Input => State);"); |
IO.New_Line (Body_File); |
IO.Put_Line (Body_File, " overriding procedure Accept_Visitor (Self : " |
& Class_Name & "; V : in out Visitors.Visitor'Class) is"); |
IO.Put_Line (Body_File, " begin"); |
IO.Put_Line (Body_File, " V.Visit_" & Class_Name & "_" & Base_Name & " (Self);"); |
IO.Put_Line (Body_File, " end Accept_Visitor;"); |
end Define_Subprogram; |
procedure Define_Type (Spec_File, Body_File : IO.File_Type; |
Base_Name, Class_Name, Field_List : String) is |
use Ada.Strings.Fixed; |
procedure Define_Accessor (Field_Name, Type_Name : String; Last : Boolean); |
procedure Define_Parameter_Body (Field_Name, Type_Name : String; Last : Boolean); |
procedure Define_Parameter_Spec (Field_Name, Type_Name : String; Last : Boolean); |
procedure Initialize_Field (Field_Name, Type_Name : String; Last : Boolean); |
procedure Define_Accessor (Field_Name, Type_Name : String; Last : Boolean) is |
pragma Unreferenced (Last); |
begin |
IO.Put (Spec_File, " function Get_" & Field_Name & " (Self : " |
& Class_Name & ") return " & Type_Name); |
if Type_Name = Base_Name & "_Handle" then |
IO.Put_Line (Spec_File, " with"); |
IO.Put_Line (Spec_File, " Post => Is_Valid (Get_" & Field_Name & "'Result);"); |
else |
IO.Put_Line (Spec_File, ";"); |
end if; |
IO.New_Line (Body_File); |
IO.Put_Line (Body_File, " function Get_" & Field_Name & " (Self : " |
& Class_Name & ") return " & Type_Name & " is"); |
IO.Put_Line (Body_File, " begin"); |
IO.Put_Line (Body_File, " return Self." & Field_Name & ";"); |
IO.Put_Line (Body_File, " end Get_" & Field_Name & ";"); |
end Define_Accessor; |
procedure Define_Parameter_Body (Field_Name, Type_Name : String; Last : Boolean) is |
begin |
IO.Put (Body_File, "My_" & Field_Name & " : " & Type_Name); |
if not Last then |
IO.Put (Body_File, "; "); |
end if; |
end Define_Parameter_Body; |
procedure Define_Parameter_Spec (Field_Name, Type_Name : String; Last : Boolean) is |
begin |
IO.Put (Spec_File, "My_" & Field_Name & " : " & Type_Name); |
if not Last then |
IO.Put (Spec_File, "; "); |
end if; |
end Define_Parameter_Spec; |
procedure Initialize_Field (Field_Name, Type_Name : String; Last : Boolean) is |
pragma Unreferenced (Type_Name, Last); |
begin |
IO.Put_Line (Body_File, " E." & Field_Name & " := My_" & Field_Name & ";"); |
end Initialize_Field; |
procedure Iterate_Accessors is new Iterate_Fields (Define_Accessor); |
procedure Iterate_Initialization is new Iterate_Fields (Initialize_Field); |
procedure Iterate_Parameters_Body is new Iterate_Fields (Define_Parameter_Body); |
procedure Iterate_Parameters_Spec is new Iterate_Fields (Define_Parameter_Spec); |
begin |
IO.Put_Line (Spec_File, ""); |
IO.Put_Line (Spec_File, " type " & Class_Name & " is new " & Base_Name & " with private;"); |
Iterate_Accessors (Field_List); |
IO.Put (Spec_File, " procedure Create_" & Class_Name & " ("); |
IO.New_Line (Body_File); |
IO.Put (Body_File, " procedure Create_" & Class_Name & " ("); |
Iterate_Parameters_Spec (Field_List); |
IO.Put_Line (Spec_File, "; Result : out " & Base_Name & "_Handle);"); |
Iterate_Parameters_Body (Field_List); |
IO.Put_Line (Body_File, "; Result : out " & Base_Name & "_Handle) is"); |
IO.Put_Line (Body_File, " E : " & Class_Name & ";"); |
IO.Put_Line (Body_File, " Success : Boolean;"); |
IO.Put_Line (Body_File, " begin"); |
Iterate_Initialization (Field_List); |
IO.Put_Line (Body_File, " Store (E, Result, Success);"); |
IO.Put_Line (Body_File, " end Create_" & Class_Name & ";"); |
end Define_Type; |
procedure Define_Visitor (Spec_File, Body_File : IO.File_Type; Base_Name : String; Types : String_Array) is |
begin |
IO.Put_Line (Spec_File, " package Visitors is"); |
IO.Put_Line (Spec_File, " type Visitor is tagged null record;"); |
IO.Put_Line (Body_File, " package body Visitors is"); |
for The_Type of Types loop |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.