diff --git "a/dataset.json" "b/dataset.json" new file mode 100644--- /dev/null +++ "b/dataset.json" @@ -0,0 +1,4002 @@ +[ + { + "function_def": "procedure ejercicio1 is", + "function_body": "s : String := \"Comenzamos las pr\u00e1cticas de STR\";\n numero : Natural := 0;\nbegin\n Put(\"Hola Mundo!!!\");\n Put_Line(s);\n pkg_ejercicio2c.OtroProcedimiento;\n\n -- Ejercicio 3\n begin\n Put(\"Introduce un numero:\");\n Ada.Integer_Text_IO.Get(numero);\n\n case numero is\n when 12 | 1 | 2 => Put_Line(\"Invierno\");\n when 3 | 4 | 5 => Put_Line(\"Primavera\");\n when 6 | 7 | 8 => Put_Line(\"Verano\");\n when 9 | 10 | 11 => Put_Line(\"Oto\u00f1o\");\n when others => Put_Line(\"Mes incorrecto\");\n end case;\n\n -- Ejercicio 5\n\n exception\n when Constraint_Error => Put_Line(\"El numero de mes debe ser > 0\");" + }, + { + "function_def": "procedure Simular_Sistema IS", + "function_body": "BEGIN\n Gtk.Main.Main;\n END Simular_Sistema;\n\n\n ------------------------------------------------------------------------\n -- Procedure que se encarga de inicializar la interfaz gr\u00e1fica\n ------------------------------------------------------------------------\n procedure Inicializar_Interfaz_Grafica is\n Win : Gtk_Window;\n Buffer : Gtk_Double_Buffer;\n Vbox, Hbox : Gtk_Box;\n Id : G_Source_Id;--Timeout_Handler_Id;\n Button : Gtk_Button;\n inbuilt_font : Pango.Font.Pango_Font_Description;\n --ventana : Gdk_Window;\n --TAM_BUTTON_EXIT : constant GLib.Gint := 20;\n alinea_button_exit: Gtk.Alignment.Gtk_Alignment;\n A_Check_Button1, A_Check_Button2 : Gtk_Check_Button;\n begin\n -- ventana principal\n Gtk.Window.Gtk_New (Win, Window_Toplevel);\n Set_Title (Win, \"PRACTICA STR: CONTROL DE TRAFICO\");\n Win.Set_Default_Size(CANVAS_WIDTH, CANVAS_HEIGHT);--+TAM_BUTTON_EXIT);\n Void_Cb.Connect (Win, \"destroy\", Void_Cb.To_Marshaller (Quit'Access));\n\n\n -- bot\u00f3n Exit\n Gtk_New (Button, \"EXIT\");\n Destroyed.Object_Connect (Button,\n \"clicked\",\n Destroyed.To_Marshaller (Quit'Access),\n Slot_Object => Win);\n\n Button.Set_Size_Request(100, 20);--TAM_BUTTON_EXIT);\n Gtk.Alignment.Gtk_New(alinea_button_exit, 0.5, 0.5, 0.0, 0.0);\n alinea_button_exit.Add(Button);\n\n\n -- Double buffer\n Double_Buffer.Gtk_New(Buffer);\n Buffer.Set_Size_Request(CANVAS_WIDTH, CANVAS_HEIGHT);-- -TAM_BUTTON_EXIT);\n\n\n -- Botones para la generaci\u00f3n de aver\u00edas\n Gtk_New (A_Check_Button1, \"Averia en Carril 1\");\n Widget_Handler.Object_Connect(A_Check_Button1, \"clicked\",\n Widget_Handler.To_Marshaller (Averia1_Generada'ACCESS),\n Slot_Object => Win);\n\n Gtk_New (A_Check_Button2, \"Averia en Carril 2\");\n Widget_Handler.Object_Connect(A_Check_Button2, \"clicked\",\n Widget_Handler.To_Marshaller (Averia2_Generada'ACCESS),\n Slot_Object => Win);\n\n\n\n -- Asociar widgets a la ventana principal y mostrarla\n Gtk_New_Hbox (Hbox, Homogeneous => True, Spacing => 10);\n Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);\n\n Pack_Start (Vbox, Buffer);\n --Pack_Start (Vbox, Button, Expand => False, Fill => False);\n Pack_Start (Vbox, alinea_button_exit);--, Expand => False, Fill => False);\n\n Pack_Start (Vbox, A_Check_Button1);\n Pack_Start (Vbox, A_Check_Button2);\n\n Pack_Start (Hbox, Vbox);\n\n\n\n\n\n\n Win.Add(Hbox);\n\n Show_All (Win);\n\n --ventana := Get_Window(Gtk_Widget(Buffer));\n --Gdk.Window.Move(ventana, 0, 0);\n\n\n Id := Main_Context_Sources.Timeout_Add (PERIODICIDAD_REDIBUJAR_MILISEGUNDOS,\n Draw_Complex_Buffer'Access,\n Gtk_Drawing_Area (Buffer));\n\n\n Gdk_New(pangoLayout, Get_Pango_Context(Buffer));\n inbuilt_font := Pango.Font.From_String(\"Courier\");\n Pango.Layout.Set_Font_Description(pangoLayout, inbuilt_font);\n\n\n -- INICIALIZACI\u00d3N DEL ESTADO DE TODOS LOS OBJETOS VISUALIZADOS\n Inicializar_Buffer_Coches;\n\n end Inicializar_Interfaz_Grafica;\n\n\n ------------------\n -- Draw_Complex --\n ------------------\n procedure Draw_Complex (Pixmap : Cairo_Context) is\n begin\n\n Draw_Rectangle (Pixmap, Black_Gc, Filled => True,\n X => 0, Y => 0,\n Width => CANVAS_WIDTH, Height => CANVAS_HEIGHT);\n\n\n -- DIBUJAR EN EL CANVAS EL ESTADO ACTUAL DE TODOS LOS OBJETOS\n Dibujar_Canvas_Calle(Pixmap);\n\n end Draw_Complex;\n\n\n -------------------------\n -- Draw_Complex_Buffer --\n -------------------------\n function Draw_Complex_Buffer (Area : Gtk_Drawing_Area) return Boolean is\n Buffer : Gtk_Double_Buffer := Gtk_Double_Buffer (Area);\n\n begin\n Draw_Complex (Get_Pixmap (Buffer));\n\n Double_Buffer.Thaw(Buffer);\n\n --Double_Buffer.Draw (Buffer);\n\n return True;\n end Draw_Complex_Buffer;\n\n\n\n ----------\n -- Quit --\n ----------\n procedure Quit (Win : access Gtk_Window_Record'Class) is\n pragma Warnings (Off, Win);\n begin\n Gnat.OS_Lib.OS_Exit(0);\n --Gtk.Main.Main_Quit;\n --Ada.Task_Identification.Abort_Task(Ada.Task_Identification.Current_Task);\n end Quit;\n\n\n\n ------------------------------------------------------------------------\n -- Procedure que inicializa el buffer de coches\n ------------------------------------------------------------------------\n procedure Inicializar_Buffer_Coches is\n coche : T_RecordCoche;\n BEGIN\n for carril IN T_Carril loop\n FOR I IN T_RangoBufferCoches LOOP\n Coche.Id := 0;\n Coche.Pos.X := 0;\n Coche.Pos.Y := y_carril(carril);\n coche.velocidad := (VELOCIDAD_COCHE, 0);\n Coche.Color:= T_ColorCoche'First;\n coche.carril := carril;\n Pkg_Buffer_Coches.Actualiza_Item(i, Coche, Buffer_Coches(carril));\n\n -- Inicializamos tambi\u00e9n el buffer de coches accidentados\n Pkg_Buffer_Accidentes.Actualiza_Item(i, Coche, Buffer_Accidentes(carril));\n END LOOP;\n END LOOP;\n\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Inicializar_Buffer_Coches: \" & Exception_Name(Exception_Identity(event)));\n\n end Inicializar_Buffer_Coches;\n\n\n\n ------------------------------------------------------------------------\n -- Funci\u00f3n que devuelve la posici\u00f3n de un coche dentro del buffer\n -----------------------------------------------------------------------\n FUNCTION Posicion_Buffer(Id : T_IdCoche;\n Buffer: Pkg_Buffer_Coches.T_Buffer) RETURN T_RangoBufferCoches is\n coche_aux : T_RecordCoche;\n pos : T_RangoBufferCoches;\n BEGIN\n BEGIN\n Pos := Pkg_Buffer_Coches.Posicion_Primer_Item(Buffer);\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n WHILE Coche_Aux.Id /= Id LOOP\n Pos := Pos+1;\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n END LOOP;\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Posicion_Buffer: \" & Exception_Name(Exception_Identity(event)));" + }, + { + "function_def": "procedure Simular_Sistema IS", + "function_body": "BEGIN\n Gtk.Main.Main;\n END Simular_Sistema;\n\n\n ------------------------------------------------------------------------\n -- Procedure que se encarga de inicializar la interfaz gr\u00e1fica\n ------------------------------------------------------------------------\n procedure Inicializar_Interfaz_Grafica is\n Win : Gtk_Window;\n Buffer : Gtk_Double_Buffer;\n Vbox, Hbox : Gtk_Box;\n Id : G_Source_Id;--Timeout_Handler_Id;\n Button : Gtk_Button;\n inbuilt_font : Pango.Font.Pango_Font_Description;\n --ventana : Gdk_Window;\n --TAM_BUTTON_EXIT : constant GLib.Gint := 20;\n alinea_button : Gtk.Alignment.Gtk_Alignment;\n begin\n -- ventana principal\n Gtk.Window.Gtk_New (Win, Window_Toplevel);\n Set_Title (Win, \"PRACTICA STR: CONTROL DE TRAFICO\");\n Win.Set_Default_Size(CANVAS_WIDTH, CANVAS_HEIGHT);--+TAM_BUTTON_EXIT);\n Void_Cb.Connect (Win, \"destroy\", Void_Cb.To_Marshaller (Quit'Access));\n\n\n -- bot\u00f3n Exit\n Gtk_New (Button, \"EXIT\");\n Destroyed.Object_Connect (Button,\n \"clicked\",\n Destroyed.To_Marshaller (Quit'Access),\n Slot_Object => Win);\n\n Button.Set_Size_Request(100, 20);--TAM_BUTTON_EXIT);\n Gtk.Alignment.Gtk_New(alinea_button, 0.5, 0.5, 0.0, 0.0);\n alinea_button.Add(Button);\n\n\n -- Double buffer\n Double_Buffer.Gtk_New(Buffer);\n Buffer.Set_Size_Request(CANVAS_WIDTH, CANVAS_HEIGHT);-- -TAM_BUTTON_EXIT);\n\n\n -- Asociar widgets a la ventana principal y mostrarla\n Gtk_New_Hbox (Hbox, Homogeneous => True, Spacing => 10);\n Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);\n\n Pack_Start (Vbox, Buffer);\n --Pack_Start (Vbox, Button, Expand => False, Fill => False);\n Pack_Start (Vbox, alinea_button);--, Expand => False, Fill => False);\n\n Pack_Start (Hbox, Vbox);\n\n\n Win.Add(Hbox);\n\n Show_All (Win);\n\n --ventana := Get_Window(Gtk_Widget(Buffer));\n --Gdk.Window.Move(ventana, 0, 0);\n\n\n Id := Main_Context_Sources.Timeout_Add (PERIODICIDAD_REDIBUJAR_MILISEGUNDOS,\n Draw_Complex_Buffer'Access,\n Gtk_Drawing_Area (Buffer));\n\n\n Gdk_New(pangoLayout, Get_Pango_Context(Buffer));\n inbuilt_font := Pango.Font.From_String(\"Courier\");\n Pango.Layout.Set_Font_Description(pangoLayout, inbuilt_font);\n\n\n -- INICIALIZACI\u00d3N DEL ESTADO DE TODOS LOS OBJETOS VISUALIZADOS\n Inicializar_Buffer_Coches;\n\n end Inicializar_Interfaz_Grafica;\n\n\n ------------------\n -- Draw_Complex --\n ------------------\n procedure Draw_Complex (Pixmap : Cairo_Context) is\n begin\n\n Draw_Rectangle (Pixmap, Black_Gc, Filled => True,\n X => 0, Y => 0,\n Width => CANVAS_WIDTH, Height => CANVAS_HEIGHT);\n\n\n -- DIBUJAR EN EL CANVAS EL ESTADO ACTUAL DE TODOS LOS OBJETOS\n Dibujar_Canvas_Calle(Pixmap);\n\n end Draw_Complex;\n\n\n -------------------------\n -- Draw_Complex_Buffer --\n -------------------------\n function Draw_Complex_Buffer (Area : Gtk_Drawing_Area) return Boolean is\n Buffer : Gtk_Double_Buffer := Gtk_Double_Buffer (Area);\n\n begin\n Draw_Complex (Get_Pixmap (Buffer));\n\n Double_Buffer.Thaw(Buffer);\n\n --Double_Buffer.Draw (Buffer);\n\n return True;\n end Draw_Complex_Buffer;\n\n\n\n ----------\n -- Quit --\n ----------\n procedure Quit (Win : access Gtk_Window_Record'Class) is\n pragma Warnings (Off, Win);\n begin\n Gnat.OS_Lib.OS_Exit(0);\n --Gtk.Main.Main_Quit;\n --Ada.Task_Identification.Abort_Task(Ada.Task_Identification.Current_Task);\n end Quit;\n\n\n\n ------------------------------------------------------------------------\n -- Procedure que inicializa el buffer de coches\n ------------------------------------------------------------------------\n procedure Inicializar_Buffer_Coches is\n coche : T_RecordCoche;\n BEGIN\n for carril IN T_Carril loop\n FOR I IN T_RangoBufferCoches LOOP\n Coche.Id := 0;\n Coche.Pos.X := 0;\n Coche.Pos.Y := y_carril(carril);\n coche.velocidad := (VELOCIDAD_COCHE, 0);\n Coche.Color:= T_ColorCoche'First;\n coche.carril := carril;\n Pkg_Buffer_Coches.Actualiza_Item(i, Coche, Buffer_Coches(carril));\n\n -- Inicializamos tambi\u00e9n el buffer de coches accidentados\n Pkg_Buffer_Accidentes.Actualiza_Item(i, Coche, Buffer_Accidentes(carril));\n END LOOP;\n END LOOP;\n\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Inicializar_Buffer_Coches: \" & Exception_Name(Exception_Identity(event)));\n\n end Inicializar_Buffer_Coches;\n\n\n\n ------------------------------------------------------------------------\n -- Funci\u00f3n que devuelve la posici\u00f3n de un coche dentro del buffer\n -----------------------------------------------------------------------\n FUNCTION Posicion_Buffer(Id : T_IdCoche;\n Buffer: Pkg_Buffer_Coches.T_Buffer) RETURN T_RangoBufferCoches is\n coche_aux : T_RecordCoche;\n pos : T_RangoBufferCoches;\n BEGIN\n BEGIN\n Pos := Pkg_Buffer_Coches.Posicion_Primer_Item(Buffer);\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n WHILE Coche_Aux.Id /= Id LOOP\n Pos := Pos+1;\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n END LOOP;\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Posicion_Buffer: \" & Exception_Name(Exception_Identity(event)));" + }, + { + "function_def": "procedure Simular_Sistema IS", + "function_body": "BEGIN\n Gtk.Main.Main;\n END Simular_Sistema;\n\n\n ------------------------------------------------------------------------\n -- Procedure que se encarga de inicializar la interfaz gr\u00e1fica\n ------------------------------------------------------------------------\n procedure Inicializar_Interfaz_Grafica is\n Win : Gtk_Window;\n Buffer : Gtk_Double_Buffer;\n Vbox, Hbox : Gtk_Box;\n Id : G_Source_Id;--Timeout_Handler_Id;\n Button : Gtk_Button;\n inbuilt_font : Pango.Font.Pango_Font_Description;\n --ventana : Gdk_Window;\n --TAM_BUTTON_EXIT : constant GLib.Gint := 20;\n alinea_button_exit: Gtk.Alignment.Gtk_Alignment;\n A_Check_Button1, A_Check_Button2 : Gtk_Check_Button;\n begin\n -- ventana principal\n Gtk.Window.Gtk_New (Win, Window_Toplevel);\n Set_Title (Win, \"PRACTICA STR: CONTROL DE TRAFICO\");\n Win.Set_Default_Size(CANVAS_WIDTH, CANVAS_HEIGHT);--+TAM_BUTTON_EXIT);\n Void_Cb.Connect (Win, \"destroy\", Void_Cb.To_Marshaller (Quit'Access));\n\n\n -- bot\u00f3n Exit\n Gtk_New (Button, \"EXIT\");\n Destroyed.Object_Connect (Button,\n \"clicked\",\n Destroyed.To_Marshaller (Quit'Access),\n Slot_Object => Win);\n\n Button.Set_Size_Request(100, 20);--TAM_BUTTON_EXIT);\n Gtk.Alignment.Gtk_New(alinea_button_exit, 0.5, 0.5, 0.0, 0.0);\n alinea_button_exit.Add(Button);\n\n\n -- Double buffer\n Double_Buffer.Gtk_New(Buffer);\n Buffer.Set_Size_Request(CANVAS_WIDTH, CANVAS_HEIGHT);-- -TAM_BUTTON_EXIT);\n\n\n -- Botones para la generaci\u00f3n de aver\u00edas\n Gtk_New (A_Check_Button1, \"Averia en Carril 1\");\n Widget_Handler.Object_Connect(A_Check_Button1, \"clicked\",\n Widget_Handler.To_Marshaller (Averia1_Generada'ACCESS),\n Slot_Object => Win);\n\n Gtk_New (A_Check_Button2, \"Averia en Carril 2\");\n Widget_Handler.Object_Connect(A_Check_Button2, \"clicked\",\n Widget_Handler.To_Marshaller (Averia2_Generada'ACCESS),\n Slot_Object => Win);\n\n\n\n -- Asociar widgets a la ventana principal y mostrarla\n Gtk_New_Hbox (Hbox, Homogeneous => True, Spacing => 10);\n Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);\n\n Pack_Start (Vbox, Buffer);\n --Pack_Start (Vbox, Button, Expand => False, Fill => False);\n Pack_Start (Vbox, alinea_button_exit);--, Expand => False, Fill => False);\n\n Pack_Start (Vbox, A_Check_Button1);\n Pack_Start (Vbox, A_Check_Button2);\n\n Pack_Start (Hbox, Vbox);\n\n\n\n\n\n\n Win.Add(Hbox);\n\n Show_All (Win);\n\n --ventana := Get_Window(Gtk_Widget(Buffer));\n --Gdk.Window.Move(ventana, 0, 0);\n\n\n Id := Main_Context_Sources.Timeout_Add (PERIODICIDAD_REDIBUJAR_MILISEGUNDOS,\n Draw_Complex_Buffer'Access,\n Gtk_Drawing_Area (Buffer));\n\n\n Gdk_New(pangoLayout, Get_Pango_Context(Buffer));\n inbuilt_font := Pango.Font.From_String(\"Courier\");\n Pango.Layout.Set_Font_Description(pangoLayout, inbuilt_font);\n\n\n -- INICIALIZACI\u00d3N DEL ESTADO DE TODOS LOS OBJETOS VISUALIZADOS\n Inicializar_Buffer_Coches;\n\n end Inicializar_Interfaz_Grafica;\n\n\n ------------------\n -- Draw_Complex --\n ------------------\n procedure Draw_Complex (Pixmap : Cairo_Context) is\n begin\n\n Draw_Rectangle (Pixmap, Black_Gc, Filled => True,\n X => 0, Y => 0,\n Width => CANVAS_WIDTH, Height => CANVAS_HEIGHT);\n\n\n -- DIBUJAR EN EL CANVAS EL ESTADO ACTUAL DE TODOS LOS OBJETOS\n Dibujar_Canvas_Calle(Pixmap);\n\n end Draw_Complex;\n\n\n -------------------------\n -- Draw_Complex_Buffer --\n -------------------------\n function Draw_Complex_Buffer (Area : Gtk_Drawing_Area) return Boolean is\n Buffer : Gtk_Double_Buffer := Gtk_Double_Buffer (Area);\n\n begin\n Draw_Complex (Get_Pixmap (Buffer));\n\n Double_Buffer.Thaw(Buffer);\n\n --Double_Buffer.Draw (Buffer);\n\n return True;\n end Draw_Complex_Buffer;\n\n\n\n ----------\n -- Quit --\n ----------\n procedure Quit (Win : access Gtk_Window_Record'Class) is\n pragma Warnings (Off, Win);\n begin\n Gnat.OS_Lib.OS_Exit(0);\n --Gtk.Main.Main_Quit;\n --Ada.Task_Identification.Abort_Task(Ada.Task_Identification.Current_Task);\n end Quit;\n\n\n\n ------------------------------------------------------------------------\n -- Procedure que inicializa el buffer de coches\n ------------------------------------------------------------------------\n procedure Inicializar_Buffer_Coches is\n coche : T_RecordCoche;\n BEGIN\n for carril IN T_Carril loop\n FOR I IN T_RangoBufferCoches LOOP\n Coche.Id := 0;\n Coche.Pos.X := 0;\n Coche.Pos.Y := y_carril(carril);\n coche.velocidad := (VELOCIDAD_COCHE, 0);\n Coche.Color:= T_ColorCoche'First;\n coche.carril := carril;\n Pkg_Buffer_Coches.Actualiza_Item(i, Coche, Buffer_Coches(carril));\n\n -- Inicializamos tambi\u00e9n el buffer de coches accidentados\n Pkg_Buffer_Accidentes.Actualiza_Item(i, Coche, Buffer_Accidentes(carril));\n END LOOP;\n END LOOP;\n\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Inicializar_Buffer_Coches: \" & Exception_Name(Exception_Identity(event)));\n\n end Inicializar_Buffer_Coches;\n\n\n\n ------------------------------------------------------------------------\n -- Funci\u00f3n que devuelve la posici\u00f3n de un coche dentro del buffer\n -----------------------------------------------------------------------\n FUNCTION Posicion_Buffer(Id : T_IdCoche;\n Buffer: Pkg_Buffer_Coches.T_Buffer) RETURN T_RangoBufferCoches is\n coche_aux : T_RecordCoche;\n pos : T_RangoBufferCoches;\n BEGIN\n BEGIN\n Pos := Pkg_Buffer_Coches.Posicion_Primer_Item(Buffer);\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n WHILE Coche_Aux.Id /= Id LOOP\n Pos := Pos+1;\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n END LOOP;\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Posicion_Buffer: \" & Exception_Name(Exception_Identity(event)));" + }, + { + "function_def": "procedure Simular_Sistema IS", + "function_body": "BEGIN\n Gtk.Main.Main;\n END Simular_Sistema;\n\n\n ------------------------------------------------------------------------\n -- Procedure que se encarga de inicializar la interfaz gr\u00e1fica\n ------------------------------------------------------------------------\n procedure Inicializar_Interfaz_Grafica is\n Win : Gtk_Window;\n Buffer : Gtk_Double_Buffer;\n Vbox, Hbox : Gtk_Box;\n Id : G_Source_Id;--Timeout_Handler_Id;\n Button : Gtk_Button;\n inbuilt_font : Pango.Font.Pango_Font_Description;\n --ventana : Gdk_Window;\n --TAM_BUTTON_EXIT : constant GLib.Gint := 20;\n alinea_button : Gtk.Alignment.Gtk_Alignment;\n begin\n -- ventana principal\n Gtk.Window.Gtk_New (Win, Window_Toplevel);\n Set_Title (Win, \"PRACTICA STR: CONTROL DE TRAFICO\");\n Win.Set_Default_Size(CANVAS_WIDTH, CANVAS_HEIGHT);--+TAM_BUTTON_EXIT);\n Void_Cb.Connect (Win, \"destroy\", Void_Cb.To_Marshaller (Quit'Access));\n\n\n -- bot\u00f3n Exit\n Gtk_New (Button, \"EXIT\");\n Destroyed.Object_Connect (Button,\n \"clicked\",\n Destroyed.To_Marshaller (Quit'Access),\n Slot_Object => Win);\n\n Button.Set_Size_Request(100, 20);--TAM_BUTTON_EXIT);\n Gtk.Alignment.Gtk_New(alinea_button, 0.5, 0.5, 0.0, 0.0);\n alinea_button.Add(Button);\n\n\n -- Double buffer\n Double_Buffer.Gtk_New(Buffer);\n Buffer.Set_Size_Request(CANVAS_WIDTH, CANVAS_HEIGHT);-- -TAM_BUTTON_EXIT);\n\n\n -- Asociar widgets a la ventana principal y mostrarla\n Gtk_New_Hbox (Hbox, Homogeneous => True, Spacing => 10);\n Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);\n\n Pack_Start (Vbox, Buffer);\n --Pack_Start (Vbox, Button, Expand => False, Fill => False);\n Pack_Start (Vbox, alinea_button);--, Expand => False, Fill => False);\n\n Pack_Start (Hbox, Vbox);\n\n\n Win.Add(Hbox);\n\n Show_All (Win);\n\n --ventana := Get_Window(Gtk_Widget(Buffer));\n --Gdk.Window.Move(ventana, 0, 0);\n\n\n Id := Main_Context_Sources.Timeout_Add (PERIODICIDAD_REDIBUJAR_MILISEGUNDOS,\n Draw_Complex_Buffer'Access,\n Gtk_Drawing_Area (Buffer));\n\n\n Gdk_New(pangoLayout, Get_Pango_Context(Buffer));\n inbuilt_font := Pango.Font.From_String(\"Courier\");\n Pango.Layout.Set_Font_Description(pangoLayout, inbuilt_font);\n\n\n -- INICIALIZACI\u00d3N DEL ESTADO DE TODOS LOS OBJETOS VISUALIZADOS\n Inicializar_Buffer_Coches;\n\n end Inicializar_Interfaz_Grafica;\n\n\n ------------------\n -- Draw_Complex --\n ------------------\n procedure Draw_Complex (Pixmap : Cairo_Context) is\n begin\n\n Draw_Rectangle (Pixmap, Black_Gc, Filled => True,\n X => 0, Y => 0,\n Width => CANVAS_WIDTH, Height => CANVAS_HEIGHT);\n\n\n -- DIBUJAR EN EL CANVAS EL ESTADO ACTUAL DE TODOS LOS OBJETOS\n Dibujar_Canvas_Calle(Pixmap);\n\n end Draw_Complex;\n\n\n -------------------------\n -- Draw_Complex_Buffer --\n -------------------------\n function Draw_Complex_Buffer (Area : Gtk_Drawing_Area) return Boolean is\n Buffer : Gtk_Double_Buffer := Gtk_Double_Buffer (Area);\n\n begin\n Draw_Complex (Get_Pixmap (Buffer));\n\n Double_Buffer.Thaw(Buffer);\n\n --Double_Buffer.Draw (Buffer);\n\n return True;\n end Draw_Complex_Buffer;\n\n\n\n ----------\n -- Quit --\n ----------\n procedure Quit (Win : access Gtk_Window_Record'Class) is\n pragma Warnings (Off, Win);\n begin\n Gnat.OS_Lib.OS_Exit(0);\n --Gtk.Main.Main_Quit;\n --Ada.Task_Identification.Abort_Task(Ada.Task_Identification.Current_Task);\n end Quit;\n\n\n\n ------------------------------------------------------------------------\n -- Procedure que inicializa el buffer de coches\n ------------------------------------------------------------------------\n procedure Inicializar_Buffer_Coches is\n coche : T_RecordCoche;\n BEGIN\n for carril IN T_Carril loop\n FOR I IN T_RangoBufferCoches LOOP\n Coche.Id := 0;\n Coche.Pos.X := 0;\n Coche.Pos.Y := y_carril(carril);\n coche.velocidad := (VELOCIDAD_COCHE, 0);\n Coche.Color:= T_ColorCoche'First;\n coche.carril := carril;\n Pkg_Buffer_Coches.Actualiza_Item(i, Coche, Buffer_Coches(carril));\n\n -- Inicializamos tambi\u00e9n el buffer de coches accidentados\n Pkg_Buffer_Accidentes.Actualiza_Item(i, Coche, Buffer_Accidentes(carril));\n END LOOP;\n END LOOP;\n\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Inicializar_Buffer_Coches: \" & Exception_Name(Exception_Identity(event)));\n\n end Inicializar_Buffer_Coches;\n\n\n\n ------------------------------------------------------------------------\n -- Funci\u00f3n que devuelve la posici\u00f3n de un coche dentro del buffer\n -----------------------------------------------------------------------\n FUNCTION Posicion_Buffer(Id : T_IdCoche;\n Buffer: Pkg_Buffer_Coches.T_Buffer) RETURN T_RangoBufferCoches is\n coche_aux : T_RecordCoche;\n pos : T_RangoBufferCoches;\n BEGIN\n BEGIN\n Pos := Pkg_Buffer_Coches.Posicion_Primer_Item(Buffer);\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n WHILE Coche_Aux.Id /= Id LOOP\n Pos := Pos+1;\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n END LOOP;\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Posicion_Buffer: \" & Exception_Name(Exception_Identity(event)));" + }, + { + "function_def": "procedure Simular_Sistema IS", + "function_body": "BEGIN\n Gtk.Main.Main;\n END Simular_Sistema;\n\n\n ------------------------------------------------------------------------\n -- Procedure que se encarga de inicializar la interfaz gr\u00e1fica\n ------------------------------------------------------------------------\n procedure Inicializar_Interfaz_Grafica is\n Win : Gtk_Window;\n Buffer : Gtk_Double_Buffer;\n Vbox, Hbox : Gtk_Box;\n Id : G_Source_Id;--Timeout_Handler_Id;\n Button : Gtk_Button;\n inbuilt_font : Pango.Font.Pango_Font_Description;\n --ventana : Gdk_Window;\n --TAM_BUTTON_EXIT : constant GLib.Gint := 20;\n alinea_button : Gtk.Alignment.Gtk_Alignment;\n begin\n -- ventana principal\n Gtk.Window.Gtk_New (Win, Window_Toplevel);\n Set_Title (Win, \"PRACTICA STR: CONTROL DE TRAFICO\");\n Win.Set_Default_Size(CANVAS_WIDTH, CANVAS_HEIGHT);--+TAM_BUTTON_EXIT);\n Void_Cb.Connect (Win, \"destroy\", Void_Cb.To_Marshaller (Quit'Access));\n\n\n -- bot\u00f3n Exit\n Gtk_New (Button, \"EXIT\");\n Destroyed.Object_Connect (Button,\n \"clicked\",\n Destroyed.To_Marshaller (Quit'Access),\n Slot_Object => Win);\n\n Button.Set_Size_Request(100, 20);--TAM_BUTTON_EXIT);\n Gtk.Alignment.Gtk_New(alinea_button, 0.5, 0.5, 0.0, 0.0);\n alinea_button.Add(Button);\n\n\n -- Double buffer\n Double_Buffer.Gtk_New(Buffer);\n Buffer.Set_Size_Request(CANVAS_WIDTH, CANVAS_HEIGHT);-- -TAM_BUTTON_EXIT);\n\n\n -- Asociar widgets a la ventana principal y mostrarla\n Gtk_New_Hbox (Hbox, Homogeneous => True, Spacing => 10);\n Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);\n\n Pack_Start (Vbox, Buffer);\n --Pack_Start (Vbox, Button, Expand => False, Fill => False);\n Pack_Start (Vbox, alinea_button);--, Expand => False, Fill => False);\n\n Pack_Start (Hbox, Vbox);\n\n\n Win.Add(Hbox);\n\n Show_All (Win);\n\n --ventana := Get_Window(Gtk_Widget(Buffer));\n --Gdk.Window.Move(ventana, 0, 0);\n\n\n Id := Main_Context_Sources.Timeout_Add (PERIODICIDAD_REDIBUJAR_MILISEGUNDOS,\n Draw_Complex_Buffer'Access,\n Gtk_Drawing_Area (Buffer));\n\n\n Gdk_New(pangoLayout, Get_Pango_Context(Buffer));\n inbuilt_font := Pango.Font.From_String(\"Courier\");\n Pango.Layout.Set_Font_Description(pangoLayout, inbuilt_font);\n\n\n -- INICIALIZACI\u00d3N DEL ESTADO DE TODOS LOS OBJETOS VISUALIZADOS\n Inicializar_Buffer_Coches;\n\n end Inicializar_Interfaz_Grafica;\n\n\n ------------------\n -- Draw_Complex --\n ------------------\n procedure Draw_Complex (Pixmap : Cairo_Context) is\n begin\n\n Draw_Rectangle (Pixmap, Black_Gc, Filled => True,\n X => 0, Y => 0,\n Width => CANVAS_WIDTH, Height => CANVAS_HEIGHT);\n\n\n -- DIBUJAR EN EL CANVAS EL ESTADO ACTUAL DE TODOS LOS OBJETOS\n Dibujar_Canvas_Calle(Pixmap);\n\n end Draw_Complex;\n\n\n -------------------------\n -- Draw_Complex_Buffer --\n -------------------------\n function Draw_Complex_Buffer (Area : Gtk_Drawing_Area) return Boolean is\n Buffer : Gtk_Double_Buffer := Gtk_Double_Buffer (Area);\n\n begin\n Draw_Complex (Get_Pixmap (Buffer));\n\n Double_Buffer.Thaw(Buffer);\n\n --Double_Buffer.Draw (Buffer);\n\n return True;\n end Draw_Complex_Buffer;\n\n\n\n ----------\n -- Quit --\n ----------\n procedure Quit (Win : access Gtk_Window_Record'Class) is\n pragma Warnings (Off, Win);\n begin\n Gnat.OS_Lib.OS_Exit(0);\n --Gtk.Main.Main_Quit;\n --Ada.Task_Identification.Abort_Task(Ada.Task_Identification.Current_Task);\n end Quit;\n\n\n\n ------------------------------------------------------------------------\n -- Procedure que inicializa el buffer de coches\n ------------------------------------------------------------------------\n procedure Inicializar_Buffer_Coches is\n coche : T_RecordCoche;\n BEGIN\n for carril IN T_Carril loop\n FOR I IN T_RangoBufferCoches LOOP\n Coche.Id := 0;\n Coche.Pos.X := 0;\n Coche.Pos.Y := y_carril(carril);\n coche.velocidad := (VELOCIDAD_COCHE, 0);\n Coche.Color:= T_ColorCoche'First;\n coche.carril := carril;\n Pkg_Buffer_Coches.Actualiza_Item(i, Coche, Buffer_Coches(carril));\n\n -- Inicializamos tambi\u00e9n el buffer de coches accidentados\n Pkg_Buffer_Accidentes.Actualiza_Item(i, Coche, Buffer_Accidentes(carril));\n END LOOP;\n END LOOP;\n\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Inicializar_Buffer_Coches: \" & Exception_Name(Exception_Identity(event)));\n\n end Inicializar_Buffer_Coches;\n\n\n\n ------------------------------------------------------------------------\n -- Funci\u00f3n que devuelve la posici\u00f3n de un coche dentro del buffer\n -----------------------------------------------------------------------\n FUNCTION Posicion_Buffer(Id : T_IdCoche;\n Buffer: Pkg_Buffer_Coches.T_Buffer) RETURN T_RangoBufferCoches is\n coche_aux : T_RecordCoche;\n pos : T_RangoBufferCoches;\n BEGIN\n BEGIN\n Pos := Pkg_Buffer_Coches.Posicion_Primer_Item(Buffer);\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n WHILE Coche_Aux.Id /= Id LOOP\n Pos := Pos+1;\n Coche_Aux := Pkg_Buffer_Coches.Consulta_Item(Pos, Buffer);\n END LOOP;\n exception\n when event: others =>\n PKG_debug.Escribir(\"ERROR en Posicion_Buffer: \" & Exception_Name(Exception_Identity(event)));" + }, + { + "function_def": "procedure Wsl_Launch is", + "function_body": "-- Ada_Launch is the default name, but is meant to be renamed\n -- to the executable name that this executable launches\n\n package Env renames Ada.Environment_Variables;\n package CL renames Ada.Command_Line;\n package CLenv renames Ada.Command_Line.Environment;\n -- Env, CL, and CLenv are just abbreviations for:\n -- Environment_Variables, Command_Line, and Command_Line.Environment\n\n package AdaList is\n new Ada.Containers.Indefinite_Doubly_Linked_Lists (String);\n\n function Exec_In_Path (Exec_Name : String) return String is\n begin\n if not (Locate_Exec_On_Path (Exec_Name) = null)\n then\n return Locate_Exec_On_Path (Exec_Name).all;\n else\n Put_Line (Standard_Error, Exec_Name & \" not found in PATH.\");\n return \"\";\n end if;" + }, + { + "function_def": "procedure Startx is", + "function_body": "-- XTerminal is a terminal bast in Xorg -- meant to be used as a login\n -- terminal.\n\n use GNAT.OS_Lib;\n\n package Env renames Ada.Environment_Variables;\n package Cl renames Ada.Command_Line;\n package Files renames Ada.Directories;\n package Os renames GNAT.OS_Lib;\n package Os_Files renames GNAT.Directory_Operations;\n package Regex renames GNAT.Regpat;\n\n-- package OS renames gnat.os_lib;\n -- Env, CL, and CLenv are just abbreviations for: Environment_Variables,\n -- Command_Line, and Command_Line.Environment\n\n -- xterm -bg black -fg white +sb +sm -fn 10x20 -sl 4000 -cr yellow\n\n -- /usr/bin/Xnest :1 -geometry 1024x768+0+0 -ac -name Windowmaker & wmaker\n -- -display :1\n\n Empty_Argument_List : constant Os.String_List (1 .. 0) := (others => null);\n Empty_List_Access : Os.String_List_Access :=\n new Os.String_List'(Empty_Argument_List);\n\n function Image (Num : Natural) return String is\n N : Natural := Num;\n S : String (1 .. 48) := (others => ' ');\n L : Natural := 0;\n procedure Image_Natural\n (N : in Natural;\n S : in out String;\n L : in out Natural) is\n begin\n null;\n if N >= 10 then\n Image_Natural (N / 10, S, L);\n L := L + 1;\n S (L) := Character'Val (48 + (N rem 10));\n else\n L := L + 1;\n S (L) := Character'Val (48 + (N rem 10));\n end if;\n end Image_Natural;\n begin\n null;\n Image_Natural (N, S, L);\n return S (1 .. L);\n end Image;\n\n function Create_Display_Number return String is\n use Ada.Directories;\n New_Number : Natural := 0;\n\n begin\n if Exists (\"/tmp\") then\n loop\n if Exists (\"/tmp/.X\" & Image (New_Number) & \"-lock\") then\n New_Number := New_Number + 1;\n\n else\n return Image (New_Number);\n\n end if;\n\n end loop;\n\n else\n return \"0\";\n\n end if;\n end Create_Display_Number;\n\n -- Using GNAT.Directory_Operations, make given filesystem path compatible\n -- with the current Operating System: Path (\"to/file\") => \"to\\file\"(windows)\n function Path (Original : String) return String is\n use Os_Files;\n Result : Path_Name :=\n Os_Files.Format_Pathname\n (Path => Path_Name (Original),\n Style => System_Default);\n begin\n return String (Result);\n end Path;\n\n -- Using GNAT.Directory_Operations, make given filesystem path compatible\n -- with the current Operating System:\n -- Path (\"${HOME}/to/file\") => \"C:\\msys\\home\\user\\to\\file\" (windows)\n function Expand_Path (Original : String) return String is\n use Os_Files;\n Result : Path_Name :=\n Os_Files.Format_Pathname\n (Path =>\n Os_Files.Expand_Path (Path => Path_Name (Original), Mode => Both),\n Style => System_Default);\n begin\n return String (Result);\n end Expand_Path;\n\n -- Using GNAT.Directory_Operations and GNAT.OS_LIB, make given filesystem\n -- path compatible with the current Operating System, returning the full\n -- path: Full_Path (\"../to/file\") => \"C:\\dir\\dir\\to\\file\" (windows)\n function Full_Path (Original : String) return String is\n use Os;\n begin\n return Os.Normalize_Pathname (Path (Original));\n end Full_Path;\n\n User_Clientrc : String := Expand_Path (\"${HOME}/.xinitrc\");\n System_Clientrc : String := Path (\"/etc/X11/xinit/xinitrc\");\n\n User_Serverrc : String := Expand_Path (\"${HOME}/.xserverrc\");\n System_Serverrc : String := Path (\"/etc/X11/xinit/xserverrc\");\n Default_Client : String := \"xterm\";\n Default_Server : String := Path (\"/usr/bin/X\");\n\n Default_Client_Arguments_Access : Os.String_List_Access :=\n Os.Argument_String_To_List (\"\");\n\n Default_Server_Arguments_Access : Os.String_List_Access :=\n Os.Argument_String_To_List (\"\");\n\n Default_Client_Arguments : Os.String_List :=\n (if\n Default_Client_Arguments_Access /= null\n then\n Default_Client_Arguments_Access.all\n else Empty_List_Access.all);\n\n Default_Server_Arguments : Os.String_List :=\n (if\n Default_Server_Arguments_Access /= null\n then\n Default_Server_Arguments_Access.all\n else Empty_List_Access.all);\n\n-- Defaultdisplay = \":0\"\n-- Clientargs = \"\"\n-- Serverargs = \"\"\n-- Vtarg = \"\"\n-- Enable_Xauth = 1\n\n Env_Display : String := Env.Value (\"DISPLAY\", \"\");\n New_Display : String := \":\" & Create_Display_Number;\n\n Custom_Client_Access : Os.String_Access :=\n (if\n Ada.Command_Line.Argument_Count > 0\n then\n Os.Locate_Exec_On_Path (Ada.Command_Line.Argument (1))\n else null);\n Manager_Command_Access : Os.String_Access :=\n Os.Locate_Exec_On_Path (\"/usr/bin/dbus-launch\");\n Xterm_Command_Access : Os.String_Access :=\n Os.Locate_Exec_On_Path (\"/usr/bin/xterm\");\n Xnest_Command_Access : Os.String_Access :=\n Os.Locate_Exec_On_Path (\"/usr/bin/Xnest\");\n Xserver_Command_Access : Os.String_Access :=\n Os.Locate_Exec_On_Path (\"/usr/bin/Xserver\");\n Xinit_Command_Access : Os.String_Access := Os.Locate_Exec_On_Path (\"xinit\");\n\n Xterm_Background : String := \"black\";\n Xterm_Foreground : String := \"white\";\n Xterm_Scrollbar : Boolean := False;\n Xterm_Session_Management_Callbacks : Boolean := False;\n Xterm_Loginshell : Boolean := False;\n-- Xterm_Font : String := \"adobe-source code pro*\";\n-- Xterm_Font : String := \"gnu-unifont*\";\n Xterm_Font : String :=\n \"-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1\";\n Xterm_Font_Size : String := \"9\";\n Xterm_Lineshistory : String := \"4000\";\n Xterm_Cursorcolor : String := \"yellow\";\n Xterm_Border : String := \"256\";\n Xterm_Geometry : String := \"200x50+-128+-128\";\n-- Xterm_Geometry : String := \"260x70+-128+-128\";\n\n Xterm_Arguments : Os.Argument_List :=\n (new String'(\"-bg\"),\n new String'(Xterm_Background),\n new String'(\"-fg\"),\n new String'(Xterm_Foreground),\n (if Xterm_Scrollbar then new String'(\"-sb\") else new String'(\"+sb\")),\n (if Xterm_Session_Management_Callbacks then new String'(\"-sm\")\n else new String'(\"+sm\")),\n (if Xterm_Loginshell then new String'(\"-ls\") else new String'(\"+ls\")),\n new String'(\"-fs\"),\n new String'(Xterm_Font_Size),\n new String'(\"-fn\"),\n new String'\n (\"-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1\"),\n new String'(\"-sl\"),\n new String'(Xterm_Lineshistory),\n new String'(\"-cr\"),\n new String'(Xterm_Cursorcolor),\n new String'(\"-geometry\"),\n new String'(Xterm_Geometry),\n new String'(\"-b\"),\n new String'(Xterm_Border),\n new String'(\"-xrm\"),\n new String'(\"*overrideRedirect: True\"));\n Xterm_Command_Arguments : Os.Argument_List :=\n (new String'(\"--\"), Xterm_Command_Access) & Xterm_Arguments;\n\n Xnest_Title : String := \"Graphical Session\";\n-- Xnest_Foreground : String := \"white\";\n-- Xnest_Background : String := \"black\";\n Xnest_Geometry : String := \"1920x1080+-0+-0\";\n Xnest_Border : String := \"64\";\n\n Empty_Arguments : GNAT.OS_Lib.Argument_List (1 .. 0) := (others => null);\n\n Xnest_Arguments : GNAT.OS_Lib.Argument_List :=\n (new String'(New_Display),\n new String'(\"-display\"),\n new String'(Env_Display),\n new String'(\"-geometry\"),\n new String'(Xnest_Geometry),\n new String'(\"-name\"),\n new String'(Xnest_Title),\n new String'(\"-reset\"),\n new String'(\"-terminate\"),\n new String'(\"-fn\"),\n new String'\n (\"-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1\"),\n new String'(\"-bw\"),\n new String'(Xnest_Border));\n\n Xserver_Arguments : GNAT.OS_Lib.Argument_List :=\n (new String'(New_Display),\n new String'(\"-display\"),\n new String'(Env_Display),\n new String'(\"-geometry\"),\n new String'(Xnest_Geometry),\n new String'(\"-name\"),\n new String'(Xnest_Title),\n new String'(\"-reset\"),\n new String'(\"-terminate\"),\n new String'(\"-fn\"),\n new String'\n (\"-gnu-unifont-medium-r-normal-sans-16-160-75-75-c-80-iso10646-1\"),\n new String'(\"-bw\"),\n new String'(Xnest_Border));\n\n Launch_Status : Boolean := True;\n -- The return status of the command + arguments\n\n function Command_Arguments return GNAT.OS_Lib.Argument_List is\n Command_Words : GNAT.OS_Lib.Argument_List (1 .. Argument_Count) :=\n (others => null);\n Xterm_Command_Words : Os.String_List := Xterm_Command_Arguments;\n\n begin\n for N in 1 .. Argument_Count loop\n Command_Words (N) := new String'(Argument (N));\n\n end loop;\n\n if Command_Words'Length > 0 then\n return Command_Words;\n else\n return Xterm_Command_Words;\n end if;\n end Command_Arguments;\n\n procedure Launch\n (Command : String;\n Arguments : GNAT.OS_Lib.Argument_List) is\n Launch_Arguments : GNAT.OS_Lib.Argument_List := Arguments;\n begin\n GNAT.OS_Lib.Spawn (Command, Launch_Arguments, Launch_Status);\n end Launch;\n\n Launch_Error_Count : Integer := 0;\n\nbegin\n Env.Clear (\"SESSION_MANAGER\");\n Env.Set (\"DISPLAY\", Env_Display);\n\n declare\n Arguments : Os.Argument_List := Command_Arguments;\n Xnest : Os.Process_Id;\n Xserver : Os.Process_Id;\n Session_Manager : Os.Process_Id;\n Process_With_Exit : Os.Process_Id;\n -- Arguments => checked and tweaked argument list given at progam start\n -- Xnest => The instance of Xnest or Xorg that will be monitored, Session_Manager\n\n-- Xterm : OS.Process_Id;\n\n begin\n\n if Env_Display /= \"\" then\n if Xnest_Command_Access /= null\n and then Manager_Command_Access /= null\n then\n Xnest :=\n Os.Non_Blocking_Spawn\n (Xnest_Command_Access.all,\n Xnest_Arguments);\n Env.Set (\"DISPLAY\", New_Display);\n delay 0.02;\n Session_Manager :=\n Os.Non_Blocking_Spawn (Manager_Command_Access.all, Arguments);\n Os.Wait_Process (Process_With_Exit, Launch_Status);\n\n else\n Launch_Status := False;\n Xnest := Os.Invalid_Pid;\n Session_Manager := Invalid_Pid;\n\n end if;\n else\n --- Remaining startx operations go here. ---\n if Xserver_Command_Access /= null\n and then Manager_Command_Access /= null\n then\n Xserver :=\n Os.Non_Blocking_Spawn\n (Xserver_Command_Access.all,\n Xserver_Arguments);\n Env.Set (\"DISPLAY\", New_Display);\n delay 0.02;\n Session_Manager :=\n Os.Non_Blocking_Spawn (Manager_Command_Access.all, Arguments);\n Os.Wait_Process (Process_With_Exit, Launch_Status);\n\n else\n Launch_Status := False;\n Xnest := Os.Invalid_Pid;\n Session_Manager := Invalid_Pid;\n\n end if;\n\n end if;\n\n if not Launch_Status then\n Launch_Error_Count := Launch_Error_Count + 1;\n Set_Exit_Status (Failure);\n\n else\n Launch_Error_Count := 0;\n Set_Exit_Status (Success);\n end if;\n --Give return status back to calling os/environment.\n\n for I in Arguments'Range loop\n Free (Arguments (I));\n end loop;" + }, + { + "function_def": "procedure Ada_Time is", + "function_body": "use Ada.Text_IO;\n use Ada.Characters.Latin_1;\n use Ada.Text_IO.Text_Streams;\n use Ada.Calendar;\n use Ada.Calendar.Time_Zones;\n use Ada.Command_Line;\n use GNAT.Calendar.Time_IO;\n\n Now : Time := Clock;\n\n function Unix_Time return Time is\n use Ada.Calendar.Formatting;\n\n U_Year : Year_Number;\n U_Month : Month_Number;\n U_Day : Day_Number;\n U_Hour : Hour_Number;\n U_Minute : Minute_Number;\n U_Second : Second_Number;\n U_Duration : Second_Duration;\n begin\n Split\n (Date => Now,\n Year => U_Year,\n Month => U_Month,\n Day => U_Day,\n Hour => U_Hour,\n Minute => U_Minute,\n Second => U_Second,\n Sub_Second => U_Duration,\n Time_Zone => 0);\n\n return Time_Of\n (Year => U_Year,\n Month => U_Month,\n Day => U_Day,\n Hour => U_Hour,\n Minute => U_Minute,\n Second => U_Second,\n Sub_Second => U_Duration,\n Time_Zone => UTC_Time_Offset);\n end Unix_Time;\n\n function To_Multimedia\n (Time : String;\n Fraction : Boolean := True) return String\n -- Convert pure seconds ***.*** to multimedia time string **h**m**s Fraction\n -- boolean value specifies whether to include the fractional part of the\n -- time: **h**m**.***s\n is\n begin\n null;\n return \"\";\n end To_Multimedia;\n\n function To_Clock\n (Time : String;\n Fraction : Boolean := True) return String\n -- Convert pure seconds ***.*** to multimedia time string **:**:** Fraction\n -- boolean value specifies whether to include the fractional part of the\n -- time: **h**m**.***s\n is\n begin\n null;\n return \"\";\n end To_Clock;\n\n function To_Seconds (Time : String) return String\n -- Convert a Multimedia time string **h**m**s or **:**:**.*** to pure\n -- seconds ***.***\n is\n begin\n null;\n return \"\";\n end To_Seconds;\n\n function \"+\" (Left : String; Right : String) return String is\n use Ada.Characters.Latin_1;\n begin\n return Left & LF & Right;\n end \"+\";\n\n-- Unix_Time : Time :=\n-- Value (Date => Image (Date => Now, Include_Time_Fraction => True),\n-- Time_Zone => UTC_Time_Offset);\nbegin\n\n for A in 1 .. Argument_Count loop\n if Argument (A) = \"-iso\" or\n Argument (A) = \"-I\" or\n Argument (A) = \"-i\"\n then\n String'Write\n (Stream (Current_Output),\n Image (Date => Now, Picture => \"%Y-%m-%d\"));\n\n elsif Argument (A) = \"-n\" or Argument (A) = \"-nano\" then\n String'Write\n (Stream (Current_Output),\n Image (Date => Unix_Time, Picture => \"%s.%o\"));\n\n elsif Argument (A) (1) = '+' then\n declare\n Feature_Argument : String := Argument (A);\n\n begin\n String'Write\n (Stream (Current_Output),\n Image\n (Date => Now,\n Picture =>\n Picture_String\n (Feature_Argument\n (Feature_Argument'First + 1 ..\n Feature_Argument'Last))));" + }, + { + "function_def": "procedure ArrivalForRepair is", + "function_body": "package FloatIO is new Ada.Text_IO.Float_IO(float);\n use FloatIO;\n package IntIO is new Ada.Text_IO.Integer_IO(Integer);\n use IntIO;\n package Fix_IO is new Ada.Text_IO.Fixed_IO(DAY_DURATION); \n use Fix_IO;\n\n function intToChar is new Unchecked_Conversion(Integer, Character);\n charStar, charTie : Character := 'A';\n intStar, intTie : Integer := 64;\n\n subtype getChar is Character range 'A'..'Z';\n\tlastCharOfTie, lastCharOfStar : getChar := getChar'First;\n\n type vehicle is\n\t\t(Star_Destroyer, Tie_Fighter);\n\tpackage vechileIO is new Ada.Text_IO.Enumeration_IO(vehicle);\n\n\ttype vName is\n\t\t(Tie, Star);\n\tpackage nameIO is new Ada.Text_IO.Enumeration_IO(vName);\n\n -- Maintainance bay record\n type garageBay is record\n vehicleType : vehicle;\n vehicleName: String(1..5);\n time2Fix: integer;\n startTime: Time;\n finishTime: Time;\n\t\t--elapsedTime: DAY_DURATION;\n end record;\n\ta : garageBay;\n \n -- Function to determine if the arriving planes are Star or Tie\n function StarOrTie(x: in out integer) return garageBay is\n randNum: float;\n\t z,b,c,d : garageBay;\n e : Time := Clock;\n\n\t --seed: integer;\n begin\n\t \n randNum := next_float(x); -- 0.0 <= randNumm <= 1.0.\n\n if randNum <= 0.25 then\n\t\tz := (vehicleType => Tie_Fighter, vehicleName => \"Tie \", time2Fix => 0, startTime => e, finishTime => e);\n return a; -- return tie\n elsif randNum <= 0.5 then\n\t\tb := (vehicleType => Tie_Fighter, vehicleName => \"Tie \", time2Fix => 0, startTime => e, finishTime => e);\n return b; -- return tie\n elsif randNum <= 0.75 then\n\t \tc := (vehicleType => Tie_Fighter, vehicleName => \"Tie \", time2Fix => 0, startTime => e, finishTime => e);\n return c; -- return tie\n else\n\t \td := (vehicleType => Star_Destroyer, vehicleName => \"Star \", time2Fix => 0, startTime => e, finishTime => e);\n return d; -- return stsr\n end if;\n\n end StarOrTie;\n\t\n\n\n -- Determine the number of new arrivals for Step 1 in the lab.\n -- Either 1, 2, 3 or 4 uniformly distributed on each call.\n function NumberNewArrivals(x: in out integer) return Integer is\n randNum: float;\n begin\n randNum := next_float(x); -- 0.0 <= randNumm <= 1.0.\n\n if randNum <= 0.25 then\n return 1; -- return tie\n elsif randNum <= 0.5 then\n return 2; -- return tie\n elsif\n randNum <= 0.75 then\n return 3; -- return tie\n else\n return 4; -- return stsr\n end if;\n\n end NumberNewArrivals;\n\n Start,Finish, elapsed, secondus : DAY_DURATION;\n StartTime, ArrivTime, departTime, ElapsTime : Time := clock; \n -- Procedure to get start time\n \n --function startTime return DAY_DURATION is\n -- Year,Month,Day : INTEGER;\n --Start : DAY_DURATION;\n --Time_And_Date : TIME;\n --begin\n --Time_And_Date := Clock; -- gets system time\n --Split(Time_And_Date,Year, Month,Day,Start);\n --return Start; -- gets start time ( stores it in seconds in the variable Start)\n --end startTime;\n\n -- Procedure to get finish time\n \n function finishTime return DAY_DURATION is\n Year,Month,Day : INTEGER;\n Finish : DAY_DURATION;\n Time_And_Date : TIME;\n begin\n Time_And_Date := Clock; -- gets system time\n Split(Time_And_Date,Year, Month,Day,Finish);\n return Finish; -- gets start time ( stores it in seconds in the variable Start)\n end finishTime;\n\n \n numberArrivals,seed,upperbound,starKnt,tieKnt, dagobah, repairStar, repairTie: Integer := 0;\n decision: garageBay;\n ET: DAY_DURATION;\n\n \n\n\n\nbegin\n-- Get upperbound of the stack.\n put(\"Enter The Maximum Number Of Vehicles Allowed In The Garagebay:\"); new_line;\n\tget(upperbound);\n\t\n\tdeclare\n -- Instantiate the generic package for type garageBay.\n\tpackage genericS is new gstack(upperbound, garageBay);\n\tuse genericS;\n\tbegin\n -- Lab Step 0. write start time to service log.\n --start := startTime;\n --finish := finishTime;\n --elapsed := finish - start;\n \t--ET := elapsed;\n startTime := clock;\n\t\tput(Image(startTime, Time_Zone => -5*60) ); put(\" Garagebay is open \"); \n new_line;\n\n\n\n -- Seed the random number generator appropriately.\n put(\"Seed the random number generator:\"); new_line;\n get(seed);\n put(\"-----------------------------------------------------------------------------------\");new_line;\n -- do the operations\n --numberArrivals := 3; -- Assuming 3 vehicles at open.\n Loop\n numberArrivals := NumberNewArrivals(seed);\n put(\"Number of Arrivals: \");new_line;put(numberArrivals,0);new_line;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n for j in 1..numberArrivals \n loop\n \n --Determine if the arrival is a Tie Fighter or a Star Destroyer.\n --Prepare the maintenance record and place it in the appropriate queue.\n decision := StarOrTie(seed);\n\t\t\t if decision.vehicleType = Star_Destroyer \n\t\t\t then\n intStar := intStar + 1;\n if intStar = 91 then\n intStar := 65;\n end if; \n charStar := intToChar(intStar);\n decision.vehicleName(1..4) := \"Star\";\n\t\t\t\t decision.vehicleName(5) := charStar;\n\t\t\t\t decision.time2Fix := 7;\n ArrivTime := clock;\n decision.startTime := ArrivTime;\n \n spush(decision);\n ---\n --if dagobah > 0 then\n --put(\"Dagobah Count: \");put(dagobah);new_line;\n --put(\"-----------------------------------------------------------------------------------\");new_line;\n --end if;\n ---\n starKnt := starKnt +1;\n --put(\"Number of Arrivals: \");put(numberArrivals);new_line;\n put(Image(startTime, Time_Zone => -5*60) );put(\":\");new_line;\n put(decision.vehicleName & \" Arrived\");new_line(2);\n -- put(\"-----------------------------------------------------------------------------------\");new_line;\n\t\t\t else \n intTie := intTie + 1;\n if intTie = 91 then\n intTie := 65;\n end if; \n charTie := intToChar(intTie);\n\t\t\t\t decision.vehicleName(4) := charTie;\n\t\t\t\t decision.time2Fix := 3;\n ArrivTime := clock;\n decision.startTime := ArrivTime;\n departTime := clock;\n decision.finishTime := departTime;\n tpush(decision);\n --\n \n \n --\n tieKnt := tieKnt + 1;\n put(Image(startTime, Time_Zone => -5*60) );put(\":\");new_line;\n put(decision.vehicleName & \" Arrived\");new_line(2);\n\t\t\t end if;\n if tieKnt + starKnt > 20 then\n dagobah := dagobah + 1;\n end if;\n if dagobah > 0 then\n put(\"Dagobah Count: \");put(dagobah);new_line;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n end if;\n\t\t end loop;\n \n \n \n \n --Lab Step 2.\n if starKnt > 0 then \n spop(decision); starKnt := starKnt - 1;repairStar:= repairStar+ 1;\n delay 3.0;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n \n put(\"Vehicle Type: \");put(vehicle'image(decision.vehicleType));new_line;\n put(\"Vehicle Name: \" & decision.vehicleName);new_line;\n put(\"Time to Fix: \");put(decision.time2Fix,0);new_line;\n put(\"Start Time: \");put(Image(decision.startTime, Time_Zone => -5*60) );new_line;\n departTime := clock;\n --finishTime := departTime;\n put(\"Finish Time: \");put(Image(departTime, Time_Zone => -5*60 ));new_line;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n --if dagobah > 0 then\n -- put(\"Dagobah Count: \");put(dagobah);new_line;\n --end if;\n \n elsif starKnt = 0 then --and tieKnt > 0\n tpop(decision); tieKnt := tieKnt - 1;repairTie := repairTie + 1;\n delay 1.00;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n put(\"Vehicle Type: \");put(vehicle'image(decision.vehicleType));new_line;\n --put(\"Vehicle Name: \" & decision.vehicleName);new_line;\n put(\"Vehicle Name: \" & decision.vehicleName);new_line;\n put(\"Time to Fix: \");put(decision.time2Fix,0);new_line;\n put(\"Start Time: \");put(Image(decision.startTime, Time_Zone => -5*60) );new_line;\n departTime := clock;\n --finishTime := departTime;\n put(\"Finish Time: \");put(Image(departTime, Time_Zone => -5*60));new_line;\n --put(\"Start Time: \");put(Image(decision.startTime, Time_Zone => -5*60) );new_line;\n put(\"-----------------------------------------------------------------------------------\");new_line;\n \n \n end if;\n\n\n -- do the operations.\n \n --Lab Step 3.\n -- do the operations.\n \n --Lab Step 4.\n -- do the operations, prepare for the vext repair operations.\n if dagobah >= 5 then\n put(\"Total Time Elpased: \");put(Duration'image(Clock - startTime));put(\" Seconds\");new_line;\n put(\"No of Vehicles Repaired: \");put(repairStar + repairTie);put(\" Vehicles\");new_line;\n --put(\"No of Vehicles Repaired: \");put(repairStar + repairTie);put(\" Vehicles\");new_line;\n put(\"No of Star Destroyers Repaired: \");put(repairStar);new_line;\n put(\"No of Tie Fighters Repaired: \");put(repairTie);new_line;\n\n exit;\n end if;\n delay 2.0;\n end loop; \n \n -- Lab Step 5\n --Five vehicles rejected.\n --Calculate and print results" + }, + { + "function_def": "function Object_Distance( Obj: Thing_Type; Ray: Ray_Type ) return Float15 is", + "function_body": "begin\n\n case Obj.Kind is\n\n when Sphere =>\n\n declare\n Eo: constant Vector := Obj.Center - Ray.Start;\n V: constant Float15 := Eo * Ray.Dir;\n begin\n\n if V > 0.0 then\n declare\n Disc: constant Float15 := Obj.Radius2 - ( Eo * Eo - V * V );\n begin\n if Disc > 0.0 then\n return V - Sqrt(Disc);\n end if;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(A,\n B);\n Configure : B := Convert (My_Event);\n begin\n GPU.Resize\n (Context,\n C.unsigned (Configure.width),\n C.unsigned (Configure.height));" + }, + { + "function_def": "procedure Run is", + "function_body": "begin\n for II in 1 .. Int (Len) loop\n\t My_Queue.Enqueue (II);\n end loop;\n\n for II in 1 .. Int (Len) loop\n\t declare\n\t Current : Int;\n\t begin\n\t My_Queue.Dequeue (Current);\n\t if Current /= II then\n\t raise Program_Error with Int'Image (Current) & \" /= \" & Int'Image (II);\n\t end if;" + }, + { + "function_def": "procedure Do_Work is", + "function_body": "begin\n loop\n\t declare\n\t New_Command : Any_Command;\n\t begin\n\t My_Command_Queue.Dequeue (New_Command);\n\n\t case New_Command.C.T is\n\t when Invalid_Type =>\n\t\t raise Program_Error;\n\n\t when Write_Type =>\n\t\t Do_Write (New_Command.C.Write_Object);\n\t when Read_Type =>\n\t\t Do_Read (New_Command.C.Read_Object);\n\t when Poll_Type =>\n\t\t Do_Poll (New_Command.C.Poll_Object);\n\t when Remind_Me_Type =>\n\t\t Do_Remind_Me (New_Command.C.Remind_Me_Object);\n\t end case;" + }, + { + "function_def": "procedure init_simulation_engine_choice is", + "function_body": "begin\n simulation_engine_choice := QComboBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs (\"simulation_engine_choice\")));\n\n for s in simulation_engine loop\n QStringList_append(handle => simulation_engines, s => s2qs(enum_image_to_beautiful_image(s'Image)));\n end loop;\n\n QComboBox_addItems (handle => simulation_engine_choice, texts => simulation_engines);" + }, + { + "function_def": "procedure update_simulation is", + "function_body": "scenario_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(scenario_choice)));\n results : Simulation_Data := Simulation(Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));\n begin\n update_line_chart(results, QComboBox_currentText(scenario_choice));" + }, + { + "function_def": "procedure set_simulation_engine_panel is", + "function_body": "simulation_engine_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(simulation_engine_choice)));\n simulation_choice : Simulation_Engine := Simulation_Engine'Value(simulation_engine_name);\n stack : QStackedWidgetH := QStackedWidgetH (QObject_findChild (QObjectH (covidsim_form), s2qs (\"simulation_panels\")));\n begin\n\n if simulation_choice = XPH_Pharmaceutical then\n QStackedWidget_setCurrentIndex (stack, 0);\n slot_change_country_choice (s2qs (\"\"));\n end if;\n\n if simulation_choice = Lancet then\n QStackedWidget_setCurrentIndex (stack, 1);\n update_simulation; -- lancet model stuff TODO : move to lancet_model\n end if;" + }, + { + "function_def": "procedure init_chart is", + "function_body": "legend : QLegendH;\n chart_view : QGraphicsViewH;\n horizontal_layout : QBoxLayoutH := QHBoxLayout_create;\n begin\n chart := QChart_create;\n\n legend := QChart_legend (chart);\n QLegend_setVisible (legend, true);\n\n chart_view := QChartView_create (chart);\n QGraphicsView_setRenderHint (chart_view, QPainterAntialiasing);\n QBoxLayout_addWidget (horizontal_layout, QWidgetH(chart_view));\n\n QWidget_setLayout (QwidgetH (graphic_view), horizontal_layout);" + }, + { + "function_def": "procedure init_scenario_choices is", + "function_body": "begin\n scenario_choice := QComboBoxH (QObject_findChild (QObjectH (covidsim_form), s2qs (\"scenario_choice\")));\n\n for s in Scenario loop\n QStringList_append(handle => scenarios, s => s2qs(enum_image_to_beautiful_image(s'Image)));\n end loop;\n\n QComboBox_addItems (handle => scenario_choice, texts => scenarios);" + }, + { + "function_def": "procedure slot_export_to_csv is", + "function_body": "scenario_name : String := beautiful_image_to_enum_image(qs2s(QComboBox_currentText(scenario_choice)));\n results : Simulation_Data := Simulation(Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));\n begin\n Export_To_CSV (results, Scenario'Value(scenario_name), QSpinBox_value(number_population), QSpinBox_value(number_iterations));" + }, + { + "function_def": "procedure covidsim is", + "function_body": "begin\n\n covidsim_form_init;\n QWidget_show(covidsim_form);\n QApplication_invoke;" + }, + { + "function_def": "procedure init_country_choices is", + "function_body": "countries : QStringListH := QStringList_create;\n disable : integer := 0;\n begin\n for c in country loop\n QComboBox_addItem (country_choice, s2qs(all_countries(c).name));\n\n declare\n raw_ce : country_entries_array := get_country_data (data_filename, c);\n begin\n if raw_ce'length < 5 then\n QComboBox_setItemData (country_choice, country'pos(c), QVariant_create(disable), QtUserRole-1);\n end if;" + }, + { + "function_def": "procedure update_forecast_range_chart is", + "function_body": "axes : QObjectListH;\n forecast_last : qreal := qreal (QSpinBox_value (forecast_days_value));\n begin\n axes := QChart_axes(chart);\n QValueAxis_setRange(QAxisH(QObjectList_at(axes, 0)), 0.0, forecast_last);" + }, + { + "function_def": "procedure update_chart is", + "function_body": "current_index : integer := QComboBox_currentIndex (country_choice);\n c : country := country'val(current_index);\n\n start_date : QDateH := QDateTimeEdit_date (start_date_value);\n start_time : Time := time_of (QDate_year (start_date), QDate_month (start_date), QDate_day (start_date));\n\n end_date : QDateH := QDateTimeEdit_date (end_date_value);\n end_time : Time := time_of (QDate_year (end_date), QDate_month (end_date), QDate_day (end_date));\n\n country_ground_truth_first : QSeriesH;\n country_ground_truth_date_range : QSeriesH;\n country_ground_truth_last : QSeriesH;\n\n country_forecast : QSeriesH;\n\n procedure init_series is\n pen_first : QPenH := QPen_create(QColor_create(0,255,0));\n pen_date_range : QPenH := QPen_create(QColor_create(255,0,0));\n pen_last : QPenH := QPen_create(QColor_create(0,255,0));\n pen_forecast: QPenH := QPen_create(QColor_create(255,255,0));\n begin\n country_ground_truth_first := QLineSeries_create;\n QPen_setWidth(pen_first, 3);\n QAreaSeries_setPen(country_ground_truth_first, pen_first);\n\n country_ground_truth_date_range := QLineSeries_create;\n QPen_setWidth(pen_date_range, 3);\n QAreaSeries_setPen(country_ground_truth_date_range, pen_date_range);\n\n country_ground_truth_last := QLineSeries_create;\n QPen_setWidth(pen_last, 3);\n QAreaSeries_setPen(country_ground_truth_last, pen_last);\n\n country_forecast := QLineSeries_create;\n QPen_setWidth(pen_forecast, 3);\n QAreaSeries_setPen(country_forecast, pen_forecast);" + }, + { + "function_def": "procedure reset_chart is", + "function_body": "begin\n country_forecast_entries.clear;\n update_chart;\n update_forecast_range_chart;" + }, + { + "function_def": "procedure set_initial_date_limits is", + "function_body": "function find_first_case_date return integer is\n begin\n for i in country_entries.first_index .. country_entries.last_index loop\n if country_entries.element (i).cumulative_cases > 0.0 then\n return i;\n end if;\n end loop;\n return -1;" + }, + { + "function_def": "procedure update_min_max_date_limits is", + "function_body": "function get_maximum_start_time(end_time : time) return Time is\n begin\n return ada.calendar.arithmetic.\"-\" (end_time, 5);" + }, + { + "function_def": "procedure slot_compute_xph is", + "function_body": "c : country := country'val(QComboBox_currentIndex (country_choice));\n steps : integer := QSpinBox_value (steps_value);\n i,j,k,l,m : integer := steps + 1;\n size : integer := i*j*k*l*m;\n\n covid_data : country_entries_array := to_country_entries_array (country_entries);\n\n start_date : QDateH := QDateTimeEdit_date (start_date_value);\n start_time : Time := Ada.Calendar.Formatting.time_of (QDate_year (start_date), QDate_month (start_date), QDate_day (start_date));\n\n end_date : QDateH := QDateTimeEdit_date (end_date_value);\n end_time : Time := Ada.Calendar.Formatting.time_of (QDate_year (end_date), QDate_month (end_date), QDate_day (end_date));\n\n\n function get_date_index (date_time : time) return integer is\n begin\n for i in covid_data'range loop\n if covid_data (i).date = date_time then\n return i;\n end if;\n end loop;\n\n return -1;" + }, + { + "function_def": "procedure slot_export_to_csv;", + "function_body": "pragma Convention (C, slot_export_to_csv);" + }, + { + "function_def": "function Conversion is new Ada.Unchecked_Conversion(", + "function_body": "Source => Stream_Element_Array,\n\t\t\tTarget => Element_Type\n\t\t);\n\tbegin\n\t\tStream.Read(Buffer, Buffer_Last);\n\t\tElement_Count := Natural(Buffer_Last / Element_Length);\n\t\tLast := Item'First; -- + (Element_Count - 1);\n\t\tBuffer_I := 1;\n\t\tfor I in 1..Element_Count loop\n\t\t\tItem(Last) := Conversion(Buffer(Buffer_I .. Buffer_I + Element_Length - 1));\n\t\t\tLast := Index_Type'Succ(Last);\n\t\t\tBuffer_I := Buffer_I + Element_Length;\n\t\tend loop;\n\t\tLast := Index_Type'Pred(Last);" + }, + { + "function_def": "procedure Inst is new Read_Array(Element_Type => Character, Index_Type => Positive, Array_Type => String);", + "function_body": "begin\n\t\tInst(Stream, Item, Last);" + }, + { + "function_def": "procedure Test is", + "function_body": "B : Block_Header;\n C : Block_Header := Block_Header'(Status => Occupied,\n Prev_Block_Address => Address_Null,\n Prev_Block_Status => Absent,\n Next_Block_Status => Free,\n Size => 1);\n A : System.Address := SSE.To_Address(0);\n begin\n Set_Block_At_Address(A, 0, C);\n pragma Assert(Proof.Block_Present_At_Address(0));\n pragma Assert(Proof.Block_At_Address(0) = C);\n end Test;\n\n \n ---------------------------\n -- Work with Free Blocks --\n ---------------------------\n \n procedure Unlink_From_Free_List (Base : System.Address;\n Address : Aligned_Address;\n Block : in out Block_Header;\n Free_List : in out Free_Blocks_List)\n is\n Prev_Address : constant Aligned_Address := Block.Free_List.Prev_Address;\n Next_Address : constant Aligned_Address := Block.Free_List.Next_Address;\n begin\n pragma Assert(Proof.Block_Present_At_Address(Address));\n Remove_Block_At_Address(Base, Address);\n Proof.Remove_Block_From_Free_List_For_Size(Block.Size, Address);\n if Is_Block_Last_In_Free_List(Block) then\n Block.Free_List := Empty_Free_List;\n Free_List := Empty_Free_List;\n else\n declare\n Prev_Block : Block_Header := Get_Block_At_Address(Base, Prev_Address);\n Next_Block : Block_Header := Get_Block_At_Address(Base, Next_Address);\n begin\n Remove_Block_At_Address(Base, Prev_Address);\n Remove_Block_At_Address(Base, Next_Address);\n \n Prev_Block.Free_List.Next_Address := Next_Address;\n Next_Block.Free_List.Prev_Address := Prev_Address;\n \n Set_Block_At_Address(Base, Prev_Address, Prev_Block);\n Set_Block_At_Address(Base, Next_Address, Next_Block);" + }, + { + "function_def": "procedure Main is", + "function_body": "function \"+\"\n (Item : Wide_Wide_String) return League.Strings.Universal_String\n renames League.Strings.To_Universal_String;\n\n function Get_OAuth_Parameter\n (Name : Wide_Wide_String) return League.Strings.Universal_String;\n function Get_Auth_URL return League.Strings.Universal_String;\n function Encode (Text : String) return League.Strings.Universal_String;\n\n procedure Get_Tokens\n (Code : Wide_Wide_String;\n Access_Token : out League.Strings.Universal_String);\n\n ------------\n -- Encode --\n ------------\n\n function Encode (Text : String) return League.Strings.Universal_String is\n begin\n return League.Strings.From_UTF_8_String (AWS.URL.Encode (Text));\n end Encode;\n\n ------------------\n -- Get_Auth_URL --\n ------------------\n\n function Get_Auth_URL return League.Strings.Universal_String is\n Result : League.Strings.Universal_String;\n begin\n Result.Append (\"https://accounts.google.com/o/oauth2/v2/auth\");\n\n Result.Append (\"?client_id=\");\n Result.Append (Get_OAuth_Parameter (\"client_id\"));\n\n Result.Append (\"&redirect_uri=urn:ietf:wg:oauth:2.0:oob\");\n\n Result.Append (\"&response_type=code\");\n\n Result.Append (\"&scope=\");\n Result.Append\n (Encode (\"https://www.googleapis.com/auth/photoslibrary.readonly\"));\n\n return Result;\n end Get_Auth_URL;\n\n -------------------\n -- Get_OAuth_Parameter --\n -------------------\n\n function Get_OAuth_Parameter\n (Name : Wide_Wide_String) return League.Strings.Universal_String\n is\n Key : constant Wide_Wide_String := \"oauth/\" & Name;\n Settings : League.Settings.Settings;\n begin\n return League.Holders.Element (Settings.Value (+Key));\n end Get_OAuth_Parameter;\n\n procedure Get_Tokens\n (Code : Wide_Wide_String;\n Access_Token : out League.Strings.Universal_String)\n is\n Result : AWS.Response.Data;\n Parameters : League.Strings.Universal_String;\n begin\n Parameters.Append (\"code=\");\n Parameters.Append (Code);\n Parameters.Append (\"&client_id=\");\n Parameters.Append (Get_OAuth_Parameter (\"client_id\"));\n Parameters.Append (\"&client_secret=\");\n Parameters.Append (Get_OAuth_Parameter (\"client_secret\"));\n Parameters.Append (\"&grant_type=authorization_code\");\n Parameters.Append (\"&redirect_uri=urn:ietf:wg:oauth:2.0:oob\");\n\n Result := AWS.Client.Post\n (URL => \"https://oauth2.googleapis.com/token\",\n Data => Parameters.To_UTF_8_String,\n Content_Type => \"application/x-www-form-urlencoded\");\n\n if AWS.Response.Status_Code (Result) not in AWS.Messages.Success then\n Ada.Wide_Wide_Text_IO.Put_Line\n (AWS.Messages.Status_Code'Wide_Wide_Image\n (AWS.Response.Status_Code (Result)));\n Ada.Wide_Wide_Text_IO.Put_Line\n (AWS.Response.Content_Length_Type'Wide_Wide_Image\n (AWS.Response.Content_Length (Result)));\n Ada.Text_IO.Put_Line (AWS.Response.Content_Type (Result));\n Ada.Text_IO.Put_Line (AWS.Response.Message_Body (Result));\n raise Program_Error with \"Unexpected response\";\n end if;\n\n declare\n Document : constant League.JSON.Documents.JSON_Document :=\n League.JSON.Documents.From_JSON\n (AWS.Response.Message_Body (Result));\n begin\n Access_Token :=\n Document.To_JSON_Object.Value (+\"access_token\").To_String;" + }, + { + "function_def": "procedure Offmt_Tool is", + "function_body": "package Helpers renames Libadalang.Helpers;\n package LAL renames Libadalang.Analysis;\n package LALU renames Libadalang.Unparsing;\n package LALCO renames Libadalang.Common;\n package LALRW renames Libadalang.Rewriting;\n package LALEXPR renames Libadalang.Expr_Eval;\n\n All_Traces : Offmt_Lib.Trace_Map;\n\n function Base_Name (Full_Path : String) return String;\n\n procedure Setup (Ctx : Helpers.App_Context;\n Jobs : Helpers.App_Job_Context_Array);\n\n procedure Process_Unit (Job_Ctx : Helpers.App_Job_Context;\n Unit : LAL.Analysis_Unit);\n\n procedure Post_Process (Ctx : Helpers.App_Context;\n Jobs : Helpers.App_Job_Context_Array);\n\n procedure Output_Unit\n (Job_Ctx : Libadalang.Helpers.App_Job_Context;\n Unit : Libadalang.Analysis.Analysis_Unit;\n Out_Dir_Path : GNATCOLL.Strings.XString);\n\n procedure Output_Map (Map : Offmt_Lib.Trace_Map);\n\n function Map_Filename return String;\n\n procedure Handle_Log_Call (RH : LALRW.Rewriting_Handle;\n Node : LAL.Call_Stmt'Class);\n\n package App is new Helpers.App\n (Name => To_String (Offmt_Lib.Log_Root_Pkg),\n Description => \"Offloaded string format\",\n App_Setup => Setup,\n App_Post_Process => Post_Process,\n Process_Unit => Process_Unit);\n\n package Output_Dir is new GNATCOLL.Opt_Parse.Parse_Option\n (Parser => App.Args.Parser,\n Long => \"--output-dir\",\n Arg_Type => GNATCOLL.Strings.XString,\n Convert => GNATCOLL.Opt_Parse.Convert,\n Default_Val => GNATCOLL.Strings.Null_XString,\n Help =>\n \"The directory in which to output the instrumented ada units.\"\n & \"When invoked with a project file, this path is treated as \"\n & \"relative to the (sub-)projects' object directories, unless \"\n & \"this is an absolute path.\");\n\n Instr_Mode_Long : constant String := \"--instrument\";\n Decode_Mode_Long : constant String := \"--decode\";\n\n package Instrument_Mode is new GNATCOLL.Opt_Parse.Parse_Flag\n (Parser => App.Args.Parser,\n Long => Instr_Mode_Long,\n Help => \"Enable instrumentation mode\");\n\n package Decode_Mode is new GNATCOLL.Opt_Parse.Parse_Flag\n (Parser => App.Args.Parser,\n Long => Decode_Mode_Long,\n Help => \"Enable decode mode\");\n\n ---------------\n -- Base_Name --\n ---------------\n\n function Base_Name (Full_Path : String) return String is\n use GNATCOLL.VFS;\n begin\n return +Create (+Full_Path).Base_Name;\n end Base_Name;\n\n ------------------\n -- Map_Filename --\n ------------------\n\n function Map_Filename return String is\n\n Out_Dir : constant VFS.Virtual_File :=\n VFS.Create_From_Base (VFS.\"+\" (Strings.To_String (Output_Dir.Get)));\n\n Out_File : constant VFS.Virtual_File :=\n VFS.Join (Out_Dir, \"offmt_map.toml\");\n\n begin\n return VFS.\"+\" (Out_File.Full_Name);\n end Map_Filename;\n\n ---------------------\n -- Handle_Log_Call --\n ---------------------\n\n procedure Handle_Log_Call (RH : LALRW.Rewriting_Handle;\n Node : LAL.Call_Stmt'Class)\n is\n Call : LAL.Call_Expr;\n begin\n if Offmt_Lib.Detection.Check_Defmt_Log_Call (Node, Call) then\n declare\n S : constant LAL.Ada_Node := Call.F_Suffix;\n Arg : LAL.Expr;\n begin\n\n Arg := S.Child (1).As_Param_Assoc.F_R_Expr;\n declare\n Arg_Val : constant LALEXPR.Eval_Result :=\n LALEXPR.Expr_Eval (Arg);\n begin\n case Arg_Val.Kind is\n when LALEXPR.String_Lit =>\n declare\n use Langkit_Support.Text;\n Txt : constant Text_Type\n := To_Text (Arg_Val.String_Result);\n Str : constant String := Image (Txt);\n Trace : constant Offmt_Lib.Trace :=\n Offmt_Lib.Parser.Parse (Str);\n begin\n Put_Line (Str);\n Offmt_Lib.Pretty_Print (Trace);\n Offmt_Lib.Rewrite.Rewrite_Log_Call (RH, Node, Trace);\n All_Traces.Include (Trace.Id, Trace);" + }, + { + "function_def": "procedure adainit is", + "function_body": "Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n null;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n\n E78 := E78 + 1;\n Cortex_M.Nvic'Elab_Spec;\n E76 := E76 + 1;\n E68 := E68 + 1;\n E28 := E28 + 1;\n E70 := E70 + 1;\n Nrf.Interrupts'Elab_Body;\n E72 := E72 + 1;\n E34 := E34 + 1;\n E37 := E37 + 1;\n E56 := E56 + 1;\n E54 := E54 + 1;\n E84 := E84 + 1;\n E80 := E80 + 1;\n E41 := E41 + 1;\n E44 := E44 + 1;\n E48 := E48 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E06 := E06 + 1;\n NRF52_DK.IOS'ELAB_SPEC;\n NRF52_DK.IOS'ELAB_BODY;\n E52 := E52 + 1;\n NRF52_DK.TIME'ELAB_BODY;\n E82 := E82 + 1;\n E87 := E87 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n adainit;\n Ada_Main_Program;" + }, + { + "function_def": "procedure adainit is", + "function_body": "Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n null;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n\n E78 := E78 + 1;\n Cortex_M.Nvic'Elab_Spec;\n E76 := E76 + 1;\n E68 := E68 + 1;\n E28 := E28 + 1;\n E70 := E70 + 1;\n Nrf.Interrupts'Elab_Body;\n E72 := E72 + 1;\n E34 := E34 + 1;\n E37 := E37 + 1;\n E56 := E56 + 1;\n E54 := E54 + 1;\n E84 := E84 + 1;\n E80 := E80 + 1;\n E41 := E41 + 1;\n E44 := E44 + 1;\n E48 := E48 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E06 := E06 + 1;\n NRF52_DK.IOS'ELAB_SPEC;\n NRF52_DK.IOS'ELAB_BODY;\n E52 := E52 + 1;\n NRF52_DK.TIME'ELAB_BODY;\n E82 := E82 + 1;\n E87 := E87 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n adainit;\n Ada_Main_Program;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => File_Type,\n Name => File_Pt);\n begin\n case What.Class is\n when None | Standard_Output =>\n null;\n\n when File =>\n Close (What.F.all);\n Free (What.F);\n end case;\n\n end Close;\n\n function To_File_Access (What : Extended_File) return File_Access\n is (case What.Class is\n when None =>\n null,\n\n when Standard_Output =>\n Standard_Output,\n\n when File =>\n File_Access (What.F));\n\n\n --------------------------\n -- Print_Warning_Header --\n --------------------------\n\n procedure Print_Warning_Header (To : File_Access)\n is\n\n begin\n Put_Line (To.all, \"%\");\n Put_Line (To.all, \"%---\");\n Put_Line (To.all, \"% WARNING: Automatically generated file\");\n Put_Line (To.all, \"% WARNING: If you edit this your changes will be lost\");\n Put_Line (To.all, \"%---\");\n Put_Line (To.all, \"%\");\n New_Page (To.all);\n end Print_Warning_Header;\n\n\n --------------------\n -- Print_Partners --\n --------------------\n\n procedure Print_Partners (Input : EU_Projects.Projects.Project_Descriptor;\n Target : Target_Spec)\n is\n use EU_Projects.Nodes.Partners;\n\n procedure Print_Partners (To : File_Access) is\n procedure Print_Single_Partner (To : File_Type; Partner : Partner_Access) is\n begin\n Put_Line (To, \"\\newpartner\"\n & \"{\" & Partner.Short_Name & \"}\"\n & \"{\" & To_String (Partner.Label) & \"}\"\n & \"{\" & Partner.Name & \"}\"\n & \"{\" & Partner.Country & \"}\");\n end Print_Single_Partner;\n begin\n for Idx in Input.All_Partners loop\n Print_Single_Partner (To.all, Element (Idx));\n end loop;\n end Print_Partners;\n\n Output : Extended_File := Open (Target);\n begin\n if Output.Class = None then\n return;\n end if;\n\n Within (Output => To_File_Access (Output),\n Env_Name => \"partnerlist\",\n Callback => Print_Partners'Access);\n\n Close (Output);\n end Print_Partners;\n\n\n ------------------\n -- Define_Label --\n ------------------\n\n procedure Define_Label (Output : File_Type;\n Item : Node_Type'Class;\n Prefix : String;\n Add_New_Line : Boolean := True)\n is\n begin\n Put (Output,\n \"\\failabel{\" & Image (Item.Label) & \"}\"\n & \"{\" & Prefix & \"}\"\n & \"{\" & Item.Short_Name & \"}\"\n & \"{\" & Item.Full_Index (False) & \"}\");\n\n if Add_New_Line then\n New_Line (Output);\n end if;\n end Define_Label;\n ------------------\n -- Join_Indexes --\n ------------------\n\n function Join_Indexes (Input : EU_Projects.Projects.Project_Descriptor;\n Labels : Node_Label_Lists.Vector;\n Separator : String)\n return String\n is\n Result : Unbounded_String;\n begin\n for Idx in Labels.Iterate loop\n Result := Result & Input.Find (Labels (Idx)).Full_Index (Prefixed => True);\n\n if Node_Label_Lists.To_Index (Idx) < Labels.Last_Index then\n Result := Result & Separator;\n end if;\n end loop;\n\n return To_String (Result);\n end Join_Indexes;\n\n procedure Print_WP (Input : Project_Descriptor;\n Output : Extended_File;\n WP : WPs.Project_WP_Access) is\n\n\n Efforts : constant Action_Nodes.Effort_List :=\n WP.Efforts_Of (Input.Partner_Names);\n\n\n function Short_Name (X : Partners.Partner_Label) return String\n is\n N : constant Node_Access := Input.Find (Node_Label (X));\n begin\n if N = null then\n raise Processor_Error\n with \"Unknown partner '\" & Image (Node_Label (X)) & \"'\";\n else\n return N.Short_Name;\n end if;\n end Short_Name;\n\n procedure Write_WP_Header (Output : File_Access;\n Table : in out Table_Handler)\n is\n pragma Unreferenced (Output);\n\n Headstyle : constant String := \"\\stilehead\";\n\n procedure Put_Pair (Title, Content : String) is\n begin\n Table.Put (Title, Headstyle);\n Table.Put (Content);\n end Put_Pair;\n\n procedure First_Row_Standard_Style is\n begin\n Table.Cline (1, 4);\n Put_Pair (\"WP Number\", WP.Index_Image);\n Put_Pair (\"Leader\", Short_Name (WP.Leader));\n Table.Hline;\n\n Table.Put (\"WP Name\", Headstyle);\n Table.Multicolumn (Span => Efforts'Length + 1,\n Spec => \"|l|\",\n Content => WP.Name);\n\n end First_Row_Standard_Style;\n\n procedure First_Row_Compact_Style is\n begin\n Table.Hline;\n Put_Pair (\"WP N.\", WP.Index_Image);\n\n Table.Put (\"WP Name\", Headstyle);\n Table.Multicolumn (Span => Efforts'Length - 4,\n Spec => \"|l|\",\n Content => WP.Name);\n\n Table.Put (\"\\WPleadertitle\");\n Table.Multicolumn (Span => 2,\n Spec => \"c|\",\n Content =>\n \"\\WPleadername{\" & Short_Name (WP.Leader) & \"}\");\n end First_Row_Compact_Style;\n begin\n if True then\n First_Row_Compact_Style;\n else\n First_Row_Standard_Style;\n end if;\n\n Table.Hline;\n\n Table.Put (\"N. Partner\", Headstyle);\n\n for Idx in Efforts'Range loop\n Table.Put (Image (Idx));\n end loop;\n Table.Put (\"\");\n Table.Hline;\n\n Table.Put (\"Name\", Headstyle);\n\n for Idx in Efforts'Range loop\n Table.Put (Short_Name (Efforts (Idx).Partner));\n end loop;\n Table.Put (\"all\");\n Table.Hline;\n\n Table.Put (\"PM\", Headstyle);\n\n declare\n use EU_Projects.Efforts;\n\n Total_Effort : Person_Months := 0;\n begin\n for Idx in Efforts'Range loop\n Table.Put (Chop (Efforts (Idx).Effort'Image));\n\n Total_Effort := Total_Effort + Efforts (Idx).Effort;\n end loop;\n\n Table.Put (Chop (Total_Effort'Image));" + }, + { + "function_def": "-- procedure Full_Header is", + "function_body": "--\n -- begin\n -- Table.Hline;\n -- Table.Head (\"WP\");\n -- Table.Head (\"WP Name\");\n -- Table.Multicolumn (2, \"|c|\", \"\\stilehead{Leader}\");\n -- -- Table.Put (\"Leader N.\", \"\\stilehead\");\n -- -- Table.Put (\"Leader\"\");\n -- Table.Head (\"PM\");\n -- Table.Head (\"Start\");\n -- Table.Head (\"End\");\n -- Table.Cline (3, 4);\n --\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Head (\"Name\");\n -- Table.Head (\"N.\");\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- end Full_Header;\n --\n -- procedure Light_Header is\n --\n -- begin\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Multicolumn (2, \"c\", \"\\stilehead{Leader}\");\n -- -- Table.Put (\"Leader N.\", \"\\stilehead\");\n -- -- Table.Put (\"Leader\"\");\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Put (\"\");\n -- Table.Cline (3, 4);\n --\n -- Table.Multicolumn (1, \"c\", \"WP\");\n -- Table.Multicolumn (1, \"c\", \"WP Name\");\n -- Table.Multicolumn (1, \"c\", \"Name\");\n -- Table.Multicolumn (1, \"c\", \"N.\");\n -- Table.Multicolumn (1, \"c\", \"~\");\n -- Table.Multicolumn (1, \"c\", \"PM\");\n -- Table.Multicolumn (1, \"c\", \"Start\");\n -- Table.Multicolumn (1, \"c\", \"End\");\n -- end Light_Header;\n\n Project_Effort : Person_Months := 0;\n\n begin\n -- case Style is\n -- when Full => Full_Header;\n -- when Light => Light_Header;\n -- end case;\n\n Put_Line (Output.all, \"\\summarywptableheader\");\n\n -- Table.Hline;\n\n\n for Pos in Input.All_WPs loop\n declare\n use EU_Projects.Nodes.Partners;\n\n procedure Put_Arg (X : String) is\n begin\n Put (Output.all, \"{\" & X & \"}\");\n end Put_Arg;\n\n WP : constant Project_WP_Access := Element (Pos);\n Wp_Effort : constant Person_Months := Total_Effort (Wp);\n Leader : constant Partner_Access :=\n Partner_Access (Input.Find (Node_Label (WP.Leader)));\n begin\n Put (Output.all, \"\\summarywpitem\");\n\n Put_Arg (WP.Full_Index (Prefixed => False));\n Put_Arg (WP.Short_Name);\n Put_Arg (Leader.Short_Name);\n Put_Arg (Leader.Full_Index (Prefixed => False));\n Put_Arg (Chop (Wp_Effort'Image));\n Put_Arg (EU_Projects.Times.Image (Formatter, Wp.Starting_Time));\n Put_Arg (EU_Projects.Times.Image (Formatter, Wp.Ending_Time));\n\n New_Line (Output.all);\n Project_Effort := Project_Effort + Wp_Effort;\n -- Table.Hline (Style = Full);" + }, + { + "function_def": "procedure Compact_Header_Line is", + "function_body": "begin\n Table.Multicolumn (2, \"c\", \"\");\n\n for M in 1 .. Last_Month loop\n if M mod Step = 0 then\n Table.Multicolumn\n (Span => 1,\n Spec => \"c\",\n Content => \"\\stilemese{\" & Image (M) & \"}\");\n else\n Table.Put (\"\");\n end if;\n\n Table.Put (\"\");\n end loop;\n\n Table.New_Row;\n end Compact_Header_Line;\n\n procedure First_Header_Line is\n begin\n Table.Put (\"\");\n Table.Put (\"\");\n for M in 1 .. Last_Month loop\n if M mod Step = 0 and M > 9 then\n Table.Put (Image (M / 10));\n else\n Table.Put (\"\");\n end if;\n\n Table.Put (\"\");\n end loop;\n\n Table.New_Row;\n end First_Header_Line;\n\n procedure Second_Header_Line is\n begin\n Table.Put (\"\");\n Table.Put (\"\");\n for M in 1 .. Last_Month loop\n if M mod Step = 0 then\n Table.Put (Image (M mod 10));\n else\n Table.Put (\"\");\n end if;\n\n Table.Put (\"\");\n end loop;\n\n Table.New_Row;\n end Second_Header_Line;\n\n procedure Show_Busy_Time (Item : EU_Projects.Nodes.Action_Nodes.Action_Node'Class)\n is\n\n From : constant Instant := Item.Starting_Time;\n To : constant Instant := Item.Ending_Time;\n begin\n if From = To_Be_Decided or To = To_Be_Decided then\n for M in 1 .. Last_Month loop\n Table.Put (\"\\TBDcell\");\n\n Table.Put (\"\");\n end loop;\n else\n declare\n T : Instant;\n begin\n for M in 1 .. Last_Month loop\n T := To_Instant (M);\n\n Table.Put ((if T >= From and then T <= To\n then\n \"\\busytimecell\"\n else\n \"\\freetimecell\"));\n\n\n Table.Put (\"\");\n end loop;" + }, + { + "function_def": "procedure Make_WP_Separator;", + "function_body": "Current_V_Pos : Picture_Length;\n\n function Month_Position (Month : Projects.Month_Number;\n Setup : Graphic_Setup_Descriptor)\n return Picture_Length\n is (Setup.Label_Size + (Integer (Month) - 1) * Setup.Month_Width);\n\n function To_Length (L : Picture_Length;\n Setup : Graphic_Setup_Descriptor)\n return Latex_Length\n is (Float (L) * Setup.Unit_Length);\n\n procedure Next_Row is\n begin\n -- Put_Line (Current_V_Pos'Image);\n -- Put_Line (Graphic_Setup.Month_Heigth'Image);\n -- Put_Line (Graphic_Setup.Interline'image);\n Current_V_Pos := Current_V_Pos - Graphic_Setup.Line_Heigth;\n end Next_Row;\n\n procedure Show_Busy_Time (Item : EU_Projects.Nodes.Action_Nodes.Action_Node'Class;\n Style : String;\n Intensity : EU_Projects.Nodes.Action_Nodes.Tasks.Task_Intensity)\n is\n\n procedure Make_Bar (From, To : Month_Number;\n Command : String;\n Show_Intensity : Boolean) is\n Start : constant Picture_Length :=\n Month_Position (From, Graphic_Setup);\n\n Len : constant Latex_Length :=\n To_Length (Month_Position (To, Graphic_Setup)-Start, Graphic_Setup);\n\n Shrink : constant Float := 0.8;\n H : constant Latex_Length :=\n Shrink * To_Length (Graphic_Setup.Line_Heigth, Graphic_Setup);\n\n H2 : constant Latex_Length := Float'Max (Intensity, 0.15) * H;\n\n Box_Raise : constant Latex_Length :=\n (1.0 - Shrink) * 0.5 * To_Length (Graphic_Setup.Line_Heigth, Graphic_Setup);\n begin\n if Show_Intensity then\n Put_Line (Output.all, Put (X => Start,\n Y => Current_V_Pos,\n What => Style\n & \"{\"\n & (\n \"\\shadedrule\"\n & \"[\" & Image (Box_Raise) & \"]\"\n & \"{\" & Image (Len) & \"}\"\n & \"{\" & Image (H) & \"}\"\n )\n & \"}\"));\n\n Put_Line (Output.all, Put (X => Start,\n Y => Current_V_Pos,\n What => Style\n & \"{\"\n & (\n Command\n & \"[\" & Image (Box_Raise) & \"]\"\n & \"{\" & Image (Len) & \"}\"\n & \"{\" & Image (H2) & \"}\"\n )\n & \"}\"));\n else\n Put_Line (Output.all, Put (X => Start,\n Y => Current_V_Pos,\n What => Style\n & \"{\"\n & (\n Command\n & \"[\" & Image (Box_Raise) & \"]\"\n & \"{\" & Image (Len) & \"}\"\n & \"{\" & Image (H) & \"}\"\n )\n & \"}\"));\n end if;\n\n declare\n Dx : constant Picture_Length := Picture_Length (Len / Graphic_Setup.Unit_Length);\n Dy : constant Picture_Length := Picture_Length (H / Graphic_Setup.Unit_Length);\n B : constant Picture_Length := Picture_Length (Box_Raise / Graphic_Setup.Unit_Length);\n Y0 : constant Picture_Length := Current_V_Pos + B;\n begin\n Put_Line (Output.all, Put (X => Start,\n Y => Y0,\n What => HLine (Dx)));\n\n\n Put_Line (Output.all, Put (X => Start,\n Y => Y0,\n What => Vline (Dy)));\n\n Put_Line (Output.all, Put (X => Start,\n Y => Y0 + Dy,\n What => HLine (Dx)));\n\n\n Put_Line (Output.all, Put (X => Start + Dx,\n Y => Y0,\n What => VLine (Dy)));" + }, + { + "function_def": "procedure Prova_Parser is", + "function_body": "type Class is (Wp, Tsk, Deliv);\n\n package My_Parser is new Node_List_Parsers (Class);\n use My_Parser;\n\n Eol : constant Character := Character'Val (10);\n X : constant String := \"\" & Eol\n & \"\" & Eol\n & \"\" & Eol\n & \" [ Wp ]\" & Eol\n & \"name : zorro\" & Eol\n & \"label : pluto \" & Eol\n & \"Viva la pappa col pomodoro\" & Eol\n & \"\" & Eol\n & \"\" & Eol\n & \"[task]\" & Eol\n & \"begin:12\" & Eol;\n\n Names : My_Parser.Name_Maps.Map;\nbegin\n Names.Insert (Key => +\"task\",\n New_Item => Tsk);\n\n declare\n Result : constant Node_List := Parse (Line_Arrays.Split (X), Names);\n begin\n Dump (Result);" + }, + { + "function_def": "function Missing_Message (Missing : String_Lists.List)", + "function_body": "return String\n is\n function Join (Item : String_Lists.List) return String is\n Result : Unbounded_String;\n\n procedure Append (Pos : String_Lists.Cursor) is\n begin\n if Result /= Null_Unbounded_String then\n Result := Result & \", \";\n end if;\n\n Result := Result & \"'\" & String_Lists.Element (Pos) & \"'\";\n end Append;\n begin\n Item.Iterate (Append'Access);\n\n return To_String (Result);\n end Join;\n\n use type Ada.Containers.Count_Type;\n begin\n if Missing.Length = 1 then\n return \"Missing mandatory option \" & Join (Missing);\n else\n return \"Missing mandatory options: \" & Join (Missing);\n end if;\n end Missing_Message;\n\n function Collect_Parameters (Extra : String_Vectors.Vector)\n return String_Vectors.Vector\n is\n Result : String_Vectors.Vector;\n begin\n for Idx in 1 .. Command_Line.Argument_Count loop\n Result.Append (Command_Line.Argument (Idx));\n end loop;\n\n Result.Append (Extra);\n\n return Result;\n end Collect_Parameters;\n\n\n Name : Unbounded_String;\n Value : Unbounded_String;\n\n use Name_To_Index_Maps;\n\n Position : Name_To_Index_Maps.Cursor;\n Param_Idx : Parameter_Index;\n\n Arguments : constant String_Vectors.Vector := Collect_Parameters (Extend_By);\n begin\n for Pos in Arguments.First_Index .. Arguments.Last_Index loop\n Split_Parameter (Arguments (Pos), Name, Value);\n declare\n N : String := To_S (Name);\n V : constant String := To_S (Value);\n Handler : Handler_Access;\n This_Parameter : Parameter_Descriptor;\n begin\n Case_Normalize (N, Parser.Case_Sensitive);\n\n Position := Parser.Name_Table.Find (N);\n\n if Position = No_Element then\n raise Bad_Command with \"Option '\" & To_S (Name) & \"' unknown\";\n end if;\n\n Param_Idx := Name_To_Index_Maps.Element (Position);\n This_Parameter := Parser.Parameters (Param_Idx);\n Handler := This_Parameter.Handler;\n\n if Handler.Is_Set and not Handler.Reusable then\n raise Bad_Command with \"Option '\" & N & \"' given twice\";\n end if;\n\n Handler.Receive (Name => (\n if Parser.Normalize_Name then\n To_S (This_Parameter.Standard_Name)\n else\n N\n ),\n Value => V,\n Position => Pos);" + }, + { + "function_def": "procedure Initialize is", + "function_body": "use Line_Parsers;\n\n Parser : Line_Parser := Create (Case_Sensitive => False);\n begin\n Add_Parameter (Parser,\n Name => \"in,input\",\n If_Missing => Die,\n Default => \"\",\n Handler => Input_File'Access);\n\n Add_Parameter (Parser,\n Name => \"p,proc,processor\",\n If_Missing => Ignore,\n Default => \"\",\n Handler => Processors'Access);\n\n\n Add_Parameter (Parser,\n Name => \"f,fmt,format\",\n If_Missing => Ignore,\n Default => \"\",\n Handler => Format'Access);\n\n Parse_Command_Line (Parser, Slurp (\"pjp.conf\"));\n end Initialize;\n\n -----------------------------\n -- Parse_Plugin_Parameters --\n -----------------------------\n\n generic\n type Plugin_Name_Type is private;\n\n with function To_Name (X : String) return Plugin_Name_Type;\n procedure Parse_Plugin_Specs\n (Input : String;\n Plugin_Name : out Plugin_Name_Type;\n Parameters : out Plugins.Parameter_Map;\n Plugin_Name_Separator : Character := ':';\n Pair_Separator : Character := ';';\n Value_Separator : Character := '=');\n\n procedure Parse_Plugin_Specs\n (Input : String;\n Plugin_Name : out Plugin_Name_Type;\n Parameters : out Plugins.Parameter_Map;\n Plugin_Name_Separator : Character := ':';\n Pair_Separator : Character := ';';\n Value_Separator : Character := '=')\n is\n use Tokenize;\n\n procedure Parse_Params (Result : out Plugins.Parameter_Maps.Map;\n Input : Unbounded_String)\n is\n use Tokenize.Token_Vectors;\n\n Pairs : constant Token_Vectors.Vector :=\n To_Vector (Split (To_Be_Splitted => To_String (Input),\n Separator => Pair_Separator,\n Collate_Separator => True));\n begin\n for P of Pairs loop\n declare\n -- Name_And_Value : constant Token_Array :=\n -- Split (To_Be_Splitted => P,\n -- Separator => Value_Separator,\n -- Max_Token_Count => 2);\n --\n -- Name : constant String := To_String (Name_And_Value (Name_And_Value'First));\n -- Value : constant String :=\n -- (if Name_And_Value'Length = 1\n -- then \"\"\n -- else To_String (Name_And_Value (Name_And_Value'First + 1)));\n Name : Unbounded_String;\n Value : Unbounded_String;\n begin\n Head_And_Tail (To_Be_Splitted => P,\n Separator => Value_Separator,\n Head => Name,\n Tail => Value,\n Trimming => Both);\n\n Result.Include (Key => To_String (Name),\n New_Item => To_String (Value));" + }, + { + "function_def": "procedure Init_Scanner is", + "function_body": "begin\n Cursor := Buffer'First;\n\n while Cursor <= Buffer'Last and then Buffer (Cursor) = ' ' loop\n Cursor := Cursor + 1;\n end loop;\n\n if Cursor <= Buffer'Last then\n Current_Char := Buffer (Cursor);\n else\n Current_Char := EOS;\n end if;\n end Init_Scanner;\n\n procedure Next_Char (Skip_Spaces : Boolean := True) is\n begin\n loop\n if Cursor >= Buffer'Last then\n Current_Char := EOS;\n else\n Cursor := Cursor + 1;\n Current_Char := Buffer (Cursor);\n end if;\n\n exit when (not Skip_Spaces) or Current_Char /= ' ';\n end loop;\n end Next_Char;\n\n procedure Expect (What : Character) is\n begin\n if Current_Char /= What then\n raise Parsing_Error\n with \"Expecting '\" & What & \"' got '\" & Current_Char & \"'\";\n else\n Next_Char;\n end if;\n end Expect;\n\n function Remaining return String is\n begin\n return Buffer (Cursor .. Buffer'Last);\n end Remaining;\n\n Level : Natural := 0;\n\n function Indent return String is\n use Ada.Strings.Fixed;\n begin\n return (Level * 3) * \" \";\n end Indent;\n\n procedure Down_Level is\n begin\n Level := Level + 1;\n end Down_Level;\n\n procedure Up_Level is\n begin\n Level := Level - 1;\n end Up_Level;\n\n procedure Ecco (X : String) is\n begin\n if Verbose then\n Ada.Text_Io.Put_Line (Indent\n & \"Calling \"\n & X & \"[\" & Remaining & \"]\"\n & \"'\" & Current_Char & \"'\");\n Down_Level;\n end if;\n end Ecco;\n\n procedure Fine is\n begin\n if Verbose then\n Up_Level;\n Ada.Text_Io.Put_Line (Indent & \"done \" & \"[\" & Remaining & \"]\"\n & \"'\" & Current_Char & \"'\");\n end if;\n end Fine;\n\n procedure Advance (N : Positive) is\n begin\n Cursor := Cursor + N - 1;\n Next_Char;\n end Advance;\n\n function Parse_Expr return Node_Access;\n\n -- function Parse_Identifier return Bounded_ID is\n -- use Ada.Strings.Maps;\n -- use Bounded_IDs;\n --\n -- Result : Bounded_ID;\n -- ID_Chars : constant Character_Set :=\n -- To_Set (Character_Range'('a', 'z')) or\n -- To_Set (Character_Range'('A', 'Z')) or\n -- To_Set (Character_Range'('0', '9')) or\n -- To_Set ('.') or\n -- To_Set ('_');\n -- begin\n -- Ecco (\"ID\");\n --\n -- while Is_In (Current_Char, ID_Chars) loop\n -- Result := Result & Current_Char;\n -- Next_Char (Skip_Spaces => False);\n -- end loop;\n --\n -- if Current_Char = ' ' then\n -- Next_Char;\n -- end if;\n --\n -- Fine;\n -- return Result;\n -- end Parse_Identifier;\n\n procedure Parse_Parameter_List (Parameters : out Parameter_Array;\n N_Params : out Natural)\n is\n begin\n Ecco (\"par-list\");\n\n if Current_Char = ')' then\n N_Params := 0;\n\n else\n N_Params := 1;\n Parameters (1) := Parse_Expr;\n\n while Current_Char = ',' loop\n Next_Char;\n N_Params := N_Params + 1;\n Parameters (N_Params) := Parse_Expr;\n end loop;\n end if;\n\n Expect (')');\n Fine;\n exception\n when others =>\n for I in Parameters'First .. N_Params - 1 loop\n Free (Parameters (I));\n end loop;\n\n raise;\n end Parse_Parameter_List;\n\n procedure Resolve_Identifier (Raw_ID : in Identifier;\n Pos : out ID_Tables.Cursor;\n N_Matches : out Natural;\n Resolved : out Identifier;\n No_Prefix_Needed : out Boolean)\n with Post =>\n (\n (ID_Tables.\"=\" (Pos, ID_Tables.No_Element) = (N_Matches = 0))\n );\n\n\n procedure Resolve_Identifier (Raw_ID : in Identifier;\n Pos : out ID_Tables.Cursor;\n N_Matches : out Natural;\n Resolved : out Identifier;\n No_Prefix_Needed : out Boolean)\n is\n use ID_Tables;\n begin\n No_Prefix_Needed := False;\n N_Matches := 0;\n\n Pos := ID_Table.T.Find (Raw_ID);\n\n if Pos /= No_Element then\n Resolved := Raw_ID;\n No_Prefix_Needed := True;\n N_Matches := 1;\n end if;\n\n\n declare\n Tmp : Identifier;\n begin\n for I in Prefix_List'Range loop\n Tmp := Join (Prefix_List (I), Raw_ID);\n\n Pos := ID_Table.T.Find (Tmp);\n\n if Pos /= No_Element then\n N_Matches := N_Matches + 1;\n\n if N_Matches = 1 then\n Resolved := Tmp;\n end if;\n end if;\n end loop;" + }, + { + "function_def": "procedure Do_Checks is", + "function_body": "new Do_Suite (Test_Case => Test_Case,\n Test_Case_Array => Test_Case_Array,\n Check => Check);\n\n type Syntax_ID_Case is\n record\n Expr : Unbounded_String;\n Action : Unknown_ID_Action_Type;\n Success : Boolean;\n end record;\n\n type Syntax_ID_Case_Array is\n array (Positive range <>) of Syntax_ID_Case;\n\n Syntax_Cases : constant Syntax_ID_Case_Array :=\n ((Expr => +\"4*foo\",\n Action => Die,\n Success => False),\n (Expr => +\"4*foo\",\n Action => OK,\n Success => True),\n (Expr => +\"4*foo()\",\n Action => Accept_As_Var,\n Success => False),\n (Expr => +\"4*bar(2,3) + pippo\",\n Action => Die,\n Success => True),\n (Expr => +\"4*pippo(2,3)\",\n Action => OK,\n Success => False),\n (Expr => +\"4*bar\",\n Action => OK,\n Success => False),\n (Expr => +\"4*bar(2)\",\n Action => OK,\n Success => False),\n (Expr => +\"4*bar(2,3,4)\",\n Action => OK,\n Success => False),\n (Expr => +\"4*pluto(2)\",\n Action => OK,\n Success => False),\n (Expr => +\"4*pluto(2,3)\",\n Action => OK,\n Success => True),\n (Expr => +\"4*pluto(2,3,4)\",\n Action => OK,\n Success => True),\n (Expr => +\"zorro()\",\n Action => OK,\n Success => False),\n (Expr => +\"zorro(1)\",\n Action => OK,\n Success => False),\n (Expr => +\" zorro (1, 2)\",\n Action => OK,\n Success => True),\n (Expr => +\"zorro(1, 2, 3)\",\n Action => OK,\n Success => True),\n (Expr => +\"zorro(1, 2, 3,4)\",\n Action => OK,\n Success => True),\n (Expr => +\"zorro(1, 2, 3,4,x)\",\n Action => OK,\n Success => False));\n\n\n\n\n\n ID_Table : ID_Table_Type;\n\n function Check_Syntax (This : Syntax_ID_Case) return Boolean is\n Tmp : Symbolic_Expression;\n pragma Unreferenced (Tmp);\n Raised : Boolean;\n Expected : Boolean;\n begin\n Raised := False;\n Expected := False;\n\n begin\n Tmp := Parse (Input => +This.Expr,\n ID_Table => ID_Table,\n On_Unknown_ID => This.Action);\n exception\n when Parsing_Error =>\n Raised := True;\n Expected := True;\n when others =>\n Raised := True;\n Expected := False;" + }, + { + "function_def": "procedure Do_Syntax_ID_Checks is", + "function_body": "new Do_Suite (Test_Case => Syntax_ID_Case,\n Test_Case_Array => Syntax_ID_Case_Array,\n Check => Check_Syntax);\n\n\n\n Reporter : Reporter_Type;\nbegin\n -- Be_Verbose (Reporter);\n Define_Function (ID_Table, \"bar\", Exactly (2));\n Define_Function (ID_Table, \"pluto\", At_Least (2));\n Define_Function (ID_Table, \"zorro\", Between (2, 4));\n Define_Variable (ID_Table, \"pippo\");\n\n for I in Variables'Range loop\n Var_Table.Insert (+Variables (I).Name, Variables (I).Value);\n end loop;\n\n Do_Checks (Reporter, Test_Cases, \"Basic\");\n\n Do_Syntax_ID_Checks (Reporter, Syntax_Cases, \"Syntax\");\n\n declare\n X : constant Symbolic_Expression := Variable (\"x\");\n Y : constant Symbolic_Expression := Variable (\"y\");\n T : constant Symbolic_Expression := (X + Y) * (X - Y);\n U : constant Symbolic_Expression := Function_Call (\"max\", (X, Y));\n R : constant Symbolic_Expression := Function_Call (\"min\", (X, Y));\n S : constant Symbolic_Expression := R * U;\n K : constant Symbolic_Expression := To_Expr (42);\n M : constant Symbolic_Expression := X + Y * U / (K - S);\n Q : constant Symbolic_Expression := Replace (S, \"x\", T);\n Z : constant Symbolic_Expression := T * (- Q);\n W : constant Symbolic_Expression := +T * (+T);\n A : constant Symbolic_Expression := W * 3-(2 + U) / (Q - 1);\n\n Val_X : constant Integer := 12;\n Val_Y : constant Integer := -3;\n Val_T : constant Integer := (Val_X + Val_Y) * (Val_X - Val_Y);\n Val_U : constant Integer := Integer'Max (Val_X, Val_Y);\n Val_R : constant Integer := Integer'Min (Val_X, Val_Y);\n Val_S : constant Integer := Val_R * Val_U;\n Val_K : constant Integer := 42;\n Val_M : constant Integer := Val_X + Val_Y * Val_U / (Val_K - Val_S);\n Val_Q : constant Integer :=\n Integer'Max (Val_Y, Val_T) * Integer'Min (Val_Y, Val_T);\n Val_Z : constant Integer := Val_T * (-Val_Q);\n Val_W : constant Integer := +Val_T * (+Val_T);\n Val_A : constant Integer := Val_W * 3-(2 + Val_U) / (Val_Q - 1);\n\n function Check (Item : Symbolic_Expression;\n Expected : Integer)\n return Boolean\n is\n Tmp : Symbolic_Expression;\n begin\n Tmp := Replace (Item, \"x\", Val_X);\n Tmp := Replace (Tmp, \"y\", Val_Y);\n\n return Is_Constant (Tmp) and then Eval (Tmp) = Expected;\n end Check;\n begin\n New_Suite (Reporter, \"Operators\");\n New_Result (Reporter, Check (X, Val_X));\n New_Result (Reporter, Check (Y, Val_Y));\n New_Result (Reporter, Check (T, Val_T));\n New_Result (Reporter, Check (U, Val_U));\n New_Result (Reporter, Check (R, Val_R));\n New_Result (Reporter, Check (S, Val_S));\n New_Result (Reporter, Check (K, Val_K));\n New_Result (Reporter, Check (M, Val_M));\n New_Result (Reporter, Check (Q, Val_Q));\n New_Result (Reporter, Check (Z, Val_Z));\n New_Result (Reporter, Check (W, Val_W));\n New_Result (Reporter, Check (A, Val_A));" + }, + { + "function_def": "function Deliverable_Type_Check is", + "function_body": "new Generic_Enumerative (Deliverables.Deliverable_Type);\n\n\n function Dissemination_Level_Check is\n new Generic_Enumerative (Deliverables.Dissemination_Level);\n\n Basic_Checker : constant Attribute_Checker :=\n Mandatory (\"label\") +\n Mandatory (\"name\") +\n Mandatory (\"short\");\n\n Project_Checker : constant Attribute_Checker :=\n Basic_Checker + Default (\"end\", Event_Names.Default_Time);\n\n Event_Checker : constant Attribute_Checker :=\n Basic_Checker + Default (\"when\", \"default\");\n\n Activity_Checker : constant Attribute_Checker :=\n Basic_Checker\n + Mandatory (\"begin\")\n + Alternative (\"end|duration\")\n + Default (\"objective\", \"\")\n + Default (\"dependencies\", \"\");\n\n WP_Checker : constant Attribute_Checker := Activity_Checker + Mandatory (\"leader\");\n\n Task_Checker : constant Attribute_Checker := WP_Checker\n + Mandatory (\"effort\")\n + Default (\"intensity\", \"100%\");\n\n Milestone_Checker : constant Attribute_Checker := Event_Checker\n + Default (\"verification\", \"\");\n -- + Default (\"deliverables\", \"\");\n\n Deliverable_Checker : constant Attribute_Checker := Event_Checker\n + Default (\"tasks\", \"\")\n + Default (\"milestones\", \"\")\n + Deliverable_Type_Check (\"type\")\n + Dissemination_Level_Check (\"dissemination\");\n\n Partner_Checker : constant Attribute_Checker := Basic_Checker\n + Mandatory (\"country\");\n\n Role_Checker : constant Attribute_Checker := Mandatory (\"name\")\n + Default (\"monthly-cost\", \"0\")\n + Default (\"description\", \"\");\n\n function Get_Times (Node : Node_Type) return Nodes.Action_Nodes.Action_Time\n is\n use Nodes.Action_Nodes;\n\n End_Given : constant Boolean := Node.Contains (+\"end\");\n Duration_Given : constant Boolean := Node.Contains (+\"duration\");\n begin\n\n if End_Given and Duration_Given then\n -- This should never happen\n raise Program_Error with \"end and duration together\";\n\n elsif (not End_Given) and (not Duration_Given) then\n -- This neither\n raise Program_Error with \"neither end nor duration\";\n\n elsif End_Given and (not Duration_Given) then\n -- Put_Line (Node (\"begin\") & \"|\" & Node (\"end\"));\n\n return Create (Start_On => Instant_Raw (Node (\"begin\")),\n End_On => Instant_Raw (Node (\"end\")));\n\n else\n return Create (Start_On => Instant_Raw (Node.Value (\"begin\")),\n Duration => Duration_Raw (Node.Value (\"duration\")));\n end if;\n end Get_Times;\n\n ------------\n -- Create --\n ------------\n\n\n function Create\n (Params : not null access Plugins.Parameter_Maps.Map)\n return Parser_Type\n is\n pragma Unreferenced (Params);\n Result : Parser_Type;\n begin\n return Result;\n end Create;\n\n procedure Parse_Deliverable (WP : EU_Projects.Nodes.Action_Nodes.WPs.Project_WP_Access;\n Node_Seq : in out Node_Parser.Node_Scanner;\n Node_Dir : in out Node_Tables.Node_Table)\n with Pre => Class_Is (Node_Seq, Deliverable);\n\n -----------------------\n -- Parse_Deliverable --\n -----------------------\n\n -----------------------\n -- Parse_Deliverable --\n -----------------------\n\n procedure Parse_Deliverable (WP : EU_Projects.Nodes.Action_Nodes.WPs.Project_WP_Access;\n Node_Seq : in out Node_Parser.Node_Scanner;\n Node_Dir : in out Node_Tables.Node_Table)\n is\n use EU_Projects.Nodes.Timed_Nodes.Deliverables;\n\n Deliv_Node : Node_Type := Peek (Node_Seq);\n This_Deliv : Deliverable_Access;\n begin\n Node_Images.Set_Current_Node (Deliv_Node);\n\n Next (Node_Seq);\n Check (Deliverable_Checker, Deliv_Node);\n\n declare\n use Tokenize;\n Label : constant Deliverable_Label :=\n Deliverable_Label'(To_ID (Deliv_Node (\"label\")));\n\n Delivered_By : constant EU_Projects.Nodes.Node_Label_Lists.Vector :=\n Nodes.Parse_Label_List (Deliv_Node (\"tasks\"));\n\n Due_Times : Token_Vectors.Vector :=\n Token_Vectors.To_Vector (Split (Deliv_Node (\"when\"), ';'));\n\n begin\n if Node_Dir.Contains (EU_Projects.Nodes.Node_Label (Label)) then\n raise Parsing_Error\n with \"Duplicated label '\" & Image (Label) & \"' in deliverable\";\n end if;\n\n\n This_Deliv :=\n Create (Label => Label,\n Name => Deliv_Node (\"name\"),\n Short_Name => Deliv_Node (\"short\"),\n Description => Deliv_Node.Description,\n Delivered_By => Delivered_By,\n Linked_Milestones => Nodes.Parse_Label_List (Deliv_Node (\"milestones\")),\n Due_On => Due_Times.First_Element,\n Node_Dir => Node_Dir,\n Parent_WP => EU_Projects.Nodes.Node_Access (WP),\n Deliv_Type => Deliverable_Type'Value (Deliv_Node (\"type\")),\n Dissemination => Dissemination_Level'Value (Deliv_Node (\"dissemination\")));\n\n for Idx in Due_Times.First_Index + 1 .. Due_Times.Last_Index loop\n Clone (Item => This_Deliv.all,\n Due_On => Due_Times (Idx),\n Node_Dir => Node_Dir);\n\n end loop;\n\n WP.Add_Deliverable (This_Deliv);" + }, + { + "function_def": "procedure Test_Config_String_Parsers is", + "function_body": "function Identity (X : String) return String\n is (X);\n\n package Test_Parsers is\n new Config_String_Parsers (Name_Type => string,\n Value_Type => String,\n No_Value => \"(null)\",\n To_Name => Identity,\n To_Value => Identity);\n\n procedure Dump (Y : Test_Parsers.Parsing_Result) is\n use Test_Parsers.Parameter_Maps, Test_Parsers;\n\n X : constant Test_Parsers.Parameter_Maps.Map := Parameters (Y);\n begin\n Put_Line (\"##################\");\n Put_line (\"header: '\"\n & (if Has_Header (Y) then Header (Y) else \"\")\n & \"'\");\n\n for Pos in X.Iterate loop\n Put_Line (\"'\" & Key (Pos) & \"' -> '\" & Element (Pos) & \"'\");\n end loop;\n end Dump;\n\n Params : Test_Parsers.Parsing_Result;\n\nbegin\n Params := Test_Parsers.Parse (\" ciao , pluto= 33 ,zimo-xamo={ 42,33 }\");\n Dump (Params);\n\n Params := Test_Parsers.Parse\n (Input => \"zorro : ciao , pluto= 33 ,zimo-xamo={}\",\n Options => Test_Parsers.Config (Expect_Header => Test_Parsers.Maybe));\n Dump (Params);\n\n declare\n use Test_Parsers;\n Syntax : Syntax_Descriptor;\n begin\n Add_Parameter_Syntax (Syntax => Syntax,\n Parameter_Name => \"ciao\",\n If_Missing => die);\n\n Add_Parameter_Syntax(Syntax => Syntax,\n Parameter_Name => \"pippo\",\n If_Missing => Use_Default,\n Default => \"minima veniali\");\n\n Params := Test_Parsers.Parse\n (Input => \"zorro : ciao , pluto=,zimo-xamo={ 42,33 }\",\n Syntax => Syntax,\n Options => Test_Parsers.Config (Expect_Header => Test_Parsers.Maybe),\n On_Unknown_Name => OK);\n Dump (Params);\n\n Params := Test_Parsers.Parse\n (Input => \"zorro : ciao , pippo= 37 ,zimo-xamo={ 42,33 }\",\n Syntax => Syntax,\n Options => Test_Parsers.Config (Expect_Header => Test_Parsers.Maybe),\n On_Unknown_Name => OK);\n Dump (Params);\n\n Params := Test_Parsers.Parse\n (Input => \"zorro : ciao=112, pippo={33,11},zimo--xamo={ 42,33 }\",\n Syntax => Syntax,\n Options => Test_Parsers.Config (Expect_Header => Test_Parsers.Maybe),\n On_Unknown_Name => OK);\n Dump (Params);" + }, + { + "function_def": "procedure Check_Missing is", + "function_body": "begin\n\n for C in Syntax.S.Iterate loop\n declare\n Name : constant Name_Type := Key (C);\n Descr : constant Syntax_Entry := Element (C);\n begin\n if not Item.Contains (Name) then\n case Descr.If_Missing is\n when Die =>\n raise Parsing_Error with \"Missing parameter\";\n\n when Ignore =>\n null;\n\n when Use_Default =>\n Item.Insert (Key => Name,\n New_Item => Descr.Default.Element);\n end case;\n end if;" + }, + { + "function_def": "procedure Register", + "function_body": "(ID : Plugin_ID;\n Tag : Ada.Tags.Tag)\n is\n OK : Boolean;\n Pos : Plugin_Maps.Cursor;\n begin\n Plugin_Map.Insert (Key => ID,\n New_Item => Tag,\n Position => Pos,\n Inserted => OK);\n end Register;\n\n ---------\n -- Get --\n ---------\n\n function Get (ID : Plugin_ID;\n Params : not null access Plugin_Parameters;\n Search_If_Missing : Boolean := False)\n return Root_Plugin_Type'Class is\n OK : Boolean;\n Tag : Ada.Tags.Tag;\n\n function New_Plugin is\n new Ada.Tags.Generic_Dispatching_Constructor\n (T => Root_Plugin_Type,\n Parameters => Plugin_Parameters,\n Constructor => Constructor);\n begin\n if not Plugin_Map.Contains (ID) then\n if Search_If_Missing then\n Find_Plugin (ID => ID,\n Success => OK);\n else\n OK := False;\n end if;\n\n if not OK then\n raise Unknown_Plugin_ID;\n end if;\n\n if not Plugin_Map.Contains (ID) then\n raise Program_Error;\n end if;\n end if;\n\n Tag := Plugin_Map.Element (ID);\n\n return New_Plugin (Tag, Params);\n end Get;\n\n function Exists (ID : Plugin_ID;\n Search_If_Missing : Boolean := False)\n return Boolean\n is\n OK : Boolean;\n begin\n if Plugin_Map.Contains (ID) then\n return True;\n elsif Search_If_Missing then\n Find_Plugin (ID => ID,\n Success => OK);\n\n return OK;\n else\n return False;\n end if;\n end Exists;\n\n procedure For_All_Plugins\n (Callback : not null access procedure (ID : Plugin_ID))\n is\n begin\n for I in Plugin_Map.Iterate loop\n Callback (Plugin_Maps.Key (I));\n end loop;\n end For_All_Plugins;\n\n subtype Valid_Finder_ID is Finder_ID range 1 .. Finder_ID'Last;\n\n package Finder_Vectors is\n new Ada.Containers.Vectors (Index_Type => Valid_Finder_ID,\n Element_Type => Finder_Access);\n\n protected Finder_Table is\n procedure Add (Finder : in Finder_Access;\n ID : out Finder_ID);\n\n procedure Remove (ID : Finder_ID);\n\n procedure Find (ID : in Plugin_ID;\n Success : out Boolean);\n private\n Finder_Array : Finder_Vectors.Vector;\n end Finder_Table;\n\n protected body Finder_Table is\n procedure Add (Finder : in Finder_Access;\n ID : out Finder_ID)\n is\n begin\n Finder_Array.Append (Finder);\n ID := Finder_Array.Last_Index;\n end Add;\n\n procedure Remove (ID : Finder_ID) is\n begin\n if ID > Finder_Array.Last_Index then\n raise Constraint_Error;\n else\n declare\n procedure Delete (Item : in out Finder_Access) is\n begin\n Item := null;\n end Delete;\n begin\n Finder_Array.Update_Element (ID, Delete'Access);" + }, + { + "function_def": "procedure Main is", + "function_body": "package SU renames Ada.Strings.Unbounded;\n package Calendar renames Ada.Calendar;\n\n type Argument_Option is (verbose, input, output);\n type Boolean_Flag is (True, False);\n\n File : File_Type;\n Fields : Slice_Set;\n Seconds_Per_Hour : Integer;\n Start : Calendar.Time;\n Clock : array(1..2) of Integer;\n Verbose_Flag : Boolean := FALSE;\n In_Filename : SU.Unbounded_String := SU.To_Unbounded_String (\"input\");\n Out_Filename : SU.Unbounded_String := SU.To_Unbounded_String (\"output\");\n T : Integer; -- number of trains\n TT : Integer; -- number of Turntables\n NT : Integer; -- number of NormalTracks\n ST : Integer; -- number of StationTracks\n Turntables : Turntables_Ptr;\n Normal_Tracks : Normal_Tracks_Ptr;\n Station_Tracks : Station_Tracks_Ptr;\n Trains : Trains_Ptr;\n Connections : Connections_Ptr;\n\n type Command is ('c', 'p', 't', 'u', 'n', 's', 'h', 'q');\n\n task Talk is\n entry Start;\n end Talk;\n\n task body Talk is\n C : String (1..1);\n Last : Natural;\n begin\n accept Start;\n\n Put_Line(\"Input char for action, availble commands:\");\n\t\tPut_Line(\" 'p' - current trains positions,\");\n\t\tPut_Line(\" 't' - list trains,\");\n Put_Line(\" 'u' - list turntables,\");\n Put_Line(\" 'n' - list normal tracks,\");\n\t\tPut_Line(\" 's' - list station tracks,\");\n\t\tPut_Line(\" 'h' - print this menu again,\");\n\t\tPut_Line(\" 'q' - to quit simulation.\");\n\n while TRUE loop\n\n Get_Line(C, Last);\n\n case C(1) is\n when 'p' =>\n null;\n for I in 0 .. T-1 loop\n Put_Line(As_String(Trains (I)) & \": \" & Trains (I).Att.As_String);\n end loop;\n when 't' =>\n for I in 0 .. T-1 loop\n Put_Line(As_Verbose_String(Trains (I)));\n end loop;\n when 'u' =>\n for I in 0 .. TT-1 loop\n Put_Line(Turntables (I).As_Verbose_String);\n end loop;\n when 'n' =>\n for I in 0 .. NT-1 loop\n Put_Line(Normal_Tracks (I).As_Verbose_String);\n end loop;\n when 's' =>\n for I in 0 .. ST-1 loop\n Put_Line(Station_Tracks (I).As_Verbose_String);\n end loop;\n when 'h' =>\n Put_Line(\"Input char for action, availble commands:\");\n Put_Line(\" 'p' - current trains positions,\");\n Put_Line(\" 't' - list trains,\");\n Put_Line(\" 'u' - list turntables,\");\n Put_Line(\" 'n' - list normal tracks,\");\n Put_Line(\" 's' - list station tracks,\");\n Put_Line(\" 'h' - print this menu again,\");\n Put_Line(\" 'q' - to quit simulation.\");\n when 'q' => OS_Exit(0);\n when others => null;\n end case;\n\n C := \"#\";\n\n end loop;\n end Talk;\n\n function Read_Fields(F: File_Type; Expected: Positive) return Slice_Set is\n File_Line : SU.Unbounded_String;\n Fields : Slice_Set;\n Seps : constant String := \" \";\n Fields_Exception : exception;\n begin\n File_Line := SU.To_Unbounded_String (Get_Line (F));\n\n loop\n exit when SU.To_String (File_Line)'Length > 0 and then SU.To_String (File_Line) (1) /= '#';\n\n File_Line := SU.To_Unbounded_String (Get_Line (F));\n end loop;\n\n Create (S => Fields,\n From => SU.To_String (File_Line),\n Separators => Seps,\n Mode => Multiple);\n\n if Positive (Slice_Count (Fields)) /= Expected then\n Raise_Exception (Fields_Exception'Identity, \"Expected to read\" & Positive'Image (Expected) & \" fields\");\n end if;\n\n return Fields;\n exception\n when Fail: Fields_Exception =>\n Put_Line (Exception_Message (Fail));\n return Fields;\n end Read_Fields;\n\nbegin\n\n for Arg in 1 .. Argument_Count/2 loop\n declare\n A : Argument_Option;\n begin\n A := Argument_Option'Value (Argument(Arg*2-1));\n case A is\n when Argument_Option'(Verbose) =>\n case Boolean_Flag'Value (Argument(Arg*2)) is\n when Boolean_Flag'(true) =>\n Verbose_Flag := TRUE;\n Put_Line (\"Verbose mode\");\n when others =>\n Verbose_Flag := FALSE;\n Put_Line (\"Silent mode\");\n end case;\n when Input =>\n In_Filename := SU.To_Unbounded_String (Argument(Arg*2));\n when Output =>\n Out_Filename := SU.To_Unbounded_String (Argument(Arg*2));\n when others =>\n null;\n end case;\n exception\n when Constraint_Error =>\n Put_Line (\"Wrong arguments\");\n OS_Exit(1);" + }, + { + "function_def": "procedure Free_Logger_Msg_Ptr is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Logger_Message_Packet, Name => Logger_Message_Packet_Ptr);\n\n function Format_Log_Level\n (Use_Color : Boolean;\n Log_Level : Log_Levels)\n return Unbounded_String\n is\n Color_Prefix : Unbounded_String;\n Log_Level_Str : Unbounded_String;\n Now : constant Time := Clock;\n begin\n\n -- Add ANSI color codes if we're using color on Linux\n if Use_Color\n then\n case Log_Level is\n when EMERGERENCY =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when ALERT =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when CRITICAL =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when ERROR =>\n Color_Prefix := To_Unbounded_String (ANSI_Red);\n when WARNING =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Yellow);\n when NOTICE =>\n Color_Prefix := To_Unbounded_String (ANSI_Yellow);\n when INFO =>\n Color_Prefix := To_Unbounded_String (ANSI_Green);\n when DEBUG =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Blue);\n end case;\n\n Log_Level_Str :=\n Color_Prefix & To_Unbounded_String (Log_Level'Image) & ANSI_Reset;\n else\n Log_Level_Str := To_Unbounded_String (Log_Level'Image);\n end if;\n\n return To_Unbounded_String\n (Image (Date => Now) & \" [\" & To_String (Log_Level_Str) & \"]\");\n end Format_Log_Level;\n\n function Create_String_From_Components\n (Components : Component_Vector.Vector)\n return Unbounded_String\n is\n Components_String : Unbounded_String;\n procedure Component_To_String (c : Component_Vector.Cursor) is\n Scratch_String : Unbounded_String;\n begin\n Scratch_String := Components (c);\n Components_String := Components_String & \"[\" & Scratch_String & \"]\";\n end Component_To_String;\n begin\n -- If there's no component, just leave it blank\n if Components.Length = 0\n then\n return To_Unbounded_String (\"\");\n end if;\n\n Components.Iterate (Component_To_String'Access);\n return Components_String;\n end Create_String_From_Components;\n\n protected body Logger_Queue_Type is\n -- Handles queue of packets for the logger thread\n entry Add_Packet (Queue : Logger_Message_Packet_Ptr) when True is\n begin\n Queued_Packets.Append (Queue);\n end Add_Packet;\n\n entry Get (Queue : out Logger_Message_Packet_Ptr)\n when Queued_Packets.Length > 0 is\n begin\n Queue := Queued_Packets.First_Element;\n Queued_Packets.Delete_First;\n end Get;\n\n entry Count (Count : out Integer) when True is\n begin\n Count := Integer (Queued_Packets.Length);\n end Count;\n\n entry Empty when True is\n begin\n declare\n procedure Dump_Vector_Data\n (c : Logger_Message_Packet_Vector.Cursor)\n is\n begin\n Free_Logger_Msg_Ptr (Queued_Packets (c));\n end Dump_Vector_Data;\n begin\n Queued_Packets.Iterate (Dump_Vector_Data'access);" + }, + { + "function_def": "procedure Process_Queue is", + "function_body": "procedure Print_Messages (c : Log_Message_Vector.Cursor) is\n Current_Msg : constant Log_Message_Record :=\n Log_Message_Vector.Element (c);\n begin\n -- This is so ugly :(\n if Log_Levels'Enum_Rep (Logger_Cfg.Log_Level) >=\n Log_Levels'Enum_Rep (Current_Msg.Log_Level)\n then\n Msg_String :=\n Format_Log_Level\n (Logger_Cfg.Use_Color, Current_Msg.Log_Level);\n Msg_String :=\n Msg_String &\n Create_String_From_Components (Current_Msg.Component);\n Msg_String := Msg_String & \" \" & Current_Msg.Message;\n Put_Line (To_String (Msg_String));\n end if;\n end Print_Messages;\n\n begin\n Logger_Queue.Count (Queues_To_Process);\n while Queues_To_Process > 0\n loop\n Logger_Queue.Get (Current_Queue);\n\n -- Get a local copy and then empty it; we don't care past that\n -- point\n if Current_Queue /= null\n then\n Current_Queue.Get_All_And_Empty (Msg_Packets);\n Msg_Packets.Iterate (Print_Messages'Access);\n Free_Logger_Msg_Ptr (Current_Queue);\n end if;\n\n Logger_Queue.Count (Queues_To_Process);\n end loop;\n\n exception\n -- Not sure if there's a better way to do this, but avoids a race\n -- condition\n when Constraint_Error =>\n begin\n null;" + }, + { + "function_def": "function To_Domain_Section is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => Domain_Section);\n begin\n Domain_Name := Domain_Name & To_Domain_Section (Raw_Data.all\n (Offset .. Stream_Element_Offset (Section_Length)));\n\n Offset := Offset + Stream_Element_Offset (Section_Length);" + }, + { + "function_def": "function Get_Byte_Fixed_Header is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => Packer_Pointer);\n begin\n -- Oh, and for more fuckery, the pointer is 16-bit ...\n Packet_Ptr := Get_Byte_Fixed_Header (Raw_Data.all\n (Offset .. Offset + 1)); -- Make the top bytes vanish\n\n -- We subtract 12-1 for the packet header\n Packet_Ptr.Packet_Offset :=\n (Packet_Ptr.Packet_Offset and 16#3fff#) - 11;\n\n -- Sanity check ourselves\n if (Section_Length and 2#11#) /= 0\n then\n -- Should never happen but you never know ...\n raise Unknown_Compression_Method;\n end if;\n\n -- Now we need to decode the whole old string ... ugh\n Decompressed_Domain_String :=\n Parse_DNS_Packet_Name_Records\n (Raw_Data,\n Stream_Element_Offset (Packet_Ptr.Packet_Offset));\n Offset := Offset + 2;\n return Domain_Name & Decompressed_Domain_String;" + }, + { + "function_def": "function To_RData is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => RData);\n begin\n Parsed_Response.RData := To_Unbounded_String (To_RData (Raw_Data\n (Offset .. Stream_Element_Offset (RData_Length))));\n Offset := Offset + Stream_Element_Offset (RData_Length);" + }, + { + "function_def": "procedure Start_Server is", + "function_body": "-- Input and Output Sockets\n Capture_Config : DNSCatcher.Config.Configuration;\n\n DNS_Transactions : DNSCatcher.DNS.Transaction_Manager\n .DNS_Transaction_Manager_Task;\n Receiver_Interface : DNSCatcher.Network.UDP.Receiver\n .UDP_Receiver_Interface;\n Sender_Interface : DNSCatcher.Network.UDP.Sender.UDP_Sender_Interface;\n Logger_Task : DNSCatcher.Utils.Logger.Logger;\n Transaction_Manager_Ptr : DNS_Transaction_Manager_Task_Ptr;\n Socket : Socket_Type;\n Logger_Packet : DNSCatcher.Utils.Logger.Logger_Message_Packet_Ptr;\n\n procedure Free_Transaction_Manager is new Ada.Unchecked_Deallocation\n (Object => DNS_Transaction_Manager_Task,\n Name => DNS_Transaction_Manager_Task_Ptr);\n begin\n -- Load the config file from disk\n DNSCatcher.Config.Initialize (Capture_Config);\n DNSCatcher.Config.Read_Cfg_File\n (Capture_Config, \"conf/dnscatcherd.conf\");\n\n -- Configure the logger\n Capture_Config.Logger_Config.Log_Level := DEBUG;\n Capture_Config.Logger_Config.Use_Color := True;\n\n Logger_Task.Initialize (Capture_Config.Logger_Config);\n Transaction_Manager_Ptr := new DNS_Transaction_Manager_Task;\n\n -- Connect the packet queue and start it all up\n Logger_Task.Start;\n Logger_Packet := new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message (NOTICE, \"DNSCatcher starting up ...\");\n DNSCatcher.Utils.Logger.Logger_Queue.Add_Packet (Logger_Packet);\n\n -- Socket has to be shared between receiver and sender. This likely needs\n -- to move to to a higher level class\n begin\n Create_Socket\n (Socket => Socket,\n Mode => Socket_Datagram);\n Set_Socket_Option\n (Socket => Socket,\n Level => IP_Protocol_For_IP_Level,\n Option => (GNAT.Sockets.Receive_Timeout, Timeout => 1.0));\n Bind_Socket\n (Socket => Socket,\n Address =>\n (Family => Family_Inet, Addr => Any_Inet_Addr,\n Port => Capture_Config.Local_Listen_Port));\n exception\n when Exp_Error : GNAT.Sockets.Socket_Error =>\n begin\n Logger_Packet :=\n new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message\n (ERROR, \"Socket error: \" & Exception_Information (Exp_Error));\n Logger_Packet.Log_Message (ERROR, \"Refusing to start!\");\n Logger_Queue.Add_Packet (Logger_Packet);\n goto Shutdown_Procedure;" + }, + { + "function_def": "function Uint8_To_Character is new Ada.Unchecked_Conversion", + "function_body": "(Source => Unsigned_8, Target => Character);\n function Uint16_To_String is new Ada.Unchecked_Conversion\n (Source => Unsigned_16, Target => QAttributes);\n -- Actually does the dirty work of creating a question\n function Create_QName_Record\n (Domain_Section : String)\n return String\n is\n Label : String (1 .. Domain_Section'Length + 1);\n begin\n if Domain_Section /= \".\"\n then\n Label (1) :=\n Uint8_To_Character (Unsigned_8 (Domain_Section'Length));\n Label\n (2 .. Domain_Section'Length + 1) := Domain_Section;\n else\n -- If this is a \".\" by itself, it's the terminator, and we need to\n -- do special handling\n declare\n Empty_Label : String (1 .. 1);\n begin\n Empty_Label (1) := Uint8_To_Character (Unsigned_8 (0));\n return Empty_Label;" + }, + { + "function_def": "function String_To_Packet is new Ada.Unchecked_Conversion", + "function_body": "(Source => String, Target => QData_SEA);\n\n begin\n Outbound_Packet.Raw_Data.Data :=\n new Stream_Element_Array (1 .. QData'Length);\n Outbound_Packet.Raw_Data.Data.all := String_To_Packet (QData);\n Outbound_Packet.Raw_Data_Length :=\n DNS_PACKET_HEADER_SIZE + QData'Length;" + }, + { + "function_def": "-- Parse_Procedure is an access procedure that is used as a common prototype", + "function_body": "-- for all parsing functionality dispatched from GCP_Management and other\n -- vectors.\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n type Parse_Procedure is access procedure\n (Config : in out Configuration;\n Value_Str : String);\n\n -- GCP_Management is a vector that handles dynamic dispatch to the\n -- parsing parameters above; it is used to match key/values from the\n -- config file to\n package GCP_Management is new Ada.Containers.Indefinite_Ordered_Maps\n (String, Parse_Procedure);\n\n GCP_Map : GCP_Management.Map;\n\n -- Configuration constructor\n procedure Initialize (Config : in out Configuration) is\n begin\n -- We initialize the ports to 53 by default\n Config.Local_Listen_Port := 53;\n Config.Upstream_DNS_Server_Port := 53;\n\n -- No upstream server is set\n Config.Upstream_DNS_Server := To_Unbounded_String (\"\");\n end Initialize;\n\n -- Loads the load listen value and sets it in the config record\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Local_Listen_Port\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Local_Listen_Port := Port_Type'Value (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line with \"Local_Listen_Port not a valid port number\";\n end Parse_Local_Listen_Port;\n\n -- Loads the upstream DNS Server from the config file\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Upstream_DNS_Server\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Upstream_DNS_Server := To_Unbounded_String (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line with \"Invalid upstrema DNS Server\";\n end Parse_Upstream_DNS_Server;\n\n -- Loads the upstream DNS Server port from the config file\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Upstream_DNS_Server_Port\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Upstream_DNS_Server_Port := Port_Type'Value (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line\n with \"Upstream_DNS_Server_Port not a valid port number\";\n end Parse_Upstream_DNS_Server_Port;\n\n procedure Initialize_Config_Parse is\n begin\n -- Load String to Type Mapping\n GCP_Map.Insert (\"LOCAL_LISTEN_PORT\", Parse_Local_Listen_Port'Access);\n GCP_Map.Insert (\"UPSTREAM_DNS_SERVER\", Parse_Upstream_DNS_Server'Access);\n GCP_Map.Insert\n (\"UPSTREAM_DNS_SERVER_PORT\", Parse_Upstream_DNS_Server_Port'Access);\n end Initialize_Config_Parse;\n\n procedure Read_Cfg_File\n (Config : in out Configuration;\n Config_File_Path : String)\n is\n Config_File : Ada.Text_IO.File_Type;\n Line_Count : Integer := 1;\n Exception_Message : Unbounded_String;\n use GCP_Management;\n begin\n Initialize_Config_Parse;\n\n -- Try to open the configuration file\n Open\n (File => Config_File,\n Mode => Ada.Text_IO.In_File,\n Name => Config_File_Path);\n\n while not End_Of_File (Config_File)\n loop\n declare\n Current_Line : constant String := Get_Line (Config_File);\n Key_End_Loc : Integer := 0;\n Equals_Loc : Integer := 0;\n Value_Loc : Integer := 0;\n Is_Whitespace : Boolean := True;\n begin\n -- Skip lines starting with a comment or blank\n if Current_Line = \"\"\n then\n goto Config_Parse_Continue;\n end if;\n\n -- Has to be done seperately or it blows an index check\n if Current_Line (1) = '#'\n then\n goto Config_Parse_Continue;\n end if;\n\n -- Skip line if its all whitespace\n for I in Current_Line'range\n loop\n if Current_Line (I) /= ' ' and\n Current_Line (I) /= Ada.Characters.Latin_1.HT\n then\n Is_Whitespace := False;\n end if;\n\n if Current_Line (I) = '='\n then\n Equals_Loc := I;\n end if;\n\n -- Determine length of the key\n --\n -- This is a little non-obvious at first glance. We subtract 2\n -- here to remove the character we want, and the previous char\n -- because a 17 char string will be 1..18 in the array.\n\n if (Is_Whitespace or Current_Line (I) = '=') and Key_End_Loc = 0\n then\n Key_End_Loc := I - 2;\n end if;\n\n exit when Is_Whitespace and Equals_Loc /= 0;\n -- We also want to confirm there's a = in there somewhere\n end loop;\n\n -- It's all whitespace, skip it\n if Is_Whitespace\n then\n goto Config_Parse_Continue;\n end if;\n\n if Equals_Loc = 0\n then\n Exception_Message :=\n To_Unbounded_String (\"Malformed line (no = found) at\");\n Append (Exception_Message, Line_Count'Image);\n Append (Exception_Message, \": \");\n Append (Exception_Message, Current_Line);\n\n raise Malformed_Line with To_String (Exception_Message);\n end if;\n\n -- Read in the essential values\n for C in GCP_Map.Iterate\n loop\n -- Slightly annoying, but need to handle not reading past the\n -- end of Current_Line. We also need to check that the next char\n -- is a space or = so we don't match substrings by accident.\n if Key_End_Loc = Key (C)'Length\n then\n if Key (C) = To_Upper (Current_Line\n (1 .. Key (C)'Length))\n then\n -- Determine the starting character of the value\n for I in Current_Line\n (Equals_Loc + 1 .. Current_Line'Length)'range\n loop\n if Current_Line (I) /= ' ' and\n Current_Line (I) /= Ada.Characters.Latin_1.HT\n then\n Value_Loc := I;\n exit;\n end if;\n end loop;\n\n -- If Value_Loc is zero, pass an empty string in\n if Value_Loc = 0\n then\n Element (C).all (Config, \"\");\n else\n Element (C).all (Config, Current_Line\n (Value_Loc .. Current_Line'Length));\n end if;\n end if;\n end if;\n end loop;\n\n <>\n Line_Count := Line_Count + 1;" + }, + { + "function_def": "procedure DNSC is", + "function_body": "DClient : DNSCatcher.DNS.Client.Client;\n Capture_Config : DNSCatcher.Config.Configuration;\n Logger_Task : DNSCatcher.Utils.Logger.Logger;\n Transaction_Manager_Ptr : DNS_Transaction_Manager_Task_Ptr;\n Sender_Interface : DNSCatcher.Network.UDP.Sender.UDP_Sender_Interface;\n Receiver_Interface : DNSCatcher.Network.UDP.Receiver.UDP_Receiver_Interface;\n Outbound_Packet : Raw_Packet_Record_Ptr;\n Logger_Packet : DNSCatcher.Utils.Logger.Logger_Message_Packet_Ptr;\n Socket : Socket_Type;\n\nbegin\n Capture_Config.Local_Listen_Port := 41231;\n Capture_Config.Upstream_DNS_Server := To_Unbounded_String (\"4.2.2.2\");\n Capture_Config.Upstream_DNS_Server_Port := 53;\n\n -- Configure the logger\n Capture_Config.Logger_Config.Log_Level := DEBUG;\n Capture_Config.Logger_Config.Use_Color := True;\n\n Logger_Task.Initialize (Capture_Config.Logger_Config);\n Logger_Task.Start;\n Logger_Packet := new Logger_Message_Packet;\n\n Transaction_Manager_Ptr := new DNS_Transaction_Manager_Task;\n\n -- Socket has to be shared between receiver and sender. This likely needs to\n -- move to to a higher level class\n begin\n Create_Socket\n (Socket => Socket,\n Mode => Socket_Datagram);\n Set_Socket_Option\n (Socket => Socket,\n Level => IP_Protocol_For_IP_Level,\n Option => (GNAT.Sockets.Receive_Timeout, Timeout => 1.0));\n Bind_Socket\n (Socket => Socket,\n Address =>\n (Family => Family_Inet, Addr => Any_Inet_Addr,\n Port => Capture_Config.Local_Listen_Port));\n exception\n when Exp_Error : GNAT.Sockets.Socket_Error =>\n begin\n Logger_Packet := new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message\n (ERROR, \"Socket error: \" & Exception_Information (Exp_Error));\n Logger_Packet.Log_Message (ERROR, \"Refusing to start!\");\n Logger_Queue.Add_Packet (Logger_Packet);\n goto Shutdown_Procedure;" + }, + { + "function_def": "procedure DNSCatcherD is", + "function_body": "begin\n Install_Handler (Handler => Signal_Handlers.SIGINT_Handler'Access);\n DNSCatcher.DNS.Server.Start_Server;\nexception\n when Error : Ada.IO_Exceptions.Name_Error =>\n begin\n Put (Standard_Error, \"FATAL: Unable to open config file: \");\n Put_Line (Standard_Error, Exception_Message (Error));\n DNSCatcher.DNS.Server.Stop_Server;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E099 := E099 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E111 := E111 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E054 := E054 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n Interfaces.C'Elab_Spec;\n E078 := E078 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E080 := E080 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E008 := E008 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E103 := E103 + 1;\n Ada.Streams'Elab_Spec;\n E101 := E101 + 1;\n Interfaces.C.Strings'Elab_Spec;\n E158 := E158 + 1;\n System.File_Control_Block'Elab_Spec;\n E115 := E115 + 1;\n System.Finalization_Root'Elab_Spec;\n E114 := E114 + 1;\n Ada.Finalization'Elab_Spec;\n E112 := E112 + 1;\n System.File_Io'Elab_Body;\n E111 := E111 + 1;\n System.Task_Info'Elab_Spec;\n E171 := E171 + 1;\n Ada.Real_Time'Elab_Spec;\n Ada.Real_Time'Elab_Body;\n E152 := E152 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E099 := E099 + 1;\n E183 := E183 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure Main is", + "function_body": "Agent_Port : constant Port_Type := 10_161;\n -- Changed from 161 to 10161 to avoid Linux permission issues.\n Agent_Addr : constant Sock_Addr_Type :=\n (Addr => Inet_Addr (\"127.0.0.1\"), Port => Agent_Port, others => <>);\n Peer_Addr : Sock_Addr_Type;\n\n Buffer :\n Stream_Element_Array\n (1 .. Stream_Element_Offset (Snowpeak.Max_UDP_Payload_Size));\n Last : Stream_Element_Offset;\n\n Socket : Snowpeak.UDP_Socket.UDP_Socket;\n Querier : Snowpeak.Querier.Map_Querier;\n\n Count : Integer := 0;\n\n -- REQUIRED FOR DUMMY QUERIER\n package Types renames RFLX.RFLX_Types;\n Dummy_Contact_OID : Types.Bytes := [43, 6, 1, 2, 1, 1, 4, 0];\n Dummy_Contact : Types.Bytes_Ptr :=\n new Types.Bytes'([102, 111, 46, 111, 98, 64, 97, 114, 98, 46, 97, 122]);\n Dummy_Name_OID : Types.Bytes := [43, 6, 1, 2, 1, 1, 5, 0];\n Dummy_Name : Types.Bytes_Ptr := new Types.Bytes'([70, 54, 51, 48, 48]);\nbegin\n -- INIT OF DUMMY QUERIER\n declare\n Element : Varbind;\n begin\n for B of Dummy_Contact_OID loop\n Element.OID.Push (Types.Byte (B));\n end loop;\n Element.Variable := (Tag_Num => 4, Data => Dummy_Contact, others => <>);\n Querier.Data.Push (Element);" + }, + { + "function_def": "function As_Bytes is new Ada.Unchecked_Conversion (BE_I64, I64_Bytes);", + "function_body": "Len : constant Short_Length := I64_Length (I);\n begin\n return As_Bytes ((Inner => I)) (Types.Index (8 - Len + 1) .. 8);\n end To_BE_Bytes;\n -- Encodes an interger with ASN.1 BER.\n\n function Length (Self : TLV) return Short_Length is\n (Short_Length (if Self.Data = null then 0 else Self.Data.all'Length));\n -- Returns the length of Data in bytes.\n\n function Length (Self : Varbind) return Short_Length is\n (Short_Length (Self.OID.Length) + Self.Variable.Length + 2 * 2);\n -- Returns the length of the ASN.1 BER encoding of this record.\n\n function Length (Self : PDU) return Short_Length is\n Res : Short_Length :=\n Short_Length\n (I64_Length (Self.Request_ID) + I64_Length (Self.Error_Status) +\n I64_Length (Self.Error_Index)) +\n 4 * 2;\n -- + [for V of Self.Variable_Bindings.View => V.Length + 2]'Reduce(\"+\", 0)\n begin\n -- HACK: Workaround for compiler internal error in version `23.0w-20220508`.\n for V of Self.Variable_Bindings.View loop\n Res := @ + V.Length + 2;\n end loop;\n return Res;\n end Length;\n -- Returns the length of the ASN.1 BER encoding of this record.\n\n function Length (Self : Message) return Short_Length is\n (I64_Length (Self.Version) + Short_Length (Self.Community.Length) +\n Self.Data.Length + 3 * 2);\n\n function Write (Item : Message) return Stream_Element_Array is\n Buffer : Types.Bytes_Ptr :=\n new Types.Bytes (1 .. Types.Index (Snowpeak.Max_UDP_Payload_Size));\n Context : Packet.Context;\n Item_Full_Length : constant Stream_Element_Offset :=\n 2 + Stream_Element_Offset (Item.Length);\n Res : Stream_Element_Array (1 .. Item_Full_Length);\n\n procedure Free is new Ada.Unchecked_Deallocation\n (Types.Bytes, Types.Bytes_Ptr);\n begin\n Packet.Initialize (Context, Buffer);\n\n\n Packet.Set_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (1));\n Packet.Set_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (16));\n Packet.Set_Untagged_Length (Context, RFLX.Prelude.Asn_Length (Item.Length));\n\n -- version: int\n Packet.Set_Untagged_Value_version_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_version_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (0));\n Packet.Set_Untagged_Value_version_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (2));\n Packet.Set_Untagged_Value_version_Untagged_Length (Context, RFLX.Prelude.Asn_Length (I64_Length (Item.Version)));\n Packet.Set_Untagged_Value_version_Untagged_Value (Context, To_BE_Bytes (Item.Version));\n\n -- community: Bytes\n Packet.Set_Untagged_Value_community_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_community_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (0));\n Packet.Set_Untagged_Value_community_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (4));\n Packet.Set_Untagged_Value_community_Untagged_Length (Context, RFLX.Prelude.Asn_Length (Item.Community.Length));\n Packet.Set_Untagged_Value_community_Untagged_Value (Context, Types.Bytes (Item.Community.View));\n\n Packet.Set_Untagged_Value_data_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (Item.Data.Tag_Class));\n Packet.Set_Untagged_Value_data_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (Item.Data.Tag_Form));\n Packet.Set_Untagged_Value_data_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (Item.Data.Tag_Num));\n Packet.Set_Untagged_Value_data_get_response_Length (Context, RFLX.Prelude.Asn_Length (Item.Data.Length));\n\n -- data_get_response@request_id: int\n Packet.Set_Untagged_Value_data_get_response_Value_request_id_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_data_get_response_Value_request_id_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (0));\n Packet.Set_Untagged_Value_data_get_response_Value_request_id_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (2));\n Packet.Set_Untagged_Value_data_get_response_Value_request_id_Untagged_Length (Context, RFLX.Prelude.Asn_Length (I64_Length (Item.Data.Request_ID)));\n Packet.Set_Untagged_Value_data_get_response_Value_request_id_Untagged_Value (Context, To_BE_Bytes (Item.Data.Request_ID));\n\n -- data_get_response@error_status: int\n Packet.Set_Untagged_Value_data_get_response_Value_error_status_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_data_get_response_Value_error_status_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (0));\n Packet.Set_Untagged_Value_data_get_response_Value_error_status_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (2));\n Packet.Set_Untagged_Value_data_get_response_Value_error_status_Untagged_Length (Context, RFLX.Prelude.Asn_Length (I64_Length (Item.Data.Error_Status)));\n Packet.Set_Untagged_Value_data_get_response_Value_error_status_Untagged_Value (Context, To_BE_Bytes (Item.Data.Error_Status));\n\n -- data_get_response@error_index: int\n Packet.Set_Untagged_Value_data_get_response_Value_error_index_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_data_get_response_Value_error_index_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (0));\n Packet.Set_Untagged_Value_data_get_response_Value_error_index_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (2));\n Packet.Set_Untagged_Value_data_get_response_Value_error_index_Untagged_Length (Context, RFLX.Prelude.Asn_Length (I64_Length (Item.Data.Error_Index)));\n Packet.Set_Untagged_Value_data_get_response_Value_error_index_Untagged_Value (Context, To_BE_Bytes (Item.Data.Error_Index));\n\n -- data_get_response@variable_bindings: Seq\n Packet.Set_Untagged_Value_data_get_response_Value_variable_bindings_Tag_Class (Context, RFLX.Prelude.Asn_Tag_Class (0));\n Packet.Set_Untagged_Value_data_get_response_Value_variable_bindings_Tag_Form (Context, RFLX.Prelude.Asn_Tag_Form (1));\n Packet.Set_Untagged_Value_data_get_response_Value_variable_bindings_Tag_Num (Context, RFLX.Prelude.Asn_Tag_Num (16));\n Packet.Set_Untagged_Value_data_get_response_Value_variable_bindings_Untagged_Length (Context, RFLX.Prelude.Asn_Length ([for E of Item.Data.Variable_Bindings.View => E.Length + 2]'Reduce(\"+\", Short_Length (0))));\n\n declare\n Varbind_Seq_Context : Varbind_Seq.Context;\n Varbind_Context : Varbind_Packet.Context;\n begin\n Packet.Switch_To_Untagged_Value_data_get_response_Value_variable_bindings_Untagged_Value\n (Context, Varbind_Seq_Context);\n\n for Element of Item.Data.Variable_Bindings.View loop\n Varbind_Seq.Switch (Varbind_Seq_Context, Varbind_Context);\n\n Varbind_Packet.Set_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (1));\n Varbind_Packet.Set_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (16));\n Varbind_Packet.Set_Untagged_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Length));\n\n Varbind_Packet.Set_Untagged_Value_name_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Untagged_Value_name_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_name_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (6));\n Varbind_Packet.Set_Untagged_Value_name_Untagged_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.OID.Length));\n Varbind_Packet.Set_Untagged_Value_name_Untagged_Value (Varbind_Context, Types.Bytes (Element.OID.View));\n\n -- Write `Element.Variable` to `Untagged_Value_value`.\n\n if Element.Variable.Tag_Class = 0 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 2 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (2));\n Varbind_Packet.Set_Untagged_Value_value_simple_number_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_simple_number_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 0 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 4 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (4));\n Varbind_Packet.Set_Untagged_Value_value_simple_string_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_simple_string_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 0 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 5 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (5));\n Varbind_Packet.Set_Untagged_Value_value_simple_empty_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n elsif Element.Variable.Tag_Class = 0 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 6 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (6));\n Varbind_Packet.Set_Untagged_Value_value_simple_object_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_simple_object_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 1 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 0 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (1));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (0));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_address_internet_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_address_internet_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 1 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 1 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (1));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (1));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_counter_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_counter_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 1 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 2 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (1));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (2));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_gauge_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_gauge_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 1 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 3 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (1));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (3));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_ticks_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_ticks_Value (Varbind_Context, Element.Variable.Data.all);\n elsif Element.Variable.Tag_Class = 1 and then Element.Variable.Tag_Form = 0 and then Element.Variable.Tag_Num = 4 then\n Varbind_Packet.Set_Untagged_Value_value_Tag_Class (Varbind_Context, RFLX.Prelude.Asn_Tag_Class (1));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Form (Varbind_Context, RFLX.Prelude.Asn_Tag_Form (0));\n Varbind_Packet.Set_Untagged_Value_value_Tag_Num (Varbind_Context, RFLX.Prelude.Asn_Tag_Num (4));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_arbitrary_Length (Varbind_Context, RFLX.Prelude.Asn_Length (Element.Variable.Length));\n Varbind_Packet.Set_Untagged_Value_value_application_wide_arbitrary_Value (Varbind_Context, Element.Variable.Data.all);\n else raise Constraint_Error with \"Unsupported ASN.1 tag found\"; end if;\n Varbind_Seq.Update (Varbind_Seq_Context, Varbind_Context);\n end loop;\n \n Packet.Update_Untagged_Value_data_get_response_Value_variable_bindings_Untagged_Value\n (Context, Varbind_Seq_Context);" + }, + { + "function_def": "procedure main is", + "function_body": "use Ada.Strings.Unbounded;\n\n package Suite is new Ada.Containers.Vectors( Index_Type => Natural,\n Element_Type => Solution_Case);\n\n Test_Suite : Suite.Vector;\n Count : Integer := 1;\n Failed : Integer := 0;\n\nbegin\n\n Test_Suite.Append(Problem_1.Get_Solutions);\n Test_Suite.Append(Problem_2.Get_Solutions);\n Test_Suite.Append(Problem_3.Get_Solutions);\n Test_Suite.Append(Problem_4.Get_Solutions);\n Test_Suite.Append(Problem_5.Get_Solutions);\n Test_Suite.Append(Problem_6.Get_Solutions);\n Test_Suite.Append(Problem_7.Get_Solutions);\n Test_Suite.Append(Problem_8.Get_Solutions);\n Test_Suite.Append(Problem_9.Get_Solutions);\n Test_Suite.Append(Problem_10.Get_Solutions);\n Test_Suite.Append(Problem_11.Get_Solutions);\n Test_Suite.Append(Problem_12.Get_Solutions);\n Test_Suite.Append(Problem_13.Get_Solutions);\n Test_Suite.Append(Problem_14.Get_Solutions);\n Test_Suite.Append(Problem_15.Get_Solutions);\n Test_Suite.Append(Problem_16.Get_Solutions);\n Test_Suite.Append(Problem_17.Get_Solutions);\n Test_Suite.Append(Problem_18.Get_Solutions);\n Test_Suite.Append(Problem_19.Get_Solutions);\n Test_Suite.Append(Problem_20.Get_Solutions);\n Test_Suite.Append(Problem_21.Get_Solutions);\n\n for C of Test_Suite loop\n Put_Line(\"Running test case: \" & To_String(C.Name) );\n Count := 1;\n for T of C.Tests loop\n Put(\"Running Test\" & Integer'Image(Count) & \" :\");\n declare\n begin\n T.all;\n Put(\" Passed\");\n exception\n when Assertion_Error =>\n Failed := Failed + 1;\n Put(\" Failed\");" + }, + { + "function_def": "procedure Test_Solution_1 is", + "function_body": "Solution : constant Integer := 837799;\n begin\n Assert( Solution_1 = Solution );" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation (Name\t=> C.Strings.Char_Array_Access,", + "function_body": "Object\t=> C.Char_Array);\n use type C.Size_T;\n Size\t: C.Size_T\t:= C_Value'Length - 1;\n begin\n if C_Setsockopt (C.Int (Obj.Fd),\n C.Int (Level),\n C.Int (Name),\n C_Value.all'Address,\n Size) < 0 then\n raise Socket_Exception with \"Setopt error\" & Nanomsg.Errors.Errno_Text;\n end if;\n Free (C_Value);\n end Set_Option;\n\n\n\n\n function Get_Option (Obj : in Socket_T;\n Level : in Nanomsg.Sockopt.Option_Level_T;\n Name : in Nanomsg.Sockopt.Option_Type_T) return String is\n type String_Access_T is access all String;\n procedure Free is new Ada.Unchecked_Deallocation (Name => String_Access_T,\n\t\t\t\t\t\t\tObject => String);\n\n function Nn_Getsockopt (Socket\t : in \t C.Int;\n\t\t\t Level\t : in \t C.Int;\n\t\t\t Option_Name : in \t C.Int;\n\t\t\t Value\t : in out String_Access_T;\n\t\t\t Size\t : in \t System.Address) return C.Int\n with Import, Convention => C, External_Name => \"nn_getsockopt\";\n\n\n use Nanomsg.Sockopt;\n Max_Size : constant := 63;\n Ptr : String_Access_T := new String(1..Max_Size);\n Size\t: C.Size_T := Max_Size;\n use type C.Size_T;\n begin\n if Nn_Getsockopt (Socket\t\t=> C.Int (Obj.Fd),\n\t\t\tLevel\t\t=> C.Int (Level),\n\t\t\tOption_Name\t=> C.Int (Name),\n\t\t\tValue\t\t=> Ptr,\n\t\t\tSize\t\t=> Size'Address) < 0 then\n\t raise Socket_Exception with \"Getopt error\" & Nanomsg.Errors.Errno_Text;\n end if;\n declare\n Retval : constant String := Ptr.all(1.. Integer (Size));\n begin\n\t Free (Ptr);\n return Retval;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (chars_ptr, Void_Ptr);", + "function_body": "begin\n Send_Signal (Plugin, \"irc_input_send\", String_Type, Convert (Signal_Message));\n Free (Signal_Message);\n exception\n when others =>\n Free (Signal_Message);\n raise;\n end Send_Message;\n\n function Get_Nick (Host : String) return String is\n Sender : constant String := SU.To_String (Split (Host, Separator => \"!\", Maximum => 2) (1));\n begin\n return Sender (Sender'First + 1 .. Sender'Last);\n end Get_Nick;\n\n function Name (Plugin : Plugin_Ptr) return String is\n (Value (Plugin.Plugin_Get_Name (Plugin)));\n\n procedure Print (Plugin : Plugin_Ptr; Prefix : Prefix_Kind; Message : String) is\n package CH renames Ada.Characters.Handling;\n\n Prefix_String : constant chars_ptr := Plugin.Prefix (CH.To_Lower (Prefix'Image) & L1.NUL);\n Message_String : constant C_String := Value (Prefix_String) & Message & L1.NUL;\n begin\n Plugin.Printf_Date_Tags\n (System.Null_Address, 0, Null_Ptr, Message_String);\n end Print;\n\n procedure Print (Plugin : Plugin_Ptr; Prefix : String; Message : String) is\n begin\n Plugin.Printf_Date_Tags\n (System.Null_Address, 0, Null_Ptr, Prefix & L1.HT & Message & L1.NUL);\n end Print;\n\n procedure Print (Plugin : Plugin_Ptr; Message : String) is\n begin\n Print (Plugin, \" \", Message);\n end Print;\n\n procedure Log (Plugin : Plugin_Ptr; Message : String) is\n begin\n Plugin.Log_Printf (Message & L1.NUL);\n end Log;\n\n procedure Print_Error (Plugin : Plugin_Ptr; Value : Ada.Exceptions.Exception_Occurrence) is\n begin\n Print (Plugin, Error, Ada.Exceptions.Exception_Information (Value));\n end Print_Error;\n\n function Command_Callback\n (Callback : On_Command_Callback;\n Data : Data_Ptr;\n Buffer : Buffer_Ptr;\n Argc : int;\n Argv : access chars_ptr;\n Unused_Argv_EOL : access chars_ptr) return Callback_Result\n is\n Raw_Arguments : chars_ptr_array (1 .. size_t (Argc))\n with Address => (if Argv /= null then Argv.all'Address else System.Null_Address),\n Import => True;\n\n function Get_Argument (Index : Positive) return String\n with Pre => Index <= Integer (Argc) or else\n raise Constraint_Error with \"Index\" & Index'Image & \" not in 1 ..\" & Argc'Image;\n\n function Get_Argument (Index : Positive) return String is\n (Value (Raw_Arguments (size_t (Index))));\n\n Arguments : String_List (1 .. Raw_Arguments'Length);\n begin\n for Index in Arguments'Range loop\n Arguments (Index) := SU.To_Unbounded_String (Get_Argument (Index));\n end loop;\n\n return Callback (Data.Plugin, Buffer, Arguments);\n exception\n when E : others =>\n Print_Error (Data.Plugin, E);\n return Error;\n end Command_Callback;\n\n function Command_Run_Callback\n (Callback : On_Command_Run_Callback;\n Data : Data_Ptr;\n Buffer : Buffer_Ptr;\n Command : chars_ptr) return Callback_Result is\n begin\n return Callback (Data.Plugin, Buffer, Value (Command));\n exception\n when E : others =>\n Print_Error (Data.Plugin, E);\n return Error;\n end Command_Run_Callback;\n\n function Completion_Callback\n (Callback : On_Completion_Callback;\n Data : Data_Ptr;\n Item : chars_ptr;\n Buffer : Buffer_Ptr;\n Completion : Completion_Ptr) return Callback_Result is\n begin\n return Callback (Data.Plugin, Value (Item), Buffer, Completion);\n exception\n when E : others =>\n Print_Error (Data.Plugin, E);\n return Error;\n end Completion_Callback;\n\n function Modifier_Callback\n (Callback : On_Modifier_Callback;\n Data : Data_Ptr;\n Modifier : chars_ptr;\n Modifier_Data : chars_ptr;\n Text : chars_ptr) return chars_ptr is\n begin\n return New_String\n (Callback (Data.Plugin, Value (Modifier), Value (Modifier_Data), Value (Text)));\n exception\n when E : others =>\n Print_Error (Data.Plugin, E);\n return Text;\n end Modifier_Callback;\n\n ----------------------------------------------------------------------------\n\n function Get_Value (Plugin : Plugin_Ptr; Data : Hashtable_Ptr; Key : String) return String is\n Result : constant chars_ptr := Plugin.Hashtable_Get (Data, Key & L1.NUL);\n begin\n if Result /= Null_Ptr then\n return Value (Result);\n else\n raise Constraint_Error with \"Key '\" & Key & \"' does not exist\";\n end if;\n end Get_Value;\n\n function Get_Value (Plugin : Plugin_Ptr; Data : Hashtable_Ptr; Key : String) return Integer is\n (Integer'Value (Get_Value (Plugin, Data, Key)));\n\n function Get_Value (Plugin : Plugin_Ptr; Data : Hashtable_Ptr; Key : String) return Boolean is\n (Get_Value (Plugin, Data, Key) = 1);\n\n function Get_Value\n (Plugin : Plugin_Ptr;\n Data : Hashtable_Ptr;\n Key : String) return SU.Unbounded_String\n is (SU.To_Unbounded_String (String'(Get_Value (Plugin, Data, Key))));\n\n function Get_Value\n (Plugin : Plugin_Ptr;\n Data : Hashtable_Ptr;\n Key : String) return Line_Buffer_Kind\n is\n Value : constant String := Get_Value (Plugin, Data, Key);\n begin\n if Value = \"formatted\" then\n return Formatted;\n elsif Value = \"free\" then\n return Free;\n else\n raise Constraint_Error;\n end if;\n end Get_Value;\n\n function Get_Value\n (Plugin : Plugin_Ptr;\n Data : Hashtable_Ptr;\n Key : String) return Notify_Level\n is\n Value : constant Integer := Get_Value (Plugin, Data, Key);\n begin\n return\n (case Value is\n when -1 => None,\n when 0 => Low,\n when 1 => Message,\n when 2 => Private_Message,\n when 3 => Highlight,\n when others => raise Constraint_Error);\n end Get_Value;\n\n function Unix_Time_To_Ada (Value : Duration) return Ada.Calendar.Time is\n use Ada.Calendar;\n\n Time_Epoch : constant Time := Time_Of (Year => 1970, Month => 1, Day => 1);\n Time_Offset : constant Duration := Duration (Time_Zones.UTC_Time_Offset (Time_Epoch)) * 60;\n begin\n return Time_Epoch + Time_Offset + Value;\n end Unix_Time_To_Ada;\n\n function Ada_To_Unix_Time (Value : Ada.Calendar.Time) return Duration is\n use Ada.Calendar;\n\n Time_Epoch : constant Time := Time_Of (Year => 1970, Month => 1, Day => 1);\n Time_Offset : constant Duration := Duration (Time_Zones.UTC_Time_Offset (Time_Epoch)) * 60;\n begin\n return Value - (Time_Epoch + Time_Offset);\n end Ada_To_Unix_Time;\n\n function Get_Value\n (Plugin : Plugin_Ptr;\n Table : Hashtable_Ptr;\n Key : String) return Ada.Calendar.Time\n is\n Value : constant Integer := Get_Value (Plugin, Table, Key);\n begin\n return Unix_Time_To_Ada (Duration (Value));\n end Get_Value;\n\n procedure Set_Value\n (Plugin : Plugin_Ptr;\n Table : Hashtable_Ptr;\n Key : String;\n Value : String)\n is\n Unused_Item : constant System.Address :=\n Plugin.Hashtable_Set (Table, Key & L1.NUL, Value & L1.NUL);\n begin\n null;\n end Set_Value;\n\n procedure Set_Value\n (Plugin : Plugin_Ptr;\n Table : Hashtable_Ptr;\n Key : String;\n Value : Ada.Calendar.Time) is\n begin\n Set_Value (Plugin, Table, Key, Integer'Image (Integer (Ada_To_Unix_Time (Value))));\n end Set_Value;\n\n procedure Set_Value\n (Plugin : Plugin_Ptr;\n Table : Hashtable_Ptr;\n Key : String;\n Value : Notify_Level) is\n begin\n Set_Value (Plugin, Table, Key,\n (case Value is\n when None => \"-1\",\n when Low => \"0\",\n when Message => \"1\",\n when Private_Message => \"2\",\n when Highlight => \"3\"));\n end Set_Value;\n\n procedure Set_Value\n (Plugin : Plugin_Ptr;\n Table : Hashtable_Ptr;\n Key : String;\n Value : Boolean) is\n begin\n Set_Value (Plugin, Table, Key, (if Value then \"1\" else \"0\"));\n end Set_Value;\n\n function Create_Line_Data (Plugin : Plugin_Ptr; Line : Hashtable_Ptr) return Line_Data is\n Kind : constant Line_Buffer_Kind := Get_Value (Plugin, Line, \"buffer_type\");\n Name : constant SU.Unbounded_String := Get_Value (Plugin, Line, \"buffer_name\");\n Message : constant SU.Unbounded_String := Get_Value (Plugin, Line, \"message\");\n\n Displayed : constant Boolean := Get_Value (Plugin, Line, \"displayed\");\n\n Buffer : constant SU.Unbounded_String := Get_Value (Plugin, Line, \"buffer\");\n begin\n case Kind is\n when Formatted =>\n return\n (Kind => Formatted,\n Buffer => Buffer,\n Name => Name,\n Message => Message,\n Displayed => Displayed,\n Date => Get_Value (Plugin, Line, \"date\"),\n Date_Printed => Get_Value (Plugin, Line, \"date_printed\"),\n Date_Display => Get_Value (Plugin, Line, \"str_time\"),\n Tags => Get_Value (Plugin, Line, \"tags\"),\n Level => Get_Value (Plugin, Line, \"notify_level\"),\n Highlight => Get_Value (Plugin, Line, \"highlight\"),\n Prefix => Get_Value (Plugin, Line, \"prefix\"));\n when Free =>\n return\n (Kind => Free,\n Buffer => Buffer,\n Name => Name,\n Message => Message,\n Displayed => Displayed,\n Line_Number => Get_Value (Plugin, Line, \"y\"));\n end case;\n end Create_Line_Data;\n\n ----------------------------------------------------------------------------\n\n function Line_Callback\n (Callback : On_Line_Callback;\n Data : Data_Ptr;\n Line : Hashtable_Ptr) return Hashtable_Ptr\n is\n use type Ada.Calendar.Time;\n use type SU.Unbounded_String;\n\n Keys_Count : constant := 10;\n Long_Bytes : constant := long'Size / System.Storage_Unit;\n begin\n declare\n Value : constant Line_Data := Create_Line_Data (Data.Plugin, Line);\n Result : Line_Data := Value;\n begin\n Callback (Data.Plugin, Result);\n\n return Table : constant Hashtable_Ptr :=\n Data.Plugin.Hashtable_New\n (Long_Bytes * Keys_Count,\n Weechat_Hashtable_String, Weechat_Hashtable_String, null, null)\n do\n if Value.Buffer /= Result.Buffer then\n Set_Value (Data.Plugin, Table, \"buffer\", +Result.Buffer);\n end if;\n\n if Value.Name /= Result.Name then\n Set_Value (Data.Plugin, Table, \"name\", +Result.Name);\n end if;\n\n if Value.Message /= Result.Message then\n Set_Value (Data.Plugin, Table, \"message\", +Result.Message);\n end if;\n\n case Result.Kind is\n when Formatted =>\n if Value.Date /= Result.Date then\n Set_Value (Data.Plugin, Table, \"date\", Result.Date);\n end if;\n\n if Value.Date_Printed /= Result.Date_Printed then\n Set_Value (Data.Plugin, Table, \"date_printed\", Result.Date_Printed);\n end if;\n\n if Value.Date_Display /= Result.Date_Display then\n Set_Value (Data.Plugin, Table, \"str_time\", +Result.Date_Display);\n end if;\n\n if Value.Tags /= Result.Tags then\n Set_Value (Data.Plugin, Table, \"tags\", +Result.Tags);\n end if;\n\n if Value.Level /= Result.Level then\n Set_Value (Data.Plugin, Table, \"notify_level\", Result.Level);\n end if;\n\n if Value.Highlight /= Result.Highlight then\n Set_Value (Data.Plugin, Table, \"highlight\", Result.Highlight);\n end if;\n\n if Value.Prefix /= Result.Prefix then\n Set_Value (Data.Plugin, Table, \"prefix\", +Result.Prefix);\n end if;\n when Free =>\n if Value.Line_Number /= Result.Line_Number then\n Set_Value (Data.Plugin, Table, \"y\", Integer'Image (Result.Line_Number));\n end if;\n end case;\n end return;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := 0;\n Time_Slice_Value := 0;\n WC_Encoding := 'b';\n Locking_Policy := 'C';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := 'F';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 1;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 4;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Ada.Strings.Text_Buffers'Elab_Spec;\n E005 := E005 + 1;\n System.Bb.Timing_Events'Elab_Spec;\n E059 := E059 + 1;\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n Ada.Tags'Elab_Body;\n E061 := E061 + 1;\n System.Exception_Table'Elab_Body;\n E096 := E096 + 1;\n E098 := E098 + 1;\n E012 := E012 + 1;\n Ada.Streams'Elab_Spec;\n E132 := E132 + 1;\n System.Finalization_Root'Elab_Spec;\n E138 := E138 + 1;\n Ada.Finalization'Elab_Spec;\n E136 := E136 + 1;\n System.Storage_Pools'Elab_Spec;\n E140 := E140 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E135 := E135 + 1;\n Ada.Real_Time'Elab_Body;\n E126 := E126 + 1;\n System.Bb.Execution_Time'Elab_Body;\n E248 := E248 + 1;\n System.Pool_Global'Elab_Spec;\n E142 := E142 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E214 := E214 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E221 := E221 + 1;\n HAL.GPIO'ELAB_SPEC;\n E163 := E163 + 1;\n HAL.I2C'ELAB_SPEC;\n E184 := E184 + 1;\n HAL.SPI'ELAB_SPEC;\n E177 := E177 + 1;\n HAL.UART'ELAB_SPEC;\n E130 := E130 + 1;\n E194 := E194 + 1;\n E192 := E192 + 1;\n E196 := E196 + 1;\n Nrf.Gpio'Elab_Spec;\n Nrf.Gpio'Elab_Body;\n E157 := E157 + 1;\n E236 := E236 + 1;\n E207 := E207 + 1;\n E172 := E172 + 1;\n Nrf.Spi_Master'Elab_Spec;\n Nrf.Spi_Master'Elab_Body;\n E175 := E175 + 1;\n E209 := E209 + 1;\n E234 := E234 + 1;\n E228 := E228 + 1;\n E238 := E238 + 1;\n E226 := E226 + 1;\n Nrf.Timers'Elab_Spec;\n Nrf.Timers'Elab_Body;\n E179 := E179 + 1;\n Nrf.Twi'Elab_Spec;\n Nrf.Twi'Elab_Body;\n E182 := E182 + 1;\n Nrf.Uart'Elab_Spec;\n Nrf.Uart'Elab_Body;\n E186 := E186 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E148 := E148 + 1;\n Microbit.Console'Elab_Body;\n E128 := E128 + 1;\n Microbit.Iosfortasking'Elab_Spec;\n Microbit.Iosfortasking'Elab_Body;\n E232 := E232 + 1;\n Microbit.Radio'Elab_Spec;\n E189 := E189 + 1;\n Microbit.Timehighspeed'Elab_Body;\n E242 := E242 + 1;\n E230 := E230 + 1;\n E244 := E244 + 1;\n Controller'Elab_Spec;\n Controller'Elab_Body;\n E122 := E122 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;" + }, + { + "function_def": "function To_Bits is new Ada.Unchecked_Conversion (Address, Bits);", + "function_body": "LE : constant := Standard'Default_Bit_Order;\n -- Static constant set to 0 for big-endian, 1 for little-endian\n\n -- The following is an array of masks used to mask the final byte, either\n -- at the high end (big-endian case) or the low end (little-endian case).\n\n Masks : constant array (1 .. 7) of Packed_Byte := (\n (1 - LE) * 2#1000_0000# + LE * 2#0000_0001#,\n (1 - LE) * 2#1100_0000# + LE * 2#0000_0011#,\n (1 - LE) * 2#1110_0000# + LE * 2#0000_0111#,\n (1 - LE) * 2#1111_0000# + LE * 2#0000_1111#,\n (1 - LE) * 2#1111_1000# + LE * 2#0001_1111#,\n (1 - LE) * 2#1111_1100# + LE * 2#0011_1111#,\n (1 - LE) * 2#1111_1110# + LE * 2#0111_1111#);\n\n -----------------------\n -- Local Subprograms --\n -----------------------\n\n procedure Raise_Error;\n -- Raise Constraint_Error, complaining about unequal lengths\n\n -------------\n -- Bit_And --\n -------------\n\n procedure Bit_And\n (Left : Address;\n Llen : Natural;\n Right : Address;\n Rlen : Natural;\n Result : Address)\n is\n-- LeftB : constant Bits := To_Bits (Left);\n-- RightB : constant Bits := To_Bits (Right);\n-- ResultB : constant Bits := To_Bits (Result);\n-- pragma Unreferenced (Llen);\n pragma Unreferenced (Rlen);\n begin\n -- for the time being we don't provide dynamic range checks\n -- if Llen /= Rlen then\n -- Raise_Error;\n -- end if;\n\n -- this routine is called only for 1, 2, or 4 byte lengths.\n -- The Rlen/Llen parameter is either, 8, 16, or 32.\n if Llen = 8 then\n declare\n use Interfaces;\n Left_Byte : Unsigned_8;\n for Left_Byte'Address use Left;\n Right_Byte : Unsigned_8;\n for Right_Byte'Address use Right;\n Result_Byte : Unsigned_8;\n for Result_Byte'Address use Result;\n begin\n Result_Byte := Left_Byte and Right_Byte;" + }, + { + "function_def": "function To_Bits is new Ada.Unchecked_Conversion (Address, Bits);", + "function_body": "LE : constant := Standard'Default_Bit_Order;\n -- Static constant set to 0 for big-endian, 1 for little-endian\n\n -- The following is an array of masks used to mask the final byte, either\n -- at the high end (big-endian case) or the low end (little-endian case).\n\n Masks : constant array (1 .. 7) of Packed_Byte := (\n (1 - LE) * 2#1000_0000# + LE * 2#0000_0001#,\n (1 - LE) * 2#1100_0000# + LE * 2#0000_0011#,\n (1 - LE) * 2#1110_0000# + LE * 2#0000_0111#,\n (1 - LE) * 2#1111_0000# + LE * 2#0000_1111#,\n (1 - LE) * 2#1111_1000# + LE * 2#0001_1111#,\n (1 - LE) * 2#1111_1100# + LE * 2#0011_1111#,\n (1 - LE) * 2#1111_1110# + LE * 2#0111_1111#);\n\n -----------------------\n -- Local Subprograms --\n -----------------------\n\n procedure Raise_Error;\n -- Raise Constraint_Error, complaining about unequal lengths\n\n -------------\n -- Bit_And --\n -------------\n\n procedure Bit_And\n (Left : Address;\n Llen : Natural;\n Right : Address;\n Rlen : Natural;\n Result : Address)\n is\n-- LeftB : constant Bits := To_Bits (Left);\n-- RightB : constant Bits := To_Bits (Right);\n-- ResultB : constant Bits := To_Bits (Result);\n-- pragma Unreferenced (Llen);\n pragma Unreferenced (Rlen);\n begin\n -- for the time being we don't provide dynamic range checks\n -- if Llen /= Rlen then\n -- Raise_Error;\n -- end if;\n\n -- this routine is called only for 1, 2, or 4 byte lengths.\n -- The Rlen/Llen parameter is either, 8, 16, or 32.\n if Llen = 8 then\n declare\n use Interfaces;\n Left_Byte : Unsigned_8;\n for Left_Byte'Address use Left;\n Right_Byte : Unsigned_8;\n for Right_Byte'Address use Right;\n Result_Byte : Unsigned_8;\n for Result_Byte'Address use Result;\n begin\n Result_Byte := Left_Byte and Right_Byte;" + }, + { + "function_def": "function To_Stack_Pool is new", + "function_body": "Ada.Unchecked_Conversion (Address, Stk_Pool_Access);\n\n pragma Warnings (Off);\n function To_Global_Ptr is new\n Ada.Unchecked_Conversion (Address, SS_Stack_Ptr);\n pragma Warnings (On);\n -- Suppress aliasing warning since the pointer we return will\n -- be the only access to the stack.\n\n Local_Stk_Address : System.Address;\n\n begin\n Num_Of_Assigned_Stacks := Num_Of_Assigned_Stacks + 1;\n\n Local_Stk_Address :=\n To_Stack_Pool\n (Default_Sized_SS_Pool) (Num_Of_Assigned_Stacks)'Address;\n Stack := To_Global_Ptr (Local_Stk_Address);" + }, + { + "function_def": "procedure Draw_Glyph is new Hershey_Fonts.Draw_Glyph", + "function_body": "(Internal_Draw_Line);\n\n Current : Point := Start;\n\n begin\n Buffer.Set_Source (Foreground);\n for C of Msg loop\n exit when Current.X > Buffer.Width;\n Draw_Glyph\n (Fnt => Font,\n C => C,\n X => Current.X,\n Y => Current.Y,\n Height => Height,\n Bold => Bold);\n end loop;\n end Draw_String;\n\n -----------------\n -- Draw_String --\n -----------------\n\n procedure Draw_String\n (Buffer : in out Bitmap_Buffer'Class;\n Area : Rect;\n Msg : String;\n Font : Hershey_Font;\n Bold : Boolean;\n Outline : Boolean;\n Foreground : Bitmap_Color;\n Fast : Boolean := True)\n is\n Length : constant Natural :=\n Hershey_Fonts.Strlen (Msg, Font, Area.Height);\n Ratio : Float;\n Current : Point := (0, 0);\n Prev : UInt32;\n FG : constant UInt32 := Bitmap_Color_To_Word (Buffer.Color_Mode,\n Foreground);\n Blk : constant UInt32 := Bitmap_Color_To_Word (Buffer.Color_Mode,\n Black);\n\n procedure Internal_Draw_Line\n (X0, Y0, X1, Y1 : Natural;\n Width : Positive);\n\n procedure Internal_Draw_Line\n (X0, Y0, X1, Y1 : Natural;\n Width : Positive)\n is\n begin\n Draw_Line (Buffer,\n (Area.Position.X + Natural (Float (X0) * Ratio),\n Area.Position.Y + Y0),\n (Area.Position.X + Natural (Float (X1) * Ratio),\n Area.Position.Y + Y1),\n Width,\n Fast);\n end Internal_Draw_Line;\n\n procedure Draw_Glyph is new Hershey_Fonts.Draw_Glyph\n (Internal_Draw_Line);\n\n begin\n if Length > Area.Width then\n Ratio := Float (Area.Width) / Float (Length);\n else\n Ratio := 1.0;\n Current.X := (Area.Width - Length) / 2;\n end if;\n\n Buffer.Set_Source (Foreground);\n\n for C of Msg loop\n Draw_Glyph\n (Fnt => Font,\n C => C,\n X => Current.X,\n Y => Current.Y,\n Height => Area.Height,\n Bold => Bold);\n end loop;\n\n if Outline and then Area.Height > 40 then\n for Y in Area.Position.Y + 1 .. Area.Position.Y + Area.Height loop\n Prev := Buffer.Pixel ((Area.Position.X, Y));\n if Prev = FG then\n Buffer.Set_Pixel ((Area.Position.X, Y), Black);\n end if;\n\n for X in Area.Position.X + 1 .. Area.Position.X + Area.Width loop\n declare\n Col : constant UInt32 := Buffer.Pixel ((X, Y));\n Top : constant UInt32 := Buffer.Pixel ((X, Y - 1));\n begin\n\n if Prev /= FG\n and then Col = FG\n then\n Buffer.Set_Pixel ((X, Y), Blk);\n\n elsif Prev = FG\n and then Col /= FG\n then\n Buffer.Set_Pixel ((X - 1, Y), Blk);\n\n elsif Top /= FG\n and then Top /= Blk\n and then Col = FG\n then\n Buffer.Set_Pixel ((X, Y), Blk);\n\n elsif Top = FG\n and then Col /= FG\n then\n Buffer.Set_Pixel ((X, Y - 1), Blk);\n end if;\n\n Prev := Col;" + }, + { + "function_def": "procedure Convert_Card_Identification_Data_Register", + "function_body": "(W0, W1, W2, W3 : UInt32;\n Res : out Card_Identification_Data_Register);\n -- Convert the R2 reply to CID\n\n procedure Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3 : UInt32;\n Card_Type : Supported_SD_Memory_Cards;\n CSD : out Card_Specific_Data_Register);\n -- Convert the R2 reply to CSD\n\n procedure Convert_SDCard_Configuration_Register\n (W0, W1 : UInt32;\n SCR : out SDCard_Configuration_Register);\n -- Convert W0 (MSB) / W1 (LSB) to SCR.\n\n function Compute_Card_Capacity\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt64;\n -- Compute the card capacity (in bytes) from the CSD\n\n function Compute_Card_Block_Size\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt32;\n -- Compute the card block size (in bytes) from the CSD.\n\n function Get_Transfer_Rate\n (CSD : Card_Specific_Data_Register) return Natural;\n -- Compute transfer rate from CSD\n\n function Swap32 (Val : UInt32) return UInt32 with Inline_Always;\n\n function BE32_To_Host (Val : UInt32) return UInt32 with Inline_Always;\n\n -- Swap bytes in a word\n ------------\n -- Swap32 --\n ------------\n\n function Swap32 (Val : UInt32) return UInt32 is\n begin\n return Shift_Left (Val and 16#00_00_00_ff#, 24)\n or Shift_Left (Val and 16#00_00_ff_00#, 8)\n or Shift_Right (Val and 16#00_ff_00_00#, 8)\n or Shift_Right (Val and 16#ff_00_00_00#, 24);\n end Swap32;\n\n ------------------\n -- BE32_To_Host --\n ------------------\n\n function BE32_To_Host (Val : UInt32) return UInt32 is\n use System;\n begin\n if Default_Bit_Order = Low_Order_First then\n return Swap32 (Val);\n else\n return Val;\n end if;\n end BE32_To_Host;\n\n ---------------------------------\n -- Card_Identification_Process --\n ---------------------------------\n\n procedure Card_Identification_Process\n (This : in out SDMMC_Driver'Class;\n Info : out Card_Information;\n Status : out SD_Error)\n is\n Rsp : UInt32;\n W0, W1, W2, W3 : UInt32;\n Rca : UInt32;\n\n begin\n -- Reset controller\n This.Reset (Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD0: Sets the SDCard state to Idle\n Send_Cmd (This, Go_Idle_State, 0, Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD8: IF_Cond, voltage supplied: 0x1 (2.7V - 3.6V)\n -- It is mandatory for the host compliant to Physical Spec v2.00\n -- to send CMD8 before ACMD41\n Send_Cmd (This, Send_If_Cond, 16#1a5#, Status);\n\n if Status = OK then\n -- at least SD Card 2.0\n Info.Card_Type := STD_Capacity_SD_Card_v2_0;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and 16#fff#) /= 16#1a5# then\n -- Bad voltage or bad pattern.\n Status := Error;\n return;\n end if;\n else\n -- If SD Card, then it's v1.1\n Info.Card_Type := STD_Capacity_SD_Card_V1_1;\n end if;\n\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD55: APP_CMD\n -- This is done manually to handle error (this command is not\n -- supported by mmc).\n Send_Cmd (This, Cmd_Desc (App_Cmd), 0, Status);\n\n if Status /= OK then\n if Status = Command_Timeout_Error\n and then I = 1\n and then Info.Card_Type = STD_Capacity_SD_Card_V1_1\n then\n -- Not an SDCard. Suppose MMC.\n Info.Card_Type := Multimedia_Card;\n exit;\n end if;\n return;\n end if;\n\n -- ACMD41: SD_SEND_OP_COND (no crc check)\n -- Arg: HCS=1, XPC=0, S18R=0\n Send_Cmd\n (This, Acmd_Desc (SD_App_Send_Op_Cond), 16#40ff_0000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_High_Capacity) = SD_OCR_High_Capacity then\n Info.Card_Type := High_Capacity_SD_Card;\n end if;\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n\n else\n Status := OK;\n exit;\n end if;\n end loop;\n\n if Status = Command_Timeout_Error\n and then Info.Card_Type = Multimedia_Card\n then\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD1: SEND_OP_COND query voltage\n Send_Cmd (This, Cmd_Desc (Send_Op_Cond), 16#00ff_8000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n else\n if (Rsp and 16#00ff_8000#) /= 16#00ff_8000# then\n Status := Error;\n return;\n end if;\n Status := OK;\n exit;\n end if;\n end loop;\n end if;\n\n if Status /= OK then\n return;\n end if;\n\n -- TODO: Switch voltage\n\n -- CMD2: ALL_SEND_CID (136 bits)\n Send_Cmd (This, All_Send_CID, 0, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Identification_Data_Register (W0, W1, W2, W3, Info.SD_CID);\n\n -- CMD3: SEND_RELATIVE_ADDR\n case Info.Card_Type is\n when Multimedia_Card =>\n Rca := 16#01_0000#;\n when others =>\n Rca := 0;\n end case;\n\n Send_Cmd (This, Send_Relative_Addr, Rca, Status);\n if Status /= OK then\n return;\n end if;\n case Info.Card_Type is\n when Multimedia_Card =>\n null;\n when others =>\n Read_Rsp48 (This, Rsp);\n Rca := Rsp and 16#ffff_0000#;\n if (Rsp and 16#e100#) /= 16#0100# then\n return;\n end if;\n end case;\n Info.RCA := UInt16 (Shift_Right (Rca, 16));\n\n -- Switch to 25Mhz\n case Info.Card_Type is\n when Multimedia_Card =>\n Set_Clock (This, Get_Transfer_Rate (Info.SD_CSD));\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Set_Clock (This, 25_000_000);\n when others =>\n -- Not yet handled\n raise Program_Error;\n end case;\n\n -- CMD10: SEND_CID (136 bits)\n Send_Cmd (This, Send_CID, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD9: SEND_CSD\n Send_Cmd (This, Send_CSD, Rca, Status);\n if Status /= OK then\n return;\n end if;\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3, Info.Card_Type, Info.SD_CSD);\n Info.Card_Capacity :=\n Compute_Card_Capacity (Info.SD_CSD, Info.Card_Type);\n Info.Card_Block_Size :=\n Compute_Card_Block_Size (Info.SD_CSD, Info.Card_Type);\n\n -- CMD7: SELECT\n Send_Cmd (This, Select_Card, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD13: STATUS\n Send_Cmd (This, Send_Status, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Bus size\n case Info.Card_Type is\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Send_ACmd (This, SD_App_Set_Bus_Width, Info.RCA, 2, Status);\n if Status /= OK then\n return;\n else\n Set_Bus_Size (This, Wide_Bus_4B);\n end if;\n when others =>\n null;\n end case;\n\n if (Info.SD_CSD.Card_Command_Class and 2**10) /= 0 then\n -- Class 10 supported.\n declare\n subtype Switch_Status_Type is UInt32_Array (1 .. 16);\n\n Switch_Status : Switch_Status_Type;\n begin\n -- CMD6\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#00_fffff0#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Handle endianness\n for I in Switch_Status'Range loop\n Switch_Status (I) := BE32_To_Host (Switch_Status (I));\n end loop;\n\n -- Switch tp 50Mhz if possible.\n if (Switch_Status (4) and 2**(16 + 1)) /= 0 then\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#80_fffff1#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Switch to 50Mhz\n Set_Clock (This, 50_000_000);\n end if;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (HALFS.Status_Code, Status_Code);", + "function_body": "function Convert is new Ada.Unchecked_Conversion (File_Mode, HALFS.File_Mode);\n function Convert is new Ada.Unchecked_Conversion (File_Size, HALFS.File_Size);\n function Convert is new Ada.Unchecked_Conversion (HALFS.File_Size, File_Size);\n function Convert is new Ada.Unchecked_Conversion (Seek_Mode, HALFS.Seek_Mode);\n\n type Mount_Record is record\n Is_Free : Boolean := True;\n Name : String (1 .. Max_Mount_Name_Length);\n Name_Len : Positive;\n FS : Any_Filesystem_Driver;\n end record;\n\n subtype Mount_Index is Integer range 0 .. Max_Mount_Points;\n subtype Valid_Mount_Index is Mount_Index range 1 .. Max_Mount_Points;\n type Mount_Array is array (Valid_Mount_Index) of Mount_Record;\n\n type VFS_Directory_Handle is new Directory_Handle with record\n Is_Free : Boolean := True;\n Mount_Id : Mount_Index;\n end record;\n\n overriding function Get_FS\n (Dir : VFS_Directory_Handle) return Any_Filesystem_Driver;\n -- Return the filesystem the handle belongs to.\n\n overriding function Read\n (Dir : in out VFS_Directory_Handle;\n Handle : out Any_Node_Handle) return HALFS.Status_Code;\n -- Reads the next directory entry. If no such entry is there, an error\n -- code is returned in Status.\n\n overriding procedure Reset (Dir : in out VFS_Directory_Handle);\n -- Resets the handle to the first node\n\n overriding procedure Close (Dir : in out VFS_Directory_Handle);\n -- Closes the handle, and free the associated resources.\n\n function Open\n (Path : String;\n Handle : out Any_Directory_Handle)\n return Status_Code;\n\n function Open\n (Path : String;\n Mode : File_Mode;\n Handle : out Any_File_Handle)\n return Status_Code;\n\n Mount_Points : Mount_Array;\n\n Handles : array (1 .. 2) of aliased VFS_Directory_Handle;\n\n function Name (Point : Mount_Record) return Mount_Path;\n procedure Set_Name (Point : in out Mount_Record;\n Path : Mount_Path);\n procedure Split\n (Path : String;\n FS : out Any_Filesystem_Driver;\n Start_Index : out Natural);\n\n ----------\n -- Open --\n ----------\n\n function Open\n (File : in out File_Descriptor;\n Name : String;\n Mode : File_Mode)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Is_Open (File) then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Mode, File.Handle);\n\n if Ret /= OK then\n File.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (File : in out File_Descriptor) is\n begin\n if File.Handle /= null then\n File.Handle.Close;\n File.Handle := null;\n end if;\n end Close;\n\n -------------\n -- Is_Open --\n -------------\n\n function Is_Open\n (File : File_Descriptor)\n return Boolean\n is (File.Handle /= null);\n\n -----------\n -- Flush --\n -----------\n\n function Flush\n (File : File_Descriptor)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Flush);\n else\n return Invalid_Parameter;\n end if;\n end Flush;\n\n ----------\n -- Size --\n ----------\n\n function Size\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle = null then\n return 0;\n else\n return Convert (File.Handle.Size);\n end if;\n end Size;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Read (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n function Write\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Write (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Write;\n\n ------------\n -- Offset --\n ------------\n\n function Offset\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Offset);\n else\n return 0;\n end if;\n end Offset;\n\n ----------\n -- Seek --\n ----------\n\n function Seek\n (File : in out File_Descriptor;\n Origin : Seek_Mode;\n Amount : in out File_Size)\n return Status_Code\n is\n Ret : Status_Code;\n HALFS_Amount : HALFS.File_Size;\n begin\n if File.Handle /= null then\n HALFS_Amount := Convert (Amount);\n Ret := Convert (File.Handle.Seek (Convert (Origin), HALFS_Amount));\n Amount := Convert (HALFS_Amount);\n return Ret;\n else\n return Invalid_Parameter;\n end if;\n end Seek;\n\n -------------------\n -- Generic_Write --\n -------------------\n\n function Generic_Write\n (File : File_Descriptor;\n Value : T)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Write (Value'Address, T'Size / 8));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Write;\n\n ------------------\n -- Generic_Read --\n ------------------\n\n function Generic_Read\n (File : File_Descriptor;\n Value : out T)\n return Status_Code\n is\n L : HALFS.File_Size := T'Size / 8;\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Read (Value'Address, L));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Read;\n\n ----------\n -- Open --\n ----------\n\n function Open\n (Dir : in out Directory_Descriptor;\n Name : String)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Dir.Handle /= null then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Dir.Handle);\n\n if Ret /= OK then\n Dir.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (Dir : in out Directory_Descriptor) is\n begin\n if Dir.Handle /= null then\n Dir.Handle.Close;\n end if;\n end Close;\n\n ----------\n -- Read --\n ----------\n\n function Read (Dir : in out Directory_Descriptor)\n return Directory_Entry\n is\n Node : Any_Node_Handle;\n Status : Status_Code;\n begin\n if Dir.Handle = null then\n return Invalid_Dir_Entry;\n end if;\n\n Status := Convert (Dir.Handle.Read (Node));\n if Status /= OK then\n return Invalid_Dir_Entry;\n end if;\n\n declare\n Name : constant String := Node.Basename;\n Ret : Directory_Entry (Name_Length => Name'Length);\n begin\n Ret.Name := Name;\n Ret.Subdirectory := Node.Is_Subdirectory;\n Ret.Read_Only := Node.Is_Read_Only;\n Ret.Hidden := Node.Is_Hidden;\n Ret.Symlink := Node.Is_Symlink;\n Ret.Size := Convert (Node.Size);\n Node.Close;\n return Ret;" + }, + { + "function_def": "function To_Data is new Ada.Unchecked_Conversion", + "function_body": "(FAT_Directory_Entry, Entry_Data);\n function To_Data is new Ada.Unchecked_Conversion\n (VFAT_Directory_Entry, Entry_Data);\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index;\n -- Finds a sequence of deleted entries that can fit Num_Entries.\n -- Returns the first entry of this sequence\n\n --------------\n -- Set_Size --\n --------------\n\n procedure Set_Size\n (E : in out FAT_Node;\n Size : FAT_File_Size)\n is\n begin\n if E.Size /= Size then\n E.Size := Size;\n E.Is_Dirty := True;\n end if;\n end Set_Size;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (Parent : FAT_Node;\n Filename : FAT_Name;\n DEntry : out FAT_Node) return Status_Code\n is\n -- We use a copy of the handle, so as not to touch the state of initial\n -- handle\n Status : Status_Code;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Parent.FS.Cluster_To_Block (Cluster);\n Index : Entry_Index := 0;\n\n begin\n loop\n Status := Next_Entry\n (FS => Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Index,\n DEntry => DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Long_Name (DEntry) = Filename or else\n (DEntry.L_Name.Len = 0 and then Short_Name (DEntry) = Filename)\n then\n return OK;\n end if;\n end loop;\n end Find;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (FS : in out FAT_Filesystem;\n Path : String;\n DEntry : out FAT_Node) return Status_Code\n is\n Status : Status_Code;\n Idx : Natural; -- Idx is used to walk through the Path\n Token : FAT_Name;\n\n begin\n DEntry := Root_Entry (FS);\n\n -- Looping through the Path. We start at 2 as we ignore the initial '/'\n Idx := Path'First + 1;\n\n while Idx <= Path'Last loop\n Token.Len := 0;\n\n for J in Idx .. Path'Last loop\n if Path (J) = '/' then\n exit;\n end if;\n\n Token.Len := Token.Len + 1;\n Token.Name (Token.Len) := Path (J);\n end loop;\n\n Idx := Idx + Token.Len + 1;\n\n Status := Find (DEntry, Token, DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Idx < Path'Last then\n -- Intermediate entry: needs to be a directory\n if not Is_Subdirectory (DEntry) then\n return No_Such_Path;\n end if;\n end if;\n end loop;\n\n return OK;\n end Find;\n\n ------------------\n -- Update_Entry --\n ------------------\n\n function Update_Entry\n (Parent : FAT_Node;\n Value : in out FAT_Node) return Status_Code\n is\n subtype Entry_Block is Block (1 .. 32);\n function To_Block is new\n Ada.Unchecked_Conversion (FAT_Directory_Entry, Entry_Block);\n function To_Entry is new\n Ada.Unchecked_Conversion (Entry_Block, FAT_Directory_Entry);\n\n Ent : FAT_Directory_Entry;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Offset : FAT_File_Size := FAT_File_Size (Value.Index) * 32;\n Block_Off : Natural;\n Block : Block_Offset;\n Ret : Status_Code;\n\n begin\n if not Value.Is_Dirty then\n return OK;\n end if;\n\n while Offset > Parent.FS.Cluster_Size loop\n Cluster := Parent.FS.Get_FAT (Cluster);\n Offset := Offset - Parent.FS.Cluster_Size;\n end loop;\n\n Block := Block_Offset (Offset / Parent.FS.Block_Size);\n Block_Off := Natural (Offset mod Parent.FS.Block_Size);\n\n Ret := Parent.FS.Ensure_Block\n (Parent.FS.Cluster_To_Block (Cluster) + Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n Ent := To_Entry (Parent.FS.Window (Block_Off .. Block_Off + 31));\n\n -- For now only the size can be modified, so just apply this\n -- modification\n Ent.Size := Value.Size;\n Value.Is_Dirty := False;\n\n Parent.FS.Window (Block_Off .. Block_Off + 31) := To_Block (Ent);\n Ret := Parent.FS.Write_Window;\n\n return Ret;\n end Update_Entry;\n\n ----------------\n -- Root_Entry --\n ----------------\n\n function Root_Entry (FS : in out FAT_Filesystem) return FAT_Node\n is\n Ret : FAT_Node;\n begin\n Ret.FS := FS'Unchecked_Access;\n Ret.Attributes := (Subdirectory => True,\n others => False);\n Ret.Is_Root := True;\n Ret.L_Name := (Name => (others => ' '),\n Len => 0);\n if FS.Version = FAT16 then\n Ret.Start_Cluster := 0;\n else\n Ret.Start_Cluster := FS.Root_Dir_Cluster;\n end if;\n Ret.Index := 0;\n\n return Ret;\n end Root_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Directory_Entry) return Status_Code\n is\n subtype Entry_Data is Block (1 .. 32);\n function To_Entry is new Ada.Unchecked_Conversion\n (Entry_Data, FAT_Directory_Entry);\n\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n if Current_Index = 16#FFFF# then\n return No_More_Entries;\n end if;\n\n if Current_Cluster = 0 and then FS.Version = FAT16 then\n if Current_Index >\n Entry_Index (FS.FAT16_Root_Dir_Num_Entries)\n then\n return No_More_Entries;\n else\n Block_Off :=\n Natural (FAT_File_Size (Current_Index * 32) mod\n FS.Block_Size);\n Current_Block :=\n FS.Root_Dir_Area +\n Block_Offset\n (FAT_File_Size (Current_Index * 32) / FS.Block_Size);\n end if;\n\n else\n Block_Off := Natural\n (FAT_File_Size (Current_Index * 32) mod FS.Block_Size);\n\n -- Check if we're on a block boundare\n if Unsigned_32 (Block_Off) = 0 and then Current_Index /= 0 then\n Current_Block := Current_Block + 1;\n end if;\n\n -- Check if we're on the boundary of a new cluster\n if Current_Block - FS.Cluster_To_Block (Current_Cluster)\n = FS.Blocks_Per_Cluster\n then\n -- The block we need to read is outside of the current cluster.\n -- Let's move on to the next\n\n -- Read the FAT table to determine the next cluster\n Current_Cluster := FS.Get_FAT (Current_Cluster);\n\n if Current_Cluster = 1\n or else FS.Is_Last_Cluster (Current_Cluster)\n then\n return Internal_Error;\n end if;\n\n Current_Block := FS.Cluster_To_Block (Current_Cluster);\n end if;\n end if;\n\n Ret := FS.Ensure_Block (Current_Block);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n if FS.Window (Block_Off) = 0 then\n -- End of entries: we stick the index here to make sure that further\n -- calls to Next_Entry always end-up here\n return No_More_Entries;\n end if;\n\n DEntry := To_Entry (FS.Window (Block_Off .. Block_Off + 31));\n Current_Index := Current_Index + 1;\n\n return OK;\n end Next_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Node) return Status_Code\n is\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural);\n -- Prepends Name to Full\n\n -------------\n -- Prepend --\n -------------\n\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural)\n is\n Val : Unsigned_16;\n begin\n for J in reverse Name'Range loop\n Val := Wide_Character'Pos (Name (J));\n if Val /= 16#FFFF#\n and then Val /= 0\n then\n Idx := Idx - 1;\n\n exit when Idx not in Full'Range;\n\n if Val < 255 then\n Full (Idx) := Character'Val (Val);\n elsif Val = 16#F029# then\n -- Path ends with a '.'\n Full (Idx) := '.';\n elsif Val = 16#F028# then\n -- Path ends with a ' '\n Full (Idx) := ' ';\n else\n Full (Idx) := '?';\n end if;\n end if;\n end loop;\n end Prepend;\n\n Ret : Status_Code;\n D_Entry : FAT_Directory_Entry;\n V_Entry : VFAT_Directory_Entry;\n function To_VFAT_Entry is new Ada.Unchecked_Conversion\n (FAT_Directory_Entry, VFAT_Directory_Entry);\n\n C : Unsigned_8;\n Last_Seq : VFAT_Sequence_Number := 0;\n CRC : Unsigned_8 := 0;\n Matches : Boolean;\n Current_CRC : Unsigned_8;\n L_Name : String (1 .. MAX_FILENAME_LENGTH);\n L_Name_First : Natural;\n\n begin\n L_Name_First := L_Name'Last + 1;\n\n loop\n Ret := Next_Entry\n (FS,\n Current_Cluster => Current_Cluster,\n Current_Block => Current_Block,\n Current_Index => Current_Index,\n DEntry => D_Entry);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Check if we have a VFAT entry here by checking that the\n -- attributes are 16#0F# (e.g. all attributes set except\n -- subdirectory and archive)\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n V_Entry := To_VFAT_Entry (D_Entry);\n\n if V_Entry.VFAT_Attr.Stop_Bit then\n L_Name_First := L_Name'Last + 1;\n\n else\n if Last_Seq = 0\n or else Last_Seq - 1 /= V_Entry.VFAT_Attr.Sequence\n then\n L_Name_First := L_Name'Last + 1;\n end if;\n end if;\n\n Last_Seq := V_Entry.VFAT_Attr.Sequence;\n\n Prepend (V_Entry.Name_3, L_Name, L_Name_First);\n Prepend (V_Entry.Name_2, L_Name, L_Name_First);\n Prepend (V_Entry.Name_1, L_Name, L_Name_First);\n\n if V_Entry.VFAT_Attr.Sequence = 1 then\n CRC := V_Entry.Checksum;\n end if;\n\n -- Ignore Volumes and deleted files\n elsif not D_Entry.Attributes.Volume_Label\n and then Character'Pos (D_Entry.Filename (1)) /= 16#E5#\n then\n if L_Name_First not in L_Name'Range then\n Matches := False;\n else\n Current_CRC := 0;\n Last_Seq := 0;\n\n for Ch of String'(D_Entry.Filename & D_Entry.Extension) loop\n C := Character'Enum_Rep (Ch);\n Current_CRC := Shift_Right (Current_CRC and 16#FE#, 1)\n or Shift_Left (Current_CRC and 16#01#, 7);\n -- Modulo addition\n Current_CRC := Current_CRC + C;\n end loop;\n\n Matches := Current_CRC = CRC;\n end if;\n\n DEntry :=\n (FS => FAT_Filesystem_Access (FS),\n L_Name => <>,\n S_Name => D_Entry.Filename,\n S_Name_Ext => D_Entry.Extension,\n Attributes => D_Entry.Attributes,\n Start_Cluster => (if FS.Version = FAT16\n then Cluster_Type (D_Entry.Cluster_L)\n else Cluster_Type (D_Entry.Cluster_L) or\n Shift_Left\n (Cluster_Type (D_Entry.Cluster_H), 16)),\n Size => D_Entry.Size,\n Index => Current_Index - 1,\n Is_Root => False,\n Is_Dirty => False);\n\n if Matches then\n DEntry.L_Name := -L_Name (L_Name_First .. L_Name'Last);\n else\n DEntry.L_Name.Len := 0;\n end if;\n\n return OK;\n end if;\n end loop;\n end Next_Entry;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (Dir : in out FAT_Directory_Handle;\n DEntry : out FAT_Node) return Status_Code\n is\n begin\n return Next_Entry\n (Dir.FS,\n Current_Cluster => Dir.Current_Cluster,\n Current_Block => Dir.Current_Block,\n Current_Index => Dir.Current_Index,\n DEntry => DEntry);\n end Read;\n\n -------------------\n -- Create_Subdir --\n -------------------\n\n function Create_Subdir\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_Dir : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n Block : Block_Offset;\n Dot : FAT_Directory_Entry;\n Dot_Dot : FAT_Directory_Entry;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n E => New_Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Block := Dir.FS.Cluster_To_Block (New_Dir.Start_Cluster);\n Ret := Handle.FS.Ensure_Block (Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Allocate '.', '..' and the directory entry terminator\n Dot :=\n (Filename => (1 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32\n (New_Dir.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (New_Dir.Start_Cluster and 16#FFFF#),\n Size => 0);\n Dot_Dot :=\n (Filename => (1 .. 2 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32 (Handle.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (Handle.Start_Cluster and 16#FFFF#),\n Size => 0);\n\n Handle.FS.Window (0 .. 31) := To_Data (Dot);\n Handle.FS.Window (32 .. 63) := To_Data (Dot_Dot);\n Handle.FS.Window (64 .. 95) := (others => 0);\n Ret := Handle.FS.Write_Window;\n\n Close (Handle.all);\n\n return Ret;\n end Create_Subdir;\n\n ----------------------\n -- Create_File_Node --\n ----------------------\n\n function Create_File_Node\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_File : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => False,\n Archive => True),\n E => New_File);\n\n Close (Handle.all);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Create_File_Node;\n\n -------------------\n -- Delete_Subdir --\n -------------------\n\n function Delete_Subdir\n (Dir : FAT_Node;\n Recursive : Boolean) return Status_Code\n is\n Parent : FAT_Node;\n Handle : FAT_Directory_Handle_Access;\n Ent : FAT_Node;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Ent) = OK loop\n if -Long_Name (Ent) = \".\" then\n null;\n elsif -Long_Name (Ent) = \"..\" then\n Parent := Ent;\n elsif not Recursive then\n return Non_Empty_Directory;\n else\n if Ent.Attributes.Subdirectory then\n Ret := Delete_Subdir (Ent, True);\n else\n Ret := Delete_Entry (Dir, Ent);\n end if;\n\n if Ret /= OK then\n Close (Handle.all);\n\n return Ret;\n end if;\n end if;\n end loop;\n\n Close (Handle.all);\n\n -- Free the clusters associated to the subdirectory\n Ret := Delete_Entry (Parent, Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Delete_Subdir;\n\n ------------------\n -- Delete_Entry --\n ------------------\n\n function Delete_Entry\n (Dir : FAT_Node;\n Ent : FAT_Node) return Status_Code\n is\n Current : Cluster_Type := Ent.Start_Cluster;\n Handle : FAT_Directory_Handle_Access;\n Next : Cluster_Type;\n Child_Ent : FAT_Node;\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n -- Mark the entry's cluster chain as available\n loop\n Next := Ent.FS.Get_FAT (Current);\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n end loop;\n\n -- Mark the parent's entry as deleted\n Ret := Dir.FAT_Open (Handle);\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Child_Ent) = OK loop\n if Long_Name (Child_Ent) = Long_Name (Ent) then\n Block_Off := Natural\n ((FAT_File_Size (Handle.Current_Index - 1) * 32)\n mod Dir.FS.Block_Size);\n -- Mark the entry as deleted: first basename character set to\n -- 16#E5#\n Handle.FS.Window (Block_Off) := 16#E5#;\n Ret := Handle.FS.Write_Window;\n\n exit;\n end if;\n end loop;\n\n Close (Handle.all);\n\n return Ret;\n end Delete_Entry;\n\n ---------------------\n -- Adjust_Clusters --\n ---------------------\n\n function Adjust_Clusters (Ent : FAT_Node) return Status_Code\n is\n B_Per_Cluster : constant FAT_File_Size :=\n FAT_File_Size (Ent.FS.Blocks_Per_Cluster) *\n Ent.FS.Block_Size;\n Size : FAT_File_Size := Ent.Size;\n Current : Cluster_Type := Ent.Start_Cluster;\n Next : Cluster_Type;\n Ret : Status_Code := OK;\n\n begin\n if Ent.Attributes.Subdirectory then\n -- ??? Do nothing for now\n return OK;\n end if;\n\n loop\n Next := Ent.FS.Get_FAT (Current);\n\n if Size > B_Per_Cluster then\n -- Current cluster is fully used\n Size := Size - B_Per_Cluster;\n elsif Size > 0 or else Current = Ent.Start_Cluster then\n -- Partially used cluster, but the last one\n Size := 0;\n if Next /= LAST_CLUSTER_VALUE then\n Ret := Ent.FS.Set_FAT (Current, LAST_CLUSTER_VALUE);\n end if;\n else\n -- We don't need more clusters\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n end if;\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n Size := Size - B_Per_Cluster;\n end loop;\n\n return Ret;\n end Adjust_Clusters;\n\n -------------------------------\n -- Find_Empty_Entry_Sequence --\n -------------------------------\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index\n is\n Status : Status_Code;\n D_Entry : FAT_Directory_Entry;\n Sequence : Natural := 0;\n Ret : Entry_Index;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Cluster_To_Block (Parent.FS.all, Cluster);\n begin\n Parent.Current_Index := 0;\n loop\n Status := Next_Entry\n (Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Parent.Current_Index,\n DEntry => D_Entry);\n\n if Status /= OK then\n return Null_Index;\n end if;\n\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n if Sequence = 0 then\n -- Parent.Current_Index points to the next unread value.\n -- So the just read entry is at Parent.Current_Index - 1\n Ret := Parent.Current_Index - 1;\n end if;\n\n Sequence := Sequence + 1;\n\n elsif Character'Pos (D_Entry.Filename (1)) = 16#E5# then\n -- A deleted entry has been found\n if Sequence >= Num_Entries then\n return Ret;\n else\n Sequence := 0;\n end if;\n\n else\n Sequence := 0;\n end if;\n end loop;\n end Find_Empty_Entry_Sequence;\n\n --------------------\n -- Allocate_Entry --\n --------------------\n\n function Allocate_Entry\n (Parent : access FAT_Directory_Handle;\n Name : FAT_Name;\n Attributes : FAT_Directory_Entry_Attribute;\n E : out FAT_Node) return Status_Code\n is\n subtype Short_Name is String (1 .. 8);\n subtype Extension is String (1 .. 3);\n\n function Is_Legal_Character (C : Character) return Boolean\n is (C in 'A' .. 'Z'\n or else C in '0' .. '9'\n or else C = '!'\n or else C = '#'\n or else C = '$'\n or else C = '%'\n or else C = '&'\n or else C = '''\n or else C = '('\n or else C = ')'\n or else C = '-'\n or else C = '@'\n or else C = '^'\n or else C = '_'\n or else C = '`'\n or else C = '{'\n or else C = '}'\n or else C = '~');\n\n Block_Off : Natural;\n Status : Status_Code;\n DEntry : FAT_Node;\n SName : Short_Name := (others => ' ');\n SExt : Extension := (others => ' ');\n Index : Entry_Index;\n\n -- Retrieve the number of VFAT entries that are needed, plus one for\n -- the regular FAT entry.\n N_Entries : Natural := Get_Num_VFAT_Entries (Name) + 1;\n Bytes : Entry_Data;\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension);\n -- Translates a long name into short 8.3 name\n -- If the long name is mixed or lower case. then 8.3 will be uppercased\n -- If the long name contains characters not allowed in an 8.3 name, then\n -- the name is stripped of invalid characters such as space and extra\n -- periods. Other unknown characters are changed to underscores.\n -- The stripped name is then truncated, followed by a ~1. Inc_SName\n -- below will increase the digit number in case there's overloaded 8.3\n -- names.\n -- If the long name is longer than 8.3, then ~1 suffix will also be\n -- used.\n\n function To_Upper (C : Character) return Character is\n (if C in 'a' .. 'z'\n then Character'Val\n (Character'Pos (C) + Character'Pos ('A') - Character'Pos ('a'))\n else C);\n\n function Value (S : String) return Natural;\n -- For a positive int represented in S, returns its value\n\n procedure Inc_SName (SName : in out String);\n -- Increment the suffix of the short FAT name\n -- e.g.:\n -- ABCDEFGH => ABCDEF~1\n -- ABC => ABC~1\n -- ABC~9 => ABC~10\n -- ABCDEF~9 => ABCDE~10\n\n procedure To_WString\n (S : FAT_Name;\n Idx : in out Natural;\n WS : in out Wide_String);\n -- Dumps S (Idx .. Idx + WS'Length - 1) into WS and increments Idx\n\n -----------\n -- Value --\n -----------\n\n function Value (S : String) return Natural\n is\n Val : constant String := Trim (S);\n Digit : Natural;\n Ret : Natural := 0;\n begin\n for J in Val'Range loop\n Digit := Character'Pos (Val (J)) - Character'Pos ('0');\n Ret := Ret * 10 + Digit;\n end loop;\n\n return Ret;\n end Value;\n\n -------------------\n -- To_Short_Name --\n -------------------\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension)\n is\n S_Idx : Natural := 0;\n Add_Tilde : Boolean := False;\n Last : Natural := Name.Len;\n\n begin\n -- Copy the file extension\n\n Ext := (others => ' ');\n\n for J in reverse 1 .. Name.Len loop\n if Name.Name (J) = '.' then\n if J = Name.Len then\n -- Take care of names ending with a '.' (e.g. no extension,\n -- the final '.' is part of the basename)\n Last := J;\n Ext := (others => ' ');\n else\n Last := J - 1;\n S_Idx := Ext'First;\n\n for K in J + 1 .. Name.Len loop\n Ext (S_Idx) := To_Upper (Name.Name (K));\n S_Idx := S_Idx + 1;\n -- In case the extension is more than 3 characters, we\n -- keep the first 3 ones.\n exit when S_Idx > Ext'Last;\n end loop;\n end if;\n\n exit;\n end if;\n end loop;\n\n S_Idx := 0;\n SName := (others => ' ');\n\n for J in 1 .. Last loop\n exit when Add_Tilde and then S_Idx >= 6;\n exit when not Add_Tilde and then S_Idx = 8;\n\n if Name.Name (J) in 'a' .. 'z' then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := To_Upper (Name.Name (J));\n\n elsif Is_Legal_Character (Name.Name (J)) then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := Name.Name (J);\n\n elsif Name.Name (J) = '.'\n or else Name.Name (J) = ' '\n then\n -- dots that are not used as extension delimiters are invalid\n -- in FAT short names and ignored in long names to short names\n -- translation\n Add_Tilde := True;\n\n else\n -- Any other character is translated as '_'\n Add_Tilde := True;\n S_Idx := S_Idx + 1;\n SName (S_Idx) := '_';\n end if;\n end loop;\n\n if Add_Tilde then\n if S_Idx >= 6 then\n SName (7 .. 8) := \"~1\";\n else\n SName (S_Idx + 1 .. S_Idx + 2) := \"~1\";\n end if;\n end if;\n end To_Short_Name;\n\n ---------------\n -- Inc_SName --\n ---------------\n\n procedure Inc_SName (SName : in out String)\n is\n Idx : Natural := 0;\n Num : Natural := 0;\n\n begin\n for J in reverse SName'Range loop\n if Idx = 0 then\n if SName (J) = ' ' then\n null;\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n else\n SName (SName'Last - 1 .. SName'Last) := \"~1\";\n\n return;\n end if;\n\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n\n elsif SName (J) = '~' then\n Num := Value (SName (Idx .. SName'Last)) + 1;\n -- make Idx point to '~'\n Idx := J;\n\n declare\n N_Suffix : String := Natural'Image (Num);\n begin\n N_Suffix (N_Suffix'First) := '~';\n\n if Idx + N_Suffix'Length - 1 > SName'Last then\n SName (SName'Last - N_Suffix'Length + 1 .. SName'Last) :=\n N_Suffix;\n else\n SName (Idx .. Idx + N_Suffix'Length - 1) := N_Suffix;\n end if;\n\n return;" + }, + { + "function_def": "function To_Disk_Parameter is new Ada.Unchecked_Conversion", + "function_body": "(Disk_Parameter_Block, FAT_Disk_Parameter);\n\n subtype FSInfo_Block is Block (0 .. 11);\n function To_FSInfo is new Ada.Unchecked_Conversion\n (FSInfo_Block, FAT_FS_Info);\n\n begin\n FS.Window_Block := 16#FFFF_FFFF#;\n Status := FS.Ensure_Block (0);\n\n if Status /= OK then\n return;\n end if;\n\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.Disk_Parameters :=\n To_Disk_Parameter (FS.Window (0 .. 91));\n\n if FS.Version = FAT32 then\n Status :=\n FS.Ensure_Block (Block_Offset (FS.FSInfo_Block_Number));\n\n if Status /= OK then\n return;\n end if;\n\n -- Check the generic FAT block signature\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.FSInfo :=\n To_FSInfo (FS.Window (16#1E4# .. 16#1EF#));\n FS.FSInfo_Changed := False;\n end if;\n\n declare\n FAT_Size_In_Block : constant Unsigned_32 :=\n FS.FAT_Table_Size_In_Blocks *\n Unsigned_32 (FS.Number_Of_FATs);\n Root_Dir_Size : Block_Offset;\n begin\n FS.FAT_Addr := Block_Offset (FS.Reserved_Blocks);\n FS.Data_Area := FS.FAT_Addr + Block_Offset (FAT_Size_In_Block);\n\n if FS.Version = FAT16 then\n -- Add space for the root directory\n FS.Root_Dir_Area := FS.Data_Area;\n Root_Dir_Size :=\n (Block_Offset (FS.FAT16_Root_Dir_Num_Entries) * 32 +\n Block_Offset (FS.Block_Size) - 1) /\n Block_Offset (FS.Block_Size);\n -- Align on clusters\n Root_Dir_Size :=\n ((Root_Dir_Size + FS.Blocks_Per_Cluster - 1) /\n FS.Blocks_Per_Cluster) *\n FS.Blocks_Per_Cluster;\n\n FS.Data_Area := FS.Data_Area + Root_Dir_Size;\n end if;\n\n FS.Num_Clusters :=\n Cluster_Type\n ((FS.Total_Number_Of_Blocks - Unsigned_32 (FS.Data_Area)) /\n Unsigned_32 (FS.Blocks_Per_Cluster));" + }, + { + "function_def": "procedure List (Path : String);", + "function_body": "----------\n -- List --\n ----------\n\n procedure List (Path : String) is\n DD : Directory_Descriptor;\n Status : Status_Code;\n First : Boolean := True;\n begin\n Status := Open (DD, Path);\n if Status /= OK then\n Put (\"Cannot open directory '\" & Path & \"': \" & Status'Img);\n return;\n end if;\n\n if Recursive then\n Put_Line (Path & \":\");\n end if;\n\n loop\n declare\n Ent : constant Directory_Entry := Read (DD);\n begin\n exit when Ent = Invalid_Dir_Entry;\n\n if not Ent.Hidden or else Show_All then\n if First then\n Put (Ent.Name);\n First := False;\n else\n Put (\" \" & Ent.Name);\n end if;\n end if;" + }, + { + "function_def": "procedure Display_File (Path : String);", + "function_body": "------------------\n -- Display_File --\n ------------------\n\n procedure Display_File (Path : String) is\n FD : File_Descriptor;\n Status : Status_Code;\n Data : String (1 .. 512);\n Amount : File_Size;\n begin\n Status := Open (FD, Path, Read_Only);\n if Status /= OK then\n Put_Line (\"Cannot open file '\" & Path & \"': \" & Status'Img);\n return;\n end if;\n\n loop\n Amount := Read (FD, Data'Address, Data'Length);\n exit when Amount = 0;\n Put (Data (Data'First .. Data'First + Natural (Amount) - 1));\n end loop;\n Close (FD);\n end Display_File;\n\n begin\n loop\n declare\n Arg : constant String := Args.Next;\n begin\n if Arg'Length = 0 then\n return;\n end if;\n Display_File (Arg);" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out SPI_Port'Class) is\n begin\n if This'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2ENR.SAI1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address /= SAI_Base then\n raise Unknown_Device;\n end if;\n\n Input_Selector := RCC_Periph.DCKCFGR.SAI1ASRC;\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLIS2DIVQ + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDIOEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDIORST := True;\n RCC_Periph.APB2RSTR.SDIORST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDIO_Clock_Source)\n is\n Src_Val : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DCKCFGR.SDMMCSEL := Src_Val;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2ENR.SDMMC2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2RSTR.SDMMC2RST := True;\n RCC_Periph.APB2RSTR.SDMMC2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n Sel_Value : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.DKCFGR2.SDMMC1SEL := Sel_Value;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.DKCFGR2.SDMMC2SEL := Sel_Value;\n else\n raise Unknown_Device;\n end if;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant\n UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant\n UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DKCFGR2.SDMMCSEL := Src = Src_Sysclk;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Disable", + "function_body": "(This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.EN1 := False;\n when Channel_2 =>\n This.CR.EN2 := False;\n end case;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.EN1;\n when Channel_2 =>\n return This.CR.EN2;\n end case;\n end Enabled;\n\n ----------------\n -- Set_Output --\n ----------------\n\n procedure Set_Output\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Channel is\n\n when Channel_1 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R1.DACC1DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n when Channel_2 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R2.DACC2DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n end case;\n end Set_Output;\n\n ------------------------------------\n -- Trigger_Conversion_By_Software --\n ------------------------------------\n\n procedure Trigger_Conversion_By_Software\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SWTRIGR.SWTRIG.Arr (1) := True; -- cleared by hardware\n when Channel_2 =>\n This.SWTRIGR.SWTRIG.Arr (2) := True; -- cleared by hardware\n end case;\n end Trigger_Conversion_By_Software;\n\n ----------------------------\n -- Converted_Output_Value --\n ----------------------------\n\n function Converted_Output_Value\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return UInt32\n is\n begin\n case Channel is\n when Channel_1 =>\n return UInt32 (This.DOR1.DACC1DOR);\n when Channel_2 =>\n return UInt32 (This.DOR2.DACC2DOR);\n end case;\n end Converted_Output_Value;\n\n ------------------------------\n -- Set_Dual_Output_Voltages --\n ------------------------------\n\n procedure Set_Dual_Output_Voltages\n (This : in out Digital_To_Analog_Converter;\n Channel_1_Value : UInt32;\n Channel_2_Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12LD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12LD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12RD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12RD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8RD.DACC1DHR :=\n UInt8 (Channel_1_Value and Max_8bit_Resolution);\n This.DHR8RD.DACC2DHR :=\n UInt8 (Channel_2_Value and Max_8bit_Resolution);\n end case;\n end Set_Dual_Output_Voltages;\n\n ---------------------------------\n -- Converted_Dual_Output_Value --\n ---------------------------------\n\n function Converted_Dual_Output_Value (This : Digital_To_Analog_Converter)\n return Dual_Channel_Output\n is\n Result : Dual_Channel_Output;\n begin\n Result.Channel_1_Data := UInt16 (This.DOR1.DACC1DOR);\n Result.Channel_2_Data := UInt16 (This.DOR2.DACC2DOR);\n return Result;\n end Converted_Dual_Output_Value;\n\n --------------------------\n -- Enable_Output_Buffer --\n --------------------------\n\n procedure Enable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := True;\n when Channel_2 =>\n This.CR.BOFF2 := True;\n end case;\n end Enable_Output_Buffer;\n\n ---------------------------\n -- Disable_Output_Buffer --\n ---------------------------\n\n procedure Disable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := False;\n when Channel_2 =>\n This.CR.BOFF2 := False;\n end case;\n end Disable_Output_Buffer;\n\n ---------------------------\n -- Output_Buffer_Enabled --\n ---------------------------\n\n function Output_Buffer_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.BOFF1;\n when Channel_2 =>\n return This.CR.BOFF2;\n end case;\n end Output_Buffer_Enabled;\n\n --------------------\n -- Select_Trigger --\n --------------------\n\n procedure Select_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Trigger : External_Event_Trigger_Selection)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TSEL1 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n when Channel_2 =>\n This.CR.TSEL2 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n end case;\n end Select_Trigger;\n\n -----------------------\n -- Trigger_Selection --\n -----------------------\n\n function Trigger_Selection\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return External_Event_Trigger_Selection\n is\n begin\n case Channel is\n when Channel_1 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL1);\n when Channel_2 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL2);\n end case;\n end Trigger_Selection;\n\n --------------------\n -- Enable_Trigger --\n --------------------\n\n procedure Enable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := True;\n when Channel_2 =>\n This.CR.TEN2 := True;\n end case;\n end Enable_Trigger;\n\n ---------------------\n -- Disable_Trigger --\n ---------------------\n\n procedure Disable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := False;\n when Channel_2 =>\n This.CR.TEN2 := False;\n end case;\n end Disable_Trigger;\n\n ---------------------\n -- Trigger_Enabled --\n ---------------------\n\n function Trigger_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.TEN1;\n when Channel_2 =>\n return This.CR.TEN2;\n end case;\n end Trigger_Enabled;\n\n ----------------\n -- Enable_DMA --\n ----------------\n\n procedure Enable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := True;\n when Channel_2 =>\n This.CR.DMAEN2 := True;\n end case;\n end Enable_DMA;\n\n -----------------\n -- Disable_DMA --\n -----------------\n\n procedure Disable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := False;\n when Channel_2 =>\n This.CR.DMAEN2 := False;\n end case;\n end Disable_DMA;\n\n -----------------\n -- DMA_Enabled --\n -----------------\n\n function DMA_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.DMAEN1;\n when Channel_2 =>\n return This.CR.DMAEN2;\n end case;\n end DMA_Enabled;\n\n ------------\n -- Status --\n ------------\n\n function Status\n (This : Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n return Boolean\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n return This.SR.DMAUDR1;\n when DMA_Underrun_Channel_2 =>\n return This.SR.DMAUDR2;\n end case;\n end Status;\n\n ------------------\n -- Clear_Status --\n ------------------\n\n procedure Clear_Status\n (This : in out Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n This.SR.DMAUDR1 := True; -- set to 1 to clear\n when DMA_Underrun_Channel_2 =>\n This.SR.DMAUDR2 := True; -- set to 1 to clear\n end case;\n end Clear_Status;\n\n -----------------------\n -- Enable_Interrupts --\n -----------------------\n\n procedure Enable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := True;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := True;\n end case;\n end Enable_Interrupts;\n\n ------------------------\n -- Disable_Interrupts --\n ------------------------\n\n procedure Disable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := False;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := False;\n end case;\n end Disable_Interrupts;\n\n -----------------------\n -- Interrupt_Enabled --\n -----------------------\n\n function Interrupt_Enabled\n (This : Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n return Boolean\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n return This.CR.DMAUDRIE1;\n when DMA_Underrun_Channel_2 =>\n return This.CR.DMAUDRIE2;\n end case;\n end Interrupt_Enabled;\n\n ----------------------\n -- Interrupt_Source --\n ----------------------\n\n function Interrupt_Source\n (This : Digital_To_Analog_Converter)\n return DAC_Interrupts\n is\n begin\n if This.CR.DMAUDRIE1 then\n return DMA_Underrun_Channel_1;\n else\n return DMA_Underrun_Channel_2;\n end if;\n end Interrupt_Source;\n\n -----------------------------\n -- Clear_Interrupt_Pending --\n -----------------------------\n\n procedure Clear_Interrupt_Pending\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SR.DMAUDR1 := False;\n when Channel_2 =>\n This.SR.DMAUDR2 := False;\n end case;\n end Clear_Interrupt_Pending;\n\n ----------------------------\n -- Select_Wave_Generation --\n ----------------------------\n\n procedure Select_Wave_Generation\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Selection : Wave_Generation)\n is\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Noise_Wave_Mask_Selection, Target => UInt4);\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Triangle_Wave_Amplitude_Selection, Target => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n This.CR.WAVE1 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n when Channel_2 =>\n This.CR.WAVE2 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n end case;\n\n case Selection.Kind is\n\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Mask);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Mask);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Amplitude);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Amplitude);\n end case;\n\n end case;\n end Select_Wave_Generation;\n\n ------------------------------\n -- Selected_Wave_Generation --\n ------------------------------\n\n function Selected_Wave_Generation\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Wave_Generation\n is\n Kind : Wave_Generation_Selection;\n\n function As_Mask is new Ada.Unchecked_Conversion\n (Target => Noise_Wave_Mask_Selection, Source => UInt4);\n\n function As_Amplitude is new Ada.Unchecked_Conversion\n (Target => Triangle_Wave_Amplitude_Selection, Source => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE1);\n when Channel_2 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE2);\n end case;\n declare\n Result : Wave_Generation (Kind);\n begin\n case Kind is\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Mask := As_Mask (This.CR.MAMP1);\n when Channel_2 =>\n Result.Mask := As_Mask (This.CR.MAMP2);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP1);\n when Channel_2 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP2);\n end case;\n end case;\n\n return Result;" + }, + { + "function_def": "procedure Disable (This : in out Analog_To_Digital_Converter) is", + "function_body": "begin\n This.CR2.ADON := False;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled (This : Analog_To_Digital_Converter) return Boolean is\n (This.CR2.ADON);\n\n ----------------------\n -- Conversion_Value --\n ----------------------\n\n function Conversion_Value\n (This : Analog_To_Digital_Converter)\n return UInt16\n is\n begin\n return This.DR.DATA;\n end Conversion_Value;\n\n ---------------------------\n -- Data_Register_Address --\n ---------------------------\n\n function Data_Register_Address\n (This : Analog_To_Digital_Converter)\n return System.Address\n is\n (This.DR'Address);\n\n -------------------------------\n -- Injected_Conversion_Value --\n -------------------------------\n\n function Injected_Conversion_Value\n (This : Analog_To_Digital_Converter;\n Rank : Injected_Channel_Rank)\n return UInt16\n is\n begin\n case Rank is\n when 1 =>\n return This.JDR1.JDATA;\n when 2 =>\n return This.JDR2.JDATA;\n when 3 =>\n return This.JDR3.JDATA;\n when 4 =>\n return This.JDR4.JDATA;\n end case;\n end Injected_Conversion_Value;\n\n --------------------------------\n -- Multimode_Conversion_Value --\n --------------------------------\n\n function Multimode_Conversion_Value return UInt32 is\n (C_ADC_Periph.CDR.Val);\n\n --------------------\n -- Configure_Unit --\n --------------------\n\n procedure Configure_Unit\n (This : in out Analog_To_Digital_Converter;\n Resolution : ADC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n This.CR1.RES := ADC_Resolution'Enum_Rep (Resolution);\n This.CR2.ALIGN := Alignment = Left_Aligned;\n end Configure_Unit;\n\n ------------------------\n -- Current_Resolution --\n ------------------------\n\n function Current_Resolution\n (This : Analog_To_Digital_Converter)\n return ADC_Resolution\n is (ADC_Resolution'Val (This.CR1.RES));\n\n -----------------------\n -- Current_Alignment --\n -----------------------\n\n function Current_Alignment\n (This : Analog_To_Digital_Converter)\n return Data_Alignment\n is ((if This.CR2.ALIGN then Left_Aligned else Right_Aligned));\n\n ---------------------------------\n -- Configure_Common_Properties --\n ---------------------------------\n\n procedure Configure_Common_Properties\n (Mode : Multi_ADC_Mode_Selections;\n Prescalar : ADC_Prescalars;\n DMA_Mode : Multi_ADC_DMA_Modes;\n Sampling_Delay : Sampling_Delay_Selections)\n is\n begin\n C_ADC_Periph.CCR.MULT := Multi_ADC_Mode_Selections'Enum_Rep (Mode);\n C_ADC_Periph.CCR.DELAY_k :=\n Sampling_Delay_Selections'Enum_Rep (Sampling_Delay);\n C_ADC_Periph.CCR.DMA := Multi_ADC_DMA_Modes'Enum_Rep (DMA_Mode);\n C_ADC_Periph.CCR.ADCPRE := ADC_Prescalars'Enum_Rep (Prescalar);\n end Configure_Common_Properties;\n\n -----------------------------------\n -- Configure_Regular_Conversions --\n -----------------------------------\n\n procedure Configure_Regular_Conversions\n (This : in out Analog_To_Digital_Converter;\n Continuous : Boolean;\n Trigger : Regular_Channel_Conversion_Trigger;\n Enable_EOC : Boolean;\n Conversions : Regular_Channel_Conversions)\n is\n begin\n This.CR2.EOCS := Enable_EOC;\n This.CR2.CONT := Continuous;\n\n This.CR1.SCAN := Conversions'Length > 1;\n\n if Trigger.Enabler /= Trigger_Disabled then\n This.CR2.EXTSEL := External_Events_Regular_Group'Enum_Rep (Trigger.Event);\n This.CR2.EXTEN := External_Trigger'Enum_Rep (Trigger.Enabler);\n else\n This.CR2.EXTSEL := 0;\n This.CR2.EXTEN := 0;\n end if;\n\n for Rank in Conversions'Range loop\n declare\n Conversion : Regular_Channel_Conversion renames Conversions (Rank);\n begin\n Configure_Regular_Channel\n (This, Conversion.Channel, Rank, Conversion.Sample_Time);\n\n -- We check the VBat first because that channel is also used for\n -- the temperature sensor channel on some MCUs, in which case the\n -- VBat conversion is the only one done. This order reflects that\n -- hardware behavior.\n if VBat_Conversion (This, Conversion.Channel) then\n Enable_VBat_Connection;\n elsif VRef_TemperatureSensor_Conversion (This, Conversion.Channel)\n then\n Enable_VRef_TemperatureSensor_Connection;\n end if;" + }, + { + "function_def": "procedure Disable_Interrupt", + "function_body": "(This : in out SDMMC_Controller;\n Interrupt : SDMMC_Interrupts)\n is\n begin\n case Interrupt is\n when Data_End_Interrupt =>\n This.Periph.MASK.DATAENDIE := False;\n when Data_CRC_Fail_Interrupt =>\n This.Periph.MASK.DCRCFAILIE := False;\n when Data_Timeout_Interrupt =>\n This.Periph.MASK.DTIMEOUTIE := False;\n when TX_FIFO_Empty_Interrupt =>\n This.Periph.MASK.TXFIFOEIE := False;\n when RX_FIFO_Full_Interrupt =>\n This.Periph.MASK.RXFIFOFIE := False;\n when TX_Underrun_Interrupt =>\n This.Periph.MASK.TXUNDERRIE := False;\n when RX_Overrun_Interrupt =>\n This.Periph.MASK.RXOVERRIE := False;\n end case;\n end Disable_Interrupt;\n\n ------------------------\n -- Delay_Milliseconds --\n ------------------------\n\n overriding procedure Delay_Milliseconds\n (This : SDMMC_Controller;\n Amount : Natural)\n is\n pragma Unreferenced (This);\n begin\n delay until Clock + Milliseconds (Amount);\n end Delay_Milliseconds;\n\n -----------\n -- Reset --\n -----------\n\n overriding procedure Reset\n (This : in out SDMMC_Controller;\n Status : out SD_Error)\n is\n begin\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n This.Periph.POWER.PWRCTRL := Power_Off;\n\n -- Use the Default SDMMC peripheral configuration for SD card init\n This.Periph.CLKCR := (others => <>);\n This.Set_Clock (400_000);\n This.Periph.DTIMER := SD_DATATIMEOUT;\n\n This.Periph.CLKCR.CLKEN := False;\n DCTRL_Write_Delay;\n This.Periph.POWER.PWRCTRL := Power_On;\n\n -- Wait for the clock to stabilize.\n DCTRL_Write_Delay;\n\n This.Periph.CLKCR.CLKEN := True;\n\n delay until Clock + Milliseconds (20);\n\n Status := OK;\n end Reset;\n\n ---------------\n -- Set_Clock --\n ---------------\n\n overriding procedure Set_Clock\n (This : in out SDMMC_Controller;\n Freq : Natural)\n is\n Div : UInt32;\n CLKCR : CLKCR_Register;\n begin\n Div := (This.CLK_In + UInt32 (Freq) - 1) / UInt32 (Freq);\n\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n if Div <= 1 then\n This.Periph.CLKCR.BYPASS := True;\n else\n Div := Div - 2;\n CLKCR := This.Periph.CLKCR;\n CLKCR.BYPASS := False;\n\n if Div > UInt32 (CLKCR_CLKDIV_Field'Last) then\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field'Last;\n else\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field (Div);\n end if;\n\n This.Periph.CLKCR := CLKCR;\n end if;\n end Set_Clock;\n\n ------------------\n -- Set_Bus_Size --\n ------------------\n\n overriding procedure Set_Bus_Size\n (This : in out SDMMC_Controller;\n Mode : Wide_Bus_Mode)\n is\n function To_WIDBUS_Field is new Ada.Unchecked_Conversion\n (Wide_Bus_Mode, CLKCR_WIDBUS_Field);\n begin\n This.Periph.CLKCR.WIDBUS := To_WIDBUS_Field (Mode);\n end Set_Bus_Size;\n\n ------------------\n -- Send_Command --\n ------------------\n\n overriding procedure Send_Cmd\n (This : in out SDMMC_Controller;\n Cmd : Cmd_Desc_Type;\n Arg : UInt32;\n Status : out SD_Error)\n is\n CMD_Reg : CMD_Register := This.Periph.CMD;\n begin\n if Cmd.Rsp = Rsp_Invalid or else Cmd.Tfr = Tfr_Invalid then\n raise Program_Error with \"Not implemented\";\n end if;\n\n This.Periph.ARG := Arg;\n CMD_Reg.CMDINDEX := CMD_CMDINDEX_Field (Cmd.Cmd);\n CMD_Reg.WAITRESP := (case Cmd.Rsp is\n when Rsp_No => No_Response,\n when Rsp_R2 => Long_Response,\n when others => Short_Response);\n CMD_Reg.WAITINT := False;\n CMD_Reg.CPSMEN := True;\n This.Periph.CMD := CMD_Reg;\n\n case Cmd.Rsp is\n when Rsp_No =>\n Status := This.Command_Error;\n\n when Rsp_R1 | Rsp_R1B =>\n Status := This.Response_R1_Error (Cmd.Cmd);\n\n when Rsp_R2 =>\n Status := This.Response_R2_Error;\n\n when Rsp_R3 =>\n Status := This.Response_R3_Error;\n\n when Rsp_R6 =>\n declare\n RCA : UInt32;\n begin\n Status := This.Response_R6_Error (Cmd.Cmd, RCA);\n This.RCA := UInt16 (Shift_Right (RCA, 16));" + }, + { + "function_def": "procedure Disable_Data", + "function_body": "(This : in out SDMMC_Controller)\n is\n begin\n This.Periph.DCTRL := (others => <>);\n end Disable_Data;\n\n --------------------------\n -- Enable_DMA_Transfers --\n --------------------------\n\n procedure Enable_DMA_Transfers\n (This : in out SDMMC_Controller;\n RX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n TX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n SD_Int : not null STM32.SDMMC_Interrupt.SDMMC_Interrupt_Handler_Access)\n is\n begin\n This.TX_DMA_Int := TX_Int;\n This.RX_DMA_Int := RX_Int;\n This.SD_Int := SD_Int;\n end Enable_DMA_Transfers;\n\n --------------------------\n -- Has_Card_Information --\n --------------------------\n\n function Has_Card_Information\n (This : SDMMC_Controller)\n return Boolean\n is (This.Has_Info);\n\n ----------------------\n -- Card_Information --\n ----------------------\n\n function Card_Information\n (This : SDMMC_Controller)\n return HAL.SDMMC.Card_Information\n is\n begin\n return This.Info;\n end Card_Information;\n\n ----------------------------\n -- Clear_Card_Information --\n ----------------------------\n\n procedure Clear_Card_Information\n (This : in out SDMMC_Controller)\n is\n begin\n This.Has_Info := False;\n end Clear_Card_Information;\n\n ---------------\n -- Read_FIFO --\n ---------------\n\n function Read_FIFO\n (Controller : in out SDMMC_Controller) return UInt32\n is\n begin\n return Controller.Periph.FIFO;\n end Read_FIFO;\n\n -------------------\n -- Command_Error --\n -------------------\n\n function Command_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n begin\n while not Controller.Periph.STA.CMDSENT loop\n if Clock - Start > Milliseconds (1000) then\n return Timeout_Error;\n end if;\n end loop;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Command_Error;\n\n -----------------------\n -- Response_R1_Error --\n -----------------------\n\n function Response_R1_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n R1 : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n R1 := Controller.Periph.RESP1;\n\n if (R1 and SD_OCR_ERRORMASK) = 0 then\n return OK;\n end if;\n\n if (R1 and SD_OCR_ADDR_OUT_OF_RANGE) /= 0 then\n return Address_Out_Of_Range;\n elsif (R1 and SD_OCR_ADDR_MISALIGNED) /= 0 then\n return Address_Missaligned;\n elsif (R1 and SD_OCR_BLOCK_LEN_ERR) /= 0 then\n return Block_Length_Error;\n elsif (R1 and SD_OCR_ERASE_SEQ_ERR) /= 0 then\n return Erase_Seq_Error;\n elsif (R1 and SD_OCR_BAD_ERASE_PARAM) /= 0 then\n return Bad_Erase_Parameter;\n elsif (R1 and SD_OCR_WRITE_PROT_VIOLATION) /= 0 then\n return Write_Protection_Violation;\n elsif (R1 and SD_OCR_LOCK_UNLOCK_FAILED) /= 0 then\n return Lock_Unlock_Failed;\n elsif (R1 and SD_OCR_COM_CRC_FAILED) /= 0 then\n return CRC_Check_Fail;\n elsif (R1 and SD_OCR_ILLEGAL_CMD) /= 0 then\n return Illegal_Cmd;\n elsif (R1 and SD_OCR_CARD_ECC_FAILED) /= 0 then\n return Card_ECC_Failed;\n elsif (R1 and SD_OCR_CC_ERROR) /= 0 then\n return CC_Error;\n elsif (R1 and SD_OCR_GENERAL_UNKNOWN_ERROR) /= 0 then\n return General_Unknown_Error;\n elsif (R1 and SD_OCR_STREAM_READ_UNDERRUN) /= 0 then\n return Stream_Read_Underrun;\n elsif (R1 and SD_OCR_STREAM_WRITE_UNDERRUN) /= 0 then\n return Stream_Write_Underrun;\n elsif (R1 and SD_OCR_CID_CSD_OVERWRITE) /= 0 then\n return CID_CSD_Overwrite;\n elsif (R1 and SD_OCR_WP_ERASE_SKIP) /= 0 then\n return WP_Erase_Skip;\n elsif (R1 and SD_OCR_CARD_ECC_DISABLED) /= 0 then\n return Card_ECC_Disabled;\n elsif (R1 and SD_OCR_ERASE_RESET) /= 0 then\n return Erase_Reset;\n elsif (R1 and SD_OCR_AKE_SEQ_ERROR) /= 0 then\n return AKE_SEQ_Error;\n else\n return General_Unknown_Error;\n end if;\n end Response_R1_Error;\n\n -----------------------\n -- Response_R2_Error --\n -----------------------\n\n function Response_R2_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R2_Error;\n\n -----------------------\n -- Response_R3_Error --\n -----------------------\n\n function Response_R3_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R3_Error;\n\n -----------------------\n -- Response_R6_Error --\n -----------------------\n\n function Response_R6_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command;\n RCA : out UInt32) return SD_Error\n is\n Response : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n Response := Controller.Periph.RESP1;\n\n if (Response and SD_R6_Illegal_Cmd) = SD_R6_Illegal_Cmd then\n return Illegal_Cmd;\n\n elsif (Response and SD_R6_General_Unknown_Error) =\n SD_R6_General_Unknown_Error\n then\n return General_Unknown_Error;\n\n elsif (Response and SD_R6_Com_CRC_Failed) = SD_R6_Com_CRC_Failed then\n return CRC_Check_Fail;\n end if;\n\n RCA := Response and 16#FFFF_0000#;\n\n return OK;\n end Response_R6_Error;\n\n -----------------------\n -- Response_R7_Error --\n -----------------------\n\n function Response_R7_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n\n elsif Controller.Periph.STA.CMDREND then\n Controller.Periph.ICR.CMDRENDC := True;\n\n return OK;\n\n else\n return Error;\n end if;\n end Response_R7_Error;\n\n -------------------\n -- Stop_Transfer --\n -------------------\n\n function Stop_Transfer\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n Send_Cmd (This, Cmd_Desc (Stop_Transmission), 0, Ret);\n\n return Ret;\n end Stop_Transfer;\n\n -----------------------\n -- Set_Clk_Src_Speed --\n -----------------------\n\n procedure Set_Clk_Src_Speed\n (This : in out SDMMC_Controller;\n CLK : UInt32)\n is\n begin\n This.CLK_In := CLK;\n end Set_Clk_Src_Speed;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n SDMMC_Init.Card_Identification_Process (This, This.Info, Ret);\n This.Card_Type := This.Info.Card_Type;\n This.RCA := This.Info.RCA;\n\n return Ret;\n end Initialize;\n\n ----------\n -- Read --\n ----------\n\n overriding\n function Read\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : out HAL.Block_Drivers.Block) return Boolean\n is\n Ret : Boolean;\n SD_Err : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n\n Ensure_Card_Informations (This);\n\n if This.RX_DMA_Int = null or else This.SD_Int = null then\n SD_Err := Read_Blocks\n (This,\n Block_Number * 512,\n Data);\n return SD_Err = OK;\n end if;\n\n This.SD_Int.Set_Transfer_State (This);\n\n SD_Err := Read_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.RX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.SD_Int.Wait_Transfer (SD_Err);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n else\n This.RX_DMA_Int.Wait_For_Completion (DMA_Err);\n\n loop\n exit when not Get_Flag (This, RX_Active);\n end loop;\n end if;\n\n Ret := SD_Err = OK and then DMA_Err = DMA_No_Error;\n\n if Last_Operation (This) =\n Read_Multiple_Blocks_Operation\n then\n SD_Err := Stop_Transfer (This);\n Ret := Ret and then SD_Err = OK;\n end if;\n\n Clear_All_Status (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable_Data (This);\n Clear_Static_Flags (This);\n\n Cortex_M.Cache.Invalidate_DCache\n (Start => Data'Address,\n Len => Data'Length);\n\n return Ret;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n overriding\n function Write\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : HAL.Block_Drivers.Block) return Boolean\n is\n Ret : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n if This.TX_DMA_Int = null then\n raise Program_Error with \"No TX DMA controller\";\n end if;\n\n if This.SD_Int = null then\n raise Program_Error with \"No SD interrupt controller\";\n end if;\n\n Ensure_Card_Informations (This);\n\n -- Flush the data cache\n Cortex_M.Cache.Clean_DCache\n (Start => Data (Data'First)'Address,\n Len => Data'Length);\n\n This.SD_Int.Set_Transfer_State (This);\n\n Ret := Write_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n -- this always leaves the last 12 byte standing. Why?\n -- also...NDTR is not what it should be.\n\n if Ret /= OK then\n This.TX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.TX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.TX_DMA_Int.Wait_For_Completion (DMA_Err); -- this unblocks\n This.SD_Int.Wait_Transfer (Ret); -- TX underrun!\n\n -- this seems slow. Do we have to wait?\n loop\n -- FIXME: some people claim, that this goes wrong with multiblock, see\n -- http://blog.frankvh.com/2011/09/04/stm32f2xx-sdio-sd-card-interface/\n exit when not Get_Flag (This, TX_Active);\n end loop;\n\n if Last_Operation (This) =\n Write_Multiple_Blocks_Operation\n then\n Ret := Stop_Transfer (This);\n end if;\n\n Clear_All_Status (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n Disable (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n\n declare\n Data_Incomplete : constant Boolean :=\n This.TX_DMA_Int.Buffer_Error and then\n Items_Transferred (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream)\n /= Data'Length / 4;\n begin\n return Ret = OK\n and then DMA_Err = DMA_No_Error\n and then not Data_Incomplete;" + }, + { + "function_def": "function To_Word is new Ada.Unchecked_Conversion (System.Address, UInt32);", + "function_body": "function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32 with Inline_Always;\n\n DMA2D_Init_Transfer_Int : DMA2D_Sync_Procedure := null;\n DMA2D_Wait_Transfer_Int : DMA2D_Sync_Procedure := null;\n\n ------------------\n -- DMA2D_DeInit --\n ------------------\n\n procedure DMA2D_DeInit is\n begin\n RCC_Periph.AHB1ENR.DMA2DEN := False;\n DMA2D_Init_Transfer_Int := null;\n DMA2D_Wait_Transfer_Int := null;\n end DMA2D_DeInit;\n\n ----------------\n -- DMA2D_Init --\n ----------------\n\n procedure DMA2D_Init\n (Init : DMA2D_Sync_Procedure;\n Wait : DMA2D_Sync_Procedure)\n is\n begin\n if DMA2D_Init_Transfer_Int = Init then\n return;\n end if;\n\n DMA2D_DeInit;\n\n DMA2D_Init_Transfer_Int := Init;\n DMA2D_Wait_Transfer_Int := Wait;\n\n RCC_Periph.AHB1ENR.DMA2DEN := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := False;\n end DMA2D_Init;\n\n ------------\n -- Offset --\n ------------\n\n function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32\n is\n Off : constant UInt32 := UInt32 (X + Buffer.Width * Y);\n begin\n case Buffer.Color_Mode is\n when ARGB8888 =>\n return 4 * Off;\n when RGB888 =>\n return 3 * Off;\n when ARGB1555 | ARGB4444 | RGB565 | AL88 =>\n return 2 * Off;\n when L8 | AL44 | A8 =>\n return Off;\n when L4 | A4 =>\n return Off / 2;\n end case;\n end Offset;\n\n ----------------\n -- DMA2D_Fill --\n ----------------\n\n procedure DMA2D_Fill\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR.CM := As_UInt3 (Buffer.Color_Mode);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr);\n DMA2D_Periph.OOR := (LO => 0, others => <>);\n DMA2D_Periph.NLR := (NL => UInt16 (Buffer.Height),\n PL => UInt14 (Buffer.Width),\n others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill;\n\n ---------------------\n -- DMA2D_Fill_Rect --\n ---------------------\n\n procedure DMA2D_Fill_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n Off : constant UInt32 := Offset (Buffer, X, Y);\n\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode),\n others => <>);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;\n DMA2D_Periph.OOR.LO := UInt14 (Buffer.Width - Width);\n DMA2D_Periph.NLR :=\n (NL => UInt16 (Height), PL => UInt14 (Width), others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill_Rect;\n\n ---------------------\n -- DMA2D_Draw_Rect --\n ---------------------\n\n procedure DMA2D_Draw_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer)\n is\n begin\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y, Width);\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y + Height - 1, Width);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X, Y, Height);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X + Width - 1, Y, Height, True);\n end DMA2D_Draw_Rect;\n\n ---------------------\n -- DMA2D_Copy_Rect --\n ---------------------\n\n procedure DMA2D_Copy_Rect\n (Src_Buffer : DMA2D_Buffer;\n X_Src : Natural;\n Y_Src : Natural;\n Dst_Buffer : DMA2D_Buffer;\n X_Dst : Natural;\n Y_Dst : Natural;\n Bg_Buffer : DMA2D_Buffer;\n X_Bg : Natural;\n Y_Bg : Natural;\n Width : Natural;\n Height : Natural;\n Synchronous : Boolean := False)\n is\n Src_Off : constant UInt32 := Offset (Src_Buffer, X_Src, Y_Src);\n Dst_Off : constant UInt32 := Offset (Dst_Buffer, X_Dst, Y_Dst);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n if Bg_Buffer /= Null_Buffer then\n -- PFC and blending\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_BLEND);\n\n elsif Src_Buffer.Color_Mode = Dst_Buffer.Color_Mode then\n -- Direct memory transfer\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M);\n else\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_PFC);\n end if;\n\n -- SOURCE CONFIGURATION\n DMA2D_Periph.FGPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Src_Buffer.Color_Mode),\n AM => DMA2D_AM'Enum_Rep (NO_MODIF),\n ALPHA => 255,\n others => <>);\n\n if Src_Buffer.Color_Mode = L8 or else Src_Buffer.Color_Mode = L4 then\n\n if Src_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Source CLUT address required\";\n end if;\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n DMA2D_Periph.FGPFCCR.CS := (case Src_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.FGPFCCR.CCM := Src_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.FGPFCCR.START := True;\n\n while DMA2D_Periph.FGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;\n\n DMA2D_Periph.FGOR := (LO => UInt14 (Src_Buffer.Width - Width),\n others => <>);\n DMA2D_Periph.FGMAR := To_Word (Src_Buffer.Addr) + Src_Off;\n\n if Bg_Buffer /= Null_Buffer then\n declare\n Bg_Off : constant UInt32 := Offset (Bg_Buffer, X_Bg, Y_Bg);\n begin\n DMA2D_Periph.BGPFCCR.CM :=\n DMA2D_Color_Mode'Enum_Rep (Bg_Buffer.Color_Mode);\n DMA2D_Periph.BGMAR := To_Word (Bg_Buffer.Addr) + Bg_Off;\n DMA2D_Periph.BGPFCCR.CS := 0;\n DMA2D_Periph.BGPFCCR.START := False;\n DMA2D_Periph.BGOR :=\n (LO => UInt14 (Bg_Buffer.Width - Width), others => <>);\n\n if Bg_Buffer.Color_Mode = L8 or else Bg_Buffer.Color_Mode = L4 then\n\n if Bg_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Background CLUT address required\";\n end if;\n\n DMA2D_Periph.BGCMAR := To_Word (Bg_Buffer.CLUT_Addr);\n DMA2D_Periph.BGPFCCR.CS := (case Bg_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.BGPFCCR.CCM := Bg_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.BGPFCCR.START := True;\n\n while DMA2D_Periph.BGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;" + }, + { + "function_def": "procedure Demo_Timer_PWM is -- low-level demo of the PWM capabilities", + "function_body": "Period : constant := 1000;\n\n Output_Channel : constant Timer_Channel := Channel_2;\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode for Timer_4. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n\n --------------------\n -- Configure_LEDs --\n --------------------\n\n procedure Configure_LEDs;\n\n procedure Configure_LEDs is\n begin\n Enable_Clock (GPIO_D);\n\n Configure_IO\n (All_LEDs,\n (Mode_AF,\n AF => GPIO_AF_TIM4_2,\n AF_Speed => Speed_50MHz,\n AF_Output_Type => Push_Pull,\n Resistors => Floating));\n end Configure_LEDs;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_LEDs;\n\n Enable_Clock (Timer_4);\n\n Reset (Timer_4);\n\n Configure\n (Timer_4,\n Prescaler => 1,\n Period => Period,\n Clock_Divisor => Div1,\n Counter_Mode => Up);\n\n Configure_Channel_Output\n (Timer_4,\n Channel => Output_Channel,\n Mode => PWM1,\n State => Enable,\n Pulse => 0,\n Polarity => High);\n\n Set_Autoreload_Preload (Timer_4, True);\n\n Enable_Channel (Timer_4, Output_Channel);\n\n Enable (Timer_4);\n\n declare\n Arg : Long_Float := 0.0;\n Pulse : UInt16;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of optimization is observable.\n begin\n loop\n Pulse := UInt16 (Long_Float (Period / 2) * (1.0 + Sine (Arg)));\n Set_Compare_Value (Timer_4, Output_Channel, Pulse);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_PWM_ADT is -- demo the higher-level PWM abstract data type", + "function_body": "Selected_Timer : STM32.Timers.Timer renames Timer_4;\n -- NOT arbitrary! We drive the on-board LEDs that are tied to the channels\n -- of Timer_4 on some boards. Not all boards have this association. If you\n -- use a different board, select a GPIO point connected to your selected\n -- timer and drive that instead.\n\n Timer_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_TIM4_2;\n -- Note that this value MUST match the corresponding timer selected!\n\n Output_Channel : constant Timer_Channel := Channel_2; -- arbitrary\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n LED_For : constant array (Timer_Channel) of User_LED :=\n (Channel_1 => Green_LED,\n Channel_2 => Orange_LED,\n Channel_3 => Red_LED,\n Channel_4 => Blue_LED);\n\n Requested_Frequency : constant Hertz := 30_000; -- arbitrary\n\n Power_Control : PWM_Modulator;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_PWM_Timer (Selected_Timer'Access, Requested_Frequency);\n\n Power_Control.Attach_PWM_Channel\n (Selected_Timer'Access,\n Output_Channel,\n LED_For (Output_Channel),\n Timer_AF);\n\n Power_Control.Enable_Output;\n\n declare\n Arg : Long_Float := 0.0;\n Value : Percentage;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of compiler optimization is observable.\n begin\n loop\n Value := Percentage (50.0 * (1.0 + Sine (Arg)));\n Power_Control.Set_Duty_Cycle (Value);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_DAC_Basic is", + "function_body": "Output_Channel : constant DAC_Channel := Channel_1; -- arbitrary\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel);\n -- Once the channel is enabled, the corresponding GPIO pin is automatically\n -- connected to the analog converter output. However, in order to avoid\n -- parasitic consumption, the PA4 pin (Channel_1) or PA5 pin (Channel_2)\n -- should first be configured to analog mode. See the note in the RM, page\n -- 431.\n\n procedure Print (Value : UInt32);\n -- Prints the image of the arg at a fixed location\n\n procedure Await_Button;\n -- Wait for the user to press and then release the blue user button\n\n -----------\n -- Print --\n -----------\n\n procedure Print (Value : UInt32) is\n Value_Image : constant String := Value'Img;\n begin\n LCD_Std_Out.Put (170, 52, Value_Image (2 .. Value_Image'Last) & \" \");\n end Print;\n\n ------------------\n -- Await_Button --\n ------------------\n\n procedure Await_Button is\n begin\n Await_Pressed : loop\n exit Await_Pressed when Set (User_Button_Point);\n end loop Await_Pressed;\n\n Await_Released : loop\n exit Await_Released when not Set (User_Button_Point);\n end loop Await_Released;\n end Await_Button;\n\n ------------------------\n -- Configure_DAC_GPIO --\n ------------------------\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel) is\n Output : constant GPIO_Point := (if Output_Channel = Channel_1\n then DAC_Channel_1_IO\n else DAC_Channel_2_IO);\n begin\n Enable_Clock (Output);\n Configure_IO (Output, (Mode => Mode_Analog, Resistors => Floating));\n end Configure_DAC_GPIO;\n\nbegin\n Initialize_LEDs;\n All_LEDs_Off;\n\n LCD_Std_Out.Clear_Screen;\n\n Configure_User_Button_GPIO;\n\n Configure_DAC_GPIO (Output_Channel);\n\n Enable_Clock (DAC_1);\n\n Reset (DAC_1);\n\n Select_Trigger (DAC_1, Output_Channel, Software_Trigger);\n\n Enable_Trigger (DAC_1, Output_Channel);\n\n Enable (DAC_1, Output_Channel);\n\n declare\n Value : UInt32 := 0;\n Percent : UInt32;\n\n Resolution : constant DAC_Resolution := DAC_Resolution_12_Bits;\n -- Arbitrary, change as desired. Counts will automatically adjust.\n\n Max_Counts : constant UInt32 := (if Resolution = DAC_Resolution_12_Bits\n then Max_12bit_Resolution\n else Max_8bit_Resolution);\n begin\n Put (0, 0, \"VRef+ is 2.95V\"); -- measured\n Put (0, 25, \"Button advances\");\n Put (0, 52, \"Current %:\");\n loop\n for K in UInt32 range 0 .. 10 loop\n Percent := K * 10;\n Print (Percent);\n\n Value := (Percent * Max_Counts) / 100;\n\n Set_Output\n (DAC_1,\n Output_Channel,\n Value,\n Resolution,\n Right_Aligned);\n\n Trigger_Conversion_By_Software (DAC_1, Output_Channel);\n\n Await_Button;\n end loop;\n end loop;" + }, + { + "function_def": "procedure Demo_CRC is", + "function_body": "Checksum_CPU : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses the CPU to transfer\n -- the memory block to the CRC processor\n\n Checksum_DMA : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses DMA to transfer the\n -- memory block to the CRC processor\n\n -- see the STM32Cube_FW_F4_V1.6.0\\Projects\\ CRC example for data and\n -- expected CRC checksum value\n\n Section1 : constant Block_32 :=\n (16#00001021#, 16#20423063#, 16#408450A5#, 16#60C670E7#, 16#9129A14A#, 16#B16BC18C#,\n 16#D1ADE1CE#, 16#F1EF1231#, 16#32732252#, 16#52B54294#, 16#72F762D6#, 16#93398318#,\n 16#A35AD3BD#, 16#C39CF3FF#, 16#E3DE2462#, 16#34430420#, 16#64E674C7#, 16#44A45485#,\n 16#A56AB54B#, 16#85289509#, 16#F5CFC5AC#, 16#D58D3653#, 16#26721611#, 16#063076D7#,\n 16#569546B4#, 16#B75BA77A#, 16#97198738#, 16#F7DFE7FE#, 16#C7BC48C4#, 16#58E56886#,\n 16#78A70840#, 16#18612802#, 16#C9CCD9ED#, 16#E98EF9AF#, 16#89489969#, 16#A90AB92B#,\n 16#4AD47AB7#, 16#6A961A71#, 16#0A503A33#, 16#2A12DBFD#, 16#FBBFEB9E#, 16#9B798B58#,\n 16#BB3BAB1A#, 16#6CA67C87#, 16#5CC52C22#, 16#3C030C60#, 16#1C41EDAE#, 16#FD8FCDEC#,\n 16#AD2ABD0B#, 16#8D689D49#, 16#7E976EB6#, 16#5ED54EF4#, 16#2E321E51#, 16#0E70FF9F#);\n\n Section2 : constant Block_32 :=\n (16#EFBEDFDD#, 16#CFFCBF1B#, 16#9F598F78#, 16#918881A9#, 16#B1CAA1EB#, 16#D10CC12D#,\n 16#E16F1080#, 16#00A130C2#, 16#20E35004#, 16#40257046#, 16#83B99398#, 16#A3FBB3DA#,\n 16#C33DD31C#, 16#E37FF35E#, 16#129022F3#, 16#32D24235#, 16#52146277#, 16#7256B5EA#,\n 16#95A88589#, 16#F56EE54F#, 16#D52CC50D#, 16#34E224C3#, 16#04817466#, 16#64475424#,\n 16#4405A7DB#, 16#B7FA8799#, 16#E75FF77E#, 16#C71DD73C#, 16#26D336F2#, 16#069116B0#,\n 16#76764615#, 16#5634D94C#, 16#C96DF90E#, 16#E92F99C8#, 16#B98AA9AB#, 16#58444865#,\n 16#78066827#, 16#18C008E1#, 16#28A3CB7D#, 16#DB5CEB3F#, 16#FB1E8BF9#, 16#9BD8ABBB#,\n 16#4A755A54#, 16#6A377A16#, 16#0AF11AD0#, 16#2AB33A92#, 16#ED0FDD6C#, 16#CD4DBDAA#,\n 16#AD8B9DE8#, 16#8DC97C26#, 16#5C644C45#, 16#3CA22C83#, 16#1CE00CC1#, 16#EF1FFF3E#,\n 16#DF7CAF9B#, 16#BFBA8FD9#, 16#9FF86E17#, 16#7E364E55#, 16#2E933EB2#, 16#0ED11EF0#);\n\n -- expected CRC value for the data above is 379E9F06 hex, or 933142278 dec\n Expected_Checksum : constant UInt32 := 933142278;\n\n Next_DMA_Interrupt : DMA_Interrupt;\n\n procedure Panic with No_Return;\n -- flash the on-board LEDs, indefinitely, to indicate a failure\n\n procedure Panic is\n begin\n loop\n Toggle_LEDs (All_LEDs);\n delay until Clock + Milliseconds (100);\n end loop;\n end Panic;\n\nbegin\n Clear_Screen;\n Initialize_LEDs;\n\n Enable_Clock (CRC_Unit);\n\n -- get the checksum using the CPU to transfer memory to the CRC processor;\n -- verify it is the expected value\n\n Update_CRC (CRC_Unit, Input => Section1, Output => Checksum_CPU);\n Update_CRC (CRC_Unit, Input => Section2, Output => Checksum_CPU);\n\n Put_Line (\"CRC:\" & Checksum_CPU'Img);\n\n if Checksum_CPU /= Expected_Checksum then\n Panic;\n end if;\n\n -- get the checksum using DMA to transfer memory to the CRC processor\n\n Enable_Clock (Controller);\n\n Reset (Controller);\n\n Reset_Calculator (CRC_Unit);\n\n Update_CRC (CRC_Unit, Controller'Access, Stream, Input => Section1);\n\n DMA_IRQ_Handler.Await_Event (Next_DMA_Interrupt);\n\n if Next_DMA_Interrupt /= Transfer_Complete_Interrupt then\n Panic;\n end if;\n\n -- In this code fragment we use the approach suited for the case in which\n -- we are calculating the CRC for a section of system memory rather than a\n -- block of application data. We pretend that Section2 is a memory section.\n -- All we need is a known starting address and a known length. Given that,\n -- we can create a view of it as if it is an object of type Block_32 (or\n -- whichever block type is appropriate).\n declare\n subtype Memory_Section is Block_32 (1 .. Section2'Length);\n type Section_Pointer is access all Memory_Section with Storage_Size => 0;\n function As_Memory_Section_Reference is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Section_Pointer);\n begin\n Update_CRC\n (CRC_Unit,\n Controller'Access,\n Stream,\n Input => As_Memory_Section_Reference (Section2'Address).all);" + }, + { + "function_def": "procedure DSB is", + "function_body": "begin\n Asm (\"dsb\", Volatile => True);\n end DSB;\n\n ---------\n -- ISB --\n ---------\n\n procedure ISB is\n begin\n Asm (\"isb\", Volatile => True);\n end ISB;\n\n -----------------------\n -- Cache_Maintenance --\n -----------------------\n\n procedure Cache_Maintenance\n (Start : System.Address;\n Len : Natural)\n is\n begin\n if not D_Cache_Enabled then\n return;\n end if;\n\n declare\n function To_U32 is new Ada.Unchecked_Conversion\n (System.Address, UInt32);\n\n Op_Size : Integer_32 := Integer_32 (Len);\n Op_Addr : UInt32 := To_U32 (Start);\n Reg : UInt32 with Volatile, Address => Reg_Address;\n\n begin\n DSB;\n\n while Op_Size > 0 loop\n Reg := Op_Addr;\n Op_Addr := Op_Addr + Data_Cache_Line_Size;\n Op_Size := Op_Size - Integer_32 (Data_Cache_Line_Size);\n end loop;\n\n DSB;\n ISB;" + }, + { + "function_def": "function To_Char is new Ada.Unchecked_Conversion (Source => UInt8,", + "function_body": "Target => Character);\n function To_UInt8 is new Ada.Unchecked_Conversion (Source => Character,\n Target => UInt8);\n\n procedure Write (This : in out TP_Device; Cmd : String);\n procedure Read (This : in out TP_Device; Str : out String);\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : in out TP_Device; Cmd : String) is\n Status : UART_Status;\n Data : UART_Data_8b (Cmd'Range);\n begin\n\n for Index in Cmd'Range loop\n Data (Index) := To_UInt8 (Cmd (Index));\n end loop;\n\n This.Port.Transmit (Data, Status);\n\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n -- This.Time.Delay_Microseconds ((11 * 1000000 / 19_2000) + Cmd'Length);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read (This : in out TP_Device; Str : out String) is\n Status : UART_Status;\n Data : UART_Data_8b (Str'Range);\n begin\n This.Port.Receive (Data, Status);\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n\n for Index in Str'Range loop\n Str (Index) := To_Char (Data (Index));\n end loop;\n end Read;\n\n ----------------------\n -- Set_Line_Spacing --\n ----------------------\n\n procedure Set_Line_Spacing (This : in out TP_Device; Spacing : UInt8) is\n begin\n Write (This, ASCII.ESC & '3' & To_Char (Spacing));\n end Set_Line_Spacing;\n\n ---------------\n -- Set_Align --\n ---------------\n\n procedure Set_Align (This : in out TP_Device; Align : Text_Align) is\n Mode : Character;\n begin\n case Align is\n when Left => Mode := '0';\n when Center => Mode := '1';\n when Right => Mode := '2';\n end case;\n Write (This, ASCII.ESC & 'a' & Mode);\n end Set_Align;\n\n ----------------------\n -- Set_Font_Enlarge --\n ----------------------\n\n procedure Set_Font_Enlarge (This : in out TP_Device; Height, Width : Boolean) is\n Data : UInt8 := 0;\n begin\n if Height then\n Data := Data or 16#01#;\n end if;\n if Width then\n Data := Data or 16#10#;\n end if;\n Write (This, ASCII.GS & '!' & To_Char (Data));\n end Set_Font_Enlarge;\n\n --------------\n -- Set_Bold --\n --------------\n\n procedure Set_Bold (This : in out TP_Device; Bold : Boolean) is\n begin\n Write (This, ASCII.ESC & 'E' & To_Char (if Bold then 1 else 0));\n end Set_Bold;\n\n ----------------------\n -- Set_Double_Width --\n ----------------------\n\n procedure Set_Double_Width (This : in out TP_Device; Double : Boolean) is\n begin\n if Double then\n Write (This, ASCII.ESC & ASCII.SO);\n else\n Write (This, ASCII.ESC & ASCII.DC4);\n end if;\n end Set_Double_Width;\n\n ----------------\n -- Set_UpDown --\n ----------------\n\n procedure Set_UpDown (This : in out TP_Device; UpDown : Boolean) is\n begin\n Write (This, ASCII.ESC & '{' & To_Char (if UpDown then 1 else 0));\n end Set_UpDown;\n\n ------------------\n -- Set_Reversed --\n ------------------\n\n procedure Set_Reversed (This : in out TP_Device; Reversed : Boolean) is\n begin\n Write (This, ASCII.GS & 'B' & To_Char (if Reversed then 1 else 0));\n end Set_Reversed;\n\n --------------------------\n -- Set_Underline_Height --\n --------------------------\n\n procedure Set_Underline_Height (This : in out TP_Device; Height : Underline_Height) is\n begin\n Write (This, ASCII.ESC & '-' & To_Char (Height));\n end Set_Underline_Height;\n\n -----------------------\n -- Set_Character_Set --\n -----------------------\n\n procedure Set_Character_Set (This : in out TP_Device; Set : Character_Set) is\n begin\n Write (This, ASCII.ESC & 't' & To_Char (Character_Set'Pos (Set)));\n end Set_Character_Set;\n\n ----------\n -- Feed --\n ----------\n\n procedure Feed (This : in out TP_Device; Rows : UInt8) is\n begin\n Write (This, ASCII.ESC & 'd' & To_Char (Rows));\n end Feed;\n\n ------------------\n -- Print_Bitmap --\n ------------------\n\n procedure Print_Bitmap (This : in out TP_Device;\n BM : Thermal_Printer_Bitmap)\n is\n Nbr_Of_Rows : constant Natural := BM'Length (2);\n Nbr_Of_Columns : constant Natural := BM'Length (1);\n Str : String (1 .. Nbr_Of_Columns / 8);\n begin\n\n Write (This, ASCII.DC2 & 'v' &\n To_Char (UInt8 (Nbr_Of_Rows rem 256)) &\n To_Char (UInt8 (Nbr_Of_Rows / 256)));\n\n for Row in 0 .. Nbr_Of_Rows - 1 loop\n for Colum in 0 .. (Nbr_Of_Columns / 8) - 1 loop\n declare\n BM_Index : constant Natural := BM'First (1) + Colum * 8;\n Str_Index : constant Natural := Str'First + Colum;\n B : UInt8 := 0;\n begin\n for X in 0 .. 7 loop\n B := B or (if BM (BM_Index + X,\n BM'First (2) + Row)\n then 2**X else 0);\n end loop;\n Str (Str_Index) := To_Char (B);" + }, + { + "function_def": "function As_UInt8 is new Ada.Unchecked_Conversion", + "function_body": "(Source => High_Pass_Filter_Mode, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => High_Pass_Cutoff_Frequency, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Power_Mode_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Output_Data_Rate_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Axes_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Bandwidth_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Block_Data_Update_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Endian_Data_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Full_Scale_Selection, Target => UInt8);\n\n type Angle_Rate_Pointer is access all Angle_Rate with Storage_Size => 0;\n\n function As_Angle_Rate_Pointer is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Angle_Rate_Pointer);\n -- So that we can treat the address of a UInt8 as a pointer to a two-UInt8\n -- sequence representing a signed integer quantity.\n\n procedure Swap2 (Location : System.Address) with Inline;\n -- Swaps the two UInt8s at Location and Location+1\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean);\n -- Enable or disable SPI mode communication with the device. This is named\n -- \"chip select\" in other demos/examples.\n\n ----------------\n -- Initialize --\n ----------------\n\n procedure Initialize\n (This : in out Three_Axis_Gyroscope;\n Port : Any_SPI_Port;\n Chip_Select : Any_GPIO_Point)\n is\n begin\n This.Port := Port;\n This.CS := Chip_Select;\n\n SPI_Mode (This, Enabled => False);\n end Initialize;\n\n -----------------\n -- SPI_Mode --\n -----------------\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean) is\n -- When the pin is low (cleared), the device is in SPI mode.\n -- When the pin is high (set), the device is in I2C mode.\n -- We want SPI mode communication, so Enabled, when True,\n -- means we must drive the pin low.\n begin\n if Enabled then\n This.CS.Clear;\n else\n This.CS.Set;\n end if;\n end SPI_Mode;\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : Three_Axis_Gyroscope; Addr : Register; Data : UInt8)\n is\n Status : SPI_Status;\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr)), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Transmit (SPI_Data_8b'(1 => Data), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n SPI_Mode (This, Enabled => False);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Data : out UInt8)\n is\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD),\n Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Data := Tmp_Data (Tmp_Data'First);\n\n SPI_Mode (This, Enabled => False);\n end Read;\n\n ----------------\n -- Read_UInt8s --\n ----------------\n\n procedure Read_UInt8s\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Buffer : out SPI_Data_8b;\n Count : Natural)\n is\n Index : Natural := Buffer'First;\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit\n (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD or MultiUInt8_CMD),\n Status);\n\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n for K in 1 .. Count loop\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Buffer (Index) := Tmp_Data (Tmp_Data'First);\n Index := Index + 1;\n end loop;\n\n SPI_Mode (This, Enabled => False);\n end Read_UInt8s;\n\n ---------------\n -- Configure --\n ---------------\n\n procedure Configure\n (This : in out Three_Axis_Gyroscope;\n Power_Mode : Power_Mode_Selection;\n Output_Data_Rate : Output_Data_Rate_Selection;\n Axes_Enable : Axes_Selection;\n Bandwidth : Bandwidth_Selection;\n BlockData_Update : Block_Data_Update_Selection;\n Endianness : Endian_Data_Selection;\n Full_Scale : Full_Scale_Selection)\n is\n Ctrl1 : UInt8;\n Ctrl4 : UInt8;\n begin\n Ctrl1 := As_UInt8 (Power_Mode) or\n As_UInt8 (Output_Data_Rate) or\n As_UInt8 (Axes_Enable) or\n As_UInt8 (Bandwidth);\n\n Ctrl4 := As_UInt8 (BlockData_Update) or\n As_UInt8 (Endianness) or\n As_UInt8 (Full_Scale);\n\n Write (This, CTRL_REG1, Ctrl1);\n Write (This, CTRL_REG4, Ctrl4);\n end Configure;\n\n -----------\n -- Sleep --\n -----------\n\n procedure Sleep (This : in out Three_Axis_Gyroscope) is\n Ctrl1 : UInt8;\n Sleep_Mode : constant := 2#1000#; -- per the Datasheet, Table 22, pg 32\n begin\n Read (This, CTRL_REG1, Ctrl1);\n Ctrl1 := Ctrl1 or Sleep_Mode;\n Write (This, CTRL_REG1, Ctrl1);\n end Sleep;\n\n --------------------------------\n -- Configure_High_Pass_Filter --\n --------------------------------\n\n procedure Configure_High_Pass_Filter\n (This : in out Three_Axis_Gyroscope;\n Mode_Selection : High_Pass_Filter_Mode;\n Cutoff_Frequency : High_Pass_Cutoff_Frequency)\n is\n Ctrl2 : UInt8;\n begin\n -- note that the two high-order bits must remain zero, per the datasheet\n Ctrl2 := As_UInt8 (Mode_Selection) or As_UInt8 (Cutoff_Frequency);\n Write (This, CTRL_REG2, Ctrl2);\n end Configure_High_Pass_Filter;\n\n -----------------------------\n -- Enable_High_Pass_Filter --\n -----------------------------\n\n procedure Enable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set HPen bit\n Ctrl5 := Ctrl5 or HighPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_High_Pass_Filter;\n\n ------------------------------\n -- Disable_High_Pass_Filter --\n ------------------------------\n\n procedure Disable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not HighPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_High_Pass_Filter;\n\n ----------------------------\n -- Enable_Low_Pass_Filter --\n ----------------------------\n\n procedure Enable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or LowPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_Low_Pass_Filter;\n\n -----------------------------\n -- Disable_Low_Pass_Filter --\n -----------------------------\n\n procedure Disable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not LowPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_Low_Pass_Filter;\n\n ---------------------\n -- Reference_Value --\n ---------------------\n\n function Reference_Value (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Reference, Result);\n return Result;\n end Reference_Value;\n\n -------------------\n -- Set_Reference --\n -------------------\n\n procedure Set_Reference (This : in out Three_Axis_Gyroscope; Value : UInt8) is\n begin\n Write (This, Reference, Value);\n end Set_Reference;\n\n -----------------\n -- Data_Status --\n -----------------\n\n function Data_Status (This : Three_Axis_Gyroscope) return Gyro_Data_Status is\n Result : UInt8;\n function As_Gyro_Data_Status is\n new Ada.Unchecked_Conversion (Source => UInt8,\n Target => Gyro_Data_Status);\n begin\n Read (This, Status, Result);\n return As_Gyro_Data_Status (Result);\n end Data_Status;\n\n ---------------\n -- Device_Id --\n ---------------\n\n function Device_Id (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Who_Am_I, Result);\n return Result;\n end Device_Id;\n\n -----------------\n -- Temperature --\n -----------------\n\n function Temperature (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, OUT_Temp, Result);\n return Result;\n end Temperature;\n\n ------------\n -- Reboot --\n ------------\n\n procedure Reboot (This : Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set the boot bit\n Ctrl5 := Ctrl5 or Boot_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Reboot;\n\n ----------------------------\n -- Full_Scale_Sensitivity --\n ----------------------------\n\n function Full_Scale_Sensitivity (This : Three_Axis_Gyroscope) return Float is\n Ctrl4 : UInt8;\n Result : Float;\n Fullscale_Selection : UInt8;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Fullscale_Selection := Ctrl4 and Fullscale_Selection_Bits;\n\n if Fullscale_Selection = L3GD20_Fullscale_250'Enum_Rep then\n Result := Sensitivity_250dps;\n elsif Fullscale_Selection = L3GD20_Fullscale_500'Enum_Rep then\n Result := Sensitivity_500dps;\n else\n Result := Sensitivity_2000dps;\n end if;\n\n return Result;\n end Full_Scale_Sensitivity;\n\n -------------------------\n -- Get_Raw_Angle_Rates --\n -------------------------\n\n procedure Get_Raw_Angle_Rates\n (This : Three_Axis_Gyroscope;\n Rates : out Angle_Rates)\n is\n\n Ctrl4 : UInt8;\n\n UInt8s_To_Read : constant Integer := 6; -- ie, three 2-UInt8 integers\n -- the number of UInt8s in an Angle_Rates record object\n\n Received : SPI_Data_8b (1 .. UInt8s_To_Read);\n\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n -- The above has the effect of separate reads, as follows:\n -- Read (This, OUT_X_L, Received (1));\n -- Read (This, OUT_X_H, Received (2));\n -- Read (This, OUT_Y_L, Received (3));\n -- Read (This, OUT_Y_H, Received (4));\n -- Read (This, OUT_Z_L, Received (5));\n -- Read (This, OUT_Z_H, Received (6));\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n Swap2 (Received (1)'Address);\n Swap2 (Received (3)'Address);\n Swap2 (Received (5)'Address);\n end if;\n\n Rates.X := As_Angle_Rate_Pointer (Received (1)'Address).all;\n Rates.Y := As_Angle_Rate_Pointer (Received (3)'Address).all;\n Rates.Z := As_Angle_Rate_Pointer (Received (5)'Address).all;\n end Get_Raw_Angle_Rates;\n\n --------------------------\n -- Configure_Interrupt1 --\n --------------------------\n\n procedure Configure_Interrupt1\n (This : in out Three_Axis_Gyroscope;\n Triggers : Threshold_Event_List;\n Latched : Boolean := False;\n Active_Edge : Interrupt1_Active_Edge := L3GD20_Interrupt1_High_Edge;\n Combine_Events : Boolean := False;\n Sample_Count : Sample_Counter := 0)\n is\n Config : UInt8;\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and 16#DF#;\n Ctrl3 := Ctrl3 or Active_Edge'Enum_Rep;\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n\n if Sample_Count > 0 then\n Set_Duration_Counter (This, Sample_Count);\n end if;\n\n Config := 0;\n\n if Latched then\n Config := Config or Int1_Latch_Enable_Bit;\n end if;\n\n if Combine_Events then\n Config := Config or Logically_And_Or_Events_Bit;\n end if;\n\n for Event of Triggers loop\n Config := Config or Axes_Interrupt_Enablers (Event.Axis);\n end loop;\n\n Write (This, INT1_CFG, Config);\n\n for Event of Triggers loop\n Set_Threshold (This, Event.Axis, Event.Threshold);\n end loop;\n end Configure_Interrupt1;\n\n ----------------------------\n -- Set_Interrupt_Pin_Mode --\n ----------------------------\n\n procedure Set_Interrupt_Pin_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : Pin_Modes)\n is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not Interrupt_Pin_Mode_Bit);\n Ctrl3 := Ctrl3 or Mode'Enum_Rep;\n Write (This, CTRL_REG3, Ctrl3);\n end Set_Interrupt_Pin_Mode;\n\n -----------------------\n -- Enable_Interrupt1 --\n -----------------------\n\n procedure Enable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n end Enable_Interrupt1;\n\n ------------------------\n -- Disable_Interrupt1 --\n ------------------------\n\n procedure Disable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not INT1_Interrupt_Enable);\n Write (This, CTRL_REG3, Ctrl3);\n end Disable_Interrupt1;\n\n -----------------------\n -- Interrupt1_Status --\n -----------------------\n\n function Interrupt1_Source (This : Three_Axis_Gyroscope) return Interrupt1_Sources is\n Result : UInt8;\n function As_Interrupt_Source is new Ada.Unchecked_Conversion\n (Source => UInt8, Target => Interrupt1_Sources);\n begin\n Read (This, INT1_SRC, Result);\n return As_Interrupt_Source (Result);\n end Interrupt1_Source;\n\n --------------------------\n -- Set_Duration_Counter --\n --------------------------\n\n procedure Set_Duration_Counter\n (This : in out Three_Axis_Gyroscope;\n Value : Sample_Counter)\n is\n Wait_Bit : constant := 2#1000_0000#;\n begin\n Write (This, INT1_Duration, UInt8 (Value) or Wait_Bit);\n end Set_Duration_Counter;\n\n ------------------\n -- Enable_Event --\n ------------------\n\n procedure Enable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config or Axes_Interrupt_Enablers (Event);\n Write (This, INT1_CFG, Config);\n end Enable_Event;\n\n -------------------\n -- Disable_Event --\n -------------------\n\n procedure Disable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config and (not Axes_Interrupt_Enablers (Event));\n Write (This, INT1_CFG, Config);\n end Disable_Event;\n\n -------------------\n -- Set_Threshold --\n -------------------\n\n procedure Set_Threshold\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts;\n Value : Axis_Sample_Threshold)\n is\n begin\n case Event is\n when Z_High_Interrupt | Z_Low_Interrupt =>\n Write (This, INT1_TSH_ZL, UInt8 (Value));\n Write (This, INT1_TSH_ZH, UInt8 (Shift_Right (Value, 8)));\n\n when Y_High_Interrupt | Y_Low_Interrupt =>\n Write (This, INT1_TSH_YL, UInt8 (Value));\n Write (This, INT1_TSH_YH, UInt8 (Shift_Right (Value, 8)));\n\n when X_High_Interrupt | X_Low_Interrupt =>\n Write (This, INT1_TSH_XL, UInt8 (Value));\n Write (This, INT1_TSH_XH, UInt8 (Shift_Right (Value, 8)));\n end case;\n end Set_Threshold;\n\n -------------------\n -- Set_FIFO_Mode --\n -------------------\n\n procedure Set_FIFO_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : FIFO_Modes)\n is\n FIFO : UInt8;\n begin\n Read (This, FIFO_CTRL, FIFO);\n FIFO := FIFO and (not FIFO_Mode_Bits); -- clear the current bits\n FIFO := FIFO or Mode'Enum_Rep;\n Write (This, FIFO_CTRL, FIFO);\n end Set_FIFO_Mode;\n\n -----------------\n -- Enable_FIFO --\n -----------------\n\n procedure Enable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or FIFO_Enable_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_FIFO;\n\n ------------------\n -- Disable_FIFO --\n ------------------\n\n procedure Disable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 and (not FIFO_Enable_Bit);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_FIFO;\n\n ------------------------\n -- Set_FIFO_Watermark --\n ------------------------\n\n procedure Set_FIFO_Watermark\n (This : in out Three_Axis_Gyroscope;\n Level : FIFO_Level)\n is\n Value : UInt8;\n begin\n Read (This, FIFO_CTRL, Value);\n Value := Value and (not Watermark_Threshold_Bits); -- clear the bits\n Value := Value or UInt8 (Level);\n Write (This, FIFO_CTRL, Value);\n end Set_FIFO_Watermark;\n\n ------------------------------\n -- Get_Raw_Angle_Rates_FIFO --\n ------------------------------\n\n procedure Get_Raw_Angle_Rates_FIFO\n (This : in out Three_Axis_Gyroscope;\n Buffer : out Angle_Rates_FIFO_Buffer)\n is\n Ctrl4 : UInt8;\n\n Angle_Rate_Size : constant Integer := 6; -- UInt8s\n UInt8s_To_Read : constant Integer := Buffer'Length * Angle_Rate_Size;\n Received : SPI_Data_8b (0 .. UInt8s_To_Read - 1)\n with Alignment => 2;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n declare\n J : Integer := 0;\n begin\n for K in Received'First .. Received'Last / 2 loop\n Swap2 (Received (J)'Address);\n J := J + 2;\n end loop;" + }, + { + "function_def": "function To_Map is new Ada.Unchecked_Conversion", + "function_body": "(SPAD_Map_Bytes, SPAD_Map);\n function To_Bytes is new Ada.Unchecked_Conversion\n (SPAD_Map, SPAD_Map_Bytes);\n\n SPAD_Count : UInt8;\n SPAD_Is_Aperture : Boolean;\n Ref_SPAD_Map_Bytes : SPAD_Map_Bytes;\n Ref_SPAD_Map : SPAD_Map;\n First_SPAD : UInt8;\n SPADS_Enabled : UInt8;\n Timing_Budget : UInt32;\n\n begin\n Status := SPAD_Info (This, SPAD_Count, SPAD_Is_Aperture);\n\n if not Status then\n return;\n end if;\n\n Read\n (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n Ref_SPAD_Map := To_Map (Ref_SPAD_Map_Bytes);\n\n -- Set reference spads\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_REF_EN_START_OFFSET,\n UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD,\n UInt8'(16#2C#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_GLOBAL_CONFIG_REF_EN_START_SELECT,\n UInt8'(16#B4#), Status);\n end if;\n\n if Status then\n if SPAD_Is_Aperture then\n First_SPAD := 13;\n else\n First_SPAD := 1;\n end if;\n\n SPADS_Enabled := 0;\n\n for J in UInt8 range 1 .. 48 loop\n\n if J < First_SPAD or else SPADS_Enabled = SPAD_Count then\n -- This bit is lower than the first one that should be enabled,\n -- or SPAD_Count bits have already been enabled, so zero this\n -- bit\n Ref_SPAD_Map (J) := False;\n\n elsif Ref_SPAD_Map (J) then\n SPADS_Enabled := SPADS_Enabled + 1;\n end if;\n end loop;\n end if;\n\n if Status then\n Ref_SPAD_Map_Bytes := To_Bytes (Ref_SPAD_Map);\n Write (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n end if;\n\n -- Load tuning Settings\n -- default tuning settings from vl53l0x_tuning.h\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#09#, UInt8'(16#00#), Status);\n Write (This, 16#10#, UInt8'(16#00#), Status);\n Write (This, 16#11#, UInt8'(16#00#), Status);\n\n Write (This, 16#24#, UInt8'(16#01#), Status);\n Write (This, 16#25#, UInt8'(16#FF#), Status);\n Write (This, 16#75#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#4E#, UInt8'(16#2C#), Status);\n Write (This, 16#48#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#20#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#09#), Status);\n Write (This, 16#54#, UInt8'(16#00#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#32#, UInt8'(16#03#), Status);\n Write (This, 16#40#, UInt8'(16#83#), Status);\n Write (This, 16#46#, UInt8'(16#25#), Status);\n Write (This, 16#60#, UInt8'(16#00#), Status);\n Write (This, 16#27#, UInt8'(16#00#), Status);\n Write (This, 16#50#, UInt8'(16#06#), Status);\n Write (This, 16#51#, UInt8'(16#00#), Status);\n Write (This, 16#52#, UInt8'(16#96#), Status);\n Write (This, 16#56#, UInt8'(16#08#), Status);\n Write (This, 16#57#, UInt8'(16#30#), Status);\n Write (This, 16#61#, UInt8'(16#00#), Status);\n Write (This, 16#62#, UInt8'(16#00#), Status);\n Write (This, 16#64#, UInt8'(16#00#), Status);\n Write (This, 16#65#, UInt8'(16#00#), Status);\n Write (This, 16#66#, UInt8'(16#A0#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#22#, UInt8'(16#32#), Status);\n Write (This, 16#47#, UInt8'(16#14#), Status);\n Write (This, 16#49#, UInt8'(16#FF#), Status);\n Write (This, 16#4A#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#7A#, UInt8'(16#0A#), Status);\n Write (This, 16#7B#, UInt8'(16#00#), Status);\n Write (This, 16#78#, UInt8'(16#21#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#23#, UInt8'(16#34#), Status);\n Write (This, 16#42#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#FF#), Status);\n Write (This, 16#45#, UInt8'(16#26#), Status);\n Write (This, 16#46#, UInt8'(16#05#), Status);\n Write (This, 16#40#, UInt8'(16#40#), Status);\n Write (This, 16#0E#, UInt8'(16#06#), Status);\n Write (This, 16#20#, UInt8'(16#1A#), Status);\n Write (This, 16#43#, UInt8'(16#40#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#34#, UInt8'(16#03#), Status);\n Write (This, 16#35#, UInt8'(16#44#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#4B#, UInt8'(16#09#), Status);\n Write (This, 16#4C#, UInt8'(16#05#), Status);\n Write (This, 16#4D#, UInt8'(16#04#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#00#), Status);\n Write (This, 16#45#, UInt8'(16#20#), Status);\n Write (This, 16#47#, UInt8'(16#08#), Status);\n Write (This, 16#48#, UInt8'(16#28#), Status);\n Write (This, 16#67#, UInt8'(16#00#), Status);\n Write (This, 16#70#, UInt8'(16#04#), Status);\n Write (This, 16#71#, UInt8'(16#01#), Status);\n Write (This, 16#72#, UInt8'(16#FE#), Status);\n Write (This, 16#76#, UInt8'(16#00#), Status);\n Write (This, 16#77#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#0D#, UInt8'(16#01#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#01#), Status);\n Write (This, 16#01#, UInt8'(16#F8#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#8E#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#01#), Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n Set_GPIO_Config (This, GPIO_Function, Polarity_High, Status);\n\n if Status then\n Timing_Budget := Measurement_Timing_Budget (This);\n\n -- Disable MSRC and TCC by default\n -- MSRC = Minimum Signal Rate Check\n -- TCC = Target CenterCheck\n\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n\n -- Recalculate the timing Budget\n if Status then\n Set_Measurement_Timing_Budget (This, Timing_Budget, Status);\n end if;\n end Static_Init;\n\n ------------------------------------\n -- Perform_Single_Ref_Calibration --\n ------------------------------------\n\n procedure Perform_Single_Ref_Calibration\n (This : VL53L0X_Ranging_Sensor;\n VHV_Init : UInt8;\n Status : out Boolean)\n is\n Val : UInt8;\n\n begin\n Write (This, REG_SYSRANGE_START, VHV_Init or 16#01#, Status);\n\n if not Status then\n return;\n end if;\n\n loop\n Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);\n exit when not Status;\n exit when (Val and 16#07#) /= 0;\n end loop;\n\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSRANGE_START, UInt8'(16#00#), Status);\n end Perform_Single_Ref_Calibration;\n\n -----------------------------\n -- Perform_Ref_Calibration --\n -----------------------------\n\n procedure Perform_Ref_Calibration\n (This : in out VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n begin\n -- VHV calibration\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#01#), Status);\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#40#, Status);\n end if;\n\n -- Phase calibration\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#02#), Status);\n end if;\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#00#, Status);\n end if;\n\n -- Restore the sequence config\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n end Perform_Ref_Calibration;\n\n ------------------------------------\n -- Start_Range_Single_Millimeters --\n ------------------------------------\n\n procedure Start_Range_Single_Millimeters\n (This : VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n Val : UInt8;\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#91#, This.Stop_Variable, Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n if Status then\n Write (This, REG_SYSRANGE_START, UInt8'(16#01#), Status);\n end if;\n\n if not Status then\n return;\n end if;\n\n loop\n Read (This, REG_SYSRANGE_START, Val, Status);\n exit when not Status;\n exit when (Val and 16#01#) = 0;\n end loop;\n end Start_Range_Single_Millimeters;\n\n ---------------------------\n -- Range_Value_Available --\n ---------------------------\n\n function Range_Value_Available\n (This : VL53L0X_Ranging_Sensor) return Boolean\n is\n Status : Boolean with Unreferenced;\n Val : UInt8;\n begin\n Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);\n return (Val and 16#07#) /= 0;\n end Range_Value_Available;\n\n ----------------------------\n -- Read_Range_Millimeters --\n ----------------------------\n\n function Read_Range_Millimeters\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt16\n is\n Status : Boolean with Unreferenced;\n Ret : HAL.UInt16;\n begin\n Read (This, REG_RESULT_RANGE_STATUS + 10, Ret, Status);\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n\n return Ret;\n end Read_Range_Millimeters;\n\n -----------------------------------\n -- Read_Range_Single_Millimeters --\n -----------------------------------\n\n function Read_Range_Single_Millimeters\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt16\n is\n Status : Boolean;\n begin\n Start_Range_Single_Millimeters (This, Status);\n if not Status then\n return 4000;\n end if;\n\n while not Range_Value_Available (This) loop\n null;\n end loop;\n\n return Read_Range_Millimeters (This);\n end Read_Range_Single_Millimeters;\n\n ---------------------\n -- Set_GPIO_Config --\n ---------------------\n\n procedure Set_GPIO_Config\n (This : in out VL53L0X_Ranging_Sensor;\n Functionality : VL53L0X_GPIO_Functionality;\n Polarity : VL53L0X_Interrupt_Polarity;\n Status : out Boolean)\n is\n Data : UInt8;\n Tmp : UInt8;\n begin\n case Functionality is\n when No_Interrupt =>\n Data := 0;\n when Level_Low =>\n Data := 1;\n when Level_High =>\n Data := 2;\n when Out_Of_Window =>\n Data := 3;\n when New_Sample_Ready =>\n Data := 4;\n end case;\n\n -- 16#04#: interrupt on new measure ready\n Write (This, REG_SYSTEM_INTERRUPT_CONFIG_GPIO, Data, Status);\n\n -- Interrupt polarity\n if Status then\n case Polarity is\n when Polarity_Low =>\n Data := 16#10#;\n when Polarity_High =>\n Data := 16#00#;\n end case;\n\n Read (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);\n Tmp := (Tmp and 16#EF#) or Data;\n Write (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);\n end if;\n\n if Status then\n Clear_Interrupt_Mask (This);\n end if;\n end Set_GPIO_Config;\n\n --------------------------\n -- Clear_Interrupt_Mask --\n --------------------------\n\n procedure Clear_Interrupt_Mask\n (This : VL53L0X_Ranging_Sensor)\n is\n Status : Boolean with Unreferenced;\n-- Tmp : UInt8;\n begin\n-- for J in 1 .. 3 loop\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n-- exit when not Status;\n-- Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#00#), Status);\n-- exit when not Status;\n-- Read (This, REG_RESULT_INTERRUPT_STATUS, Tmp, Status);\n-- exit when not Status;\n-- exit when (Tmp and 16#07#) /= 0;\n-- end loop;\n end Clear_Interrupt_Mask;\n\n ---------------------------\n -- Sequence_Step_Enabled --\n ---------------------------\n\n function Sequence_Step_Enabled\n (This : VL53L0X_Ranging_Sensor) return VL53L0x_Sequence_Step_Enabled\n is\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Sequence_Config : UInt8 := 0;\n Status : Boolean;\n\n function Sequence_Step_Enabled\n (Step : VL53L0x_Sequence_Step;\n Sequence_Config : UInt8) return Boolean;\n\n ---------------------------\n -- Sequence_Step_Enabled --\n ---------------------------\n\n function Sequence_Step_Enabled\n (Step : VL53L0x_Sequence_Step;\n Sequence_Config : UInt8) return Boolean\n is\n begin\n case Step is\n when TCC =>\n return (Sequence_Config and 16#10#) /= 0;\n when DSS =>\n return (Sequence_Config and 16#08#) /= 0;\n when MSRC =>\n return (Sequence_Config and 16#04#) /= 0;\n when Pre_Range =>\n return (Sequence_Config and 16#40#) /= 0;\n when Final_Range =>\n return (Sequence_Config and 16#80#) /= 0;\n end case;\n end Sequence_Step_Enabled;\n\n begin\n Read (This, REG_SYSTEM_SEQUENCE_CONFIG, Sequence_Config, Status);\n\n if not Status then\n return (others => False);\n end if;\n\n for Step in Sequence_Steps'Range loop\n Sequence_Steps (Step) :=\n Sequence_Step_Enabled (Step, Sequence_Config);\n end loop;\n\n return Sequence_Steps;\n end Sequence_Step_Enabled;\n\n ---------------------------\n -- Sequence_Step_Timeout --\n ---------------------------\n\n function Sequence_Step_Timeout\n (This : VL53L0X_Ranging_Sensor;\n Step : VL53L0x_Sequence_Step;\n As_Mclks : Boolean := False) return UInt32\n is\n VCSel_Pulse_Period_Pclk : UInt8;\n Encoded_UInt8 : UInt8;\n Encoded_UInt16 : UInt16;\n Status : Boolean;\n Timeout_Mclks : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n\n begin\n case Step is\n when TCC | DSS | MSRC =>\n Read (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,\n Encoded_UInt8, Status);\n if Status then\n Timeout_Mclks := Decode_Timeout (UInt16 (Encoded_UInt8));\n end if;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n\n when Pre_Range =>\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n\n when Final_Range =>\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if Sequence_Steps (Pre_Range) then\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n else\n Timeout_Mclks := 0;\n end if;\n\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Final_Range);\n\n Read (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n Timeout_Mclks :=\n Decode_Timeout (Encoded_UInt16) - Timeout_Mclks;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n end case;\n end Sequence_Step_Timeout;\n\n -------------------------------\n -- Measurement_Timing_Budget --\n -------------------------------\n\n function Measurement_Timing_Budget\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt32\n is\n Ret : UInt32;\n Pre_Range_Timeout : UInt32;\n Final_Range_Timeout : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Msrc_Dcc_Tcc_Timeout : UInt32;\n\n begin\n Ret := Start_Overhead + End_Overhead;\n\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if Sequence_Steps (TCC)\n or else Sequence_Steps (MSRC)\n or else Sequence_Steps (DSS)\n then\n Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);\n if Sequence_Steps (TCC) then\n Ret := Ret + Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;\n end if;\n if Sequence_Steps (DSS) then\n Ret := Ret + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);\n elsif Sequence_Steps (MSRC) then\n Ret := Ret + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;\n end if;\n end if;\n\n if Sequence_Steps (Pre_Range) then\n Pre_Range_Timeout := Sequence_Step_Timeout (This, Pre_Range);\n Ret := Ret + Pre_Range_Timeout + Pre_Range_Overhead;\n end if;\n\n if Sequence_Steps (Final_Range) then\n Final_Range_Timeout := Sequence_Step_Timeout (This, Final_Range);\n Ret := Ret + Final_Range_Timeout + Final_Range_Overhead;\n end if;\n\n return Ret;\n end Measurement_Timing_Budget;\n\n -----------------------------------\n -- Set_Measurement_Timing_Budget --\n -----------------------------------\n\n procedure Set_Measurement_Timing_Budget\n (This : VL53L0X_Ranging_Sensor;\n Budget_Micro_Seconds : HAL.UInt32;\n Status : out Boolean)\n is\n Final_Range_Timing_Budget_us : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Pre_Range_Timeout_us : UInt32 := 0;\n Sub_Timeout : UInt32 := 0;\n Msrc_Dcc_Tcc_Timeout : UInt32;\n\n begin\n Status := True;\n\n Final_Range_Timing_Budget_us :=\n Budget_Micro_Seconds - Start_Overhead - End_Overhead\n - Final_Range_Overhead;\n\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if not Sequence_Steps (Final_Range) then\n return;\n end if;\n\n if Sequence_Steps (TCC)\n or else Sequence_Steps (MSRC)\n or else Sequence_Steps (DSS)\n then\n Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);\n\n if Sequence_Steps (TCC) then\n Sub_Timeout := Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;\n end if;\n\n if Sequence_Steps (DSS) then\n Sub_Timeout :=\n Sub_Timeout + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);\n\n elsif Sequence_Steps (MSRC) then\n Sub_Timeout := Sub_Timeout + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;\n end if;\n end if;\n\n if Sequence_Steps (Pre_Range) then\n Pre_Range_Timeout_us := Sequence_Step_Timeout (This, Pre_Range);\n\n Sub_Timeout :=\n Sub_Timeout + Pre_Range_Timeout_us + Pre_Range_Overhead;\n end if;\n\n if Sub_Timeout < Final_Range_Timing_Budget_us then\n Final_Range_Timing_Budget_us :=\n Final_Range_Timing_Budget_us - Sub_Timeout;\n\n else\n -- Requested timeout too big\n Status := False;\n\n return;\n end if;\n\n declare\n VCSel_Pulse_Period_Pclk : UInt8;\n Encoded_UInt16 : UInt16;\n Timeout_Mclks : UInt32;\n begin\n if Sequence_Steps (Pre_Range) then\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n else\n Timeout_Mclks := 0;\n end if;\n\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Final_Range);\n\n Timeout_Mclks := Timeout_Mclks + To_Timeout_Mclks\n (Final_Range_Timing_Budget_us,\n VCSel_Pulse_Period_Pclk);\n\n Write (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encode_Timeout (Timeout_Mclks), Status);" + }, + { + "function_def": "function To_U32 is new Ada.Unchecked_Conversion", + "function_body": "(Fix_Point_16_16, UInt32);\n Val : UInt16;\n Status : Boolean;\n begin\n -- Expecting Fixed Point 9.7\n Val := UInt16 (Shift_Right (To_U32 (Limit_Mcps), 9) and 16#FF_FF#);\n Write (This,\n REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Val,\n Status);\n return Status;\n end Set_Signal_Rate_Limit;\n\n ---------------\n -- SPAD_Info --\n ---------------\n\n function SPAD_Info\n (This : VL53L0X_Ranging_Sensor;\n SPAD_Count : out HAL.UInt8;\n Is_Aperture : out Boolean) return Boolean\n is\n Status : Boolean;\n Tmp : UInt8;\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp or 16#04#, Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#07#), Status);\n end if;\n if Status then\n Write (This, 16#81#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#80#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#94#, UInt8'(16#6B#), Status);\n end if;\n if Status then\n Write (This, 16#83#, UInt8'(16#00#), Status);\n end if;\n\n loop\n exit when not Status;\n Read (This, 16#83#, Tmp, Status);\n exit when Tmp /= 0;\n end loop;\n\n if Status then\n Write (This, 16#83#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Read (This, 16#92#, Tmp, Status);\n end if;\n\n if Status then\n SPAD_Count := Tmp and 16#7F#;\n Is_Aperture := (Tmp and 16#80#) /= 0;\n\n Write (This, 16#81#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp and not 16#04#, Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n return Status;\n end SPAD_Info;\n\n ---------------------------\n -- Set_Signal_Rate_Limit --\n ---------------------------\n\n procedure Set_Signal_Rate_Limit\n (This : VL53L0X_Ranging_Sensor;\n Rate_Limit : Fix_Point_16_16)\n is\n function To_U32 is new Ada.Unchecked_Conversion\n (Fix_Point_16_16, UInt32);\n Reg : UInt16;\n Status : Boolean with Unreferenced;\n begin\n -- Encoded as Fixed Point 9.7. Let's translate.\n Reg := UInt16 (Shift_Right (To_U32 (Rate_Limit), 9) and 16#FFFF#);\n Write (This, REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Reg, Status);\n end Set_Signal_Rate_Limit;\n\n --------------------------------------\n -- Set_Vcsel_Pulse_Period_Pre_Range --\n --------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Pre_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Pre_Range, Status);\n end Set_VCSEL_Pulse_Period_Pre_Range;\n\n ----------------------------------------\n -- Set_Vcsel_Pulse_Period_Final_Range --\n ----------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Final_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Final_Range, Status);\n end Set_VCSEL_Pulse_Period_Final_Range;\n\n ----------------------------\n -- Set_VCSel_Pulse_Period --\n ----------------------------\n\n procedure Set_VCSel_Pulse_Period\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Sequence : VL53L0x_Sequence_Step;\n Status : out Boolean)\n is\n Encoded : constant UInt8 := Shift_Right (Period, 1) - 1;\n Phase_High : UInt8;\n Pre_Timeout : UInt32;\n Final_Timeout : UInt32;\n Msrc_Timeout : UInt32;\n Timeout_Mclks : UInt32;\n Steps_Enabled : constant VL53L0x_Sequence_Step_Enabled :=\n Sequence_Step_Enabled (This);\n Budget : UInt32;\n Sequence_Cfg : UInt8;\n\n begin\n -- Save the measurement timing budget\n Budget := Measurement_Timing_Budget (This);\n\n case Sequence is\n when Pre_Range =>\n Pre_Timeout := Sequence_Step_Timeout (This, Pre_Range);\n Msrc_Timeout := Sequence_Step_Timeout (This, MSRC);\n\n case Period is\n when 12 =>\n Phase_High := 16#18#;\n when 14 =>\n Phase_High := 16#30#;\n when 16 =>\n Phase_High := 16#40#;\n when 18 =>\n Phase_High := 16#50#;\n when others =>\n Status := False;\n\n return;\n end case;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,\n Encoded, Status);\n if not Status then\n return;\n end if;\n\n -- Update the timeouts\n Timeout_Mclks := To_Timeout_Mclks (Pre_Timeout, Period);\n Write (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n UInt16 (Timeout_Mclks), Status);\n\n Timeout_Mclks := To_Timeout_Mclks (Msrc_Timeout, Period);\n if Timeout_Mclks > 256 then\n Timeout_Mclks := 255;\n else\n Timeout_Mclks := Timeout_Mclks - 1;\n end if;\n\n Write (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,\n UInt8 (Timeout_Mclks), Status);\n\n when Final_Range =>\n Pre_Timeout := Sequence_Step_Timeout\n (This, Pre_Range, As_Mclks => True);\n Final_Timeout := Sequence_Step_Timeout (This, Final_Range);\n\n declare\n Phase_High : UInt8;\n Width : UInt8;\n Cal_Timeout : UInt8;\n Cal_Lim : UInt8;\n begin\n case Period is\n when 8 =>\n Phase_High := 16#10#;\n Width := 16#02#;\n Cal_Timeout := 16#0C#;\n Cal_Lim := 16#30#;\n when 10 =>\n Phase_High := 16#28#;\n Width := 16#03#;\n Cal_Timeout := 16#09#;\n Cal_Lim := 16#20#;\n when 12 =>\n Phase_High := 16#38#;\n Width := 16#03#;\n Cal_Timeout := 16#08#;\n Cal_Lim := 16#20#;\n when 14 =>\n Phase_High := 16#48#;\n Width := 16#03#;\n Cal_Timeout := 16#07#;\n Cal_Lim := 16#20#;\n when others =>\n return;\n end case;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_GLOBAL_CONFIG_VCSEL_WIDTH,\n Width, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_ALGO_PHASECAL_CONFIG_TIMEOUT,\n Cal_Timeout, Status);\n if not Status then\n return;\n end if;\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, REG_ALGO_PHASECAL_LIM,\n Cal_Lim, Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n if not Status then\n return;\n end if;" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT6206_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n begin\n if Touch_Id not in FT6206_Px_Regs'Range then\n return (0, 0, 0);\n end if;\n\n if Touch_Id > This.Active_Touch_Points then\n return (0, 0, 0);\n end if;\n\n -- X/Y are swaped from the screen coordinates\n\n Regs := FT6206_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n if Ret.Weight = 0 then\n Ret.Weight := 50;\n end if;\n\n Ret.X := Natural'Max (0, Ret.X);\n Ret.Y := Natural'Max (0, Ret.Y);\n Ret.X := Natural'Min (This.LCD_Natural_Width - 1, Ret.X);\n Ret.Y := Natural'Min (This.LCD_Natural_Height - 1, Ret.Y);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "function Read_Register (This : STMPE811_Device;", + "function_body": "Reg_Addr : UInt8) return UInt8\n is\n Data : TSC_Data (1 .. 1);\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Read (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n Data,\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n return Data (1);\n end Read_Register;\n\n --------------------\n -- Write_Register --\n --------------------\n\n procedure Write_Register (This : in out STMPE811_Device;\n Reg_Addr : UInt8;\n Data : UInt8) is\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Write (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n (1 => Data),\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n end Write_Register;\n\n ---------------\n -- IOE_Reset --\n ---------------\n\n procedure IOE_Reset (This : in out STMPE811_Device) is\n begin\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#02#);\n\n -- Give some time for the reset\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#00#);\n end IOE_Reset;\n\n --------------------------\n -- IOE_Function_Command --\n --------------------------\n\n procedure IOE_Function_Command (This : in out STMPE811_Device;\n Func : UInt8;\n Enabled : Boolean)\n is\n Reg : UInt8 := This.Read_Register (IOE_REG_SYS_CTRL2);\n begin\n -- CTRL2 functions are disabled when corresponding bit is set\n\n if Enabled then\n Reg := Reg and (not Func);\n else\n Reg := Reg or Func;\n end if;\n\n This.Write_Register (IOE_REG_SYS_CTRL2, Reg);\n end IOE_Function_Command;\n\n -------------------\n -- IOE_AF_Config --\n -------------------\n\n procedure IOE_AF_Config (This : in out STMPE811_Device;\n Pin : UInt8;\n Enabled : Boolean) is\n Reg : UInt8 := This.Read_Register (IOE_REG_GPIO_AF);\n begin\n if Enabled then\n Reg := Reg or Pin;\n else\n Reg := Reg and (not Pin);\n end if;\n\n This.Write_Register (IOE_REG_GPIO_AF, Reg);\n end IOE_AF_Config;\n\n ----------------\n -- Get_IOE_ID --\n ----------------\n\n function Get_IOE_ID (This : in out STMPE811_Device) return UInt16 is\n begin\n return (UInt16 (This.Read_Register (0)) * (2**8))\n or UInt16 (This.Read_Register (1));\n end Get_IOE_ID;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize (This : in out STMPE811_Device) return Boolean\n is\n begin\n\n This.Time.Delay_Milliseconds (100);\n\n if This.Get_IOE_ID /= 16#0811# then\n return False;\n end if;\n\n This.IOE_Reset;\n\n This.IOE_Function_Command (IOE_ADC_FCT, True);\n This.IOE_Function_Command (IOE_TSC_FCT, True);\n\n This.Write_Register (IOE_REG_ADC_CTRL1, 16#49#);\n\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_ADC_CTRL2, 16#01#);\n\n This.IOE_AF_Config (TOUCH_IO_ALL, False);\n\n This.Write_Register (IOE_REG_TSC_CFG, 16#9A#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_FRACT_Z, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_I_DRIVE, 16#01#);\n\n This.Write_Register (IOE_REG_TSC_CTRL, 16#01#);\n\n This.Write_Register (IOE_REG_INT_STA, 16#FF#);\n\n return True;\n end Initialize;\n\n ----------------\n -- Set_Bounds --\n ----------------\n\n overriding\n procedure Set_Bounds (This : in out STMPE811_Device;\n Width : Natural;\n Height : Natural;\n Swap : HAL.Touch_Panel.Swap_State)\n is\n begin\n This.LCD_Natural_Width := Width;\n This.LCD_Natural_Height := Height;\n This.Swap := Swap;\n end Set_Bounds;\n\n -------------------------\n -- Active_Touch_Points --\n -------------------------\n\n overriding\n function Active_Touch_Points (This : in out STMPE811_Device)\n return Touch_Identifier\n is\n Val : constant UInt8 := This.Read_Register (IOE_REG_TSC_CTRL) and 16#80#;\n begin\n if Val = 0 then\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n This.Write_Register (IOE_REG_FIFO_STA, 16#00#);\n\n return 0;\n else\n return 1;\n end if;\n end Active_Touch_Points;\n\n ---------------------\n -- Get_Touch_Point --\n ---------------------\n\n overriding\n function Get_Touch_Point (This : in out STMPE811_Device;\n Touch_Id : Touch_Identifier)\n return TP_Touch_State\n is\n State : TP_Touch_State;\n Raw_X : UInt32;\n Raw_Y : UInt32;\n Raw_Z : UInt32;\n X : Integer;\n Y : Integer;\n Tmp : Integer;\n\n begin\n\n -- Check Touch detected bit in CTRL register\n if Touch_Id /= 1 or else This.Active_Touch_Points = 0 then\n return (0, 0, 0);\n end if;\n\n declare\n Data_X : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_X, 2);\n Data_Y : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Y, 2);\n Data_Z : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Z, 1);\n Z_Frac : constant TSC_Data := This.Read_Data (IOE_REG_TSC_FRACT_Z, 1);\n\n begin\n Raw_X := 2 ** 12 -\n (Shift_Left (UInt32 (Data_X (1)) and 16#0F#, 8) or UInt32 (Data_X (2)));\n Raw_Y :=\n Shift_Left (UInt32 (Data_Y (1)) and 16#0F#, 8) or UInt32 (Data_Y (2));\n Raw_Z :=\n Shift_Right (UInt32 (Data_Z (1)), Natural (Z_Frac (1) and 2#111#));" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT5336_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n\n begin\n -- X/Y are swaped from the screen coordinates\n\n if Touch_Id not in FT5336_Px_Regs'Range\n or else Touch_Id > This.Active_Touch_Points\n then\n return (0, 0, 0);\n end if;\n\n Regs := FT5336_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n Ret.X :=\n Natural'Min (Natural'Max (0, Ret.X), This.LCD_Natural_Width - 1);\n Ret.Y :=\n Natural'Min (Natural'Max (0, Ret.Y), This.LCD_Natural_Height - 1);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "procedure Destroy is new Ada.Unchecked_Deallocation", + "function_body": "(File_Handle, File_Handle_Access);\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Directory_Handle, Directory_Handle_Access);\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Node_Handle, Node_Handle_Access);\n\n function \"<\" (Left, Right : Node_Handle) return Boolean is\n (Ada.Strings.Unbounded.\"<\" (Left.Name, Right.Name));\n\n package Node_Sorting is\n new Node_Vectors.Generic_Sorting;\n\n -- Most of the time, standard operations give us no reliable way to\n -- determine specifically what triggered a failure, so use the following\n -- error code as a \"generic\" one.\n\n Generic_Error : constant Status_Code := Input_Output_Error;\n\n function Absolute_Path\n (This : Native_FS_Driver;\n Relative_Path : String)\n return String\n is (if Relative_Path = \"\"\n then +This.Root_Dir\n else Join (+This.Root_Dir, Relative_Path, True));\n\n ----------------\n -- Get_Handle --\n ----------------\n\n function Get_Handle\n (FS : in out Native_FS_Driver)\n return File_Handle_Access\n is\n Result : File_Handle_Access := FS.Free_File_Handles;\n begin\n if Result = null then\n Result := new File_Handle'\n (FS => FS'Unrestricted_Access,\n others => <>);\n else\n FS.Free_File_Handles := Result.Next;\n end if;\n return Result;\n end Get_Handle;\n\n ----------------\n -- Get_Handle --\n ----------------\n\n function Get_Handle\n (FS : in out Native_FS_Driver)\n return Directory_Handle_Access\n is\n Result : Directory_Handle_Access := FS.Free_Dir_Handles;\n begin\n if Result = null then\n Result := new Directory_Handle'\n (FS => FS'Unrestricted_Access,\n others => <>);\n else\n FS.Free_Dir_Handles := Result.Next;\n end if;\n return Result;\n end Get_Handle;\n\n ---------------------\n -- Add_Free_Handle --\n ---------------------\n\n procedure Add_Free_Handle\n (FS : in out Native_FS_Driver;\n Handle : in out File_Handle_Access)\n is\n begin\n Handle.Next := FS.Free_File_Handles;\n FS.Free_File_Handles := Handle;\n Handle := null;\n end Add_Free_Handle;\n\n ---------------------\n -- Add_Free_Handle --\n ---------------------\n\n procedure Add_Free_Handle\n (FS : in out Native_FS_Driver;\n Handle : in out Directory_Handle_Access)\n is\n begin\n Handle.Next := FS.Free_Dir_Handles;\n FS.Free_Dir_Handles := Handle;\n Handle := null;\n end Add_Free_Handle;\n\n -------------\n -- Destroy --\n -------------\n\n procedure Destroy (This : in out Native_FS_Driver_Access) is\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Native_FS_Driver, Native_FS_Driver_Access);\n begin\n -- Free all handles\n\n while This.Free_File_Handles /= null loop\n declare\n H : constant File_Handle_Access := This.Free_File_Handles.Next;\n begin\n Destroy (This.Free_File_Handles);\n This.Free_File_Handles := H;" + }, + { + "function_def": "procedure update_Enn is", + "function_body": "begin\n if Next_Ennmie = 0 then\n for i in Ennmies'First .. Ennmies'Last loop\n if Ennmies(i).State = DEAD then\n Ennmie.appear_enn(Ennmies(i), RANDOM(G), MAX_HEIGHT -5 , MAX_HEIGHT, MAX_WIDTH);\n exit;\n end if;\n end loop;\n Next_Ennmie := 50;\n else\n Next_Ennmie := Next_Ennmie - 1;\n end if;\n if Next_Enemie_Move = 0 then\n for i in Ennmies'First .. Ennmies'Last loop\n if Ennmies(i).State = DMG_DEALT then\n Ennmies(i).State := DEAD;\n end if;\n if Ennmies(i).State /= DEAD then\n Ennmie.move_enn(Ennmies(i));\n end if;\n end loop;\n Next_Enemie_Move := 2;\n else\n Next_Enemie_Move := Next_Enemie_Move - 1;\n end if;\n end update_Enn;\n\n procedure update(X : Integer; Y : Integer) is\n begin\n if Next_missile = 0 then\n for i in Missiles'First .. Missiles'Last loop\n if Missiles(i).State = DEAD then\n Missile.appear_mis(Missiles(i), space.X, space.Y, Height);\n exit;\n end if;\n end loop;\n Next_missile := 20;\n else\n Next_missile := Next_missile - 1;\n end if;\n for i in Missiles'First .. Missiles'Last loop\n if Missiles(i).State /= DEAD then\n Missile.move_mis(Missiles(i));\n end if;\n if Missiles(i).State = TOUCHED then\n Missiles(i).State := DEAD;\n end if;\n end loop;\n update_Enn;\n for i in Missiles'First .. Missiles'Last loop\n if Missiles(i).State = ALIVE then\n for j in Ennmies'First .. Ennmies'Last loop\n if Ennmies(j).State = ALIVE then\n ishit(Missiles(i), Ennmies(j));\n end if;\n end loop;\n end if;\n end loop;\n if X = 0 then\n return;\n end if;\n space.X := X;\n space.Y := Y;\n end update;\n\n procedure draw_mis(s : in Missile.Missile) is\n begin\n if s.State = DEAD then\n return;\n end if;\n\n Bitmap_Buffer.Set_Source (HAL.Bitmap.Yellow);\n Bitmap_Buffer.Fill_Rect ((Position => (s.X, s.Y),\n Width => Width / 80,\n Height => Height / 80));\n end draw_mis;\n\n procedure draw_space(s : in out Spaceship.Spaceship; X : Integer; Y : Integer) is\n begin\n s.X := X;\n s.Y := Y;\n if s.State = ALIVE then\n Bitmap_Buffer.Set_Source (HAL.Bitmap.Blue);\n else if s.State = DMG_DEALT then\n Bitmap_Buffer.Set_Source (HAL.Bitmap.White);\n end if;\n end if;\n Bitmap_Buffer.Fill_Rect ((Position => (X, Y),\n Width => Width / 8,\n Height => Height / 8));\n end draw_space;\n\n procedure draw_enn(e : in Ennmie.Ennmie) is\n begin\n if e.State = DEAD then\n return;\n end if;\n if e.State = ALIVE then\n Bitmap_Buffer.Set_Source (HAL.Bitmap.Red);\n else if e.State = DMG_DEALT then\n Bitmap_Buffer.Set_Source (HAL.Bitmap.White);\n end if;\n end if;\n Bitmap_Buffer.Fill_Rect ((Position => (e.X, e.Y),\n Width => Width / 12,\n Height => Height / 12));\n end draw_enn;\n\n procedure draw(X : Integer; Y : Integer) is\n begin\n draw_space(space, X, Y);\n for i in Missiles'First .. Missiles'Last loop\n draw_mis(Missiles(i));\n end loop;\n for i in Ennmies'First .. Ennmies'Last loop\n draw_enn(Ennmies(i));\n end loop;\n end draw;\n\nbegin\n Reset(G);\n -- Initialize LCD\n Display.Initialize;\n Display.Initialize_Layer (1, HAL.Bitmap.ARGB_8888);\n\n Touch_Panel.Initialize;\n\n Width := Bitmap_Buffer.Width;\n Height := Bitmap_Buffer.Height;\n\n space.Y := 20;\n space.X := Width/2;\n loop\n declare\n State : constant TP_State := Touch_Panel.Get_All_Touch_Points;\n begin\n if State'Length > 0 then\n X_Coord := State (State'First).X;\n Y_Coord := State (State'First).Y;\n end if;" + }, + { + "function_def": "procedure Clear;", + "function_body": "-----------\n -- Clear --\n -----------\n\n procedure Clear is\n begin\n Display.Hidden_Buffer (1).Set_Source (BG);\n Display.Hidden_Buffer (1).Fill;\n\n LCD_Std_Out.Clear_Screen;\n LCD_Std_Out.Put_Line (\"Touch the screen to draw or\");\n LCD_Std_Out.Put_Line (\"press the blue button for\");\n LCD_Std_Out.Put_Line (\"a demo of drawing primitives.\");\n\n Display.Update_Layer (1, Copy_Back => True);\n end Clear;\n\n Last_X : Integer := -1;\n Last_Y : Integer := -1;\n\n type Mode is (Drawing_Mode, Bitmap_Showcase_Mode);\n\n Current_Mode : Mode := Drawing_Mode;\n\nbegin\n\n -- Initialize LCD\n Display.Initialize;\n Display.Initialize_Layer (1, ARGB_8888);\n\n -- Initialize touch panel\n Touch_Panel.Initialize;\n\n -- Initialize button\n User_Button.Initialize;\n\n LCD_Std_Out.Set_Font (BMP_Fonts.Font8x8);\n LCD_Std_Out.Current_Background_Color := BG;\n\n -- Clear LCD (set background)\n Clear;\n\n -- The application: set pixel where the finger is (so that you\n -- cannot see what you are drawing).\n loop\n if User_Button.Has_Been_Pressed then\n case Current_Mode is\n when Drawing_Mode =>\n Current_Mode := Bitmap_Showcase_Mode;\n when Bitmap_Showcase_Mode =>\n Clear;\n Current_Mode := Drawing_Mode;\n end case;\n end if;\n\n if Current_Mode = Drawing_Mode then\n\n Display.Hidden_Buffer (1).Set_Source (HAL.Bitmap.Green);\n\n declare\n State : constant TP_State := Touch_Panel.Get_All_Touch_Points;\n begin\n if State'Length = 0 then\n Last_X := -1;\n Last_Y := -1;\n\n elsif State'Length = 1 then\n -- Lines can be drawn between two consecutive points only when\n -- one touch point is active: the order of the touch data is not\n -- necessarily preserved by the hardware.\n if Last_X > 0 then\n Draw_Line\n (Display.Hidden_Buffer (1).all,\n Start => (Last_X, Last_Y),\n Stop => (State (State'First).X, State (State'First).Y),\n Thickness => State (State'First).Weight / 2,\n Fast => False);\n end if;\n\n Last_X := State (State'First).X;\n Last_Y := State (State'First).Y;\n\n else\n Last_X := -1;\n Last_Y := -1;\n end if;\n\n for Id in State'Range loop\n Fill_Circle\n (Display.Hidden_Buffer (1).all,\n Center => (State (Id).X, State (Id).Y),\n Radius => State (Id).Weight / 4);\n end loop;\n\n if State'Length > 0 then\n Display.Update_Layer (1, Copy_Back => True);\n end if;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => T_Cellule, Name => T_Registre);\n\n\n\t-- Trouver si une cl\u00e9 est d\u00e9j\u00e0 pr\u00e9sente ou non, utilis\u00e9e dans Creer_Cle\n\t-- Param\u00e8tres :\n\t--\t\t\t\tReg : in T_Registre\t Registre dans lequel on cherche\n\t--\t\t\t\tCle : in Entier\t\t Cl\u00e9 provisoire en attente d'unicit\u00e9\n\tfunction Est_Present(Reg : in T_Registre; Cle : in Integer; X : in out Integer) return Integer is\n\tbegin\n\t\tif Reg = Null then\n\t\t\treturn X;\n\t\telsif Reg.all.Cle < Cle then\n\t\t\treturn Est_Present (Reg.all.Sous_Arbre_Droit, Cle, X);\n\t\telsif Reg.all.Cle > Cle then\n\t\t\treturn Est_Present (Reg.all.Sous_Arbre_Gauche, Cle, X);\n\t\telse -- { Reg.all.Cle = Cle }\n\t\t\tX := X + 1;\n\t\t\t-- On relance une recherche sur la cl\u00e9 Cle + 1\n\t\t\treturn Est_Present(Reg, Cle+1, X);\n\t\tend if;\n\tend Est_Present;\n\n\n procedure Creer_Cle (Reg : in T_Registre; Cle : out Integer; Donnee : in T_Donnee) is\n\t\tX : Integer;\n\t\tCle_Provisoire : Integer;\n begin\n\t\t-- On cherche si d'autres individus sont n\u00e9s le m\u00eame jour\n\t\tCle_Provisoire := 100000000 * Donnee.Mois_N + 1000000 * Donnee.Jour_N + 100*Donnee.Annee_N;\n\t\tX := 0;\n\n\t\t-- Si la cl\u00e9 est d\u00e9j\u00e0 pr\u00e9sente on incr\u00e9mente X et on cherche si la cl\u00e9 avec X+1 est pr\u00e9sente etc...\n\t\tX := Est_Present (Reg, Cle_Provisoire, X);\n\n\t\t-- Finalement on change la cl\u00e9 !\n Cle := Cle_Provisoire + X;\n end Creer_Cle;\n\n\n procedure Initialiser_Donnee ( Donnee : out T_Donnee;\n Nom : in unbounded_string;\n Prenom : in unbounded_string;\n Jour_N : in Integer;\n Mois_N : in Integer;\n Annee_N : in Integer;\n Sexe : in Character) is\n begin\n Donnee.Nom := Nom;\n Donnee.Prenom := Prenom;\n Donnee.Jour_N := Jour_N;\n Donnee.Mois_N := Mois_N;\n Donnee.Annee_N := Annee_N;\n Donnee.Sexe := Sexe;\n end Initialiser_Donnee;\n\n\n\tprocedure Initialiser_Reg(Reg: out T_Registre; Cle : in Integer; Donnee : in T_Donnee) is\n\t\tCellule : T_Registre;\n\tbegin\n\t\tCellule := new T_Cellule;\n Cellule.all.Cle := Cle;\n Cellule.all.Sous_Arbre_Droit := null;\n Cellule.all.Sous_Arbre_Gauche := null;\n\t\tCellule.all.Donnee := Donnee;\n Reg := Cellule;\n\tend Initialiser_Reg;\n\n\n\tfunction Est_Vide (Reg : T_Registre) return Boolean is\n\tbegin\n\t\treturn Reg = Null;" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Test_Event_Base'Class,\n Name => Test_Event_Access);\n\n begin\n\n N_E.Event.Clean_Up;\n Free (N_E.Event);\n\n end Clean_Up_Events;\n\n -----------------------------------------------------\n\n begin\n\n Obj.Active_Node_Map.Clear;\n\n Obj.Event_Vector.Iterate (Clean_Up_Events'Access);\n Obj.Event_Vector.Clear;\n\n Obj.Node_Data_Tree.Clear;\n\n end Reset;\n\n ----------------------------------------------------------------------------\n\n overriding\n function Is_Active (Obj : Test_Reporter_Data;\n Node_Tag : Tag) return Boolean\n is (Obj.Active_Node_Map.Contains (Node_Tag));\n\n ----------------------------------------------------------------------------\n\n overriding\n procedure Include_Node (Obj : in out Test_Reporter_Data;\n Node_Lineage : Tag_Array) is\n\n C : Cursor := Root (Obj.Node_Data_Tree);\n\n begin\n\n for T of Node_Lineage loop\n\n declare\n\n Insertion_Required : Boolean := Is_Leaf (C);\n\n begin\n\n for Child_C in Obj.Node_Data_Tree.Iterate_Children (C) loop\n\n if Element (Child_C).T = T then\n C := Child_C;\n exit;\n end if;\n\n Insertion_Required := Child_C = Last_Child (C);\n\n end loop;\n\n if Insertion_Required then\n\n declare\n Position : Cursor;\n begin\n Obj.Node_Data_Tree.Insert_Child\n (Parent => C,\n Before => No_Element,\n New_Item => (T => T,\n Event_Index_Vector => <>),\n Position => Position);\n C := Position;" + }, + { + "function_def": "procedure Update_Map_With_Work_Data is", + "function_body": "C : constant Cursor := M.Find (T);\n begin\n if C = No_Element then\n M.Insert (Key => T,\n New_Item => S);\n else\n M.Replace_Element (Position => C,\n New_Item => S);\n end if;\n end Update_Map_With_Work_Data;\n\n procedure Extract_Work_Data is\n C : constant Cursor := M.Find (Node_Tag);\n begin\n T := Node_Tag;\n S := (if C = No_Element then\n Initial_Routine_State\n else\n Element (C));\n end Extract_Work_Data;\n\n begin\n\n if T /= Node_Tag then\n\n if T /= No_Tag then\n Update_Map_With_Work_Data;\n end if;\n\n Extract_Work_Data;\n\n end if;\n\n end Switch_Key_If_Needed;\n\n -----------------------------------------------------\n\n procedure Reset_Routine_State (Node_Tag : Tag;\n Routine_Index : Test_Routine_Index) is\n\n begin\n\n Switch_Key_If_Needed (Node_Tag);\n S := Initial_Routine_State (Routine_Index);\n\n end Reset_Routine_State;\n\n -----------------------------------------------------\n\n procedure Increment_Assert_Count (Node_Tag : Tag) is\n\n begin\n\n Switch_Key_If_Needed (Node_Tag);\n Prot_Test_Assert_Count.Inc (S.Assert_Count);\n\n end Increment_Assert_Count;\n\n -----------------------------------------------------\n\n procedure Set_Failed_Outcome (Node_Tag : Tag) is\n\n begin\n\n Switch_Key_If_Needed (Node_Tag);\n S.Assert_Outcome := Failed;\n\n end Set_Failed_Outcome;\n\n -----------------------------------------------------\n\n procedure Get_Assert_Count (Node_Tag : Tag;\n Routine_Index : out Test_Routine_Index;\n Count : out O_P_I_Test_Assert_Count)\n is\n\n begin\n\n Switch_Key_If_Needed (Node_Tag);\n Routine_Index := S.Routine_Index;\n Count := S.Assert_Count;\n\n end Get_Assert_Count;\n\n -----------------------------------------------------\n\n procedure Get_Assert_Outcome (Node_Tag : Tag;\n Outcome : out Test_Outcome) is\n\n begin\n\n Switch_Key_If_Needed (Node_Tag);\n Outcome := S.Assert_Outcome;\n\n end Get_Assert_Outcome;\n\n -----------------------------------------------------\n\n procedure Delete (Node_Tag : Tag) is\n\n use Routine_State_Hashed_Maps;\n\n begin\n\n if M.Length = 0 then\n T := No_Tag;\n else\n\n declare\n C : Cursor := M.Find (Node_Tag);\n begin\n\n if C /= No_Element then\n M.Delete (C);\n end if;\n\n if T = Node_Tag and then M.Length > 0 then\n declare\n C_First : constant Cursor := M.First;\n begin\n T := Key (C_First);\n S := Element (C_First);" + }, + { + "function_def": "procedure Populate_Current is", + "function_body": "begin\n if N /= 0 then\n Ret(1).T := T;\n Ret(1).S := S;\n end if;\n end Populate_Current;\n\n procedure Populate_Others is\n K : Index_Type := 1;\n procedure Process (C : Cursor) is\n Key_C : constant Tag := Key (C);\n begin\n if Key_C /= T then\n K := K + 1;\n Ret(K).T := Key_C;\n Ret(K).S := Element (C);\n end if;\n end Process;\n begin\n M.Iterate (Process'Access);\n Ada.Assertions.Assert ((N = 0 and then K = 1)\n or else\n (N > 0 and then K = N));\n end Populate_Others;\n\n begin\n\n Populate_Current;\n Populate_Others;\n return Ret;\n\n end To_Array;\n\n -----------------------------------------------------\n\n end Routine_State_Map_Handler;\n\n ----------------------------------------------------------------------------\n\n procedure Run_Test_Routines (Obj : Test_Node_Interfa'Class;\n Outcome : out Test_Outcome;\n Kind : Run_Kind) is\n\n use Ada.Assertions,\n Private_Test_Reporter;\n\n pragma Unreferenced (Kind);\n\n T : constant Tag := Obj'Tag;\n\n K : Test_Routine_Count := 0;\n R : Test_Routine := Null_Test_Routine'Access;\n Err : Boolean := False; -- \"Unexpected error\" flag.\n\n -----------------------------------------------------\n\n function Done return Boolean is\n\n N : constant Test_Routine_Count := Obj.Routine_Count;\n Ret : Boolean := K >= N;\n\n begin\n\n if Err and then not Ret then\n Ret := True;\n Outcome := Failed;\n Test_Reporter.Report_Test_Routines_Cancellation (Obj'Tag,\n K + 1,\n N);\n end if;\n\n return Ret;\n\n end Done;\n\n -----------------------------------------------------\n\n begin\n\n Outcome := Passed;\n\n while not Done loop\n\n K := K + 1;\n Err := True;\n\n Routine_State_Map_Handler.Reset_Routine_State (T, K);\n Test_Reporter.Report_Test_Routine_Start (T, K);\n\n begin\n\n R := Obj.Routine (K);\n\n begin\n\n Obj.Setup_Routine;\n\n declare\n Assert_Outcome : Test_Outcome;\n begin\n R.all;\n Err := False;\n Routine_State_Map_Handler.Get_Assert_Outcome\n (T, Assert_Outcome);\n case Assert_Outcome is\n when Failed =>\n raise Assertion_Error; -- Causes a jump to\n -- Assertion_Error handler\n -- below. Happens when a test\n -- assertion has failed but has\n -- been handled in the test\n -- routine.\n when Passed =>\n null;\n end case;\n Test_Reporter.Report_Passed_Test_Routine (T, K);\n exception\n when Run_E : Assertion_Error =>\n Routine_State_Map_Handler.Get_Assert_Outcome\n (T, Assert_Outcome);\n Err := False;\n Outcome := Failed;\n case Assert_Outcome is\n when Failed => -- Exception very likely originates in\n -- a failed test assertion and not in\n -- an \"unexpected error\".\n Test_Reporter.Report_Failed_Test_Routine (T, K);\n when Passed => -- Exception may originates in a failed\n -- contract.\n Test_Reporter.Report_Unexpected_Routine_Exception\n (T, K, Run_E);\n end case;\n when Run_E : others => -- Exception originates in an\n -- unexpected error.\n Test_Reporter.Report_Unexpected_Routine_Exception\n (T, K, Run_E);" + }, + { + "function_def": "procedure Unl_CB is", + "function_body": "begin\n\n if Unlock_CB /= null then\n Unlock_CB.all;\n end if;\n\n if Deallocation_Needed then\n\n declare\n\n procedure Free is new Ada.Unchecked_Deallocation\n (Object => Instance_Ancestor_Type'Class,\n Name => Instance_Type_Access);\n\n begin\n\n Deallocation_Needed := False;\n Free (Instance_Access);" + }, + { + "function_def": "procedure SB_Lock_CB_procedure_Test is", + "function_body": "procedure P_Null is new SB_Lock_CB_procedure (null);\n\n procedure P_Increment_N is new SB_Lock_CB_procedure (Increment_N'Access);\n\n begin\n\n P_Null;\n Assert (SBLF.N = 0);\n\n P_Increment_N;\n Assert (SBLF.N = 1);\n\n end SB_Lock_CB_procedure_Test;\n\n ----------------------------------------------------------------------------\n\n procedure Locked_Test is\n\n begin\n\n Assert (not Locked (SBLF.Lock));\n\n declare\n Locker : SB_L_Locker (SBLF.Lock'Access);\n pragma Unreferenced (Locker);\n begin\n Assert (Locked (SBLF.Lock));" + }, + { + "function_def": "procedure Locked_With_CB_Test is", + "function_body": "begin\n\n Assert (not Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 0);\n\n declare\n Locker : SB_L_Locker (SBLF.Lock_W_CB'Access);\n pragma Unreferenced (Locker);\n begin\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);" + }, + { + "function_def": "procedure Has_Actually_Locked_Test is", + "function_body": "begin\n\n declare\n Outer_Locker : SB_L_Locker (SBLF.Lock'Access);\n begin\n Assert (Outer_Locker.Has_Actually_Locked);\n\n declare\n Inner_Locker : SB_L_Locker (SBLF.Lock'Access);\n begin\n Assert (not Inner_Locker.Has_Actually_Locked);" + }, + { + "function_def": "procedure Has_Actually_Locked_With_CB_Test is", + "function_body": "begin\n\n declare\n Outer_Locker : SB_L_Locker (SBLF.Lock_W_CB'Access);\n begin\n Assert (Outer_Locker.Has_Actually_Locked);\n Assert (SBLF.N = 1);\n\n declare\n Inner_Locker : SB_L_Locker (SBLF.Lock_W_CB'Access);\n begin\n Assert (not Inner_Locker.Has_Actually_Locked);\n Assert (SBLF.N = 1);" + }, + { + "function_def": "procedure Allocator_Test is", + "function_body": "type SB_L_Locker_Access is access SB_L_Locker;\n\n procedure Free\n is new Ada.Unchecked_Deallocation (SB_L_Locker, SB_L_Locker_Access);\n\n Locker_Access_1, Locker_Access_2 : SB_L_Locker_Access;\n\n begin\n\n Assert (not Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 0);\n\n Locker_Access_1 := new SB_L_Locker (SBLF.Lock_W_CB'Access);\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);\n Assert (Locker_Access_1.Has_Actually_Locked);\n\n Locker_Access_2 := new SB_L_Locker (SBLF.Lock_W_CB'Access);\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);\n Assert (not Locker_Access_2.Has_Actually_Locked);\n\n Assert (Locker_Access_1.Has_Actually_Locked);\n Free (Locker_Access_1);\n Assert (Locker_Access_1 = null);\n Assert (not Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 0);\n\n Assert (not Locker_Access_2.Has_Actually_Locked);\n Free (Locker_Access_2);\n Assert (Locker_Access_2 = null);\n Assert (not Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 0);\n\n Locker_Access_1 := new SB_L_Locker (SBLF.Lock_W_CB'Access);\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);\n Assert (Locker_Access_1.Has_Actually_Locked);\n\n Locker_Access_2 := new SB_L_Locker (SBLF.Lock_W_CB'Access);\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);\n\n Assert (not Locker_Access_2.Has_Actually_Locked);\n Free (Locker_Access_2);\n Assert (Locker_Access_2 = null);\n Assert (Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 1);\n\n Assert (Locker_Access_1.Has_Actually_Locked);\n Free (Locker_Access_1);\n Assert (Locker_Access_1 = null);\n Assert (not Locked (SBLF.Lock_W_CB));\n Assert (SBLF.N = 0);" + }, + { + "function_def": "procedure Scope_Debug_Create_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n declare\n C_D_T : Controlled_Debug_Tracer := Create (\"Scope_Debug_Create_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 1);\n Assert (SDF.Scope_Exit_Count = 0);" + }, + { + "function_def": "procedure Scope_Debug_Create_A_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n declare\n C_D_T : Controlled_Debug_Tracer\n := Create_A (\"Scope_Debug_Create_A_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 1);\n Assert (SDF.Scope_Exit_Count = 0);" + }, + { + "function_def": "procedure Scope_Debug_Create_A_E_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n begin\n\n declare\n C_D_T : Controlled_Debug_Tracer\n := Create_A (\"Scope_Debug_Create_A_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 1);\n Assert (SDF.Scope_Exit_Count = 0);\n raise Program_Error;" + }, + { + "function_def": "procedure Scope_Debug_Create_I_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n declare\n C_D_T : Controlled_Debug_Tracer\n := Create_I (\"Scope_Debug_Create_I_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 1);\n Assert (SDF.Scope_Exit_Count = 0);" + }, + { + "function_def": "procedure Scope_Debug_Create_F_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n declare\n C_D_T : Controlled_Debug_Tracer\n := Create_F (\"Scope_Debug_Create_F_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);" + }, + { + "function_def": "procedure Scope_Debug_Create_N_Test is", + "function_body": "begin\n\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);\n\n declare\n C_D_T : Controlled_Debug_Tracer\n := Create_N (\"Scope_Debug_Create_N_Test\");\n pragma Unreferenced (C_D_T);\n begin\n Assert (SDF.Scope_Entry_Count = 0);\n Assert (SDF.Scope_Exit_Count = 0);" + }, + { + "function_def": "procedure Shared_Instance_Access_Setter_L_Null_CB_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_L;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n declare\n package Outer_A_S is new SIFLI_Shared_Instance_L.Access_Setter\n (Inst_Access => SIFLI_Concrete_1_Instance'Access);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance\n =\n SIFLI_Concrete_1_Instance'Access);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag = SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_A_S.Has_Actually_Set);\n\n declare\n package Inner_A_S is new SIFLI_Shared_Instance_L.Access_Setter\n (Inst_Access => SIFLI_Concrete_2_Instance'Access);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance\n =\n SIFLI_Concrete_1_Instance'Access);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag\n =\n SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_A_S.Has_Actually_Set);\n Assert (not Inner_A_S.Has_Actually_Set);" + }, + { + "function_def": "procedure Shared_Instance_Access_Setter_L_Null_CB_E_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_L;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n begin\n\n declare\n package Outer_A_S is new SIFLI_Shared_Instance_L.Access_Setter\n (Inst_Access => SIFLI_Concrete_1_Instance'Access);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance\n =\n SIFLI_Concrete_1_Instance'Access);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag\n =\n SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_A_S.Has_Actually_Set);\n raise Program_Error;" + }, + { + "function_def": "procedure Shared_Instance_Access_Setter_U_Null_CB_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_U;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_U.Locked);\n Assert (not SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n declare\n package Outer_A_S is new SIFLI_Shared_Instance_U.Access_Setter\n (Inst_Access => SIFLI_Concrete_2_Instance'Access);\n begin\n Assert (SIFLI_Shared_Instance_U.Locked);\n Assert (SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance\n =\n SIFLI_Concrete_2_Instance'Access);\n Assert (SIFLI_Shared_Instance_U.Instance'Tag = SIFLI_Concrete_2'Tag);\n Assert (SIFLI_Shared_Instance_U.Instance.Primitive = '2');\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_A_S.Has_Actually_Set);\n\n declare\n package Inner_A_S is new SIFLI_Shared_Instance_U.Access_Setter\n (Inst_Access => SIFLI_Concrete_2_Instance'Access);\n begin\n Assert (SIFLI_Shared_Instance_U.Locked);\n Assert (SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance\n =\n SIFLI_Concrete_2_Instance'Access);\n Assert (SIFLI_Shared_Instance_U.Instance'Tag\n =\n SIFLI_Concrete_2'Tag);\n Assert (SIFLI_Shared_Instance_U.Instance.Primitive = '2');\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_A_S.Has_Actually_Set);\n Assert (not Inner_A_S.Has_Actually_Set);" + }, + { + "function_def": "procedure Shared_Instance_Access_Setter_CB_Test is", + "function_body": "begin\n\n Assert (SIF.CB_Calls_Count = 0);\n\n declare\n package A_S is new SIFLI_Shared_Instance_L.Access_Setter\n (Inst_Access => SIFLI_Concrete_1_Instance'Access,\n CB => CB);\n pragma Unreferenced (A_S);\n begin\n Assert (SIF.CB_Calls_Count = 1);" + }, + { + "function_def": "procedure Shared_Instance_Creator_L_Null_CB_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_L;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n declare\n package Outer_C is new SIFLI_Shared_Instance_L.Creator\n (Allocate => Allocate_SIFLI_Concrete_1_L);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag = SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n\n declare\n package Inner_C is new SIFLI_Shared_Instance_L.Creator\n (Allocate => Allocate_SIFLI_Concrete_2_L);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag\n =\n SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n Assert (not Inner_C.Has_Actually_Created);" + }, + { + "function_def": "procedure Shared_Instance_Creator_L_Null_CB_J_P_Test is", + "function_body": "use SIFLI_Shared_Instance_L;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n declare\n package Outer_C is new SIFLI_Shared_Instance_L.Creator\n (Allocate => Allocate_SIFLI_Concrete_1_L,\n Just_Pretend => True);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n\n declare\n package Inner_C is new SIFLI_Shared_Instance_L.Creator\n (Allocate => Allocate_SIFLI_Concrete_2_L);\n begin\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (SIF.Lock_Count = 1);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n Assert (not Inner_C.Has_Actually_Created);" + }, + { + "function_def": "procedure Shared_Instance_Creator_U_Null_CB_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_U;\n\n begin\n\n Assert (not SIFLI_Shared_Instance_U.Locked);\n Assert (not SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance = null);\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n\n declare\n package Outer_C is new SIFLI_Shared_Instance_U.Creator\n (Allocate => Allocate_SIFLI_Concrete_2_U);\n begin\n Assert (SIFLI_Shared_Instance_U.Locked);\n Assert (SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance'Tag = SIFLI_Concrete_2'Tag);\n Assert (SIFLI_Shared_Instance_U.Instance.Primitive = '2');\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n\n declare\n package Inner_C is new SIFLI_Shared_Instance_U.Creator\n (Allocate => Allocate_SIFLI_Concrete_2_U);\n begin\n Assert (SIFLI_Shared_Instance_U.Locked);\n Assert (SIFLI_Shared_Instance_U.Instantiated);\n Assert (SIFLI_Shared_Instance_U.Instance'Tag\n =\n SIFLI_Concrete_2'Tag);\n Assert (SIFLI_Shared_Instance_U.Instance.Primitive = '2');\n Assert (SIF.Lock_Count = 0);\n Assert (SIF.Unlock_Count = 0);\n Assert (Outer_C.Has_Actually_Created);\n Assert (not Inner_C.Has_Actually_Created);" + }, + { + "function_def": "procedure Shared_Instance_Creator_CB_Test is", + "function_body": "begin\n\n Assert (SIF.CB_Calls_Count = 0);\n\n declare\n package C is new SIFLI_Shared_Instance_L.Creator\n (Allocate => Allocate_SIFLI_Concrete_1_L,\n CB => CB);\n pragma Unreferenced (C);\n begin\n Assert (SIF.CB_Calls_Count = 1);" + }, + { + "function_def": "procedure Shared_Instance_Fallback_Switch_Test is", + "function_body": "use Ada.Tags;\n use SIFLI_Shared_Instance_L;\n\n package F_S is new SIFLI_Shared_Instance_L.Fallback_Switch\n (Fallback_Instance => SIFLI_Concrete_2_Instance'Access);\n\n begin\n\n Assert (not SIFLI_Shared_Instance_L.Locked);\n Assert (not SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance = null);\n Assert (F_S.Instance_FS'Tag = SIFLI_Concrete_2'Tag);\n Assert (F_S.Instance_FS.Primitive = '2');\n\n declare\n package A_S is new SIFLI_Shared_Instance_L.Access_Setter\n (Inst_Access => SIFLI_Concrete_1_Instance'Access);\n begin\n\n Assert (SIFLI_Shared_Instance_L.Locked);\n Assert (SIFLI_Shared_Instance_L.Instantiated);\n Assert (SIFLI_Shared_Instance_L.Instance'Tag = SIFLI_Concrete_1'Tag);\n Assert (SIFLI_Shared_Instance_L.Instance.Primitive = '1');\n Assert (A_S.Has_Actually_Set);\n Assert (F_S.Instance_FS'Tag = SIFLI_Concrete_1'Tag);\n Assert (F_S.Instance_FS.Primitive = '1');" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Exception_Occurrence,\n Name => Exception_Occurrence_Access);\n\n begin\n\n Inc (Crossing_Count);\n\n if not Permanently_Opened then\n\n if Sat (Crossing_Count) then\n Permanent_Opening_Cause\n := Saturation; -- Causes Permanently_Opened to be True from\n -- from now on.\n C_D_T.Trace (\"Test node barrier saturated\");\n elsif Val (Crossing_Count) > Expected_Tag'Length then\n Permanent_Opening_Cause := Overflow; -- Ditto.\n Crossing_Count_On_Overflow := Val (Crossing_Count) - 1;\n C_D_T.Trace (\"Test node barrier overflowed\");\n end if;\n\n end if;\n\n if not Permanently_Opened then\n declare\n Excep : Exception_Occurrence_Access := Event_Data.E;\n begin\n Validate (Val (Crossing_Count),\n Event_Kind,\n Event_Data,\n Char,\n Char_To_Tag,\n Msg_Pref);\n Free (Excep); -- Free the exception allocated by Save_Occurrence\n -- in the Report_ primitives of\n -- Test_Reporter_W_Barrier.\n exception\n when E : others => -- Probably\n -- Ada.Assertions.Assertion_Error.\n C_D_T.Trace (Msg_Pref & Exception_Message (E));\n Failed_Validation_Flag := True;\n Failed_Val := True;" + }, + { + "function_def": "procedure Assert_Node_Tags is", + "function_body": "Not_All_Desc : constant String\n := \" elements are not all descendant of \";\n\n Dup_Tag : constant String := \"Duplicate tag in array \";\n\n begin\n\n Ada.Assertions.Assert\n ((for all E of Simu_Case =>\n Is_Descendant_At_Same_Level (E'Tag, Simu_Test_Case'Tag)),\n \"Simu_Case\" & Not_All_Desc & \"Simu_Test_Case\");\n\n Ada.Assertions.Assert\n ((for all K_1 in Simu_Case'Range =>\n (for all K_2 in Simu_Case'Range =>\n K_1 = K_2\n or else\n Simu_Case(K_1)'Tag /= Simu_Case(K_2)'Tag)),\n Dup_Tag & \"Simu_Case\");\n\n Ada.Assertions.Assert\n ((for all E of Slave_Runner_Arr =>\n Is_Descendant_At_Same_Level (E'Tag, Test_Runner_Sequential'Tag)),\n \"Slave_Runner_Arr\" & Not_All_Desc & \"Test_Runner_Sequential\");\n\n Ada.Assertions.Assert\n (not (for some E of Slave_Runner_Arr =>\n E'Tag = Test_Runner_Sequential_W_Slave_Tasks'Tag),\n \"No element in Slave_Runner_Arr should have the tag of \"\n & \"Test_Runner_Sequential_W_Slave_Tasks\");\n\n Ada.Assertions.Assert\n ((for all K_1 in Slave_Runner_Arr'Range =>\n (for all K_2 in Slave_Runner_Arr'Range =>\n K_1 = K_2\n or else\n Slave_Runner_Arr(K_1)'Tag /= Slave_Runner_Arr(K_2)'Tag)),\n Dup_Tag & \"Slave_Runner_Arr\");\n\n end Assert_Node_Tags;\n\n ----------------------------------------------------------------------------\n\n procedure Assert_Barrier_Status\n (Barrier : not null Test_Node_Barrier_Access;\n Expected_Tag_Length : Natural) is\n\n F : constant Boolean := Barrier.Timed_Out;\n N : constant Natural := Barrier.Cross_Count_On_Time_Out;\n M : constant String := (if F then\n (if N = 0 then\n \", no crossing happened\"\n else\n \" after crossing \")\n else\n \"\");\n Image_N : String := (if F and then N > 0 then\n Positive'Image (N)\n else\n \"\");\n\n begin\n\n if Image_N'Length > 0 then\n Image_N(Image_N'First) := '#';\n end if;\n Ada.Assertions.Assert (not Barrier.Timed_Out,\n \"Barrier timed out\" & M & Image_N);\n\n Ada.Assertions.Assert (not Barrier.Saturated,\n \"Barrier saturated (quite an exploit)\");\n\n Ada.Assertions.Assert (not Barrier.Overflowed, \"Barrier overflowed, \"\n & \"looks like Expected_Tag.all'Length should be greater (than\"\n & Integer'Image (Barrier.Cross_Count_On_Overflow) & \")\");\n\n Ada.Assertions.Assert (Barrier.Completed,\n \"Expected_Tag'Length is\" & Integer'Image (Expected_Tag_Length)\n & (if Barrier.Cross_Count = 0 then\n \", O crossing done\"\n else\n \", only\" & Natural'Image (Barrier.Cross_Count)\n & \" crossing(s) done\"));\n\n Ada.Assertions.Assert (not Barrier.Failed_Validation,\n \"Failed validation, please analyse trace for details\");\n\n end Assert_Barrier_Status;\n\n ----------------------------------------------------------------------------\n\n function Ind (A : Test_Node_Char_Array) return Test_Node_Array is\n\n Ret : Test_Node_Array (1 .. A'Length) := (others => A(A'First));\n K : Test_Node_Count := 0;\n\n begin\n\n for E of A loop\n K := K + 1;\n Ret(K) := E;\n end loop;\n\n return Ret;" + }, + { + "function_def": "procedure Process is", + "function_body": "begin\n K := K + 1;\n if Node_Tag_Tree(K).Node_Tag = Parent_Tag then\n A.Parent_Index := K;\n end if;\n end Process;\n\n begin\n\n A.Parent_Index := 0;\n\n while A.Parent_Index = 0 and then K < Node_Tag_Tree'Last loop\n Process;\n end loop;\n K := 0;\n while A.Parent_Index = 0 and then K < K_Node_Tag_Tree loop\n Process;\n end loop;\n Ada.Assertions.Assert\n (A.Parent_Index /= 0,\n \"Unable to build Node_Tag_Tree array\");" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Test_Node_Array,\n Name => Test_Node_Array_Access);\n\n begin\n\n Free (Obj.A);\n\n end Finalize;\n\n ----------------------------------------------------------------------------\n\n overriding\n procedure Run\n (Obj : in out Test_Runner_Sequential_W_Slave_Tasks;\n Outcome : out Test_Outcome;\n Kind : Run_Kind := Assert_Cond_And_Run_Test)\n is\n\n use Private_Test_Reporter;\n\n R_A : constant Shared_Instance.Instance_Type_Access\n := Shared_Instance.Instance_Type_Access (Obj.Reporter_Access);\n\n procedure CB is new SB_Lock_CB_procedure (SBLCB_Access => Obj.R_A_S_CB);\n\n package Test_Reporter_Access_Setter is new Shared_Instance.Access_Setter\n (Inst_Access => R_A,\n CB => CB);\n\n pragma Unreferenced (Test_Reporter_Access_Setter);\n\n -----------------------------------------------------\n\n procedure Run_Test is\n\n Node_Task : Slave_Node_Task_Array (Obj.Slaves.A'Range);\n Ex : Exception_Occurrence_Access;\n\n procedure Free is new Ada.Unchecked_Deallocation\n (Object => Exception_Occurrence,\n Name => Exception_Occurrence_Access);\n\n begin\n\n for K in Node_Task'Range loop\n Node_Task(K).Start_Run (Obj.Slaves.A(K));\n end loop;\n\n Test_Runner_Sequential (Obj).Run (Outcome);\n -- Inherited procedure call.\n\n for Ta of Node_Task loop\n declare\n Outc : Test_Outcome;\n E : Exception_Occurrence_Access;\n begin\n Ta.Get_Outcome_And_E (Outc, E);\n if Ex /= null and then E /= null then\n Free (E);\n elsif E /= null then\n Ex := E; -- Ex will be freed later.\n end if;\n case Outc is\n when Failed => Outcome := Failed;\n when Passed => null;\n end case;" + }, + { + "function_def": "procedure Cursor_Left is", + "function_body": "begin\n Platform.Put (CSI & \"1D\");\n end Cursor_Left;\n\n procedure Cursor_Right is\n begin\n Platform.Put (CSI & \"1C\");\n end Cursor_Right;\n\n procedure Cursor_Down is\n begin\n Platform.Put (CSI & \"B\");\n end Cursor_Down;\n\n procedure Cursor_Up is\n begin\n Platform.Put (CSI & \"A\");\n end Cursor_Up;\n\n procedure Hide_Cursor is\n begin\n Platform.Put (CSI & \"?25l\");\n end Hide_Cursor;\n\n procedure Show_Cursor is\n begin\n Platform.Put (CSI & \"?25h\");\n end Show_Cursor;\n\n procedure Scroll_Down is\n begin\n Platform.Put (CSI & \"T\");\n end Scroll_Down;\n\n procedure Scroll_Up is\n begin\n Platform.Put (CSI & \"S\");\n end Scroll_Up;\n\n procedure Cursor_Next_Line is\n begin\n Platform.Put (CSI & \"E\");\n end Cursor_Next_Line;\n\n procedure Erase is\n begin\n Platform.Put (CSI & 'X');\n end Erase;\n\n procedure Beginning_Of_Line is\n begin\n Platform.Put (CSI & \"1G\");\n end Beginning_Of_Line;\n\n procedure Clear_Line is\n begin\n Platform.Put (CSI & 'K');\n end Clear_Line;\n\n procedure Report_Cursor_Position is\n begin\n Platform.Put (CSI & \"6n\");\n end Report_Cursor_Position;\n\n procedure Set_Cursor_Position (C : Cursor_Position) is\n use Ada.Strings;\n use Ada.Strings.Fixed;\n begin\n Platform.Put (CSI & Trim (C.Row'Image, Left) & \";\" & Trim (C.Col'Image, Left) & \"H\");\n end Set_Cursor_Position;\n\n function Get_Cursor_Position return VT100.Cursor_Position is\n begin\n loop\n VT100.Report_Cursor_Position;\n declare\n Result : constant String := Platform.Get_Input;\n Semicolon_Index : constant Natural := Ada.Strings.Fixed.Index(Result, \";\", 1);\n Row : Integer := 1;\n Col : Integer := 1;\n begin\n -- The cursor position is reported as\n -- ESC [ ROW ; COL R\n\n -- May throw on bad parse.\n Row := Integer'Value(Result(3 .. Semicolon_Index - 1));\n Col := Integer'Value(Result(Semicolon_Index + 1 .. Result'Length - 1));\n\n return VT100.Cursor_Position'(Row => Row, Col => Col);\n exception\n -- Bad parse due to existing input on the line.\n when Constraint_Error =>\n null;" + }, + { + "function_def": "procedure Run_Print_Input is", + "function_body": "subtype Key_Enter is Integer with\n Static_Predicate => Key_Enter in 10 | 13;\n begin\n loop\n declare\n Input : constant ASU.Unbounded_String := ASU.To_Unbounded_String (TT.Platform.Get_Input);\n begin\n AIO.New_Line;\n if Trendy_Terminal.Maps.Is_Key (ASU.To_String (Input)) then\n AIO.Put_Line (TT.Maps.Key'Image (Trendy_Terminal.Maps.Key_For (ASU.To_String (Input))));\n end if;\n\n for X in 1 .. ASU.Length (Input) loop\n if Character'Pos (ASU.Element (Input, X)) in Key_Enter then\n return;\n end if;\n AIO.Put_Line (Character'Pos (ASU.Element (Input, X))'Image);\n end loop;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := 1;\n Time_Slice_Value := 0;\n WC_Encoding := 'b';\n Locking_Policy := 'C';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := 'F';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 1;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Ada.Strings.Text_Buffers'Elab_Spec;\n E096 := E096 + 1;\n System.Bb.Timing_Events'Elab_Spec;\n E094 := E094 + 1;\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n Ada.Tags'Elab_Body;\n E105 := E105 + 1;\n System.Exception_Table'Elab_Body;\n E045 := E045 + 1;\n E047 := E047 + 1;\n E022 := E022 + 1;\n Ada.Streams'Elab_Spec;\n E130 := E130 + 1;\n System.Finalization_Root'Elab_Spec;\n E136 := E136 + 1;\n Ada.Finalization'Elab_Spec;\n E134 := E134 + 1;\n System.Storage_Pools'Elab_Spec;\n E138 := E138 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E133 := E133 + 1;\n Ada.Real_Time'Elab_Body;\n E006 := E006 + 1;\n Ada.Real_Time.Timing_Events'Elab_Spec;\n E235 := E235 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E241 := E241 + 1;\n Ada.Strings.Unbounded'Elab_Spec;\n E237 := E237 + 1;\n System.Pool_Global'Elab_Spec;\n E140 := E140 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E219 := E219 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E226 := E226 + 1;\n E253 := E253 + 1;\n HAL.GPIO'ELAB_SPEC;\n E161 := E161 + 1;\n HAL.I2C'ELAB_SPEC;\n E128 := E128 + 1;\n HAL.SPI'ELAB_SPEC;\n E175 := E175 + 1;\n HAL.UART'ELAB_SPEC;\n E185 := E185 + 1;\n LSM303AGR'ELAB_SPEC;\n LSM303AGR'ELAB_BODY;\n E127 := E127 + 1;\n E217 := E217 + 1;\n E215 := E215 + 1;\n E210 := E210 + 1;\n Nrf.Gpio'Elab_Spec;\n Nrf.Gpio'Elab_Body;\n E155 := E155 + 1;\n E212 := E212 + 1;\n E170 := E170 + 1;\n Nrf.Spi_Master'Elab_Spec;\n Nrf.Spi_Master'Elab_Body;\n E173 := E173 + 1;\n E197 := E197 + 1;\n E195 := E195 + 1;\n E260 := E260 + 1;\n Nrf.Timers'Elab_Spec;\n Nrf.Timers'Elab_Body;\n E177 := E177 + 1;\n Nrf.Twi'Elab_Spec;\n Nrf.Twi'Elab_Body;\n E180 := E180 + 1;\n Nrf.Uart'Elab_Spec;\n Nrf.Uart'Elab_Body;\n E183 := E183 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E146 := E146 + 1;\n Microbit.Console'Elab_Body;\n E231 := E231 + 1;\n Microbit.Displayrt'Elab_Body;\n E233 := E233 + 1;\n E255 := E255 + 1;\n E189 := E189 + 1;\n Microbit.Accelerometer'Elab_Body;\n E187 := E187 + 1;\n Microbit.Radio'Elab_Spec;\n E257 := E257 + 1;\n Microbit.Timewithrtc1'Elab_Spec;\n Microbit.Timewithrtc1'Elab_Body;\n E193 := E193 + 1;\n Microbit.Buttons'Elab_Body;\n E191 := E191 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := 0;\n Time_Slice_Value := 0;\n WC_Encoding := 'b';\n Locking_Policy := 'C';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := 'F';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 1;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 4;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Ada.Strings.Text_Buffers'Elab_Spec;\n E005 := E005 + 1;\n System.Bb.Timing_Events'Elab_Spec;\n E059 := E059 + 1;\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n Ada.Tags'Elab_Body;\n E061 := E061 + 1;\n System.Exception_Table'Elab_Body;\n E096 := E096 + 1;\n E098 := E098 + 1;\n E012 := E012 + 1;\n Ada.Streams'Elab_Spec;\n E148 := E148 + 1;\n System.Finalization_Root'Elab_Spec;\n E155 := E155 + 1;\n Ada.Finalization'Elab_Spec;\n E153 := E153 + 1;\n System.Storage_Pools'Elab_Spec;\n E157 := E157 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E152 := E152 + 1;\n Ada.Real_Time'Elab_Body;\n E125 := E125 + 1;\n System.Pool_Global'Elab_Spec;\n E159 := E159 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E222 := E222 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E229 := E229 + 1;\n HAL.GPIO'ELAB_SPEC;\n E150 := E150 + 1;\n HAL.I2C'ELAB_SPEC;\n E182 := E182 + 1;\n HAL.SPI'ELAB_SPEC;\n E175 := E175 + 1;\n HAL.UART'ELAB_SPEC;\n E186 := E186 + 1;\n LSM303AGR'ELAB_SPEC;\n LSM303AGR'ELAB_BODY;\n E253 := E253 + 1;\n E195 := E195 + 1;\n E193 := E193 + 1;\n E212 := E212 + 1;\n Nrf.Gpio'Elab_Spec;\n Nrf.Gpio'Elab_Body;\n E141 := E141 + 1;\n E214 := E214 + 1;\n E216 := E216 + 1;\n E170 := E170 + 1;\n Nrf.Spi_Master'Elab_Spec;\n Nrf.Spi_Master'Elab_Body;\n E173 := E173 + 1;\n E199 := E199 + 1;\n E197 := E197 + 1;\n E243 := E243 + 1;\n E218 := E218 + 1;\n E241 := E241 + 1;\n Nrf.Timers'Elab_Spec;\n Nrf.Timers'Elab_Body;\n E177 := E177 + 1;\n Nrf.Twi'Elab_Spec;\n Nrf.Twi'Elab_Body;\n E180 := E180 + 1;\n Nrf.Uart'Elab_Spec;\n Nrf.Uart'Elab_Body;\n E184 := E184 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E131 := E131 + 1;\n Microbit.Console'Elab_Body;\n E188 := E188 + 1;\n E257 := E257 + 1;\n Microbit.Accelerometer'Elab_Body;\n E255 := E255 + 1;\n Microbit.Iosfortasking'Elab_Spec;\n Microbit.Iosfortasking'Elab_Body;\n E190 := E190 + 1;\n Microbit.Radio'Elab_Spec;\n E238 := E238 + 1;\n Microbit.Timehighspeed'Elab_Body;\n E245 := E245 + 1;\n Mybrain'Elab_Spec;\n E247 := E247 + 1;\n Mymotordriver'Elab_Spec;\n E234 := E234 + 1;\n Taskact'Elab_Spec;\n Taskact'Elab_Body;\n E123 := E123 + 1;\n Drivingstatesfsm'Elab_Spec;\n E263 := E263 + 1;\n E261 := E261 + 1;\n Taskthink'Elab_Spec;\n Taskthink'Elab_Body;\n E259 := E259 + 1;\n E249 := E249 + 1;\n E251 := E251 + 1;\n Tasksense'Elab_Spec;\n Tasksense'Elab_Body;\n E236 := E236 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;" + }, + { + "function_def": "procedure SetupMotors is", + "function_body": "Pins : MotorControllerPins;\n \n begin\n Pins.LeftFrontSpeedEnA := 0;\n Pins.LeftFrontPin1In1 := 6;\n Pins.LeftFrontPin2In2 := 7;\n Pins.LeftBackSpeedEnB := 0;\n Pins.LeftBackPin1In3 := 2;\n Pins.LeftBackPin2In4 := 3;\n \n Pins.RightFrontSpeedEnA := 1;\n Pins.RightFrontPin1In1 := 12;\n Pins.RightFrontPin2In2 := 13;\n Pins.RightBackSpeedEnB := 1;\n Pins.RightBackPin1In3 := 14;\n Pins.RightBackPin2In4 := 15;\n \n MotorDriver.SetMotorPins(Pins);\n \n Set_Analog_Period_Us (20_000);\n \n null;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := 0;\n Time_Slice_Value := 0;\n WC_Encoding := 'b';\n Locking_Policy := 'C';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := 'F';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 1;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 4;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Ada.Text_Io'Elab_Body;\n E249 := E249 + 1;\n Ada.Strings.Text_Buffers'Elab_Spec;\n E005 := E005 + 1;\n System.Bb.Timing_Events'Elab_Spec;\n E059 := E059 + 1;\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n Ada.Tags'Elab_Body;\n E061 := E061 + 1;\n System.Exception_Table'Elab_Body;\n E096 := E096 + 1;\n E098 := E098 + 1;\n E012 := E012 + 1;\n Ada.Streams'Elab_Spec;\n E157 := E157 + 1;\n System.Finalization_Root'Elab_Spec;\n E164 := E164 + 1;\n Ada.Finalization'Elab_Spec;\n E162 := E162 + 1;\n System.Storage_Pools'Elab_Spec;\n E166 := E166 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E161 := E161 + 1;\n Ada.Real_Time'Elab_Body;\n E134 := E134 + 1;\n System.Bb.Execution_Time'Elab_Body;\n E132 := E132 + 1;\n System.Pool_Global'Elab_Spec;\n E168 := E168 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E231 := E231 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E130 := E130 + 1;\n HAL.GPIO'ELAB_SPEC;\n E159 := E159 + 1;\n HAL.I2C'ELAB_SPEC;\n E191 := E191 + 1;\n HAL.SPI'ELAB_SPEC;\n E184 := E184 + 1;\n HAL.UART'ELAB_SPEC;\n E195 := E195 + 1;\n LSM303AGR'ELAB_SPEC;\n LSM303AGR'ELAB_BODY;\n E266 := E266 + 1;\n E204 := E204 + 1;\n E202 := E202 + 1;\n E221 := E221 + 1;\n Nrf.Gpio'Elab_Spec;\n Nrf.Gpio'Elab_Body;\n E150 := E150 + 1;\n E223 := E223 + 1;\n E225 := E225 + 1;\n E179 := E179 + 1;\n Nrf.Spi_Master'Elab_Spec;\n Nrf.Spi_Master'Elab_Body;\n E182 := E182 + 1;\n E208 := E208 + 1;\n E206 := E206 + 1;\n E256 := E256 + 1;\n E227 := E227 + 1;\n E254 := E254 + 1;\n Nrf.Timers'Elab_Spec;\n Nrf.Timers'Elab_Body;\n E186 := E186 + 1;\n Nrf.Twi'Elab_Spec;\n Nrf.Twi'Elab_Body;\n E189 := E189 + 1;\n Nrf.Uart'Elab_Spec;\n Nrf.Uart'Elab_Body;\n E193 := E193 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E140 := E140 + 1;\n Microbit.Console'Elab_Body;\n E197 := E197 + 1;\n E270 := E270 + 1;\n Microbit.Accelerometer'Elab_Body;\n E268 := E268 + 1;\n Microbit.Iosfortasking'Elab_Spec;\n Microbit.Iosfortasking'Elab_Body;\n E199 := E199 + 1;\n Microbit.Radio'Elab_Spec;\n E251 := E251 + 1;\n Microbit.Timehighspeed'Elab_Body;\n E258 := E258 + 1;\n Mybrain'Elab_Spec;\n E260 := E260 + 1;\n Mymotordriver'Elab_Spec;\n E238 := E238 + 1;\n Drivingstatesfsm'Elab_Spec;\n E276 := E276 + 1;\n E274 := E274 + 1;\n Taskact'Elab_Spec;\n Taskact'Elab_Body;\n E123 := E123 + 1;\n Taskthink'Elab_Spec;\n Taskthink'Elab_Body;\n E272 := E272 + 1;\n E262 := E262 + 1;\n E264 := E264 + 1;\n Tasksense'Elab_Spec;\n Tasksense'Elab_Body;\n E247 := E247 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;" + }, + { + "function_def": "procedure SetupMotors is", + "function_body": "Pins : MotorControllerPins;\n \n begin\n Pins.LeftFrontSpeedEnA := 0; -- set you MB pins here. Note that some pins overlap with other M:B functions! See the Microbit package to inspect which function lives on which pin.\n Pins.LeftFrontPin1In1 := 6;\n Pins.LeftFrontPin2In2 := 7;\n Pins.LeftBackSpeedEnB := 0;\n Pins.LeftBackPin1In3 := 2;\n Pins.LeftBackPin2In4 := 3;\n \n Pins.RightFrontSpeedEnA := 1;\n Pins.RightFrontPin1In1 := 12;\n Pins.RightFrontPin2In2 := 13;\n Pins.RightBackSpeedEnB := 1;\n Pins.RightBackPin1In3 := 14;\n Pins.RightBackPin2In4 := 15;\n \n MotorDriver.SetMotorPins(Pins);\n \n --For example set the PWM period, as you only need to do this once\n Set_Analog_Period_Us (20_000); --20 ms = 50 Hz, typical for many actuators. You can change this, check the motor behavior with an oscilloscope.\n \n null;" + }, + { + "function_def": "procedure Test is", + "function_body": "function \"+\"\n (Text : Wide_Wide_String) return League.Strings.Universal_String\n renames League.Strings.To_Universal_String;\n\n function Headless return League.JSON.Values.JSON_Value;\n\n --------------\n -- Headless --\n --------------\n\n function Headless return League.JSON.Values.JSON_Value is\n Cap : League.JSON.Objects.JSON_Object;\n Options : League.JSON.Objects.JSON_Object;\n Args : League.JSON.Arrays.JSON_Array;\n begin\n return Cap.To_JSON_Value;\n pragma Warnings (Off);\n Args.Append (League.JSON.Values.To_JSON_Value (+\"--headless\"));\n Args.Append (League.JSON.Values.To_JSON_Value (+\"--disable-extensions\"));\n Args.Append (League.JSON.Values.To_JSON_Value (+\"--no-sandbox\"));\n Options.Insert (+\"args\", Args.To_JSON_Value);\n Options.Insert\n (+\"binary\",\n League.JSON.Values.To_JSON_Value\n (+\"/usr/lib64/chromium-browser/headless_shell\"));\n Cap.Insert (+\"chromeOptions\", Options.To_JSON_Value);\n return Cap.To_JSON_Value;\n end Headless;\n\n Web_Driver : aliased WebDriver.Drivers.Driver'Class\n := WebDriver.Remote.Create (+\"http://127.0.0.1:9515\");\n Session : constant WebDriver.Sessions.Session_Access :=\n Web_Driver.New_Session (Headless);\nbegin\n Session.Go (+\"http://www.ada-ru.org/\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Session.Get_Current_URL.To_Wide_Wide_String);\n\n declare\n Body_Element : constant WebDriver.Elements.Element_Access :=\n Session.Find_Element\n (Strategy => WebDriver.Tag_Name,\n Selector => +\"body\");\n begin\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"Selected=\" & Boolean'Wide_Wide_Image (Body_Element.Is_Selected));\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"itemtype=\" &\n Body_Element.Get_Attribute (+\"itemtype\").To_Wide_Wide_String);\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"height=\" &\n Body_Element.Get_CSS_Value (+\"height\").To_Wide_Wide_String);\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"tag=\" & Body_Element.Get_Tag_Name.To_Wide_Wide_String);" + }, + { + "function_def": "procedure Example is", + "function_body": "Addr : constant League.Strings.Universal_String :=\n League.Application.Arguments.Element (1);\n Error : League.Strings.Universal_String;\n Manager : Network.Managers.Manager;\n Promise : Network.Connection_Promises.Promise;\nbegin\n Manager.Initialize;\n Network.Managers.TCP_V4.Register (Manager);\n\n Manager.Connect\n (Address => Network.Addresses.To_Address (Addr),\n Error => Error,\n Promise => Promise);\n\n if not Error.Is_Empty then\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"Connect fails: \" & Error.To_Wide_Wide_String);\n return;\n end if;\n\n declare\n Listener : aliased Listeners.Listener :=\n (Promise => Promise, others => <>);\n begin\n Promise.Add_Listener (Listener'Unchecked_Access);\n\n for J in 1 .. 100 loop\n Manager.Wait (1.0);\n exit when Listener.Done;\n end loop;" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(List_Node, List_Node_Access);\n\n function Has_Listener\n (Self : Promise'Class;\n Value : not null Listener_Access) return Boolean;\n\n ------------------\n -- Add_Listener --\n ------------------\n\n not overriding procedure Add_Listener\n (Self : in out Promise'Class;\n Value : not null Listener_Access)\n is\n Parent : constant Controller_Access := Self.Parent;\n begin\n case Parent.Data.State is\n when Pending =>\n if not Self.Has_Listener (Value) then\n Parent.Data.Listeners := new List_Node'\n (Item => Value,\n Next => Parent.Data.Listeners);\n end if;\n when Resolved =>\n Value.On_Resolve (Parent.Data.Resolve_Value);\n when Rejected =>\n Value.On_Reject (Parent.Data.Reject_Value);\n end case;\n end Add_Listener;\n\n --------------\n -- Finalize --\n --------------\n\n overriding procedure Finalize (Self : in out Controller) is\n begin\n if Self.Data.State = Pending then\n declare\n Next : List_Node_Access := Self.Data.Listeners;\n begin\n while Next /= null loop\n declare\n Item : List_Node_Access := Next;\n begin\n Next := Item.Next;\n Free (Item);" + }, + { + "function_def": "function Has_Listener", + "function_body": "(Self : Promise'Class;\n Value : not null Listener_Access) return Boolean\n is\n Next : List_Node_Access := Self.Parent.Data.Listeners;\n begin\n while Next /= null loop\n if Next.Item = Value then\n return True;\n end if;\n\n Next := Next.Next;\n end loop;\n\n return False;\n end Has_Listener;\n\n -----------------\n -- Is_Attached --\n -----------------\n\n function Is_Attached (Self : Promise'Class) return Boolean is\n begin\n return Self.Parent /= null;\n end Is_Attached;\n\n ----------------\n -- Is_Pending --\n ----------------\n\n function Is_Pending (Self : Promise'Class) return Boolean is\n begin\n return Self.Parent.Is_Pending;\n end Is_Pending;\n\n function Is_Pending (Self : Controller'Class) return Boolean is\n begin\n return Self.Data.State = Pending;\n end Is_Pending;\n\n -----------------\n -- Is_Rejected --\n -----------------\n\n function Is_Rejected (Self : Promise'Class) return Boolean is\n begin\n return Self.Parent.Is_Rejected;\n end Is_Rejected;\n\n function Is_Rejected (Self : Controller'Class) return Boolean is\n begin\n return Self.Data.State = Rejected;\n end Is_Rejected;\n\n -----------------\n -- Is_Resolved --\n -----------------\n\n function Is_Resolved (Self : Promise'Class) return Boolean is\n begin\n return Self.Parent.Is_Resolved;\n end Is_Resolved;\n\n function Is_Resolved (Self : Controller'Class) return Boolean is\n begin\n return Self.Data.State = Resolved;\n end Is_Resolved;\n\n ------------\n -- Reject --\n ------------\n\n procedure Reject (Self : in out Controller'Class;\n Value : Reject_Element) is\n Next : List_Node_Access := Self.Data.Listeners;\n begin\n Self.Data := (Rejected, Value);\n\n while Next /= null loop\n declare\n Item : List_Node_Access := Next;\n begin\n Item.Item.On_Reject (Self.Data.Reject_Value);\n Next := Item.Next;\n Free (Item);" + }, + { + "function_def": "procedure Remove_Listener", + "function_body": "(Self : in out Promise'Class;\n Value : not null Listener_Access)\n is\n Next : List_Node_Access := Self.Parent.Data.Listeners;\n begin\n if Next.Item = Value then\n Self.Parent.Data.Listeners := Next.Next;\n Free (Next);\n end if;\n\n while Next /= null loop\n if Next.Next /= null\n and then Next.Next.Item = Value\n then\n Next.Next := Next.Next.Next;\n Free (Next);\n\n exit;\n end if;\n end loop;\n end Remove_Listener;\n\n -------------\n -- Resolve --\n -------------\n\n procedure Resolve (Self : in out Controller'Class;\n Value : Resolve_Element) is\n Next : List_Node_Access := Self.Data.Listeners;\n begin\n Self.Data := (Resolved, Value);\n\n while Next /= null loop\n declare\n Item : List_Node_Access := Next;\n begin\n Item.Item.On_Resolve (Self.Data.Resolve_Value);\n Next := Item.Next;\n Free (Item);" + }, + { + "function_def": "overriding function Has_Listener (Self : Out_Socket) return Boolean is", + "function_body": "begin\n return Self.Listener.Assigned;\n end Has_Listener;\n\n ---------------\n -- Is_Closed --\n ---------------\n\n overriding function Is_Closed (Self : Out_Socket) return Boolean is\n begin\n return Self.Is_Closed;\n end Is_Closed;\n\n --------------\n -- On_Event --\n --------------\n\n overriding procedure On_Event\n (Self : in out Out_Socket;\n Events : Network.Polls.Event_Set)\n is\n use type Network.Connections.Listener_Access;\n\n function Get_Error return League.Strings.Universal_String;\n procedure Disconnect (Error : League.Strings.Universal_String);\n\n ----------------\n -- Disconnect --\n ----------------\n\n procedure Disconnect (Error : League.Strings.Universal_String) is\n begin\n Self.Change_Watch ((others => False));\n GNAT.Sockets.Close_Socket (Self.Internal);\n Self.Is_Closed := True;\n\n if Self.Listener.Assigned then\n Self.Listener.Closed (Error);\n end if;\n end Disconnect;\n\n ---------------\n -- Get_Error --\n ---------------\n\n function Get_Error return League.Strings.Universal_String is\n use type GNAT.Sockets.Error_Type;\n\n Option : constant GNAT.Sockets.Option_Type :=\n GNAT.Sockets.Get_Socket_Option\n (Self.Internal,\n GNAT.Sockets.Socket_Level,\n GNAT.Sockets.Error);\n begin\n if Option.Error = GNAT.Sockets.Success then\n return League.Strings.Empty_Universal_String;\n else\n return League.Strings.To_Universal_String\n (GNAT.Sockets.Error_Type'Wide_Wide_Image (Option.Error));\n end if;\n end Get_Error;\n\n Prev : constant Network.Polls.Event_Set := Self.Events;\n -- Active poll events\n\n Input : constant Network.Polls.Event := Network.Polls.Input;\n Output : constant Network.Polls.Event := Network.Polls.Output;\n Listener : array (Input .. Output) of Network.Connections.Listener_Access\n := (others => Self.Listener);\n\n Again : Boolean := True;\n\n begin\n Self.In_Event := True;\n\n if Self.Promise.Is_Pending then\n Self.Error := Get_Error;\n\n if Self.Error.Is_Empty then\n Self.Events := (others => False); -- no events before listener\n Self.Promise.Resolve (Self'Unchecked_Access);\n -- Usually it changes Listener\n\n if Self.Listener.Assigned then\n if not Self.Events (Polls.Output) then\n Self.Events := not Write_Event; -- We can write now\n Self.Listener.Can_Write;\n else\n Self.Events := (others => True);\n end if;\n end if;\n\n if Self.Events /= Prev then\n Self.Change_Watch (Self.Events);\n end if;\n else\n Disconnect (Self.Error);\n Self.Promise.Reject (Self.Error);\n end if;\n elsif Self.Is_Closed then\n -- Connection has been closed, but some events arrive after that.\n null;\n else\n pragma Assert (Self.Listener.Assigned);\n pragma Assert (Self.Error.Is_Empty);\n\n Self.Events := Self.Events and not Events;\n\n -- Report read event to current listener\n if Events (Input) then -- Have something to read\n Self.Listener.Can_Read;\n -- This can change Self.Events, Self.Listener or close\n end if;\n\n -- Report write event to current listener\n if Events (Output)\n and not Self.Events (Output) -- Have space to write\n and Self.Listener = Listener (Output)\n and not Self.Is_Closed\n then\n Self.Listener.Can_Write;\n -- This can change Self.Events, Self.Listener or close\n end if;\n\n -- Now report to changed listener if any\n while Again loop\n Again := False;\n\n if not Self.Events (Input) -- Can read\n and Self.Listener /= Listener (Input)\n and not Self.Is_Closed\n then\n Listener (Input) := Self.Listener;\n Self.Listener.Can_Read;\n Again := True;\n end if;\n\n if not Self.Events (Output) -- Can write\n and Self.Listener /= Listener (Output)\n and not Self.Is_Closed\n then\n Listener (Output) := Self.Listener;\n Self.Listener.Can_Write;\n Again := True;\n end if;\n end loop;\n\n if Self.Is_Closed then\n Disconnect (League.Strings.Empty_Universal_String);\n elsif not Self.Error.Is_Empty then\n Disconnect (Self.Error);\n elsif Events (Network.Polls.Error) then\n Disconnect (Get_Error);\n elsif Events (Network.Polls.Close) then\n Disconnect (League.Strings.Empty_Universal_String);\n elsif Self.Events /= Prev then\n Self.Change_Watch (Self.Events);\n end if;\n end if;\n\n Self.In_Event := False;\n end On_Event;\n\n ----------\n -- Read --\n ----------\n\n overriding procedure Read\n (Self : in out Out_Socket;\n Data : out Ada.Streams.Stream_Element_Array;\n Last : out Ada.Streams.Stream_Element_Offset)\n is\n use type Ada.Streams.Stream_Element_Offset;\n use type GNAT.Sockets.Error_Type;\n\n Kind : GNAT.Sockets.Error_Type;\n begin\n GNAT.Sockets.Receive_Socket (Self.Internal, Data, Last);\n\n if Last < Data'First then -- End of stream\n Self.Is_Closed := True;\n\n if not Self.In_Event then\n raise Program_Error with \"Unimplemented\";\n end if;\n end if;\n\n exception\n when E : GNAT.Sockets.Socket_Error =>\n Last := Data'First - 1;\n Kind := GNAT.Sockets.Resolve_Exception (E);\n\n if Kind /= GNAT.Sockets.Resource_Temporarily_Unavailable then\n Self.Is_Closed := True;\n Self.Error := League.Strings.From_UTF_8_String\n (Ada.Exceptions.Exception_Message (E));\n\n if not Self.In_Event then\n raise Program_Error with \"Unimplemented\";\n end if;\n\n elsif Self.In_Event then\n Self.Events := Self.Events or Read_Event;\n\n else\n Self.Change_Watch (Self.Events or Read_Event);\n end if;\n end Read;\n\n ------------\n -- Remote --\n ------------\n\n overriding function Remote (Self : Out_Socket)\n return Network.Addresses.Address\n is\n Result : League.Strings.Universal_String;\n Value : GNAT.Sockets.Sock_Addr_Type;\n begin\n Value := GNAT.Sockets.Get_Peer_Name (Self.Internal);\n Result.Append (\"/ip4/\");\n Result.Append\n (League.Strings.From_UTF_8_String (GNAT.Sockets.Image (Value.Addr)));\n Result.Append (\"/tcp/\");\n\n declare\n Port : constant Wide_Wide_String := Value.Port'Wide_Wide_Image;\n begin\n Result.Append (Port (2 .. Port'Last));\n\n return Network.Addresses.To_Address (Result);" + }, + { + "function_def": "overriding function Can_Listen", + "function_body": "(Self : Protocol; Address : Network.Addresses.Address) return Boolean\n renames Can_Connect;\n\n -------------\n -- Connect --\n -------------\n\n overriding procedure Connect\n (Self : in out Protocol;\n Address : Network.Addresses.Address;\n Poll : in out Network.Polls.Poll;\n Error : out League.Strings.Universal_String;\n Promise : out Network.Connection_Promises.Promise;\n Options : League.String_Vectors.Universal_String_Vector :=\n League.String_Vectors.Empty_Universal_String_Vector)\n is\n pragma Unreferenced (Options, Self);\n\n Req : GNAT.Sockets.Request_Type :=\n (GNAT.Sockets.Non_Blocking_IO, Enabled => True);\n\n List : constant League.String_Vectors.Universal_String_Vector :=\n Network.Addresses.To_String (Address).Split ('/');\n\n Internal : GNAT.Sockets.Socket_Type;\n Addr : GNAT.Sockets.Sock_Addr_Type;\n Socket : Out_Socket_Access;\n begin\n Addr.Addr := GNAT.Sockets.Inet_Addr (List (3).To_UTF_8_String);\n Addr.Port := GNAT.Sockets.Port_Type'Wide_Wide_Value\n (List (5).To_Wide_Wide_String);\n\n GNAT.Sockets.Create_Socket (Internal);\n GNAT.Sockets.Control_Socket (Internal, Req);\n\n begin\n GNAT.Sockets.Connect_Socket (Internal, Addr);\n exception -- Ignore Operation_Now_In_Progress\n when E : GNAT.Sockets.Socket_Error =>\n declare\n Kind : constant GNAT.Sockets.Error_Type :=\n GNAT.Sockets.Resolve_Exception (E);\n begin\n if Kind not in GNAT.Sockets.Operation_Now_In_Progress then\n Error := League.Strings.From_UTF_8_String\n (Ada.Exceptions.Exception_Message (E));\n return;\n end if;" + }, + { + "function_def": "procedure Listen", + "function_body": "(Self : in out Manager'Class;\n List : Network.Addresses.Address_Array;\n Listener : Connection_Listener_Access;\n Error : out League.Strings.Universal_String;\n Options : League.String_Vectors.Universal_String_Vector :=\n League.String_Vectors.Empty_Universal_String_Vector)\n is\n Done : array (List'Range) of Boolean := (List'Range => False);\n begin\n for Proto of Self.Proto (1 .. Self.Last) loop\n declare\n Ok : League.Strings.Universal_String;\n Slice : Network.Addresses.Address_Array (List'Range);\n Last : Natural := Slice'First - 1;\n begin\n for J in List'Range loop\n if not Done (J) and then Proto.Can_Listen (List (J)) then\n Done (J) := True;\n Last := Last + 1;\n Slice (Last) := List (J);\n end if;\n end loop;\n\n if Last >= Slice'First then\n Proto.Listen\n (Slice (Slice'First .. Last),\n Listener,\n Self.Poll,\n Ok,\n Options);\n\n Error.Append (Ok);\n end if;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(Raw_Protocol_Name, Protocol_Name);\n\n Raw : Ada.Streams.Stream_Element_Count;\n begin\n Read (Stream, Raw);\n Value := Convert (Raw_Protocol_Name (Raw));\n end Read_Protocol_Name;\n\n ----------------\n -- To_Address --\n ----------------\n\n function To_Address\n (Value : League.Strings.Universal_String) return Address is\n begin\n return (Value => Value);\n end To_Address;\n\n ----------------\n -- To_Address --\n ----------------\n\n function To_Address\n (Value : Ada.Streams.Stream_Element_Array) return Address\n is\n use type Ada.Streams.Stream_Element_Count;\n\n UTF : constant League.Text_Codecs.Text_Codec :=\n League.Text_Codecs.Codec (+\"utf-8\");\n\n S : aliased Simple_Stream :=\n (Ada.Streams.Root_Stream_Type with\n Size => Value'Length,\n Last => 0,\n Data => Value);\n Result : League.Strings.Universal_String;\n Proto : Protocol_Name;\n Length : Ada.Streams.Stream_Element_Count;\n begin\n while S.Last < S.Size loop\n Protocol_Name'Read (S'Access, Proto);\n Result.Append ('/');\n Result.Append (Image (Proto));\n\n case Proto is\n when ip4 =>\n declare\n Addr : IP4_Raw;\n begin\n Result.Append ('/');\n IP4_Raw'Read (S'Access, Addr);\n Result.Append (Image (Addr (1)));\n\n for X in 2 .. 4 loop\n Result.Append ('.');\n Result.Append (Image (Addr (X)));\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n subtype Big_Cave_Character is Character range 'A' .. 'Z';\n subtype Small_Cave_Character is Character range 'a' .. 'z';\n\n package Cave_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,\n Element_Type => String,\n \"=\" => \"=\");\n use Cave_Vectors;\n\n type Cave_Kind is (K_Start, K_Big, K_Small, K_End);\n Start_Name : constant String := \"start\";\n End_Name : constant String := \"end\";\n\n -- Given the name of a node, it retreive the corresponding kind\n function Get_Kind (Name : String) return Cave_Kind;\n\n --------------\n -- Get_Kind --\n --------------\n\n function Get_Kind (Name : String) return Cave_Kind is\n begin\n if Name = Start_Name then\n return K_Start;\n elsif Name = End_Name then\n return K_End;\n elsif Name (Name'First) in Big_Cave_Character then\n return K_Big;\n elsif Name (Name'First) in Small_Cave_Character then\n return K_Small;\n end if;\n raise Constraint_Error with \"Unexpected cave name: \" & Name;\n end Get_Kind;\n\n type Cave_Info (Length : Positive) is record\n Name : String (1 .. Length);\n Kind : Cave_Kind;\n Adjacent : Vector;\n end record;\n\n package Cave_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => String,\n Element_Type => Cave_Info,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\");\n\n package String_Sets is new Ada.Containers.Indefinite_Hashed_Sets (Element_Type => String,\n Hash => Ada.Strings.Hash,\n Equivalent_Elements => \"=\",\n \"=\" => \"=\");\n\n type Cave_Explorer is record\n Name : Unbounded_String;\n Already_Visited_Small_Cave_Name : Unbounded_String;\n Already_Visited_Small_Cave : String_Sets.Set;\n end record;\n\n package Explored_Cave_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces\n (Element_Type => Cave_Explorer);\n\n package Explored_Cave_Queue is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Explored_Cave_Interfaces);\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\n Nodes : Cave_Maps.Map := Cave_Maps.Empty_Map;\nbegin\n Get_File (File);\n\n -- Get all values\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => \"-\");\n Node_1 : constant String := Str (1 .. Separator_Index - 1);\n Node_2 : constant String := Str (Separator_Index + 1 .. Str'Last);\n begin\n declare\n Cave_Node_1 : Cave_Info := (Length => Node_1'Length,\n Name => Node_1,\n Kind => Get_Kind (Node_1),\n Adjacent => Empty_Vector);\n\n Cave_Node_2 : Cave_Info := (Length => Node_2'Length,\n Name => Node_2,\n Kind => Get_Kind (Node_2),\n Adjacent => Empty_Vector);\n begin\n if Nodes.Contains (Node_1) then\n Cave_Node_1 := Nodes.Element (Node_1);\n end if;\n if Nodes.Contains (Node_2) then\n Cave_Node_2 := Nodes.Element (Node_2);\n end if;\n\n Cave_Node_1.Adjacent.Append (Node_2);\n Cave_Node_2.Adjacent.Append (Node_1);\n\n Nodes.Include (Node_1, Cave_Node_1);\n Nodes.Include (Node_2, Cave_Node_2);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n subtype Big_Cave_Character is Character range 'A' .. 'Z';\n subtype Small_Cave_Character is Character range 'a' .. 'z';\n\n package Cave_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,\n Element_Type => String,\n \"=\" => \"=\");\n use Cave_Vectors;\n\n type Cave_Kind is (K_Start, K_Big, K_Small, K_End);\n Start_Name : constant String := \"start\";\n End_Name : constant String := \"end\";\n\n -- Given the name of a node, it retreive the corresponding kind\n function Get_Kind (Name : String) return Cave_Kind;\n\n --------------\n -- Get_Kind --\n --------------\n\n function Get_Kind (Name : String) return Cave_Kind is\n begin\n if Name = Start_Name then\n return K_Start;\n elsif Name = End_Name then\n return K_End;\n elsif Name (Name'First) in Big_Cave_Character then\n return K_Big;\n elsif Name (Name'First) in Small_Cave_Character then\n return K_Small;\n end if;\n raise Constraint_Error with \"Unexpected cave name: \" & Name;\n end Get_Kind;\n\n type Cave_Info (Length : Positive) is record\n Name : String (1 .. Length);\n Kind : Cave_Kind;\n Adjacent : Vector;\n end record;\n\n package Cave_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => String,\n Element_Type => Cave_Info,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\");\n\n package String_Sets is new Ada.Containers.Indefinite_Hashed_Sets (Element_Type => String,\n Hash => Ada.Strings.Hash,\n Equivalent_Elements => \"=\",\n \"=\" => \"=\");\n\n type Cave_Explorer is record\n Name : Unbounded_String;\n Already_Visited_Small_Cave_Name : Unbounded_String;\n Already_Visited_Small_Cave : String_Sets.Set;\n end record;\n\n package Explored_Cave_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces\n (Element_Type => Cave_Explorer);\n\n package Explored_Cave_Queue is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Explored_Cave_Interfaces);\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\n Nodes : Cave_Maps.Map := Cave_Maps.Empty_Map;\nbegin\n Get_File (File);\n\n -- Get all values\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => \"-\");\n Node_1 : constant String := Str (1 .. Separator_Index - 1);\n Node_2 : constant String := Str (Separator_Index + 1 .. Str'Last);\n begin\n declare\n Cave_Node_1 : Cave_Info := (Length => Node_1'Length,\n Name => Node_1,\n Kind => Get_Kind (Node_1),\n Adjacent => Empty_Vector);\n\n Cave_Node_2 : Cave_Info := (Length => Node_2'Length,\n Name => Node_2,\n Kind => Get_Kind (Node_2),\n Adjacent => Empty_Vector);\n begin\n if Nodes.Contains (Node_1) then\n Cave_Node_1 := Nodes.Element (Node_1);\n end if;\n if Nodes.Contains (Node_2) then\n Cave_Node_2 := Nodes.Element (Node_2);\n end if;\n\n Cave_Node_1.Adjacent.Append (Node_2);\n Cave_Node_2.Adjacent.Append (Node_1);\n\n Nodes.Include (Node_1, Cave_Node_1);\n Nodes.Include (Node_2, Cave_Node_2);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Fixed,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n package Character_Queue_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces (Element_Type => Character);\n\n package Character_Queues is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Character_Queue_Interfaces);\n use Character_Queues;\n\n function Pop (Q : in out Queue; N : Positive; Nb_Delete : in out Natural) return String;\n\n function Pop (Q : in out Queue; N : Positive; Nb_Delete : in out Natural) return String is\n Result : String (1 .. N);\n begin\n for Index in 1 .. N loop\n Q.Dequeue (Result (Index));\n end loop;\n Nb_Delete := Nb_Delete + N;\n return Result;\n end Pop;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\n Packet : Queue;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Value : Natural;\n Temp : String (1 .. 8);\n begin\n for Char of Str loop\n Value := Natural'Value (\"16#\" & Char & \"#\");\n Ada.Integer_Text_IO.Put (Temp,\n Value,\n Base => 2);\n File_Is_Empty := False;\n\n declare\n Trimmed : constant String := Trim (Temp, Ada.Strings.Both);\n Formatted_Bin_Str : constant String :=\n Tail (Trimmed (Trimmed'First + 2 .. Trimmed'Last - 1), 4, '0');\n begin\n for Elt of Formatted_Bin_Str loop\n Packet.Enqueue (Elt);\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Fixed,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n package Character_Queue_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces (Element_Type => Character);\n\n package Character_Queues is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Character_Queue_Interfaces);\n use Character_Queues;\n\n function Pop (Q : in out Queue; N : Positive; Nb_Delete : in out Long_Long_Natural) return String;\n\n function Pop (Q : in out Queue; N : Positive; Nb_Delete : in out Long_Long_Natural) return String is\n Result : String (1 .. N);\n begin\n for Index in 1 .. N loop\n Q.Dequeue (Result (Index));\n end loop;\n Nb_Delete := Nb_Delete + Long_Long_Natural (N);\n return Result;\n end Pop;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Long_Long_Natural := Long_Long_Natural'First;\n Packet : Queue;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Value : Natural;\n Temp : String (1 .. 8);\n begin\n for Char of Str loop\n Value := Natural'Value (\"16#\" & Char & \"#\");\n Ada.Integer_Text_IO.Put (Temp,\n Value,\n Base => 2);\n File_Is_Empty := False;\n\n declare\n Trimmed : constant String := Trim (Temp, Ada.Strings.Both);\n Formatted_Bin_Str : constant String :=\n Tail (Trimmed (Trimmed'First + 2 .. Trimmed'Last - 1), 4, '0');\n begin\n for Elt of Formatted_Bin_Str loop\n Packet.Enqueue (Elt);\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n package L9 renames Ada.Characters.Latin_9;\n\n type Movements is (Forward, Down, Up);\n\n File : File_Type;\n Horizontal_Position : Natural := 0;\n Depth : Natural := 0;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n begin\n Split_Value : for Index in Line'Range loop\n if Line (Index) = L9.Space then\n Solve_Puzzle : declare\n Movement : constant Movements := Movements'Value (Line (Line'First .. Index - 1));\n Value : constant Natural := Natural'Value (Line (Index + 1 .. Line'Last));\n begin\n case Movement is\n when Forward =>\n Horizontal_Position := Horizontal_Position + Value;\n when Down =>\n Depth := Depth + Value;\n when Up =>\n Depth := Depth - Value;\n end case;\n end Solve_Puzzle;\n exit Split_Value;\n end if;\n\n end loop Split_Value;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n package L9 renames Ada.Characters.Latin_9;\n\n type Movements is (Forward, Down, Up);\n\n File : File_Type;\n Horizontal_Position : Natural := 0;\n Depth : Natural := 0;\n Aim : Natural := 0;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n begin\n Split_Value : for Index in Line'Range loop\n if Line (Index) = L9.Space then\n Solve_Puzzle : declare\n Movement : constant Movements := Movements'Value (Line (Line'First .. Index - 1));\n Value : constant Natural := Natural'Value (Line (Index + 1 .. Line'Last));\n begin\n case Movement is\n when Forward =>\n Horizontal_Position := Horizontal_Position + Value;\n Depth := Depth + Aim * Value;\n when Down =>\n Aim := Aim + Value;\n when Up =>\n Aim := Aim - Value;\n end case;\n end Solve_Puzzle;\n exit Split_Value;\n end if;\n\n end loop Split_Value;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n File : File_Type;\n Result : Natural := Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Resolve puzzle while exploring file\n while not End_Of_File (File) loop\n declare\n use Ada.Integer_Text_IO;\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n After_Pipe : Boolean := False;\n Current_Size : Natural := Natural'First;\n begin\n while Last <= Line'Last loop\n if After_Pipe then\n -- Process data\n if Line (Last) = ' ' then\n Current_Size := Last - First;\n First := Last + 1;\n\n if Current_Size in 2 .. 4 or Current_Size = 7 then\n Result := Result + 1;\n end if;\n elsif Last = Line'Last then\n Current_Size := Last - First + 1;\n First := Last + 1;\n\n if Current_Size in 2 .. 4 or Current_Size = 7 then\n Result := Result + 1;\n end if;\n end if;\n\n Last := Last + 1;\n elsif Line (Last) = '|' then\n After_Pipe := True;\n\n Last := Last + 2;\n First := Last;\n else\n Last := Last + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n package Digit_Str is new\n Ada.Strings.Bounded.Generic_Bounded_Length (Max => 7);\n use Digit_Str;\n\n subtype Segment is Character range 'a' .. 'g';\n subtype Digit is Bounded_String;\n subtype Seven_Segments_Digits is Natural range 0 .. 9;\n\n -- Sort the characters in a String\n procedure String_Sort is new Ada.Containers.Generic_Array_Sort (Positive, Character, String);\n\n function Digit_Hash is new Ada.Strings.Bounded.Hash (Digit_Str);\n\n package Segments_To_Digit_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => Digit,\n Element_Type => Seven_Segments_Digits,\n Hash => Digit_Hash,\n Equivalent_Keys => \"=\");\n\n function Segment_Hash (Elt : Segment) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (Segment'Pos (Elt)));\n\n package Mapping_Table_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => Segment,\n Element_Type => Segment,\n Hash => Segment_Hash,\n Equivalent_Keys => \"=\");\n\n subtype Digits_Array_Index is Positive range 1 .. 10;\n type Digits_Array is array (Digits_Array_Index) of Digit;\n\n function Is_Lower_Than (Left, Right : Digit) return Boolean is (Length (Left) < Length (Right));\n\n procedure Digits_Sort is new Ada.Containers.Generic_Constrained_Array_Sort (Index_Type => Digits_Array_Index,\n Element_Type => Digit,\n Array_Type => Digits_Array,\n \"<\" => Is_Lower_Than);\n\n -- Given a String that represent a segment (like \"be\", or \"fgaecd\", etc.) it retrieve the corresponding segment.\n -- Note: when the word \"associated\" is used, it means that we cannot know exactly which segment corresponds\n -- to which other segment.\n -- When the word \"corresponding\" is used, it means that we know exactly which segment corresponds to which\n -- other segment.\n --\n -- @param Seg a String that represent a digit\n -- @returns Retruns the corresponding mapping table between segments of digits\n function Get_Corresponding_Segments (Digit_Array : Digits_Array) return Mapping_Table_Maps.Map;\n\n --------------------------------\n -- Get_Corresponding_Segments --\n --------------------------------\n\n function Get_Corresponding_Segments (Digit_Array : Digits_Array) return Mapping_Table_Maps.Map is\n use Mapping_Table_Maps;\n\n Mapping_Table : Mapping_Table_Maps.Map;\n CF_Seg,\n BD_Seg,\n EG_Seg : Digit := Null_Bounded_String;\n Can_Break_CF,\n Can_Break_BD : Boolean := False;\n begin\n -- Get the number 1 to get associated segments \"c\" and \"f\"\n CF_Seg := Digit_Array (1);\n\n -- Get the number 7 to find the corresponding segment of \"a\"\n for Char of To_String (Digit_Array (2)) loop\n if Index (CF_Seg, Char & \"\", 1) = 0 then\n Mapping_Table.Include (Char, 'a');\n exit;\n end if;\n end loop;\n\n -- Get the number 4 to find associated to \"b\" and \"d\"\n for Char of To_String (Digit_Array (3)) loop\n if Index (CF_Seg, Char & \"\", 1) = 0 then\n BD_Seg := BD_Seg & Char;\n end if;\n end loop;\n\n for Idx in 7 .. 9 loop\n -- Find the number 6 to find corresponding segment of \"f\" and \"c\"\n if (Index (Digit_Array (Idx), Element (CF_Seg, 1) & \"\") > 0) /=\n (Index (Digit_Array (Idx), Element (CF_Seg, 2) & \"\") > 0)\n then\n if Index (Digit_Array (Idx), Element (CF_Seg, 1) & \"\") > 0 then\n Mapping_Table.Include (Element (CF_Seg, 1), 'f');\n Mapping_Table.Include (Element (CF_Seg, 2), 'c');\n else\n Mapping_Table.Include (Element (CF_Seg, 2), 'f');\n Mapping_Table.Include (Element (CF_Seg, 1), 'c');\n end if;\n Can_Break_CF := True;\n end if;\n\n -- Find the number 0 to find corresponding segment of \"b\" and \"d\"\n if (Index (Digit_Array (Idx), Element (BD_Seg, 1) & \"\") > 0) /=\n (Index (Digit_Array (Idx), Element (BD_Seg, 2) & \"\") > 0)\n then\n if Index (Digit_Array (Idx), Element (BD_Seg, 1) & \"\") > 0 then\n Mapping_Table.Include (Element (BD_Seg, 1), 'b');\n Mapping_Table.Include (Element (BD_Seg, 2), 'd');\n else\n Mapping_Table.Include (Element (BD_Seg, 2), 'b');\n Mapping_Table.Include (Element (BD_Seg, 1), 'd');\n end if;\n Can_Break_BD := True;\n end if;\n\n if Can_Break_CF and Can_Break_BD then\n exit;\n end if;\n end loop;\n\n for Char in Character range 'a' .. 'g' loop\n if not Mapping_Table.Contains (Char) then\n EG_Seg := EG_Seg & Char;\n end if;\n end loop;\n\n -- Find the number 9 to find corresponding segment of \"e\" and \"g\"\n for Idx in 7 .. 10 loop\n if (Index (Digit_Array (Idx), Element (EG_Seg, 1) & \"\") > 0) /=\n (Index (Digit_Array (Idx), Element (EG_Seg, 2) & \"\") > 0)\n then\n if Index (Digit_Array (Idx), Element (EG_Seg, 1) & \"\") > 0 then\n Mapping_Table.Include (Element (EG_Seg, 1), 'g');\n Mapping_Table.Include (Element (EG_Seg, 2), 'e');\n else\n Mapping_Table.Include (Element (EG_Seg, 2), 'g');\n Mapping_Table.Include (Element (EG_Seg, 1), 'e');\n end if;\n exit;\n end if;\n end loop;\n\n return Mapping_Table;\n end Get_Corresponding_Segments;\n use Segments_To_Digit_Maps;\n\n -- Given a Value, it retrieve the original value according to Mapping_Table.\n -- @param Mapping_Table The mapping table that correspond mixed segment signal with the good segment signal\n -- @param Value The digit te retrieve\n -- @returns Return the resolved digit\n function Digit_Reconstruction (Mapping_Table : Mapping_Table_Maps.Map; Value : Digit) return Digit;\n\n --------------------------\n -- Digit_Reconstruction --\n --------------------------\n\n function Digit_Reconstruction (Mapping_Table : Mapping_Table_Maps.Map; Value : Digit) return Digit is\n Result : Digit := Null_Bounded_String;\n begin\n for Char of To_String (Value) loop\n Result := Result & Mapping_Table.Element (Char);\n end loop;\n\n declare\n Str : String := To_String (Result);\n begin\n String_Sort (Str);\n Result := To_Bounded_String (Str);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Lanternfish_Life_Span is range -1 .. 8;\n subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;\n type Lanternfishes_School is array (Lanternfish_Life_Span) of Long_Long_Natural;\n\n package Lanternfish_Life_Span_IO is new Ada.Text_IO.Integer_IO (Lanternfish_Life_Span);\n use Lanternfish_Life_Span_IO;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Lanternfishes : Lanternfishes_School := (others => Long_Long_Natural'First);\n Nb_Lanternfishes : Long_Long_Natural := Long_Long_Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all Lanternfishes\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Lanternfish_Life_Span;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n Lanternfishes (Value) := Lanternfishes (Value) + 1;\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n Lanternfishes (Value) := Lanternfishes (Value) + 1;\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Lanternfish_Life_Span is range -1 .. 8;\n subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;\n type Lanternfishes_School is array (Lanternfish_Life_Span) of Long_Long_Natural;\n\n package Lanternfish_Life_Span_IO is new Ada.Text_IO.Integer_IO (Lanternfish_Life_Span);\n use Lanternfish_Life_Span_IO;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Lanternfishes : Lanternfishes_School := (others => Long_Long_Natural'First);\n Nb_Lanternfishes : Long_Long_Natural := Long_Long_Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all Lanternfishes\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Lanternfish_Life_Span;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n Lanternfishes (Value) := Lanternfishes (Value) + 1;\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n Lanternfishes (Value) := Lanternfishes (Value) + 1;\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n subtype Chunks is Character\n with Static_Predicate => Chunks in\n '(' .. '('\n | '{' .. '{'\n | '[' .. '['\n | '<' .. '<'\n | ')' .. ')'\n | '}' .. '}'\n | ']' .. ']'\n | '>' .. '>';\n subtype Open_Chunks is Chunks\n with Static_Predicate => Open_Chunks in\n '(' .. '('\n | '{' .. '{'\n | '[' .. '['\n | '<' .. '<';\n subtype Close_Chunks is Chunks\n with Static_Predicate => Close_Chunks in\n ')' .. ')'\n | '}' .. '}'\n | ']' .. ']'\n | '>' .. '>';\n\n function ID_Hashed (Id : Open_Chunks) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (Open_Chunks'Pos (Id)));\n\n package Corresponding_Chunk_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Open_Chunks,\n Element_Type => Close_Chunks,\n Hash => ID_Hashed,\n Equivalent_Keys => \"=\");\n\n package Chunks_Vectors is new Ada.Containers.Vectors (Natural, Chunks);\n\n package Chunks_Vectors_Vectors is new Ada.Containers.Vectors (Natural, Chunks_Vectors.Vector, Chunks_Vectors.\"=\");\n\n Corresponding_Chunk : Corresponding_Chunk_Maps.Map;\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Values : Chunks_Vectors_Vectors.Vector := Chunks_Vectors_Vectors.Empty_Vector;\n Result : Natural := Natural'First;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n use Chunks_Vectors;\n\n Str : constant String := Get_Line (File);\n Row : Vector := Empty_Vector;\n begin\n for Char of Str loop\n Row.Append (Char);\n end loop;\n Values.Append (Row);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n subtype Chunks is Character\n with Static_Predicate => Chunks in\n '(' .. '('\n | '{' .. '{'\n | '[' .. '['\n | '<' .. '<'\n | ')' .. ')'\n | '}' .. '}'\n | ']' .. ']'\n | '>' .. '>';\n subtype Open_Chunks is Chunks\n with Static_Predicate => Open_Chunks in\n '(' .. '('\n | '{' .. '{'\n | '[' .. '['\n | '<' .. '<';\n subtype Close_Chunks is Chunks\n with Static_Predicate => Close_Chunks in\n ')' .. ')'\n | '}' .. '}'\n | ']' .. ']'\n | '>' .. '>';\n\n function ID_Hashed (Id : Open_Chunks) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (Open_Chunks'Pos (Id)));\n\n package Corresponding_Chunk_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Open_Chunks,\n Element_Type => Close_Chunks,\n Hash => ID_Hashed,\n Equivalent_Keys => \"=\");\n\n package Chunks_Vectors is new Ada.Containers.Vectors (Natural, Chunks);\n subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;\n package Natural_Vectors is new Ada.Containers.Vectors (Natural, Long_Long_Natural);\n package Natural_Vectors_Sorting is new Natural_Vectors.Generic_Sorting;\n\n package Chunks_Vectors_Vectors is new Ada.Containers.Vectors (Natural, Chunks_Vectors.Vector, Chunks_Vectors.\"=\");\n\n Corresponding_Chunk : Corresponding_Chunk_Maps.Map;\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Values : Chunks_Vectors_Vectors.Vector := Chunks_Vectors_Vectors.Empty_Vector;\n Result : Long_Long_Natural := 0;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n use Chunks_Vectors;\n\n Str : constant String := Get_Line (File);\n Row : Vector := Empty_Vector;\n begin\n for Char of Str loop\n Row.Append (Char);\n end loop;\n Values.Append (Row);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n package Natural_Vectors is new Ada.Containers.Vectors (Natural, Natural);\n use Natural_Vectors;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Crabs : Vector;\n Min_Dist : Natural := Natural'Last;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all Lanternfishes\n while not End_Of_File (File) loop\n declare\n use Ada.Integer_Text_IO;\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Natural;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n Crabs.Append (Value);\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n Crabs.Append (Value);\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n package Natural_Vectors is new Ada.Containers.Vectors (Natural, Natural);\n use Natural_Vectors;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Crabs : Vector;\n Min_Dist, Min : Natural := Natural'Last;\n Max : Natural := Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all Lanternfishes\n while not End_Of_File (File) loop\n declare\n use Ada.Integer_Text_IO;\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Natural;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n Crabs.Append (Value);\n\n if Value < Min then\n Min := Value;\n end if;\n\n if Value > Max then\n Max := Value;\n end if;\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n Crabs.Append (Value);\n\n if Value < Min then\n Value := Min;\n end if;\n\n if Value > Max then\n Value := Max;\n end if;\n\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n Max_Steps : constant := 10;\n\n subtype Rule_Str is String (1 .. 2);\n subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;\n\n package Rule_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Rule_Str,\n Element_Type => Character,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n\n package Rule_Counter_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Rule_Str,\n Element_Type => Long_Long_Natural,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n use Rule_Maps;\n use Rule_Counter_Maps;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Long_Long_Natural := Long_Long_Natural'First;\n Rules : Rule_Maps.Map := Rule_Maps.Empty_Map;\n Counter : Rule_Counter_Maps.Map := Rule_Counter_Maps.Empty_Map;\n Polymer_Template : Unbounded_String;\nbegin\n Get_File (File);\n\n Polymer_Template := To_Unbounded_String (Get_Line (File));\n\n -- Get all rules\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n begin\n if Str'Length = 0 then\n goto Continue_Next_Line;\n end if;\n\n declare\n Pattern : constant String := \" -> \";\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => Pattern);\n Left_Str : constant String := Str (1 .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length .. Str'Last);\n begin\n Rules.Include (Rule_Str (Left_Str), Right_Str (Right_Str'First));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Strings.Unbounded,\n Ada.Text_IO;\n use Utils;\n\n Max_Steps : constant := 40;\n\n subtype Rule_Str is String (1 .. 2);\n subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;\n\n package Rule_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Rule_Str,\n Element_Type => Character,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n\n package Rule_Counter_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Rule_Str,\n Element_Type => Long_Long_Natural,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n use Rule_Maps;\n use Rule_Counter_Maps;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Long_Long_Natural := Long_Long_Natural'First;\n Rules : Rule_Maps.Map := Rule_Maps.Empty_Map;\n Counter : Rule_Counter_Maps.Map := Rule_Counter_Maps.Empty_Map;\n Polymer_Template : Unbounded_String;\nbegin\n Get_File (File);\n\n Polymer_Template := To_Unbounded_String (Get_Line (File));\n\n -- Get all rules\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n begin\n if Str'Length = 0 then\n goto Continue_Next_Line;\n end if;\n\n declare\n Pattern : constant String := \" -> \";\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => Pattern);\n Left_Str : constant String := Str (1 .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length .. Str'Last);\n begin\n Rules.Include (Rule_Str (Left_Str), Right_Str (Right_Str'First));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);\n use Integer_Vectors;\n\n File : File_Type;\n Values : Vector := Empty_Vector;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Value : Natural;\n begin\n Ada.Integer_Text_IO.Get (File, Value);\n Values.Append (Value);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n use type Ada.Containers.Count_Type;\n\n package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);\n use Integer_Vectors;\n\n File : File_Type;\n Values : Vector := Empty_Vector;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Value : Natural;\n begin\n Ada.Integer_Text_IO.Get (File, Value);\n Values.Append (Value);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n Opening_Bracket : constant := -2;\n Closing_Bracket : constant := -1;\n subtype Snailfish_Values is Integer range Opening_Bracket .. Integer'Last;\n\n package Snailfish_Math_List is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Snailfish_Values,\n \"=\" => \"=\");\n use Snailfish_Math_List;\n\n function \"+\" (Left, Right : List) return List;\n function \"+\" (Left, Right : List) return List is\n Result : List := Copy (Left);\n begin\n Result.Prepend (New_Item => Opening_Bracket,\n Count => 1);\n\n for Elt of Right loop\n Result.Append (Elt);\n end loop;\n\n Result.Append (Closing_Bracket);\n\n return Result;\n end \"+\";\n\n function \"+\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;\n\n function \"+\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is\n Result : Snailfish_Math_List.Cursor := Left;\n begin\n for Index in 1 .. Right loop\n Result := Next (Result);\n end loop;\n return Result;\n end \"+\";\n\n function \"-\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;\n\n function \"-\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is\n Result : Snailfish_Math_List.Cursor := Left;\n begin\n for Index in 1 .. Right loop\n Result := Previous (Result);\n end loop;\n return Result;\n end \"-\";\n\n procedure Put (Snailfish_Number : List);\n\n procedure Put (Snailfish_Number : List) is\n Curs : Snailfish_Math_List.Cursor := Snailfish_Number.First;\n begin\n while Has_Element (Curs) loop\n case Element (Curs) is\n when Opening_Bracket =>\n Put (\"[\");\n when Closing_Bracket =>\n Put (\"]\");\n if Has_Element (Curs + 1) and then Element (Curs + 1) = Opening_Bracket then\n Put (\", \");\n end if;\n when others =>\n if Element (Curs - 1) > Closing_Bracket then\n Put (\", \");\n end if;\n Ada.Integer_Text_IO.Put (Item => Element (Curs), Width => 0);\n end case;\n Curs := Curs + 1;\n end loop;\n end Put;\n\n package Snailfish_Math_Vectors is new Ada.Containers.Vectors (Index_Type => Natural,\n Element_Type => List,\n \"=\" => \"=\");\n use Snailfish_Math_Vectors;\n\n function Pop (Vec : in out Vector) return List;\n\n function Pop (Vec : in out Vector) return List is\n Result : List;\n begin\n if Vec.Is_Empty then\n raise Constraint_Error with \"Container is empty\";\n end if;\n Result := Vec.First_Element;\n Vec.Delete_First;\n return Result;\n end Pop;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\n Result_List : List;\n Input : Vector;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Last : Positive;\n Value : Natural;\n Snailfish_Number : List;\n begin\n for Char of Str loop\n case Char is\n when '[' =>\n Snailfish_Number.Append (Opening_Bracket);\n when ']' =>\n Snailfish_Number.Append (Closing_Bracket);\n when '0' .. '9' =>\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Snailfish_Number.Append (Value);\n when others =>\n null;\n end case;\n File_Is_Empty := False;\n end loop;\n Input.Append (Snailfish_Number);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n Opening_Bracket : constant := -2;\n Closing_Bracket : constant := -1;\n subtype Snailfish_Values is Integer range Opening_Bracket .. Integer'Last;\n\n package Snailfish_Math_List is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Snailfish_Values,\n \"=\" => \"=\");\n use Snailfish_Math_List;\n\n function \"+\" (Left, Right : List) return List;\n function \"+\" (Left, Right : List) return List is\n Result : List := Copy (Left);\n begin\n Result.Prepend (New_Item => Opening_Bracket,\n Count => 1);\n\n for Elt of Right loop\n Result.Append (Elt);\n end loop;\n\n Result.Append (Closing_Bracket);\n\n return Result;\n end \"+\";\n\n function \"+\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;\n\n function \"+\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is\n Result : Snailfish_Math_List.Cursor := Left;\n begin\n for Index in 1 .. Right loop\n Result := Next (Result);\n end loop;\n return Result;\n end \"+\";\n\n function \"-\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;\n\n function \"-\" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is\n Result : Snailfish_Math_List.Cursor := Left;\n begin\n for Index in 1 .. Right loop\n Result := Previous (Result);\n end loop;\n return Result;\n end \"-\";\n\n procedure Put (Snailfish_Number : List);\n\n procedure Put (Snailfish_Number : List) is\n Curs : Snailfish_Math_List.Cursor := Snailfish_Number.First;\n begin\n while Has_Element (Curs) loop\n case Element (Curs) is\n when Opening_Bracket =>\n Put (\"[\");\n when Closing_Bracket =>\n Put (\"]\");\n if Has_Element (Curs + 1) and then Element (Curs + 1) = Opening_Bracket then\n Put (\", \");\n end if;\n when others =>\n if Element (Curs - 1) > Closing_Bracket then\n Put (\", \");\n end if;\n Ada.Integer_Text_IO.Put (Item => Element (Curs), Width => 0);\n end case;\n Curs := Curs + 1;\n end loop;\n end Put;\n\n package Snailfish_Math_Vectors is new Ada.Containers.Vectors (Index_Type => Natural,\n Element_Type => List,\n \"=\" => \"=\");\n use Snailfish_Math_Vectors;\n\n function Pop (Vec : in out Vector) return List;\n\n function Pop (Vec : in out Vector) return List is\n Result : List;\n begin\n if Vec.Is_Empty then\n raise Constraint_Error with \"Container is empty\";\n end if;\n Result := Vec.First_Element;\n Vec.Delete_First;\n return Result;\n end Pop;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\n Result_List : List;\n Input : Vector;\n Output : Vector;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Last : Positive;\n Value : Natural;\n Snailfish_Number : List;\n begin\n for Char of Str loop\n case Char is\n when '[' =>\n Snailfish_Number.Append (Opening_Bracket);\n when ']' =>\n Snailfish_Number.Append (Closing_Bracket);\n when '0' .. '9' =>\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Snailfish_Number.Append (Value);\n when others =>\n null;\n end case;\n File_Is_Empty := False;\n end loop;\n Input.Append (Snailfish_Number);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n package My_Coordinates is new Coordinates_2D (Integer);\n use My_Coordinates;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Result : Integer := Integer'First;\n\n X_Min, X_Max,\n Y_Min, Y_Max : Integer;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n procedure Split_Range (Str : String; Lower, Upper : out Integer);\n\n procedure Split_Range (Str : String; Lower, Upper : out Integer) is\n use Ada.Integer_Text_IO;\n\n Pattern : constant String := \"..\";\n Separator_Index : constant Natural :=\n Ada.Strings.Fixed.Index (Source => Str, Pattern => Pattern);\n Left_Str : constant String := Str (Str'First .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length .. Str'Last);\n\n Last : Positive;\n begin\n Get (Left_Str, Lower, Last);\n Get (Right_Str, Upper, Last);\n end Split_Range;\n\n Str : constant String := Get_Line (File);\n Pattern : constant String := \",\";\n Separator_Index : constant Natural :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => Pattern);\n Left_Str : constant String := Str (16 .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length + 3 .. Str'Last);\n\n begin\n Split_Range (Left_Str, X_Min, X_Max);\n Split_Range (Right_Str, Y_Min, Y_Max);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n package My_Coordinates is new Coordinates_2D (Integer);\n use My_Coordinates;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Result : Natural := Natural'First;\n\n X_Min, X_Max,\n Y_Min, Y_Max : Integer;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n procedure Split_Range (Str : String; Lower, Upper : out Integer);\n\n procedure Split_Range (Str : String; Lower, Upper : out Integer) is\n use Ada.Integer_Text_IO;\n\n Pattern : constant String := \"..\";\n Separator_Index : constant Natural :=\n Ada.Strings.Fixed.Index (Source => Str, Pattern => Pattern);\n Left_Str : constant String := Str (Str'First .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length .. Str'Last);\n\n Last : Positive;\n begin\n Get (Left_Str, Lower, Last);\n Get (Right_Str, Upper, Last);\n end Split_Range;\n\n Str : constant String := Get_Line (File);\n Pattern : constant String := \",\";\n Separator_Index : constant Natural :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => Pattern);\n Left_Str : constant String := Str (16 .. Separator_Index - 1);\n Right_Str : constant String := Str (Separator_Index + Pattern'Length + 3 .. Str'Last);\n\n begin\n Split_Range (Left_Str, X_Min, X_Max);\n Split_Range (Right_Str, Y_Min, Y_Max);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers, Ada.Text_IO;\n use Utils;\n\n type Binary_Rate is record\n Zero : Natural;\n One : Natural;\n end record;\n\n type Binary is mod 2;\n\n package Binary_Rate_Vectors is new Ada.Containers.Vectors (Natural, Binary_Rate);\n use Binary_Rate_Vectors;\n\n File : File_Type;\n Gamma : Vector := Empty_Vector;\n Epsilon : Vector := Empty_Vector;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n procedure Process (Vec : out Vector; Index : Natural; Bit : Binary);\n\n procedure Process (Vec : out Vector; Index : Natural; Bit : Binary) is\n begin\n if Count_Type (Index) > Vec.Length then\n Vec.Append (New_Item => (Zero => (if Bit = 0 then 1 else 0), One => Natural (Bit)));\n else\n declare\n Temp_Rate : Binary_Rate := Vec.Element (Index - 1);\n begin\n if Bit = 0 then\n Temp_Rate.Zero := Temp_Rate.Zero + 1;\n else\n Temp_Rate.One := Temp_Rate.One + 1;\n end if;\n\n Vec.Replace_Element (Index - 1, Temp_Rate);" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers, Ada.Strings.Unbounded, Ada.Text_IO;\n use Utils;\n\n subtype Binary_Values is Natural range 0 .. 1;\n\n package Unbounded_String_Vectors is new Ada.Containers.Vectors (Natural, Unbounded_String);\n use Unbounded_String_Vectors;\n\n package Unbounded_String_Cursor_Vectors is new Ada.Containers.Vectors (Natural, Cursor);\n\n type Rate_Arrays is array (Binary_Values'Range) of Natural;\n type Binary_Maps is array (Binary_Values'Range) of Unbounded_String_Cursor_Vectors.Vector;\n type Strategies is (Most_Common, Least_Common);\n\n -- Given a String which represents a Natural in binary format, it returns the corresponding Natural.\n -- @param Str A String which represents a Natural in binary format\n -- @retuns Returns the corresponding Natural\n function Binary_String_To_Number (Str : String) return Natural;\n\n function Binary_String_To_Number (Str : String) return Natural\n is\n Exponent : Natural := Natural'First;\n Result : Natural := Natural'First;\n begin\n for Elt of reverse Str loop\n if Elt = '1' then\n Result := Result + 2 ** Exponent;\n end if;\n Exponent := Exponent + 1;\n end loop;\n\n return Result;\n end Binary_String_To_Number;\n\n -- Find the result in a set of String which represents a Natural in binary format according to criteria.\n -- @param Values Contains all values (String which represents a Natural in binary format) extracted from a file.\n -- @param Rate Indicate how many 0s and 1s there are at index \"Index\".\n -- @param Map An array (Called Map because each index corresponds to a filter) that contains for each index (0 and\n -- 1) each values of Values that contain a 0 (for index 0 of Map) or a 1 (for index 1 of Map) at index \"Index\" in\n -- the the value in Values.\n -- @param Index This index denote the position in the binary string representation of a Natural.\n -- @param Strategy The strategy to apply (Most Common, Least Common).\n -- @retuns Return the value that match the criteria (Strategy)\n function Find_Value_According_To_Criteria (Values : Vector;\n Rate : Rate_Arrays;\n Map : Binary_Maps;\n Index : in out Positive;\n Strategy : Strategies)\n return Natural;\n\n function Find_Value_According_To_Criteria (Values : Vector;\n Rate : Rate_Arrays;\n Map : Binary_Maps;\n Index : in out Positive;\n Strategy : Strategies)\n return Natural\n is\n -- Filter the result for the next recursive call of Find_Value_According_To_Criteria.\n -- @param Previous_Filtered_Values List of Cursor (pointing to value in Values) that match the previous\n -- criteria.\n -- @param Rate Indicate how many 0s and 1s there are at index \"Index\".\n -- @param Map An array (Called Map because each index corresponds to a filter) that contains for each index (0\n -- and 1) each values of Values that contain a 0 (for index 0 of Map) or a 1 (for index 1 of Map) at index\n -- \"Index\" in the the value in Values.\n procedure Filter (Previous_Filtered_Values : Unbounded_String_Cursor_Vectors.Vector;\n Rate : in out Rate_Arrays;\n Map : in out Binary_Maps);\n\n procedure Filter (Previous_Filtered_Values : Unbounded_String_Cursor_Vectors.Vector;\n Rate : in out Rate_Arrays;\n Map : in out Binary_Maps)\n is\n Current_Value : Unbounded_String;\n Binary_Value : Binary_Values;\n\n begin\n for Curs : Cursor of Previous_Filtered_Values loop\n Current_Value := Element (Curs);\n\n declare\n Str : constant String := To_String (Current_Value);\n begin\n Binary_Value := Binary_Values'Value (Str (Index .. Index));\n\n Map (Binary_Value).Append (Curs);\n Rate (Binary_Value) := Rate (Binary_Value) + 1;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n Nb_Tiles : constant := 1;\n\n subtype Risk_Level is Natural range 1 .. 9;\n\n type Location is record\n Line : Natural;\n Column : Natural;\n end record;\n\n subtype Adjacent_Index is Integer range -1 .. 1;\n type Adjacent_Location is record\n Line : Adjacent_Index;\n Column : Adjacent_Index;\n end record;\n\n type Adjacent is (Top, Right, Bottom, Left);\n type Adjacent_Array is array (Adjacent) of Adjacent_Location;\n\n -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.\n -- @param Loc A 2 dimensional location\n -- @returns Return the corresponding hash\n -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function\n function Hash (Loc : Location) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column));\n\n package Location_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Location,\n Element_Type => Risk_Level,\n Hash => Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n use Location_Maps;\n\n Adjacents : constant Adjacent_Array := (Top => (-1, 0),\n Right => (0, 1),\n Bottom => (1, 0),\n Left => (0, -1));\n\n function Equivalent_Keys (Left, Right : Location) return Boolean is\n (Left.Line = Right.Line and Left.Column = Right.Column);\n\n -- Display the location\n procedure Put (Loc : Location);\n\n ---------\n -- Put --\n ---------\n\n procedure Put (Loc : Location) is\n begin\n Put (\"(\");\n Ada.Integer_Text_IO.Put (Item => Loc.Line,\n Width => 0);\n Put (\",\");\n Ada.Integer_Text_IO.Put (Item => Loc.Column,\n Width => 0);\n Put (\")\");\n end Put;\n\n package Chiton_Dijkstra is new Dijkstra (Node => Location,\n Hash => Hash,\n Equivalent_Keys => Equivalent_Keys,\n Put => Put,\n Is_Directed => True);\n\n -- This heuristic compute the Manhattan distance from Current to To\n function Heuristic (Current, To : Location) return Long_Long_Natural;\n\n function Heuristic (Current, To : Location) return Long_Long_Natural is\n begin\n return Long_Long_Natural (abs (To.Line - Current.Line) + abs (To.Column - Current.Column));\n end Heuristic;\n\n use Chiton_Dijkstra;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Array_Width,\n Array_Height : Natural := Natural'First;\n Result : Long_Long_Natural := Long_Long_Natural'First;\n Nodes : Map;\n Edges : Edges_Lists.Vector := Edges_Lists.Empty_Vector;\n Graph : Graph_Access;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Value : Risk_Level;\n Last : Positive;\n Current_Colum : Natural := Natural'First;\n begin\n if Array_Width = Natural'First then\n Array_Width := Str'Length;\n end if;\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Nodes.Insert ((Array_Height, Current_Colum), Value);\n Current_Colum := Current_Colum + 1;\n end loop;\n\n Create_Horizontal_Tiles : for Column in Array_Width .. Array_Width * Nb_Tiles - 1 loop\n Last := Nodes.Element ((Array_Height, Column - Array_Width)) + 1;\n if Last > 9 then\n Last := Last - 9;\n end if;\n Nodes.Insert ((Array_Height, Column), Last);\n end loop Create_Horizontal_Tiles;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n Nb_Tiles : constant := 5;\n\n subtype Risk_Level is Natural range 1 .. 9;\n\n type Location is record\n Line : Natural;\n Column : Natural;\n end record;\n\n subtype Adjacent_Index is Integer range -1 .. 1;\n type Adjacent_Location is record\n Line : Adjacent_Index;\n Column : Adjacent_Index;\n end record;\n\n type Adjacent is (Top, Right, Bottom, Left);\n type Adjacent_Array is array (Adjacent) of Adjacent_Location;\n\n -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.\n -- @param Loc A 2 dimensional location\n -- @returns Return the corresponding hash\n -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function\n function Hash (Loc : Location) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column));\n\n package Location_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Location,\n Element_Type => Risk_Level,\n Hash => Hash,\n Equivalent_Keys => \"=\",\n \"=\" => \"=\");\n use Location_Maps;\n\n Adjacents : constant Adjacent_Array := (Top => (-1, 0),\n Right => (0, 1),\n Bottom => (1, 0),\n Left => (0, -1));\n\n function Equivalent_Keys (Left, Right : Location) return Boolean is\n (Left.Line = Right.Line and Left.Column = Right.Column);\n\n -- Display the location\n procedure Put (Loc : Location);\n\n ---------\n -- Put --\n ---------\n\n procedure Put (Loc : Location) is\n begin\n Put (\"(\");\n Ada.Integer_Text_IO.Put (Item => Loc.Line,\n Width => 0);\n Put (\",\");\n Ada.Integer_Text_IO.Put (Item => Loc.Column,\n Width => 0);\n Put (\")\");\n end Put;\n\n package Chiton_Dijkstra is new Dijkstra (Node => Location,\n Hash => Hash,\n Equivalent_Keys => Equivalent_Keys,\n Put => Put,\n Is_Directed => True);\n\n -- This heuristic compute the Manhattan distance from Current to To\n function Heuristic (Current, To : Location) return Long_Long_Natural;\n\n function Heuristic (Current, To : Location) return Long_Long_Natural is\n begin\n return Long_Long_Natural (abs (To.Line - Current.Line) + abs (To.Column - Current.Column));\n end Heuristic;\n\n use Chiton_Dijkstra;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Array_Width,\n Array_Height : Natural := Natural'First;\n Result : Long_Long_Natural := Long_Long_Natural'First;\n Nodes : Map;\n Edges : Edges_Lists.Vector := Edges_Lists.Empty_Vector;\n Graph : Graph_Access;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Value : Risk_Level;\n Last : Positive;\n Current_Colum : Natural := Natural'First;\n begin\n if Array_Width = Natural'First then\n Array_Width := Str'Length;\n end if;\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Nodes.Insert ((Array_Height, Current_Colum), Value);\n Current_Colum := Current_Colum + 1;\n end loop;\n\n Create_Horizontal_Tiles : for Column in Array_Width .. Array_Width * Nb_Tiles - 1 loop\n Last := Nodes.Element ((Array_Height, Column - Array_Width)) + 1;\n if Last > 9 then\n Last := Last - 9;\n end if;\n Nodes.Insert ((Array_Height, Column), Last);\n end loop Create_Horizontal_Tiles;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Text_IO;\n use Utils;\n\n package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);\n use Integer_Vectors;\n\n subtype Hegihtmap_Values is Natural range 0 .. 10;\n subtype Hegiht is Hegihtmap_Values range 0 .. 9;\n\n type Cave_Heightmap_Array is array (Natural range <>, Natural range <>) of Hegihtmap_Values;\n\n File : File_Type;\n Values : Vector := Empty_Vector;\n Array_Width,\n Array_Height : Natural := Natural'First;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n Array_Height := Array_Height + 1;\n declare\n Str : constant String := Get_Line (File);\n Value : Hegiht;\n Last : Positive;\n begin\n if Array_Width = Natural'First then\n Array_Width := Str'Length;\n end if;\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Values.Append (Value);\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n package Integer_Vectors is new Ada.Containers.Vectors (Natural, Natural);\n use Integer_Vectors;\n\n subtype Hegihtmap_Values is Natural range 0 .. 10;\n subtype Hegiht is Hegihtmap_Values range 0 .. 9;\n\n type Cave_Heightmap_Array is array (Natural range <>, Natural range <>) of Hegihtmap_Values;\n\n type Location is record\n Line : Natural;\n Column : Natural;\n end record;\n\n subtype Adjacent_Index is Integer range -1 .. 1;\n type Adjacent_Location is record\n Line : Adjacent_Index;\n Column : Adjacent_Index;\n end record;\n\n type Adjacent is (Top, Right, Bottom, Left);\n type Adjacent_Array is array (Adjacent) of Adjacent_Location;\n\n -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.\n -- @param Loc A 2 dimensional location\n -- @returns Return the corresponding hash\n -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function\n function Hash (Loc : Location) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column));\n\n function Is_Equal (Loc_1, Loc_2 : Location) return Boolean is\n (Loc_1.Line = Loc_2.Line and Loc_1.Column = Loc_2.Column);\n\n package Location_Sets is new Ada.Containers.Hashed_Sets (Element_Type => Location,\n Hash => Hash,\n Equivalent_Elements => Is_Equal,\n \"=\" => Is_Equal);\n\n Adjacents : constant Adjacent_Array := (Top => (-1, 0),\n Right => (0, 1),\n Bottom => (1, 0),\n Left => (0, -1));\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Values : Vector := Empty_Vector;\n Array_Width,\n Array_Height : Natural := Natural'First;\nbegin\n Get_File (File);\n\n -- Get all values\n while not End_Of_File (File) loop\n Array_Height := Array_Height + 1;\n declare\n Str : constant String := Get_Line (File);\n Value : Hegiht;\n Last : Positive;\n begin\n if Array_Width = Natural'First then\n Array_Width := Str'Length;\n end if;\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Value, Last);\n Values.Append (Value);\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers,\n Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Bingo_Range is range 1 .. 5;\n subtype Bingo_Values is Natural range 0 .. 99;\n package Bingo_Values_IO is new Ada.Text_IO.Integer_IO (Bingo_Values);\n use Bingo_Values_IO;\n\n type Grid_Element is record\n Value : Bingo_Values;\n Marked : Boolean;\n end record;\n\n type Lookup_Item is record\n Board_Id : Natural;\n Line : Bingo_Range;\n Column : Bingo_Range;\n end record;\n\n package Lookup_Item_Vectors is new Ada.Containers.Vectors (Natural, Lookup_Item);\n\n function Bingo_Range_Hash (Elt : Bingo_Values) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type (Elt));\n\n package Lookup_Map is new Ada.Containers.Hashed_Maps (Key_Type => Bingo_Values,\n Element_Type => Lookup_Item_Vectors.Vector,\n Hash => Bingo_Range_Hash,\n Equivalent_Keys => \"=\",\n \"=\" => Lookup_Item_Vectors.\"=\");\n use Lookup_Map;\n\n -- Given a Lookup map, it add an element to the specified value.\n -- @param Lookup Lookup map to update\n -- @param Value Id in the map \"Lookup\"\n -- @param Board_Id Property of the Lookup_Item that will be added to the vector at id \"Value\"\n -- @param Line Property of the Lookup_Item that will be added to the vector at id \"Value\"\n -- @param Column Property of the Lookup_Item that will be added to the vector at id \"Value\"\n procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range);\n\n -------------------\n -- Update_Lookup --\n -------------------\n\n procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range)\n is\n use Lookup_Item_Vectors;\n\n Item : constant Lookup_Item := (Board_Id, Line, Column);\n Vec : Lookup_Item_Vectors.Vector := Lookup.Element (Value);\n begin\n Vec.Append (Item);\n Lookup.Replace_Element (Lookup.Find (Value), Vec);\n end Update_Lookup;\n\n type Grid is array (Bingo_Range, Bingo_Range) of Grid_Element;\n\n package Grid_Vectors is new Ada.Containers.Vectors (Natural, Grid);\n use Grid_Vectors;\n\n package Bingo_Values_Queue_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces\n (Element_Type => Bingo_Values);\n\n package Bingo_Balls is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Bingo_Values_Queue_Interfaces);\n use Bingo_Balls;\n\n -- Tell if there is a bingo.\n -- @param Board The board to check\n -- @param Line The marked line\n -- @param Column The marked column\n -- @returns Return True if there is a bingo, False otherwise\n function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean;\n\n --------------\n -- Is_Bingo --\n --------------\n\n function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean is\n Line_Bingo, Column_Bingo : Boolean := True;\n begin\n for Index in Bingo_Range loop\n Line_Bingo := Line_Bingo and Board (Index, Column).Marked;\n Column_Bingo := Column_Bingo and Board (Line, Index).Marked;\n\n if not Line_Bingo and not Column_Bingo then\n return False;\n end if;\n end loop;\n\n return True;\n end Is_Bingo;\n\n -- Compute the value of a board according to the exercice.\n -- Formula: \"sum of all unmarked numbers\" x Current_Value\n -- @param Board the winning board\n -- @param Current_Value The last number called\n -- @returns Returns the result of the calculation\n function Compute_Board_Value (Board : Grid; Current_Value : Bingo_Values) return Natural;\n\n -------------------------\n -- Compute_Board_Value --\n -------------------------\n\n function Compute_Board_Value (Board : Grid; Current_Value : Bingo_Values) return Natural is\n Sum : Natural := Natural'First;\n begin\n for Line in Board'Range (1) loop\n for Column in Board'Range (2) loop\n if not Board (Line, Column).Marked then\n Sum := Sum + Board (Line, Column).Value;\n end if;\n end loop;\n end loop;\n\n return Sum * Current_Value;\n end Compute_Board_Value;\n\n File : File_Type;\n Ball_Box : Queue;\n Boards : Vector := Empty_Vector;\n Lookup : Map := Empty_Map;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n Fill_Ball_Box : declare\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Bingo_Values;\n begin\n while Last <= Line'Last loop\n if Line (Last .. Last) = \",\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n\n Ball_Box.Enqueue (Value);\n Lookup.Insert (Value, Lookup_Item_Vectors.Empty_Vector);\n\n First := Last + 1;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n\n Ball_Box.Enqueue (Value);\n Lookup.Insert (Value, Lookup_Item_Vectors.Empty_Vector);\n\n First := Last + 1;\n end if;\n Last := Last + 1;\n end loop;\n end Fill_Ball_Box;\n\n -- Get all boards\n Load_Boards : declare\n Line_Index : Bingo_Range := Bingo_Range'First;\n Column_Index : Bingo_Range := Bingo_Range'First;\n Value : Bingo_Values;\n Board : Grid;\n begin\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n Last : Positive := Line'First;\n begin\n while Last < Line'Last loop\n Get (Line (Last .. Line'Last), Value, Last);\n\n Board (Line_Index, Column_Index) := (Value, False);\n Update_Lookup (Lookup => Lookup,\n Value => Value,\n Board_Id => Natural (Boards.Length),\n Line => Line_Index,\n Column => Column_Index);\n\n if Column_Index = Bingo_Range'Last then\n Column_Index := Bingo_Range'First;\n\n if Line_Index = Bingo_Range'Last then\n Line_Index := Bingo_Range'First;\n\n Boards.Append (Board);\n else\n Line_Index := Line_Index + 1;\n end if;\n else\n Column_Index := Column_Index + 1;\n end if;\n\n Last := Last + 1;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers,\n Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Bingo_Range is range 1 .. 5;\n subtype Bingo_Values is Natural range 0 .. 99;\n package Bingo_Values_IO is new Ada.Text_IO.Integer_IO (Bingo_Values);\n use Bingo_Values_IO;\n\n type Grid_Element is record\n Value : Bingo_Values;\n Marked : Boolean;\n end record;\n\n type Lookup_Item is record\n Board_Id : Natural;\n Line : Bingo_Range;\n Column : Bingo_Range;\n end record;\n\n package Lookup_Item_Vectors is new Ada.Containers.Vectors (Natural, Lookup_Item);\n\n function Bingo_Range_Hash (Elt : Bingo_Values) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type (Elt));\n\n package Lookup_Map is new Ada.Containers.Hashed_Maps (Key_Type => Bingo_Values,\n Element_Type => Lookup_Item_Vectors.Vector,\n Hash => Bingo_Range_Hash,\n Equivalent_Keys => \"=\",\n \"=\" => Lookup_Item_Vectors.\"=\");\n use Lookup_Map;\n\n package Winner_Boards_Sets is new Ada.Containers.Ordered_Sets (Element_Type => Natural);\n use Winner_Boards_Sets;\n\n -- Given a Lookup map, it add an element to the specified value.\n -- @param Lookup Lookup map to update\n -- @param Value Id in the map \"Lookup\"\n -- @param Board_Id Property of the Lookup_Item that will be added to the vector at id \"Value\"\n -- @param Line Property of the Lookup_Item that will be added to the vector at id \"Value\"\n -- @param Column Property of the Lookup_Item that will be added to the vector at id \"Value\"\n procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range);\n\n -------------------\n -- Update_Lookup --\n -------------------\n\n procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range)\n is\n use Lookup_Item_Vectors;\n\n Item : constant Lookup_Item := (Board_Id, Line, Column);\n Vec : Lookup_Item_Vectors.Vector := Lookup.Element (Value);\n begin\n Vec.Append (Item);\n Lookup.Replace_Element (Lookup.Find (Value), Vec);\n end Update_Lookup;\n\n type Grid is array (Bingo_Range, Bingo_Range) of Grid_Element;\n\n package Grid_Vectors is new Ada.Containers.Vectors (Natural, Grid);\n use Grid_Vectors;\n\n package Bingo_Values_Queue_Interfaces is\n new Ada.Containers.Synchronized_Queue_Interfaces\n (Element_Type => Bingo_Values);\n\n package Bingo_Balls is new Ada.Containers.Unbounded_Synchronized_Queues\n (Queue_Interfaces => Bingo_Values_Queue_Interfaces);\n use Bingo_Balls;\n\n -- Tell if there is a bingo.\n -- @param Board The board to check\n -- @param Line The marked line\n -- @param Column The marked column\n -- @returns Return True if there is a bingo, False otherwise\n function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean;\n\n --------------\n -- Is_Bingo --\n --------------\n\n function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean is\n Line_Bingo, Column_Bingo : Boolean := True;\n begin\n for Index in Bingo_Range loop\n Line_Bingo := Line_Bingo and Board (Index, Column).Marked;\n Column_Bingo := Column_Bingo and Board (Line, Index).Marked;\n\n if not Line_Bingo and not Column_Bingo then\n return False;\n end if;\n end loop;\n\n return True;\n end Is_Bingo;\n\n -- Compute the value of a board according to the exercice.\n -- Formula: \"sum of all unmarked numbers\" x Current_Value\n -- @param Board the winning board\n -- @param Current_Value The last number called\n -- @returns Returns the result of the calculation\n function Compute_Board_Value (Board : Grid; Current_Value : Bingo_Values) return Natural;\n\n -------------------------\n -- Compute_Board_Value --\n -------------------------\n\n function Compute_Board_Value (Board : Grid; Current_Value : Bingo_Values) return Natural is\n Sum : Natural := Natural'First;\n begin\n for Line in Board'Range (1) loop\n for Column in Board'Range (2) loop\n if not Board (Line, Column).Marked then\n Sum := Sum + Board (Line, Column).Value;\n end if;\n end loop;\n end loop;\n\n return Sum * Current_Value;\n end Compute_Board_Value;\n\n File : File_Type;\n Ball_Box : Queue;\n Boards : Vector := Empty_Vector;\n Lookup : Map := Empty_Map;\n Winner_Boards : Set := Empty_Set;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n Fill_Ball_Box : declare\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Value : Bingo_Values;\n begin\n while Last <= Line'Last loop\n if Line (Last .. Last) = \",\" then\n Get (Line (First .. Last - 1), Value, Last_Index);\n\n Ball_Box.Enqueue (Value);\n Lookup.Insert (Value, Lookup_Item_Vectors.Empty_Vector);\n\n First := Last + 1;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Value, Last_Index);\n\n Ball_Box.Enqueue (Value);\n Lookup.Insert (Value, Lookup_Item_Vectors.Empty_Vector);\n\n First := Last + 1;\n end if;\n Last := Last + 1;\n end loop;\n end Fill_Ball_Box;\n\n -- Get all boards\n Load_Boards : declare\n Line_Index : Bingo_Range := Bingo_Range'First;\n Column_Index : Bingo_Range := Bingo_Range'First;\n Value : Bingo_Values;\n Board : Grid;\n begin\n while not End_Of_File (File) loop\n declare\n Line : constant String := Get_Line (File);\n Last : Positive := Line'First;\n begin\n while Last < Line'Last loop\n Get (Line (Last .. Line'Last), Value, Last);\n\n Board (Line_Index, Column_Index) := (Value, False);\n Update_Lookup (Lookup => Lookup,\n Value => Value,\n Board_Id => Natural (Boards.Length),\n Line => Line_Index,\n Column => Column_Index);\n\n if Column_Index = Bingo_Range'Last then\n Column_Index := Bingo_Range'First;\n\n if Line_Index = Bingo_Range'Last then\n Line_Index := Bingo_Range'First;\n\n Boards.Append (Board);\n else\n Line_Index := Line_Index + 1;\n end if;\n else\n Column_Index := Column_Index + 1;\n end if;\n\n Last := Last + 1;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Coordinate_2D is record\n Line : Natural;\n Column : Natural;\n end record;\n\n type Folding_Kind is (K_Line, K_Column);\n\n type Folding_T is record\n Kind : Folding_Kind;\n Value : Natural;\n end record;\n\n package Folding_Vectors is new Ada.Containers.Vectors (Natural, Folding_T);\n\n -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.\n -- @param Coord A 2 dimensional location\n -- @returns Return the corresponding hash\n -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function\n function Hash (Coord : Coordinate_2D) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (((Coord.Line + Coord.Column) * (Coord.Line + Coord.Column + 1) / 2) + Coord.Column));\n\n function Equivalent_Keys (Left, Right : Coordinate_2D) return Boolean is\n (Left.Line = Right.Line and Left.Column = Right.Column);\n\n package Dots_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Coordinate_2D,\n Element_Type => Boolean,\n Hash => Hash,\n Equivalent_Keys => Equivalent_Keys,\n \"=\" => \"=\");\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Max_Lines, Max_Columns : Positive := Positive'First;\n Folding_Instructions : Folding_Vectors.Vector := Folding_Vectors.Empty_Vector;\n Dots_Map : Dots_Maps.Map := Dots_Maps.Empty_Map;\nbegin\n Get_File (File);\n\n -- Get all values\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n begin\n if Str'Length = 0 then\n goto Continue_Next_Line;\n end if;\n\n if Str (Str'First) = 'f' then\n -- \"fold along\" instruction\n declare\n use Ada.Integer_Text_IO;\n\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => \"=\");\n Kind : constant String := Str (Separator_Index - 1 .. Separator_Index - 1);\n Value_Str : constant String := Str (Separator_Index + 1 .. Str'Last);\n Last_Index : Positive := Positive'First;\n Value : Natural;\n begin\n Get (Value_Str, Value, Last_Index);\n\n Folding_Instructions.Append (((if Kind = \"x\" then K_Column else K_Line), Value));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Coordinate_2D is record\n Line : Natural;\n Column : Natural;\n end record;\n\n type Folding_Kind is (K_Line, K_Column);\n\n type Folding_T is record\n Kind : Folding_Kind;\n Value : Natural;\n end record;\n\n package Folding_Vectors is new Ada.Containers.Vectors (Natural, Folding_T);\n\n -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.\n -- @param Coord A 2 dimensional location\n -- @returns Return the corresponding hash\n -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function\n function Hash (Coord : Coordinate_2D) return Ada.Containers.Hash_Type is\n (Ada.Containers.Hash_Type (((Coord.Line + Coord.Column) * (Coord.Line + Coord.Column + 1) / 2) + Coord.Column));\n\n function Equivalent_Keys (Left, Right : Coordinate_2D) return Boolean is\n (Left.Line = Right.Line and Left.Column = Right.Column);\n\n package Dots_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Coordinate_2D,\n Element_Type => Boolean,\n Hash => Hash,\n Equivalent_Keys => Equivalent_Keys,\n \"=\" => \"=\");\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n File_Is_Empty : Boolean := True;\n Max_Lines, Max_Columns : Positive := Positive'First;\n Folding_Instructions : Folding_Vectors.Vector := Folding_Vectors.Empty_Vector;\n Dots_Map : Dots_Maps.Map := Dots_Maps.Empty_Map;\nbegin\n Get_File (File);\n\n -- Get all values\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n begin\n if Str'Length = 0 then\n goto Continue_Next_Line;\n end if;\n\n if Str (Str'First) = 'f' then\n -- \"fold along\" instruction\n declare\n use Ada.Integer_Text_IO;\n\n Separator_Index : constant Integer :=\n Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => \"=\");\n Kind : constant String := Str (Separator_Index - 1 .. Separator_Index - 1);\n Value_Str : constant String := Str (Separator_Index + 1 .. Str'Last);\n Last_Index : Positive := Positive'First;\n Value : Natural;\n begin\n Get (Value_Str, Value, Last_Index);\n\n Folding_Instructions.Append (((if Kind = \"x\" then K_Column else K_Line), Value));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers,\n Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Coordinate_2D is record\n Line : Natural;\n Column : Natural;\n end record;\n\n type Segment is record\n Start_Line : Coordinate_2D;\n End_Line : Coordinate_2D;\n end record;\n\n package Segment_Vectors is new Ada.Containers.Vectors (Natural, Segment);\n use Segment_Vectors;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Segments : Vector := Empty_Vector;\n Max_Lines, Max_Columns : Positive := Positive'First;\n Nb_Dangerous_Cells : Natural := Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all segments\n while not End_Of_File (File) loop\n declare\n use Ada.Integer_Text_IO;\n\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Values : array (1 .. 4) of Natural := (others => 0);\n Current_Value_Index : Positive := Positive'First;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Values (Current_Value_Index), Last_Index);\n Current_Value_Index := Current_Value_Index + 1;\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Values (Current_Value_Index), Last_Index);\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;\n\n if Values (1) > Max_Lines then\n Max_Lines := Values (1);\n elsif Values (3) > Max_Lines then\n Max_Lines := Values (3);\n end if;\n\n if Values (2) > Max_Columns then\n Max_Columns := Values (2);\n elsif Values (4) > Max_Columns then\n Max_Columns := Values (4);\n end if;\n\n Segments.Append ((\n Start_Line => (Line => Values (1), Column => Values (2)),\n End_Line => (Line => Values (3), Column => Values (4))\n ));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Containers,\n Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n type Coordinate_2D is record\n Line : Natural;\n Column : Natural;\n end record;\n\n type Segment is record\n Start_Line : Coordinate_2D;\n End_Line : Coordinate_2D;\n end record;\n\n package Segment_Vectors is new Ada.Containers.Vectors (Natural, Segment);\n use Segment_Vectors;\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Segments : Vector := Empty_Vector;\n Max_Lines, Max_Columns : Positive := Positive'First;\n Nb_Dangerous_Cells : Natural := Natural'First;\nbegin\n Get_File (File);\n\n if End_Of_File (File) then\n raise Program_Error with \"Empty file\";\n end if;\n\n -- Get all segments\n while not End_Of_File (File) loop\n declare\n use Ada.Integer_Text_IO;\n\n Line : constant String := Get_Line (File);\n First : Positive := Line'First;\n Last : Positive := Line'First;\n Last_Index : Positive := Line'First;\n Values : array (1 .. 4) of Natural := (others => 0);\n Current_Value_Index : Positive := Positive'First;\n begin\n while Last <= Line'Last loop\n if Line (Last) not in '0' .. '9' then\n if Line (First .. Last - 1) /= \"\" then\n Get (Line (First .. Last - 1), Values (Current_Value_Index), Last_Index);\n Current_Value_Index := Current_Value_Index + 1;\n end if;\n First := Last + 1;\n Last := First;\n elsif Last = Line'Last then\n Get (Line (First .. Line'Last), Values (Current_Value_Index), Last_Index);\n Last := Last + 1;\n else\n Last := Last + 1;\n end if;\n end loop;\n\n if Values (1) > Max_Lines then\n Max_Lines := Values (1);\n elsif Values (3) > Max_Lines then\n Max_Lines := Values (3);\n end if;\n\n if Values (2) > Max_Columns then\n Max_Columns := Values (2);\n elsif Values (4) > Max_Columns then\n Max_Columns := Values (4);\n end if;\n\n Segments.Append ((\n Start_Line => (Line => Values (1), Column => Values (2)),\n End_Line => (Line => Values (3), Column => Values (4))\n ));" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n subtype Adjacent_Index is Integer range -1 .. 1;\n type Adjacent_Location is record\n Line : Adjacent_Index;\n Column : Adjacent_Index;\n end record;\n\n Max_Steps : constant := 100;\n\n type Adjacent is (Top, Top_Right, Right, Bottom_Right, Bottom, Bottom_Left, Left, Top_Left);\n type Adjacent_Array is array (Adjacent) of Adjacent_Location;\n\n type Octopuses_Energy_Level_Array is array (1 .. 10, 1 .. 10) of Integer;\n\n Adjacents : constant Adjacent_Array := (Top => (-1, 0),\n Top_Right => (-1, 1),\n Right => (0, 1),\n Bottom_Right => (1, 1),\n Bottom => (1, 0),\n Bottom_Left => (1, -1),\n Left => (0, -1),\n Top_Left => (-1, -1));\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Octopuses_Energy_Level : Octopuses_Energy_Level_Array;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n Current_Line,\n Current_Column : Positive := Positive'First;\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Last : Positive;\n begin\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Octopuses_Energy_Level (Current_Line, Current_Column), Last);\n Current_Column := Current_Column + 1;\n File_Is_Empty := False;\n end loop;" + }, + { + "function_def": "procedure Main is", + "function_body": "use Ada.Execution_Time,\n Ada.Real_Time,\n Ada.Text_IO;\n use Utils;\n\n subtype Adjacent_Index is Integer range -1 .. 1;\n type Adjacent_Location is record\n Line : Adjacent_Index;\n Column : Adjacent_Index;\n end record;\n\n type Adjacent is (Top, Top_Right, Right, Bottom_Right, Bottom, Bottom_Left, Left, Top_Left);\n type Adjacent_Array is array (Adjacent) of Adjacent_Location;\n\n type Octopuses_Energy_Level_Array is array (1 .. 10, 1 .. 10) of Integer;\n\n Adjacents : constant Adjacent_Array := (Top => (-1, 0),\n Top_Right => (-1, 1),\n Right => (0, 1),\n Bottom_Right => (1, 1),\n Bottom => (1, 0),\n Bottom_Left => (1, -1),\n Left => (0, -1),\n Top_Left => (-1, -1));\n\n File : File_Type;\n Start_Time, End_Time : CPU_Time;\n Execution_Duration : Time_Span;\n Octopuses_Energy_Level : Octopuses_Energy_Level_Array;\n File_Is_Empty : Boolean := True;\n Result : Natural := Natural'First;\nbegin\n Get_File (File);\n\n -- Get all values\n declare\n Current_Line,\n Current_Column : Positive := Positive'First;\n begin\n while not End_Of_File (File) loop\n declare\n Str : constant String := Get_Line (File);\n Last : Positive;\n begin\n for Char of Str loop\n Ada.Integer_Text_IO.Get (Char & \"\", Octopuses_Energy_Level (Current_Line, Current_Column), Last);\n Current_Column := Current_Column + 1;\n File_Is_Empty := False;\n end loop;" + }, + { + "function_def": "procedure Parse_Register(parser : in out Parser_Type;", + "function_body": "result : out Memory_Pointer) is\n\n mem : Memory_Pointer := null;\n\nbegin\n\n while Get_Type(parser) = Open loop\n Match(parser, Open);\n declare\n name : constant String := Get_Value(parser);\n begin\n Match(parser, Literal);\n if name = \"memory\" then\n if mem /= null then\n Destroy(mem);\n Raise_Error(parser,\n \"memory declared multiple times in register\");\n end if;\n Parse_Memory(parser, mem);\n else\n Raise_Error(parser, \"invalid register attribute: \" & name);\n end if;" + }, + { + "function_def": "procedure MemGen is", + "function_body": "mem : Memory_Pointer;\n name : Unbounded_String := To_Unbounded_String(\"mem\");\n addr_width : Positive := 32 - 3;\n mem_index : Integer := -1;\n simplify : Boolean := True;\n\n procedure Show_Usage is\n begin\n Put_Line(\"usage: \" & Command_Name & \" [options] \");\n Put_Line(\"options:\");\n Put_Line(\" -width Address width (default\" &\n Positive'Image(addr_width) & \")\");\n Put_Line(\" -nosimplify Disable memory simplification\");\n end Show_Usage;\n\nbegin\n\n -- Parse arguments.\n declare\n i : Positive := 1;\n arg : Unbounded_String;\n begin\n while i <= Argument_Count loop\n arg := To_Unbounded_String(Argument(i));\n if arg = \"-width\" and i + 1 <= Argument_Count then\n i := i + 1;\n addr_width := Positive'Value(Argument(i));\n elsif arg = \"-name\" and i + 1 <= Argument_Count then\n i := i + 1;\n name := To_Unbounded_String(Argument(i));\n elsif arg = \"-nosimplify\" then\n simplify := False;\n elsif mem_index < 0 then\n mem_index := i;\n else\n Show_Usage;\n return;\n end if;\n i := i + 1;\n end loop;" + }, + { + "function_def": "procedure Register_Benchmark(runner : in out Runner_Type;", + "function_body": "benchmark : in Benchmark_Pointer) is\n begin\n runner.benchmarks.Append(benchmark);\n end Register_Benchmark;\n\n procedure Run(runner : in out Runner_Type;\n mem : in Memory_Pointer) is\n first : constant Natural := runner.benchmarks.First_Index;\n last : constant Natural := runner.benchmarks.Last_Index;\n bp : Benchmark_Pointer;\n begin\n for i in first .. last loop\n bp := runner.benchmarks.Element(i);\n Set_Memory(bp.all, mem);\n end loop;\n loop\n for i in reverse first .. last loop\n bp := runner.benchmarks.Element(i);\n Reset(bp.all, i);\n begin\n Run(bp.all);\n exception\n when Prune_Error =>\n null;" + }, + { + "function_def": "procedure MemSim is", + "function_body": "mem : Memory_Pointer := null;\n runner : Runner_Type;\n arg : Positive := 1;\n\n type Benchmark_Constructor_Type is\n access function return Benchmark.Benchmark_Pointer;\n\n type Benchmark_Info_Type is record\n name : Unbounded_String;\n usage : Unbounded_String;\n constructor : Benchmark_Constructor_Type;\n end record;\n\n type Benchmark_Info_Array is array(Natural range <>) of Benchmark_Info_Type;\n\n function BM_Entry(name : String;\n usage : String;\n constructor : Benchmark_Constructor_Type)\n return Benchmark_Info_Type is\n begin\n return Benchmark_Info_Type'(To_Unbounded_String(name),\n To_Unbounded_String(usage),\n constructor);\n end BM_Entry;\n\n benchmark_map : constant Benchmark_Info_Array := (\n BM_Entry(\"cholesky\",\n \"[size=256][iterations=1][spacing=0]\",\n Benchmark.Matrix.Cholesky.Create_Cholesky'Access),\n BM_Entry(\"hash\",\n \"[size=1024][iterations=1000][spacing=0][seed=15]\",\n Benchmark.Hash.Create_Hash'Access),\n BM_Entry(\"heap\",\n \"[size=1024][spacing=0][seed=15]\",\n Benchmark.Heap.Create_Heap'Access),\n BM_Entry(\"lu\",\n \"[size=256][iterations=1][spacing=0]\",\n Benchmark.Matrix.LU.Create_LU'Access),\n BM_Entry(\"mm\",\n \"[size=256][iterations=1][spacing=0][seed=15]\",\n Benchmark.Matrix.MM.Create_MM'Access),\n BM_Entry(\"qsort\",\n \"[size=1024][iterations=1][spacing=0][seed=15]\",\n Benchmark.QSort.Create_QSort'Access),\n BM_Entry(\"stride\",\n \"[size=1024][iterations=1000][stride=1][spacing=0]\",\n Benchmark.Stride.Create_Stride'Access),\n BM_Entry(\"trace\",\n \"[file=trace.txt][spacing=0]\",\n Benchmark.Trace.Create_Trace'Access),\n BM_Entry(\"tree\",\n \"[size=1024][iterations=10000][spacing=0]\",\n Benchmark.Tree.Create_Tree'Access)\n );\n\n procedure Show_Usage is\n begin\n Put_Line(\"usage: \" & Command_Name & \" [options] \" &\n \" { []}\");\n Put_Line(\"options:\");\n Put_Line(\" -addr_bits Number of address bits\");\n Put_Line(\" -device Device type (asic, virtex6, ...)\");\n Put_Line(\"benchmarks:\");\n for i in benchmark_map'First .. benchmark_map'Last loop\n Put_Line(\" \" & To_String(benchmark_map(i).name & \" \" &\n To_String(benchmark_map(i).usage)));\n end loop;\n Put_Line(\" show\");\n end Show_Usage;\n\nbegin\n\n -- Run the tests if requested.\n if Argument_Count = 1 and then Argument(1) = \"test\" then\n Test.Run_Tests;\n return;\n end if;\n\n -- Parse options.\n Parse_Options: while arg < Argument_Count loop\n begin\n if Argument(arg) = \"-addr_bits\" then\n Device.Set_Address_Bits(Positive'Value(Argument(arg + 1)));\n arg := arg + 2;\n elsif Argument(arg) = \"-device\" then\n Device.Set_Device(Argument(arg + 1));\n arg := arg + 2;\n else\n exit Parse_Options;\n end if;\n exception\n when others =>\n Put_Line(\"error: invalid option value\");\n return;" + }, + { + "function_def": "procedure Finish_Run(mem : in out Super_Type) is", + "function_body": "context : constant Context_Pointer := mem.context;\n cost : constant Cost_Type := Get_Cost(mem);\n value : Value_Type := Get_Value(mem'Access);\n sum : Long_Float;\n count : Long_Float;\n total : Long_Integer;\n var : LF_Variance.Variance_Type;\n result : Result_Type;\n begin\n\n -- Scale the result if necessary.\n if mem.current_length > context.total_length then\n context.total_length := mem.current_length;\n end if;\n if mem.current_length /= context.total_length then\n Put_Line(\"Prune\");\n declare\n mult : constant Long_Float := Long_Float(context.total_length) /\n Long_Float(mem.current_length);\n fval : constant Long_Float := Long_Float(value) * mult;\n begin\n if fval >= Long_Float(Value_Type'Last) then\n value := Value_Type'Last;\n else\n value := Value_Type(fval);\n end if;" + }, + { + "function_def": "procedure Destroy is new Ada.Unchecked_Deallocation(Distribution_Type,", + "function_body": "Distribution_Pointer);\n\n procedure Destroy is new Ada.Unchecked_Deallocation(Context_Type,\n Context_Pointer);\n\n procedure Finalize(mem : in out Super_Type) is\n begin\n for i in mem.contexts.First_Index .. mem.contexts.Last_Index loop\n declare\n cp : Context_Pointer := mem.contexts.Element(i);\n begin\n Destroy(cp);" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation(Cache_Data, Cache_Data_Pointer);\n\n function Create_Cache(mem : access Memory_Type'Class;\n line_count : Positive := 1;\n line_size : Positive := 8;\n associativity : Positive := 1;\n latency : Time_Type := 1;\n policy : Policy_Type := LRU;\n write_back : Boolean := True)\n return Cache_Pointer is\n result : constant Cache_Pointer := new Cache_Type;\n begin\n Set_Memory(result.all, mem);\n result.line_size := line_size;\n result.line_count := line_count;\n result.associativity := associativity;\n result.latency := latency;\n result.policy := policy;\n result.write_back := write_back;\n result.data.Set_Length(Count_Type(result.line_count));\n for i in 0 .. result.line_count - 1 loop\n result.data.Replace_Element(i, new Cache_Data);\n end loop;\n return result;\n end Create_Cache;\n\n function Random_Policy is new Random_Enum(Policy_Type);\n\n function Random_Boolean is new Random_Enum(Boolean);\n\n -- Set the latency based on associativity.\n procedure Update_Latency(mem : in out Cache_Type'Class) is\n begin\n if Get_Device = ASIC then\n mem.latency := CACTI.Get_Time(mem);\n else\n case mem.policy is\n when PLRU =>\n mem.latency := 3 + Time_Type(mem.associativity) / 8;\n when others =>\n mem.latency := 3 + Time_Type(mem.associativity) / 4;\n end case;\n end if;\n end Update_Latency;\n\n function Random_Cache(next : access Memory_Type'Class;\n generator : Distribution_Type;\n max_cost : Cost_Type)\n return Memory_Pointer is\n result : Cache_Pointer := new Cache_Type;\n begin\n\n -- Start with everything set to the minimum.\n Set_Memory(result.all, next);\n result.line_size := Get_Word_Size(next.all);\n result.line_count := MIN_LINE_COUNT;\n result.associativity := 1;\n result.policy := LRU;\n result.write_back := True;\n\n -- If even the minimum cache is too costly, return null.\n if Get_Cost(result.all) > max_cost then\n Set_Memory(result.all, null);\n Destroy(Memory_Pointer(result));\n return Memory_Pointer(next);\n end if;\n\n -- Randomly increase parameters, reverting them if we exceed the cost.\n loop\n\n -- Line size.\n declare\n line_size : constant Positive := result.line_size;\n begin\n if Random_Boolean(Random(generator)) then\n result.line_size := line_size * 2;\n if Get_Cost(result.all) > max_cost then\n result.line_size := line_size;\n exit;\n end if;\n end if;" + }, + { + "function_def": "function Insert_Register(mem : Memory_Pointer) return Boolean is", + "function_body": "max_path : constant Natural := Device.Get_Max_Path;\n begin\n\n if Get_Path_Length(mem.all) <= max_path then\n return False;\n end if;\n\n if mem.all in Split_Type'Class then\n\n declare\n sp : constant Split_Pointer := Split_Pointer(mem);\n np : constant Memory_Pointer := Get_Memory(sp.all);\n b0 : constant Memory_Pointer := Get_Bank(sp.all, 0);\n b1 : constant Memory_Pointer := Get_Bank(sp.all, 1);\n begin\n\n if Insert_Register(np) then\n return True;\n end if;\n\n if Insert_Register(b0) then\n return True;\n end if;\n\n if Insert_Register(b1) then\n return True;\n end if;\n\n -- Insert two registers: one for each bank.\n Set_Bank(sp.all, 0, Create_Register(b0));\n Set_Bank(sp.all, 1, Create_Register(b1));\n\n return True;" + }, + { + "function_def": "procedure Insert_Registers(mem : access Memory_Type'Class) is", + "function_body": "begin\n\n -- Continue inserting registers until we either no longer exceed\n -- the max path length or we are unable to reduce the path length.\n loop\n exit when not Insert_Register(Memory_Pointer(mem));\n end loop;\n\n end Insert_Registers;\n\n function Remove_Registers(mem : Memory_Pointer) return Memory_Pointer is\n begin\n if mem = null then\n return null;\n elsif mem.all in Register_Type'Class then\n declare\n rp : Register_Pointer := Register_Pointer(mem);\n np : constant Memory_Pointer := Get_Memory(rp.all);\n begin\n Set_Memory(rp.all, null);\n Destroy(Memory_Pointer(rp));\n return Remove_Registers(np);" + }, + { + "function_def": "procedure Parse_Register(parser : in out Parser_Type;", + "function_body": "result : out Memory_Pointer) is separate;\n\n procedure Parse_Shift(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n procedure Parse_Split(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n procedure Parse_SPM(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n procedure Parse_Stats(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n procedure Parse_Super(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n procedure Parse_Trace(parser : in out Parser_Type;\n result : out Memory_Pointer) is separate;\n\n type Memory_Parser_Type is record\n name : Unbounded_String;\n parser : access procedure(parser : in out Parser_Type;\n result : out Memory_Pointer);\n end record;\n\n type Memory_Parser_Array is array(Positive range <>) of Memory_Parser_Type;\n\n parser_map : constant Memory_Parser_Array := (\n (To_Unbounded_String(\"arbiter\"), Parse_Arbiter'Access),\n (To_Unbounded_String(\"cache\"), Parse_Cache'Access),\n (To_Unbounded_String(\"dram\"), Parse_DRAM'Access),\n (To_Unbounded_String(\"dup\"), Parse_Dup'Access),\n (To_Unbounded_String(\"eor\"), Parse_EOR'Access),\n (To_Unbounded_String(\"flash\"), Parse_Flash'Access),\n (To_Unbounded_String(\"flip\"), Parse_Flip'Access),\n (To_Unbounded_String(\"join\"), Parse_Join'Access),\n (To_Unbounded_String(\"offset\"), Parse_Offset'Access),\n (To_Unbounded_String(\"option\"), Parse_Option'Access),\n (To_Unbounded_String(\"perfect_prefetch\"), Parse_Perfect_Prefetch'Access),\n (To_Unbounded_String(\"prefetch\"), Parse_Prefetch'Access),\n (To_Unbounded_String(\"ram\"), Parse_RAM'Access),\n (To_Unbounded_String(\"register\"), Parse_Register'Access),\n (To_Unbounded_String(\"shift\"), Parse_Shift'Access),\n (To_Unbounded_String(\"split\"), Parse_Split'Access),\n (To_Unbounded_String(\"spm\"), Parse_SPM'Access),\n (To_Unbounded_String(\"stats\"), Parse_Stats'Access),\n (To_Unbounded_String(\"super\"), Parse_Super'Access),\n (To_Unbounded_String(\"trace\"), Parse_Trace'Access)\n );\n\n function Parse_Boolean(value : String) return Boolean is\n begin\n if value = \"true\" then\n return True;\n elsif value = \"false\" then\n return False;\n else\n raise Data_Error;\n end if;\n end Parse_Boolean;\n\n procedure Parse_Memory(parser : in out Parser_Type;\n result : out Memory_Pointer) is\n begin\n Match(parser, Open);\n declare\n name : constant String := Get_Value(parser.lexer);\n begin\n Next(parser.lexer);\n for i in parser_map'First .. parser_map'Last loop\n if parser_map(i).name = name then\n parser_map(i).parser(parser, result);\n Match(parser, Close);\n return;\n end if;\n end loop;\n Raise_Error(parser, \"invalid memory type: \" & name);" + }, + { + "function_def": "procedure Raise_Error(parser : in Parser_Type;", + "function_body": "msg : in String) is\n name : constant String := Get_File_Name(parser.lexer);\n line : constant String := Positive'Image(Get_Line(parser.lexer));\n begin\n Put_Line(name & \"[\" & line(2 .. line'Last) & \"]: error: \" & msg);\n raise Parse_Error;\n end Raise_Error;\n\n function Get_Type(parser : Parser_Type) return Token_Type is\n begin\n return Get_Type(parser.lexer);\n end Get_Type;\n\n function Get_Value(parser : Parser_Type) return String is\n begin\n return Get_Value(parser.lexer);\n end Get_Value;\n\n procedure Match(parser : in out Parser_Type;\n token : in Token_Type) is\n begin\n if Get_Type(parser) /= token then\n Raise_Error(parser, \"got '\" & Get_Value(parser) &\n \"' expected '\" & Token_Type'Image(token) & \"'\");\n end if;\n Next(parser.lexer);\n end Match;\n\n procedure Push_Wrapper(parser : in out Parser_Type;\n wrapper : in Wrapper_Pointer;\n count : in Positive := 1) is\n last : constant Natural := Natural(count);\n begin\n parser.wrappers.Append(Wrapper_Node'(wrapper, 0, last));\n end Push_Wrapper;\n\n procedure Pop_Wrapper(parser : in out Parser_Type;\n wrapper : out Wrapper_Pointer;\n index : out Natural) is\n begin\n if parser.wrappers.Is_Empty then\n Raise_Error(parser, \"unexpected join\");\n end if;\n declare\n node : Wrapper_Node := parser.wrappers.Last_Element;\n begin\n wrapper := node.wrapper;\n index := node.current;\n node.current := node.current + 1;\n if node.current = node.last then\n Delete_Wrapper(parser);\n else\n parser.wrappers.Replace_Element(parser.wrappers.Last, node);\n end if;" + }, + { + "function_def": "function Create_From_Status is", + "function_body": "new AWA.Helpers.Selectors.Create_From_Enum (Jason.Tickets.Models.Status_Type,\n \"ticket_status\");\n\n function Create_From_Ticket_Type is\n new AWA.Helpers.Selectors.Create_From_Enum (Jason.Tickets.Models.Ticket_Type,\n \"ticket_type\");\n\n procedure Append (Into : in out Ada.Strings.Unbounded.Unbounded_String;\n Value : in Jason.Tickets.Models.Status_Type);\n function To_Priority (Value : in Util.Beans.Objects.Object) return Integer;\n\n -- ------------------------------\n -- Get a select item list which contains a list of ticket status.\n -- ------------------------------\n function Create_Status_List (Module : in Jason.Tickets.Modules.Ticket_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n pragma Unreferenced (Module);\n use AWA.Helpers;\n begin\n return Selectors.Create_Selector_Bean (Bundle => \"tickets\",\n Context => null,\n Create => Create_From_Status'Access).all'Access;\n end Create_Status_List;\n\n -- ------------------------------\n -- Get a select item list which contains a list of ticket types.\n -- ------------------------------\n function Create_Type_List (Module : in Jason.Tickets.Modules.Ticket_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n pragma Unreferenced (Module);\n use AWA.Helpers;\n begin\n return Selectors.Create_Selector_Bean (Bundle => \"tickets\",\n Context => null,\n Create => Create_From_Ticket_Type'Access).all'Access;\n end Create_Type_List;\n\n -- ------------------------------\n -- Create ticket action.\n -- ------------------------------\n overriding\n procedure Create (Bean : in out Ticket_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n pragma Unreferenced (Outcome);\n begin\n Bean.Module.Create (Bean, Bean.Project.Get_Id);\n Bean.Tags.Update_Tags (Bean.Get_Id);\n end Create;\n\n -- Save ticket action.\n overriding\n procedure Save (Bean : in out Ticket_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n pragma Unreferenced (Outcome);\n begin\n Bean.Module.Save (Bean, Ada.Strings.Unbounded.To_String (Bean.Comment));\n Bean.Tags.Update_Tags (Bean.Get_Id);\n end Save;\n\n -- Save ticket action.\n overriding\n procedure Save_Status (Bean : in out Ticket_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n pragma Unreferenced (Outcome);\n begin\n Bean.Module.Save (Bean, Ada.Strings.Unbounded.To_String (Bean.Comment));\n end Save_Status;\n\n -- Load ticket action.\n overriding\n procedure Load (Bean : in out Ticket_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n use type AWA.Comments.Beans.Comment_List_Bean_Access;\n\n Comment_List : AWA.Comments.Beans.Comment_List_Bean_Access;\n begin\n Bean.Module.Load_Ticket (Bean, Bean.Project.all, Bean.Tags, Bean.Ticket_Id);\n Comment_List := AWA.Comments.Beans.Get_Comment_List_Bean (\"ticketComments\");\n if Comment_List /= null then\n Comment_List.Load_Comments (Bean.Get_Id);\n end if;\n Outcome := Ada.Strings.Unbounded.To_Unbounded_String (\"loaded\");\n end Load;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Ticket_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"project_id\" then\n if From.Project.Is_Inserted then\n return ADO.Utils.To_Object (From.Project.Get_Id);\n else\n return ADO.Utils.To_Object (From.Project.Get_Id);\n end if;\n elsif Name = \"ticket_id\" or Name = \"id\" then\n if From.Is_Inserted or From.Is_Loaded then\n return ADO.Utils.To_Object (From.Get_Id);\n else\n return ADO.Utils.To_Object (From.Ticket_Id);\n end if;\n elsif Name = \"tags\" then\n return Util.Beans.Objects.To_Object (From.Tags_Bean, Util.Beans.Objects.STATIC);\n else\n return Jason.Tickets.Models.Ticket_Bean (From).Get_Value (Name);\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Ticket_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n if Name = \"project_id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Project.Set_Id (ADO.Utils.To_Identifier (Value));\n elsif Name = \"ticket_id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Ticket_Id := ADO.Utils.To_Identifier (Value);\n elsif Name = \"id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Ticket_Id := ADO.Utils.To_Identifier (Value);\n From.Module.Load_Ticket (From, From.Project.all, From.Tags, From.Ticket_Id);\n else\n Jason.Tickets.Models.Ticket_Bean (From).Set_Value (Name, Value);\n end if;\n end Set_Value;\n\n -- ------------------------------\n -- Create the Ticket_Bean bean instance.\n -- ------------------------------\n function Create_Ticket_Bean (Module : in Jason.Tickets.Modules.Ticket_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Ticket_Bean_Access := new Ticket_Bean;\n begin\n Object.Module := Module;\n Object.Tags_Bean := Object.Tags'Access;\n Object.Tags.Set_Entity_Type (Jason.Tickets.Models.TICKET_TABLE);\n Object.Tags.Set_Permission (\"ticket-update\");\n Object.Project := Jason.Projects.Beans.Get_Project_Bean (\"project\");\n return Object.all'Access;\n end Create_Ticket_Bean;\n\n -- Get the value identified by the name.\n overriding\n function Get_Value (From : in Ticket_List_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n Pos : Natural;\n begin\n if Name = \"tags\" then\n Pos := From.Tickets.Get_Row_Index;\n if Pos = 0 then\n return Util.Beans.Objects.Null_Object;\n end if;\n declare\n Item : constant Models.List_Info := From.Tickets.List.Element (Pos - 1);\n begin\n return From.Tags.Get_Tags (Item.Id);" + }, + { + "function_def": "function Create_Ticket_List_Bean (Module : in Jason.Tickets.Modules.Ticket_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Ticket_List_Bean_Access := new Ticket_List_Bean;\n begin\n Object.Module := Module;\n Object.Page_Size := 20;\n Object.Count := 0;\n Object.Page := 1;\n Object.Priority := 0;\n Object.Project_Id := ADO.NO_IDENTIFIER;\n Object.Status := Jason.Tickets.Models.OPEN;\n Object.Status_Filter := Ada.Strings.Unbounded.To_Unbounded_String (\"pending\");\n Object.Tickets_Bean := Object.Tickets'Access;\n Object.Project := Jason.Projects.Beans.Get_Project_Bean (\"project\");\n return Object.all'Access;\n end Create_Ticket_List_Bean;\n\n procedure Initialize (Object : in out Ticket_Raw_Stat_Bean) is\n begin\n Object.Low_Bean := Util.Beans.Objects.To_Object (Object.Low'Unchecked_Access,\n Util.Beans.Objects.STATIC);\n Object.High_Bean := Util.Beans.Objects.To_Object (Object.High'Unchecked_Access,\n Util.Beans.Objects.STATIC);\n Object.Medium_Bean := Util.Beans.Objects.To_Object (Object.Medium'Unchecked_Access,\n Util.Beans.Objects.STATIC);\n Object.Closed_Bean := Util.Beans.Objects.To_Object (Object.Closed'Unchecked_Access,\n Util.Beans.Objects.STATIC);\n end Initialize;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Ticket_Raw_Stat_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"low\" then\n return From.Low_Bean;\n elsif Name = \"medium\" then\n return From.Medium_Bean;\n elsif Name = \"high\" then\n return From.High_Bean;\n elsif Name = \"closed\" then\n return From.Closed_Bean;\n elsif Name = \"progress\" then\n return Util.Beans.Objects.To_Object (From.Progress);\n else\n return Jason.Tickets.Models.Stat_Bean (From).Get_Value (Name);\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Ticket_Report_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if name = \"count\" then\n return Util.Beans.Objects.To_Object (Natural (From.Report.Length));\n elsif name = \"total\" then\n return From.Total_Bean;\n end if;\n return Util.Beans.Objects.Null_Object;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Ticket_Report_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n null;\n end Set_Value;\n\n -- ------------------------------\n -- Get the number of elements in the list.\n -- ------------------------------\n function Get_Count (From : Ticket_Report_Bean) return Natural is\n begin\n return Natural (From.Report.Length);\n end Get_Count;\n\n -- ------------------------------\n -- Set the current row index. Valid row indexes start at 1.\n -- ------------------------------\n overriding\n procedure Set_Row_Index (From : in out Ticket_Report_Bean;\n Index : in Natural) is\n begin\n if Index = 1 then\n From.Current := From.Report.First;\n From.Current_Pos := Index;\n elsif Index = Natural (From.Report.Length) then\n From.Current := From.Report.Last;\n From.Current_Pos := Index;\n else\n while Index > From.Current_Pos and Ticket_Stat_Vectors.Has_Element (From.Current) loop\n Ticket_Stat_Vectors.Next (From.Current);\n From.Current_Pos := From.Current_Pos + 1;\n end loop;\n end if;\n Ticket_Stat_Bean (From.Element) := Ticket_Stat_Vectors.Element (From.Report,\n From.Current_Pos);\n end Set_Row_Index;\n\n -- ------------------------------\n -- Get the element at the current row index.\n -- ------------------------------\n overriding\n function Get_Row (From : in Ticket_Report_Bean) return Util.Beans.Objects.Object is\n begin\n return From.Row;\n end Get_Row;\n\n -- ------------------------------\n -- Load the information for the tickets.\n -- ------------------------------\n overriding\n procedure Load (Bean : in out Ticket_Report_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n pragma Unreferenced (Outcome);\n\n Session : constant ADO.Sessions.Session := Bean.Module.Get_Session;\n Query : ADO.Queries.Context;\n Empty : constant Jason.Tickets.Models.Stat_Bean := (Kind => Models.WORK,\n others => 0);\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n begin\n Query.Set_Query (Jason.Tickets.Models.Query_Stats);\n Query.Bind_Param (\"project_id\", Bean.Project.Get_Id);\n Query.Bind_Param (\"user_id\", User.Get_Id);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"project_table\",\n Table => Jason.Projects.Models.PROJECT_TABLE,\n Session => Session);\n declare\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n begin\n Stmt.Execute;\n while Stmt.Has_Elements loop\n declare\n use Models;\n\n Status : constant Models.Status_Type := Status_Type'Val (Stmt.Get_Integer (0));\n Kind : constant Models.Ticket_Type := Ticket_Type'Val (Stmt.Get_Integer (1));\n Priority : constant Natural := Stmt.Get_Integer (2);\n Count : constant Natural := Stmt.Get_Integer (3);\n Time : constant Natural := Stmt.Get_Integer (4);\n Done : constant Natural := Stmt.Get_Integer (5);\n Remain : constant Natural := Stmt.Get_Integer (6);\n\n procedure Update (Key : in Models.Ticket_Type;\n Item : in out Ticket_Stat_Bean);\n\n procedure Update (Key : in Models.Ticket_Type;\n Item : in out Ticket_Stat_Bean) is\n pragma Unreferenced (Key);\n begin\n if Status = Models.CLOSED or Status = Models.REJECTED then\n Item.Closed.Count := Item.Closed.Count + Count;\n Item.Closed.Time := Item.Closed.Time + Time;\n Item.Closed.Done := Item.Closed.Done + Done;\n Item.Closed.Remain := Item.Closed.Remain + Remain;\n elsif Priority <= 3 then\n Item.High.Count := Item.High.Count + Count;\n Item.High.Time := Item.High.Time + Time;\n Item.High.Done := Item.High.Done + Done;\n Item.High.Remain := Item.High.Remain + Remain;\n elsif Priority > 4 then\n Item.Low.Count := Item.Low.Count + Count;\n Item.Low.Time := Item.Low.Time + Time;\n Item.Low.Done := Item.Low.Done + Done;\n Item.Low.Remain := Item.Low.Remain + Remain;\n else\n Item.Medium.Count := Item.Medium.Count + Count;\n Item.Medium.Time := Item.Medium.Time + Time;\n Item.Medium.Done := Item.Medium.Done + Done;\n Item.Medium.Remain := Item.Medium.Remain + Remain;\n end if;\n end Update;\n\n Pos : constant Ticket_Stat_Map.Cursor := Bean.List.Find (Kind);\n begin\n if Ticket_Stat_Map.Has_Element (Pos) then\n Bean.List.Update_Element (Pos, Update'Access);\n else\n declare\n T : Ticket_Stat_Bean;\n begin\n T.Kind := Kind;\n T.Count := 0;\n T.Time := 0;\n T.Remain := 0;\n T.High := Empty;\n T.Low := Empty;\n T.Medium := Empty;\n T.Closed := Empty;\n Update (Kind, T);\n Bean.List.Insert (Kind, T);" + }, + { + "function_def": "procedure Set_Field_Discrete is", + "function_body": "new ADO.Objects.Set_Field_Operation\n (Status_Type);\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Discrete (Impl.all, 7, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Ticket_Ref)\n return Status_Type is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Description (Object : in out Ticket_Ref;\n Value : in String) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 8, Impl.Description, Value);\n end Set_Description;\n\n procedure Set_Description (Object : in out Ticket_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 8, Impl.Description, Value);\n end Set_Description;\n\n function Get_Description (Object : in Ticket_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Description);\n end Get_Description;\n function Get_Description (Object : in Ticket_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Description;\n end Get_Description;\n\n\n procedure Set_Update_Date (Object : in out Ticket_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 9, Impl.Update_Date, Value);\n end Set_Update_Date;\n\n function Get_Update_Date (Object : in Ticket_Ref)\n return Ada.Calendar.Time is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Update_Date;\n end Get_Update_Date;\n\n\n procedure Set_Kind (Object : in out Ticket_Ref;\n Value : in Ticket_Type) is\n procedure Set_Field_Discrete is\n new ADO.Objects.Set_Field_Operation\n (Ticket_Type);\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Discrete (Impl.all, 10, Impl.Kind, Value);\n end Set_Kind;\n\n function Get_Kind (Object : in Ticket_Ref)\n return Ticket_Type is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Kind;\n end Get_Kind;\n\n\n procedure Set_Duration (Object : in out Ticket_Ref;\n Value : in Integer) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 11, Impl.Duration, Value);\n end Set_Duration;\n\n function Get_Duration (Object : in Ticket_Ref)\n return Integer is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Duration;\n end Get_Duration;\n\n\n procedure Set_Progress (Object : in out Ticket_Ref;\n Value : in Integer) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 12, Impl.Progress, Value);\n end Set_Progress;\n\n function Get_Progress (Object : in Ticket_Ref)\n return Integer is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Progress;\n end Get_Progress;\n\n\n procedure Set_Project (Object : in out Ticket_Ref;\n Value : in Jason.Projects.Models.Project_Ref'Class) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 13, Impl.Project, Value);\n end Set_Project;\n\n function Get_Project (Object : in Ticket_Ref)\n return Jason.Projects.Models.Project_Ref'Class is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Project;\n end Get_Project;\n\n\n procedure Set_Creator (Object : in out Ticket_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Ticket_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 14, Impl.Creator, Value);\n end Set_Creator;\n\n function Get_Creator (Object : in Ticket_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Creator;\n end Get_Creator;\n\n -- Copy of the object.\n procedure Copy (Object : in Ticket_Ref;\n Into : in out Ticket_Ref) is\n Result : Ticket_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Ticket_Access\n := Ticket_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Ticket_Access\n := new Ticket_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Version := Impl.Version;\n Copy.Summary := Impl.Summary;\n Copy.Ident := Impl.Ident;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Priority := Impl.Priority;\n Copy.Status := Impl.Status;\n Copy.Description := Impl.Description;\n Copy.Update_Date := Impl.Update_Date;\n Copy.Kind := Impl.Kind;\n Copy.Duration := Impl.Duration;\n Copy.Progress := Impl.Progress;\n Copy.Project := Impl.Project;\n Copy.Creator := Impl.Creator;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Ticket_Impl, Ticket_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Ticket_Impl_Ptr := Ticket_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Ticket_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TICKET_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Ticket_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Ticket_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (TICKET_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- summary\n Value => Object.Summary);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- ident\n Value => Object.Ident);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- priority\n Value => Object.Priority);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- status\n Value => Integer (Status_Type'Enum_Rep (Object.Status)));\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- description\n Value => Object.Description);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- update_date\n Value => Object.Update_Date);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_1_NAME, -- kind\n Value => Integer (Ticket_Type'Enum_Rep (Object.Kind)));\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_1_NAME, -- duration\n Value => Object.Duration);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_1_NAME, -- progress\n Value => Object.Progress);\n Object.Clear_Modified (12);\n end if;\n if Object.Is_Modified (13) then\n Stmt.Save_Field (Name => COL_12_1_NAME, -- project_id\n Value => Object.Project);\n Object.Clear_Modified (13);\n end if;\n if Object.Is_Modified (14) then\n Stmt.Save_Field (Name => COL_13_1_NAME, -- creator_id\n Value => Object.Creator);\n Object.Clear_Modified (14);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Ticket_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TICKET_DEF'Access);\n begin\n Stmt.Execute;\n Ticket_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Ticket_Ref;\n Impl : constant Ticket_Access := new Ticket_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Attribute_Impl, Attribute_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Attribute_Impl_Ptr := Attribute_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Attribute_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ATTRIBUTE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Attribute_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Attribute_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (ATTRIBUTE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- value\n Value => Object.Value);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- definition_id\n Value => Object.Definition);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- ticket_id\n Value => Object.Ticket);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Attribute_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ATTRIBUTE_DEF'Access);\n begin\n Stmt.Execute;\n Attribute_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Attribute_Ref;\n Impl : constant Attribute_Access := new Attribute_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Set_Field_Discrete is", + "function_body": "new ADO.Objects.Set_Field_Operation\n (Status_Type);\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Discrete (Impl.all, 5, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Project_Ref)\n return Status_Type is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Last_Ticket (Object : in out Project_Ref;\n Value : in Integer) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 6, Impl.Last_Ticket, Value);\n end Set_Last_Ticket;\n\n function Get_Last_Ticket (Object : in Project_Ref)\n return Integer is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Last_Ticket;\n end Get_Last_Ticket;\n\n\n procedure Set_Update_Date (Object : in out Project_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 7, Impl.Update_Date, Value);\n end Set_Update_Date;\n\n function Get_Update_Date (Object : in Project_Ref)\n return Ada.Calendar.Time is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Update_Date;\n end Get_Update_Date;\n\n\n procedure Set_Description (Object : in out Project_Ref;\n Value : in String) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 8, Impl.Description, Value);\n end Set_Description;\n\n procedure Set_Description (Object : in out Project_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 8, Impl.Description, Value);\n end Set_Description;\n\n function Get_Description (Object : in Project_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Description);\n end Get_Description;\n function Get_Description (Object : in Project_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Description;\n end Get_Description;\n\n\n procedure Set_Wiki (Object : in out Project_Ref;\n Value : in AWA.Wikis.Models.Wiki_Space_Ref'Class) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.Wiki, Value);\n end Set_Wiki;\n\n function Get_Wiki (Object : in Project_Ref)\n return AWA.Wikis.Models.Wiki_Space_Ref'Class is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Wiki;\n end Get_Wiki;\n\n\n procedure Set_Owner (Object : in out Project_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Project_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 10, Impl.Owner, Value);\n end Set_Owner;\n\n function Get_Owner (Object : in Project_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Owner;\n end Get_Owner;\n\n -- Copy of the object.\n procedure Copy (Object : in Project_Ref;\n Into : in out Project_Ref) is\n Result : Project_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Project_Access\n := Project_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Project_Access\n := new Project_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Version := Impl.Version;\n Copy.Name := Impl.Name;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Status := Impl.Status;\n Copy.Last_Ticket := Impl.Last_Ticket;\n Copy.Update_Date := Impl.Update_Date;\n Copy.Description := Impl.Description;\n Copy.Wiki := Impl.Wiki;\n Copy.Owner := Impl.Owner;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Project_Impl, Project_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Project_Impl_Ptr := Project_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Project_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, PROJECT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Project_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Project_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (PROJECT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- status\n Value => Integer (Status_Type'Enum_Rep (Object.Status)));\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- last_ticket\n Value => Object.Last_Ticket);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- update_date\n Value => Object.Update_Date);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- description\n Value => Object.Description);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- wiki_id\n Value => Object.Wiki);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_1_NAME, -- owner_id\n Value => Object.Owner);\n Object.Clear_Modified (10);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Project_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, PROJECT_DEF'Access);\n begin\n Stmt.Execute;\n Project_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Project_Ref;\n Impl : constant Project_Access := new Project_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Attribute_Definition_Impl, Attribute_Definition_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Attribute_Definition_Impl_Ptr := Attribute_Definition_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Attribute_Definition_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ATTRIBUTE_DEFINITION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Attribute_Definition_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Attribute_Definition_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (ATTRIBUTE_DEFINITION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- default_value\n Value => Object.Default_Value);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- project_id\n Value => Object.Project);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Attribute_Definition_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ATTRIBUTE_DEFINITION_DEF'Access);\n begin\n Stmt.Execute;\n Attribute_Definition_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Attribute_Definition_Ref;\n Impl : constant Attribute_Definition_Access := new Attribute_Definition_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "function Unchecked_To_Unsigned_16 is", + "function_body": "new Ada.Unchecked_Conversion (Octets_2, Unsigned_16);\n\n function Unchecked_To_Unsigned_32 is\n new Ada.Unchecked_Conversion (Octets_4, Unsigned_32);\n\n function Unchecked_To_Octets_2 is\n new Ada.Unchecked_Conversion (Unsigned_16, Octets_2);\n\n function Unchecked_To_Octets_4 is\n new Ada.Unchecked_Conversion (Unsigned_32, Octets_4);\n\n function Swap_Bus (X : Unsigned_16) return Unsigned_16\n is\n O : Octets_2 with\n Address => X'Address, Alignment => Unsigned_16'Alignment;\n begin\n if System.Default_Bit_Order = System.Low_Order_First then\n return X;\n else\n return Unchecked_To_Unsigned_16 ((O (1), O (0)));\n end if;\n end Swap_Bus;\n\n function Swap_Bus (X : Unsigned_32) return Unsigned_32\n is\n O : Octets_4 with\n Address => X'Address, Alignment => Unsigned_32'Alignment;\n begin\n if System.Default_Bit_Order = System.Low_Order_First then\n return X;\n else\n return Unchecked_To_Unsigned_32 ((O (3), O (2), O (1), O (0)));\n end if;\n end Swap_Bus;\n\n function Swap_Bus (X : Octets_2) return Unsigned_16\n is\n begin\n if System.Default_Bit_Order = System.Low_Order_First then\n return Unchecked_To_Unsigned_16 (X);\n else\n return Unchecked_To_Unsigned_16 ((X (1), X (0)));\n end if;\n end Swap_Bus;\n\n function Swap_Bus (X : Octets_4) return Unsigned_32\n is\n begin\n if System.Default_Bit_Order = System.Low_Order_First then\n return Unchecked_To_Unsigned_32 (X);\n else\n return Unchecked_To_Unsigned_32 ((X (3), X (2), X (1), X (0)));\n end if;\n end Swap_Bus;\n\n function Swap_Bus (X : Unsigned_16) return Octets_2\n is\n begin\n if System.Default_Bit_Order = System.Low_Order_First then\n return Unchecked_To_Octets_2 (X);\n else\n declare\n O : constant Octets_2 := Unchecked_To_Octets_2 (X);\n begin\n return (O (1), O (0));" + }, + { + "function_def": "function Object_Exist", + "function_body": "(This : Object_Dictionary'Class;\n Index : Object_Index) return Boolean\n is (This.Index_Map (Index) /= No_Index);\n\n function Entry_Exist\n (This : Object_Dictionary'Class;\n Index : Object_Index;\n Subindex : Object_Subindex) return Boolean\n is\n Arr_Idx : constant Index_Type := This.Index_Map (Index);\n begin\n return Arr_Idx /= No_Index and then\n Subindex in This.Objects (Arr_Idx).Entries'Range;\n end Entry_Exist;\n\n function Maximum_Nof_Entries\n (This : Object_Dictionary;\n Index : Object_Index)\n return Natural\n is (This.Object (Index).Entries'Length);\n\n function Is_Entry_Compatible\n (This : Object_Dictionary;\n An_Entry : Entry_Base'Class;\n Index : Object_Index;\n Subindex : Object_Subindex)\n return Boolean\n is\n use type Ada.Tags.Tag;\n\n OD_Entry : constant Entry_Ref := This.Object (Index).Entries (Subindex);\n begin\n return OD_Entry'Tag = An_Entry'Tag;\n end Is_Entry_Compatible;\n\n function Is_Entry_Writable\n (This : Object_Dictionary;\n Index : Entry_Index)\n return Boolean\n is\n begin\n if This.Entry_Exist (Index.Object, Index.Sub) then\n return This.Object (Index.Object).Entries (Index.Sub).Is_Writable;\n else\n return False;\n end if;\n end Is_Entry_Writable;\n\n function Is_Entry_Readable\n (This : Object_Dictionary;\n Index : Entry_Index)\n return Boolean\n is\n begin\n if This.Entry_Exist (Index.Object, Index.Sub) then\n return This.Object (Index.Object).Entries (Index.Sub).Is_Readable;\n else\n return False;\n end if;\n end Is_Entry_Readable;\n\n function Get_Entry\n (This : Object_Dictionary;\n Index : Object_Index;\n Subindex : Object_Subindex) return Entry_Base'Class\n is\n (This.Object (Index).Entries (Subindex).all);\n\n procedure Set_Entry\n (This : in out Object_Dictionary;\n New_Entry : in Entry_Base'Class;\n Index : in Object_Index;\n Subindex : in Object_Subindex;\n Silently : in Boolean := False)\n is\n begin\n This.Object (Index).Entries (Subindex).all := New_Entry;\n if not Silently then\n This.Events.Node_Events.Put\n ((Event => ACO.Events.OD_Entry_Update,\n Index => (Index, Subindex)));\n end if;\n end Set_Entry;\n\n procedure Set_Node_State\n (This : in out Object_Dictionary;\n Node_State : in ACO.States.State)\n is\n Prev : ACO.States.State;\n begin\n Prev := This.Node_State;\n This.Node_State := Node_State;\n This.Events.Node_Events.Put\n ((Event => ACO.Events.State_Transition,\n State => (Previous => Prev, Current => Node_State)));\n end Set_Node_State;\n\n function Get_Node_State (This : Object_Dictionary) return ACO.States.State is\n (This.Node_State);\n\n function Get_Hbt_Node_Id (Reg : U32) return ACO.Messages.Node_Nr is\n (ACO.Messages.Node_Nr (Shift_Right (Reg, 16) and 16#FF#));\n\n function Get_Hbt_Slave_Subindex\n (This : Object_Dictionary;\n Node_Id : ACO.Messages.Node_Nr)\n return Object_Subindex\n is\n Object : constant Object_Ref := This.Object (Heartbeat_Consumer_Index);\n begin\n for I in 1 .. Object.Entries'Last loop\n declare\n E_Ref : constant Entry_Ref := Object.Entries (I);\n Reg : constant U32 := Entry_U32 (E_Ref.all).Read;\n use type ACO.Messages.Node_Nr;\n begin\n if Get_Hbt_Node_Id (Reg) = Node_Id then\n return Object_Subindex (I);\n end if;" + }, + { + "function_def": "function To_Data_Array is new Ada.Unchecked_Conversion (From, To);", + "function_body": "begin\n return To_Data_Array (D);\n end Convert;\n\n function Convert (D : ACO.Messages.Data_Array)\n return STM32.CAN.Message_Data\n is\n subtype From is ACO.Messages.Data_Array (D'Range);\n subtype To is STM32.CAN.Message_Data (D'Range);\n function To_Message_Data is new Ada.Unchecked_Conversion (From, To);\n begin\n return To_Message_Data (D);\n end Convert;\n\n overriding\n procedure Receive_Message_Blocking\n (This : in out CAN_Driver;\n Msg : out ACO.Messages.Message)\n is\n Rx_Msg : CAN_Message;\n begin\n -- Suspend until new CAN message is received\n This.Controller.Receive_Message (Rx_Msg);\n\n Msg := ACO.Messages.Create\n (CAN_Id => ACO.Messages.Id_Type (Rx_Msg.Std_ID),\n RTR => Rx_Msg.Rtr,\n DLC => ACO.Messages.Data_Length (Rx_Msg.Dlc),\n Data => Convert (Rx_Msg.Data));\n end Receive_Message_Blocking;\n\n overriding\n procedure Send_Message\n (This : in out CAN_Driver;\n Msg : in ACO.Messages.Message)\n is\n Success : Boolean;\n Tx_Msg : constant CAN_Message :=\n (Std_ID => Standard_Id (ACO.Messages.CAN_Id (Msg)),\n Ext_ID => 0,\n Ide => False,\n Rtr => Msg.RTR,\n Dlc => Data_Length_Type (Msg.Length),\n Data => Convert (Msg.Data));\n begin\n This.Controller.Transmit_Message\n (Message => Tx_Msg,\n Success => Success);\n end Send_Message;\n\n overriding\n procedure Initialize (This : in out CAN_Driver)\n is\n use STM32.GPIO;\n use STM32.Device;\n\n Tx_Pin : GPIO_Point renames PD1;\n Rx_Pin : GPIO_Point renames PD0;\n\n Fifo_X : constant Fifo_Nr := FIFO_0;\n\n -- For now, set to 125 kbit/s\n -- see http://www.bittiming.can-wiki.info/#bxCAN\n Bit_Timing : constant Bit_Timing_Config :=\n (Resynch_Jump_Width => 1,\n Time_Segment_1 => 13,\n Time_Segment_2 => 2,\n Quanta_Prescaler => 21);\n\n Mask_Allow_All : constant Filter_32 :=\n (Std_ID => 0,\n Ext_ID => 0,\n Ide => False,\n Rtr => False);\n\n Bank_Config : constant CAN_Filter_Bank :=\n (Bank_Nr => 0,\n Activated => True,\n Fifo_Assignment => Fifo_X,\n Filters => (Mask32, (Mask_Allow_All, Mask_Allow_All)));\n begin\n Enable_Clock (Points => (Tx_Pin, Rx_Pin));\n Configure_IO (Rx_Pin, (Mode_AF, Pull_Up, Push_Pull, Speed_50MHz, GPIO_AF_CAN1_9));\n Configure_IO (Tx_Pin, (Mode_AF, Floating, Push_Pull, Speed_50MHz, GPIO_AF_CAN1_9));\n\n Enable_Clock (This.Device.all);\n\n Reset (This.Device.all);\n\n Configure\n (This => This.Device.all,\n Mode => Normal,\n Time_Triggered => False,\n Auto_Bus_Off => False,\n Auto_Wakeup => False,\n Auto_Retransmission => False,\n Rx_FIFO_Locked => False,\n Tx_FIFO_Prio => False,\n Timing_Config => Bit_Timing);\n\n Set_Slave_Start_Bank (14);\n\n Configure_Filter\n (This => This.Device.all,\n Bank_Config => Bank_Config);\n\n This.Controller.Enable_Receiver (Fifo_X);\n end Initialize;\n\n overriding\n function Is_Message_Pending\n (This : CAN_Driver)\n return Boolean\n is\n begin\n return This.Controller.Is_Message_Pending;\n end Is_Message_Pending;\n\n\n overriding\n function Current_Time\n (This : CAN_Driver)\n return Ada.Real_Time.Time\n is\n pragma Unreferenced (This);\n begin\n return Ada.Real_Time.Clock;\n end Current_Time;\n\n package body CAN_ISR is\n function Tx_Interrupt_Id\n (Device : not null access CAN_Controller)\n return Ada.Interrupts.Interrupt_ID\n is\n begin\n if Device = STM32.Device.CAN_1'Access then\n return Ada.Interrupts.Names.CAN1_TX_Interrupt;\n elsif Device = STM32.Device.CAN_2'Access then\n return Ada.Interrupts.Names.CAN2_TX_Interrupt;\n else\n raise Constraint_Error;\n end if;\n end Tx_Interrupt_Id;\n\n function Rx0_Interrupt_Id\n (Device : not null access CAN_Controller)\n return Ada.Interrupts.Interrupt_ID\n is\n begin\n if Device = STM32.Device.CAN_1'Access then\n return Ada.Interrupts.Names.CAN1_RX0_Interrupt;\n elsif Device = STM32.Device.CAN_2'Access then\n return Ada.Interrupts.Names.CAN2_RX0_Interrupt;\n else\n raise Constraint_Error;\n end if;\n end Rx0_Interrupt_Id;\n\n function Rx1_Interrupt_Id\n (Device : not null access CAN_Controller)\n return Ada.Interrupts.Interrupt_ID\n is\n begin\n if Device = STM32.Device.CAN_1'Access then\n return Ada.Interrupts.Names.CAN1_RX1_Interrupt;\n elsif Device = STM32.Device.CAN_2'Access then\n return Ada.Interrupts.Names.CAN2_RX1_Interrupt;\n else\n raise Constraint_Error;\n end if;\n end Rx1_Interrupt_Id;\n\n function SCE_Interrupt_Id\n (Device : not null access CAN_Controller)\n return Ada.Interrupts.Interrupt_ID\n is\n begin\n if Device = STM32.Device.CAN_1'Access then\n return Ada.Interrupts.Names.CAN1_SCE_Interrupt;\n elsif Device = STM32.Device.CAN_2'Access then\n return Ada.Interrupts.Names.CAN2_SCE_Interrupt;\n else\n raise Constraint_Error;\n end if;\n end SCE_Interrupt_Id;\n\n function Nof_Messages (This : Message_Buffer) return Natural\n is\n begin\n if This.Idx_New >= This.Idx_Old then\n return This.Idx_New - This.Idx_Old;\n else\n return Index'Last - This.Idx_Old + 1 + This.Idx_New - Index'First;\n end if;\n end Nof_Messages;\n\n procedure Get_Next_Message\n (This : in out Message_Buffer;\n Message : out CAN_Message)\n is\n begin\n Message := This.Buffer (This.Idx_Old);\n This.Idx_Old := (This.Idx_Old + 1) mod (Index'Last + 1);\n end Get_Next_Message;\n\n procedure Put_Message\n (This : in out Message_Buffer;\n Message : in CAN_Message)\n is\n Idx_Next : constant Index := (This.Idx_New + 1) mod (Index'Last + 1);\n begin\n This.Buffer (This.Idx_New) := Message;\n This.Idx_New := Idx_Next;\n end Put_Message;\n\n protected body Controller is\n\n procedure Transmit_Message\n (Message : in CAN_Message;\n Success : out Boolean)\n is\n begin\n Success := Nof_Messages (Tx_Buffer) < Max_Nof_Messages;\n if Success then\n Put_Message (Tx_Buffer, Message);\n Send;\n end if;\n end Transmit_Message;\n\n entry Receive_Message\n (Message : out CAN_Message) when Is_Rx_Pending\n is\n begin\n Get_Next_Message (Rx_Buffer, Message);\n\n Is_Rx_Pending := (Nof_Messages (Rx_Buffer) > 0);\n end Receive_Message;\n\n procedure Enable_Receiver\n (Fifo : in Fifo_Nr)\n is\n CAN : CAN_Controller renames Device.all;\n begin\n case Fifo is\n when FIFO_0 =>\n Enable_Interrupts (CAN, FIFO_0_Message_Pending);\n when FIFO_1 =>\n Enable_Interrupts (CAN, FIFO_1_Message_Pending);\n end case;\n end Enable_Receiver;\n\n procedure Send is\n CAN : CAN_Controller renames Device.all;\n begin\n while Nof_Messages (Tx_Buffer) > 0 loop\n declare\n Message : CAN_Message;\n Empty_Found : Boolean;\n Mailbox : Mailbox_Type;\n begin\n Get_Empty_Mailbox (CAN, Mailbox, Empty_Found);\n\n exit when not Empty_Found;\n\n Get_Next_Message (Tx_Buffer, Message);\n Write_Tx_Message (CAN, Message, Mailbox);\n Enable_Interrupts (CAN, Transmit_Mailbox_Empty);\n Transmission_Request (CAN, Mailbox);" + }, + { + "function_def": "function Read_U16 is new ACO.Nodes.Remotes.Generic_Read", + "function_body": "(Entry_T => Entry_U16);\n To_Entry : constant Entry_U16 :=\n Read_U16 (Node, ACO.OD.Heartbeat_Producer_Index, 0);\n begin\n Ada.Text_IO.Put_Line\n (\"Generic function read value = \" & U16' (To_Entry.Read)'Img);" + }, + { + "function_def": "procedure InitExit is", + "function_body": "Ctx: aliased USB.LibUSB1.Context_Access;\n R: USB.LibUSB1.Status;\nbegin\n R := USB.LibUSB1.Init_Lib(Ctx'Access);\n Put(USB.LibUSB1.Status'Image(R));\n Put_Line(\"\");\n USB.LibUSB1.Exit_Lib(Ctx);" + }, + { + "function_def": "procedure List_Devices_C is", + "function_body": "Ctx: aliased Context_Access;\n R: Status;\n Ri: Integer;\n Cnt: ssize_t;\n Devs: aliased Device_Access_Lists.Pointer;\nbegin\n R := Init_Lib(Ctx'Access);\n if R /= Success then\n Put(Status'Image(R));\n Put_Line(\"\");\n return;\n end if;\n\n Cnt := Get_Device_List(Ctx, Devs'Access);\n if Cnt < 0 then\n --R := Status(Cnt);\n --Put(Status'Image(R));\n Put_Line(\"\");\n --Exit_Lib(Ctx);\n --return;\n else\n declare\n Dev_Array: Device_Access_Array :=\n Device_Access_Lists.Value(Devs, Interfaces.C.ptrdiff_t(Cnt));\n Desc: aliased USB.Protocol.Device_Descriptor;\n Path: Port_Number_Array(0..7);\n begin\n Put(Integer(Cnt));\n Put_Line(\" devices listed\");\n for I in Dev_Array'Range loop\n Put(Integer(I-Dev_Array'First), 3);\n Put(Integer(Get_Bus_Number(Dev_Array(I))), 4);\n Put(Integer(Get_Device_Address(Dev_Array(I))), 4);\n R := Get_Device_Descriptor(Dev_Array(I), Desc);\n if R /= Success then\n Put(\"Failed to get device descriptor: \" & Status'Image(R));\n else\n Put(Integer(Desc.idVendor), 10, 16);\n Put(Integer(Desc.idProduct), 10, 16);\n Ri := Integer(Get_Port_Numbers(Dev_Array(I),\n Path(0)'Unrestricted_Access, -- do not know how to do right\n Path'Length));\n if Ri > 0 then\n Put(\" path: \");\n for I in 0 .. Ri-1 loop\n Put(Integer(Path(I)), 4);\n end loop;\n end if;\n end if;\n New_Line;\n end loop;" + }, + { + "function_def": "procedure Greet2 is", + "function_body": "begin\n loop\n Put_Line (\"Please enter your name: \");\n\n declare\n\t Name : String := Get_Line;\n\t -- ^ Call to the Get_Line function\n begin\n\t exit when Name = \"\";\n\t Put_line (\"Hi \" & Name & \"!\");" + }, + { + "function_def": "procedure Check_Positive2 is", + "function_body": "N : Integer;\nbegin\n Put (\"Enter an integer value: \"); -- Put a String\n Get (N); -- Reads in an integer value\n Put (N); -- Put an Integer\n declare\n S : String :=\n (if N > 0 then \" is a positive number\"\n\telse \" is not a positive number\");\n\tbegin\n\t Put_Line (S);" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E006 := E006 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E109 := E109 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E054 := E054 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n Interfaces.C'Elab_Spec;\n E078 := E078 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E080 := E080 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E008 := E008 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E101 := E101 + 1;\n Ada.Streams'Elab_Spec;\n E099 := E099 + 1;\n System.File_Control_Block'Elab_Spec;\n E113 := E113 + 1;\n System.Finalization_Root'Elab_Spec;\n E112 := E112 + 1;\n Ada.Finalization'Elab_Spec;\n E110 := E110 + 1;\n System.File_Io'Elab_Body;\n E109 := E109 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E006 := E006 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_greet\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure Down is", + "function_body": "begin\n Indent_Level := Indent_Level + Indent_Step;\n Indent := Indent_String (Indent_Level);\n end Down;\n\n --------\n -- Up --\n --------\n\n procedure Up is\n begin\n Indent_Level := Indent_Level - Indent_Step;\n Indent := Indent_String (Indent_Level);\n end Up;\n\n --------------\n -- End_Line --\n --------------\n\n procedure End_Line is\n begin\n Put (\"\" & ASCII.LF);\n end End_Line;\n\n --------------\n -- Dump_Rec --\n --------------\n\n procedure Dump_Rec (N : Node) is\n begin\n case N.Kind is\n when Map =>\n for Ent of N.Iterate_On_Table loop\n Put (Indent);\n\n Put (Format_String (Ent.Key));\n Put (Key_Separator);\n\n if Ent.Value.Kind in Composite_Node_Kind then\n End_Line;\n Down;\n Dump_Rec (Ent.Value);\n Up;\n else\n Dump_Rec (Ent.Value);\n End_Line;\n end if;\n end loop;\n\n when Vector =>\n for Index in 1 .. N.Length loop\n declare\n Value : constant Node := N.Item (Index);\n begin\n Put (Indent);\n Put (\"- \");\n\n if Value.Kind in Composite_Node_Kind then\n End_Line;\n Down;\n Dump_Rec (Value);\n Up;\n else\n Dump_Rec (Value);\n End_Line;\n end if;" + }, + { + "function_def": "procedure Down is", + "function_body": "begin\n Indent_Level := Indent_Level + Indent_Step;\n Indent := Indent_String (Indent_Level);\n -- Put (\"#down (\" & Indent_Level'Img & \")#\");\n end Down;\n\n --------\n -- Up --\n --------\n\n procedure Up is\n begin\n Indent_Level := Indent_Level - Indent_Step;\n Indent := Indent_String (Indent_Level);\n -- Put (\"#up (\" & Indent_Level'Img & \")#\");\n end Up;\n\n --------------\n -- End_Line --\n --------------\n\n procedure End_Line is\n begin\n if Indent_Step /= 0 then\n Put (\"\" & ASCII.LF);\n end if;\n end End_Line;\n\n --------------\n -- Dump_Rec --\n --------------\n\n procedure Dump_Rec (N : Node) is\n begin\n case N.Kind is\n when Map =>\n for Ent of N.Iterate_On_Table loop\n declare\n Name : constant Unbounded_UTF8_String :=\n Element_Name (Ent.Key);\n begin\n Put (Indent);\n Put (\"<\");\n Put (Name);\n Put (\">\");\n\n if Ent.Value.Kind in Composite_Node_Kind then\n End_Line;\n Down;\n Dump_Rec (Ent.Value);\n Up;\n Put (Indent);\n else\n Dump_Rec (Ent.Value);\n end if;\n Put (\"\");\n End_Line;" + }, + { + "function_def": "procedure Sort_Keys is new Ada.Containers.Generic_Array_Sort", + "function_body": "(Index_Type => Positive,\n Element_Type => Unbounded_UTF8_String,\n Array_Type => Key_Array);\n\n package TOML_Maps is new Ada.Containers.Hashed_Maps\n (Key_Type => Unbounded_String,\n Element_Type => Node,\n Hash => Hash,\n Equivalent_Keys => \"=\");\n\n package TOML_Vectors is new Ada.Containers.Vectors (Positive, Node);\n\n type Node_Record (Kind : Any_Node_Kind) is limited record\n Ref_Count : Natural;\n\n case Kind is\n when Map =>\n Map_Value : TOML_Maps.Map;\n\n when Vector =>\n Array_Value : TOML_Vectors.Vector;\n -- List of values for all items\n\n Array_Implicitly_Created : Boolean;\n -- Same as Table_Implicitly_Created\n\n when Value =>\n String_Value : Unbounded_String;\n\n end case;\n end record;\n\n procedure Free is new Ada.Unchecked_Deallocation\n (Node_Record, Node_Record_Access);\n\n function Create_Node (Rec : Node_Record_Access) return Node;\n -- Wrap a value record in a value. This resets its ref-count to 1.\n\n -----------------\n -- Create_Node --\n -----------------\n\n function Create_Node (Rec : Node_Record_Access) return Node is\n begin\n return Result : Node do\n Rec.Ref_Count := 1;\n Result.Value := Rec;\n end return;\n end Create_Node;\n\n -------------\n -- Is_Null --\n -------------\n\n function Is_Null (This : Node) return Boolean is\n begin\n return This.Value = null;\n end Is_Null;\n\n ----------\n -- Kind --\n ----------\n\n function Kind (This : Node) return Any_Node_Kind is\n begin\n return This.Value.Kind;\n end Kind;\n\n ------------\n -- Equals --\n ------------\n\n function Equals (Left, Right : Node) return Boolean is\n begin\n -- If Left and Right refer to the same document, they are obviously\n -- equivalent (X is equivalent to X). If they don't have the same kind,\n -- they are obviously not equivalent.\n\n if Left = Right then\n return True;\n elsif Left.Kind /= Right.Kind then\n return False;\n end if;\n\n case Left.Kind is\n when Map =>\n declare\n Left_Keys : constant Key_Array := Left.Keys;\n Right_Keys : constant Key_Array := Right.Keys;\n begin\n if Left_Keys /= Right_Keys then\n return False;\n end if;\n\n for K of Left_Keys loop\n if not Equals (Left.Get (K), Right.Get (K)) then\n return False;\n end if;\n end loop;" + }, + { + "function_def": "procedure Comp_Stats_Unit_test is", + "function_body": "Values: CompStats_Statistics.Values_Array(1..20);\n Values2 : CompStats_Statistics.Values_Array(1..10);\n\n\n procedure Test_Get_Count (Values : CompStats_Statistics.Values_Array) is\n\n Result : INTEGER;\n\n begin\n Put(\"Get_Count : \");\n Result := Get_Count(Values);\n if Result = 20 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Count;\n\n\n procedure Test_Get_Minimum (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Minimum : \");\n Result := Get_Minimum(Values);\n if Result = -1.405158 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Minimum;\n\n\n procedure Test_Get_Maximum (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Maximum : \");\n Result := Get_Maximum(Values);\n if Result = 2.614303 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Maximum;\n\n\n procedure Test_Get_Range (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Range : \");\n Result := Get_Range(Values);\n if Result = 4.019462 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Range;\n\n\n procedure Test_Get_Sum (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Sum : \");\n Result := Get_Sum(Values);\n if Result = 4.070304 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Sum;\n\n\n procedure Test_Get_Mean (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Mean : \");\n Result := Get_Mean (Values);\n if Result = 0.2035152 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Mean;\n\n\n procedure Test_Get_Sum_Of_Squares (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Sum_Of_Squares : \");\n Result := Get_Sum_Of_Squares (Values);\n if Result = 24.19856 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Sum_Of_Squares;\n\n\n procedure Test_Get_Population_Variance (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Population_Variance : \");\n Result := Get_Population_Variance (Values);\n if Result = 1.209928 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Population_Variance;\n\n \n procedure Test_Get_Sample_Variance (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Sample_Variance : \");\n Result := Get_Sample_Variance (Values);\n if Result = 1.273608 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Sample_Variance;\n\n\n procedure Test_Get_Population_Standard_Deviation (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Population_Standard_Deviation : \");\n Result := Get_Population_Standard_Deviation (Values);\n if Result = 1.099967 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Population_Standard_Deviation;\n\n\n procedure Test_Get_Sample_Standard_Deviation (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Sample_Standard_Deviation : \");\n Result := Get_Sample_Standard_Deviation (Values);\n if Result = 1.128543 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Sample_Standard_Deviation;\n\n\n procedure Test_Get_Standard_Error_of_Mean (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Standard_Error_of_Mean : \");\n Result := Get_Standard_Error_of_Mean (Values);\n if Result = 0.2523498 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Standard_Error_of_Mean;\n\n\n procedure Test_Get_Coefficient_Of_Variation (Values : CompStats_Statistics.Values_Array) is\n\n Result : FLOAT;\n\n begin\n Put(\"Get_Coefficient_Of_Variation : \");\n Result := Get_Coefficient_Of_Variation (Values);\n if Result = 5.54525 then\n Put(\"True\");\n else \n Put(\" False - \");\n Put(Result);\n end if;\n New_Line;\n end Test_Get_Coefficient_Of_Variation;\n\n\n procedure Test_Get_Unique_Values (Values : CompStats_Statistics.Values_Array) is\n\n begin\n Put(\"Get_Unique_Values : \");\n declare \n Result : CompStats_Statistics.Values_Array := Get_Unique_Values (Values);\n begin\n for index in Integer range 1..Result'Length loop\n put(Result(index));\n put(\", \");\n end loop;\n New_Line;" + }, + { + "function_def": "procedure Execute is", + "function_body": "begin\n Sub_Cmd.Parse_Global_Switches;\n CLIC.TTY.Enable_Color (Force => False);\n\n begin\n\n Sub_Cmd.Execute;\n exception\n when Child_Failed | Command_Failed | Wrong_Command_Arguments =>\n GNAT.OS_Lib.OS_Exit (1);\n when CLIC.User_Input.User_Interrupt =>\n GNAT.OS_Lib.OS_Exit (1);" + }, + { + "function_def": "function Only_Objects is new Classes.Generic_Filter (Only_Object);", + "function_body": "function Is_Not_A_Token (P : Classes.Property) return Boolean is\n (not Is_Token (P.Type_Name));\n\n function Skip_Tokens is new Classes.Generic_Filter (Is_Not_A_Token);\n\n function Is_A_Token (P : Classes.Property) return Boolean is\n (Is_Token (P.Type_Name));\n\n function Is_Not_A_Text (P : Classes.Property) return Boolean is\n (not Is_Text (P.Type_Name));\n\n function Skip_Texts is new Classes.Generic_Filter (Is_Not_A_Text);\n\n function Only_Tokens is new Classes.Generic_Filter (Is_A_Token);\n\n function Is_A_Text (P : Classes.Property) return Boolean is\n (Is_Text (P.Type_Name));\n\n function Only_Texts is new Classes.Generic_Filter (Is_A_Text);\n\n function Is_A_Boolean (P : Classes.Property) return Boolean is\n (Is_Boolean (P.Type_Name));\n\n function Only_Booleans is new Classes.Generic_Filter (Is_A_Boolean);\n\n function Is_Not_A_Boolean (P : Classes.Property) return Boolean is\n (not Is_Boolean (P.Type_Name));\n\n function Skip_Booleans is new Classes.Generic_Filter (Is_Not_A_Boolean);\n\n function Visit_Spec\n (F : aliased in out Ada_Pretty.Factory;\n Name : Ada_Pretty.Node_Access;\n Is_Abstract : Boolean := True)\n return Ada_Pretty.Node_Access;\n\n generic\n type T is limited private;\n type T_Array is array (Positive range <>) of T;\n\n with function Convert\n (F : aliased in out Ada_Pretty.Factory;\n Item : T) return Ada_Pretty.Node_Access;\n F : in out Ada_Pretty.Factory;\n function Generic_List_Reduce (List : T_Array) return Ada_Pretty.Node_Access;\n\n -----------------\n -- All_Parents --\n -----------------\n\n function All_Parents\n (Item : Classes.Class;\n Vector : Meta.Read.Class_Vectors.Vector) return String_Array\n is\n procedure Collect\n (Result : in out League.String_Vectors.Universal_String_Vector;\n Item : Meta.Classes.Class);\n\n procedure Collect\n (Result : in out League.String_Vectors.Universal_String_Vector;\n Item : Meta.Classes.Class) is\n begin\n if Is_Element (Item.Name) then\n return;\n end if;\n\n if Result.Index (Item.Name) = 0 then\n Result.Append (Item.Name);\n\n for J in 1 .. Item.Parents.Length loop\n declare\n Parent : constant League.Strings.Universal_String :=\n Item.Parents.Element (J);\n begin\n for Next of Vector loop\n if Next.Name = Parent then\n Collect (Result, Next);\n exit;\n end if;\n end loop;" + }, + { + "function_def": "function Generic_List_Reduce", + "function_body": "(List : T_Array) return Ada_Pretty.Node_Access\n is\n Result : Ada_Pretty.Node_Access;\n begin\n for Item of List loop\n Result := F.New_List (Result, Convert (F, Item));\n end loop;\n\n return Result;\n end Generic_List_Reduce;\n\n Map : constant array (Boolean) of Ada_Pretty.Trilean :=\n (False => Ada_Pretty.False, True => Ada_Pretty.True);\n\n ----------------------\n -- Full_Record_Name --\n ----------------------\n\n function Full_Record_Name\n (Type_Name : League.Strings.Universal_String)\n return League.Strings.Universal_String\n is\n Result : League.Strings.Universal_String := Get_Package_Name (Type_Name);\n begin\n if not Result.Is_Empty then\n Result.Append (\".\");\n end if;\n\n Result.Append (To_Element_Name (Type_Name));\n return Result;\n end Full_Record_Name;\n\n ----------------------\n -- Full_Vector_Name --\n ----------------------\n\n function Full_Vector_Name\n (Type_Name : League.Strings.Universal_String)\n return League.Strings.Universal_String\n is\n Result : League.Strings.Universal_String;\n begin\n if Is_Element (Type_Name) then\n Result := Full_Record_Name (Element_Vector);\n else\n Result := Get_Package_Name (Type_Name);\n Result.Append (\".\");\n Result.Append (To_Element_Name (Type_Name));\n Result.Append (\"_Vector\");\n end if;\n\n return Result;\n end Full_Vector_Name;\n\n ----------------------\n -- Full_Access_Name --\n ----------------------\n\n function Full_Access_Name\n (Type_Name : League.Strings.Universal_String)\n return League.Strings.Universal_String\n is\n Result : League.Strings.Universal_String := Get_Package_Name (Type_Name);\n begin\n Result.Append (\".\");\n Result.Append (Type_Name);\n Result.Append (\"_Access\");\n return Result;\n end Full_Access_Name;\n\n ----------------------\n -- Get_Parent_Props --\n ----------------------\n\n function Get_Parent_Props\n (Item : Classes.Class;\n Vector : Meta.Read.Class_Vectors.Vector)\n return Classes.Property_Array\n is\n Parent : constant League.Strings.Universal_String :=\n Item.Parents.Element (1);\n begin\n if Is_Element (Parent) then\n return (1 .. 0 => <>);\n end if;\n\n for Next of Vector loop\n if Next.Name = Parent then\n return Next.Properties;\n end if;\n end loop;\n\n raise Program_Error;\n end Get_Parent_Props;\n\n -------------------\n -- Prop_Argument --\n -------------------\n\n function Prop_Argument\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access\n is\n Name : constant Ada_Pretty.Node_Access := F.New_Name (Prop.Name);\n begin\n return F.New_Component_Association\n (Choices => Name,\n Value => Name);\n end Prop_Argument;\n\n --------------------\n -- Prop_Parameter --\n --------------------\n\n function Prop_Parameter\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access is\n begin\n if Is_Boolean (Prop.Type_Name) then\n return F.New_Parameter\n (Name => F.New_Name (Prop.Name),\n Type_Definition => Property_Type (F, Prop),\n Initialization => F.New_Name (+\"False\"));\n else\n return F.New_Parameter\n (Name => F.New_Name (Prop.Name),\n Type_Definition => Property_Type (F, Prop));\n end if;\n end Prop_Parameter;\n\n function Prop_Check_Spec\n (F : aliased in out Ada_Pretty.Factory;\n Name : League.Strings.Universal_String;\n Base_Name : Ada_Pretty.Node_Access) return Ada_Pretty.Node_Access is\n begin\n return F.New_Subprogram_Specification\n (Is_Overriding => Ada_Pretty.True,\n Name => F.New_Name (\"Is_\" & Name & \"_Element\"),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => Base_Name),\n Result => F.New_Name (+\"Boolean\"));\n end Prop_Check_Spec;\n\n\n -------------------\n -- Property_Type --\n -------------------\n\n function Property_Type\n (F : aliased in out Ada_Pretty.Factory;\n P : Meta.Classes.Property) return Ada_Pretty.Node_Access\n is\n use all type Meta.Classes.Capacity_Kind;\n\n R_Type : Ada_Pretty.Node_Access;\n begin\n if Is_Boolean (P.Type_Name) or Is_Text (P.Type_Name) then\n R_Type := F.New_Name (P.Type_Name);\n\n elsif Is_Token (P.Type_Name) then\n R_Type := F.New_Selected_Name (Full_Access_Name (Lexical_Element));\n\n elsif P.Capacity in Just_One | Zero_Or_One then\n R_Type := F.New_Selected_Name (Full_Access_Name (P.Type_Name));\n\n elsif Is_Element (P.Type_Name) then\n R_Type := F.New_Selected_Name\n (+\"Program.Element_Vectors.Element_Vector_Access\");\n\n else\n R_Type := F.New_Selected_Name\n (Full_Vector_Name (P.Type_Name) & \"_Access\");\n\n end if;\n\n if P.Capacity in Just_One | One_Or_More\n and then not Is_Boolean (P.Type_Name)\n and then not Is_Text (P.Type_Name)\n then\n R_Type := F.New_Null_Exclusion (R_Type);\n end if;\n\n return R_Type;\n end Property_Type;\n\n ---------------\n -- Get_Props --\n ---------------\n\n function Get_Props\n (F : aliased in out Ada_Pretty.Factory;\n Name : Ada_Pretty.Node_Access;\n Props : Meta.Classes.Property_Array;\n Prefix : Ada_Pretty.Node_Access;\n Is_Abstr : Boolean := True) return Ada_Pretty.Node_Access\n is\n Next : Ada_Pretty.Node_Access;\n Result : Ada_Pretty.Node_Access := Prefix;\n begin\n for P of Props loop\n Next := F.New_Subprogram_Declaration\n (Specification => F.New_Subprogram_Specification\n (Is_Overriding => Map (not Is_Abstr),\n Name => F.New_Name (P.Name),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => Name),\n Result => Property_Type (F, P)),\n Is_Abstract => Is_Abstr);\n\n Result := F.New_List (Result, Next);\n end loop;\n\n return Result;\n end Get_Props;\n\n ----------------------\n -- Get_With_Clauses --\n ----------------------\n\n function Get_With_Clauses\n (F : access Ada_Pretty.Factory;\n Vector : Meta.Read.Class_Vectors.Vector;\n Is_Limited : Boolean;\n With_Abstract : Boolean := True;\n Skip : Natural := 1) return Ada_Pretty.Node_Access\n is\n Result : Ada_Pretty.Node_Access;\n begin\n for J in 1 + Skip .. Vector.Last_Index loop\n declare\n Item : constant Meta.Classes.Class := Vector (J);\n Name : constant League.Strings.Universal_String := Item.Name;\n Package_Name : constant League.Strings.Universal_String :=\n Get_Package_Name (Name);\n Next : constant Ada_Pretty.Node_Access :=\n F.New_With (F.New_Name (Package_Name), Is_Limited);\n begin\n if With_Abstract or else not Item.Is_Abstract then\n Result := F.New_List (Result, Next);\n end if;" + }, + { + "function_def": "function Visit_Spec", + "function_body": "(F : aliased in out Ada_Pretty.Factory;\n Name : Ada_Pretty.Node_Access;\n Is_Abstract : Boolean := True)\n return Ada_Pretty.Node_Access\n is\n Visit : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Specification\n (Is_Overriding => Map (not Is_Abstract),\n Name => F.New_Name (+\"Visit\"),\n Parameters => F.New_List\n (F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => F.New_Null_Exclusion\n (F.New_Access\n (Target => Name))),\n F.New_Parameter\n (Name => F.New_Name (+\"Visitor\"),\n Type_Definition => F.New_Selected_Name\n (Full_Record_Name (Element_Visitor) & \"'Class\"),\n Is_In => True,\n Is_Out => True)));\n begin\n return Visit;\n end Visit_Spec;\n\n --------------------\n -- Write_Elements --\n --------------------\n\n procedure Write_Elements (Vector : Meta.Read.Class_Vectors.Vector) is\n\n F : aliased Ada_Pretty.Factory;\n\n function Element_Classifications return Ada_Pretty.Node_Access;\n\n function Element_Casts return Ada_Pretty.Node_Access;\n\n -------------------\n -- Element_Casts --\n -------------------\n\n function Element_Casts return Ada_Pretty.Node_Access is\n Result : Ada_Pretty.Node_Access;\n begin\n for J in 2 .. Vector.Last_Index loop\n declare\n Item : constant Meta.Classes.Class := Vector (J);\n\n Name : constant League.Strings.Universal_String :=\n \"To_\" & Item.Name;\n\n Type_Name : constant Ada_Pretty.Node_Access :=\n F.New_Selected_Name (Full_Access_Name (Item.Name));\n\n Funct : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (F.New_Subprogram_Specification\n (Name => F.New_Name (Name),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => F.New_Access\n (Target => F.New_Name (+\"Element'Class\"))),\n Result => Type_Name),\n Aspects => F.New_Aspect\n (Name => F.New_Name (+\"Pre\"),\n Value => F.New_Name (\"Self.Is_\" & Item.Name)));\n begin\n Result := F.New_List (Result, Funct);" + }, + { + "function_def": "function Prop_Parameters is new Generic_List_Reduce", + "function_body": "(Classes.Property, Classes.Property_Array, Prop_Parameter, F);\n\n function Get_Params\n (Item : Classes.Class) return Ada_Pretty.Node_Access;\n\n function Prop_List (Item : Classes.Class) return Classes.Property_Array;\n\n ----------------\n -- Get_Params --\n ----------------\n\n function Get_Params\n (Item : Classes.Class) return Ada_Pretty.Node_Access\n is\n List : constant Ada_Pretty.Node_Access :=\n Prop_Parameters (Prop_List (Item));\n Self : constant Ada_Pretty.Node_Access := F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => Type_Name);\n begin\n if List in null then\n return Self;\n else\n return F.New_List (Self, List);\n end if;\n end Get_Params;\n\n -------------\n -- Methods --\n -------------\n\n function Methods return Ada_Pretty.Node_Access is\n Result : Ada_Pretty.Node_Access;\n begin\n for Item of Vector loop\n if not Item.Is_Abstract then\n declare\n Funct : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (F.New_Subprogram_Specification\n (Is_Overriding => Ada_Pretty.False,\n Name => F.New_Name (\"Create_\" & Item.Name),\n Parameters => Get_Params (Item),\n Result => F.New_Null_Exclusion\n (F.New_Selected_Name\n (Full_Access_Name (Item.Name)))));\n begin\n Result := F.New_List (Result, Funct);" + }, + { + "function_def": "function Prop_List", + "function_body": "(Item : Classes.Class) return Classes.Property_Array\n is\n use type Classes.Property_Array;\n\n Parent_Props : constant Classes.Property_Array :=\n Get_Parent_Props (Item, Vector);\n\n begin\n if Implicit then\n return Skip_Texts (Skip_Tokens (Item.Properties))\n & Only_Booleans\n (Vector.First_Element.Properties & Parent_Props);\n else\n return Skip_Texts (Skip_Booleans (Item.Properties))\n & Only_Booleans (Parent_Props);\n end if;\n end Prop_List;\n\n Pure : constant Ada_Pretty.Node_Access :=\n F.New_Pragma (F.New_Name (+\"Preelaborate\"));\n\n Public_Part : constant Ada_Pretty.Node_Access :=\n F.New_List ((Pure, Type_Decl, Methods));\n\n Full_Type_Decl : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Type_Name,\n Discriminants => F.New_Parameter\n (Name => Subpool,\n Type_Definition => F.New_Null_Exclusion\n (F.New_Selected_Name\n (+\"System.Storage_Pools.Subpools.Subpool_Handle\"))),\n Definition => F.New_Record\n (Is_Limited => True, Is_Tagged => True));\n\n Root : constant Ada_Pretty.Node_Access :=\n F.New_Package\n (F.New_Selected_Name (Package_Name), Public_Part, Full_Type_Decl);\n\n With_Clauses : constant Ada_Pretty.Node_Access_Array :=\n (F.New_With (F.New_Selected_Name (+\"System.Storage_Pools.Subpools\")),\n Get_With_Clauses\n (F'Access, Vector, Is_Limited => False),\n F.New_With\n (F.New_Selected_Name (Get_Package_Name (Lexical_Element))),\n F.New_With\n (F.New_Selected_Name (Get_Package_Name (Element_Vector))));\n\n Unit : constant Ada_Pretty.Node_Access :=\n F.New_Compilation_Unit\n (Root,\n F.New_List (With_Clauses));\n\n Output : Ada.Wide_Wide_Text_IO.File_Type;\n begin\n Open_File (Output, Package_Name, \"nodes/\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output,\n F.To_Text (Unit).Join (Ada.Characters.Wide_Wide_Latin_1.LF)\n .To_Wide_Wide_String);\n\n Ada.Wide_Wide_Text_IO.Close (Output);\n end Write_Factories;\n\n --------------------------\n -- Write_Factories_Body --\n --------------------------\n\n procedure Write_Factories_Body\n (Vector : Meta.Read.Class_Vectors.Vector;\n Implicit : Boolean := False)\n is\n function Methods return Ada_Pretty.Node_Access;\n\n Package_Name : constant League.Strings.Universal_String :=\n (if Implicit then +\"Program.Implicit_Element_Factories\"\n else +\"Program.Element_Factories\");\n\n F : aliased Ada_Pretty.Factory;\n\n Type_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (+\"Element_Factory\");\n\n function Prop_Parameters is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Parameter, F);\n\n function Prop_Arguments is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Argument, F);\n\n function Get_Params\n (Item : Classes.Class) return Ada_Pretty.Node_Access;\n\n function Allocator_Args\n (Item : Classes.Class) return Ada_Pretty.Node_Access;\n\n function Get_With_Clauses return Ada_Pretty.Node_Access;\n function Access_Types return Ada_Pretty.Node_Access;\n\n function Prop_List\n (Item : Classes.Class) return Classes.Property_Array;\n\n ------------------\n -- Access_Types --\n ------------------\n\n function Access_Types return Ada_Pretty.Node_Access is\n Result : Ada_Pretty.Node_Access;\n begin\n for Item of Vector loop\n if not Item.Is_Abstract then\n declare\n Element_Name : constant League.Strings.Universal_String :=\n (if Implicit then \"Implicit_\" & Item.Name\n else To_Element_Name (Item.Name));\n Def : constant Ada_Pretty.Node_Access := F.New_Access\n (Target => F.New_Selected_Name\n (F.New_Selected_Name (Node_Package_Name (Item.Name)),\n F.New_Name (Element_Name)));\n begin\n Result := F.New_List\n (Result,\n F.New_Type\n (F.New_Name (Item.Name & \"_Access\"),\n Definition => F.New_Null_Exclusion (Def),\n Aspects => F.New_Aspect\n (F.New_Name (+\"Storage_Pool\"),\n F.New_Selected_Name\n (+\"Program.Storage_Pools.Pool\"))));" + }, + { + "function_def": "function Prop_List", + "function_body": "(Item : Classes.Class) return Classes.Property_Array\n is\n use type Classes.Property_Array;\n\n Parent_Props : constant Classes.Property_Array :=\n Get_Parent_Props (Item, Vector);\n\n begin\n if Implicit then\n return Skip_Texts (Skip_Tokens (Item.Properties))\n & Only_Booleans\n (Vector.First_Element.Properties & Parent_Props);\n else\n return Skip_Texts (Skip_Booleans (Item.Properties))\n & Only_Booleans (Parent_Props);\n end if;\n end Prop_List;\n\n Root : constant Ada_Pretty.Node_Access :=\n F.New_Package_Body\n (F.New_Selected_Name (Package_Name),\n F.New_List (Access_Types, Methods));\n\n Unit : constant Ada_Pretty.Node_Access :=\n F.New_Compilation_Unit\n (Root,\n Get_With_Clauses);\n\n Output : Ada.Wide_Wide_Text_IO.File_Type;\n begin\n Open_File (Output, Package_Name, \"nodes/\", Spec => False);\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output,\n F.To_Text (Unit).Join (Ada.Characters.Wide_Wide_Latin_1.LF)\n .To_Wide_Wide_String);\n\n Ada.Wide_Wide_Text_IO.Close (Output);\n end Write_Factories_Body;\n\n ------------------\n -- Write_Header --\n ------------------\n\n procedure Write_Header (Output : Ada.Wide_Wide_Text_IO.File_Type) is\n begin\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output, \"-- Copyright (c) 2019 Maxim Reznik \");\n\n Ada.Wide_Wide_Text_IO.Put_Line (Output, \"--\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output, \"-- SPDX-License-Identifier: MIT\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output, \"-- License-Filename: LICENSE\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output,\n \"-------------------------------------------------------------\");\n Ada.Wide_Wide_Text_IO.New_Line (Output);\n end Write_Header;\n\n ---------------------\n -- Write_Iterators --\n ---------------------\n\n procedure Write_Iterators (Vector : Meta.Read.Class_Vectors.Vector) is\n Package_Name : constant League.Strings.Universal_String :=\n +\"Internal\";\n\n F : aliased Ada_Pretty.Factory;\n\n Visitor : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => F.New_Name (+\"Visitor\"),\n Definition => F.New_Record\n (Parent => F.New_Selected_Name\n (Full_Record_Name (Element_Visitor)),\n Components => F.New_Variable\n (Name => F.New_Name (+\"Result\"),\n Type_Definition => F.New_Access\n (Modifier => Access_Constant,\n Target => F.New_Name (+\"Getter_Array\")),\n Initialization => F.New_Name (+\"Empty'Access\"))));\n\n function Method_Bodies return Ada_Pretty.Node_Access;\n\n function Method_Spec\n (Item : Classes.Class) return Ada_Pretty.Node_Access;\n\n function Child_Args\n (Item : Classes.Class;\n P : Classes.Property) return Ada_Pretty.Node_Access;\n\n function Vector_Args\n (Item : Classes.Class;\n P : Classes.Property) return Ada_Pretty.Node_Access;\n\n function Get_Inst\n (Item : Classes.Class;\n P : Classes.Property;\n Index : Positive) return Ada_Pretty.Node_Access;\n\n function Is_Vector (P : Classes.Property) return Boolean is\n (P.Capacity in Classes.Zero_Or_More | Classes.One_Or_More);\n\n function Get_Name (Index : Natural) return Wide_Wide_String;\n\n Count : Positive := 1;\n\n function Get_Name (Index : Natural) return Wide_Wide_String is\n Count_Image : constant Wide_Wide_String :=\n Integer'Wide_Wide_Image (Count);\n Index_Image : constant Wide_Wide_String :=\n Integer'Wide_Wide_Image (Index);\n\n Name : constant Wide_Wide_String :=\n \"F\" & Count_Image (2 .. Count_Image'Last);\n\n begin\n if Index = 0 then\n return Name;\n else\n return Name & \"_\" & Index_Image (2 .. Index_Image'Last);\n end if;\n end Get_Name;\n\n ----------------\n -- Child_Args --\n ----------------\n\n function Child_Args\n (Item : Classes.Class;\n P : Classes.Property) return Ada_Pretty.Node_Access\n is\n Args : constant Ada_Pretty.Node_Access_Array :=\n (F.New_Argument_Association\n (Choice => F.New_Name (+\"Element\"),\n Value => F.New_Selected_Name\n (Full_Record_Name (Item.Name))\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Child\"),\n Value => F.New_Selected_Name\n (Full_Record_Name (P.Type_Name))\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Child_Access\"),\n Value => F.New_Selected_Name (Full_Access_Name (P.Type_Name))\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Get_Child\"),\n Value => F.New_Selected_Name\n (Get_Package_Name (Item.Name) & \".\" & P.Name)\n )\n );\n begin\n return F.New_List (Args);\n end Child_Args;\n\n -----------------\n -- Vector_Args --\n -----------------\n\n function Vector_Args\n (Item : Classes.Class;\n P : Classes.Property) return Ada_Pretty.Node_Access\n is\n Args : constant Ada_Pretty.Node_Access_Array :=\n (F.New_Argument_Association\n (Choice => F.New_Name (+\"Parent\"),\n Value => F.New_Selected_Name\n (Full_Record_Name (Item.Name))\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Vector\"),\n Value => F.New_Selected_Name\n (Full_Vector_Name (P.Type_Name))\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Vector_Access\"),\n Value => F.New_Selected_Name\n (Full_Vector_Name (P.Type_Name) & \"_Access\")\n ),\n F.New_Argument_Association\n (Choice => F.New_Name (+\"Get_Vector\"),\n Value => F.New_Selected_Name\n (Get_Package_Name (Item.Name) & \".\" & P.Name)\n )\n );\n begin\n return F.New_List (Args);\n end Vector_Args;\n\n --------------\n -- Get_Inst --\n --------------\n\n function Get_Inst\n (Item : Classes.Class;\n P : Classes.Property;\n Index : Positive) return Ada_Pretty.Node_Access\n is\n Template : constant Wide_Wide_String :=\n (if Is_Vector (P)\n then \"Vector\"\n else \"Child\");\n\n Result : constant Ada_Pretty.Node_Access :=\n (F.New_Apply\n (Prefix => F.New_Name\n (+\"function \" & Get_Name (Index) &\n \" is new Generic_\" & Template),\n Arguments =>\n (if Is_Vector (P) then Vector_Args (Item, P)\n else Child_Args (Item, P))));\n begin\n return Result;\n end Get_Inst;\n\n -----------------\n -- Method_Spec --\n -----------------\n\n function Method_Spec\n (Item : Classes.Class) return Ada_Pretty.Node_Access\n is\n Element_Name : constant League.Strings.Universal_String :=\n To_Element_Name (Item.Name);\n\n Funct : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Specification\n (Is_Overriding => Ada_Pretty.True,\n Name => F.New_Name (Element_Name),\n Parameters => F.New_List\n (F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Is_In => True,\n Is_Out => True,\n Type_Definition => F.New_Name (+\"Visitor\")),\n F.New_Parameter\n (Name => F.New_Name (Element),\n Type_Definition => F.New_Null_Exclusion\n (F.New_Selected_Name\n (Full_Access_Name (Item.Name))))));\n begin\n return Funct;\n end Method_Spec;\n\n -------------------\n -- Method_Bodies --\n -------------------\n\n function Method_Bodies return Ada_Pretty.Node_Access is\n Result : Ada_Pretty.Node_Access;\n Bodies : Ada_Pretty.Node_Access;\n Map : constant array (Boolean) of Ada_Pretty.Node_Access :=\n (False => F.New_Name (+\"False\"),\n True => F.New_Name (+\"True\"));\n begin\n for Item of Vector loop\n if not Item.Is_Abstract then\n declare\n Props : constant Meta.Classes.Property_Array :=\n Only_Objects (Item.Properties);\n\n Funct : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => Method_Spec (Item),\n Declarations => F.New_Pragma\n (Name => F.New_Name (+\"Unreferenced\"),\n Arguments => F.New_Name (+\"Element\")),\n Statements => F.New_Assignment\n (Left => F.New_Selected_Name (+\"Self.Result\"),\n Right => F.New_Name (+Get_Name (0) & \"'Access\")));\n\n Index : Positive := 1;\n\n List : Ada_Pretty.Node_Access;\n begin\n for P of Props loop\n declare\n Inst : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Get_Inst (Item, P, Index));\n Data : constant Ada_Pretty.Node_Access_Array :=\n (Map (Is_Vector (P)),\n F.New_Name (P.Name),\n F.New_Name (+Get_Name (Index) & \"'Access\"));\n begin\n Bodies := F.New_List (Bodies, Inst);\n\n List := F.New_List\n (List, F.New_Component_Association\n (Choices => F.New_Literal (Index),\n Value => F.New_Parentheses\n (F.New_List (Data))\n ));\n\n Index := Index + 1;" + }, + { + "function_def": "function Prop_Parameters is new Generic_List_Reduce", + "function_body": "(Classes.Property, Classes.Property_Array, Prop_Parameter, F);\n\n function Prop_Check\n (F : aliased in out Ada_Pretty.Factory;\n Name : League.Strings.Universal_String) return Ada_Pretty.Node_Access;\n\n function Prop_Checks is new Generic_List_Reduce\n (League.Strings.Universal_String, String_Array, Prop_Check, F);\n\n -------------------\n -- Prop_Variable --\n -------------------\n\n function Prop_Variable\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access\n is\n begin\n return F.New_Variable\n (Name => F.New_Name (Prop.Name),\n Type_Definition => Property_Type (F, Prop));\n end Prop_Variable;\n\n function Prop_Variables is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Variable, F);\n\n Text_Name : constant League.Strings.Universal_String :=\n Get_Package_Name (Item.Name) & \".\" & Item.Name & \"_Text\";\n\n Elem : constant Classes.Class := Vector.First_Element;\n\n Bool_Props : constant Classes.Property_Array :=\n Only_Booleans (Elem.Properties & Item.Properties);\n\n Parent_Props : constant Classes.Property_Array :=\n Get_Parent_Props (Item, Vector);\n\n Bool_Vars : constant Ada_Pretty.Node_Access :=\n Prop_Variables (Bool_Props);\n\n Package_Name : constant League.Strings.Universal_String :=\n Node_Package_Name (Item.Name);\n\n Element_Package_Name : constant League.Strings.Universal_String :=\n Get_Package_Name (Item.Name);\n\n Pure : constant Ada_Pretty.Node_Access :=\n F.New_Pragma (F.New_Name (+\"Preelaborate\"));\n\n Base_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (\"Base_\" & Item.Name);\n\n ----------------\n -- Prop_Check --\n ----------------\n\n function Prop_Check\n (F : aliased in out Ada_Pretty.Factory;\n Name : League.Strings.Universal_String) return Ada_Pretty.Node_Access\n is\n begin\n return F.New_Subprogram_Declaration\n (Specification => Prop_Check_Spec (F, Name, Base_Name));\n end Prop_Check;\n\n Base_Props : constant Ada_Pretty.Node_Access := Prop_Variables\n (Only_Objects (Item.Properties) & Only_Booleans (Parent_Props));\n\n Base : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => Base_Name,\n Definition => F.New_Record\n (Parent => F.New_List\n (F.New_Selected_Name (+\"Program.Nodes.Node\"),\n F.New_Infix\n (Operator => +\"and\",\n Left => F.New_Selected_Name\n (Full_Record_Name (Item.Name)))),\n Components => Base_Props,\n Is_Abstract => True));\n\n Base_Init : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Initialize\"),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => F.New_Name\n (\"Base_\" & Item.Name & \"'Class\"),\n Is_Aliased => True,\n Is_In => True,\n Is_Out => True)));\n\n Visit : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Visit_Spec (F, Base_Name, False));\n\n Base_List : constant Ada_Pretty.Node_Access := F.New_List\n (Get_Props\n (F,\n Base_Name,\n Only_Objects (Item.Properties) & Only_Booleans (Parent_Props),\n F.New_List ((Base, Base_Init, Visit)),\n Is_Abstr => False),\n Prop_Checks (All_Parents (Item, Vector)));\n\n Node_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (To_Element_Name (Item.Name));\n\n Node_Props : constant Ada_Pretty.Node_Access :=\n Prop_Variables (Only_Tokens (Item.Properties));\n\n Node : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => Node_Name,\n Definition => F.New_Record\n (Parent => F.New_List\n (Base_Name,\n F.New_Infix (+\"and\",\n F.New_Selected_Name (Text_Name))),\n Components => Node_Props));\n\n Public_Node : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => Node_Name,\n Definition => F.New_Private_Record\n (Parents => F.New_List\n ((F.New_Selected_Name (+\"Program.Nodes.Node\"),\n F.New_Infix\n (+\"and\",\n F.New_Selected_Name (Full_Record_Name (Item.Name))),\n F.New_Infix (+\"and\",\n F.New_Selected_Name (Text_Name))))));\n\n Create_Node : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Create\"),\n Parameters => Prop_Parameters\n (Skip_Texts (Skip_Booleans (Item.Properties & Parent_Props))\n & Only_Booleans (Parent_Props)),\n Result => Node_Name));\n\n Node_To_Text : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Specification => To_Text_Spec (F, Item, Node_Name));\n\n Node_List : constant Ada_Pretty.Node_Access :=\n Get_Props\n (F,\n Name => Node_Name,\n Props => Only_Tokens (Item.Properties)\n & Only_Booleans (Item.Properties)\n & Only_Texts (Item.Properties & Parent_Props),\n Prefix => F.New_List (Node, Node_To_Text),\n Is_Abstr => False);\n\n Implicit_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (\"Implicit_\" & Item.Name);\n\n Implicit_Getters : constant Ada_Pretty.Node_Access :=\n Get_Props\n (F,\n Name => Implicit_Name,\n Props => Bool_Props\n & Only_Texts (Item.Properties & Parent_Props),\n Prefix => null,\n Is_Abstr => False);\n\n Implicit : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => Implicit_Name,\n Definition => F.New_Record\n (Parent => Base_Name,\n Components => Bool_Vars));\n\n Implicit_To_Text : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Specification => To_Text_Spec (F, Item, Implicit_Name));\n\n Implicit_List : constant Ada_Pretty.Node_Access :=\n F.New_List ((Implicit, Implicit_To_Text, Implicit_Getters));\n\n Public_Implicit : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Name => Implicit_Name,\n Definition => F.New_Private_Record\n (Parents => F.New_List\n (F.New_Selected_Name (+\"Program.Nodes.Node\"),\n F.New_Infix\n (+\"and\",\n F.New_Selected_Name (Full_Record_Name (Item.Name))))));\n\n Aspec_List : constant Ada_Pretty.Node_Access_Array :=\n (F.New_Name (+\"Is_Part_Of_Implicit\"),\n F.New_Infix (+\"or\", F.New_Name (+\"Is_Part_Of_Inherited\")),\n F.New_Infix (+\"or\", F.New_Name (+\"Is_Part_Of_Instance\")));\n\n Create_Implicit : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Create\"),\n Parameters => Prop_Parameters\n (Only_Objects (Item.Properties & Parent_Props) &\n Bool_Props & Only_Booleans (Parent_Props)),\n Result => Implicit_Name),\n Aspects => F.New_Aspect\n (Name => F.New_Name (+\"Pre\"),\n Value => F.New_List (Aspec_List)));\n\n Public_Part : constant Ada_Pretty.Node_Access := F.New_List\n ((Pure, Public_Node, Create_Node, Public_Implicit, Create_Implicit));\n\n Private_Part : constant Ada_Pretty.Node_Access :=\n F.New_List ((Base_List, Node_List, Implicit_List));\n\n Root : constant Ada_Pretty.Node_Access :=\n F.New_Package\n (F.New_Selected_Name (Package_Name), Public_Part, Private_Part);\n\n With_Clauses_1 : constant Ada_Pretty.Node_Access :=\n Get_With_Clauses\n (F'Access, Item,\n With_List => False,\n With_Parent => False);\n\n With_Clauses_2 : constant not null Ada_Pretty.Node_Access :=\n F.New_With (F.New_Selected_Name (Element_Package_Name));\n\n With_Clauses_3 : constant not null Ada_Pretty.Node_Access :=\n F.New_With (F.New_Selected_Name (Get_Package_Name (Element_Visitor)));\n\n With_Clauses : constant Ada_Pretty.Node_Access :=\n F.New_List\n (F.New_List (With_Clauses_1, With_Clauses_2), With_Clauses_3);\n\n Unit : constant Ada_Pretty.Node_Access :=\n F.New_Compilation_Unit (Root, With_Clauses);\n\n Output : Ada.Wide_Wide_Text_IO.File_Type;\n begin\n Open_File (Output, Package_Name, \"nodes/\");\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output,\n F.To_Text (Unit).Join (Ada.Characters.Wide_Wide_Latin_1.LF)\n .To_Wide_Wide_String);\n\n Ada.Wide_Wide_Text_IO.Close (Output);\n end Write_One_Node;\n\n -------------------------\n -- Write_One_Node_Body --\n -------------------------\n\n procedure Write_One_Node_Body\n (Vector : Meta.Read.Class_Vectors.Vector;\n Item : Meta.Classes.Class)\n is\n\n use type Classes.Property_Array;\n\n F : aliased Ada_Pretty.Factory;\n\n function Prop_Parameters is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Parameter, F);\n\n function Prop_Arguments is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Argument, F);\n\n function Prop_Set_Enclosing\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access;\n\n function Prop_Check\n (F : aliased in out Ada_Pretty.Factory;\n Name : League.Strings.Universal_String) return Ada_Pretty.Node_Access;\n\n function Prop_Checks is new Generic_List_Reduce\n (League.Strings.Universal_String, String_Array, Prop_Check, F);\n\n generic\n Type_Name : Ada_Pretty.Node_Access;\n Is_Node : Boolean;\n function Prop_Getter\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access;\n\n Unreferenced : constant Ada_Pretty.Node_Access := F.New_Pragma\n (Name => F.New_Name (+\"Unreferenced\"),\n Arguments => F.New_Name (+\"Self\"));\n\n -----------------\n -- Prop_Getter --\n -----------------\n\n function Prop_Getter\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access\n is\n Pragmas : Ada_Pretty.Node_Access;\n Return_Expr : Ada_Pretty.Node_Access;\n Token : League.Strings.Universal_String;\n begin\n if Is_Node and then Prop.Name.Starts_With (\"Has_\") then\n if Prop.Name.Starts_With (\"Has_Not_Null\") then\n Token := Prop.Name.Tail_From (9); -- Null or Null_2\n else\n Token := Prop.Name.Tail_From (5);\n end if;\n\n Return_Expr := F.New_Selected_Name\n (\"Self.\" & Token & \"_Token.Assigned\");\n elsif Is_Text (Prop.Type_Name) then\n if Is_Node then\n Return_Expr := F.New_Selected_Name\n (\"Self.\" & Only_Tokens (Item.Properties) (1).Name & \".Image\");\n else\n Return_Expr := F.New_Name (+\"\"\"\"\"\");\n Pragmas := Unreferenced;\n end if;\n else\n Return_Expr := F.New_Selected_Name (\"Self.\" & Prop.Name);\n end if;\n\n return F.New_Subprogram_Body\n (Specification => F.New_Subprogram_Specification\n (Is_Overriding => Ada_Pretty.True,\n Name => F.New_Name (Prop.Name),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => Type_Name),\n Result => Property_Type (F, Prop)),\n Declarations => Pragmas,\n Statements => F.New_Return (Return_Expr));\n end Prop_Getter;\n\n Set_Enclosing_Element : constant Ada_Pretty.Node_Access :=\n F.New_Name (+\"Set_Enclosing_Element\");\n\n ------------------------\n -- Prop_Set_Enclosing --\n ------------------------\n\n function Prop_Set_Enclosing\n (F : aliased in out Ada_Pretty.Factory;\n Prop : Classes.Property) return Ada_Pretty.Node_Access\n is\n Result : Ada_Pretty.Node_Access;\n\n Attr : constant Ada_Pretty.Node_Access :=\n F.New_Argument_Association\n (Value => F.New_Name (+\"Self.\" & Prop.Name));\n\n Self : constant Ada_Pretty.Node_Access :=\n F.New_Argument_Association\n (Value => F.New_Name (+\"Self'Unchecked_Access\"));\n\n Item : constant Ada_Pretty.Node_Access :=\n F.New_Argument_Association\n (Value => F.New_Selected_Name (+\"Item.Element\"));\n\n begin\n case Prop.Capacity is\n when Meta.Classes.Just_One =>\n Result := F.New_Statement\n (F.New_Apply\n (Set_Enclosing_Element, F.New_List (Attr, Self)));\n\n when Meta.Classes.Zero_Or_One =>\n Result := F.New_If\n (Condition => F.New_Selected_Name\n (Prefix => Attr,\n Selector => F.New_Name (+\"Assigned\")),\n Then_Path => F.New_Statement\n (F.New_Apply\n (Set_Enclosing_Element, F.New_List (Attr, Self))));\n\n when others =>\n Result := F.New_For\n (Name => F.New_Name (+\"Item\"),\n Iterator => F.New_Selected_Name\n (Prefix => Attr,\n Selector => F.New_Name (+\"Each_Element\")),\n Statements => F.New_Statement\n (F.New_Apply\n (Set_Enclosing_Element,\n F.New_List (Item, Self))));\n end case;\n\n return Result;\n end Prop_Set_Enclosing;\n\n function Prop_Set_Enclosings is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Prop_Set_Enclosing, F);\n\n Base_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (\"Base_\" & Item.Name);\n\n function Base_Getter is new Prop_Getter (Base_Name, False);\n\n ----------------\n -- Prop_Check --\n ----------------\n\n function Prop_Check\n (F : aliased in out Ada_Pretty.Factory;\n Name : League.Strings.Universal_String) return Ada_Pretty.Node_Access\n is\n begin\n return F.New_Subprogram_Body\n (Specification => Prop_Check_Spec (F, Name, Base_Name),\n Declarations => Unreferenced,\n Statements => F.New_Return (F.New_Name (+\"True\")));\n end Prop_Check;\n\n Package_Name : constant League.Strings.Universal_String :=\n Node_Package_Name (Item.Name);\n\n Node_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (To_Element_Name (Item.Name));\n\n function Node_Getter is new Prop_Getter (Node_Name, True);\n\n Implicit_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (\"Implicit_\" & Item.Name);\n\n function Impl_Getter is new Prop_Getter (Implicit_Name, False);\n\n Elem : constant Classes.Class := Vector.First_Element;\n\n Bool_Props : constant Classes.Property_Array :=\n Only_Booleans (Elem.Properties & Item.Properties);\n\n Parent_Props : constant Classes.Property_Array :=\n Get_Parent_Props (Item, Vector);\n\n Result : constant Ada_Pretty.Node_Access := F.New_Name (+\"Result\");\n\n Initialize : constant Ada_Pretty.Node_Access :=\n F.New_Name (+\"Initialize\");\n\n Create_Node : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Create\"),\n Parameters => Prop_Parameters\n (Skip_Texts (Skip_Booleans (Item.Properties & Parent_Props))\n & Only_Booleans (Parent_Props)),\n Result => Node_Name),\n Statements => F.New_Extended_Return\n (Name => Result,\n Type_Definition => Node_Name,\n Initialization => F.New_Parentheses\n (F.New_List\n (Prop_Arguments\n (Skip_Texts (Skip_Booleans\n (Item.Properties & Parent_Props))\n & Only_Booleans (Parent_Props)),\n F.New_Component_Association\n (Choices => F.New_Name (+\"Enclosing_Element\"),\n Value => F.New_Name (+\"null\")))),\n Statements => F.New_Statement\n (F.New_Apply\n (Prefix => Initialize,\n Arguments => Result))));\n\n Create_Implicit : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Create\"),\n Parameters => Prop_Parameters\n (Only_Objects (Item.Properties & Parent_Props) &\n Bool_Props & Only_Booleans (Parent_Props)),\n Result => Implicit_Name),\n Statements => F.New_Extended_Return\n (Name => Result,\n Type_Definition => Implicit_Name,\n Initialization => F.New_Parentheses\n (F.New_List\n (Prop_Arguments\n (Only_Objects (Item.Properties & Parent_Props) &\n Bool_Props & Only_Booleans (Parent_Props)),\n F.New_Component_Association\n (Choices => F.New_Name (+\"Enclosing_Element\"),\n Value => F.New_Name (+\"null\")))),\n Statements => F.New_Statement\n (F.New_Apply\n (Prefix => Initialize,\n Arguments => Result))));\n\n Base_Init : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => F.New_Subprogram_Specification\n (Name => F.New_Name (+\"Initialize\"),\n Parameters => F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Type_Definition => F.New_Name\n (\"Base_\" & Item.Name & \"'Class\"),\n Is_Aliased => True,\n Is_In => True,\n Is_Out => True)),\n Statements => F.New_List\n (Prop_Set_Enclosings (Only_Objects (Item.Properties)),\n F.New_Statement));\n\n function Base_Getters is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Base_Getter, F);\n\n BG : constant Ada_Pretty.Node_Access := Base_Getters\n (Only_Objects (Item.Properties) & Only_Booleans (Parent_Props));\n\n function Node_Getters is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Node_Getter, F);\n\n NG : constant Ada_Pretty.Node_Access := Node_Getters\n (Only_Tokens (Item.Properties)\n & Only_Booleans (Item.Properties)\n & Only_Texts (Item.Properties & Parent_Props));\n\n function Impl_Getters is new Generic_List_Reduce\n (Classes.Property, Classes.Property_Array, Impl_Getter, F);\n\n IG : constant Ada_Pretty.Node_Access := Impl_Getters\n (Bool_Props & Only_Texts (Item.Properties & Parent_Props));\n\n Visit : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Visit_Spec (F, Base_Name, False),\n Statements => F.New_Statement\n (F.New_Apply\n (F.New_Selected_Name (F.New_Name (+\"Visitor\"), Node_Name),\n F.New_Name (+\"Self\"))));\n\n Node_To_Text : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => To_Text_Spec (F, Item, Node_Name),\n Statements => F.New_Return\n (F.New_Name (+\"Self'Unchecked_Access\")));\n\n Implicit_To_Text : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Body\n (Specification => To_Text_Spec (F, Item, Implicit_Name),\n Declarations => Unreferenced,\n Statements => F.New_Return\n (F.New_Name (+\"null\")));\n\n List : constant Ada_Pretty.Node_Access_Array :=\n (Create_Node, Create_Implicit,\n F.New_List (BG,\n F.New_List (NG,\n F.New_List (IG, Base_Init))),\n Prop_Checks (All_Parents (Item, Vector)),\n Visit,\n Node_To_Text,\n Implicit_To_Text);\n\n Root : constant Ada_Pretty.Node_Access :=\n F.New_Package_Body\n (F.New_Selected_Name (Package_Name), F.New_List (List));\n\n Unit : constant Ada_Pretty.Node_Access :=\n F.New_Compilation_Unit (Root);\n\n Output : Ada.Wide_Wide_Text_IO.File_Type;\n begin\n Open_File (Output, Package_Name, \"nodes/\", Spec => False);\n\n Ada.Wide_Wide_Text_IO.Put_Line\n (Output,\n F.To_Text (Unit).Join (Ada.Characters.Wide_Wide_Latin_1.LF)\n .To_Wide_Wide_String);\n\n Ada.Wide_Wide_Text_IO.Close (Output);\n end Write_One_Node_Body;\n\n --------------------\n -- Write_Visitors --\n --------------------\n\n procedure Write_Visitors (Vector : Meta.Read.Class_Vectors.Vector) is\n\n function Methods return Ada_Pretty.Node_Access;\n\n Package_Name : constant League.Strings.Universal_String :=\n Get_Package_Name (Element_Visitor);\n\n F : aliased Ada_Pretty.Factory;\n\n Pure : constant Ada_Pretty.Node_Access :=\n F.New_Pragma\n (F.New_Name (+\"Pure\"), F.New_Selected_Name (Package_Name));\n\n Type_Name : constant Ada_Pretty.Node_Access :=\n F.New_Name (Element_Visitor);\n\n Type_Decl : constant Ada_Pretty.Node_Access :=\n F.New_Type\n (Type_Name,\n Definition => F.New_Interface\n (Is_Limited => True));\n\n function Methods return Ada_Pretty.Node_Access is\n Result : Ada_Pretty.Node_Access;\n begin\n for Item of Vector loop\n if not Item.Is_Abstract then\n declare\n Element_Name : constant League.Strings.Universal_String :=\n To_Element_Name (Item.Name);\n\n Funct : constant Ada_Pretty.Node_Access :=\n F.New_Subprogram_Declaration\n (F.New_Subprogram_Specification\n (Name => F.New_Name (Element_Name),\n Parameters => F.New_List\n (F.New_Parameter\n (Name => F.New_Name (+\"Self\"),\n Is_In => True,\n Is_Out => True,\n Type_Definition => F.New_Name\n (Element_Visitor)),\n F.New_Parameter\n (Name => F.New_Name (Element),\n Type_Definition => F.New_Null_Exclusion\n (F.New_Selected_Name\n (Full_Access_Name (Item.Name)))))),\n Is_Null => True);\n begin\n Result := F.New_List (Result, Funct);" + }, + { + "function_def": "procedure Ada_LARL is", + "function_body": "use type Anagram.Grammars.Rule_Count;\n use type Anagram.Grammars.LR.State_Count;\n\n procedure Put_Proc_Decl\n (Output : in out Writer;\n Suffix : Wide_Wide_String);\n\n procedure Put_Piece\n (Piece : in out Writer;\n From : Anagram.Grammars.Production_Index;\n To : Anagram.Grammars.Production_Index);\n\n procedure Put_Rule\n (Output : in out Writer;\n Prod : Anagram.Grammars.Production;\n Rule : Anagram.Grammars.Rule);\n\n function Image (X : Integer) return Wide_Wide_String;\n\n procedure Print_Go_To;\n procedure Print_Action;\n\n File : constant String := Ada.Command_Line.Argument (1);\n G : constant Anagram.Grammars.Grammar :=\n Anagram.Grammars.Reader.Read (File);\n Plain : constant Anagram.Grammars.Grammar :=\n Anagram.Grammars_Convertors.Convert (G, Left => False);\n AG : constant Anagram.Grammars.Grammar :=\n Anagram.Grammars.Constructors.To_Augmented (Plain);\n Table : constant Anagram.Grammars.LR_Tables.Table_Access :=\n Anagram.Grammars.LR.LALR.Build\n (Input => AG,\n Right_Nulled => False);\n Resolver : Anagram.Grammars.Conflicts.Resolver;\n Output : Writer;\n\n -----------\n -- Image --\n -----------\n\n function Image (X : Integer) return Wide_Wide_String is\n Img : constant Wide_Wide_String := Integer'Wide_Wide_Image (X);\n begin\n return Img (2 .. Img'Last);\n end Image;\n\n ------------------\n -- Print_Action --\n ------------------\n\n procedure Print_Action is\n use type Anagram.Grammars.Production_Count;\n use type Anagram.Grammars.Part_Count;\n type Action_Code is mod 2 ** 16;\n\n Count : Natural;\n Code : Action_Code;\n begin\n Output.P (\" type Action_Code is mod 2 ** 16;\");\n Output.P (\" for Action_Code'Size use 16;\");\n Output.P;\n Output.P (\" Action_Table : constant array\");\n Output.N (\" (State_Index range 1 .. \");\n Output.N (Natural (Anagram.Grammars.LR_Tables.Last_State (Table.all)));\n Output.P (\",\");\n Output.N (\" Anagram.Grammars.Terminal_Count range 0 .. \");\n Output.N (Natural (Plain.Last_Terminal));\n Output.P (\") of Action_Code :=\");\n\n for State in 1 .. Anagram.Grammars.LR_Tables.Last_State (Table.all) loop\n if State = 1 then\n Output.N (\" (\");\n else\n Output.P (\",\");\n Output.N (\" \");\n end if;\n Output.N (Natural (State));\n Output.P (\" =>\");\n Output.N (\" (\");\n Count := 0;\n\n for T in 0 .. Plain.Last_Terminal loop\n declare\n use Anagram.Grammars.LR_Tables;\n S : constant Anagram.Grammars.LR.State_Count :=\n Shift (Table.all, State, T);\n R : constant Reduce_Iterator := Reduce (Table.all, State, T);\n begin\n if S /= 0 then\n Code := Action_Code (S) + 16#80_00#;\n elsif not Is_Empty (R) then\n Code := Action_Code (Production (R));\n else\n Code := 0;\n end if;\n\n if Code /= 0 then\n Output.N (Natural (T));\n Output.N (\" => \");\n Output.N (Natural (Code));\n Count := Count + 1;\n if Count < 4 then\n Output.N (\", \");\n else\n Count := 0;\n Output.P (\",\");\n Output.N (\" \");\n end if;\n end if;" + }, + { + "function_def": "procedure Print_Go_To is", + "function_body": "Count : Natural;\n begin\n Output.P (\" Go_To_Table : constant array\");\n Output.N (\" (Anagram.Grammars.LR_Parsers.State_Index range 1 .. \");\n Output.N (Natural (Anagram.Grammars.LR_Tables.Last_State (Table.all)));\n Output.P (\",\");\n Output.N (\" Anagram.Grammars.Non_Terminal_Index range 1 .. \");\n Output.N (Natural (Plain.Last_Non_Terminal));\n Output.P (\") of State_Index :=\");\n\n for State in 1 .. Anagram.Grammars.LR_Tables.Last_State (Table.all) loop\n if State = 1 then\n Output.N (\" (\");\n else\n Output.P (\",\");\n Output.N (\" \");\n end if;\n Output.N (Natural (State));\n Output.P (\" =>\");\n Output.N (\" (\");\n Count := 0;\n\n for NT in 1 .. Plain.Last_Non_Terminal loop\n declare\n use Anagram.Grammars.LR;\n Next : constant State_Count :=\n Anagram.Grammars.LR_Tables.Shift (Table.all, State, NT);\n begin\n if Next /= 0 then\n Output.N (Natural (NT));\n Output.N (\" => \");\n Output.N (Natural (Next));\n Count := Count + 1;\n if Count < 4 then\n Output.N (\", \");\n else\n Count := 0;\n Output.P (\",\");\n Output.N (\" \");\n end if;\n end if;" + }, + { + "function_def": "procedure Dump_Standard is", + "function_body": "procedure Print (View : Program.Visibility.View);\n procedure Print (View : Program.Visibility.View_Array);\n\n Ctx : aliased Program.Plain_Contexts.Context;\n Env : aliased Program.Visibility.Context;\n\n -----------\n -- Print --\n -----------\n\n procedure Print (View : Program.Visibility.View_Array) is\n begin\n for J in View'Range loop\n Print (View (J));\n end loop;\n end Print;\n\n -----------\n -- Print --\n -----------\n\n procedure Print (View : Program.Visibility.View) is\n use Program.Visibility;\n Name : constant Program.Elements.Defining_Names.Defining_Name_Access :=\n Program.Visibility.Name (View);\n begin\n if Name.Assigned then\n Ada.Wide_Wide_Text_IO.Put_Line\n (Name.Image\n & \" [\"\n & View_Kind'Wide_Wide_Image (View.Kind)\n & \"]\");\n else\n Ada.Wide_Wide_Text_IO.Put_Line\n (\"___ [\"\n & View_Kind'Wide_Wide_Image (View.Kind)\n & \"]\");\n end if;\n\n case View.Kind is\n when Enumeration_Type_View =>\n Print (Enumeration_Literals (View));\n when Signed_Integer_Type_View =>\n null;\n when Modular_Type_View =>\n null;\n when Float_Point_Type_View =>\n null;\n when Array_Type_View =>\n declare\n Indexes : constant Program.Visibility.View_Array :=\n Program.Visibility.Indexes (View);\n begin\n for J in Indexes'Range loop\n Ada.Wide_Wide_Text_IO.Put (\" \");\n Print (Indexes (J));\n end loop;\n Ada.Wide_Wide_Text_IO.Put (\" => \");\n Print (Program.Visibility.Component (View));" + }, + { + "function_def": "function Immediate_Visible", + "function_body": "(Self : access constant Context;\n Region : Item_Offset;\n Symbol : Program.Visibility.Symbol) return View_Array;\n\n -----------------\n -- Append_Item --\n -----------------\n\n procedure Append_Item\n (Self : in out Context'Class;\n Value : Item) is\n begin\n Self.Last_Entity := Self.Last_Entity + 1;\n Self.Data.Append (Value);\n\n if not Self.Stack.Is_Empty then\n Self.Data (Self.Stack.Last_Element.Enclosing_Item).Region.Append\n (Self.Data.Last_Index);\n end if;\n end Append_Item;\n\n ---------------\n -- Component --\n ---------------\n\n function Component (Self : View) return View is\n Type_Item : Item renames Self.Env.Data (Self.Index);\n begin\n return Self.Env.Get_View (Type_Item.Component);\n end Component;\n\n -----------------------\n -- Create_Array_Type --\n -----------------------\n\n not overriding procedure Create_Array_Type\n (Self : in out Context;\n Symbol : Program.Visibility.Symbol;\n Name : Defining_Name;\n Indexes : View_Array;\n Component : View)\n is\n Value : constant Item :=\n (Kind => Array_Type_View,\n Symbol => Symbol,\n Name => Name,\n Entity_Id => Self.Last_Entity + 1,\n Indexes => To_Vector (Indexes),\n Component => Component.Index);\n\n begin\n Self.Append_Item (Value);\n end Create_Array_Type;\n\n ------------------------------\n -- Create_Character_Literal --\n ------------------------------\n\n not overriding procedure Create_Character_Literal\n (Self : in out Context;\n Symbol : Program.Visibility.Symbol;\n Name : Defining_Name;\n Enumeration_Type : View)\n is\n Value : constant Item :=\n (Kind => Character_Literal_View,\n Symbol => Symbol,\n Name => Name,\n Entity_Id => Self.Last_Entity + 1,\n Character_Type => Enumeration_Type.Index);\n\n begin\n Self.Append_Item (Value);\n\n declare\n Type_Item : Item renames Self.Data (Enumeration_Type.Index);\n begin\n Type_Item.Enumeration_Literals.Append (Self.Data.Last_Index);" + }, + { + "function_def": "function Immediate_Visible", + "function_body": "(Self : access constant Context;\n Region : Item_Offset;\n Symbol : Program.Visibility.Symbol) return View_Array\n is\n Result : View_Array (1 .. 10);\n Last : Natural := 0;\n Value : Item renames Self.Data (Region);\n begin\n if Value.Kind in Has_Region_Kind then\n for Index of Value.Region loop\n declare\n Value : constant Item := Self.Data (Index);\n begin\n if Value.Symbol = Symbol then\n Last := Last + 1;\n Result (Last) := (Value.Kind, Self, Index);\n end if;" + }, + { + "function_def": "function Immediate_Visible", + "function_body": "(Self : View;\n Symbol : Program.Visibility.Symbol) return View_Array is\n begin\n return Immediate_Visible (Self.Env, Self.Index, Symbol);\n end Immediate_Visible;\n\n -----------------------\n -- Immediate_Visible --\n -----------------------\n\n not overriding function Immediate_Visible\n (Self : aliased Context; Symbol : Program.Visibility.Symbol)\n return View_Array\n is\n procedure Append (List : View_Array);\n Result : View_Array (1 .. 10);\n Last : Natural := 0;\n\n procedure Append (List : View_Array) is\n begin\n Result (Last + 1 .. Last + List'Length) := List;\n Last := Last + List'Length;\n end Append;\n\n begin\n for J of reverse Self.Stack loop\n Append (Immediate_Visible (Self'Access, J.Enclosing_Item, Symbol));\n end loop;\n\n if Symbol = Standard and then not Self.Stack.Is_Empty then\n declare\n Top : constant View :=\n (Package_View,\n Self'Access,\n Self.Stack.First_Element.Enclosing_Item);\n begin\n Append ((1 => Top));" + }, + { + "function_def": "not overriding function Create_Discrete_Range_Vector", + "function_body": "(Self : Element_Vector_Factory;\n Each : Program.Element_Vectors.Iterators.Forward_Iterator'Class)\n return Program.Elements.Discrete_Ranges.Discrete_Range_Vector_Access\n is\n Cursor : constant Program.Element_Vectors.Element_Cursor := Each.First;\n begin\n if not Program.Element_Vectors.Has_Element (Cursor) then\n return null;\n end if;\n\n declare\n Result : constant Discrete_Range_Vector_Access :=\n new (Self.Subpool)\n Program.Nodes.Discrete_Range_Vectors.Vector'\n (Program.Nodes.Discrete_Range_Vectors.Create (Each));\n begin\n return Program.Elements.Discrete_Ranges\n .Discrete_Range_Vector_Access (Result);" + }, + { + "function_def": "not overriding function Create_Discriminant_Association_Vector", + "function_body": "(Self : Element_Vector_Factory;\n Each : Program.Element_Vectors.Iterators.Forward_Iterator'Class)\n return Program.Elements.Discriminant_Associations\n .Discriminant_Association_Vector_Access\n is\n Cursor : constant Program.Element_Vectors.Element_Cursor := Each.First;\n begin\n if not Program.Element_Vectors.Has_Element (Cursor) then\n return null;\n end if;\n\n declare\n Result : constant Discriminant_Association_Vector_Access :=\n new (Self.Subpool)\n Program.Nodes.Discriminant_Association_Vectors.Vector'\n (Program.Nodes.Discriminant_Association_Vectors.Create (Each));\n begin\n return Program.Elements.Discriminant_Associations\n .Discriminant_Association_Vector_Access (Result);" + }, + { + "function_def": "not overriding function Create_Discriminant_Specification_Vector", + "function_body": "(Self : Element_Vector_Factory;\n Each : Program.Element_Vectors.Iterators.Forward_Iterator'Class)\n return Program.Elements.Discriminant_Specifications\n .Discriminant_Specification_Vector_Access\n is\n Cursor : constant Program.Element_Vectors.Element_Cursor := Each.First;\n begin\n if not Program.Element_Vectors.Has_Element (Cursor) then\n return null;\n end if;\n\n declare\n Result : constant Discriminant_Specification_Vector_Access :=\n new (Self.Subpool)\n Program.Nodes.Discriminant_Specification_Vectors.Vector'\n (Program.Nodes.Discriminant_Specification_Vectors.Create\n (Each));\n begin\n return Program.Elements.Discriminant_Specifications\n .Discriminant_Specification_Vector_Access (Result);" + }, + { + "function_def": "procedure Init is", + "function_body": "RCC : RCC_Peripheral renames RCC_Periph;\n begin\n\t if PLL_Source = HSE_Input then\n\t\t RCC.CR.HSEON := 1;\n\t\t while RCC.CR.HSERDY = 0 loop\n\t\t\tnull;\n\t\t end loop;\n\t end if;\n\t RCC.CFGR := (\n\t\t PLLMUL => UInt4 (PLL_Mul),\n\t\t PLLSRC => (\n\t\t\tcase PLL_Source is\n\t\t\t when HSI_Input => 1,\n\t\t\t when HSE_Input => 1),\n\t\t others => <>);" + }, + { + "function_def": "procedure Init is", + "function_body": "RCC : RCC_Peripheral renames RCC_Periph;\n begin\n\t if PLL_Source = HSE_Input then\n\t\t RCC.CR.HSEON := 1;\n\t\t while RCC.CR.HSERDY = 0 loop\n\t\t\tnull;\n\t\t end loop;\n\t end if;" + }, + { + "function_def": "procedure Wait_For_Trigger is", + "function_body": "begin\n STM32GD.EXTI.IRQ.IRQ_Handler.Wait;\n end Wait_For_Trigger;\n\n procedure Clear_Trigger is\n begin\n STM32GD.EXTI.IRQ.IRQ_Handler.Reset_Status (Interrupt_Line_Number);\n end Clear_Trigger;\n\n function Triggered return Boolean is\n begin\n return False;" + }, + { + "function_def": "procedure Init is", + "function_body": "begin\n STM32_SVD.RCC.RCC_Periph.APB2ENR.AFIOEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPAEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPBEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPCEN := 1;\n STM32_SVD.NVIC.NVIC_Periph.ISER0 := 2#00000000_10000000_00000000_00000000#;\n BUTTON.Init;\n USB_DISC.Init;\n SWO.Init;\n LED.Init;\n LED2.Init;\n end Init;\n\n procedure USB_Re_Enumerate is\n begin\n Ada.Text_IO.Put_Line (\"Re-enumerate\");\n USB_DISC.Set;\n declare\n I : UInt32 with volatile;\n begin\n I := 10000;\n while I > 0 loop\n I := I - 1;\n end loop;" + }, + { + "function_def": "procedure Init is", + "function_body": "begin\n STM32_SVD.RCC.RCC_Periph.APB2ENR.AFIOEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPAEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPBEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPCEN := 1;\n STM32_SVD.NVIC.NVIC_Periph.ISER0 := 2#00000000_10000000_00000000_00000000#;\n BUTTON.Init;\n -- SWO.Init;\n LED.Init;\n LED2.Init;\n end Init;\n\n procedure USB_Re_Enumerate is\n begin\n STM32_SVD.GPIO.GPIOA_Periph.CRH.CNF12 := 0;\n STM32_SVD.GPIO.GPIOA_Periph.CRH.MODE12 := 1;\n STM32_SVD.GPIO.GPIOA_Periph.BSRR.BR.Arr (12) := 1;\n declare\n I : UInt32 with volatile;\n begin\n I := 100000;\n while I > 0 loop\n I := I - 1;\n end loop;" + }, + { + "function_def": "procedure Init is", + "function_body": "begin\n Clocks.Init;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.AFIOEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPAEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPBEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.IOPCEN := 1;\n STM32_SVD.RCC.RCC_Periph.APB2ENR.USART1EN := 1;\n BUTTON.Init;\n LED.Init;\n LED2.Init;\n TX.Init;\n RX.Init;\n USART.Init;\n RTC.Init;\n end Init;\n\n procedure USB_Re_Enumerate is\n begin\n STM32_SVD.GPIO.GPIOA_Periph.CRH.CNF12 := 0;\n STM32_SVD.GPIO.GPIOA_Periph.CRH.MODE12 := 1;\n STM32_SVD.GPIO.GPIOA_Periph.BSRR.BR.Arr (12) := 1;\n declare\n I : UInt32 with volatile;\n begin\n I := 100000;\n while I > 0 loop\n I := I - 1;\n end loop;" + }, + { + "function_def": "procedure Init is", + "function_body": "RCC : RCC_Peripheral renames RCC_Periph;\n begin\n\t if PLL_Source = HSE_Input then\n\t\t RCC.CR.HSEON := 1;\n\t\t while RCC.CR.HSERDY = 0 loop\n\t\t\tnull;\n\t\t end loop;\n\t end if;\n\t RCC.CFGR := (\n\t\t PLLMUL => UInt4 (PLL_Mul),\n\t\t PLLSRC => (\n\t\t\tcase PLL_Source is\n\t\t\t when HSI_Input => 1,\n\t\t\t when HSE_Input => 1),\n\t\t others => <>);" + }, + { + "function_def": "procedure bot is", + "function_body": "game : T_game;\n logic : T_logic;\n message : T_round;\n\n MAX_LINE_LENGTH : constant integer := 100;\n line : string(1..MAX_LINE_LENGTH);\n line_length : integer;\n\n last_command : T_command;\n\n winning_chances : Float;\n\n NbBluffInit : Constant integer :=3;\n CompteurBluffInit : Integer :=0;\n\nbegin\n\n initGame(game);\n\n while not End_Of_File loop\n get_line(line, line_length);\n\n last_command := splitLine(line, line_length);\n\n case last_command.prefix is\n --Settings\n when settings => readSettings(last_command, game);\n\n --update_game\n when update_game => readUpdateGame(last_command, game);\n\n --update_hand\n when update_hand => readUpdateHand(last_command, game, logic);\n\n when action =>\n\n winning_chances := get_winning_chances(logic);\n\n if CompteurBluffInit= LOW) then\n message := strat(logic, game);\n\n else\n if get_my_money(game) > get_op_money(game) then\n message := create_round(bet,Integer(IDIOT_OP*get_op_money(game)));\n else\n message:= create_round(bet, Integer(IDIOT_OWN*get_my_money(game)));\n end if;\n CompteurBluffInit := CompteurBluffInit +1;\n end if;\n else\n message := strat(logic, game);\n\n\n end if;\n Put_Line(Standard_Error,To_Lower(ToString(message)));\n printCard(get_card(get_hand(game),0));\n printCard(get_card(get_hand(game),1));\n Put_Line(Standard_Error, winning_chances'Img);\n Put_line(To_Lower(ToString(message)));\n\n end case;\n end loop;\n Put_Line(Standard_Error, can_bluff(logic)'Img&can_get_bluffed(logic)'Img&can_semi_bluff(logic)'Img);" + }, + { + "function_def": "procedure Stop_Driver is", + "function_body": "begin\n SPI.Stop;\n GPIO.Close;\n end Stop_Driver;\n\n procedure Init_Display is\n begin\n OLED_SH1106.Display.Reset;\n OLED_SH1106.Display.Init_Reg;\n delay 0.2;\n Write_Reg(16#AF#);\n end Init_Display;\n\n procedure Show is\n Start : Natural := 0;\n begin\n for Page in 0..7 loop\n -- set page address\n Write_Reg(16#B0# + Unsigned_8(Page));\n -- set low column address\n Write_Reg(16#02#);\n -- set high column address\n Write_Reg(16#10#);\n\n -- write data\n Start_Data;\n for I in Start..(Start+Display_Width-1) loop\n Write_Data(Buffer.Data(i));\n end loop;\n Start := Start + Display_Width;\n end loop;\n end Show;\n\n -- Clear the screen.\n procedure Clear(Clr: Color:= Black) is\n begin\n Graphics.Set(Buffer'access, Clr);\n end Clear;\n\n -- Draw a point with size \"Size\" at poiny X,Y.\n procedure Dot(P: Point; Size: Positive:=1; Clr: Color:=White) is\n begin\n Graphics.Dot(Buffer'access, P, Size, Clr);\n end Dot;\n\n procedure Line\n (P,Q: Point; Size: Positive:= 1; Clr:Color:= White) is\n begin\n Graphics.Line(Buffer'access, P, Q, Size, Clr);\n end Line;\n\n procedure Rectangle\n (P, Q: Point; Size: Positive:= 1; Clr: Color:= White) is\n begin\n Graphics.Rectangle(Buffer'access, P, Q, Size, Clr);\n end Rectangle;\n\n procedure Fill_Rectangle\n (P, Q: Point; Clr: Color := White) is\n begin\n Graphics.Fill_Rectangle(Buffer'access, P, Q, Clr);\n end Fill_Rectangle;\n\n\n procedure Circle\n (Center: Point; R:Natural; Size: Positive := 1; Clr: Color:= White) is\n begin\n Graphics.Circle(Buffer'access, Center, R, Size, Clr);\n end Circle;\n\n procedure Fill_Circle\n (Center: Point; R: Natural; Clr: Color:= White) is\n begin\n Graphics.Fill_Circle(Buffer'access, Center, R, Clr);\n end Fill_Circle;\n\n procedure Put\n (P : Point;\n Ch : Character;\n Size : Positive:= 12;\n Fgnd : Color := White;\n Bgnd : Color := Black) is\n begin\n Graphics.Put(Buffer'access, P, Ch, Size, Fgnd, Bgnd);\n end Put;\n\n\n procedure Put\n (P : Point;\n Text : String;\n Size : Positive:= 12;\n Fgnd : Color := White;\n Bgnd : Color := Black) is\n begin\n Graphics.Put(Buffer'access, P, Text, Size, Fgnd, Bgnd);\n end Put;\n\n\n -- Draw a number to the display\n procedure Put\n (P : Point; -- Position\n Num : Natural; -- The number to draw\n Size : Positive := 12; -- Font size\n Fgnd : Color := White; -- Foreground color\n Bgnd : Color := Black) is -- Background color\n begin\n Graphics.Put(Buffer'access, P, Num, Size, Fgnd, Bgnd);\n end Put;\n\n\n procedure Bitmap\n (P: Point; Bytes : Byte_Array_Access; S: Size) is\n begin\n Graphics.Bitmap(Buffer'access, P, Bytes, S);\n end Bitmap;\n\n procedure Bitmap\n (P: Point; Icon: Bitmap_Icon) is\n begin\n Graphics.Bitmap(Buffer'access, P, Icon);" + }, + { + "function_def": "procedure Tests is", + "function_body": "Failures : Natural := 0;\nbegin\n\n for Kind in Testsuite.Encode.Encoder_Kind\n loop\n declare\n Suite : aliased AUnit.Test_Suites.Test_Suite;\n\n function Get_Suite return AUnit.Test_Suites.Access_Test_Suite\n is (Suite'Unchecked_Access);\n\n function Runner is new AUnit.Run.Test_Runner_With_Status (Get_Suite);\n\n Reporter : AUnit.Reporter.Text.Text_Reporter;\n begin\n\n Ada.Text_IO.New_Line;\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\"Testing \" & Kind'Img & \" encoder:\");\n Testsuite.Encode.Set_Encoder_Kind (Kind);\n Testsuite.Encode.Add_Tests (Suite);\n\n Reporter.Set_Use_ANSI_Colors (True);\n\n if Runner (Reporter,\n (Global_Timer => True,\n Test_Case_Timer => True,\n Report_Successes => True,\n others => <>))\n /= AUnit.Success\n then\n Failures := Failures + 1;\n end if;" + }, + { + "function_def": "function Runner is new AUnit.Run.Test_Runner_With_Status (Get_Suite);", + "function_body": "Reporter : AUnit.Reporter.Text.Text_Reporter;\n begin\n\n Ada.Text_IO.New_Line;\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\"Testing \" & Kind'Img & \" decoder:\");\n Testsuite.Decode.Set_Decoder_Kind (Kind);\n Testsuite.Decode.Add_Tests (Suite);\n\n Reporter.Set_Use_ANSI_Colors (True);\n\n if Runner (Reporter,\n (Global_Timer => True,\n Test_Case_Timer => True,\n Report_Successes => True,\n others => <>))\n /= AUnit.Success\n then\n Failures := Failures + 1;\n end if;" + }, + { + "function_def": "function Runner is new AUnit.Run.Test_Runner_With_Status", + "function_body": "(Get_Suite);\n\n Reporter : AUnit.Reporter.Text.Text_Reporter;\n begin\n\n Ada.Text_IO.New_Line;\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\"Testing \" & E_Kind'Img & \" encoder\" &\n \" with \" & D_Kind'Img & \" decoder\");\n Testsuite.Encode_Decode.Set_Kinds (E_Kind, D_Kind);\n Testsuite.Encode_Decode.Add_Tests (Suite);\n\n Reporter.Set_Use_ANSI_Colors (True);\n\n if Runner (Reporter,\n (Global_Timer => True,\n Test_Case_Timer => True,\n Report_Successes => True,\n others => <>))\n /= AUnit.Success\n then\n Failures := Failures + 1;\n end if;" + }, + { + "function_def": "procedure Refresh is", + "function_body": "begin\n\t\t--clear screen\n\t\t--New_Line(100);\n\t\tPut(ASCII.ESC & \"[;H\");\n\t\t--fill screen\n\t\tFor Y in Integer Range 0..Screen_Height loop\n\t\t\tFor X in Integer Range 0..Screen_Width loop\n\t\t\t\tbegin\n\t\t\t\t\tPut(Screen(X,Y).color);\n\t\t\t\t\tif(Character'Pos(Screen(X,Y).char) >= 32) then\n\t\t\t\t\t\tPut(Screen(X,Y).char);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(' ');\n\t\t\t\t\tend if;\n\t\t\t\texception\n\t\t\t\t\twhen others =>\n\t\t\t\t\t\tnull;" + }, + { + "function_def": "procedure spritemaker is", + "function_body": "procedure showFile(Filename : String) is\n\t\tFile : File_Type;\n\tbegin\n\t\tOpen(File, In_File, Filename);\n\t\twhile(not End_Of_File(File)) loop\n\t\t\tPut(Get_Line(File => File));\n\t\t\tnew_line;\n\t\tend loop;\n\t\tClose(File);\n\tend showFile;\n\t\n\n\tfunction LoadSpriteNoFormat(FileName : String) return SpriteType is\n\t\t\tFile : File_Type;\n\t\t\twidth : Integer;\n\t\t\theight : Integer;\n\t\t\tsprite : SpriteType;\n\t\t\tline: String(1..128);\n\t\t\tcolor : colorType := colorDefault;\n\t\t\toffset : Positive := 1;\n\t\tbegin\n\t\t\t--clear garbage data\n\t\t\twidth := 127;\n\t\t\theight := 63;\n\t\t\tFor Y in Integer range 0..height loop\n\t\t\t\tFor X in Integer range 0..width loop\n\t\t\t\t\tsprite.Image(X,Y).char := ' ';\n\t\t\t\t\tsprite.color := colorDefault;\n\t\t\t\tend loop;\n\t\t\tend loop;\n\t\t\t--load sprite\n\t\t\tOpen(File, In_File, FileName);\n\t\t\tGet(File => File, Item => width);\n\t\t\tGet(File => File, Item => height);\n\t\t\tsprite.Width := width;\n\t\t\tsprite.Height := height;\n\t\t\tSkip_Line(File);\n\t\t\tFor Y in Integer range 0..height-1 loop\n\t\t\t\tGet_Line(File => File, Item => line, Last => width);\n\t\t\t\tWidth := Width - 1;\n\t\t\t\toffset := 1;\n\t\t\t\tFor X in Integer range 0..width loop\n\t\t\t\t\tsprite.Image(X,Y).char := line(X+offset);\n\t\t\t\t\tsprite.Image(X,Y).color := colorDefault;\n\t\t\t\t\tput(line(X+offset));\n\t\t\t\tend loop;\n\t\t\t\t--Put(\" \");\n\t\t\t\tnew_line;\n\t\t\tend loop;\n\t\t\tClose(File);\n\t\t\tReturn sprite;\n\t\tend LoadSpriteNoFormat;\n\n\tprocedure saveSprite(sprite : SpriteType; FileName : String) is\n\t\tFile : File_Type;\n\t\twidth : Natural := sprite.width;\n\t\theight : Natural := sprite.height;\n\tbegin\n\t\tCreate(File, Out_File, FileName);\n\t\tPut(File => File, Item => sprite.width , Width => 0);\n\t\tPut(File => File, Item => \" \");\n\t\tPut(File => File, Item => sprite.height, Width => 0);\n\t\tNew_Line(File);\n\t\tFor Y in Integer range 0..height loop\n\t\t\tFor X in Integer range 0..width loop\n\t\t\t\tPut(File => File, Item => sprite.Image(X,Y).color);\n\t\t\t\tPut(File => File, Item => sprite.Image(X,Y).char);\n\t\t\tend loop;\n\t\t\tNew_Line(File);\n\t\tend loop;\n\t\tClose(File);\n\tend saveSprite;\n\t\t\n\t--paint tools\n\tprocedure boxFill (X,Y,W,H : Integer) is\n\tbegin\n\t\tnull;--do stuff" + }, + { + "function_def": "procedure ShowCommands is", + "function_body": "posX : Integer := Screen_Width-14;\n\t\tposY : Integer := 2;\n\tbegin\n\t\t\n\t\tfor I in 0..Screen_Height loop\n\t\t\tsetPixel(posX-02,I,character'val(186), colorDefault);\n\t\t\tsetPixel(posX+14,I,character'val(186), colorDefault);\n\t\tend loop;\n\t\n\t\tSetText(posX, posY+00, \"Color \", currentCol);\n\t\tSetText(posX, posY+02, \"Black : 0\");\n\t\tSetText(posX, posY+03, \"Red : 1\");\n\t\tSetText(posX, posY+04, \"Green : 2\");\n\t\tSetText(posX, posY+05, \"Yellow : 3\");\n\t\tSetText(posX, posY+06, \"Blue : 4\");\n\t\tSetText(posX, posY+07, \"Magenta : 5\");\n\t\tSetText(posX, posY+08, \"Cyan : 6\");\n\t\tSetText(posX, posY+09, \"White : 7\");\n\t\tSetText(posX, posY+10, \"Shade : 8\");\n\t\tSetText(posX, posY+11, \"Invert : 9\");\n\t\tSetText(posX, posY+12, \"Set : Space\");\n\t\tSetText(posX, posY+13, \"Auto : S\");\n\t\tSetText(posX, posY+14, \"Fill : F\");\n\t\t--SetText(posX, posY+15, \"\\Box Fill: B\");\n\t\t\n\t\tSetText(posX, posY+20, \"Save : -\");\n\t\tSetText(posX, posY+21, \"Quit : Q\");\n\tend ShowCommands;\n\t\t\n\tline : String(1..250);\n\tlen : Natural;\n\teditSprite : SpriteType;\n\t\n\tuseBox : Boolean := False;\n\tboxStartX : Integer := 0;\n\tboxStartY : Integer := 0;\n\t\t\nbegin\n\n\tput(ASCII.ESC & \"[?25l\"); -- cursor off (?25h for on)\n\n\tcursorX := 0;\n\tcursorY := 0;\n\n\tInitialize(140,50);\n\n\t--primary menu\n\tloop\n\t\tWipeScreen;\n\t\tsetText(4, 12, \"What would you like to load?\");\n\t\tsetText(6, 14, \"1 - Unformatted sprite\");\n\t\tsetText(6, 15, \"2 - Existing Sprite file\");\n\t\trefresh;\n\t\tget_immediate(input);\n\t\texit when input = '1';\n\t\texit when input = '2';\n\tend loop;\n\t\n\tloop\n\t\tPut(\"Enter File to load\");\n\t\tnew_line;\n\t\tGet_Line(Item => line, Last => len);\n\t\tPut(\"Loading \" & line(1..len));\n\t\tnew_line;\n\t\t\n\t\tbegin--exception\n\t\t\tif(input = '1') then\t\t\n\t\t\t\teditSprite := LoadSpriteNoFormat(line(1..len));\n\t\t\t\tPut(\"----\");\n\t\t\t\texit;\n\t\t\telsif(input = '2') then\n\t\t\t\teditSprite := LoadSprite(line(1..len));\n\t\t\t\tPut(\"----\");\n\t\t\tend if;\n\t\t\t\texit;\n\t\t\t\n\t\texception\n\t\t\twhen others => \n\t\t\t\tPut(\"File does not exist or the file format is incorrect.\");" + }, + { + "function_def": "procedure Monitor is", + "function_body": "ptr : Proxy.ManagerPtr := Proxy.GetManager;\nbegin\n ptr.Start;\n LOG_INFO (\"LOG \", \"Start Manager\");\n\n loop\n declare\n str : String := Get_Line;\n begin\n exit when str = \"quit\" or else str = \"exit\";" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation (SinkOutputer, SinkOutputerPtr);", + "function_body": "begin\n self.handler.Stop;\n Free (self.handler);\n end Close;\n \n -----------------------------------------------------------------------------\n task body SinkOutputer is\n isWorked : Pal.bool := true;\n sinkTag : ESinkType;\n severity : Logging_Message.ESeverity;\n channel : Logging_Message.LogChannel;\n var : Pal.uint32_t;\n begin\n accept Start (tag : ESinkType;\n sev : Logging_Message.ESeverity;\n ch : Logging_Message.LogChannel) do\n sinkTag := tag;\n severity := sev;\n channel := ch;\n end Start;\n \n while isWorked loop\n select\n accept Write (logs : in LogMessages;\n file : in ASU.Unbounded_String := ASU.Null_Unbounded_String) do\n for i in logs.Get.First_Index .. logs.Get.Last_Index loop\n declare\n msg : Logging_Message.LogMessage := logs.Get.Element (i);\n begin\n if msg.Get.lchannel = channel and then\n msg.Get.severity >= severity and then\n msg.Get.command = Logging_Message.eMessage then\n if sinkTag = CONSOLE_SINK then\n Put_Line (FormatMessage (msg.Get));\n elsif sinkTag = FILE_SINK then\n -- TODO: implement\n null;\n end if;\n end if;" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation (RTI_Connext_Replier, RTI_Connext_Replier_Access);", + "function_body": "begin\n Free (Self);" + }, + { + "function_def": "procedure free is new ada.Unchecked_Deallocation (Ref'class, ref_access);", + "function_body": "------------\n -- Create --\n ------------\n\n function Create\n (Participant : DDS.DomainParticipant.Ref_Access;\n Service_Name : DDS.String;\n Library_Name : DDS.String;\n Profile_Name : DDS.String;\n Publisher : DDS.Publisher.Ref_Access := null;\n Subscriber : DDS.Subscriber.Ref_Access := null;\n Listner : Replyer_Listeners.Ref_Access := null;\n Mask : DDS.StatusKind := DDS.STATUS_MASK_NONE) return Ref_Access\n is\n Request_Topic_Name : DDS.String := DDS.Request_Reply.Impl.Create_Request_Topic_Name_From_Service_Name (Service_Name);\n Reply_Topic_Name : DDS.String := DDS.Request_Reply.Impl.Create_Reply_Topic_Name_From_Service_Name (Service_Name);\n Ret : Ref_Access;\n begin\n Ret := Create (Participant,\n Request_Topic_Name,\n Reply_Topic_Name,\n Library_Name,\n Profile_Name,\n Publisher,\n Subscriber,\n Listner, Mask);\n Finalize (Request_Topic_Name);\n Finalize (Reply_Topic_Name);\n return Ret;\n\n end Create;\n\n ------------\n -- Create --\n ------------\n\n function Create\n (Participant : DDS.DomainParticipant.Ref_Access;\n Request_Topic_Name : DDS.String;\n Reply_Topic_Name : DDS.String;\n Library_Name : DDS.String;\n Profile_Name : DDS.String;\n Publisher : DDS.Publisher.Ref_Access := null;\n Subscriber : DDS.Subscriber.Ref_Access := null;\n Listner : Replyer_Listeners.Ref_Access := null;\n Mask : DDS.StatusKind := DDS.STATUS_MASK_NONE) return Ref_Access\n is\n Datawriter_Qos : DDS.DataWriterQos;\n Datareader_Qos : DDS.DataReaderQos;\n Request_Topic_QoS : DDS.TopicQos;\n Reply_Topic_Qos : DDS.TopicQos;\n begin\n Participant.Get_Factory.Get_Datareader_Qos_From_Profile_W_Topic_Name (Datareader_Qos, Library_Name, Profile_Name, Request_Topic_Name);\n Participant.Get_Factory.Get_Datawriter_Qos_From_Profile_W_Topic_Name (DataWriter_Qos, Library_Name, Profile_Name, Reply_Topic_Name);\n Participant.Get_Factory.Get_Topic_Qos_From_Profile_W_Topic_Name (Request_Topic_QoS, Library_Name, Profile_Name, Request_Topic_Name);\n Participant.Get_Factory.Get_Topic_Qos_From_Profile_W_Topic_Name (Reply_Topic_Qos, Library_Name, Profile_Name, Reply_Topic_Name);\n\n return Create (Participant => Participant,\n Request_Topic_Name => Request_Topic_Name,\n Reply_Topic_Name => Reply_Topic_Name,\n Datawriter_Qos => Datawriter_Qos,\n Datareader_Qos => Datareader_Qos,\n Reply_Topic_Qos => Reply_Topic_Qos,\n Request_Topic_QoS => Request_Topic_QoS,\n Publisher => Publisher,\n Subscriber => Subscriber,\n Listner => Listner,\n Mask => Mask);\n\n end Create;\n\n ------------\n -- Create --\n ------------\n\n function Create\n (Participant : DDS.DomainParticipant.Ref_Access;\n Service_Name : DDS.String;\n Datawriter_Qos : DDS.DataWriterQos;\n Datareader_Qos : DDS.DataReaderQos;\n Reply_Topic_Qos : DDS.TopicQos;\n Request_Topic_Qos : DDS.TopicQos;\n Publisher : DDS.Publisher.Ref_Access := null;\n Subscriber : DDS.Subscriber.Ref_Access := null;\n Listner : Replyer_Listeners.Ref_Access := null;\n Mask : DDS.StatusKind := DDS.STATUS_MASK_NONE) return Ref_Access\n is\n Request_Topic_Name : DDS.String := DDS.Request_Reply.Impl.Create_Request_Topic_Name_From_Service_Name (Service_Name);\n Reply_Topic_Name : DDS.String := DDS.Request_Reply.Impl.Create_Reply_Topic_Name_From_Service_Name (Service_Name);\n Ret : Ref_Access;\n begin\n Ret := Create (Participant => Participant,\n Request_Topic_Name => Request_Topic_Name,\n Reply_Topic_Name => Reply_Topic_Name,\n Datawriter_Qos => Datawriter_Qos,\n Datareader_Qos => Datareader_Qos,\n Reply_Topic_Qos => Reply_Topic_Qos,\n Request_Topic_Qos => Request_Topic_Qos,\n Publisher => Publisher,\n Subscriber => Subscriber,\n Listner => Listner,\n Mask => Mask);\n Finalize (Request_Topic_Name);\n Finalize (Reply_Topic_Name);\n return Ret;\n end Create;\n\n ------------\n -- Create --\n ------------\n function Create\n (Participant : DDS.DomainParticipant.Ref_Access;\n Request_Topic_Name : DDS.String;\n Reply_Topic_Name : DDS.String;\n Datawriter_Qos : DDS.DataWriterQos;\n Datareader_Qos : DDS.DataReaderQos;\n Reply_Topic_Qos : DDS.TopicQos;\n Request_Topic_Qos : DDS.TopicQos;\n Publisher : DDS.Publisher.Ref_Access := null;\n Subscriber : DDS.Subscriber.Ref_Access := null;\n Listner : Replyer_Listeners.Ref_Access := null;\n Mask : DDS.StatusKind := DDS.STATUS_MASK_NONE) return Ref_Access\n is\n Ret : ref_access := new Ref;\n begin\n Ret.Listner := Listner;\n ret.Participant := Participant;\n ret.Publisher := (if Publisher /= null then\n Publisher\n else\n Participant.Get_Implicit_Publisher);\n ret.Subscriber := (if Subscriber /= null then\n Subscriber\n else\n Participant.Get_Implicit_Subscriber);\n\n Ret.Reply_Topic := Ret.Create_Reply_Topic (Reply_Topic_Name, Reply_DataWriter.Treats.Get_Type_Name, Reply_Topic_Qos);\n\n Ret.Request_Topic := Ret.Create_Request_Topic (Request_Topic_Name, Request_DataReader.Treats.Get_Type_Name, Request_Topic_Qos);\n\n ret.Reader := DDS.DataReader_Impl.Ref_Access (ret.Subscriber.Create_DataReader\n (Topic => ret.Request_Topic,\n Qos => Datareader_Qos,\n A_Listener => ret.Reader_Listner'access,\n Mask => Mask));\n\n Ret.Writer := DDS.DataWriter_Impl.Ref_Access (Ret.Publisher.Create_DataWriter\n (A_Topic => Ret.Reply_Topic,\n Qos => Datawriter_Qos,\n A_Listener => Ret.Writer_Listner'Access,\n Mask => Mask));\n Ret.Any_Sample_Cond := Ret.Reader.Create_Readcondition\n (Sample_States => DDS.ANY_SAMPLE_STATE,\n View_States => DDS.ANY_VIEW_STATE,\n Instance_States => DDS.ANY_INSTANCE_STATE);\n Ret.Not_Read_Sample_Cond := Ret.Reader.Create_Readcondition\n (Sample_States => DDS.NOT_READ_SAMPLE_STATE,\n View_States => DDS.ANY_VIEW_STATE,\n Instance_States => DDS.ANY_INSTANCE_STATE);\n return ret;\n exception\n when others =>\n ret.Delete;\n free (ret);\n raise;\n end Create;\n\n ------------\n -- Delete --\n ------------\n\n procedure Delete (Self : in out Ref_Access) is\n begin\n -- pragma Compile_Time_Warning (Standard.True, \"Delete unimplemented\");\n raise Program_Error with \"Unimplemented procedure Delete\";\n end Delete;\n\n ----------------\n -- Send_Reply --\n ----------------\n\n ----------------\n -- Send_Reply --\n ----------------\n\n procedure Send_Reply\n (Self : not null access Ref;\n Reply : Reply_DataWriter.Treats.Data_Type;\n Id : DDS.SampleIdentity_T)\n is\n params : DDS.WriteParams_t;\n begin\n self.send_Sample (Data => Reply , Related_Request_Info => Id, WriteParams => params);\n end Send_Reply;\n\n ---------------------\n -- Receive_Request --\n ---------------------\n\n function Receive_Request\n (Self : not null access Ref;\n Request : in out Request_DataReader.Treats.Data_Type;\n SampleInfo : in out DDS.SampleInfo;\n Timeout : DDS.Duration_T := DDS.DURATION_INFINITE) return DDS.ReturnCode_T\n is\n begin\n return Ret : DDS.ReturnCode_T := DDS.RETCODE_NO_DATA do\n for I of Self.Receive_Request (Min_Reply_Count => 1, Max_Reply_Count => 1, Timeout => Timeout) loop\n if I.Sample_Info.Valid_Data then\n Request_DataReader.Treats.Copy (Request, I.Data.all);\n Copy (SampleInfo, I.Sample_Info.all);\n Ret := DDS.RETCODE_OK;\n end if;\n end loop;\n end return;\n end Receive_Request;\n\n ---------------------\n -- Receive_Request --\n ---------------------\n\n procedure Receive_Request\n (Self : not null access Ref;\n Request : in out Request_DataReader.Treats.Data_Type;\n Info_Seq : in out DDS.SampleInfo;\n Timeout : DDS.Duration_T := DDS.DURATION_INFINITE)\n is\n begin\n Dds.Ret_Code_To_Exception (Self.Receive_Request (Request, Info_Seq, Timeout));\n end Receive_Request;\n\n ---------------------\n -- Receive_Request --\n ---------------------\n\n function Receive_Request\n (Self : not null access Ref; Timeout : DDS.Duration_T)\n return Request_DataReader.Container'class\n is\n begin\n return Request_DataReader.Ref_Access (Self.Reader).Take;\n end Receive_Request;\n\n\n\n ----------------------\n -- Receive_Requests --\n ----------------------\n\n\n ----------------------\n -- Receive_Requests --\n ----------------------\n\n\n ---------------------\n -- Receive_Request --\n ---------------------\n\n function Take_Request\n (Self : not null access Ref;\n Max_Reply_Count : DDS.long := DDS.INFINITE)\n return Request_DataReader.Container'Class is\n begin\n return Self.Get_Request_Data_Reader.Take (Max_Samples => Max_Reply_Count);" + }, + { + "function_def": "procedure On_Offered_Deadline_Missed", + "function_body": "(Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.OfferedDeadlineMissedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Offered_Deadline_Missed (Self.Parent.all'Access, Status);\n end if;\n end On_Offered_Deadline_Missed;\n\n -----------------------\n -- On_Data_Available --\n -----------------------\n\n procedure On_Data_Available\n (Self : not null access DataReader_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Request_Avalible (Self.Parent.all'Access);\n end if;\n end On_Data_Available;\n\n ---------------------------------\n -- On_Offered_Incompatible_Qos --\n ---------------------------------\n\n procedure On_Offered_Incompatible_Qos\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.OfferedIncompatibleQosStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Offered_Incompatible_Qos (Self.Parent.all'Access, Status);\n end if;\n end On_Offered_Incompatible_Qos;\n\n ------------------------\n -- On_Liveliness_Lost --\n ------------------------\n\n procedure On_Liveliness_Lost\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.LivelinessLostStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Liveliness_Lost (Self.Parent.all'Access, Status);\n end if;\n end On_Liveliness_Lost;\n\n ----------------------------\n -- On_Publication_Matched --\n ----------------------------\n\n procedure On_Publication_Matched\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.PublicationMatchedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Publication_Matched (Self.Parent.all'Access, Status);\n end if;\n end On_Publication_Matched;\n\n --------------------------------------\n -- On_Reliable_Writer_Cache_Changed --\n --------------------------------------\n\n procedure On_Reliable_Writer_Cache_Changed\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.ReliableWriterCacheChangedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Reliable_Writer_Cache_Changed (Self.Parent.all'Access, Status);\n end if;\n end On_Reliable_Writer_Cache_Changed;\n\n -----------------------------------------\n -- On_Reliable_Reader_Activity_Changed --\n -----------------------------------------\n\n procedure On_Reliable_Reader_Activity_Changed\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Status : in DDS.ReliableReaderActivityChangedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Reliable_Reader_Activity_Changed (Self.Parent.all'Access, Status);\n end if;\n end On_Reliable_Reader_Activity_Changed;\n\n --------------------------------\n -- On_Destination_Unreachable --\n --------------------------------\n\n procedure On_Destination_Unreachable\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Instance : in DDS.InstanceHandle_T; Locator : in DDS.Locator_T)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Destination_Unreachable (Self.Parent.all'Access, Instance, Locator);\n end if;\n end On_Destination_Unreachable;\n\n ---------------------\n -- On_Data_Request --\n ---------------------\n\n procedure On_Data_Request\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Cookie : in DDS.Cookie_T;\n Request : in out System.Address)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Data_Request (Self.Parent.all'Access, Cookie, Request);\n end if;\n end On_Data_Request;\n\n --------------------\n -- On_Data_Return --\n --------------------\n\n procedure On_Data_Return\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Arg : System.Address;\n Cookie : in DDS.Cookie_T)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Data_Return (Self.Parent.all'Access, Arg, Cookie);\n end if;\n end On_Data_Return;\n\n -----------------------\n -- On_Sample_Removed --\n -----------------------\n\n procedure On_Sample_Removed\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Cookie : in DDS.Cookie_T)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Sample_Removed (Self.Parent.all'Access, Cookie);\n end if;\n end On_Sample_Removed;\n\n --------------------------\n -- On_Instance_Replaced --\n --------------------------\n\n procedure On_Instance_Replaced\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Instance : in DDS.InstanceHandle_T)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Instance_Replaced (Self.Parent.all'Access, Instance);\n end if;\n end On_Instance_Replaced;\n\n -----------------------------------\n -- On_Application_Acknowledgment --\n -----------------------------------\n\n procedure On_Application_Acknowledgment\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Info : in DDS.AcknowledgmentInfo)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Application_Acknowledgment (Self.Parent.all'Access, Info);\n end if;\n end On_Application_Acknowledgment;\n\n ---------------------------------\n -- On_Service_Request_Accepted --\n ---------------------------------\n\n procedure On_Service_Request_Accepted\n (Self : not null access DataReader_Listner;\n Writer : access DDS.DataWriter.Ref'Class;\n Info : in DDS.ServiceRequestAcceptedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Service_Request_Accepted (Self.Parent.all'Access, Info);\n end if;\n end On_Service_Request_Accepted;\n\n ----------------------------------\n -- On_Requested_Deadline_Missed --\n ----------------------------------\n\n procedure On_Requested_Deadline_Missed\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.RequestedDeadlineMissedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Requested_Deadline_Missed (Self.Parent.all'Access, Status);\n end if;\n end On_Requested_Deadline_Missed;\n\n -----------------------------------\n -- On_Requested_Incompatible_Qos --\n -----------------------------------\n\n procedure On_Requested_Incompatible_Qos\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.RequestedIncompatibleQosStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Requested_Incompatible_Qos (Self.Parent.all'Access, Status);\n end if;\n end On_Requested_Incompatible_Qos;\n\n ------------------------\n -- On_Sample_Rejected --\n ------------------------\n\n procedure On_Sample_Rejected\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.SampleRejectedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Sample_Rejected (Self.Parent.all'Access, Status);\n end if;\n end On_Sample_Rejected;\n\n ---------------------------\n -- On_Liveliness_Changed --\n ---------------------------\n\n procedure On_Liveliness_Changed\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.LivelinessChangedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Liveliness_Changed (Self.Parent.all'Access, Status);\n end if;\n end On_Liveliness_Changed;\n\n -----------------------\n -- On_Data_Available --\n -----------------------\n\n -- procedure On_Data_Available\n -- (Self : not null access DataWriter_Listner;\n -- The_Reader : in DDS.DataReaderListener.DataReader_Access)\n -- is\n -- begin\n -- if Self.Parent.Listner /= null then\n -- Self.Parent.Listner.On_Request_Avalible (Self.all'Access);\n -- end if;\n -- end On_Data_Available;\n\n -----------------------------\n -- On_Subscription_Matched --\n -----------------------------\n\n procedure On_Subscription_Matched\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.SubscriptionMatchedStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Subscription_Matched (Self.Parent.all'Access, Status);\n end if;\n end On_Subscription_Matched;\n\n --------------------\n -- On_Sample_Lost --\n --------------------\n\n procedure On_Sample_Lost\n (Self : not null access DataWriter_Listner;\n The_Reader : in DDS.DataReaderListener.DataReader_Access;\n Status : in DDS.SampleLostStatus)\n is\n begin\n if Self.Parent.Listner /= null then\n Self.Parent.Listner.On_Sample_Lost (Self.Parent.all'Access, Status);\n end if;\n end On_Sample_Lost;\n procedure Send_Sample (Self : not null access Ref;\n Data : Reply_DataWriter.Treats.Data_Type;\n Related_Request_Info : DDS.SampleIdentity_T;\n WriteParams : in out DDS.WriteParams_T) is\n begin\n Self.Configure_Params_For_Reply (WriteParams, Related_Request_Info);\n Reply_DataWriter.Ref_Access (Self.Writer).Write_W_Params (Data, WriteParams);" + }, + { + "function_def": "function To_Bits is new Ada.Unchecked_Conversion (Address, Bits);", + "function_body": "LE : constant := Standard'Default_Bit_Order;\n -- Static constant set to 0 for big-endian, 1 for little-endian\n\n -- The following is an array of masks used to mask the final byte, either\n -- at the high end (big-endian case) or the low end (little-endian case).\n\n Masks : constant array (1 .. 7) of Packed_Byte := (\n (1 - LE) * 2#1000_0000# + LE * 2#0000_0001#,\n (1 - LE) * 2#1100_0000# + LE * 2#0000_0011#,\n (1 - LE) * 2#1110_0000# + LE * 2#0000_0111#,\n (1 - LE) * 2#1111_0000# + LE * 2#0000_1111#,\n (1 - LE) * 2#1111_1000# + LE * 2#0001_1111#,\n (1 - LE) * 2#1111_1100# + LE * 2#0011_1111#,\n (1 - LE) * 2#1111_1110# + LE * 2#0111_1111#);\n\n -----------------------\n -- Local Subprograms --\n -----------------------\n\n procedure Raise_Error;\n -- Raise Constraint_Error, complaining about unequal lengths\n\n -------------\n -- Bit_And --\n -------------\n\n procedure Bit_And\n (Left : Address;\n Llen : Natural;\n Right : Address;\n Rlen : Natural;\n Result : Address)\n is\n-- LeftB : constant Bits := To_Bits (Left);\n-- RightB : constant Bits := To_Bits (Right);\n-- ResultB : constant Bits := To_Bits (Result);\n-- pragma Unreferenced (Llen);\n pragma Unreferenced (Rlen);\n begin\n -- for the time being we don't provide dynamic range checks\n -- if Llen /= Rlen then\n -- Raise_Error;\n -- end if;\n\n -- this routine is called only for 1, 2, or 4 byte lengths.\n -- The Rlen/Llen parameter is either, 8, 16, or 32.\n if Llen = 8 then\n declare\n use Interfaces;\n Left_Byte : Unsigned_8;\n for Left_Byte'Address use Left;\n Right_Byte : Unsigned_8;\n for Right_Byte'Address use Right;\n Result_Byte : Unsigned_8;\n for Result_Byte'Address use Result;\n begin\n Result_Byte := Left_Byte and Right_Byte;" + }, + { + "function_def": "function To_Bits is new Ada.Unchecked_Conversion (Address, Bits);", + "function_body": "LE : constant := Standard'Default_Bit_Order;\n -- Static constant set to 0 for big-endian, 1 for little-endian\n\n -- The following is an array of masks used to mask the final byte, either\n -- at the high end (big-endian case) or the low end (little-endian case).\n\n Masks : constant array (1 .. 7) of Packed_Byte := (\n (1 - LE) * 2#1000_0000# + LE * 2#0000_0001#,\n (1 - LE) * 2#1100_0000# + LE * 2#0000_0011#,\n (1 - LE) * 2#1110_0000# + LE * 2#0000_0111#,\n (1 - LE) * 2#1111_0000# + LE * 2#0000_1111#,\n (1 - LE) * 2#1111_1000# + LE * 2#0001_1111#,\n (1 - LE) * 2#1111_1100# + LE * 2#0011_1111#,\n (1 - LE) * 2#1111_1110# + LE * 2#0111_1111#);\n\n -----------------------\n -- Local Subprograms --\n -----------------------\n\n procedure Raise_Error;\n -- Raise Constraint_Error, complaining about unequal lengths\n\n -------------\n -- Bit_And --\n -------------\n\n procedure Bit_And\n (Left : Address;\n Llen : Natural;\n Right : Address;\n Rlen : Natural;\n Result : Address)\n is\n-- LeftB : constant Bits := To_Bits (Left);\n-- RightB : constant Bits := To_Bits (Right);\n-- ResultB : constant Bits := To_Bits (Result);\n-- pragma Unreferenced (Llen);\n pragma Unreferenced (Rlen);\n begin\n -- for the time being we don't provide dynamic range checks\n -- if Llen /= Rlen then\n -- Raise_Error;\n -- end if;\n\n -- this routine is called only for 1, 2, or 4 byte lengths.\n -- The Rlen/Llen parameter is either, 8, 16, or 32.\n if Llen = 8 then\n declare\n use Interfaces;\n Left_Byte : Unsigned_8;\n for Left_Byte'Address use Left;\n Right_Byte : Unsigned_8;\n for Right_Byte'Address use Right;\n Result_Byte : Unsigned_8;\n for Result_Byte'Address use Result;\n begin\n Result_Byte := Left_Byte and Right_Byte;" + }, + { + "function_def": "function To_Stack_Pool is new", + "function_body": "Ada.Unchecked_Conversion (Address, Stk_Pool_Access);\n\n pragma Warnings (Off);\n function To_Global_Ptr is new\n Ada.Unchecked_Conversion (Address, SS_Stack_Ptr);\n pragma Warnings (On);\n -- Suppress aliasing warning since the pointer we return will\n -- be the only access to the stack.\n\n Local_Stk_Address : System.Address;\n\n begin\n Num_Of_Assigned_Stacks := Num_Of_Assigned_Stacks + 1;\n\n Local_Stk_Address :=\n To_Stack_Pool\n (Default_Sized_SS_Pool) (Num_Of_Assigned_Stacks)'Address;\n Stack := To_Global_Ptr (Local_Stk_Address);" + }, + { + "function_def": "procedure Main is", + "function_body": "package Positive_IO is new Ada.Text_IO.Integer_IO (Positive);\n\n type Image_Access is access all Bitmaps.RGB.Image;\n package Image_Problem is new Problem (Image_Access);\n\n function Opt_Iterations return Positive is\n Result : Positive := 1000000;\n Last : Positive;\n begin\n if Ada.Environment_Variables.Exists (\"ANNEALING_ITERATIONS\") then\n Positive_IO.Get\n (From => Ada.Environment_Variables.Value (\"ANNEALING_ITERATIONS\"),\n Item => Result, Last => Last);\n end if;\n return Result;\n end Opt_Iterations;\n\n function Opt_Temperature return Float is\n Result : Float := 100.0;\n Last : Positive;\n begin\n if Ada.Environment_Variables.Exists (\"ANNEALING_TEMPERATURE\") then\n Ada.Float_Text_IO.Get\n (From => Ada.Environment_Variables.Value (\"ANNEALING_TEMPERATURE\"),\n Item => Result, Last => Last);\n end if;\n return Result;\n end Opt_Temperature;\n\n function Opt_Size return Positive is\n Result : Positive := 64;\n Last : Positive;\n begin\n if Ada.Environment_Variables.Exists(\"ANNEALING_SIZE\") then\n Positive_IO.Get\n (From => Ada.Environment_Variables.Value(\"ANNEALING_SIZE\"),\n Item => Result, Last => Last);\n end if;\n return Result;\n end Opt_Size;\n\n Bitmap_Size : constant Positive := Opt_Size;\n\n B : aliased Bitmaps.RGB.Image (Bitmap_Size, Bitmap_Size);\n S : Image_Problem.State;\nbegin\n ImageOps.Noise (B);\n\n S.Img := B'Access;\n S.E := ImageOps.Adj_Distance_Sum (B);\n Image_Problem.Roll (S);\n S.Visited := False;\n\n declare\n M : Image_Problem.Opt.Minimization := Image_Problem.Opt.Minimize (S);\n Sched : Simulated_Annealing.Scheduler :=\n Simulated_Annealing.Exponential (Opt_Iterations, Opt_Temperature);\n Improved : Boolean := False;\n begin\n while Image_Problem.Opt.Step (M, Sched, Improved) loop\n if Improved then\n Ada.Text_IO.Put (\"T = \");\n Ada.Float_Text_IO.Put (Simulated_Annealing.Temperature (Sched));\n Ada.Text_IO.Put (\", E = \");\n Ada.Long_Integer_Text_IO.Put\n (Image_Problem.Opt.Minimum (M).E, Width => 0);\n Ada.Text_IO.New_Line;\n\n if Ada.Command_Line.Argument_Count > 0 then\n declare\n CF : RAII.Controlled_File;\n begin\n Ada.Text_IO.Open\n (CF.File, Ada.Text_IO.Out_File,\n Ada.Command_Line.Argument (1));\n Bitmaps.IO.Write_PPM_P6\n (Ada.Text_IO.Text_Streams.Stream (CF.File), B);" + }, + { + "function_def": "function New_FlagRegister return FlagRegister; -- ./registers.hpp:16", + "function_body": "pragma CPP_Constructor (New_FlagRegister, \"_ZN12FlagRegisterC1Ev\");\n\n procedure setFlag (this : access FlagRegister; the_flag : Flag); -- ./registers.hpp:18\n pragma Import (CPP, setFlag, \"_ZN12FlagRegister7setFlagE4Flag\");\n\n procedure unsetFlag (this : access FlagRegister; the_flag : Flag); -- ./registers.hpp:19\n pragma Import (CPP, unsetFlag, \"_ZN12FlagRegister9unsetFlagE4Flag\");\n\n function getFlag (this : access FlagRegister; the_flag : Flag) return Extensions.bool; -- ./registers.hpp:20\n pragma Import (CPP, getFlag, \"_ZN12FlagRegister7getFlagE4Flag\");\n\n function get_value (this : access FlagRegister) return unsigned_char; -- ./registers.hpp:21\n pragma Import (CPP, get_value, \"_ZN12FlagRegister9get_valueEv\");\n\n procedure set_value (this : access FlagRegister; val : unsigned_char); -- ./registers.hpp:22\n pragma Import (CPP, set_value, \"_ZN12FlagRegister9set_valueEh\");" + }, + { + "function_def": "procedure disableIME (this : access Processor); -- ./processor.hpp:81", + "function_body": "pragma Import (CPP, disableIME, \"_ZN9Processor10disableIMEEv\");\n\n procedure enableIMEDelay (this : access Processor); -- ./processor.hpp:84\n pragma Import (CPP, enableIMEDelay, \"_ZN9Processor14enableIMEDelayEv\");\n\n procedure HALT (this : access Processor); -- ./processor.hpp:95\n pragma Import (CPP, HALT, \"_ZN9Processor4HALTEv\");\n\n procedure STOP (this : access Processor); -- ./processor.hpp:103\n pragma Import (CPP, STOP, \"_ZN9Processor4STOPEv\");\n\n procedure push_word (this : access Processor; word : word_operations_hpp.uint16_t); -- ./processor.hpp:107\n pragma Import (CPP, push_word, \"_ZN9Processor9push_wordEt\");\n\n function pop_word (this : access Processor) return word_operations_hpp.uint16_t; -- ./processor.hpp:108\n pragma Import (CPP, pop_word, \"_ZN9Processor8pop_wordEv\");\n\n function handleInterrupts (this : access Processor) return int; -- ./processor.hpp:112\n pragma Import (CPP, handleInterrupts, \"_ZN9Processor16handleInterruptsEv\");\n\n procedure setupInterrupt (this : access Processor; inter : unsigned); -- ./processor.hpp:115\n pragma Import (CPP, setupInterrupt, \"_ZN9Processor14setupInterruptEj\");\n\n function execCurrentInstruction (this : access Processor) return int; -- ./processor.hpp:117\n pragma Import (CPP, execCurrentInstruction, \"_ZN9Processor22execCurrentInstructionEv\");\n\n procedure fetchNextInstruction (this : access Processor); -- ./processor.hpp:119\n pragma Import (CPP, fetchNextInstruction, \"_ZN9Processor20fetchNextInstructionEv\");\n\n procedure operator_as (this : access Processor; arg2 : access constant Processor); -- ./processor.hpp:122\n pragma Import (CPP, operator_as, \"_ZN9ProcessoraSERKS_\");\n\n INTERRUPT_VECTOR : aliased word_operations_hpp.uint16_t; -- ./processor.hpp:43\n pragma Import (CPP, INTERRUPT_VECTOR, \"_ZN9Processor16INTERRUPT_VECTORE\");" + }, + { + "function_def": "function New_FlagRegister return FlagRegister; -- ./registers.hpp:16", + "function_body": "pragma CPP_Constructor (New_FlagRegister, \"_ZN12FlagRegisterC1Ev\");\n\n procedure setFlag (this : access FlagRegister; the_flag : Flag); -- ./registers.hpp:18\n pragma Import (CPP, setFlag, \"_ZN12FlagRegister7setFlagE4Flag\");\n\n procedure unsetFlag (this : access FlagRegister; the_flag : Flag); -- ./registers.hpp:19\n pragma Import (CPP, unsetFlag, \"_ZN12FlagRegister9unsetFlagE4Flag\");\n\n function getFlag (this : access FlagRegister; the_flag : Flag) return Extensions.bool; -- ./registers.hpp:20\n pragma Import (CPP, getFlag, \"_ZN12FlagRegister7getFlagE4Flag\");\n\n function get_value (this : access FlagRegister) return unsigned_char; -- ./registers.hpp:21\n pragma Import (CPP, get_value, \"_ZN12FlagRegister9get_valueEv\");\n\n procedure set_value (this : access FlagRegister; val : unsigned_char); -- ./registers.hpp:22\n pragma Import (CPP, set_value, \"_ZN12FlagRegister9set_valueEh\");" + }, + { + "function_def": "procedure disableIME (this : access Processor); -- ./processor.hpp:81", + "function_body": "pragma Import (CPP, disableIME, \"_ZN9Processor10disableIMEEv\");\n\n procedure enableIMEDelay (this : access Processor); -- ./processor.hpp:84\n pragma Import (CPP, enableIMEDelay, \"_ZN9Processor14enableIMEDelayEv\");\n\n procedure HALT (this : access Processor); -- ./processor.hpp:95\n pragma Import (CPP, HALT, \"_ZN9Processor4HALTEv\");\n\n procedure STOP (this : access Processor); -- ./processor.hpp:103\n pragma Import (CPP, STOP, \"_ZN9Processor4STOPEv\");\n\n procedure push_word (this : access Processor; word : word_operations_hpp.uint16_t); -- ./processor.hpp:107\n pragma Import (CPP, push_word, \"_ZN9Processor9push_wordEt\");\n\n function pop_word (this : access Processor) return word_operations_hpp.uint16_t; -- ./processor.hpp:108\n pragma Import (CPP, pop_word, \"_ZN9Processor8pop_wordEv\");\n\n function handleInterrupts (this : access Processor) return int; -- ./processor.hpp:112\n pragma Import (CPP, handleInterrupts, \"_ZN9Processor16handleInterruptsEv\");\n\n procedure setupInterrupt (this : access Processor; inter : unsigned); -- ./processor.hpp:115\n pragma Import (CPP, setupInterrupt, \"_ZN9Processor14setupInterruptEj\");\n\n function execCurrentInstruction (this : access Processor) return int; -- ./processor.hpp:117\n pragma Import (CPP, execCurrentInstruction, \"_ZN9Processor22execCurrentInstructionEv\");\n\n procedure fetchNextInstruction (this : access Processor); -- ./processor.hpp:119\n pragma Import (CPP, fetchNextInstruction, \"_ZN9Processor20fetchNextInstructionEv\");\n\n procedure operator_as (this : access Processor; arg2 : access constant Processor); -- ./processor.hpp:122\n pragma Import (CPP, operator_as, \"_ZN9ProcessoraSERKS_\");\n\n INTERRUPT_VECTOR : aliased word_operations_hpp.uint16_t; -- ./processor.hpp:43\n pragma Import (CPP, INTERRUPT_VECTOR, \"_ZN9Processor16INTERRUPT_VECTORE\");" + }, + { + "function_def": "procedure Convert_Card_Identification_Data_Register", + "function_body": "(W0, W1, W2, W3 : UInt32;\n Res : out Card_Identification_Data_Register);\n -- Convert the R2 reply to CID\n\n procedure Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3 : UInt32;\n Card_Type : Supported_SD_Memory_Cards;\n CSD : out Card_Specific_Data_Register);\n -- Convert the R2 reply to CSD\n\n procedure Convert_SDCard_Configuration_Register\n (W0, W1 : UInt32;\n SCR : out SDCard_Configuration_Register);\n -- Convert W0 (MSB) / W1 (LSB) to SCR.\n\n function Compute_Card_Capacity\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt64;\n -- Compute the card capacity (in bytes) from the CSD\n\n function Compute_Card_Block_Size\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt32;\n -- Compute the card block size (in bytes) from the CSD.\n\n function Get_Transfer_Rate\n (CSD : Card_Specific_Data_Register) return Natural;\n -- Compute transfer rate from CSD\n\n function Swap32 (Val : UInt32) return UInt32 with Inline_Always;\n\n function BE32_To_Host (Val : UInt32) return UInt32 with Inline_Always;\n\n -- Swap bytes in a word\n ------------\n -- Swap32 --\n ------------\n\n function Swap32 (Val : UInt32) return UInt32 is\n begin\n return Shift_Left (Val and 16#00_00_00_ff#, 24)\n or Shift_Left (Val and 16#00_00_ff_00#, 8)\n or Shift_Right (Val and 16#00_ff_00_00#, 8)\n or Shift_Right (Val and 16#ff_00_00_00#, 24);\n end Swap32;\n\n ------------------\n -- BE32_To_Host --\n ------------------\n\n function BE32_To_Host (Val : UInt32) return UInt32 is\n use System;\n begin\n if Default_Bit_Order = Low_Order_First then\n return Swap32 (Val);\n else\n return Val;\n end if;\n end BE32_To_Host;\n\n ---------------------------------\n -- Card_Identification_Process --\n ---------------------------------\n\n procedure Card_Identification_Process\n (This : in out SDMMC_Driver'Class;\n Info : out Card_Information;\n Status : out SD_Error)\n is\n Rsp : UInt32;\n W0, W1, W2, W3 : UInt32;\n Rca : UInt32;\n\n begin\n -- Reset controller\n This.Reset (Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD0: Sets the SDCard state to Idle\n Send_Cmd (This, Go_Idle_State, 0, Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD8: IF_Cond, voltage supplied: 0x1 (2.7V - 3.6V)\n -- It is mandatory for the host compliant to Physical Spec v2.00\n -- to send CMD8 before ACMD41\n Send_Cmd (This, Send_If_Cond, 16#1a5#, Status);\n\n if Status = OK then\n -- at least SD Card 2.0\n Info.Card_Type := STD_Capacity_SD_Card_v2_0;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and 16#fff#) /= 16#1a5# then\n -- Bad voltage or bad pattern.\n Status := Error;\n return;\n end if;\n else\n -- If SD Card, then it's v1.1\n Info.Card_Type := STD_Capacity_SD_Card_V1_1;\n end if;\n\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD55: APP_CMD\n -- This is done manually to handle error (this command is not\n -- supported by mmc).\n Send_Cmd (This, Cmd_Desc (App_Cmd), 0, Status);\n\n if Status /= OK then\n if Status = Command_Timeout_Error\n and then I = 1\n and then Info.Card_Type = STD_Capacity_SD_Card_V1_1\n then\n -- Not an SDCard. Suppose MMC.\n Info.Card_Type := Multimedia_Card;\n exit;\n end if;\n return;\n end if;\n\n -- ACMD41: SD_SEND_OP_COND (no crc check)\n -- Arg: HCS=1, XPC=0, S18R=0\n Send_Cmd\n (This, Acmd_Desc (SD_App_Send_Op_Cond), 16#40ff_0000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_High_Capacity) = SD_OCR_High_Capacity then\n Info.Card_Type := High_Capacity_SD_Card;\n end if;\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n\n else\n Status := OK;\n exit;\n end if;\n end loop;\n\n if Status = Command_Timeout_Error\n and then Info.Card_Type = Multimedia_Card\n then\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD1: SEND_OP_COND query voltage\n Send_Cmd (This, Cmd_Desc (Send_Op_Cond), 16#00ff_8000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n else\n if (Rsp and 16#00ff_8000#) /= 16#00ff_8000# then\n Status := Error;\n return;\n end if;\n Status := OK;\n exit;\n end if;\n end loop;\n end if;\n\n if Status /= OK then\n return;\n end if;\n\n -- TODO: Switch voltage\n\n -- CMD2: ALL_SEND_CID (136 bits)\n Send_Cmd (This, All_Send_CID, 0, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Identification_Data_Register (W0, W1, W2, W3, Info.SD_CID);\n\n -- CMD3: SEND_RELATIVE_ADDR\n case Info.Card_Type is\n when Multimedia_Card =>\n Rca := 16#01_0000#;\n when others =>\n Rca := 0;\n end case;\n\n Send_Cmd (This, Send_Relative_Addr, Rca, Status);\n if Status /= OK then\n return;\n end if;\n case Info.Card_Type is\n when Multimedia_Card =>\n null;\n when others =>\n Read_Rsp48 (This, Rsp);\n Rca := Rsp and 16#ffff_0000#;\n if (Rsp and 16#e100#) /= 16#0100# then\n return;\n end if;\n end case;\n Info.RCA := UInt16 (Shift_Right (Rca, 16));\n\n -- Switch to 25Mhz\n case Info.Card_Type is\n when Multimedia_Card =>\n Set_Clock (This, Get_Transfer_Rate (Info.SD_CSD));\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Set_Clock (This, 25_000_000);\n when others =>\n -- Not yet handled\n raise Program_Error;\n end case;\n\n -- CMD10: SEND_CID (136 bits)\n Send_Cmd (This, Send_CID, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD9: SEND_CSD\n Send_Cmd (This, Send_CSD, Rca, Status);\n if Status /= OK then\n return;\n end if;\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3, Info.Card_Type, Info.SD_CSD);\n Info.Card_Capacity :=\n Compute_Card_Capacity (Info.SD_CSD, Info.Card_Type);\n Info.Card_Block_Size :=\n Compute_Card_Block_Size (Info.SD_CSD, Info.Card_Type);\n\n -- CMD7: SELECT\n Send_Cmd (This, Select_Card, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD13: STATUS\n Send_Cmd (This, Send_Status, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Bus size\n case Info.Card_Type is\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Send_ACmd (This, SD_App_Set_Bus_Width, Info.RCA, 2, Status);\n if Status /= OK then\n return;\n else\n Set_Bus_Size (This, Wide_Bus_4B);\n end if;\n when others =>\n null;\n end case;\n\n if (Info.SD_CSD.Card_Command_Class and 2**10) /= 0 then\n -- Class 10 supported.\n declare\n subtype Switch_Status_Type is UInt32_Array (1 .. 16);\n\n Switch_Status : Switch_Status_Type;\n begin\n -- CMD6\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#00_fffff0#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Handle endianness\n for I in Switch_Status'Range loop\n Switch_Status (I) := BE32_To_Host (Switch_Status (I));\n end loop;\n\n -- Switch tp 50Mhz if possible.\n if (Switch_Status (4) and 2**(16 + 1)) /= 0 then\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#80_fffff1#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Switch to 50Mhz\n Set_Clock (This, 50_000_000);\n end if;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (HALFS.Status_Code, Status_Code);", + "function_body": "function Convert is new Ada.Unchecked_Conversion (File_Mode, HALFS.File_Mode);\n function Convert is new Ada.Unchecked_Conversion (File_Size, HALFS.File_Size);\n function Convert is new Ada.Unchecked_Conversion (HALFS.File_Size, File_Size);\n function Convert is new Ada.Unchecked_Conversion (Seek_Mode, HALFS.Seek_Mode);\n\n type Mount_Record is record\n Is_Free : Boolean := True;\n Name : String (1 .. MAX_MOUNT_NAME_LENGTH);\n Name_Len : Positive;\n FS : Any_Filesystem_Driver;\n end record;\n\n subtype Mount_Index is Integer range 0 .. MAX_MOUNT_POINTS;\n subtype Valid_Mount_Index is Mount_Index range 1 .. MAX_MOUNT_POINTS;\n type Mount_Array is array (Valid_Mount_Index) of Mount_Record;\n\n type VFS_Directory_Handle is new Directory_Handle with record\n Is_Free : Boolean := True;\n Mount_Id : Mount_Index;\n end record;\n\n overriding function Get_FS\n (Dir : VFS_Directory_Handle) return Any_Filesystem_Driver;\n -- Return the filesystem the handle belongs to.\n\n overriding function Read\n (Dir : in out VFS_Directory_Handle;\n Handle : out Any_Node_Handle) return HALFS.Status_Code;\n -- Reads the next directory entry. If no such entry is there, an error\n -- code is returned in Status.\n\n overriding procedure Reset (Dir : in out VFS_Directory_Handle);\n -- Resets the handle to the first node\n\n overriding procedure Close (Dir : in out VFS_Directory_Handle);\n -- Closes the handle, and free the associated resources.\n\n function Open\n (Path : String;\n Handle : out Any_Directory_Handle)\n return Status_Code;\n\n function Open\n (Path : String;\n Mode : File_Mode;\n Handle : out Any_File_Handle)\n return Status_Code;\n\n Mount_Points : Mount_Array;\n\n Handles : array (1 .. 2) of aliased VFS_Directory_Handle;\n\n function Name (Point : Mount_Record) return Mount_Path;\n procedure Set_Name (Point : in out Mount_Record;\n Path : Mount_Path);\n procedure Split\n (Path : String;\n FS : out Any_Filesystem_Driver;\n Start_Index : out Natural);\n\n ----------\n -- Open --\n ----------\n\n function Open\n (File : in out File_Descriptor;\n Name : String;\n Mode : File_Mode)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Is_Open (File) then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Mode, File.Handle);\n\n if Ret /= OK then\n File.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (File : in out File_Descriptor) is\n begin\n if File.Handle /= null then\n File.Handle.Close;\n File.Handle := null;\n end if;\n end Close;\n\n -------------\n -- Is_Open --\n -------------\n\n function Is_Open\n (File : File_Descriptor)\n return Boolean\n is (File.Handle /= null);\n\n -----------\n -- Flush --\n -----------\n\n function Flush\n (File : File_Descriptor)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Flush);\n else\n return Invalid_Parameter;\n end if;\n end Flush;\n\n ----------\n -- Size --\n ----------\n\n function Size\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle = null then\n return 0;\n else\n return Convert (File.Handle.Size);\n end if;\n end Size;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Read (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n function Write\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Write (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Write;\n\n ------------\n -- Offset --\n ------------\n\n function Offset\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Offset);\n else\n return 0;\n end if;\n end Offset;\n\n ----------\n -- Seek --\n ----------\n\n function Seek\n (File : in out File_Descriptor;\n Origin : Seek_Mode;\n Amount : in out File_Size)\n return Status_Code\n is\n Ret : Status_Code;\n HALFS_Amount : HALFS.File_Size;\n begin\n if File.Handle /= null then\n HALFS_Amount := Convert (Amount);\n Ret := Convert (File.Handle.Seek (Convert (Origin), HALFS_Amount));\n Amount := Convert (HALFS_Amount);\n return Ret;\n else\n return Invalid_Parameter;\n end if;\n end Seek;\n\n -------------------\n -- Generic_Write --\n -------------------\n\n function Generic_Write\n (File : File_Descriptor;\n Value : T)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Write (Value'Address, T'Size / 8));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Write;\n\n ------------------\n -- Generic_Read --\n ------------------\n\n function Generic_Read\n (File : File_Descriptor;\n Value : out T)\n return Status_Code\n is\n L : HALFS.File_Size := T'Size / 8;\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Read (Value'Address, L));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Read;\n\n ----------\n -- Open --\n ----------\n\n function Open\n (Dir : in out Directory_Descriptor;\n Name : String)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Dir.Handle /= null then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Dir.Handle);\n\n if Ret /= OK then\n Dir.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (Dir : in out Directory_Descriptor) is\n begin\n if Dir.Handle /= null then\n Dir.Handle.Close;\n end if;\n end Close;\n\n ----------\n -- Read --\n ----------\n\n function Read (Dir : in out Directory_Descriptor)\n return Directory_Entry\n is\n Node : Any_Node_Handle;\n Status : Status_Code;\n begin\n if Dir.Handle = null then\n return Invalid_Dir_Entry;\n end if;\n\n Status := Convert (Dir.Handle.Read (Node));\n if Status /= OK then\n return Invalid_Dir_Entry;\n end if;\n\n declare\n Name : constant String := Node.Basename;\n Ret : Directory_Entry (Name_Length => Name'Length);\n begin\n Ret.Name := Name;\n Ret.Subdirectory := Node.Is_Subdirectory;\n Ret.Read_Only := Node.Is_Read_Only;\n Ret.Hidden := Node.Is_Hidden;\n Ret.Symlink := Node.Is_Symlink;\n Ret.Size := Convert (Node.Size);\n Node.Close;\n return Ret;" + }, + { + "function_def": "function To_Data is new Ada.Unchecked_Conversion", + "function_body": "(FAT_Directory_Entry, Entry_Data);\n function To_Data is new Ada.Unchecked_Conversion\n (VFAT_Directory_Entry, Entry_Data);\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index;\n -- Finds a sequence of deleted entries that can fit Num_Entries.\n -- Returns the first entry of this sequence\n\n --------------\n -- Set_Size --\n --------------\n\n procedure Set_Size\n (E : in out FAT_Node;\n Size : FAT_File_Size)\n is\n begin\n if E.Size /= Size then\n E.Size := Size;\n E.Is_Dirty := True;\n end if;\n end Set_Size;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (Parent : FAT_Node;\n Filename : FAT_Name;\n DEntry : out FAT_Node) return Status_Code\n is\n -- We use a copy of the handle, so as not to touch the state of initial\n -- handle\n Status : Status_Code;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Parent.FS.Cluster_To_Block (Cluster);\n Index : Entry_Index := 0;\n\n begin\n loop\n Status := Next_Entry\n (FS => Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Index,\n DEntry => DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Long_Name (DEntry) = Filename or else\n (DEntry.L_Name.Len = 0 and then Short_Name (DEntry) = Filename)\n then\n return OK;\n end if;\n end loop;\n end Find;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (FS : in out FAT_Filesystem;\n Path : String;\n DEntry : out FAT_Node) return Status_Code\n is\n Status : Status_Code;\n Idx : Natural; -- Idx is used to walk through the Path\n Token : FAT_Name;\n\n begin\n DEntry := Root_Entry (FS);\n\n -- Looping through the Path. We start at 2 as we ignore the initial '/'\n Idx := Path'First + 1;\n\n while Idx <= Path'Last loop\n Token.Len := 0;\n\n for J in Idx .. Path'Last loop\n if Path (J) = '/' then\n exit;\n end if;\n\n Token.Len := Token.Len + 1;\n Token.Name (Token.Len) := Path (J);\n end loop;\n\n Idx := Idx + Token.Len + 1;\n\n Status := Find (DEntry, Token, DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Idx < Path'Last then\n -- Intermediate entry: needs to be a directory\n if not Is_Subdirectory (DEntry) then\n return No_Such_Path;\n end if;\n end if;\n end loop;\n\n return OK;\n end Find;\n\n ------------------\n -- Update_Entry --\n ------------------\n\n function Update_Entry\n (Parent : FAT_Node;\n Value : in out FAT_Node) return Status_Code\n is\n subtype Entry_Block is Block (1 .. 32);\n function To_Block is new\n Ada.Unchecked_Conversion (FAT_Directory_Entry, Entry_Block);\n function To_Entry is new\n Ada.Unchecked_Conversion (Entry_Block, FAT_Directory_Entry);\n\n Ent : FAT_Directory_Entry;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Offset : FAT_File_Size := FAT_File_Size (Value.Index) * 32;\n Block_Off : Natural;\n Block : Block_Offset;\n Ret : Status_Code;\n\n begin\n if not Value.Is_Dirty then\n return OK;\n end if;\n\n while Offset > Parent.FS.Cluster_Size loop\n Cluster := Parent.FS.Get_FAT (Cluster);\n Offset := Offset - Parent.FS.Cluster_Size;\n end loop;\n\n Block := Block_Offset (Offset / Parent.FS.Block_Size);\n Block_Off := Natural (Offset mod Parent.FS.Block_Size);\n\n Ret := Parent.FS.Ensure_Block\n (Parent.FS.Cluster_To_Block (Cluster) + Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n Ent := To_Entry (Parent.FS.Window (Block_Off .. Block_Off + 31));\n\n -- For now only the size can be modified, so just apply this\n -- modification\n Ent.Size := Value.Size;\n Value.Is_Dirty := False;\n\n Parent.FS.Window (Block_Off .. Block_Off + 31) := To_Block (Ent);\n Ret := Parent.FS.Write_Window;\n\n return Ret;\n end Update_Entry;\n\n ----------------\n -- Root_Entry --\n ----------------\n\n function Root_Entry (FS : in out FAT_Filesystem) return FAT_Node\n is\n Ret : FAT_Node;\n begin\n Ret.FS := FS'Unchecked_Access;\n Ret.Attributes := (Subdirectory => True,\n others => False);\n Ret.Is_Root := True;\n Ret.L_Name := (Name => (others => ' '),\n Len => 0);\n if FS.Version = FAT16 then\n Ret.Start_Cluster := 0;\n else\n Ret.Start_Cluster := FS.Root_Dir_Cluster;\n end if;\n Ret.Index := 0;\n\n return Ret;\n end Root_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Directory_Entry) return Status_Code\n is\n subtype Entry_Data is Block (1 .. 32);\n function To_Entry is new Ada.Unchecked_Conversion\n (Entry_Data, FAT_Directory_Entry);\n\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n if Current_Index = 16#FFFF# then\n return No_More_Entries;\n end if;\n\n if Current_Cluster = 0 and then FS.Version = FAT16 then\n if Current_Index >\n Entry_Index (FS.FAT16_Root_Dir_Num_Entries)\n then\n return No_More_Entries;\n else\n Block_Off :=\n Natural (FAT_File_Size (Current_Index * 32) mod\n FS.Block_Size);\n Current_Block :=\n FS.Root_Dir_Area +\n Block_Offset\n (FAT_File_Size (Current_Index * 32) / FS.Block_Size);\n end if;\n\n else\n Block_Off := Natural\n (FAT_File_Size (Current_Index * 32) mod FS.Block_Size);\n\n -- Check if we're on a block boundare\n if Unsigned_32 (Block_Off) = 0 and then Current_Index /= 0 then\n Current_Block := Current_Block + 1;\n end if;\n\n -- Check if we're on the boundary of a new cluster\n if Current_Block - FS.Cluster_To_Block (Current_Cluster)\n = FS.Blocks_Per_Cluster\n then\n -- The block we need to read is outside of the current cluster.\n -- Let's move on to the next\n\n -- Read the FAT table to determine the next cluster\n Current_Cluster := FS.Get_FAT (Current_Cluster);\n\n if Current_Cluster = 1\n or else FS.Is_Last_Cluster (Current_Cluster)\n then\n return Internal_Error;\n end if;\n\n Current_Block := FS.Cluster_To_Block (Current_Cluster);\n end if;\n end if;\n\n Ret := FS.Ensure_Block (Current_Block);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n if FS.Window (Block_Off) = 0 then\n -- End of entries: we stick the index here to make sure that further\n -- calls to Next_Entry always end-up here\n return No_More_Entries;\n end if;\n\n DEntry := To_Entry (FS.Window (Block_Off .. Block_Off + 31));\n Current_Index := Current_Index + 1;\n\n return OK;\n end Next_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Node) return Status_Code\n is\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural);\n -- Prepends Name to Full\n\n -------------\n -- Prepend --\n -------------\n\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural)\n is\n Val : Unsigned_16;\n begin\n for J in reverse Name'Range loop\n Val := Wide_Character'Pos (Name (J));\n if Val /= 16#FFFF#\n and then Val /= 0\n then\n Idx := Idx - 1;\n\n exit when Idx not in Full'Range;\n\n if Val < 255 then\n Full (Idx) := Character'Val (Val);\n elsif Val = 16#F029# then\n -- Path ends with a '.'\n Full (Idx) := '.';\n elsif Val = 16#F028# then\n -- Path ends with a ' '\n Full (Idx) := ' ';\n else\n Full (Idx) := '?';\n end if;\n end if;\n end loop;\n end Prepend;\n\n Ret : Status_Code;\n D_Entry : FAT_Directory_Entry;\n V_Entry : VFAT_Directory_Entry;\n function To_VFAT_Entry is new Ada.Unchecked_Conversion\n (FAT_Directory_Entry, VFAT_Directory_Entry);\n\n C : Unsigned_8;\n Last_Seq : VFAT_Sequence_Number := 0;\n CRC : Unsigned_8 := 0;\n Matches : Boolean;\n Current_CRC : Unsigned_8;\n L_Name : String (1 .. MAX_FILENAME_LENGTH);\n L_Name_First : Natural;\n\n begin\n L_Name_First := L_Name'Last + 1;\n\n loop\n Ret := Next_Entry\n (FS,\n Current_Cluster => Current_Cluster,\n Current_Block => Current_Block,\n Current_Index => Current_Index,\n DEntry => D_Entry);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Check if we have a VFAT entry here by checking that the\n -- attributes are 16#0F# (e.g. all attributes set except\n -- subdirectory and archive)\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n V_Entry := To_VFAT_Entry (D_Entry);\n\n if V_Entry.VFAT_Attr.Stop_Bit then\n L_Name_First := L_Name'Last + 1;\n\n else\n if Last_Seq = 0\n or else Last_Seq - 1 /= V_Entry.VFAT_Attr.Sequence\n then\n L_Name_First := L_Name'Last + 1;\n end if;\n end if;\n\n Last_Seq := V_Entry.VFAT_Attr.Sequence;\n\n Prepend (V_Entry.Name_3, L_Name, L_Name_First);\n Prepend (V_Entry.Name_2, L_Name, L_Name_First);\n Prepend (V_Entry.Name_1, L_Name, L_Name_First);\n\n if V_Entry.VFAT_Attr.Sequence = 1 then\n CRC := V_Entry.Checksum;\n end if;\n\n -- Ignore Volumes and deleted files\n elsif not D_Entry.Attributes.Volume_Label\n and then Character'Pos (D_Entry.Filename (1)) /= 16#E5#\n then\n if L_Name_First not in L_Name'Range then\n Matches := False;\n else\n Current_CRC := 0;\n Last_Seq := 0;\n\n for Ch of String'(D_Entry.Filename & D_Entry.Extension) loop\n C := Character'Enum_Rep (Ch);\n Current_CRC := Shift_Right (Current_CRC and 16#FE#, 1)\n or Shift_Left (Current_CRC and 16#01#, 7);\n -- Modulo addition\n Current_CRC := Current_CRC + C;\n end loop;\n\n Matches := Current_CRC = CRC;\n end if;\n\n DEntry :=\n (FS => FAT_Filesystem_Access (FS),\n L_Name => <>,\n S_Name => D_Entry.Filename,\n S_Name_Ext => D_Entry.Extension,\n Attributes => D_Entry.Attributes,\n Start_Cluster => (if FS.Version = FAT16\n then Cluster_Type (D_Entry.Cluster_L)\n else Cluster_Type (D_Entry.Cluster_L) or\n Shift_Left\n (Cluster_Type (D_Entry.Cluster_H), 16)),\n Size => D_Entry.Size,\n Index => Current_Index - 1,\n Is_Root => False,\n Is_Dirty => False);\n\n if Matches then\n DEntry.L_Name := -L_Name (L_Name_First .. L_Name'Last);\n else\n DEntry.L_Name.Len := 0;\n end if;\n\n return OK;\n end if;\n end loop;\n end Next_Entry;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (Dir : in out FAT_Directory_Handle;\n DEntry : out FAT_Node) return Status_Code\n is\n begin\n return Next_Entry\n (Dir.FS,\n Current_Cluster => Dir.Current_Cluster,\n Current_Block => Dir.Current_Block,\n Current_Index => Dir.Current_Index,\n DEntry => DEntry);\n end Read;\n\n -------------------\n -- Create_Subdir --\n -------------------\n\n function Create_Subdir\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_Dir : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n Block : Block_Offset;\n Dot : FAT_Directory_Entry;\n Dot_Dot : FAT_Directory_Entry;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n E => New_Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Block := Dir.FS.Cluster_To_Block (New_Dir.Start_Cluster);\n Ret := Handle.FS.Ensure_Block (Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Allocate '.', '..' and the directory entry terminator\n Dot :=\n (Filename => (1 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32\n (New_Dir.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (New_Dir.Start_Cluster and 16#FFFF#),\n Size => 0);\n Dot_Dot :=\n (Filename => (1 .. 2 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32 (Handle.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (Handle.Start_Cluster and 16#FFFF#),\n Size => 0);\n\n Handle.FS.Window (0 .. 31) := To_Data (Dot);\n Handle.FS.Window (32 .. 63) := To_Data (Dot_Dot);\n Handle.FS.Window (64 .. 95) := (others => 0);\n Ret := Handle.FS.Write_Window;\n\n Close (Handle.all);\n\n return Ret;\n end Create_Subdir;\n\n ----------------------\n -- Create_File_Node --\n ----------------------\n\n function Create_File_Node\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_File : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => False,\n Archive => True),\n E => New_File);\n\n Close (Handle.all);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Create_File_Node;\n\n -------------------\n -- Delete_Subdir --\n -------------------\n\n function Delete_Subdir\n (Dir : FAT_Node;\n Recursive : Boolean) return Status_Code\n is\n Parent : FAT_Node;\n Handle : FAT_Directory_Handle_Access;\n Ent : FAT_Node;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Ent) = OK loop\n if -Long_Name (Ent) = \".\" then\n null;\n elsif -Long_Name (Ent) = \"..\" then\n Parent := Ent;\n elsif not Recursive then\n return Non_Empty_Directory;\n else\n if Ent.Attributes.Subdirectory then\n Ret := Delete_Subdir (Ent, True);\n else\n Ret := Delete_Entry (Dir, Ent);\n end if;\n\n if Ret /= OK then\n Close (Handle.all);\n\n return Ret;\n end if;\n end if;\n end loop;\n\n Close (Handle.all);\n\n -- Free the clusters associated to the subdirectory\n Ret := Delete_Entry (Parent, Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Delete_Subdir;\n\n ------------------\n -- Delete_Entry --\n ------------------\n\n function Delete_Entry\n (Dir : FAT_Node;\n Ent : FAT_Node) return Status_Code\n is\n Current : Cluster_Type := Ent.Start_Cluster;\n Handle : FAT_Directory_Handle_Access;\n Next : Cluster_Type;\n Child_Ent : FAT_Node;\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n -- Mark the entry's cluster chain as available\n loop\n Next := Ent.FS.Get_FAT (Current);\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n end loop;\n\n -- Mark the parent's entry as deleted\n Ret := Dir.FAT_Open (Handle);\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Child_Ent) = OK loop\n if Long_Name (Child_Ent) = Long_Name (Ent) then\n Block_Off := Natural\n ((FAT_File_Size (Handle.Current_Index - 1) * 32)\n mod Dir.FS.Block_Size);\n -- Mark the entry as deleted: first basename character set to\n -- 16#E5#\n Handle.FS.Window (Block_Off) := 16#E5#;\n Ret := Handle.FS.Write_Window;\n\n exit;\n end if;\n end loop;\n\n Close (Handle.all);\n\n return Ret;\n end Delete_Entry;\n\n ---------------------\n -- Adjust_Clusters --\n ---------------------\n\n function Adjust_Clusters (Ent : FAT_Node) return Status_Code\n is\n B_Per_Cluster : constant FAT_File_Size :=\n FAT_File_Size (Ent.FS.Blocks_Per_Cluster) *\n Ent.FS.Block_Size;\n Size : FAT_File_Size := Ent.Size;\n Current : Cluster_Type := Ent.Start_Cluster;\n Next : Cluster_Type;\n Ret : Status_Code := OK;\n\n begin\n if Ent.Attributes.Subdirectory then\n -- ??? Do nothing for now\n return OK;\n end if;\n\n loop\n Next := Ent.FS.Get_FAT (Current);\n\n if Size > B_Per_Cluster then\n -- Current cluster is fully used\n Size := Size - B_Per_Cluster;\n elsif Size > 0 or else Current = Ent.Start_Cluster then\n -- Partially used cluster, but the last one\n Size := 0;\n if Next /= LAST_CLUSTER_VALUE then\n Ret := Ent.FS.Set_FAT (Current, LAST_CLUSTER_VALUE);\n end if;\n else\n -- We don't need more clusters\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n end if;\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n Size := Size - B_Per_Cluster;\n end loop;\n\n return Ret;\n end Adjust_Clusters;\n\n -------------------------------\n -- Find_Empty_Entry_Sequence --\n -------------------------------\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index\n is\n Status : Status_Code;\n D_Entry : FAT_Directory_Entry;\n Sequence : Natural := 0;\n Ret : Entry_Index;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Cluster_To_Block (Parent.FS.all, Cluster);\n begin\n Parent.Current_Index := 0;\n loop\n Status := Next_Entry\n (Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Parent.Current_Index,\n DEntry => D_Entry);\n\n if Status /= OK then\n return Null_Index;\n end if;\n\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n if Sequence = 0 then\n -- Parent.Current_Index points to the next unread value.\n -- So the just read entry is at Parent.Current_Index - 1\n Ret := Parent.Current_Index - 1;\n end if;\n\n Sequence := Sequence + 1;\n\n elsif Character'Pos (D_Entry.Filename (1)) = 16#E5# then\n -- A deleted entry has been found\n if Sequence >= Num_Entries then\n return Ret;\n else\n Sequence := 0;\n end if;\n\n else\n Sequence := 0;\n end if;\n end loop;\n end Find_Empty_Entry_Sequence;\n\n --------------------\n -- Allocate_Entry --\n --------------------\n\n function Allocate_Entry\n (Parent : access FAT_Directory_Handle;\n Name : FAT_Name;\n Attributes : FAT_Directory_Entry_Attribute;\n E : out FAT_Node) return Status_Code\n is\n subtype Short_Name is String (1 .. 8);\n subtype Extension is String (1 .. 3);\n\n function Is_Legal_Character (C : Character) return Boolean\n is (C in 'A' .. 'Z'\n or else C in '0' .. '9'\n or else C = '!'\n or else C = '#'\n or else C = '$'\n or else C = '%'\n or else C = '&'\n or else C = '''\n or else C = '('\n or else C = ')'\n or else C = '-'\n or else C = '@'\n or else C = '^'\n or else C = '_'\n or else C = '`'\n or else C = '{'\n or else C = '}'\n or else C = '~');\n\n Block_Off : Natural;\n Status : Status_Code;\n DEntry : FAT_Node;\n SName : Short_Name := (others => ' ');\n SExt : Extension := (others => ' ');\n Index : Entry_Index;\n\n -- Retrieve the number of VFAT entries that are needed, plus one for\n -- the regular FAT entry.\n N_Entries : Natural := Get_Num_VFAT_Entries (Name) + 1;\n Bytes : Entry_Data;\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension);\n -- Translates a long name into short 8.3 name\n -- If the long name is mixed or lower case. then 8.3 will be uppercased\n -- If the long name contains characters not allowed in an 8.3 name, then\n -- the name is stripped of invalid characters such as space and extra\n -- periods. Other unknown characters are changed to underscores.\n -- The stripped name is then truncated, followed by a ~1. Inc_SName\n -- below will increase the digit number in case there's overloaded 8.3\n -- names.\n -- If the long name is longer than 8.3, then ~1 suffix will also be\n -- used.\n\n function To_Upper (C : Character) return Character is\n (if C in 'a' .. 'z'\n then Character'Val\n (Character'Pos (C) + Character'Pos ('A') - Character'Pos ('a'))\n else C);\n\n function Value (S : String) return Natural;\n -- For a positive int represented in S, returns its value\n\n procedure Inc_SName (SName : in out String);\n -- Increment the suffix of the short FAT name\n -- e.g.:\n -- ABCDEFGH => ABCDEF~1\n -- ABC => ABC~1\n -- ABC~9 => ABC~10\n -- ABCDEF~9 => ABCDE~10\n\n procedure To_WString\n (S : FAT_Name;\n Idx : in out Natural;\n WS : in out Wide_String);\n -- Dumps S (Idx .. Idx + WS'Length - 1) into WS and increments Idx\n\n -----------\n -- Value --\n -----------\n\n function Value (S : String) return Natural\n is\n Val : constant String := Trim (S);\n Digit : Natural;\n Ret : Natural := 0;\n begin\n for J in Val'Range loop\n Digit := Character'Pos (Val (J)) - Character'Pos ('0');\n Ret := Ret * 10 + Digit;\n end loop;\n\n return Ret;\n end Value;\n\n -------------------\n -- To_Short_Name --\n -------------------\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension)\n is\n S_Idx : Natural := 0;\n Add_Tilde : Boolean := False;\n Last : Natural := Name.Len;\n\n begin\n -- Copy the file extension\n\n Ext := (others => ' ');\n\n for J in reverse 1 .. Name.Len loop\n if Name.Name (J) = '.' then\n if J = Name.Len then\n -- Take care of names ending with a '.' (e.g. no extension,\n -- the final '.' is part of the basename)\n Last := J;\n Ext := (others => ' ');\n else\n Last := J - 1;\n S_Idx := Ext'First;\n\n for K in J + 1 .. Name.Len loop\n Ext (S_Idx) := To_Upper (Name.Name (K));\n S_Idx := S_Idx + 1;\n -- In case the extension is more than 3 characters, we\n -- keep the first 3 ones.\n exit when S_Idx > Ext'Last;\n end loop;\n end if;\n\n exit;\n end if;\n end loop;\n\n S_Idx := 0;\n SName := (others => ' ');\n\n for J in 1 .. Last loop\n exit when Add_Tilde and then S_Idx >= 6;\n exit when not Add_Tilde and then S_Idx = 8;\n\n if Name.Name (J) in 'a' .. 'z' then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := To_Upper (Name.Name (J));\n\n elsif Is_Legal_Character (Name.Name (J)) then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := Name.Name (J);\n\n elsif Name.Name (J) = '.'\n or else Name.Name (J) = ' '\n then\n -- dots that are not used as extension delimiters are invalid\n -- in FAT short names and ignored in long names to short names\n -- translation\n Add_Tilde := True;\n\n else\n -- Any other character is translated as '_'\n Add_Tilde := True;\n S_Idx := S_Idx + 1;\n SName (S_Idx) := '_';\n end if;\n end loop;\n\n if Add_Tilde then\n if S_Idx >= 6 then\n SName (7 .. 8) := \"~1\";\n else\n SName (S_Idx + 1 .. S_Idx + 2) := \"~1\";\n end if;\n end if;\n end To_Short_Name;\n\n ---------------\n -- Inc_SName --\n ---------------\n\n procedure Inc_SName (SName : in out String)\n is\n Idx : Natural := 0;\n Num : Natural := 0;\n\n begin\n for J in reverse SName'Range loop\n if Idx = 0 then\n if SName (J) = ' ' then\n null;\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n else\n SName (SName'Last - 1 .. SName'Last) := \"~1\";\n\n return;\n end if;\n\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n\n elsif SName (J) = '~' then\n Num := Value (SName (Idx .. SName'Last)) + 1;\n -- make Idx point to '~'\n Idx := J;\n\n declare\n N_Suffix : String := Natural'Image (Num);\n begin\n N_Suffix (N_Suffix'First) := '~';\n\n if Idx + N_Suffix'Length - 1 > SName'Last then\n SName (SName'Last - N_Suffix'Length + 1 .. SName'Last) :=\n N_Suffix;\n else\n SName (Idx .. Idx + N_Suffix'Length - 1) := N_Suffix;\n end if;\n\n return;" + }, + { + "function_def": "function To_Disk_Parameter is new Ada.Unchecked_Conversion", + "function_body": "(Disk_Parameter_Block, FAT_Disk_Parameter);\n\n subtype FSInfo_Block is Block (0 .. 11);\n function To_FSInfo is new Ada.Unchecked_Conversion\n (FSInfo_Block, FAT_FS_Info);\n\n begin\n FS.Window_Block := 16#FFFF_FFFF#;\n Status := FS.Ensure_Block (0);\n\n if Status /= OK then\n return;\n end if;\n\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.Disk_Parameters :=\n To_Disk_Parameter (FS.Window (0 .. 91));\n\n if FS.Version = FAT32 then\n Status :=\n FS.Ensure_Block (Block_Offset (FS.FSInfo_Block_Number));\n\n if Status /= OK then\n return;\n end if;\n\n -- Check the generic FAT block signature\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.FSInfo :=\n To_FSInfo (FS.Window (16#1E4# .. 16#1EF#));\n FS.FSInfo_Changed := False;\n end if;\n\n declare\n FAT_Size_In_Block : constant Unsigned_32 :=\n FS.FAT_Table_Size_In_Blocks *\n Unsigned_32 (FS.Number_Of_FATs);\n Root_Dir_Size : Block_Offset;\n begin\n FS.FAT_Addr := Block_Offset (FS.Reserved_Blocks);\n FS.Data_Area := FS.FAT_Addr + Block_Offset (FAT_Size_In_Block);\n\n if FS.Version = FAT16 then\n -- Add space for the root directory\n FS.Root_Dir_Area := FS.Data_Area;\n Root_Dir_Size :=\n (Block_Offset (FS.FAT16_Root_Dir_Num_Entries) * 32 +\n Block_Offset (FS.Block_Size) - 1) /\n Block_Offset (FS.Block_Size);\n -- Align on clusters\n Root_Dir_Size :=\n ((Root_Dir_Size + FS.Blocks_Per_Cluster - 1) /\n FS.Blocks_Per_Cluster) *\n FS.Blocks_Per_Cluster;\n\n FS.Data_Area := FS.Data_Area + Root_Dir_Size;\n end if;\n\n FS.Num_Clusters :=\n Cluster_Type\n ((FS.Total_Number_Of_Blocks - Unsigned_32 (FS.Data_Area)) /\n Unsigned_32 (FS.Blocks_Per_Cluster));" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out SPI_Port'Class) is\n begin\n if This'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2ENR.SAI1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address /= SAI_Base then\n raise Unknown_Device;\n end if;\n\n Input_Selector := RCC_Periph.DCKCFGR.SAI1ASRC;\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLIS2DIVQ + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDIOEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDIORST := True;\n RCC_Periph.APB2RSTR.SDIORST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDIO_Clock_Source)\n is\n Src_Val : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DCKCFGR.SDMMCSEL := Src_Val;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2ENR.SDMMC2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2RSTR.SDMMC2RST := True;\n RCC_Periph.APB2RSTR.SDMMC2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n Sel_Value : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.DKCFGR2.SDMMC1SEL := Sel_Value;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.DKCFGR2.SDMMC2SEL := Sel_Value;\n else\n raise Unknown_Device;\n end if;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant\n UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant\n UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DKCFGR2.SDMMCSEL := Src = Src_Sysclk;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Disable", + "function_body": "(This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.EN1 := False;\n when Channel_2 =>\n This.CR.EN2 := False;\n end case;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.EN1;\n when Channel_2 =>\n return This.CR.EN2;\n end case;\n end Enabled;\n\n ----------------\n -- Set_Output --\n ----------------\n\n procedure Set_Output\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Channel is\n\n when Channel_1 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R1.DACC1DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n when Channel_2 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R2.DACC2DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n end case;\n end Set_Output;\n\n ------------------------------------\n -- Trigger_Conversion_By_Software --\n ------------------------------------\n\n procedure Trigger_Conversion_By_Software\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SWTRIGR.SWTRIG.Arr (1) := True; -- cleared by hardware\n when Channel_2 =>\n This.SWTRIGR.SWTRIG.Arr (2) := True; -- cleared by hardware\n end case;\n end Trigger_Conversion_By_Software;\n\n ----------------------------\n -- Converted_Output_Value --\n ----------------------------\n\n function Converted_Output_Value\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return UInt32\n is\n begin\n case Channel is\n when Channel_1 =>\n return UInt32 (This.DOR1.DACC1DOR);\n when Channel_2 =>\n return UInt32 (This.DOR2.DACC2DOR);\n end case;\n end Converted_Output_Value;\n\n ------------------------------\n -- Set_Dual_Output_Voltages --\n ------------------------------\n\n procedure Set_Dual_Output_Voltages\n (This : in out Digital_To_Analog_Converter;\n Channel_1_Value : UInt32;\n Channel_2_Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12LD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12LD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12RD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12RD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8RD.DACC1DHR :=\n UInt8 (Channel_1_Value and Max_8bit_Resolution);\n This.DHR8RD.DACC2DHR :=\n UInt8 (Channel_2_Value and Max_8bit_Resolution);\n end case;\n end Set_Dual_Output_Voltages;\n\n ---------------------------------\n -- Converted_Dual_Output_Value --\n ---------------------------------\n\n function Converted_Dual_Output_Value (This : Digital_To_Analog_Converter)\n return Dual_Channel_Output\n is\n Result : Dual_Channel_Output;\n begin\n Result.Channel_1_Data := UInt16 (This.DOR1.DACC1DOR);\n Result.Channel_2_Data := UInt16 (This.DOR2.DACC2DOR);\n return Result;\n end Converted_Dual_Output_Value;\n\n --------------------------\n -- Enable_Output_Buffer --\n --------------------------\n\n procedure Enable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := True;\n when Channel_2 =>\n This.CR.BOFF2 := True;\n end case;\n end Enable_Output_Buffer;\n\n ---------------------------\n -- Disable_Output_Buffer --\n ---------------------------\n\n procedure Disable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := False;\n when Channel_2 =>\n This.CR.BOFF2 := False;\n end case;\n end Disable_Output_Buffer;\n\n ---------------------------\n -- Output_Buffer_Enabled --\n ---------------------------\n\n function Output_Buffer_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.BOFF1;\n when Channel_2 =>\n return This.CR.BOFF2;\n end case;\n end Output_Buffer_Enabled;\n\n --------------------\n -- Select_Trigger --\n --------------------\n\n procedure Select_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Trigger : External_Event_Trigger_Selection)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TSEL1 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n when Channel_2 =>\n This.CR.TSEL2 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n end case;\n end Select_Trigger;\n\n -----------------------\n -- Trigger_Selection --\n -----------------------\n\n function Trigger_Selection\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return External_Event_Trigger_Selection\n is\n begin\n case Channel is\n when Channel_1 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL1);\n when Channel_2 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL2);\n end case;\n end Trigger_Selection;\n\n --------------------\n -- Enable_Trigger --\n --------------------\n\n procedure Enable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := True;\n when Channel_2 =>\n This.CR.TEN2 := True;\n end case;\n end Enable_Trigger;\n\n ---------------------\n -- Disable_Trigger --\n ---------------------\n\n procedure Disable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := False;\n when Channel_2 =>\n This.CR.TEN2 := False;\n end case;\n end Disable_Trigger;\n\n ---------------------\n -- Trigger_Enabled --\n ---------------------\n\n function Trigger_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.TEN1;\n when Channel_2 =>\n return This.CR.TEN2;\n end case;\n end Trigger_Enabled;\n\n ----------------\n -- Enable_DMA --\n ----------------\n\n procedure Enable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := True;\n when Channel_2 =>\n This.CR.DMAEN2 := True;\n end case;\n end Enable_DMA;\n\n -----------------\n -- Disable_DMA --\n -----------------\n\n procedure Disable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := False;\n when Channel_2 =>\n This.CR.DMAEN2 := False;\n end case;\n end Disable_DMA;\n\n -----------------\n -- DMA_Enabled --\n -----------------\n\n function DMA_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.DMAEN1;\n when Channel_2 =>\n return This.CR.DMAEN2;\n end case;\n end DMA_Enabled;\n\n ------------\n -- Status --\n ------------\n\n function Status\n (This : Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n return Boolean\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n return This.SR.DMAUDR1;\n when DMA_Underrun_Channel_2 =>\n return This.SR.DMAUDR2;\n end case;\n end Status;\n\n ------------------\n -- Clear_Status --\n ------------------\n\n procedure Clear_Status\n (This : in out Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n This.SR.DMAUDR1 := True; -- set to 1 to clear\n when DMA_Underrun_Channel_2 =>\n This.SR.DMAUDR2 := True; -- set to 1 to clear\n end case;\n end Clear_Status;\n\n -----------------------\n -- Enable_Interrupts --\n -----------------------\n\n procedure Enable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := True;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := True;\n end case;\n end Enable_Interrupts;\n\n ------------------------\n -- Disable_Interrupts --\n ------------------------\n\n procedure Disable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := False;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := False;\n end case;\n end Disable_Interrupts;\n\n -----------------------\n -- Interrupt_Enabled --\n -----------------------\n\n function Interrupt_Enabled\n (This : Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n return Boolean\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n return This.CR.DMAUDRIE1;\n when DMA_Underrun_Channel_2 =>\n return This.CR.DMAUDRIE2;\n end case;\n end Interrupt_Enabled;\n\n ----------------------\n -- Interrupt_Source --\n ----------------------\n\n function Interrupt_Source\n (This : Digital_To_Analog_Converter)\n return DAC_Interrupts\n is\n begin\n if This.CR.DMAUDRIE1 then\n return DMA_Underrun_Channel_1;\n else\n return DMA_Underrun_Channel_2;\n end if;\n end Interrupt_Source;\n\n -----------------------------\n -- Clear_Interrupt_Pending --\n -----------------------------\n\n procedure Clear_Interrupt_Pending\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SR.DMAUDR1 := False;\n when Channel_2 =>\n This.SR.DMAUDR2 := False;\n end case;\n end Clear_Interrupt_Pending;\n\n ----------------------------\n -- Select_Wave_Generation --\n ----------------------------\n\n procedure Select_Wave_Generation\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Selection : Wave_Generation)\n is\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Noise_Wave_Mask_Selection, Target => UInt4);\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Triangle_Wave_Amplitude_Selection, Target => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n This.CR.WAVE1 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n when Channel_2 =>\n This.CR.WAVE2 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n end case;\n\n case Selection.Kind is\n\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Mask);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Mask);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Amplitude);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Amplitude);\n end case;\n\n end case;\n end Select_Wave_Generation;\n\n ------------------------------\n -- Selected_Wave_Generation --\n ------------------------------\n\n function Selected_Wave_Generation\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Wave_Generation\n is\n Kind : Wave_Generation_Selection;\n\n function As_Mask is new Ada.Unchecked_Conversion\n (Target => Noise_Wave_Mask_Selection, Source => UInt4);\n\n function As_Amplitude is new Ada.Unchecked_Conversion\n (Target => Triangle_Wave_Amplitude_Selection, Source => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE1);\n when Channel_2 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE2);\n end case;\n declare\n Result : Wave_Generation (Kind);\n begin\n case Kind is\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Mask := As_Mask (This.CR.MAMP1);\n when Channel_2 =>\n Result.Mask := As_Mask (This.CR.MAMP2);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP1);\n when Channel_2 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP2);\n end case;\n end case;\n\n return Result;" + }, + { + "function_def": "procedure Disable (This : in out Analog_To_Digital_Converter) is", + "function_body": "begin\n This.CR2.ADON := False;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled (This : Analog_To_Digital_Converter) return Boolean is\n (This.CR2.ADON);\n\n ----------------------\n -- Conversion_Value --\n ----------------------\n\n function Conversion_Value\n (This : Analog_To_Digital_Converter)\n return UInt16\n is\n begin\n return This.DR.DATA;\n end Conversion_Value;\n\n ---------------------------\n -- Data_Register_Address --\n ---------------------------\n\n function Data_Register_Address\n (This : Analog_To_Digital_Converter)\n return System.Address\n is\n (This.DR'Address);\n\n -------------------------------\n -- Injected_Conversion_Value --\n -------------------------------\n\n function Injected_Conversion_Value\n (This : Analog_To_Digital_Converter;\n Rank : Injected_Channel_Rank)\n return UInt16\n is\n begin\n case Rank is\n when 1 =>\n return This.JDR1.JDATA;\n when 2 =>\n return This.JDR2.JDATA;\n when 3 =>\n return This.JDR3.JDATA;\n when 4 =>\n return This.JDR4.JDATA;\n end case;\n end Injected_Conversion_Value;\n\n --------------------------------\n -- Multimode_Conversion_Value --\n --------------------------------\n\n function Multimode_Conversion_Value return UInt32 is\n (C_ADC_Periph.CDR.Val);\n\n --------------------\n -- Configure_Unit --\n --------------------\n\n procedure Configure_Unit\n (This : in out Analog_To_Digital_Converter;\n Resolution : ADC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n This.CR1.RES := ADC_Resolution'Enum_Rep (Resolution);\n This.CR2.ALIGN := Alignment = Left_Aligned;\n end Configure_Unit;\n\n ------------------------\n -- Current_Resolution --\n ------------------------\n\n function Current_Resolution\n (This : Analog_To_Digital_Converter)\n return ADC_Resolution\n is (ADC_Resolution'Val (This.CR1.RES));\n\n -----------------------\n -- Current_Alignment --\n -----------------------\n\n function Current_Alignment\n (This : Analog_To_Digital_Converter)\n return Data_Alignment\n is ((if This.CR2.ALIGN then Left_Aligned else Right_Aligned));\n\n ---------------------------------\n -- Configure_Common_Properties --\n ---------------------------------\n\n procedure Configure_Common_Properties\n (Mode : Multi_ADC_Mode_Selections;\n Prescalar : ADC_Prescalars;\n DMA_Mode : Multi_ADC_DMA_Modes;\n Sampling_Delay : Sampling_Delay_Selections)\n is\n begin\n C_ADC_Periph.CCR.MULT := Multi_ADC_Mode_Selections'Enum_Rep (Mode);\n C_ADC_Periph.CCR.DELAY_k :=\n Sampling_Delay_Selections'Enum_Rep (Sampling_Delay);\n C_ADC_Periph.CCR.DMA := Multi_ADC_DMA_Modes'Enum_Rep (DMA_Mode);\n C_ADC_Periph.CCR.ADCPRE := ADC_Prescalars'Enum_Rep (Prescalar);\n end Configure_Common_Properties;\n\n -----------------------------------\n -- Configure_Regular_Conversions --\n -----------------------------------\n\n procedure Configure_Regular_Conversions\n (This : in out Analog_To_Digital_Converter;\n Continuous : Boolean;\n Trigger : Regular_Channel_Conversion_Trigger;\n Enable_EOC : Boolean;\n Conversions : Regular_Channel_Conversions)\n is\n begin\n This.CR2.EOCS := Enable_EOC;\n This.CR2.CONT := Continuous;\n\n This.CR1.SCAN := Conversions'Length > 1;\n\n if Trigger.Enabler /= Trigger_Disabled then\n This.CR2.EXTSEL := External_Events_Regular_Group'Enum_Rep (Trigger.Event);\n This.CR2.EXTEN := External_Trigger'Enum_Rep (Trigger.Enabler);\n else\n This.CR2.EXTSEL := 0;\n This.CR2.EXTEN := 0;\n end if;\n\n for Rank in Conversions'Range loop\n declare\n Conversion : Regular_Channel_Conversion renames Conversions (Rank);\n begin\n Configure_Regular_Channel\n (This, Conversion.Channel, Rank, Conversion.Sample_Time);\n\n -- We check the VBat first because that channel is also used for\n -- the temperature sensor channel on some MCUs, in which case the\n -- VBat conversion is the only one done. This order reflects that\n -- hardware behavior.\n if VBat_Conversion (This, Conversion.Channel) then\n Enable_VBat_Connection;\n elsif VRef_TemperatureSensor_Conversion (This, Conversion.Channel)\n then\n Enable_VRef_TemperatureSensor_Connection;\n end if;" + }, + { + "function_def": "procedure Disable_Interrupt", + "function_body": "(This : in out SDMMC_Controller;\n Interrupt : SDMMC_Interrupts)\n is\n begin\n case Interrupt is\n when Data_End_Interrupt =>\n This.Periph.MASK.DATAENDIE := False;\n when Data_CRC_Fail_Interrupt =>\n This.Periph.MASK.DCRCFAILIE := False;\n when Data_Timeout_Interrupt =>\n This.Periph.MASK.DTIMEOUTIE := False;\n when TX_FIFO_Empty_Interrupt =>\n This.Periph.MASK.TXFIFOEIE := False;\n when RX_FIFO_Full_Interrupt =>\n This.Periph.MASK.RXFIFOFIE := False;\n when TX_Underrun_Interrupt =>\n This.Periph.MASK.TXUNDERRIE := False;\n when RX_Overrun_Interrupt =>\n This.Periph.MASK.RXOVERRIE := False;\n end case;\n end Disable_Interrupt;\n\n ------------------------\n -- Delay_Milliseconds --\n ------------------------\n\n overriding procedure Delay_Milliseconds\n (This : SDMMC_Controller;\n Amount : Natural)\n is\n pragma Unreferenced (This);\n begin\n delay until Clock + Milliseconds (Amount);\n end Delay_Milliseconds;\n\n -----------\n -- Reset --\n -----------\n\n overriding procedure Reset\n (This : in out SDMMC_Controller;\n Status : out SD_Error)\n is\n begin\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n This.Periph.POWER.PWRCTRL := Power_Off;\n\n -- Use the Default SDMMC peripheral configuration for SD card init\n This.Periph.CLKCR := (others => <>);\n This.Set_Clock (400_000);\n This.Periph.DTIMER := SD_DATATIMEOUT;\n\n This.Periph.CLKCR.CLKEN := False;\n DCTRL_Write_Delay;\n This.Periph.POWER.PWRCTRL := Power_On;\n\n -- Wait for the clock to stabilize.\n DCTRL_Write_Delay;\n\n This.Periph.CLKCR.CLKEN := True;\n\n delay until Clock + Milliseconds (20);\n\n Status := OK;\n end Reset;\n\n ---------------\n -- Set_Clock --\n ---------------\n\n overriding procedure Set_Clock\n (This : in out SDMMC_Controller;\n Freq : Natural)\n is\n Div : UInt32;\n CLKCR : CLKCR_Register;\n begin\n Div := (This.CLK_In + UInt32 (Freq) - 1) / UInt32 (Freq);\n\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n if Div <= 1 then\n This.Periph.CLKCR.BYPASS := True;\n else\n Div := Div - 2;\n CLKCR := This.Periph.CLKCR;\n CLKCR.BYPASS := False;\n\n if Div > UInt32 (CLKCR_CLKDIV_Field'Last) then\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field'Last;\n else\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field (Div);\n end if;\n\n This.Periph.CLKCR := CLKCR;\n end if;\n end Set_Clock;\n\n ------------------\n -- Set_Bus_Size --\n ------------------\n\n overriding procedure Set_Bus_Size\n (This : in out SDMMC_Controller;\n Mode : Wide_Bus_Mode)\n is\n function To_WIDBUS_Field is new Ada.Unchecked_Conversion\n (Wide_Bus_Mode, CLKCR_WIDBUS_Field);\n begin\n This.Periph.CLKCR.WIDBUS := To_WIDBUS_Field (Mode);\n end Set_Bus_Size;\n\n ------------------\n -- Send_Command --\n ------------------\n\n overriding procedure Send_Cmd\n (This : in out SDMMC_Controller;\n Cmd : Cmd_Desc_Type;\n Arg : UInt32;\n Status : out SD_Error)\n is\n CMD_Reg : CMD_Register := This.Periph.CMD;\n begin\n if Cmd.Rsp = Rsp_Invalid or else Cmd.Tfr = Tfr_Invalid then\n raise Program_Error with \"Not implemented\";\n end if;\n\n This.Periph.ARG := Arg;\n CMD_Reg.CMDINDEX := CMD_CMDINDEX_Field (Cmd.Cmd);\n CMD_Reg.WAITRESP := (case Cmd.Rsp is\n when Rsp_No => No_Response,\n when Rsp_R2 => Long_Response,\n when others => Short_Response);\n CMD_Reg.WAITINT := False;\n CMD_Reg.CPSMEN := True;\n This.Periph.CMD := CMD_Reg;\n\n case Cmd.Rsp is\n when Rsp_No =>\n Status := This.Command_Error;\n\n when Rsp_R1 | Rsp_R1B =>\n Status := This.Response_R1_Error (Cmd.Cmd);\n\n when Rsp_R2 =>\n Status := This.Response_R2_Error;\n\n when Rsp_R3 =>\n Status := This.Response_R3_Error;\n\n when Rsp_R6 =>\n declare\n RCA : UInt32;\n begin\n Status := This.Response_R6_Error (Cmd.Cmd, RCA);\n This.RCA := UInt16 (Shift_Right (RCA, 16));" + }, + { + "function_def": "procedure Disable_Data", + "function_body": "(This : in out SDMMC_Controller)\n is\n begin\n This.Periph.DCTRL := (others => <>);\n end Disable_Data;\n\n --------------------------\n -- Enable_DMA_Transfers --\n --------------------------\n\n procedure Enable_DMA_Transfers\n (This : in out SDMMC_Controller;\n RX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n TX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n SD_Int : not null STM32.SDMMC_Interrupt.SDMMC_Interrupt_Handler_Access)\n is\n begin\n This.TX_DMA_Int := TX_Int;\n This.RX_DMA_Int := RX_Int;\n This.SD_Int := SD_Int;\n end Enable_DMA_Transfers;\n\n --------------------------\n -- Has_Card_Information --\n --------------------------\n\n function Has_Card_Information\n (This : SDMMC_Controller)\n return Boolean\n is (This.Has_Info);\n\n ----------------------\n -- Card_Information --\n ----------------------\n\n function Card_Information\n (This : SDMMC_Controller)\n return HAL.SDMMC.Card_Information\n is\n begin\n return This.Info;\n end Card_Information;\n\n ----------------------------\n -- Clear_Card_Information --\n ----------------------------\n\n procedure Clear_Card_Information\n (This : in out SDMMC_Controller)\n is\n begin\n This.Has_Info := False;\n end Clear_Card_Information;\n\n ---------------\n -- Read_FIFO --\n ---------------\n\n function Read_FIFO\n (Controller : in out SDMMC_Controller) return UInt32\n is\n begin\n return Controller.Periph.FIFO;\n end Read_FIFO;\n\n -------------------\n -- Command_Error --\n -------------------\n\n function Command_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n begin\n while not Controller.Periph.STA.CMDSENT loop\n if Clock - Start > Milliseconds (1000) then\n return Timeout_Error;\n end if;\n end loop;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Command_Error;\n\n -----------------------\n -- Response_R1_Error --\n -----------------------\n\n function Response_R1_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n R1 : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n R1 := Controller.Periph.RESP1;\n\n if (R1 and SD_OCR_ERRORMASK) = 0 then\n return OK;\n end if;\n\n if (R1 and SD_OCR_ADDR_OUT_OF_RANGE) /= 0 then\n return Address_Out_Of_Range;\n elsif (R1 and SD_OCR_ADDR_MISALIGNED) /= 0 then\n return Address_Missaligned;\n elsif (R1 and SD_OCR_BLOCK_LEN_ERR) /= 0 then\n return Block_Length_Error;\n elsif (R1 and SD_OCR_ERASE_SEQ_ERR) /= 0 then\n return Erase_Seq_Error;\n elsif (R1 and SD_OCR_BAD_ERASE_PARAM) /= 0 then\n return Bad_Erase_Parameter;\n elsif (R1 and SD_OCR_WRITE_PROT_VIOLATION) /= 0 then\n return Write_Protection_Violation;\n elsif (R1 and SD_OCR_LOCK_UNLOCK_FAILED) /= 0 then\n return Lock_Unlock_Failed;\n elsif (R1 and SD_OCR_COM_CRC_FAILED) /= 0 then\n return CRC_Check_Fail;\n elsif (R1 and SD_OCR_ILLEGAL_CMD) /= 0 then\n return Illegal_Cmd;\n elsif (R1 and SD_OCR_CARD_ECC_FAILED) /= 0 then\n return Card_ECC_Failed;\n elsif (R1 and SD_OCR_CC_ERROR) /= 0 then\n return CC_Error;\n elsif (R1 and SD_OCR_GENERAL_UNKNOWN_ERROR) /= 0 then\n return General_Unknown_Error;\n elsif (R1 and SD_OCR_STREAM_READ_UNDERRUN) /= 0 then\n return Stream_Read_Underrun;\n elsif (R1 and SD_OCR_STREAM_WRITE_UNDERRUN) /= 0 then\n return Stream_Write_Underrun;\n elsif (R1 and SD_OCR_CID_CSD_OVERWRITE) /= 0 then\n return CID_CSD_Overwrite;\n elsif (R1 and SD_OCR_WP_ERASE_SKIP) /= 0 then\n return WP_Erase_Skip;\n elsif (R1 and SD_OCR_CARD_ECC_DISABLED) /= 0 then\n return Card_ECC_Disabled;\n elsif (R1 and SD_OCR_ERASE_RESET) /= 0 then\n return Erase_Reset;\n elsif (R1 and SD_OCR_AKE_SEQ_ERROR) /= 0 then\n return AKE_SEQ_Error;\n else\n return General_Unknown_Error;\n end if;\n end Response_R1_Error;\n\n -----------------------\n -- Response_R2_Error --\n -----------------------\n\n function Response_R2_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R2_Error;\n\n -----------------------\n -- Response_R3_Error --\n -----------------------\n\n function Response_R3_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R3_Error;\n\n -----------------------\n -- Response_R6_Error --\n -----------------------\n\n function Response_R6_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command;\n RCA : out UInt32) return SD_Error\n is\n Response : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n Response := Controller.Periph.RESP1;\n\n if (Response and SD_R6_Illegal_Cmd) = SD_R6_Illegal_Cmd then\n return Illegal_Cmd;\n\n elsif (Response and SD_R6_General_Unknown_Error) =\n SD_R6_General_Unknown_Error\n then\n return General_Unknown_Error;\n\n elsif (Response and SD_R6_Com_CRC_Failed) = SD_R6_Com_CRC_Failed then\n return CRC_Check_Fail;\n end if;\n\n RCA := Response and 16#FFFF_0000#;\n\n return OK;\n end Response_R6_Error;\n\n -----------------------\n -- Response_R7_Error --\n -----------------------\n\n function Response_R7_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n\n elsif Controller.Periph.STA.CMDREND then\n Controller.Periph.ICR.CMDRENDC := True;\n\n return OK;\n\n else\n return Error;\n end if;\n end Response_R7_Error;\n\n -------------------\n -- Stop_Transfer --\n -------------------\n\n function Stop_Transfer\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n Send_Cmd (This, Cmd_Desc (Stop_Transmission), 0, Ret);\n\n return Ret;\n end Stop_Transfer;\n\n -----------------------\n -- Set_Clk_Src_Speed --\n -----------------------\n\n procedure Set_Clk_Src_Speed\n (This : in out SDMMC_Controller;\n CLK : UInt32)\n is\n begin\n This.CLK_In := CLK;\n end Set_Clk_Src_Speed;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n SDMMC_Init.Card_Identification_Process (This, This.Info, Ret);\n This.Card_Type := This.Info.Card_Type;\n This.RCA := This.Info.RCA;\n\n return Ret;\n end Initialize;\n\n ----------\n -- Read --\n ----------\n\n overriding\n function Read\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : out HAL.Block_Drivers.Block) return Boolean\n is\n Ret : Boolean;\n SD_Err : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n\n Ensure_Card_Informations (This);\n\n if This.RX_DMA_Int = null or else This.SD_Int = null then\n SD_Err := Read_Blocks\n (This,\n Block_Number * 512,\n Data);\n return SD_Err = OK;\n end if;\n\n This.SD_Int.Set_Transfer_State (This);\n\n SD_Err := Read_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.RX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.SD_Int.Wait_Transfer (SD_Err);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n else\n This.RX_DMA_Int.Wait_For_Completion (DMA_Err);\n\n loop\n exit when not Get_Flag (This, RX_Active);\n end loop;\n end if;\n\n Ret := SD_Err = OK and then DMA_Err = DMA_No_Error;\n\n if Last_Operation (This) =\n Read_Multiple_Blocks_Operation\n then\n SD_Err := Stop_Transfer (This);\n Ret := Ret and then SD_Err = OK;\n end if;\n\n Clear_All_Status (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable_Data (This);\n Clear_Static_Flags (This);\n\n Cortex_M.Cache.Invalidate_DCache\n (Start => Data'Address,\n Len => Data'Length);\n\n return Ret;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n overriding\n function Write\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : HAL.Block_Drivers.Block) return Boolean\n is\n Ret : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n if This.TX_DMA_Int = null then\n raise Program_Error with \"No TX DMA controller\";\n end if;\n\n if This.SD_Int = null then\n raise Program_Error with \"No SD interrupt controller\";\n end if;\n\n Ensure_Card_Informations (This);\n\n -- Flush the data cache\n Cortex_M.Cache.Clean_DCache\n (Start => Data (Data'First)'Address,\n Len => Data'Length);\n\n This.SD_Int.Set_Transfer_State (This);\n\n Ret := Write_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n -- this always leaves the last 12 byte standing. Why?\n -- also...NDTR is not what it should be.\n\n if Ret /= OK then\n This.TX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.TX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.TX_DMA_Int.Wait_For_Completion (DMA_Err); -- this unblocks\n This.SD_Int.Wait_Transfer (Ret); -- TX underrun!\n\n -- this seems slow. Do we have to wait?\n loop\n -- FIXME: some people claim, that this goes wrong with multiblock, see\n -- http://blog.frankvh.com/2011/09/04/stm32f2xx-sdio-sd-card-interface/\n exit when not Get_Flag (This, TX_Active);\n end loop;\n\n if Last_Operation (This) =\n Write_Multiple_Blocks_Operation\n then\n Ret := Stop_Transfer (This);\n end if;\n\n Clear_All_Status (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n Disable (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n\n declare\n Data_Incomplete : constant Boolean :=\n This.TX_DMA_Int.Buffer_Error and then\n Items_Transferred (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream)\n /= Data'Length / 4;\n begin\n return Ret = OK\n and then DMA_Err = DMA_No_Error\n and then not Data_Incomplete;" + }, + { + "function_def": "function To_Word is new Ada.Unchecked_Conversion (System.Address, UInt32);", + "function_body": "function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32 with Inline_Always;\n\n DMA2D_Init_Transfer_Int : DMA2D_Sync_Procedure := null;\n DMA2D_Wait_Transfer_Int : DMA2D_Sync_Procedure := null;\n\n ------------------\n -- DMA2D_DeInit --\n ------------------\n\n procedure DMA2D_DeInit is\n begin\n RCC_Periph.AHB1ENR.DMA2DEN := False;\n DMA2D_Init_Transfer_Int := null;\n DMA2D_Wait_Transfer_Int := null;\n end DMA2D_DeInit;\n\n ----------------\n -- DMA2D_Init --\n ----------------\n\n procedure DMA2D_Init\n (Init : DMA2D_Sync_Procedure;\n Wait : DMA2D_Sync_Procedure)\n is\n begin\n if DMA2D_Init_Transfer_Int = Init then\n return;\n end if;\n\n DMA2D_DeInit;\n\n DMA2D_Init_Transfer_Int := Init;\n DMA2D_Wait_Transfer_Int := Wait;\n\n RCC_Periph.AHB1ENR.DMA2DEN := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := False;\n end DMA2D_Init;\n\n ------------\n -- Offset --\n ------------\n\n function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32\n is\n Off : constant UInt32 := UInt32 (X + Buffer.Width * Y);\n begin\n case Buffer.Color_Mode is\n when ARGB8888 =>\n return 4 * Off;\n when RGB888 =>\n return 3 * Off;\n when ARGB1555 | ARGB4444 | RGB565 | AL88 =>\n return 2 * Off;\n when L8 | AL44 | A8 =>\n return Off;\n when L4 | A4 =>\n return Off / 2;\n end case;\n end Offset;\n\n ----------------\n -- DMA2D_Fill --\n ----------------\n\n procedure DMA2D_Fill\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR.CM := As_UInt3 (Buffer.Color_Mode);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr);\n DMA2D_Periph.OOR := (LO => 0, others => <>);\n DMA2D_Periph.NLR := (NL => UInt16 (Buffer.Height),\n PL => UInt14 (Buffer.Width),\n others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill;\n\n ---------------------\n -- DMA2D_Fill_Rect --\n ---------------------\n\n procedure DMA2D_Fill_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n Off : constant UInt32 := Offset (Buffer, X, Y);\n\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode),\n others => <>);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;\n DMA2D_Periph.OOR.LO := UInt14 (Buffer.Width - Width);\n DMA2D_Periph.NLR :=\n (NL => UInt16 (Height), PL => UInt14 (Width), others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill_Rect;\n\n ---------------------\n -- DMA2D_Draw_Rect --\n ---------------------\n\n procedure DMA2D_Draw_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer)\n is\n begin\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y, Width);\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y + Height - 1, Width);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X, Y, Height);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X + Width - 1, Y, Height, True);\n end DMA2D_Draw_Rect;\n\n ---------------------\n -- DMA2D_Copy_Rect --\n ---------------------\n\n procedure DMA2D_Copy_Rect\n (Src_Buffer : DMA2D_Buffer;\n X_Src : Natural;\n Y_Src : Natural;\n Dst_Buffer : DMA2D_Buffer;\n X_Dst : Natural;\n Y_Dst : Natural;\n Bg_Buffer : DMA2D_Buffer;\n X_Bg : Natural;\n Y_Bg : Natural;\n Width : Natural;\n Height : Natural;\n Synchronous : Boolean := False)\n is\n Src_Off : constant UInt32 := Offset (Src_Buffer, X_Src, Y_Src);\n Dst_Off : constant UInt32 := Offset (Dst_Buffer, X_Dst, Y_Dst);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n if Bg_Buffer /= Null_Buffer then\n -- PFC and blending\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_BLEND);\n\n elsif Src_Buffer.Color_Mode = Dst_Buffer.Color_Mode then\n -- Direct memory transfer\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M);\n else\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_PFC);\n end if;\n\n -- SOURCE CONFIGURATION\n DMA2D_Periph.FGPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Src_Buffer.Color_Mode),\n AM => DMA2D_AM'Enum_Rep (NO_MODIF),\n ALPHA => 255,\n others => <>);\n\n if Src_Buffer.Color_Mode = L8 or else Src_Buffer.Color_Mode = L4 then\n\n if Src_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Source CLUT address required\";\n end if;\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n DMA2D_Periph.FGPFCCR.CS := (case Src_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.FGPFCCR.CCM := Src_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.FGPFCCR.START := True;\n\n while DMA2D_Periph.FGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;\n\n DMA2D_Periph.FGOR := (LO => UInt14 (Src_Buffer.Width - Width),\n others => <>);\n DMA2D_Periph.FGMAR := To_Word (Src_Buffer.Addr) + Src_Off;\n\n if Bg_Buffer /= Null_Buffer then\n declare\n Bg_Off : constant UInt32 := Offset (Bg_Buffer, X_Bg, Y_Bg);\n begin\n DMA2D_Periph.BGPFCCR.CM :=\n DMA2D_Color_Mode'Enum_Rep (Bg_Buffer.Color_Mode);\n DMA2D_Periph.BGMAR := To_Word (Bg_Buffer.Addr) + Bg_Off;\n DMA2D_Periph.BGPFCCR.CS := 0;\n DMA2D_Periph.BGPFCCR.START := False;\n DMA2D_Periph.BGOR :=\n (LO => UInt14 (Bg_Buffer.Width - Width), others => <>);\n\n if Bg_Buffer.Color_Mode = L8 or else Bg_Buffer.Color_Mode = L4 then\n\n if Bg_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Background CLUT address required\";\n end if;\n\n DMA2D_Periph.BGCMAR := To_Word (Bg_Buffer.CLUT_Addr);\n DMA2D_Periph.BGPFCCR.CS := (case Bg_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.BGPFCCR.CCM := Bg_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.BGPFCCR.START := True;\n\n while DMA2D_Periph.BGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;" + }, + { + "function_def": "procedure Demo_Timer_PWM is -- low-level demo of the PWM capabilities", + "function_body": "Period : constant := 1000;\n\n Output_Channel : constant Timer_Channel := Channel_2;\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode for Timer_4. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n\n --------------------\n -- Configure_LEDs --\n --------------------\n\n procedure Configure_LEDs;\n\n procedure Configure_LEDs is\n begin\n Enable_Clock (GPIO_D);\n\n Configure_IO\n (All_LEDs,\n (Mode_AF,\n AF => GPIO_AF_TIM4_2,\n AF_Speed => Speed_50MHz,\n AF_Output_Type => Push_Pull,\n Resistors => Floating));\n end Configure_LEDs;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_LEDs;\n\n Enable_Clock (Timer_4);\n\n Reset (Timer_4);\n\n Configure\n (Timer_4,\n Prescaler => 1,\n Period => Period,\n Clock_Divisor => Div1,\n Counter_Mode => Up);\n\n Configure_Channel_Output\n (Timer_4,\n Channel => Output_Channel,\n Mode => PWM1,\n State => Enable,\n Pulse => 0,\n Polarity => High);\n\n Set_Autoreload_Preload (Timer_4, True);\n\n Enable_Channel (Timer_4, Output_Channel);\n\n Enable (Timer_4);\n\n declare\n use STM32;\n Arg : Long_Float := 0.0;\n Pulse : UInt16;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of optimization is observable.\n begin\n loop\n Pulse := UInt16 (Long_Float (Period / 2) * (1.0 + Sine (Arg)));\n Set_Compare_Value (Timer_4, Output_Channel, Pulse);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_PWM_ADT is -- demo the higher-level PWM abstract data type", + "function_body": "Selected_Timer : STM32.Timers.Timer renames Timer_4;\n -- NOT arbitrary! We drive the on-board LEDs that are tied to the channels\n -- of Timer_4 on some boards. Not all boards have this association. If you\n -- use a difference board, select a GPIO point connected to your selected\n -- timer and drive that instead.\n\n Timer_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_TIM4_2;\n -- Note that this value MUST match the corresponding timer selected!\n\n Output_Channel : constant Timer_Channel := Channel_2; -- arbitrary\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n LED_For : constant array (Timer_Channel) of User_LED :=\n (Channel_1 => Green_LED,\n Channel_2 => Orange_LED,\n Channel_3 => Red_LED,\n Channel_4 => Blue_LED);\n\n Requested_Frequency : constant Hertz := 30_000; -- arbitrary\n\n Power_Control : PWM_Modulator;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_PWM_Timer (Selected_Timer'Access, Requested_Frequency);\n\n Power_Control.Attach_PWM_Channel\n (Selected_Timer'Access,\n Output_Channel,\n LED_For (Output_Channel),\n Timer_AF);\n\n Power_Control.Enable_Output;\n\n declare\n Arg : Long_Float := 0.0;\n Value : Percentage;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of optimization is observable.\n begin\n loop\n Value := Percentage (50.0 * (1.0 + Sine (Arg)));\n Set_Duty_Cycle (Power_Control, Value);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_DAC_Basic is", + "function_body": "Output_Channel : constant DAC_Channel := Channel_1; -- arbitrary\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel);\n -- Once the channel is enabled, the corresponding GPIO pin is automatically\n -- connected to the analog converter output. However, in order to avoid\n -- parasitic consumption, the PA4 pin (Channel_1) or PA5 pin (Channel_2)\n -- should first be configured to analog mode. See the note in the RM, page\n -- 431.\n\n procedure Print (Value : UInt32);\n -- Prints the image of the arg at a fixed location\n\n procedure Await_Button;\n -- Wait for the user to press and then release the blue user button\n\n -----------\n -- Print --\n -----------\n\n procedure Print (Value : UInt32) is\n Value_Image : constant String := Value'Img;\n begin\n LCD_Std_Out.Put (170, 52, Value_Image (2 .. Value_Image'Last) & \" \");\n end Print;\n\n ------------------\n -- Await_Button --\n ------------------\n\n procedure Await_Button is\n begin\n Await_Pressed : loop\n exit Await_Pressed when Set (User_Button_Point);\n end loop Await_Pressed;\n\n Await_Released : loop\n exit Await_Released when not Set (User_Button_Point);\n end loop Await_Released;\n end Await_Button;\n\n ------------------------\n -- Configure_DAC_GPIO --\n ------------------------\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel) is\n Output : constant GPIO_Point := (if Output_Channel = Channel_1\n then DAC_Channel_1_IO\n else DAC_Channel_2_IO);\n begin\n Enable_Clock (Output);\n Configure_IO (Output, (Mode => Mode_Analog, Resistors => Floating));\n end Configure_DAC_GPIO;\n\nbegin\n Initialize_LEDs;\n All_LEDs_Off;\n\n LCD_Std_Out.Clear_Screen;\n\n Configure_User_Button_GPIO;\n\n Configure_DAC_GPIO (Output_Channel);\n\n Enable_Clock (DAC_1);\n\n Reset (DAC_1);\n\n Select_Trigger (DAC_1, Output_Channel, Software_Trigger);\n\n Enable_Trigger (DAC_1, Output_Channel);\n\n Enable (DAC_1, Output_Channel);\n\n declare\n Value : UInt32 := 0;\n Percent : UInt32;\n\n Resolution : constant DAC_Resolution := DAC_Resolution_12_Bits;\n -- Arbitrary, change as desired. Counts will automatically adjust.\n\n Max_Counts : constant UInt32 := (if Resolution = DAC_Resolution_12_Bits\n then Max_12bit_Resolution\n else Max_8bit_Resolution);\n begin\n Put (0, 0, \"VRef+ is 2.95V\"); -- measured\n Put (0, 25, \"Button advances\");\n Put (0, 52, \"Current %:\");\n loop\n for K in UInt32 range 0 .. 10 loop\n Percent := K * 10;\n Print (Percent);\n\n Value := (Percent * Max_Counts) / 100;\n\n Set_Output\n (DAC_1,\n Output_Channel,\n Value,\n Resolution,\n Right_Aligned);\n\n Trigger_Conversion_By_Software (DAC_1, Output_Channel);\n\n Await_Button;\n end loop;\n end loop;" + }, + { + "function_def": "procedure Demo_CRC is", + "function_body": "Checksum_CPU : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses the CPU to transfer\n -- the memory block to the CRC processor\n\n Checksum_DMA : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses DMA to transfer the\n -- memory block to the CRC processor\n\n -- see the STM32Cube_FW_F4_V1.6.0\\Projects\\ CRC example for data and\n -- expected CRC checksum value\n\n Section1 : constant Block_32 :=\n (16#00001021#, 16#20423063#, 16#408450A5#, 16#60C670E7#, 16#9129A14A#, 16#B16BC18C#,\n 16#D1ADE1CE#, 16#F1EF1231#, 16#32732252#, 16#52B54294#, 16#72F762D6#, 16#93398318#,\n 16#A35AD3BD#, 16#C39CF3FF#, 16#E3DE2462#, 16#34430420#, 16#64E674C7#, 16#44A45485#,\n 16#A56AB54B#, 16#85289509#, 16#F5CFC5AC#, 16#D58D3653#, 16#26721611#, 16#063076D7#,\n 16#569546B4#, 16#B75BA77A#, 16#97198738#, 16#F7DFE7FE#, 16#C7BC48C4#, 16#58E56886#,\n 16#78A70840#, 16#18612802#, 16#C9CCD9ED#, 16#E98EF9AF#, 16#89489969#, 16#A90AB92B#,\n 16#4AD47AB7#, 16#6A961A71#, 16#0A503A33#, 16#2A12DBFD#, 16#FBBFEB9E#, 16#9B798B58#,\n 16#BB3BAB1A#, 16#6CA67C87#, 16#5CC52C22#, 16#3C030C60#, 16#1C41EDAE#, 16#FD8FCDEC#,\n 16#AD2ABD0B#, 16#8D689D49#, 16#7E976EB6#, 16#5ED54EF4#, 16#2E321E51#, 16#0E70FF9F#);\n\n Section2 : constant Block_32 :=\n (16#EFBEDFDD#, 16#CFFCBF1B#, 16#9F598F78#, 16#918881A9#, 16#B1CAA1EB#, 16#D10CC12D#,\n 16#E16F1080#, 16#00A130C2#, 16#20E35004#, 16#40257046#, 16#83B99398#, 16#A3FBB3DA#,\n 16#C33DD31C#, 16#E37FF35E#, 16#129022F3#, 16#32D24235#, 16#52146277#, 16#7256B5EA#,\n 16#95A88589#, 16#F56EE54F#, 16#D52CC50D#, 16#34E224C3#, 16#04817466#, 16#64475424#,\n 16#4405A7DB#, 16#B7FA8799#, 16#E75FF77E#, 16#C71DD73C#, 16#26D336F2#, 16#069116B0#,\n 16#76764615#, 16#5634D94C#, 16#C96DF90E#, 16#E92F99C8#, 16#B98AA9AB#, 16#58444865#,\n 16#78066827#, 16#18C008E1#, 16#28A3CB7D#, 16#DB5CEB3F#, 16#FB1E8BF9#, 16#9BD8ABBB#,\n 16#4A755A54#, 16#6A377A16#, 16#0AF11AD0#, 16#2AB33A92#, 16#ED0FDD6C#, 16#CD4DBDAA#,\n 16#AD8B9DE8#, 16#8DC97C26#, 16#5C644C45#, 16#3CA22C83#, 16#1CE00CC1#, 16#EF1FFF3E#,\n 16#DF7CAF9B#, 16#BFBA8FD9#, 16#9FF86E17#, 16#7E364E55#, 16#2E933EB2#, 16#0ED11EF0#);\n\n -- expected CRC value for the data above is 379E9F06 hex, or 933142278 dec\n Expected_Checksum : constant UInt32 := 933142278;\n\n Next_DMA_Interrupt : DMA_Interrupt;\n\n procedure Panic with No_Return;\n -- flash the on-board LEDs, indefinitely, to indicate a failure\n\n procedure Panic is\n begin\n loop\n Toggle_LEDs (All_LEDs);\n delay until Clock + Milliseconds (100);\n end loop;\n end Panic;\n\nbegin\n Clear_Screen;\n Initialize_LEDs;\n\n Enable_Clock (CRC_Unit);\n\n -- get the checksum using the CPU to transfer memory to the CRC processor;\n -- verify it is the expected value\n\n Update_CRC (CRC_Unit, Input => Section1, Output => Checksum_CPU);\n Update_CRC (CRC_Unit, Input => Section2, Output => Checksum_CPU);\n\n Put_Line (\"CRC:\" & Checksum_CPU'Img);\n\n if Checksum_CPU /= Expected_Checksum then\n Panic;\n end if;\n\n -- get the checksum using DMA to transfer memory to the CRC processor\n\n Enable_Clock (Controller);\n\n Reset (Controller);\n\n Reset_Calculator (CRC_Unit);\n\n Update_CRC (CRC_Unit, Controller'Access, Stream, Input => Section1);\n\n DMA_IRQ_Handler.Await_Event (Next_DMA_Interrupt);\n\n if Next_DMA_Interrupt /= Transfer_Complete_Interrupt then\n Panic;\n end if;\n\n -- In this code fragment we use the approach suited for the case in which\n -- we are calculating the CRC for a section of system memory rather than a\n -- block of application data. We pretend that Section2 is a memory section.\n -- All we need is a known starting address and a known length. Given that,\n -- we can create a view of it as if it is an object of type Block_32 (or\n -- whichever block type is appropriate).\n declare\n subtype Memory_Section is Block_32 (1 .. Section2'Length);\n type Section_Pointer is access all Memory_Section with Storage_Size => 0;\n function As_Memory_Section_Reference is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Section_Pointer);\n begin\n Update_CRC\n (CRC_Unit,\n Controller'Access,\n Stream,\n Input => As_Memory_Section_Reference (Section2'Address).all);" + }, + { + "function_def": "procedure DSB is", + "function_body": "begin\n Asm (\"dsb\", Volatile => True);\n end DSB;\n\n ---------\n -- ISB --\n ---------\n\n procedure ISB is\n begin\n Asm (\"isb\", Volatile => True);\n end ISB;\n\n -----------------------\n -- Cache_Maintenance --\n -----------------------\n\n procedure Cache_Maintenance\n (Start : System.Address;\n Len : Natural)\n is\n begin\n if not D_Cache_Enabled then\n return;\n end if;\n\n declare\n function To_U32 is new Ada.Unchecked_Conversion\n (System.Address, UInt32);\n\n Op_Size : Integer_32 := Integer_32 (Len);\n Op_Addr : UInt32 := To_U32 (Start);\n Reg : UInt32 with Volatile, Address => Reg_Address;\n\n begin\n DSB;\n\n while Op_Size > 0 loop\n Reg := Op_Addr;\n Op_Addr := Op_Addr + Data_Cache_Line_Size;\n Op_Size := Op_Size - Integer_32 (Data_Cache_Line_Size);\n end loop;\n\n DSB;\n ISB;" + }, + { + "function_def": "procedure TC_FAT_Read is", + "function_body": "function Check_Dir (Dirname : String) return Boolean;\n function Check_File (Basename : String;\n Dirname : String)\n return Boolean;\n function Check_Expected_Number return Boolean;\n\n Number_Of_Files_Checked : Natural := 0;\n\n ---------------\n -- Check_Dir --\n ---------------\n\n function Check_Dir (Dirname : String) return Boolean is\n DD : Directory_Descriptor;\n Status : File_IO.Status_Code;\n begin\n Put_Line (\"Checking directory: '\" & Dirname & \"'\");\n Status := Open (DD, Dirname);\n\n if Status /= OK then\n Put_Line (\"Cannot open directory: '\" & Dirname & \"'\");\n Put_Line (\"Status: \" & Status'Img);\n return False;\n end if;\n\n loop\n declare\n Ent : constant Directory_Entry := Read (DD);\n begin\n if Ent /= Invalid_Dir_Entry then\n if Ent.Name = \".\" or else Ent.Name = \"..\" then\n null; -- do nothing\n elsif Ent.Subdirectory then\n\n if not Check_Dir (Dirname & \"/\" & Ent.Name) then\n return False;\n end if;\n elsif not Ent.Symlink then\n if not Check_File (Ent.Name, Dirname) then\n return False;\n end if;\n end if;\n else\n exit;\n end if;" + }, + { + "function_def": "procedure TC_FAT_Write is", + "function_body": "use type HAL.Filesystem.Status_Code;\n\n package Hash renames GNAT.MD5;\n\n Test_File_Size : constant := 2000;\n\n function Write_File (Filename : String) return String;\n function Check_File (Filename : String; Md5 : String) return Boolean;\n function Delete_Tree (Filename : String) return Boolean;\n function Check_Read_Test_Dir return Boolean;\n\n ----------------\n -- Write_File --\n ----------------\n\n function Write_File (Filename : String) return String is\n FD : File_Descriptor;\n Status : Status_Code;\n\n Context : aliased GNAT.MD5.Context := GNAT.MD5.Initial_Context;\n\n Buffer : Ada.Streams.Stream_Element_Array (1 .. Test_File_Size);\n Last : Ada.Streams.Stream_Element_Offset;\n Size : File_Size;\n use type Ada.Streams.Stream_Element_Offset;\n\n begin\n Status := Open (FD, Filename, Write_Only);\n\n if Status /= OK then\n Put_Line (\"Cannot open file: '\" & Filename & \"'\");\n Put_Line (\"Status: \" & Status'Img);\n return \"\";\n end if;\n\n Size := Buffer'Length;\n Buffer := (others => 42);\n Last := Ada.Streams.Stream_Element_Offset (Size);\n Hash.Update (Context, Buffer (1 .. Last));\n\n if Write (FD, Buffer'Address, Size) /= Size then\n Put_Line (\"Cannot write file: '\" & Filename & \"'\");\n Put_Line (\"Status: \" & Status'Img);\n return \"\";\n end if;\n\n Close (FD);\n return Hash.Digest (Context);\n end Write_File;\n\n ----------------\n -- Check_File --\n ----------------\n\n function Check_File (Filename : String;\n Md5 : String)\n return Boolean\n is\n FD : File_Descriptor;\n Status : Status_Code;\n begin\n Status := Open (FD, Filename, Read_Only);\n\n if Status /= OK then\n Put_Line (\"Cannot open file: '\" & Filename & \"'\");\n Put_Line (\"Status: \" & Status'Img);\n return False;\n end if;\n\n if Size (FD) /= Test_File_Size then\n Put_Line (\"Error: wrong file size: \" & Size (FD)'Img &\n \" (expected \" & Test_File_Size'Img & \")\");\n return False;\n end if;\n\n declare\n Hash_Str : constant String := Compare_Files.Compute_Hash (FD);\n begin\n if Hash_Str /= Md5 then\n Put_Line (\"Error: Hash is different than filename\");\n return False;\n else\n return True;\n end if;" + }, + { + "function_def": "procedure TC_Virtual_Wire is", + "function_body": "pragma Assertion_Policy (Assert => Check);\n\n No_Pull_Wire : Virtual_Wire (Default_Pull => Floating,\n Max_Points => 2);\n\n Pull_Up_Wire : Virtual_Wire (Default_Pull => Pull_Up,\n Max_Points => 2);\n\n Pull_Down_Wire : Virtual_Wire (Default_Pull => Pull_Down,\n Max_Points => 2);\n\n Unref : Boolean with Unreferenced;\nbegin\n\n -- Default mode --\n\n pragma Assert (No_Pull_Wire.Point (1).Mode = Input,\n \"Default point mode should be input\");\n\n -- State with only inputs and a wire pull resistor --\n\n pragma Assert (Pull_Up_Wire.Point (1).Set,\n \"Default state of pull up wire should be high\");\n pragma Assert (not Pull_Down_Wire.Point (1).Set,\n \"Default state of pull down wire should be low\");\n\n -- State with only inputs and a point pull resistor --\n\n pragma Assert (No_Pull_Wire.Point (1).Set_Pull_Resistor (Pull_Up),\n \"It should be possible to change the pull resitor\");\n\n pragma Assert (No_Pull_Wire.Point (1).Set,\n \"State of wire with one pull up point should be high\");\n\n\n Unref := No_Pull_Wire.Point (1).Set_Pull_Resistor (Pull_Down);\n pragma Assert (not No_Pull_Wire.Point (1).Set,\n \"State of wire with one pull down point should be low\");\n\n -- State with one input one output and no pull resistor --\n\n pragma Assert (No_Pull_Wire.Point (1).Set_Mode (Input),\n \"It should be possible to change the mode\");\n Unref := No_Pull_Wire.Point (1).Set_Pull_Resistor (Pull_Down);\n\n Unref := No_Pull_Wire.Point (2).Set_Mode (Output);\n Unref := No_Pull_Wire.Point (2).Set_Pull_Resistor (Floating);\n\n No_Pull_Wire.Point (2).Set;\n pragma Assert (No_Pull_Wire.Point (1).Set, \"Should be high\");\n No_Pull_Wire.Point (2).Clear;\n pragma Assert (not No_Pull_Wire.Point (1).Set, \"Should be low\");\n\n -- State with one input one output and point pull resistor --\n\n Unref := No_Pull_Wire.Point (1).Set_Mode (Input);\n Unref := No_Pull_Wire.Point (1).Set_Pull_Resistor (Pull_Up);\n\n Unref := No_Pull_Wire.Point (2).Set_Mode (Output);\n Unref := No_Pull_Wire.Point (2).Set_Pull_Resistor (Floating);\n\n No_Pull_Wire.Point (2).Set;\n pragma Assert (No_Pull_Wire.Point (1).Set, \"Should be high\");\n No_Pull_Wire.Point (2).Clear;\n pragma Assert (not No_Pull_Wire.Point (1).Set, \"Should be low\");\n\n Unref := No_Pull_Wire.Point (1).Set_Pull_Resistor (Pull_Down);\n\n No_Pull_Wire.Point (2).Set;\n pragma Assert (No_Pull_Wire.Point (1).Set, \"Should be high\");\n No_Pull_Wire.Point (2).Clear;\n pragma Assert (not No_Pull_Wire.Point (1).Set, \"Should be low\");\n\n -- Opposite pull on the same wire --\n declare\n begin\n Unref := Pull_Down_Wire.Point (1).Set_Pull_Resistor (Pull_Up);\n exception\n when Invalid_Configuration =>\n Put_Line (\"Expected exception on oppposite pull (1)\");" + }, + { + "function_def": "procedure TC_Log_Priorities is", + "function_body": "Maximum_Message_Length : constant := 64;\n\n package Log is new Logging_With_Priority\n (Priorities => Natural,\n Maximum_Message_Length => Maximum_Message_Length,\n Maximum_Number_Of_Messages => 6);\n\n procedure Pop_And_Print;\n procedure Fill_Queue;\n procedure Empty_Queue;\n\n -------------------\n -- Pop_And_Print --\n -------------------\n\n procedure Pop_And_Print is\n Str : String (1 .. Maximum_Message_Length);\n Length : Natural;\n Prio : Natural;\n begin\n Log.Pop (Str, Length, Prio);\n if Length /= 0 then\n Ada.Text_IO.Put_Line (\"Prio:\" & Prio'Img & \" -> \" &\n Str (Str'First .. Str'First + Length - 1));\n else\n Ada.Text_IO.Put_Line (\"Pop : The queue is empty\");\n end if;\n end Pop_And_Print;\n\n ----------------\n -- Fill_Queue --\n ----------------\n\n procedure Fill_Queue is\n begin\n Log.Log_Line (\"Prio 1 - 1\", 1);\n Log.Log_Line (\"Prio 2 - 1\", 2);\n Log.Log_Line (\"Prio 5 - 1\", 5);\n Log.Log_Line (\"Prio 1 - 2\", 1);\n Log.Log_Line (\"Prio 5 - 2\", 5);\n Log.Log_Line (\"Prio 8 - 1\", 8);\n\n if not Log.Full then\n raise Program_Error with \"The queue should be full\";\n end if;\n\n end Fill_Queue;\n\n -----------------\n -- Empty_Queue --\n -----------------\n\n procedure Empty_Queue is\n begin\n -- Empty the queue\n for Cnt in 1 .. 6 loop\n Pop_And_Print;\n end loop;\n\n if not Log.Empty then\n raise Program_Error with \"The queue should be empty\";\n end if;\n end Empty_Queue;\n\n\nbegin\n Ada.Text_IO.Put_Line (\"--- Log test begin ---\");\n\n declare\n begin\n Ada.Text_IO.Put_Line (\"--- Test priorities ---\");\n\n -- Try to print but there should be nothing in the queue\n Pop_And_Print;\n\n -- Insert a few messages with various priorities to check that the messages\n -- will be properly sorted.\n Fill_Queue;\n Empty_Queue;\n\n -- Try to print but there should be nothing in the queue\n Pop_And_Print;" + }, + { + "function_def": "function To_Char is new Ada.Unchecked_Conversion (Source => UInt8,", + "function_body": "Target => Character);\n function To_UInt8 is new Ada.Unchecked_Conversion (Source => Character,\n Target => UInt8);\n\n procedure Write (This : in out TP_Device; Cmd : String);\n procedure Read (This : in out TP_Device; Str : out String);\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : in out TP_Device; Cmd : String) is\n Status : UART_Status;\n Data : UART_Data_8b (Cmd'Range);\n begin\n\n for Index in Cmd'Range loop\n Data (Index) := To_UInt8 (Cmd (Index));\n end loop;\n\n This.Port.Transmit (Data, Status);\n\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n -- This.Time.Delay_Microseconds ((11 * 1000000 / 19_2000) + Cmd'Length);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read (This : in out TP_Device; Str : out String) is\n Status : UART_Status;\n Data : UART_Data_8b (Str'Range);\n begin\n This.Port.Receive (Data, Status);\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n\n for Index in Str'Range loop\n Str (Index) := To_Char (Data (Index));\n end loop;\n end Read;\n\n ----------------------\n -- Set_Line_Spacing --\n ----------------------\n\n procedure Set_Line_Spacing (This : in out TP_Device; Spacing : UInt8) is\n begin\n Write (This, ASCII.ESC & '3' & To_Char (Spacing));\n end Set_Line_Spacing;\n\n ---------------\n -- Set_Align --\n ---------------\n\n procedure Set_Align (This : in out TP_Device; Align : Text_Align) is\n Mode : Character;\n begin\n case Align is\n when Left => Mode := '0';\n when Center => Mode := '1';\n when Right => Mode := '2';\n end case;\n Write (This, ASCII.ESC & 'a' & Mode);\n end Set_Align;\n\n ----------------------\n -- Set_Font_Enlarge --\n ----------------------\n\n procedure Set_Font_Enlarge (This : in out TP_Device; Height, Width : Boolean) is\n Data : UInt8 := 0;\n begin\n if Height then\n Data := Data or 16#01#;\n end if;\n if Width then\n Data := Data or 16#10#;\n end if;\n Write (This, ASCII.GS & '!' & To_Char (Data));\n end Set_Font_Enlarge;\n\n --------------\n -- Set_Bold --\n --------------\n\n procedure Set_Bold (This : in out TP_Device; Bold : Boolean) is\n begin\n Write (This, ASCII.ESC & 'E' & To_Char (if Bold then 1 else 0));\n end Set_Bold;\n\n ----------------------\n -- Set_Double_Width --\n ----------------------\n\n procedure Set_Double_Width (This : in out TP_Device; Double : Boolean) is\n begin\n if Double then\n Write (This, ASCII.ESC & ASCII.SO);\n else\n Write (This, ASCII.ESC & ASCII.DC4);\n end if;\n end Set_Double_Width;\n\n ----------------\n -- Set_UpDown --\n ----------------\n\n procedure Set_UpDown (This : in out TP_Device; UpDown : Boolean) is\n begin\n Write (This, ASCII.ESC & '{' & To_Char (if UpDown then 1 else 0));\n end Set_UpDown;\n\n ------------------\n -- Set_Reversed --\n ------------------\n\n procedure Set_Reversed (This : in out TP_Device; Reversed : Boolean) is\n begin\n Write (This, ASCII.GS & 'B' & To_Char (if Reversed then 1 else 0));\n end Set_Reversed;\n\n --------------------------\n -- Set_Underline_Height --\n --------------------------\n\n procedure Set_Underline_Height (This : in out TP_Device; Height : Underline_Height) is\n begin\n Write (This, ASCII.ESC & '-' & To_Char (Height));\n end Set_Underline_Height;\n\n -----------------------\n -- Set_Character_Set --\n -----------------------\n\n procedure Set_Character_Set (This : in out TP_Device; Set : Character_Set) is\n begin\n Write (This, ASCII.ESC & 't' & To_Char (Character_Set'Pos (Set)));\n end Set_Character_Set;\n\n ----------\n -- Feed --\n ----------\n\n procedure Feed (This : in out TP_Device; Rows : UInt8) is\n begin\n Write (This, ASCII.ESC & 'd' & To_Char (Rows));\n end Feed;\n\n ------------------\n -- Print_Bitmap --\n ------------------\n\n procedure Print_Bitmap (This : in out TP_Device;\n BM : Thermal_Printer_Bitmap)\n is\n Nbr_Of_Rows : constant Natural := BM'Length (2);\n Nbr_Of_Columns : constant Natural := BM'Length (1);\n Str : String (1 .. Nbr_Of_Columns / 8);\n begin\n\n Write (This, ASCII.DC2 & 'v' &\n To_Char (UInt8 (Nbr_Of_Rows rem 256)) &\n To_Char (UInt8 (Nbr_Of_Rows / 256)));\n\n for Row in 0 .. Nbr_Of_Rows - 1 loop\n for Colum in 0 .. (Nbr_Of_Columns / 8) - 1 loop\n declare\n BM_Index : constant Natural := BM'First (1) + Colum * 8;\n Str_Index : constant Natural := Str'First + Colum;\n B : UInt8 := 0;\n begin\n for X in 0 .. 7 loop\n B := B or (if BM (BM_Index + X,\n BM'First (2) + Row)\n then 2**X else 0);\n end loop;\n Str (Str_Index) := To_Char (B);" + }, + { + "function_def": "function As_UInt8 is new Ada.Unchecked_Conversion", + "function_body": "(Source => High_Pass_Filter_Mode, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => High_Pass_Cutoff_Frequency, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Power_Mode_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Output_Data_Rate_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Axes_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Bandwidth_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Block_Data_Update_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Endian_Data_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Full_Scale_Selection, Target => UInt8);\n\n type Angle_Rate_Pointer is access all Angle_Rate with Storage_Size => 0;\n\n function As_Angle_Rate_Pointer is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Angle_Rate_Pointer);\n -- So that we can treat the address of a UInt8 as a pointer to a two-UInt8\n -- sequence representing a signed integer quantity.\n\n procedure Swap2 (Location : System.Address) with Inline;\n -- Swaps the two UInt8s at Location and Location+1\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean);\n -- Enable or disable SPI mode communication with the device. This is named\n -- \"chip select\" in other demos/examples.\n\n ----------------\n -- Initialize --\n ----------------\n\n procedure Initialize\n (This : in out Three_Axis_Gyroscope;\n Port : Any_SPI_Port;\n Chip_Select : Any_GPIO_Point)\n is\n begin\n This.Port := Port;\n This.CS := Chip_Select;\n\n SPI_Mode (This, Enabled => False);\n end Initialize;\n\n -----------------\n -- SPI_Mode --\n -----------------\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean) is\n -- When the pin is low (cleared), the device is in SPI mode.\n -- When the pin is high (set), the device is in I2C mode.\n -- We want SPI mode communication, so Enabled, when True,\n -- means we must drive the pin low.\n begin\n if Enabled then\n This.CS.Clear;\n else\n This.CS.Set;\n end if;\n end SPI_Mode;\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : Three_Axis_Gyroscope; Addr : Register; Data : UInt8)\n is\n Status : SPI_Status;\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr)), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Transmit (SPI_Data_8b'(1 => Data), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n SPI_Mode (This, Enabled => False);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Data : out UInt8)\n is\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD),\n Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Data := Tmp_Data (Tmp_Data'First);\n\n SPI_Mode (This, Enabled => False);\n end Read;\n\n ----------------\n -- Read_UInt8s --\n ----------------\n\n procedure Read_UInt8s\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Buffer : out SPI_Data_8b;\n Count : Natural)\n is\n Index : Natural := Buffer'First;\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit\n (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD or MultiUInt8_CMD),\n Status);\n\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n for K in 1 .. Count loop\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Buffer (Index) := Tmp_Data (Tmp_Data'First);\n Index := Index + 1;\n end loop;\n\n SPI_Mode (This, Enabled => False);\n end Read_UInt8s;\n\n ---------------\n -- Configure --\n ---------------\n\n procedure Configure\n (This : in out Three_Axis_Gyroscope;\n Power_Mode : Power_Mode_Selection;\n Output_Data_Rate : Output_Data_Rate_Selection;\n Axes_Enable : Axes_Selection;\n Bandwidth : Bandwidth_Selection;\n BlockData_Update : Block_Data_Update_Selection;\n Endianness : Endian_Data_Selection;\n Full_Scale : Full_Scale_Selection)\n is\n Ctrl1 : UInt8;\n Ctrl4 : UInt8;\n begin\n Ctrl1 := As_UInt8 (Power_Mode) or\n As_UInt8 (Output_Data_Rate) or\n As_UInt8 (Axes_Enable) or\n As_UInt8 (Bandwidth);\n\n Ctrl4 := As_UInt8 (BlockData_Update) or\n As_UInt8 (Endianness) or\n As_UInt8 (Full_Scale);\n\n Write (This, CTRL_REG1, Ctrl1);\n Write (This, CTRL_REG4, Ctrl4);\n end Configure;\n\n -----------\n -- Sleep --\n -----------\n\n procedure Sleep (This : in out Three_Axis_Gyroscope) is\n Ctrl1 : UInt8;\n Sleep_Mode : constant := 2#1000#; -- per the Datasheet, Table 22, pg 32\n begin\n Read (This, CTRL_REG1, Ctrl1);\n Ctrl1 := Ctrl1 or Sleep_Mode;\n Write (This, CTRL_REG1, Ctrl1);\n end Sleep;\n\n --------------------------------\n -- Configure_High_Pass_Filter --\n --------------------------------\n\n procedure Configure_High_Pass_Filter\n (This : in out Three_Axis_Gyroscope;\n Mode_Selection : High_Pass_Filter_Mode;\n Cutoff_Frequency : High_Pass_Cutoff_Frequency)\n is\n Ctrl2 : UInt8;\n begin\n -- note that the two high-order bits must remain zero, per the datasheet\n Ctrl2 := As_UInt8 (Mode_Selection) or As_UInt8 (Cutoff_Frequency);\n Write (This, CTRL_REG2, Ctrl2);\n end Configure_High_Pass_Filter;\n\n -----------------------------\n -- Enable_High_Pass_Filter --\n -----------------------------\n\n procedure Enable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set HPen bit\n Ctrl5 := Ctrl5 or HighPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_High_Pass_Filter;\n\n ------------------------------\n -- Disable_High_Pass_Filter --\n ------------------------------\n\n procedure Disable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not HighPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_High_Pass_Filter;\n\n ----------------------------\n -- Enable_Low_Pass_Filter --\n ----------------------------\n\n procedure Enable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or LowPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_Low_Pass_Filter;\n\n -----------------------------\n -- Disable_Low_Pass_Filter --\n -----------------------------\n\n procedure Disable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not LowPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_Low_Pass_Filter;\n\n ---------------------\n -- Reference_Value --\n ---------------------\n\n function Reference_Value (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Reference, Result);\n return Result;\n end Reference_Value;\n\n -------------------\n -- Set_Reference --\n -------------------\n\n procedure Set_Reference (This : in out Three_Axis_Gyroscope; Value : UInt8) is\n begin\n Write (This, Reference, Value);\n end Set_Reference;\n\n -----------------\n -- Data_Status --\n -----------------\n\n function Data_Status (This : Three_Axis_Gyroscope) return Gyro_Data_Status is\n Result : UInt8;\n function As_Gyro_Data_Status is\n new Ada.Unchecked_Conversion (Source => UInt8,\n Target => Gyro_Data_Status);\n begin\n Read (This, Status, Result);\n return As_Gyro_Data_Status (Result);\n end Data_Status;\n\n ---------------\n -- Device_Id --\n ---------------\n\n function Device_Id (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Who_Am_I, Result);\n return Result;\n end Device_Id;\n\n -----------------\n -- Temperature --\n -----------------\n\n function Temperature (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, OUT_Temp, Result);\n return Result;\n end Temperature;\n\n ------------\n -- Reboot --\n ------------\n\n procedure Reboot (This : Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set the boot bit\n Ctrl5 := Ctrl5 or Boot_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Reboot;\n\n ----------------------------\n -- Full_Scale_Sensitivity --\n ----------------------------\n\n function Full_Scale_Sensitivity (This : Three_Axis_Gyroscope) return Float is\n Ctrl4 : UInt8;\n Result : Float;\n Fullscale_Selection : UInt8;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Fullscale_Selection := Ctrl4 and Fullscale_Selection_Bits;\n\n if Fullscale_Selection = L3GD20_Fullscale_250'Enum_Rep then\n Result := Sensitivity_250dps;\n elsif Fullscale_Selection = L3GD20_Fullscale_500'Enum_Rep then\n Result := Sensitivity_500dps;\n else\n Result := Sensitivity_2000dps;\n end if;\n\n return Result;\n end Full_Scale_Sensitivity;\n\n -------------------------\n -- Get_Raw_Angle_Rates --\n -------------------------\n\n procedure Get_Raw_Angle_Rates\n (This : Three_Axis_Gyroscope;\n Rates : out Angle_Rates)\n is\n\n Ctrl4 : UInt8;\n\n UInt8s_To_Read : constant Integer := 6; -- ie, three 2-UInt8 integers\n -- the number of UInt8s in an Angle_Rates record object\n\n Received : SPI_Data_8b (1 .. UInt8s_To_Read);\n\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n -- The above has the effect of separate reads, as follows:\n -- Read (This, OUT_X_L, Received (1));\n -- Read (This, OUT_X_H, Received (2));\n -- Read (This, OUT_Y_L, Received (3));\n -- Read (This, OUT_Y_H, Received (4));\n -- Read (This, OUT_Z_L, Received (5));\n -- Read (This, OUT_Z_H, Received (6));\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n Swap2 (Received (1)'Address);\n Swap2 (Received (3)'Address);\n Swap2 (Received (5)'Address);\n end if;\n\n Rates.X := As_Angle_Rate_Pointer (Received (1)'Address).all;\n Rates.Y := As_Angle_Rate_Pointer (Received (3)'Address).all;\n Rates.Z := As_Angle_Rate_Pointer (Received (5)'Address).all;\n end Get_Raw_Angle_Rates;\n\n --------------------------\n -- Configure_Interrupt1 --\n --------------------------\n\n procedure Configure_Interrupt1\n (This : in out Three_Axis_Gyroscope;\n Triggers : Threshold_Event_List;\n Latched : Boolean := False;\n Active_Edge : Interrupt1_Active_Edge := L3GD20_Interrupt1_High_Edge;\n Combine_Events : Boolean := False;\n Sample_Count : Sample_Counter := 0)\n is\n Config : UInt8;\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and 16#DF#;\n Ctrl3 := Ctrl3 or Active_Edge'Enum_Rep;\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n\n if Sample_Count > 0 then\n Set_Duration_Counter (This, Sample_Count);\n end if;\n\n Config := 0;\n\n if Latched then\n Config := Config or Int1_Latch_Enable_Bit;\n end if;\n\n if Combine_Events then\n Config := Config or Logically_And_Or_Events_Bit;\n end if;\n\n for Event of Triggers loop\n Config := Config or Axes_Interrupt_Enablers (Event.Axis);\n end loop;\n\n Write (This, INT1_CFG, Config);\n\n for Event of Triggers loop\n Set_Threshold (This, Event.Axis, Event.Threshold);\n end loop;\n end Configure_Interrupt1;\n\n ----------------------------\n -- Set_Interrupt_Pin_Mode --\n ----------------------------\n\n procedure Set_Interrupt_Pin_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : Pin_Modes)\n is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not Interrupt_Pin_Mode_Bit);\n Ctrl3 := Ctrl3 or Mode'Enum_Rep;\n Write (This, CTRL_REG3, Ctrl3);\n end Set_Interrupt_Pin_Mode;\n\n -----------------------\n -- Enable_Interrupt1 --\n -----------------------\n\n procedure Enable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n end Enable_Interrupt1;\n\n ------------------------\n -- Disable_Interrupt1 --\n ------------------------\n\n procedure Disable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not INT1_Interrupt_Enable);\n Write (This, CTRL_REG3, Ctrl3);\n end Disable_Interrupt1;\n\n -----------------------\n -- Interrupt1_Status --\n -----------------------\n\n function Interrupt1_Source (This : Three_Axis_Gyroscope) return Interrupt1_Sources is\n Result : UInt8;\n function As_Interrupt_Source is new Ada.Unchecked_Conversion\n (Source => UInt8, Target => Interrupt1_Sources);\n begin\n Read (This, INT1_SRC, Result);\n return As_Interrupt_Source (Result);\n end Interrupt1_Source;\n\n --------------------------\n -- Set_Duration_Counter --\n --------------------------\n\n procedure Set_Duration_Counter\n (This : in out Three_Axis_Gyroscope;\n Value : Sample_Counter)\n is\n Wait_Bit : constant := 2#1000_0000#;\n begin\n Write (This, INT1_Duration, UInt8 (Value) or Wait_Bit);\n end Set_Duration_Counter;\n\n ------------------\n -- Enable_Event --\n ------------------\n\n procedure Enable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config or Axes_Interrupt_Enablers (Event);\n Write (This, INT1_CFG, Config);\n end Enable_Event;\n\n -------------------\n -- Disable_Event --\n -------------------\n\n procedure Disable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config and (not Axes_Interrupt_Enablers (Event));\n Write (This, INT1_CFG, Config);\n end Disable_Event;\n\n -------------------\n -- Set_Threshold --\n -------------------\n\n procedure Set_Threshold\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts;\n Value : Axis_Sample_Threshold)\n is\n begin\n case Event is\n when Z_High_Interrupt | Z_Low_Interrupt =>\n Write (This, INT1_TSH_ZL, UInt8 (Value));\n Write (This, INT1_TSH_ZH, UInt8 (Shift_Right (Value, 8)));\n\n when Y_High_Interrupt | Y_Low_Interrupt =>\n Write (This, INT1_TSH_YL, UInt8 (Value));\n Write (This, INT1_TSH_YH, UInt8 (Shift_Right (Value, 8)));\n\n when X_High_Interrupt | X_Low_Interrupt =>\n Write (This, INT1_TSH_XL, UInt8 (Value));\n Write (This, INT1_TSH_XH, UInt8 (Shift_Right (Value, 8)));\n end case;\n end Set_Threshold;\n\n -------------------\n -- Set_FIFO_Mode --\n -------------------\n\n procedure Set_FIFO_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : FIFO_Modes)\n is\n FIFO : UInt8;\n begin\n Read (This, FIFO_CTRL, FIFO);\n FIFO := FIFO and (not FIFO_Mode_Bits); -- clear the current bits\n FIFO := FIFO or Mode'Enum_Rep;\n Write (This, FIFO_CTRL, FIFO);\n end Set_FIFO_Mode;\n\n -----------------\n -- Enable_FIFO --\n -----------------\n\n procedure Enable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or FIFO_Enable_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_FIFO;\n\n ------------------\n -- Disable_FIFO --\n ------------------\n\n procedure Disable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 and (not FIFO_Enable_Bit);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_FIFO;\n\n ------------------------\n -- Set_FIFO_Watermark --\n ------------------------\n\n procedure Set_FIFO_Watermark\n (This : in out Three_Axis_Gyroscope;\n Level : FIFO_Level)\n is\n Value : UInt8;\n begin\n Read (This, FIFO_CTRL, Value);\n Value := Value and (not Watermark_Threshold_Bits); -- clear the bits\n Value := Value or UInt8 (Level);\n Write (This, FIFO_CTRL, Value);\n end Set_FIFO_Watermark;\n\n ------------------------------\n -- Get_Raw_Angle_Rates_FIFO --\n ------------------------------\n\n procedure Get_Raw_Angle_Rates_FIFO\n (This : in out Three_Axis_Gyroscope;\n Buffer : out Angle_Rates_FIFO_Buffer)\n is\n Ctrl4 : UInt8;\n\n Angle_Rate_Size : constant Integer := 6; -- UInt8s\n UInt8s_To_Read : constant Integer := Buffer'Length * Angle_Rate_Size;\n Received : SPI_Data_8b (0 .. UInt8s_To_Read - 1)\n with Alignment => 2;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n declare\n J : Integer := 0;\n begin\n for K in Received'First .. Received'Last / 2 loop\n Swap2 (Received (J)'Address);\n J := J + 2;\n end loop;" + }, + { + "function_def": "function To_Map is new Ada.Unchecked_Conversion", + "function_body": "(SPAD_Map_Bytes, SPAD_Map);\n function To_Bytes is new Ada.Unchecked_Conversion\n (SPAD_Map, SPAD_Map_Bytes);\n\n SPAD_Count : UInt8;\n SPAD_Is_Aperture : Boolean;\n Ref_SPAD_Map_Bytes : SPAD_Map_Bytes;\n Ref_SPAD_Map : SPAD_Map;\n First_SPAD : UInt8;\n SPADS_Enabled : UInt8;\n Timing_Budget : UInt32;\n\n begin\n Status := SPAD_Info (This, SPAD_Count, SPAD_Is_Aperture);\n\n if not Status then\n return;\n end if;\n\n Read\n (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n Ref_SPAD_Map := To_Map (Ref_SPAD_Map_Bytes);\n\n -- Set reference spads\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_REF_EN_START_OFFSET,\n UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD,\n UInt8'(16#2C#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_GLOBAL_CONFIG_REF_EN_START_SELECT,\n UInt8'(16#B4#), Status);\n end if;\n\n if Status then\n if SPAD_Is_Aperture then\n First_SPAD := 13;\n else\n First_SPAD := 1;\n end if;\n\n SPADS_Enabled := 0;\n\n for J in UInt8 range 1 .. 48 loop\n\n if J < First_SPAD or else SPADS_Enabled = SPAD_Count then\n -- This bit is lower than the first one that should be enabled,\n -- or SPAD_Count bits have already been enabled, so zero this\n -- bit\n Ref_SPAD_Map (J) := False;\n\n elsif Ref_SPAD_Map (J) then\n SPADS_Enabled := SPADS_Enabled + 1;\n end if;\n end loop;\n end if;\n\n if Status then\n Ref_SPAD_Map_Bytes := To_Bytes (Ref_SPAD_Map);\n Write (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n end if;\n\n -- Load tuning Settings\n -- default tuning settings from vl53l0x_tuning.h\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#09#, UInt8'(16#00#), Status);\n Write (This, 16#10#, UInt8'(16#00#), Status);\n Write (This, 16#11#, UInt8'(16#00#), Status);\n\n Write (This, 16#24#, UInt8'(16#01#), Status);\n Write (This, 16#25#, UInt8'(16#FF#), Status);\n Write (This, 16#75#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#4E#, UInt8'(16#2C#), Status);\n Write (This, 16#48#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#20#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#09#), Status);\n Write (This, 16#54#, UInt8'(16#00#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#32#, UInt8'(16#03#), Status);\n Write (This, 16#40#, UInt8'(16#83#), Status);\n Write (This, 16#46#, UInt8'(16#25#), Status);\n Write (This, 16#60#, UInt8'(16#00#), Status);\n Write (This, 16#27#, UInt8'(16#00#), Status);\n Write (This, 16#50#, UInt8'(16#06#), Status);\n Write (This, 16#51#, UInt8'(16#00#), Status);\n Write (This, 16#52#, UInt8'(16#96#), Status);\n Write (This, 16#56#, UInt8'(16#08#), Status);\n Write (This, 16#57#, UInt8'(16#30#), Status);\n Write (This, 16#61#, UInt8'(16#00#), Status);\n Write (This, 16#62#, UInt8'(16#00#), Status);\n Write (This, 16#64#, UInt8'(16#00#), Status);\n Write (This, 16#65#, UInt8'(16#00#), Status);\n Write (This, 16#66#, UInt8'(16#A0#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#22#, UInt8'(16#32#), Status);\n Write (This, 16#47#, UInt8'(16#14#), Status);\n Write (This, 16#49#, UInt8'(16#FF#), Status);\n Write (This, 16#4A#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#7A#, UInt8'(16#0A#), Status);\n Write (This, 16#7B#, UInt8'(16#00#), Status);\n Write (This, 16#78#, UInt8'(16#21#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#23#, UInt8'(16#34#), Status);\n Write (This, 16#42#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#FF#), Status);\n Write (This, 16#45#, UInt8'(16#26#), Status);\n Write (This, 16#46#, UInt8'(16#05#), Status);\n Write (This, 16#40#, UInt8'(16#40#), Status);\n Write (This, 16#0E#, UInt8'(16#06#), Status);\n Write (This, 16#20#, UInt8'(16#1A#), Status);\n Write (This, 16#43#, UInt8'(16#40#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#34#, UInt8'(16#03#), Status);\n Write (This, 16#35#, UInt8'(16#44#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#4B#, UInt8'(16#09#), Status);\n Write (This, 16#4C#, UInt8'(16#05#), Status);\n Write (This, 16#4D#, UInt8'(16#04#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#00#), Status);\n Write (This, 16#45#, UInt8'(16#20#), Status);\n Write (This, 16#47#, UInt8'(16#08#), Status);\n Write (This, 16#48#, UInt8'(16#28#), Status);\n Write (This, 16#67#, UInt8'(16#00#), Status);\n Write (This, 16#70#, UInt8'(16#04#), Status);\n Write (This, 16#71#, UInt8'(16#01#), Status);\n Write (This, 16#72#, UInt8'(16#FE#), Status);\n Write (This, 16#76#, UInt8'(16#00#), Status);\n Write (This, 16#77#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#0D#, UInt8'(16#01#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#01#), Status);\n Write (This, 16#01#, UInt8'(16#F8#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#8E#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#01#), Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n Set_GPIO_Config (This, GPIO_Function, Polarity_High, Status);\n\n if Status then\n Timing_Budget := Measurement_Timing_Budget (This);\n\n -- Disable MSRC and TCC by default\n -- MSRC = Minimum Signal Rate Check\n -- TCC = Target CenterCheck\n\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n\n -- Recalculate the timing Budget\n if Status then\n Set_Measurement_Timing_Budget (This, Timing_Budget, Status);\n end if;\n end Static_Init;\n\n ------------------------------------\n -- Perform_Single_Ref_Calibration --\n ------------------------------------\n\n procedure Perform_Single_Ref_Calibration\n (This : VL53L0X_Ranging_Sensor;\n VHV_Init : UInt8;\n Status : out Boolean)\n is\n Val : UInt8;\n\n begin\n Write (This, REG_SYSRANGE_START, VHV_Init or 16#01#, Status);\n\n if not Status then\n return;\n end if;\n\n loop\n Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);\n exit when not Status;\n exit when (Val and 16#07#) /= 0;\n end loop;\n\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSRANGE_START, UInt8'(16#00#), Status);\n end Perform_Single_Ref_Calibration;\n\n -----------------------------\n -- Perform_Ref_Calibration --\n -----------------------------\n\n procedure Perform_Ref_Calibration\n (This : in out VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n begin\n -- VHV calibration\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#01#), Status);\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#40#, Status);\n end if;\n\n -- Phase calibration\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#02#), Status);\n end if;\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#00#, Status);\n end if;\n\n -- Restore the sequence config\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n end Perform_Ref_Calibration;\n\n ------------------------------------\n -- Start_Range_Single_Millimeters --\n ------------------------------------\n\n procedure Start_Range_Single_Millimeters\n (This : VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n Val : UInt8;\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#91#, This.Stop_Variable, Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n if Status then\n Write (This, REG_SYSRANGE_START, UInt8'(16#01#), Status);\n end if;\n\n if not Status then\n return;\n end if;\n\n loop\n Read (This, REG_SYSRANGE_START, Val, Status);\n exit when not Status;\n exit when (Val and 16#01#) = 0;\n end loop;\n end Start_Range_Single_Millimeters;\n\n ---------------------------\n -- Range_Value_Available --\n ---------------------------\n\n function Range_Value_Available\n (This : VL53L0X_Ranging_Sensor) return Boolean\n is\n Status : Boolean with Unreferenced;\n Val : UInt8;\n begin\n Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);\n return (Val and 16#07#) /= 0;\n end Range_Value_Available;\n\n ----------------------------\n -- Read_Range_Millimeters --\n ----------------------------\n\n function Read_Range_Millimeters\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt16\n is\n Status : Boolean with Unreferenced;\n Ret : HAL.UInt16;\n begin\n Read (This, REG_RESULT_RANGE_STATUS + 10, Ret, Status);\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n\n return Ret;\n end Read_Range_Millimeters;\n\n -----------------------------------\n -- Read_Range_Single_Millimeters --\n -----------------------------------\n\n function Read_Range_Single_Millimeters\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt16\n is\n Status : Boolean;\n begin\n Start_Range_Single_Millimeters (This, Status);\n if not Status then\n return 4000;\n end if;\n\n while not Range_Value_Available (This) loop\n null;\n end loop;\n\n return Read_Range_Millimeters (This);\n end Read_Range_Single_Millimeters;\n\n ---------------------\n -- Set_GPIO_Config --\n ---------------------\n\n procedure Set_GPIO_Config\n (This : in out VL53L0X_Ranging_Sensor;\n Functionality : VL53L0X_GPIO_Functionality;\n Polarity : VL53L0X_Interrupt_Polarity;\n Status : out Boolean)\n is\n Data : UInt8;\n Tmp : UInt8;\n begin\n case Functionality is\n when No_Interrupt =>\n Data := 0;\n when Level_Low =>\n Data := 1;\n when Level_High =>\n Data := 2;\n when Out_Of_Window =>\n Data := 3;\n when New_Sample_Ready =>\n Data := 4;\n end case;\n\n -- 16#04#: interrupt on new measure ready\n Write (This, REG_SYSTEM_INTERRUPT_CONFIG_GPIO, Data, Status);\n\n -- Interrupt polarity\n if Status then\n case Polarity is\n when Polarity_Low =>\n Data := 16#10#;\n when Polarity_High =>\n Data := 16#00#;\n end case;\n\n Read (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);\n Tmp := (Tmp and 16#EF#) or Data;\n Write (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);\n end if;\n\n if Status then\n Clear_Interrupt_Mask (This);\n end if;\n end Set_GPIO_Config;\n\n --------------------------\n -- Clear_Interrupt_Mask --\n --------------------------\n\n procedure Clear_Interrupt_Mask\n (This : VL53L0X_Ranging_Sensor)\n is\n Status : Boolean with Unreferenced;\n-- Tmp : UInt8;\n begin\n-- for J in 1 .. 3 loop\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n-- exit when not Status;\n-- Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#00#), Status);\n-- exit when not Status;\n-- Read (This, REG_RESULT_INTERRUPT_STATUS, Tmp, Status);\n-- exit when not Status;\n-- exit when (Tmp and 16#07#) /= 0;\n-- end loop;\n end Clear_Interrupt_Mask;\n\n ---------------------------\n -- Sequence_Step_Enabled --\n ---------------------------\n\n function Sequence_Step_Enabled\n (This : VL53L0X_Ranging_Sensor) return VL53L0x_Sequence_Step_Enabled\n is\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Sequence_Config : UInt8 := 0;\n Status : Boolean;\n\n function Sequence_Step_Enabled\n (Step : VL53L0x_Sequence_Step;\n Sequence_Config : UInt8) return Boolean;\n\n ---------------------------\n -- Sequence_Step_Enabled --\n ---------------------------\n\n function Sequence_Step_Enabled\n (Step : VL53L0x_Sequence_Step;\n Sequence_Config : UInt8) return Boolean\n is\n begin\n case Step is\n when TCC =>\n return (Sequence_Config and 16#10#) /= 0;\n when DSS =>\n return (Sequence_Config and 16#08#) /= 0;\n when MSRC =>\n return (Sequence_Config and 16#04#) /= 0;\n when Pre_Range =>\n return (Sequence_Config and 16#40#) /= 0;\n when Final_Range =>\n return (Sequence_Config and 16#80#) /= 0;\n end case;\n end Sequence_Step_Enabled;\n\n begin\n Read (This, REG_SYSTEM_SEQUENCE_CONFIG, Sequence_Config, Status);\n\n if not Status then\n return (others => False);\n end if;\n\n for Step in Sequence_Steps'Range loop\n Sequence_Steps (Step) :=\n Sequence_Step_Enabled (Step, Sequence_Config);\n end loop;\n\n return Sequence_Steps;\n end Sequence_Step_Enabled;\n\n ---------------------------\n -- Sequence_Step_Timeout --\n ---------------------------\n\n function Sequence_Step_Timeout\n (This : VL53L0X_Ranging_Sensor;\n Step : VL53L0x_Sequence_Step;\n As_Mclks : Boolean := False) return UInt32\n is\n VCSel_Pulse_Period_Pclk : UInt8;\n Encoded_UInt8 : UInt8;\n Encoded_UInt16 : UInt16;\n Status : Boolean;\n Timeout_Mclks : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n\n begin\n case Step is\n when TCC | DSS | MSRC =>\n Read (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,\n Encoded_UInt8, Status);\n if Status then\n Timeout_Mclks := Decode_Timeout (UInt16 (Encoded_UInt8));\n end if;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n\n when Pre_Range =>\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n\n when Final_Range =>\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if Sequence_Steps (Pre_Range) then\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n else\n Timeout_Mclks := 0;\n end if;\n\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Final_Range);\n\n Read (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n Timeout_Mclks :=\n Decode_Timeout (Encoded_UInt16) - Timeout_Mclks;\n\n if As_Mclks then\n return Timeout_Mclks;\n else\n return To_Timeout_Microseconds\n (Timeout_Mclks, VCSel_Pulse_Period_Pclk);\n end if;\n end case;\n end Sequence_Step_Timeout;\n\n -------------------------------\n -- Measurement_Timing_Budget --\n -------------------------------\n\n function Measurement_Timing_Budget\n (This : VL53L0X_Ranging_Sensor) return HAL.UInt32\n is\n Ret : UInt32;\n Pre_Range_Timeout : UInt32;\n Final_Range_Timeout : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Msrc_Dcc_Tcc_Timeout : UInt32;\n\n begin\n Ret := Start_Overhead + End_Overhead;\n\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if Sequence_Steps (TCC)\n or else Sequence_Steps (MSRC)\n or else Sequence_Steps (DSS)\n then\n Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);\n if Sequence_Steps (TCC) then\n Ret := Ret + Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;\n end if;\n if Sequence_Steps (DSS) then\n Ret := Ret + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);\n elsif Sequence_Steps (MSRC) then\n Ret := Ret + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;\n end if;\n end if;\n\n if Sequence_Steps (Pre_Range) then\n Pre_Range_Timeout := Sequence_Step_Timeout (This, Pre_Range);\n Ret := Ret + Pre_Range_Timeout + Pre_Range_Overhead;\n end if;\n\n if Sequence_Steps (Final_Range) then\n Final_Range_Timeout := Sequence_Step_Timeout (This, Final_Range);\n Ret := Ret + Final_Range_Timeout + Final_Range_Overhead;\n end if;\n\n return Ret;\n end Measurement_Timing_Budget;\n\n -----------------------------------\n -- Set_Measurement_Timing_Budget --\n -----------------------------------\n\n procedure Set_Measurement_Timing_Budget\n (This : VL53L0X_Ranging_Sensor;\n Budget_Micro_Seconds : HAL.UInt32;\n Status : out Boolean)\n is\n Final_Range_Timing_Budget_us : UInt32;\n Sequence_Steps : VL53L0x_Sequence_Step_Enabled;\n Pre_Range_Timeout_us : UInt32 := 0;\n Sub_Timeout : UInt32 := 0;\n Msrc_Dcc_Tcc_Timeout : UInt32;\n\n begin\n Status := True;\n\n Final_Range_Timing_Budget_us :=\n Budget_Micro_Seconds - Start_Overhead - End_Overhead\n - Final_Range_Overhead;\n\n Sequence_Steps := Sequence_Step_Enabled (This);\n\n if not Sequence_Steps (Final_Range) then\n return;\n end if;\n\n if Sequence_Steps (TCC)\n or else Sequence_Steps (MSRC)\n or else Sequence_Steps (DSS)\n then\n Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);\n\n if Sequence_Steps (TCC) then\n Sub_Timeout := Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;\n end if;\n\n if Sequence_Steps (DSS) then\n Sub_Timeout :=\n Sub_Timeout + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);\n\n elsif Sequence_Steps (MSRC) then\n Sub_Timeout := Sub_Timeout + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;\n end if;\n end if;\n\n if Sequence_Steps (Pre_Range) then\n Pre_Range_Timeout_us := Sequence_Step_Timeout (This, Pre_Range);\n\n Sub_Timeout :=\n Sub_Timeout + Pre_Range_Timeout_us + Pre_Range_Overhead;\n end if;\n\n if Sub_Timeout < Final_Range_Timing_Budget_us then\n Final_Range_Timing_Budget_us :=\n Final_Range_Timing_Budget_us - Sub_Timeout;\n\n else\n -- Requested timeout too big\n Status := False;\n\n return;\n end if;\n\n declare\n VCSel_Pulse_Period_Pclk : UInt8;\n Encoded_UInt16 : UInt16;\n Timeout_Mclks : UInt32;\n begin\n if Sequence_Steps (Pre_Range) then\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Pre_Range);\n\n Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encoded_UInt16, Status);\n\n if Status then\n Timeout_Mclks := Decode_Timeout (Encoded_UInt16);\n end if;\n else\n Timeout_Mclks := 0;\n end if;\n\n VCSel_Pulse_Period_Pclk :=\n VCSel_Pulse_Period (This, Final_Range);\n\n Timeout_Mclks := Timeout_Mclks + To_Timeout_Mclks\n (Final_Range_Timing_Budget_us,\n VCSel_Pulse_Period_Pclk);\n\n Write (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n Encode_Timeout (Timeout_Mclks), Status);" + }, + { + "function_def": "function To_U32 is new Ada.Unchecked_Conversion", + "function_body": "(Fix_Point_16_16, UInt32);\n Val : UInt16;\n Status : Boolean;\n begin\n -- Expecting Fixed Point 9.7\n Val := UInt16 (Shift_Right (To_U32 (Limit_Mcps), 9) and 16#FF_FF#);\n Write (This,\n REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Val,\n Status);\n return Status;\n end Set_Signal_Rate_Limit;\n\n ---------------\n -- SPAD_Info --\n ---------------\n\n function SPAD_Info\n (This : VL53L0X_Ranging_Sensor;\n SPAD_Count : out HAL.UInt8;\n Is_Aperture : out Boolean) return Boolean\n is\n Status : Boolean;\n Tmp : UInt8;\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp or 16#04#, Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#07#), Status);\n end if;\n if Status then\n Write (This, 16#81#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#80#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#94#, UInt8'(16#6B#), Status);\n end if;\n if Status then\n Write (This, 16#83#, UInt8'(16#00#), Status);\n end if;\n\n loop\n exit when not Status;\n Read (This, 16#83#, Tmp, Status);\n exit when Tmp /= 0;\n end loop;\n\n if Status then\n Write (This, 16#83#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Read (This, 16#92#, Tmp, Status);\n end if;\n\n if Status then\n SPAD_Count := Tmp and 16#7F#;\n Is_Aperture := (Tmp and 16#80#) /= 0;\n\n Write (This, 16#81#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp and not 16#04#, Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n return Status;\n end SPAD_Info;\n\n ---------------------------\n -- Set_Signal_Rate_Limit --\n ---------------------------\n\n procedure Set_Signal_Rate_Limit\n (This : VL53L0X_Ranging_Sensor;\n Rate_Limit : Fix_Point_16_16)\n is\n function To_U32 is new Ada.Unchecked_Conversion\n (Fix_Point_16_16, UInt32);\n Reg : UInt16;\n Status : Boolean with Unreferenced;\n begin\n -- Encoded as Fixed Point 9.7. Let's translate.\n Reg := UInt16 (Shift_Right (To_U32 (Rate_Limit), 9) and 16#FFFF#);\n Write (This, REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Reg, Status);\n end Set_Signal_Rate_Limit;\n\n --------------------------------------\n -- Set_Vcsel_Pulse_Period_Pre_Range --\n --------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Pre_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Pre_Range, Status);\n end Set_VCSEL_Pulse_Period_Pre_Range;\n\n ----------------------------------------\n -- Set_Vcsel_Pulse_Period_Final_Range --\n ----------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Final_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Final_Range, Status);\n end Set_VCSEL_Pulse_Period_Final_Range;\n\n ----------------------------\n -- Set_VCSel_Pulse_Period --\n ----------------------------\n\n procedure Set_VCSel_Pulse_Period\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Sequence : VL53L0x_Sequence_Step;\n Status : out Boolean)\n is\n Encoded : constant UInt8 := Shift_Right (Period, 1) - 1;\n Phase_High : UInt8;\n Pre_Timeout : UInt32;\n Final_Timeout : UInt32;\n Msrc_Timeout : UInt32;\n Timeout_Mclks : UInt32;\n Steps_Enabled : constant VL53L0x_Sequence_Step_Enabled :=\n Sequence_Step_Enabled (This);\n Budget : UInt32;\n Sequence_Cfg : UInt8;\n\n begin\n -- Save the measurement timing budget\n Budget := Measurement_Timing_Budget (This);\n\n case Sequence is\n when Pre_Range =>\n Pre_Timeout := Sequence_Step_Timeout (This, Pre_Range);\n Msrc_Timeout := Sequence_Step_Timeout (This, MSRC);\n\n case Period is\n when 12 =>\n Phase_High := 16#18#;\n when 14 =>\n Phase_High := 16#30#;\n when 16 =>\n Phase_High := 16#40#;\n when 18 =>\n Phase_High := 16#50#;\n when others =>\n Status := False;\n\n return;\n end case;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,\n Encoded, Status);\n if not Status then\n return;\n end if;\n\n -- Update the timeouts\n Timeout_Mclks := To_Timeout_Mclks (Pre_Timeout, Period);\n Write (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n UInt16 (Timeout_Mclks), Status);\n\n Timeout_Mclks := To_Timeout_Mclks (Msrc_Timeout, Period);\n if Timeout_Mclks > 256 then\n Timeout_Mclks := 255;\n else\n Timeout_Mclks := Timeout_Mclks - 1;\n end if;\n\n Write (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,\n UInt8 (Timeout_Mclks), Status);\n\n when Final_Range =>\n Pre_Timeout := Sequence_Step_Timeout\n (This, Pre_Range, As_Mclks => True);\n Final_Timeout := Sequence_Step_Timeout (This, Final_Range);\n\n declare\n Phase_High : UInt8;\n Width : UInt8;\n Cal_Timeout : UInt8;\n Cal_Lim : UInt8;\n begin\n case Period is\n when 8 =>\n Phase_High := 16#10#;\n Width := 16#02#;\n Cal_Timeout := 16#0C#;\n Cal_Lim := 16#30#;\n when 10 =>\n Phase_High := 16#28#;\n Width := 16#03#;\n Cal_Timeout := 16#09#;\n Cal_Lim := 16#20#;\n when 12 =>\n Phase_High := 16#38#;\n Width := 16#03#;\n Cal_Timeout := 16#08#;\n Cal_Lim := 16#20#;\n when 14 =>\n Phase_High := 16#48#;\n Width := 16#03#;\n Cal_Timeout := 16#07#;\n Cal_Lim := 16#20#;\n when others =>\n return;\n end case;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_GLOBAL_CONFIG_VCSEL_WIDTH,\n Width, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_ALGO_PHASECAL_CONFIG_TIMEOUT,\n Cal_Timeout, Status);\n if not Status then\n return;\n end if;\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, REG_ALGO_PHASECAL_LIM,\n Cal_Lim, Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n if not Status then\n return;\n end if;" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT6206_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n begin\n if Touch_Id not in FT6206_Px_Regs'Range then\n return (0, 0, 0);\n end if;\n\n if Touch_Id > This.Active_Touch_Points then\n return (0, 0, 0);\n end if;\n\n -- X/Y are swaped from the screen coordinates\n\n Regs := FT6206_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n if Ret.Weight = 0 then\n Ret.Weight := 50;\n end if;\n\n Ret.X := Natural'Max (0, Ret.X);\n Ret.Y := Natural'Max (0, Ret.Y);\n Ret.X := Natural'Min (This.LCD_Natural_Width - 1, Ret.X);\n Ret.Y := Natural'Min (This.LCD_Natural_Height - 1, Ret.Y);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "function Read_Register (This : STMPE811_Device;", + "function_body": "Reg_Addr : UInt8) return UInt8\n is\n Data : TSC_Data (1 .. 1);\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Read (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n Data,\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n return Data (1);\n end Read_Register;\n\n --------------------\n -- Write_Register --\n --------------------\n\n procedure Write_Register (This : in out STMPE811_Device;\n Reg_Addr : UInt8;\n Data : UInt8) is\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Write (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n (1 => Data),\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n end Write_Register;\n\n ---------------\n -- IOE_Reset --\n ---------------\n\n procedure IOE_Reset (This : in out STMPE811_Device) is\n begin\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#02#);\n\n -- Give some time for the reset\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#00#);\n end IOE_Reset;\n\n --------------------------\n -- IOE_Function_Command --\n --------------------------\n\n procedure IOE_Function_Command (This : in out STMPE811_Device;\n Func : UInt8;\n Enabled : Boolean)\n is\n Reg : UInt8 := This.Read_Register (IOE_REG_SYS_CTRL2);\n begin\n -- CTRL2 functions are disabled when corresponding bit is set\n\n if Enabled then\n Reg := Reg and (not Func);\n else\n Reg := Reg or Func;\n end if;\n\n This.Write_Register (IOE_REG_SYS_CTRL2, Reg);\n end IOE_Function_Command;\n\n -------------------\n -- IOE_AF_Config --\n -------------------\n\n procedure IOE_AF_Config (This : in out STMPE811_Device;\n Pin : UInt8;\n Enabled : Boolean) is\n Reg : UInt8 := This.Read_Register (IOE_REG_GPIO_AF);\n begin\n if Enabled then\n Reg := Reg or Pin;\n else\n Reg := Reg and (not Pin);\n end if;\n\n This.Write_Register (IOE_REG_GPIO_AF, Reg);\n end IOE_AF_Config;\n\n ----------------\n -- Get_IOE_ID --\n ----------------\n\n function Get_IOE_ID (This : in out STMPE811_Device) return UInt16 is\n begin\n return (UInt16 (This.Read_Register (0)) * (2**8))\n or UInt16 (This.Read_Register (1));\n end Get_IOE_ID;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize (This : in out STMPE811_Device) return Boolean\n is\n begin\n\n This.Time.Delay_Milliseconds (100);\n\n if This.Get_IOE_ID /= 16#0811# then\n return False;\n end if;\n\n This.IOE_Reset;\n\n This.IOE_Function_Command (IOE_ADC_FCT, True);\n This.IOE_Function_Command (IOE_TSC_FCT, True);\n\n This.Write_Register (IOE_REG_ADC_CTRL1, 16#49#);\n\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_ADC_CTRL2, 16#01#);\n\n This.IOE_AF_Config (TOUCH_IO_ALL, False);\n\n This.Write_Register (IOE_REG_TSC_CFG, 16#9A#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_FRACT_Z, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_I_DRIVE, 16#01#);\n\n This.Write_Register (IOE_REG_TSC_CTRL, 16#01#);\n\n This.Write_Register (IOE_REG_INT_STA, 16#FF#);\n\n return True;\n end Initialize;\n\n ----------------\n -- Set_Bounds --\n ----------------\n\n overriding\n procedure Set_Bounds (This : in out STMPE811_Device;\n Width : Natural;\n Height : Natural;\n Swap : HAL.Touch_Panel.Swap_State)\n is\n begin\n This.LCD_Natural_Width := Width;\n This.LCD_Natural_Height := Height;\n This.Swap := Swap;\n end Set_Bounds;\n\n -------------------------\n -- Active_Touch_Points --\n -------------------------\n\n overriding\n function Active_Touch_Points (This : in out STMPE811_Device)\n return Touch_Identifier\n is\n Val : constant UInt8 := This.Read_Register (IOE_REG_TSC_CTRL) and 16#80#;\n begin\n if Val = 0 then\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n This.Write_Register (IOE_REG_FIFO_STA, 16#00#);\n\n return 0;\n else\n return 1;\n end if;\n end Active_Touch_Points;\n\n ---------------------\n -- Get_Touch_Point --\n ---------------------\n\n overriding\n function Get_Touch_Point (This : in out STMPE811_Device;\n Touch_Id : Touch_Identifier)\n return TP_Touch_State\n is\n State : TP_Touch_State;\n Raw_X : UInt32;\n Raw_Y : UInt32;\n Raw_Z : UInt32;\n X : Integer;\n Y : Integer;\n Tmp : Integer;\n\n begin\n\n -- Check Touch detected bit in CTRL register\n if Touch_Id /= 1 or else This.Active_Touch_Points = 0 then\n return (0, 0, 0);\n end if;\n\n declare\n Data_X : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_X, 2);\n Data_Y : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Y, 2);\n Data_Z : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Z, 1);\n Z_Frac : constant TSC_Data := This.Read_Data (IOE_REG_TSC_FRACT_Z, 1);\n\n begin\n Raw_X := 2 ** 12 -\n (Shift_Left (UInt32 (Data_X (1)) and 16#0F#, 8) or UInt32 (Data_X (2)));\n Raw_Y :=\n Shift_Left (UInt32 (Data_Y (1)) and 16#0F#, 8) or UInt32 (Data_Y (2));\n Raw_Z :=\n Shift_Right (UInt32 (Data_Z (1)), Natural (Z_Frac (1) and 2#111#));" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT5336_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n\n begin\n -- X/Y are swaped from the screen coordinates\n\n if Touch_Id not in FT5336_Px_Regs'Range\n or else Touch_Id > This.Active_Touch_Points\n then\n return (0, 0, 0);\n end if;\n\n Regs := FT5336_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n Ret.X :=\n Natural'Min (Natural'Max (0, Ret.X), This.LCD_Natural_Width - 1);\n Ret.Y :=\n Natural'Min (Natural'Max (0, Ret.Y), This.LCD_Natural_Height - 1);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "procedure Destroy is new Ada.Unchecked_Deallocation", + "function_body": "(File_Handle, File_Handle_Access);\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Directory_Handle, Directory_Handle_Access);\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Node_Handle, Node_Handle_Access);\n\n function \"<\" (Left, Right : Node_Handle) return Boolean is\n (Ada.Strings.Unbounded.\"<\" (Left.Name, Right.Name));\n\n package Node_Sorting is\n new Node_Vectors.Generic_Sorting;\n\n -- Most of the time, standard operations give us no reliable way to\n -- determine specifically what triggered a failure, so use the following\n -- error code as a \"generic\" one.\n\n Generic_Error : constant Status_Code := Input_Output_Error;\n\n function Absolute_Path\n (This : Native_FS_Driver;\n Relative_Path : String)\n return String\n is (if Relative_Path = \"\"\n then +This.Root_Dir\n else Join (+This.Root_Dir, Relative_Path, True));\n\n ----------------\n -- Get_Handle --\n ----------------\n\n function Get_Handle\n (FS : in out Native_FS_Driver)\n return File_Handle_Access\n is\n Result : File_Handle_Access := FS.Free_File_Handles;\n begin\n if Result = null then\n Result := new File_Handle'\n (FS => FS'Unrestricted_Access,\n others => <>);\n else\n FS.Free_File_Handles := Result.Next;\n end if;\n return Result;\n end Get_Handle;\n\n ----------------\n -- Get_Handle --\n ----------------\n\n function Get_Handle\n (FS : in out Native_FS_Driver)\n return Directory_Handle_Access\n is\n Result : Directory_Handle_Access := FS.Free_Dir_Handles;\n begin\n if Result = null then\n Result := new Directory_Handle'\n (FS => FS'Unrestricted_Access,\n others => <>);\n else\n FS.Free_Dir_Handles := Result.Next;\n end if;\n return Result;\n end Get_Handle;\n\n ---------------------\n -- Add_Free_Handle --\n ---------------------\n\n procedure Add_Free_Handle\n (FS : in out Native_FS_Driver;\n Handle : in out File_Handle_Access)\n is\n begin\n Handle.Next := FS.Free_File_Handles;\n FS.Free_File_Handles := Handle;\n Handle := null;\n end Add_Free_Handle;\n\n ---------------------\n -- Add_Free_Handle --\n ---------------------\n\n procedure Add_Free_Handle\n (FS : in out Native_FS_Driver;\n Handle : in out Directory_Handle_Access)\n is\n begin\n Handle.Next := FS.Free_Dir_Handles;\n FS.Free_Dir_Handles := Handle;\n Handle := null;\n end Add_Free_Handle;\n\n -------------\n -- Destroy --\n -------------\n\n procedure Destroy (This : in out Native_FS_Driver_Access) is\n procedure Destroy is new Ada.Unchecked_Deallocation\n (Native_FS_Driver, Native_FS_Driver_Access);\n begin\n -- Free all handles\n\n while This.Free_File_Handles /= null loop\n declare\n H : constant File_Handle_Access := This.Free_File_Handles.Next;\n begin\n Destroy (This.Free_File_Handles);\n This.Free_File_Handles := H;" + }, + { + "function_def": "procedure Draw_Glyph is new Hershey_Fonts.Draw_Glyph", + "function_body": "(Internal_Draw_Line);\n\n Current : Point := Start;\n\n begin\n Buffer.Set_Source (Foreground);\n for C of Msg loop\n exit when Current.X > Buffer.Width;\n Draw_Glyph\n (Fnt => Font,\n C => C,\n X => Current.X,\n Y => Current.Y,\n Height => Height,\n Bold => Bold);\n end loop;\n end Draw_String;\n\n -----------------\n -- Draw_String --\n -----------------\n\n procedure Draw_String\n (Buffer : in out Bitmap_Buffer'Class;\n Area : Rect;\n Msg : String;\n Font : Hershey_Font;\n Bold : Boolean;\n Outline : Boolean;\n Foreground : Bitmap_Color;\n Fast : Boolean := True)\n is\n Length : constant Natural :=\n Hershey_Fonts.Strlen (Msg, Font, Area.Height);\n Ratio : Float;\n Current : Point := (0, 0);\n Prev : UInt32;\n FG : constant UInt32 := Bitmap_Color_To_Word (Buffer.Color_Mode,\n Foreground);\n Blk : constant UInt32 := Bitmap_Color_To_Word (Buffer.Color_Mode,\n Black);\n\n procedure Internal_Draw_Line\n (X0, Y0, X1, Y1 : Natural;\n Width : Positive);\n\n procedure Internal_Draw_Line\n (X0, Y0, X1, Y1 : Natural;\n Width : Positive)\n is\n begin\n Draw_Line (Buffer,\n (Area.Position.X + Natural (Float (X0) * Ratio),\n Area.Position.Y + Y0),\n (Area.Position.X + Natural (Float (X1) * Ratio),\n Area.Position.Y + Y1),\n Width,\n Fast);\n end Internal_Draw_Line;\n\n procedure Draw_Glyph is new Hershey_Fonts.Draw_Glyph\n (Internal_Draw_Line);\n\n begin\n if Length > Area.Width then\n Ratio := Float (Area.Width) / Float (Length);\n else\n Ratio := 1.0;\n Current.X := (Area.Width - Length) / 2;\n end if;\n\n Buffer.Set_Source (Foreground);\n\n for C of Msg loop\n Draw_Glyph\n (Fnt => Font,\n C => C,\n X => Current.X,\n Y => Current.Y,\n Height => Area.Height,\n Bold => Bold);\n end loop;\n\n if Outline and then Area.Height > 40 then\n for Y in Area.Position.Y + 1 .. Area.Position.Y + Area.Height loop\n Prev := Buffer.Pixel ((Area.Position.X, Y));\n if Prev = FG then\n Buffer.Set_Pixel ((Area.Position.X, Y), Black);\n end if;\n\n for X in Area.Position.X + 1 .. Area.Position.X + Area.Width loop\n declare\n Col : constant UInt32 := Buffer.Pixel ((X, Y));\n Top : constant UInt32 := Buffer.Pixel ((X, Y - 1));\n begin\n\n if Prev /= FG\n and then Col = FG\n then\n Buffer.Set_Pixel ((X, Y), Blk);\n\n elsif Prev = FG\n and then Col /= FG\n then\n Buffer.Set_Pixel ((X - 1, Y), Blk);\n\n elsif Top /= FG\n and then Top /= Blk\n and then Col = FG\n then\n Buffer.Set_Pixel ((X, Y), Blk);\n\n elsif Top = FG\n and then Col /= FG\n then\n Buffer.Set_Pixel ((X, Y - 1), Blk);\n end if;\n\n Prev := Col;" + }, + { + "function_def": "procedure adainit is", + "function_body": "procedure Start_Slave_CPUs;\n pragma Import (C, Start_Slave_CPUs, \"__gnat_start_slave_cpus\");\n begin\n\n Ada.Real_Time'Elab_Body;\n E021 := E021 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E087 := E087 + 1;\n System.Tasking.Protected_Objects.Multiprocessors'Elab_Body;\n E091 := E091 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E083 := E083 + 1;\n E013 := E013 + 1;\n Cortex_M.Cache'Elab_Body;\n E143 := E143 + 1;\n E195 := E195 + 1;\n HAL.SDMMC'ELAB_SPEC;\n E149 := E149 + 1;\n FT5336'ELAB_BODY;\n E206 := E206 + 1;\n E212 := E212 + 1;\n E210 := E210 + 1;\n Ravenscar_Time'Elab_Body;\n E169 := E169 + 1;\n E147 := E147 + 1;\n Soft_Drawing_Bitmap'Elab_Body;\n E197 := E197 + 1;\n Memory_Mapped_Bitmap'Elab_Body;\n E193 := E193 + 1;\n STM32.ADC'ELAB_SPEC;\n E100 := E100 + 1;\n E103 := E103 + 1;\n E109 := E109 + 1;\n E178 := E178 + 1;\n STM32.DMA2D.INTERRUPT'ELAB_BODY;\n E181 := E181 + 1;\n E183 := E183 + 1;\n STM32.DMA2D_BITMAP'ELAB_SPEC;\n STM32.DMA2D_BITMAP'ELAB_BODY;\n E191 := E191 + 1;\n E117 := E117 + 1;\n E187 := E187 + 1;\n STM32.I2C'ELAB_BODY;\n E123 := E123 + 1;\n E134 := E134 + 1;\n E113 := E113 + 1;\n STM32.RTC'ELAB_BODY;\n E131 := E131 + 1;\n STM32.SPI'ELAB_BODY;\n E157 := E157 + 1;\n STM32.SPI.DMA'ELAB_BODY;\n E160 := E160 + 1;\n STM32.GPIO'ELAB_BODY;\n E111 := E111 + 1;\n E153 := E153 + 1;\n STM32.DEVICE'ELAB_SPEC;\n E096 := E096 + 1;\n STM32.SDMMC'ELAB_BODY;\n E140 := E140 + 1;\n STM32.I2S'ELAB_BODY;\n E127 := E127 + 1;\n E115 := E115 + 1;\n STM32.LTDC'ELAB_BODY;\n E199 := E199 + 1;\n E165 := E165 + 1;\n E167 := E167 + 1;\n WM8994'ELAB_BODY;\n E172 := E172 + 1;\n Audio'Elab_Spec;\n Framebuffer_Rk043fn48h'Elab_Body;\n E174 := E174 + 1;\n STM32.BOARD'ELAB_SPEC;\n E074 := E074 + 1;\n Sdcard'Elab_Body;\n E202 := E202 + 1;\n E185 := E185 + 1;\n Framebuffer_Ltdc'Elab_Body;\n E176 := E176 + 1;\n Audio'Elab_Body;\n E094 := E094 + 1;\n Touch_Panel_Ft5336'Elab_Body;\n E204 := E204 + 1;\n E019 := E019 + 1;\n Lcd_Std_Out'Elab_Body;\n E208 := E208 + 1;\n STM32.USER_BUTTON'ELAB_BODY;\n E214 := E214 + 1;\n Start_Slave_CPUs;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_draw\");\n\n procedure main is\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n adainit;\n Ada_Main_Program;" + }, + { + "function_def": "procedure Clear;", + "function_body": "-----------\n -- Clear --\n -----------\n\n procedure Clear is\n begin\n Display.Hidden_Buffer (1).Set_Source (BG);\n Display.Hidden_Buffer (1).Fill;\n\n LCD_Std_Out.Clear_Screen;\n LCD_Std_Out.Put_Line (\"Touch the screen to draw or\");\n LCD_Std_Out.Put_Line (\"press the blue button for\");\n LCD_Std_Out.Put_Line (\"a demo of drawing pimitives.\");\n\n Display.Update_Layer (1, Copy_Back => True);\n end Clear;\n\n Last_X : Integer := -1;\n Last_Y : Integer := -1;\n\n type Mode is (Drawing_Mode, Bitmap_Showcase_Mode);\n\n Current_Mode : Mode := Drawing_Mode;\n\nbegin\n\n -- Initialize LCD\n Display.Initialize;\n Display.Initialize_Layer (1, ARGB_8888);\n\n -- Initialize touch panel\n Touch_Panel.Initialize;\n\n -- Initialize button\n User_Button.Initialize;\n\n LCD_Std_Out.Set_Font (BMP_Fonts.Font8x8);\n LCD_Std_Out.Current_Background_Color := BG;\n\n -- Clear LCD (set background)\n Clear;\n\n -- The application: set pixel where the finger is (so that you\n -- cannot see what you are drawing).\n loop\n if User_Button.Has_Been_Pressed then\n case Current_Mode is\n when Drawing_Mode =>\n Current_Mode := Bitmap_Showcase_Mode;\n when Bitmap_Showcase_Mode =>\n Clear;\n Current_Mode := Drawing_Mode;\n end case;\n end if;\n\n if Current_Mode = Drawing_Mode then\n\n Display.Hidden_Buffer (1).Set_Source (HAL.Bitmap.Green);\n\n declare\n State : constant TP_State := Touch_Panel.Get_All_Touch_Points;\n begin\n if State'Length = 0 then\n Last_X := -1;\n Last_Y := -1;\n\n elsif State'Length = 1 then\n -- Lines can be drawn between two consecutive points only when\n -- one touch point is active: the order of the touch data is not\n -- necessarily preserved by the hardware.\n if Last_X > 0 then\n Draw_Line\n (Display.Hidden_Buffer (1).all,\n Start => (Last_X, Last_Y),\n Stop => (State (State'First).X, State (State'First).Y),\n Thickness => State (State'First).Weight / 2,\n Fast => False);\n end if;\n\n Last_X := State (State'First).X;\n Last_Y := State (State'First).Y;\n\n else\n Last_X := -1;\n Last_Y := -1;\n end if;\n\n for Id in State'Range loop\n Fill_Circle\n (Display.Hidden_Buffer (1).all,\n Center => (State (Id).X, State (Id).Y),\n Radius => State (Id).Weight / 4);\n end loop;\n\n if State'Length > 0 then\n Display.Update_Layer (1, Copy_Back => True);\n end if;" + }, + { + "function_def": "procedure Host is", + "function_body": "COM : aliased Serial_Port;\n COM3 : constant Port_Name := Name (3);\n\n Outgoing : String (1 .. 1024); -- arbitrary\n Last : Natural;\nbegin\n COM.Open (COM3);\n COM.Set (Rate => B115200, Block => False);\n\n loop\n Put (\"> \");\n Get_Line (Outgoing, Last);\n exit when Last = Outgoing'First - 1;\n\n Put_Line (\"Sending: '\" & Outgoing (1 .. Last) & \"'\");\n\n String'Output (COM'Access, Outgoing (1 .. Last));\n\n declare\n Incoming : constant String := String'Input (COM'Access);\n begin\n Put_Line (\"From board: \" & Incoming);" + }, + { + "function_def": "-- procedure Host is", + "function_body": "-- COM : aliased Serial_Port;\n-- COM3 : constant Port_Name := Name (3);\n--\n-- Outgoing : String (1 .. 1024); -- arbitrary\n-- Last : Natural;\n-- begin\n-- COM.Open (COM3);\n-- COM.Set (Rate => B115200, Block => False);\n--\n-- loop\n-- Put (\"> \");\n-- Get_Line (Outgoing, Last);\n-- exit when Last = Outgoing'First - 1;\n--\n-- Put_Line (\"Sending: '\" & Outgoing (1 .. Last) & \"'\");\n-- String'Output (COM'Access, Outgoing (1 .. Last));\n--\n-- declare\n-- Incoming : constant String := String'Input (COM'Access);\n-- begin\n-- Put_Line (\"From board: \" & Incoming);\n-- end;\n-- end loop;\n--\n-- COM.Close;\n-- end Host;\n\n-- You can change the COM port number, or even get it from the command line\n-- as an argument, but it must match what the host OS sees from the USB-COM\n-- cable.\n\n-- When running it, enter a string at the prompt (\">\") or just hit carriage\n-- return if you are ready to quit. If you enter a string, it will be sent to\n-- the target board, along with the bounds. The program (in this file) running\n-- on the target, echos it back so the host app will show that response from\n-- the board.\n\n-- TARGET BOARD SIDE:\n\n-- This file declares the main procedure for the program running on the target\n-- board. It simply echos the incoming strings, forever.\n\nwith Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler);\n\nwith Peripherals_Streaming; use Peripherals_Streaming;\nwith Serial_IO.Streaming; use Serial_IO.Streaming;\n\nprocedure Demo_Serial_Port_Streaming is\nbegin\n Initialize (COM);\n Configure (COM, Baud_Rate => 115_200);\n\n loop\n declare\n Incoming : constant String := String'Input (COM'Access);\n begin\n String'Output (COM'Access, \"'\" & Incoming & \"'\");" + }, + { + "function_def": "procedure Main is", + "function_body": "use type Partitions.Status_Code;\n\n procedure List_Dir (Path : String);\n -- List files in directory\n\n procedure List_Partitions (Path_To_Disk_Image : String);\n -- List partition in a disk file\n\n --------------\n -- List_Dir --\n --------------\n\n procedure List_Dir (Path : String) is\n Status : Status_Code;\n DD : Directory_Descriptor;\n begin\n Status := Open (DD, Path);\n if Status /= OK then\n Semihosting.Log_Line (\"Open Directory '\" & Path & \"' Error: \" & Status'Img);\n else\n Semihosting.Log_Line (\"Listing '\" & Path & \"' content:\");\n loop\n declare\n Ent : constant Directory_Entry := Read (DD);\n begin\n if Ent /= Invalid_Dir_Entry then\n Semihosting.Log_Line (\" - '\" & Ent.Name & \"'\");\n Semihosting.Log_Line (\" Kind: \" & Ent.Subdirectory'Img);\n else\n exit;\n end if;" + }, + { + "function_def": "procedure Xaa is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xaa() called\");" + }, + { + "function_def": "procedure Xab is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xab() called\");" + }, + { + "function_def": "procedure Xac is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xac() called\");" + }, + { + "function_def": "procedure Object_Hierarchy is", + "function_body": "procedure Dump_Object (This : in out Aof.Core.Objects.Access_Object) is \n begin\n Ada.Text_Io.Put_Line(\"Object: \" & This.Get_Name);" + }, + { + "function_def": "procedure Xaa is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xaa() called\");" + }, + { + "function_def": "procedure Xab is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xab() called\");" + }, + { + "function_def": "procedure Xac is", + "function_body": "begin\n Ada.Text_Io.Put_Line(\"Xac() called\");" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Exception_Tracebacks : Integer;\n pragma Import (C, Exception_Tracebacks, \"__gl_exception_tracebacks\");\n Zero_Cost_Exceptions : Integer;\n pragma Import (C, Zero_Cost_Exceptions, \"__gl_zero_cost_exceptions\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n\n procedure Install_Handler;\n pragma Import (C, Install_Handler, \"__gnat_install_handler\");\n\n Handler_Installed : Integer;\n pragma Import (C, Handler_Installed, \"__gnat_handler_installed\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Exception_Tracebacks := 1;\n Zero_Cost_Exceptions := 1;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n if Handler_Installed = 0 then\n Install_Handler;\n end if;\n\n Finalize_Library_Objects := null;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E36 := E36 + 1;\n System.Soft_Links'Elab_Body;\n E26 := E26 + 1;\n System.Secondary_Stack'Elab_Body;\n E30 := E30 + 1;\n E08 := E08 + 1;\n E06 := E06 + 1;\n E12 := E12 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_project_main\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n procedure Install_Restricted_Handlers_Sequential;\n pragma Import (C,Install_Restricted_Handlers_Sequential, \"__gnat_attach_all_handlers\");\n\n Partition_Elaboration_Policy : Character;\n pragma Import (C, Partition_Elaboration_Policy, \"__gnat_partition_elaboration_policy\");\n\n procedure Activate_All_Tasks_Sequential;\n pragma Import (C, Activate_All_Tasks_Sequential, \"__gnat_activate_all_tasks\");\n procedure Start_Slave_CPUs;\n pragma Import (C, Start_Slave_CPUs, \"__gnat_start_slave_cpus\");\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := 0;\n WC_Encoding := 'b';\n Locking_Policy := 'C';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := 'F';\n Partition_Elaboration_Policy := 'S';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 1;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n Runtime_Initialize (1);\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E051 := E051 + 1;\n Ada.Tags'Elab_Body;\n E095 := E095 + 1;\n System.Bb.Timing_Events'Elab_Spec;\n E109 := E109 + 1;\n E053 := E053 + 1;\n Ada.Real_Time'Elab_Body;\n E006 := E006 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E126 := E126 + 1;\n System.Tasking.Protected_Objects.Multiprocessors'Elab_Body;\n E139 := E139 + 1;\n System.Tasking.Restricted.Stages'Elab_Body;\n E133 := E133 + 1;\n ST.STM32F4.GPIO'ELAB_SPEC;\n E142 := E142 + 1;\n ST.STM32F4.RCC'ELAB_SPEC;\n E141 := E141 + 1;\n Button'Elab_Spec;\n Button'Elab_Body;\n E121 := E121 + 1;\n Lights'Elab_Spec;\n Lights'Elab_Body;\n E119 := E119 + 1;\n Install_Restricted_Handlers_Sequential;\n Activate_All_Tasks_Sequential;\n Start_Slave_CPUs;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_led_flasher\");\n\n procedure main is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n<<<<<<< HEAD\n E98 := E98 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__text_streams__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"ada__text_io__finalize_spec\");\n begin\n F2;" + }, + { + "function_def": "procedure F3;", + "function_body": "pragma Import (Ada, F3, \"system__file_io__finalize_body\");\n begin\n E64 := E64 - 1;\n F3;" + }, + { + "function_def": "procedure F4;", + "function_body": "pragma Import (Ada, F4, \"system__file_control_block__finalize_spec\");\n begin\n E77 := E77 - 1;\n F4;" + }, + { + "function_def": "procedure F5;", + "function_body": "pragma Import (Ada, F5, \"system__pool_global__finalize_spec\");\n begin\n F5;" + }, + { + "function_def": "procedure F6;", + "function_body": "pragma Import (Ada, F6, \"system__storage_pools__subpools__finalize_spec\");\n=======\n E117 := E117 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__directories__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__regexp__finalize_spec\");\n begin\n F2;" + }, + { + "function_def": "procedure F3;", + "function_body": "pragma Import (Ada, F3, \"ada__text_io__finalize_spec\");\n begin\n F3;" + }, + { + "function_def": "procedure F4;", + "function_body": "pragma Import (Ada, F4, \"ada__strings__unbounded__finalize_spec\");\n begin\n F4;" + }, + { + "function_def": "procedure F5;", + "function_body": "pragma Import (Ada, F5, \"system__storage_pools__subpools__finalize_spec\");\n begin\n F5;" + }, + { + "function_def": "procedure F6;", + "function_body": "pragma Import (Ada, F6, \"system__finalization_masters__finalize_spec\");\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n begin\n F6;" + }, + { + "function_def": "procedure F7;", + "function_body": "<<<<<<< HEAD\n pragma Import (Ada, F7, \"system__finalization_masters__finalize_spec\");\n begin\n=======\n pragma Import (Ada, F7, \"system__file_io__finalize_body\");\n begin\n E109 := E109 - 1;\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n F7;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n<<<<<<< HEAD\n=======\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n<<<<<<< HEAD\n=======\n Runtime_Finalize;\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Exception_Tracebacks : Integer;\n pragma Import (C, Exception_Tracebacks, \"__gl_exception_tracebacks\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n<<<<<<< HEAD\n\n procedure Install_Handler;\n pragma Import (C, Install_Handler, \"__gnat_install_handler\");\n\n Handler_Installed : Integer;\n pragma Import (C, Handler_Installed, \"__gnat_handler_installed\");\n=======\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Exception_Tracebacks := 1;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n<<<<<<< HEAD\n if Handler_Installed = 0 then\n Install_Handler;\n end if;\n=======\n Runtime_Initialize (1);\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n\n Finalize_Library_Objects := finalize_library'access;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n<<<<<<< HEAD\n E23 := E23 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E50 := E50 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Streams'Elab_Spec;\n E49 := E49 + 1;\n Interfaces.C'Elab_Spec;\n System.Exceptions'Elab_Spec;\n E29 := E29 + 1;\n System.Finalization_Root'Elab_Spec;\n E68 := E68 + 1;\n Ada.Finalization'Elab_Spec;\n E66 := E66 + 1;\n System.Storage_Pools'Elab_Spec;\n E87 := E87 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Storage_Pools.Subpools'Elab_Spec;\n System.Pool_Global'Elab_Spec;\n E89 := E89 + 1;\n System.File_Control_Block'Elab_Spec;\n E77 := E77 + 1;\n System.File_Io'Elab_Body;\n E64 := E64 + 1;\n E93 := E93 + 1;\n System.Finalization_Masters'Elab_Body;\n E79 := E79 + 1;\n E70 := E70 + 1;\n Ada.Tags'Elab_Body;\n E52 := E52 + 1;\n System.Soft_Links'Elab_Body;\n E13 := E13 + 1;\n System.Os_Lib'Elab_Body;\n E74 := E74 + 1;\n System.Secondary_Stack'Elab_Body;\n E17 := E17 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E06 := E06 + 1;\n Ada.Text_Io.Text_Streams'Elab_Spec;\n E98 := E98 + 1;\n=======\n E023 := E023 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E066 := E066 + 1;\n Ada.Strings'Elab_Spec;\n E050 := E050 + 1;\n Ada.Containers'Elab_Spec;\n E038 := E038 + 1;\n System.Exceptions'Elab_Spec;\n E025 := E025 + 1;\n System.Soft_Links'Elab_Body;\n E013 := E013 + 1;\n Interfaces.C'Elab_Spec;\n System.Os_Lib'Elab_Body;\n E070 := E070 + 1;\n Ada.Strings.Maps'Elab_Spec;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E056 := E056 + 1;\n System.Secondary_Stack'Elab_Body;\n E017 := E017 + 1;\n System.Object_Reader'Elab_Spec;\n System.Dwarf_Lines'Elab_Spec;\n E045 := E045 + 1;\n E076 := E076 + 1;\n E052 := E052 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E037 := E037 + 1;\n E078 := E078 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E099 := E099 + 1;\n Ada.Streams'Elab_Spec;\n E097 := E097 + 1;\n System.File_Control_Block'Elab_Spec;\n E113 := E113 + 1;\n System.Finalization_Root'Elab_Spec;\n E112 := E112 + 1;\n Ada.Finalization'Elab_Spec;\n E110 := E110 + 1;\n System.File_Io'Elab_Body;\n E109 := E109 + 1;\n System.Storage_Pools'Elab_Spec;\n E157 := E157 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E153 := E153 + 1;\n System.Storage_Pools.Subpools'Elab_Spec;\n E151 := E151 + 1;\n Ada.Strings.Unbounded'Elab_Spec;\n E145 := E145 + 1;\n Ada.Calendar'Elab_Spec;\n Ada.Calendar'Elab_Body;\n E119 := E119 + 1;\n Ada.Calendar.Time_Zones'Elab_Spec;\n E128 := E128 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E006 := E006 + 1;\n Ada.Text_Io.Text_Streams'Elab_Spec;\n E170 := E170 + 1;\n System.Regexp'Elab_Spec;\n E168 := E168 + 1;\n Ada.Directories'Elab_Spec;\n Ada.Directories'Elab_Body;\n E117 := E117 + 1;\n E115 := E115 + 1;\n>>>>>>> 69f69bc261da4a8489896c1cdee2a7aab20a4053\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_controller\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure write_File is", + "function_body": "Output : File_Type;\n\n line : String := \"Text output\";\n loop_value : integer := 0;\n\nbegin\n Create (File => Output,\n Mode => Out_File,\n Name => \"output.txt\");\n\n\n while loop_value < 1 loop\n begin\n -- You can process the contents of Line here.\n Put_Line (Output, Line);\n loop_value := 1;" + }, + { + "function_def": "procedure Register_Path", + "function_body": "(This : access Uri_Router;\n Rgx_Str : Interfaces.C.Strings.Chars_Ptr;\n Cb : Callback_Function) -- uri_router.hh:36\n with Import => True, \n Convention => CPP, \n External_Name => \"_ZN10uri_router13register_pathEPKcPFvP14capture_groupsPvE\";\n\n procedure Register_Default (This : access Uri_Router; Cb : Default_Callback) -- uri_router.hh:37\n with Import => True, \n Convention => CPP, \n External_Name => \"_ZN10uri_router16register_defaultEPFvPKcPvE\";\n\n function Match_Path\n (This : access Uri_Router;\n Path : Interfaces.C.Strings.Chars_Ptr;\n Response : System.Address) return Extensions.Bool -- uri_router.hh:38\n with Import => True, \n Convention => CPP, \n External_Name => \"_ZN10uri_router10match_pathEPKcPv\";" + }, + { + "function_def": "procedure Define_Visitor (Spec_File, Body_File : IO.File_Type; Base_Name : String; Types : String_Array);", + "function_body": "procedure Define_Storage (Spec_File : IO.File_Type; Base_Name : String);\n function Substring (Input, Separator : String; Item_Number : Positive) return String;\n\n generic\n with procedure Process_Field (Field_Name, Type_Name : String; Last : Boolean);\n procedure Iterate_Fields (List : String);\n\n procedure Define_Ast (Output_Dir, Base_Name : String; Types : String_Array) is\n Spec_Path : constant String := Output_Dir & \"/\"\n & Ada.Characters.Handling.To_Lower (Base_Name) & \"s.ads\";\n Body_Path : constant String := Output_Dir & \"/\"\n & Ada.Characters.Handling.To_Lower (Base_Name) & \"s.adb\";\n Spec_File, Body_File : IO.File_Type;\n Handle_Name : constant String := Base_Name & \"_Handle\";\n begin\n IO.Create (File => Spec_File, Name => Spec_Path);\n IO.Create (File => Body_File, Name => Body_Path);\n\n IO.Put_Line (Spec_File, \"with Ada.Containers.Formal_Indefinite_Vectors;\");\n IO.Put_Line (Spec_File, \"with L_Strings; use L_Strings;\");\n IO.Put_Line (Spec_File, \"with Tokens; use Tokens;\");\n IO.New_Line (Spec_File);\n IO.Put_Line (Spec_File, \"package \" & Base_Name & \"s with\");\n IO.Put_Line (Spec_File, \" Abstract_State => State is\");\n IO.Put_Line (Body_File, \"package body \" & Base_Name & \"s with\");\n IO.Put_Line (Body_File, \" Refined_State => (State => Container) is\");\n IO.Put_Line (Spec_File, \" type \" & Base_Name & \" is abstract tagged private;\");\n IO.Put_Line (Spec_File, \" type \" & Handle_Name & \" is new Positive;\");\n IO.Put_Line (Spec_File, \" function Is_Valid (Handle : \" & Handle_Name & \") return Boolean;\");\n IO.Put_Line (Body_File, \" function Is_Valid (Handle : Expr_Handle) return Boolean with\");\n IO.Put_Line (Body_File, \" Refined_Post => (if Is_Valid'Result then \" &\n \"Handle in Storage.First_Index (Container) .. Storage.Last_Index (Container)) is\");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" return Handle in Storage.First_Index (Container) .. Storage.Last_Index (Container);\");\n IO.Put_Line (Body_File, \" end Is_Valid;\");\n IO.New_Line (Body_File);\n IO.Put_Line (Spec_File, \" procedure Store (The_\" & Base_Name & \" : \" & Base_Name & \"'Class;\");\n IO.Put_Line (Spec_File, \" Result : out \" & Handle_Name & \";\");\n IO.Put_Line (Spec_File, \" Success : out Boolean) with\");\n IO.Put_Line (Spec_File, \" Post => (if Success then Is_Valid (Result));\");\n IO.Put_Line (Spec_File, \" function Retrieve (Handle : \" & Handle_Name\n & \") return \" & Base_Name & \"'Class with\");\n IO.Put_Line (Spec_File, \" Pre => Is_Valid (Handle);\");\n IO.Put_Line (Body_File, \" function Retrieve (Handle : Expr_Handle) return Expr'Class is\");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" return Storage.Element (Container, Handle);\");\n IO.Put_Line (Body_File, \" end Retrieve;\");\n\n IO.Put_Line (Body_File, \" procedure Store (The_\" & Base_Name & \" : \" & Base_Name & \"'Class;\");\n IO.Put_Line (Body_File, \" Result : out \" & Handle_Name & \";\");\n IO.Put_Line (Body_File, \" Success : out Boolean) is separate;\");\n -- The AST classes.\n for The_Type of Types loop\n declare\n Class_Name : constant String := Substring (The_Type.all, \":\", 1);\n Fields : constant String := Substring (The_Type.all, \":\", 2);\n begin\n Define_Type (Spec_File, Body_File, Base_Name, Class_Name, Fields);" + }, + { + "function_def": "IO.Put_Line (Spec_File, \" procedure Accept_Visitor (Self : Expr; V : \"", + "function_body": "& \"in out Visitors.Visitor'Class) with \"\n & \"Global => (Input => State);\");\n IO.Put_Line (Body_File, \" procedure Accept_Visitor (Self : Expr; V : \"\n & \"in out Visitors.Visitor'Class) is \");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" null; -- maybe raise an exception here\");\n IO.Put_Line (Body_File, \" end Accept_Visitor;\");\n IO.New_Line (Body_File);\n\n IO.Put_Line (Spec_File, \"private\");\n IO.Put_Line (Spec_File, \" type \" & Base_Name & \" is abstract tagged null record;\");\n Define_Storage (Spec_File, Base_Name);\n\n for The_Type of Types loop\n declare\n Class_Name : constant String := Substring (The_Type.all, \":\", 1);\n Fields : constant String := Substring (The_Type.all, \":\", 2);\n begin\n Define_Full_Type (Spec_File, Body_File, Base_Name, Class_Name, Fields);" + }, + { + "function_def": "procedure Iterate_Types is new Iterate_Fields (Define_One_Type);", + "function_body": "begin\n IO.Put (Spec_File, \" type \" & Class_Name & \" is new \" & Base_Name & \" with \");\n\n if Field_List'Length > 0 then\n IO.Put_Line (Spec_File, \"record\");\n Iterate_Types (Field_List);\n IO.Put_Line (Spec_File, \" end record;\");\n else\n IO.Put_Line (Spec_File, \"null record;\");\n end if;\n end Define_Full_Type;\n\n procedure Define_Storage (Spec_File : IO.File_Type; Base_Name : String) is\n Handle_Name : constant String := Base_Name & \"_Handle\";\n begin\n IO.Put_Line (Spec_File, \" Max_Element_Size : constant Natural := 2272;\");\n IO.Put_Line (Spec_File, \" package Storage is new Ada.Containers.Formal_Indefinite_Vectors\");\n IO.Put_Line (Spec_File, \" (Index_Type => \" & Handle_Name & \",\");\n IO.Put_Line (Spec_File, \" Element_Type => \" & Base_Name & \"'Class,\");\n IO.Put_Line (Spec_File, \" Max_Size_In_Storage_Elements => Max_Element_Size);\");\n IO.Put_Line (Spec_File, \" -- Should be Bounded => False, but that triggers a prover bug\");\n IO.Put_Line (Spec_File, \" pragma Compile_Time_Warning (True, \"\"gnatprove bug workaround\"\");\");\n IO.New_Line (Spec_File);\n IO.Put_Line (Spec_File, \" Container : Storage.Vector (5) with Part_Of => State;\");\n IO.New_Line (Spec_File);\n end Define_Storage;\n\n procedure Define_Subprogram (Spec_File, Body_File : IO.File_Type;\n Base_Name, Class_Name, Field_List : String) is\n pragma Unreferenced (Field_List);\n use Ada.Strings.Fixed;\n\n begin\n -- Visitor pattern.\n IO.New_Line (Spec_File);\n IO.Put_Line (Spec_File, \" procedure Accept_Visitor (Self : \"\n & Class_Name & \"; V : in out Visitors.Visitor'Class) with\");\n IO.Put_Line (Spec_File, \" Global => (Input => State);\");\n IO.New_Line (Body_File);\n IO.Put_Line (Body_File, \" overriding procedure Accept_Visitor (Self : \"\n & Class_Name & \"; V : in out Visitors.Visitor'Class) is\");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" V.Visit_\" & Class_Name & \"_\" & Base_Name & \" (Self);\");\n IO.Put_Line (Body_File, \" end Accept_Visitor;\");\n end Define_Subprogram;\n\n procedure Define_Type (Spec_File, Body_File : IO.File_Type;\n Base_Name, Class_Name, Field_List : String) is\n use Ada.Strings.Fixed;\n\n procedure Define_Accessor (Field_Name, Type_Name : String; Last : Boolean);\n procedure Define_Parameter_Body (Field_Name, Type_Name : String; Last : Boolean);\n procedure Define_Parameter_Spec (Field_Name, Type_Name : String; Last : Boolean);\n procedure Initialize_Field (Field_Name, Type_Name : String; Last : Boolean);\n\n procedure Define_Accessor (Field_Name, Type_Name : String; Last : Boolean) is\n pragma Unreferenced (Last);\n begin\n IO.Put (Spec_File, \" function Get_\" & Field_Name & \" (Self : \"\n & Class_Name & \") return \" & Type_Name);\n if Type_Name = Base_Name & \"_Handle\" then\n IO.Put_Line (Spec_File, \" with\");\n IO.Put_Line (Spec_File, \" Post => Is_Valid (Get_\" & Field_Name & \"'Result);\");\n else\n IO.Put_Line (Spec_File, \";\");\n end if;\n IO.New_Line (Body_File);\n IO.Put_Line (Body_File, \" function Get_\" & Field_Name & \" (Self : \"\n & Class_Name & \") return \" & Type_Name & \" is\");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" return Self.\" & Field_Name & \";\");\n IO.Put_Line (Body_File, \" end Get_\" & Field_Name & \";\");\n end Define_Accessor;\n\n procedure Define_Parameter_Body (Field_Name, Type_Name : String; Last : Boolean) is\n begin\n IO.Put (Body_File, \"My_\" & Field_Name & \" : \" & Type_Name);\n if not Last then\n IO.Put (Body_File, \"; \");\n end if;\n end Define_Parameter_Body;\n\n procedure Define_Parameter_Spec (Field_Name, Type_Name : String; Last : Boolean) is\n begin\n IO.Put (Spec_File, \"My_\" & Field_Name & \" : \" & Type_Name);\n if not Last then\n IO.Put (Spec_File, \"; \");\n end if;\n end Define_Parameter_Spec;\n\n procedure Initialize_Field (Field_Name, Type_Name : String; Last : Boolean) is\n pragma Unreferenced (Type_Name, Last);\n begin\n IO.Put_Line (Body_File, \" E.\" & Field_Name & \" := My_\" & Field_Name & \";\");\n end Initialize_Field;\n\n procedure Iterate_Accessors is new Iterate_Fields (Define_Accessor);\n procedure Iterate_Initialization is new Iterate_Fields (Initialize_Field);\n procedure Iterate_Parameters_Body is new Iterate_Fields (Define_Parameter_Body);\n procedure Iterate_Parameters_Spec is new Iterate_Fields (Define_Parameter_Spec);\n\n begin\n IO.Put_Line (Spec_File, \"\");\n IO.Put_Line (Spec_File, \" type \" & Class_Name & \" is new \" & Base_Name & \" with private;\");\n\n Iterate_Accessors (Field_List);\n IO.Put (Spec_File, \" procedure Create_\" & Class_Name & \" (\");\n\n IO.New_Line (Body_File);\n IO.Put (Body_File, \" procedure Create_\" & Class_Name & \" (\");\n Iterate_Parameters_Spec (Field_List);\n IO.Put_Line (Spec_File, \"; Result : out \" & Base_Name & \"_Handle);\");\n Iterate_Parameters_Body (Field_List);\n IO.Put_Line (Body_File, \"; Result : out \" & Base_Name & \"_Handle) is\");\n IO.Put_Line (Body_File, \" E : \" & Class_Name & \";\");\n IO.Put_Line (Body_File, \" Success : Boolean;\");\n IO.Put_Line (Body_File, \" begin\");\n Iterate_Initialization (Field_List);\n IO.Put_Line (Body_File, \" Store (E, Result, Success);\");\n IO.Put_Line (Body_File, \" end Create_\" & Class_Name & \";\");\n end Define_Type;\n\n procedure Define_Visitor (Spec_File, Body_File : IO.File_Type; Base_Name : String; Types : String_Array) is\n begin\n IO.Put_Line (Spec_File, \" package Visitors is\");\n IO.Put_Line (Spec_File, \" type Visitor is tagged null record;\");\n IO.Put_Line (Body_File, \" package body Visitors is\");\n\n for The_Type of Types loop\n declare\n Type_Name : constant String := Substring (The_Type.all, \":\", 1);\n begin\n IO.Put_Line (Spec_File, \" procedure Visit_\" & Type_Name & \"_\" & Base_Name &\n \" (Self : in out Visitor; The_\" & Base_Name &\n \" : \" & Type_Name & \") with\");\n IO.Put_Line (Spec_File, \" Global => (Input => Exprs.State);\");\n IO.Put_Line (Body_File, \" procedure Visit_\" & Type_Name & \"_\" & Base_Name &\n \" (Self : in out Visitor; The_\" & Base_Name &\n \" : \" & Type_Name & \") is\");\n IO.Put_Line (Body_File, \" begin\");\n IO.Put_Line (Body_File, \" null;\");\n IO.Put_Line (Body_File, \" end Visit_\" & Type_Name & \"_\" & Base_Name & \";\");\n IO.New_Line (Body_File);" + }, + { + "function_def": "procedure Scan_Token is", + "function_body": "procedure Add_Token (Kind : Token_Kind) with\n Global => (input => (Start, Current, Source, Line),\n in_out => (Error_Reporter.State, SPARK.Text_IO.Standard_Error, Token_List)),\n Pre => Source'First <= Start and then Start < Current and then Current - 1 <= Source'Last;\n procedure Add_Token (Kind : Token_Kind; Lexeme : String) with\n Global => (input => (Line),\n in_out => (Error_Reporter.State, SPARK.Text_IO.Standard_Error, Token_List));\n procedure Advance (C : out Character) with\n Global => (Input => Source, In_Out => Current),\n Pre => Current >= Source'First and then\n Current <= Source'Last and then\n Current < Integer'Last,\n Post => Current = Current'Old + 1;\n procedure Ignore with\n Global => (Input => Source, In_Out => Current),\n Pre => Current >= Source'First and then\n Current <= Source'Last and then\n Current < Integer'Last,\n Post => Current = Current'Old + 1;\n procedure Advance_If_Match (Expected : Character; Match : out Boolean) with\n Global => (in_out => Current, Input => Source),\n Pre => Source'First <= Current and then Source'Last < Integer'Last,\n Post => (if Match then\n (Current - 1 <= Source'Last and then Current = Current'Old + 1)\n else\n Current = Current'Old);\n function Peek return Character with\n Global => (Input => (Current, Source)),\n Pre => Current >= Source'First,\n Post => (if Peek'Result /= NUL then Current <= Source'Last);\n function Peek_Next return Character with\n Pre => Current >= Source'First and then Current < Integer'Last;\n procedure Scan_Identifier with\n Pre => Source'First <= Start and then Start < Current and then\n Current - 1 <= Source'Last and then Source'Last < Integer'Last,\n Post => Current >= Current'Old;\n procedure Scan_Number with\n Pre => Source'First <= Start and then Start < Current and then\n Current - 1 <= Source'Last and then Source'Last < Integer'Last,\n Post => Current >= Current'Old;\n procedure Scan_String with\n Global => (Input => (Source, Start),\n in_out => (Current, Line, Token_List, SPARK.Text_IO.Standard_Error, Error_Reporter.State)),\n Pre => Source'First <= Start and then Start < Current and then Source'Last < Integer'Last,\n Post => Current >= Current'Old;\n\n procedure Add_Token (Kind : Token_Kind) is\n begin\n Add_Token (Kind, Source (Start .. Current - 1));\n end Add_Token;\n\n procedure Add_Token (Kind : Token_Kind; Lexeme : String) is\n use Tokens.Lists;\n begin\n if Length (Token_List) >= Token_List.Capacity then\n Error_Reporter.Error (Line_No => Line,\n Message => \"Out of token capacity\");\n return;\n end if;\n Append (Container => Token_List,\n New_Item => Tokens.New_Token (Kind => Kind,\n Lexeme => Lexeme,\n Line => Line));\n end Add_Token;\n\n procedure Advance (C : out Character) is\n begin\n Current := Current + 1;\n C := Source (Current - 1);\n end Advance;\n\n procedure Advance_If_Match (Expected : Character; Match : out Boolean) is\n begin\n if Is_At_End then\n Match := False;\n elsif Source (Current) /= Expected then\n Match := False;\n else\n Current := Current + 1;\n Match := True;\n end if;\n end Advance_If_Match;\n\n procedure Ignore is\n begin\n Current := Current + 1;\n end Ignore;\n\n function Peek return Character is\n begin\n if Is_At_End then\n return NUL;\n else\n return Source (Current);\n end if;\n end Peek;\n\n function Peek_Next return Character is\n begin\n if Current + 1 > Source'Last then\n return NUL;\n else\n return Source (Current + 1);\n end if;\n end Peek_Next;\n\n procedure Scan_Identifier is\n-- use Hashed_Maps;\n begin\n while Is_Alphanumeric (Peek)\n or else Peek = '_' loop\n pragma Loop_Invariant (Start <= Current);\n pragma Loop_Invariant (Source'First <= Current and then Current <= Source'Last);\n pragma Loop_Invariant (Start = Start'Loop_Entry);\n pragma Loop_Invariant (Current >= Current'Loop_Entry);\n Ignore;\n end loop;\n declare\n Text : constant L_String := L_Strings.To_Bounded_String (Source (Start .. Current - 1));\n begin\n-- if Contains (Keywords, Text) then\n-- Add_Token (Element (Keywords, Text));\n if Text = \"and\" then\n Add_Token (T_AND);\n elsif Text = \"class\" then\n Add_Token (T_CLASS);\n elsif Text = \"else\" then\n Add_Token (T_ELSE);\n elsif Text = \"false\" then\n Add_Token (T_FALSE);\n elsif Text = \"for\" then\n Add_Token (T_FOR);\n elsif Text = \"fun\" then\n Add_Token (T_FUN);\n elsif Text = \"if\" then\n Add_Token (T_IF);\n elsif Text = \"nil\" then\n Add_Token (T_NIL);\n elsif Text = \"or\" then\n Add_Token (T_OR);\n elsif Text = \"print\" then\n Add_Token (T_PRINT);\n elsif Text = \"return\" then\n Add_Token (T_RETURN);\n elsif Text = \"super\" then\n Add_Token (T_SUPER);\n elsif Text = \"this\" then\n Add_Token (T_THIS);\n elsif Text = \"true\" then\n Add_Token (T_TRUE);\n elsif Text = \"var\" then\n Add_Token (T_VAR);\n elsif Text = \"while\" then\n Add_Token (T_WHILE);\n else\n Add_Token (T_IDENTIFIER);\n end if;" + }, + { + "function_def": "procedure Sort is new Ada.Containers.Generic_Anonymous_Array_Sort", + "function_body": "(Index_Type => Natural,\n Less => Less,\n Swap => Swap);\n\n Text : League.Strings.Universal_String;\n ASCII : constant League.Text_Codecs.Text_Codec :=\n League.Text_Codecs.Codec (+\"USASCII\");\n begin\n for J in Map'Range loop\n Map (J) := J;\n end loop;\n\n Sort (Map'First, Map'Last);\n\n Text.Append (\"{\");\n\n for J of Map loop\n if Text.Length > 1 then\n Text.Append (\",\");\n end if;\n\n Text.Append ('\"');\n Text.Append (Keys (J));\n Text.Append (\"\"\":\"\"\");\n Text.Append (Key.Value (Keys (J)).To_String);\n Text.Append ('\"');\n end loop;\n\n Text.Append (\"}\");\n\n return ASCII.Encode (Text).To_Stream_Element_Array;\n end Thumbprint;\n\n ------------------------------------\n -- Validate_Compact_Serialization --\n ------------------------------------\n\n procedure Validate_Compact_Serialization\n (Self : out JSON_Web_Signature'Class;\n Value : League.Strings.Universal_String;\n Secret : Ada.Streams.Stream_Element_Array;\n Valid : out Boolean)\n is\n use type League.Strings.Universal_String;\n\n function Alg return Wide_Wide_String;\n\n function Alg return Wide_Wide_String is\n begin\n return Self.Header.Value (+\"alg\").To_String.To_Wide_Wide_String;\n end Alg;\n\n List : constant League.String_Vectors.Universal_String_Vector :=\n Value.Split ('.');\n\n Ok : Boolean;\n Document : League.JSON.Documents.JSON_Document;\n ASCII : constant League.Text_Codecs.Text_Codec :=\n League.Text_Codecs.Codec (+\"USASCII\");\n Encoded_Payload : League.Strings.Universal_String;\n Raw_Header : League.Stream_Element_Vectors.Stream_Element_Vector;\n Encoded_Header : League.Strings.Universal_String;\n Text : League.Strings.Universal_String;\n Signature : League.Stream_Element_Vectors.Stream_Element_Vector;\n Encoded_Signature : League.Strings.Universal_String;\n\n begin\n Valid := False;\n -- 1. Parse the JWS representation to extract the serialized values...\n if List.Length /= 3 then\n return;\n end if;\n\n Encoded_Header := List.Element (1);\n Encoded_Payload := List.Element (2);\n Encoded_Signature := List.Element (3);\n -- 2. decode the encoded representation of the JWS Protected Header\n From_Base_64_URL\n (Data => Encoded_Header,\n Value => Raw_Header,\n Success => Ok);\n\n if not Ok then\n return;\n end if;\n\n -- 3. Verify that the resulting octet sequence is ... JSON object\n Document := League.JSON.Documents.From_JSON (Raw_Header);\n\n if not Document.Is_Object or Document.Is_Empty then\n return;\n end if;\n\n Self.Header := (Document.To_JSON_Object with null record);\n -- 5. Verify that the implementation understands and can process...\n if not Self.Header.Value (+\"alg\").Is_String then\n return;\n elsif Alg not in \"none\" | \"HS256\"\n and (Alg /= \"RS256\" or RS256_Validation_Link = null)\n then\n return;\n elsif Self.Header.Critical.Length > 0 then\n -- Any critical extensions are not supported here\n return;\n end if;\n\n -- 6. decode the encoded representation of the JWS Payload\n From_Base_64_URL\n (Data => Encoded_Payload,\n Value => Self.Payload,\n Success => Ok);\n\n if not Ok then\n return;\n end if;\n\n -- 7. decode the encoded representation of the JWS Signature\n From_Base_64_URL\n (Data => Encoded_Signature,\n Value => Signature,\n Success => Ok);\n\n if not Ok then\n return;\n end if;\n\n -- 8. Validate the JWS Signature against the JWS Signing Input\n Text := Encoded_Header & \".\" & Encoded_Payload;\n\n if not Self.Header.Validate_Signature\n (ASCII.Encode (Text), Secret, Signature)\n then\n return;\n end if;\n\n Valid := True;\n end Validate_Compact_Serialization;\n\n ------------------------\n -- Validate_Signature --\n ------------------------\n\n function Validate_Signature\n (Self : JOSE_Header'Class;\n Data : League.Stream_Element_Vectors.Stream_Element_Vector;\n Secret : Ada.Streams.Stream_Element_Array;\n Value : League.Stream_Element_Vectors.Stream_Element_Vector)\n return Boolean\n is\n use type League.Strings.Universal_String;\n\n Alg : constant League.Strings.Universal_String := Self.Algorithm;\n begin\n if Alg = +\"HS256\" then\n declare\n use type League.Stream_Element_Vectors.Stream_Element_Vector;\n begin\n return Self.Compute_Signature (Data, Secret) = Value;" + }, + { + "function_def": "procedure Disp_Flush", + "function_body": "(X1 : Int32_T;\n Y1 : Int32_T;\n X2 : Int32_T;\n Y2 : Int32_T;\n Color : access constant Color_Array)\n with Convention => C;\n\n procedure Disp_Fill\n (X1 : Int32_T;\n Y1 : Int32_T;\n X2 : Int32_T;\n Y2 : Int32_T;\n Color : Lv.Color.Color_T)\n with Convention => C;\n\n procedure Disp_Map\n (X1 : Int32_T;\n Y1 : Int32_T;\n X2 : Int32_T;\n Y2 : Int32_T;\n Color : access constant Color_Array)\n with Convention => C;\n\n ----------------\n -- Initialize --\n ----------------\n\n procedure Initialize (Enable_Pointer : Boolean := True) is\n Mouse_Cursor_Icon : Integer;\n pragma Import (C, Mouse_Cursor_Icon, \"mouse_cursor_icon\");\n begin\n\n Lv.Hal.Disp.Init_Drv (LV_Disp_Drv'Access);\n\n LV_Disp_Drv.Disp_Flush := Disp_Flush'Access;\n LV_Disp_Drv.Disp_Fill := Disp_Fill'Access;\n LV_Disp_Drv.Disp_Map := Disp_Map'Access;\n\n LV_Disp := Lv.Hal.Disp.Register (LV_Disp_Drv'Access);\n Lv.Hal.Disp.Set_Active (LV_Disp);\n\n Pointer.Union.Point := (0, 0);\n Pointer.State := Lv.Hal.Indev.State_Rel;\n\n Lv.Hal.Indev.Init_Drv (LV_Indev_Keypad_Drv'Access);\n LV_Indev_Keypad_Drv.Read := Read_Keypad'Access;\n LV_Indev_Keypad_Drv.C_Type := Lv.Hal.Indev.Type_Keypad;\n LV_Indev_Keypad := Lv.Hal.Indev.Register (LV_Indev_Keypad_Drv'Access);\n\n Lv.Hal.Indev.Init_Drv (LV_Indev_Pointer_Drv'Access);\n LV_Indev_Pointer_Drv.Read := Read_Pointer'Access;\n LV_Indev_Pointer_Drv.C_Type := Lv.Hal.Indev.Type_Pointer;\n LV_Indev_Pointer := Lv.Hal.Indev.Register (LV_Indev_Pointer_Drv'Access);\n\n if Enable_Pointer then\n Cursor_Obj := Lv.Objx.Img.Create (Lv.Objx.Scr_Act, Lv.Objx.No_Obj);\n Lv.Objx.Img.Set_Src (Cursor_Obj, Mouse_Cursor_Icon'Address);\n Lv.Indev.Set_Cursor (LV_Indev_Pointer, Cursor_Obj);\n end if;\n end Initialize;\n\n ------------------\n -- Keypad_Indev --\n ------------------\n\n function Keypad_Indev return Lv.Hal.Indev.Indev_T\n is (LV_Indev_Keypad);\n\n ------------------\n -- Read_Pointer --\n ------------------\n\n function Read_Pointer (Data : access Indev_Data_T) return U_Bool is\n begin\n\n Pointer.State := Lv.Hal.Indev.State_Rel;\n\n for Elt of BB_Pico_Bsp.Touch.Get_All_Touch_Points loop\n if Elt.Weight /= 0 then\n Pointer.Union.Point.X := Integer_16 (Elt.X);\n Pointer.Union.Point.Y := Integer_16 (Elt.Y);\n Pointer.State := Lv.Hal.Indev.State_Pr;\n end if;\n end loop;\n\n Data.all := Pointer;\n\n return 0;\n end Read_Pointer;\n\n -----------------\n -- Read_Keypad --\n -----------------\n\n function Read_Keypad (Data : access Indev_Data_T) return U_Bool is\n use BBQ10KBD;\n\n State : Key_State;\n begin\n loop\n State := BB_Pico_Bsp.Keyboard.Key_FIFO_Pop;\n\n case State.Kind is\n when Error =>\n return 0; -- No more events\n when Held_Pressed =>\n null; -- LVGL doesn't have a held pressed event\n when others =>\n declare\n Pressed : constant Boolean := State.Kind = BBQ10KBD.Pressed;\n begin\n case State.Code is\n when Keyboard.KEY_JOY_UP =>\n Data.Union.Key := Lv.LV_KEY_UP;\n when Keyboard.KEY_JOY_DOWN =>\n Data.Union.Key := Lv.LV_KEY_DOWN;\n when Keyboard.KEY_JOY_LEFT =>\n Data.Union.Key := Lv.LV_KEY_LEFT;\n when Keyboard.KEY_JOY_RIGHT =>\n Data.Union.Key := Lv.LV_KEY_RIGHT;\n when Keyboard.KEY_JOY_CENTER =>\n Data.Union.Key := Lv.LV_KEY_ENTER;\n when Keyboard.KEY_BTN_LEFT1 =>\n Data.Union.Key := Lv.LV_KEY_PREV;\n when Keyboard.KEY_BTN_LEFT2 =>\n Data.Union.Key := Lv.LV_KEY_HOME;\n when Keyboard.KEY_BTN_RIGHT1 =>\n Data.Union.Key := Lv.LV_KEY_BACKSPACE;\n when Keyboard.KEY_BTN_RIGHT2 =>\n Data.Union.Key := Lv.LV_KEY_NEXT;\n when others =>\n Data.Union.Key := Unsigned_32 (State.Code);\n end case;\n\n Data.State := (if Pressed\n then Lv.Hal.Indev.State_Pr\n else Lv.Hal.Indev.State_Rel);\n return 1;" + }, + { + "function_def": "function Read_Register (This : STMPE811_Device;", + "function_body": "Reg_Addr : UInt8)\n return UInt8\n is\n Data : TSC_Data (1 .. 1);\n Status : SPI_Status;\n\n begin\n This.Chip_Select.Clear;\n\n This.Port.Transmit (SPI_Data_8b'(16#80# or Reg_Addr, 0), Status);\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n This.Port.Receive (Data, Status);\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n This.Chip_Select.Set;\n\n return Data (Data'First);\n end Read_Register;\n\n --------------------\n -- Write_Register --\n --------------------\n\n procedure Write_Register (This : in out STMPE811_Device;\n Reg_Addr : UInt8;\n Data : UInt8)\n is\n Status : SPI_Status;\n\n begin\n This.Chip_Select.Clear;\n\n This.Port.Transmit (SPI_Data_8b'(Reg_Addr, Data), Status);\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n This.Chip_Select.Set;\n end Write_Register;\n\n ---------------\n -- IOE_Reset --\n ---------------\n\n procedure IOE_Reset (This : in out STMPE811_Device) is\n Discard : UInt8;\n begin\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#02#);\n\n -- Give some time for the reset\n This.Time.Delay_Milliseconds (10);\n\n for X in UInt8 range 0 .. 64 loop\n Discard := This.Read_Register (X);\n end loop;\n\n This.Write_Register (IOE_REG_SYS_CTRL2, 16#00#);\n end IOE_Reset;\n\n --------------------------\n -- IOE_Function_Command --\n --------------------------\n\n procedure IOE_Function_Command (This : in out STMPE811_Device;\n Func : UInt8;\n Enabled : Boolean)\n is\n Reg : UInt8 := This.Read_Register (IOE_REG_SYS_CTRL2);\n begin\n -- CTRL2 functions are disabled when corresponding bit is set\n\n if Enabled then\n Reg := Reg and (not Func);\n else\n Reg := Reg or Func;\n end if;\n\n This.Write_Register (IOE_REG_SYS_CTRL2, Reg);\n end IOE_Function_Command;\n\n -------------------\n -- IOE_AF_Config --\n -------------------\n\n procedure IOE_AF_Config (This : in out STMPE811_Device;\n Pin : UInt8;\n Enabled : Boolean) is\n Reg : UInt8 := This.Read_Register (IOE_REG_GPIO_AF);\n begin\n if Enabled then\n Reg := Reg or Pin;\n else\n Reg := Reg and (not Pin);\n end if;\n\n This.Write_Register (IOE_REG_GPIO_AF, Reg);\n end IOE_AF_Config;\n\n ----------------\n -- Get_IOE_ID --\n ----------------\n\n function Get_IOE_ID (This : in out STMPE811_Device) return UInt16 is\n begin\n return (UInt16 (This.Read_Register (0)) * (2**8))\n or UInt16 (This.Read_Register (1));\n end Get_IOE_ID;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize (This : in out STMPE811_Device) return Boolean\n is\n Discard : UInt8;\n begin\n\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#02#);\n\n -- Give some time for the reset\n This.Time.Delay_Milliseconds (10);\n\n for X in UInt8 range 0 .. 64 loop\n Discard := This.Read_Register (X);\n end loop;\n\n declare\n Id : constant UInt16 := This.Get_IOE_ID;\n begin\n if Id /= 16#0811# then\n return False;\n end if;" + }, + { + "function_def": "procedure Initialize;", + "function_body": "----------------\n -- Initialize --\n ----------------\n\n procedure Initialize is\n Config : RP.SPI.SPI_Configuration;\n begin\n SPI_CLK.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI);\n SPI_DO.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI);\n SPI_DI.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI);\n\n Config := RP.SPI.Default_SPI_Configuration;\n\n Config.Baud := 10_000_000;\n Config.Blocking := True;\n\n SPI_Port.Configure (Config);\n\n -- DMA --\n declare\n use RP.DMA;\n Config : DMA_Configuration;\n begin\n Config.Trigger := DMA_TX_Trigger;\n Config.High_Priority := True;\n Config.Data_Size := Transfer_8;\n Config.Increment_Read := True;\n Config.Increment_Write := False;\n\n RP.DMA.Configure (SPI_TX_DMA, Config);" + }, + { + "function_def": "procedure CommsTime is", + "function_body": "-- Parameters for the experimental run.\n-- Experiments - number of data points collected\n-- Iterations_Experiment - number of cycles round commstime for a single data point\nExperiments : CONSTANT INTEGER := 100;\nIterations_Experiment : CONSTANT INTEGER := 10000;\n\ntask PREFIX is\n entry Send(Value : in INTEGER);\nend PREFIX;\n\ntask SEQ_DELTA is\n entry Send(Value : in INTEGER);\nend SEQ_DELTA;\n\ntask SUCC is\n entry Send(Value : in INTEGER);\nend SUCC;\n\ntask PRINTER is\n entry Send(Value : in INTEGER);\nend PRINTER;\n\ntask body PREFIX is\n N : INTEGER;\nbegin\n for i in 0..Experiments loop\n SEQ_DELTA.Send(0);\n for j in 0..Iterations_Experiment loop\n accept Send(Value : in INTEGER) do\n N := Value;" + }, + { + "function_def": "procedure Getinfo is", + "function_body": "use GNAT.Command_Line;\n use Ada.Text_IO;\n command_Name : constant String :=\n Ada.Directories.Base_Name (Ada.Command_Line.Command_Name);\n procedure Help;\n procedure Help is\n use ASCII;\n begin\n Put_Line\n (command_Name & \" [options]\" & LF &\n \"Options:\" & LF &\n \" --ada-library-version Print Ada-Library version\" & LF &\n \" --binding-version Print Binding version\" & LF &\n \" --library-version Print version of the 0mq library.\" & LF &\n \" -? | -h | --help Print this text\");\n\n end Help;\n\nbegin\n loop\n case Getopt (\"-binding-version \" &\n \"-ada-library-version \" &\n \"-library-version \" &\n \"-compiler-version \" &\n \"h ? -help\") is -- Accepts '-a', '-ad', or '-b argument'\n when ASCII.NUL => exit;\n\n when 'h' | '?' =>\n Help;\n return;\n\n when '-' =>\n if Full_Switch = \"-binding-version\" then\n Put_Line (ZMQ.Image (ZMQ.Binding_Version));\n elsif Full_Switch = \"-library-version\" then\n Put_Line (ZMQ.Image (ZMQ.Library_Version));\n elsif Full_Switch = \"-compiler-version\" then\n Put_Line (Standard'Compiler_Version);\n elsif Full_Switch = \"-ada-library-version\" then\n Put_Line ($version);\n elsif Full_Switch = \"-help\" then\n Help;\n return;\n end if;\n when others =>\n raise Program_Error; -- cannot occur!\n end case;\n end loop;\n\n loop\n declare\n S : constant String := Get_Argument (Do_Expansion => True);\n begin\n exit when S'Length = 0;\n Put_Line (\"Got \" & S);" + }, + { + "function_def": "function uuid_is_null", + "function_body": "(arg1 : access unsigned_char) return int; -- uuid.h:84:5\n pragma Import (C, uuid_is_null, \"uuid_is_null\");\n\n function uuid_parse\n (arg1 : access Character;\n arg2 : access unsigned_char) return int; -- uuid.h:87:5\n pragma Import (C, uuid_parse, \"uuid_parse\");\n\n procedure uuid_unparse\n (arg1 : access unsigned_char;\n arg2 : access Character); -- uuid.h:90:6\n pragma Import (C, uuid_unparse, \"uuid_unparse\");\n\n procedure uuid_unparse_lower\n (arg1 : access unsigned_char;\n arg2 : access Character); -- uuid.h:91:6\n pragma Import (C, uuid_unparse_lower, \"uuid_unparse_lower\");\n\n procedure uuid_unparse_upper\n (arg1 : access unsigned_char;\n arg2 : access Character); -- uuid.h:92:6\n pragma Import (C, uuid_unparse_upper, \"uuid_unparse_upper\");\n\n function uuid_time\n (arg1 : access unsigned_char;\n arg2 : access bits_time_h.timeval) return time_h.time_t; -- uuid.h:95\n pragma Import (C, uuid_time, \"uuid_time\");\n\n function uuid_type\n (arg1 : access unsigned_char) return int; -- uuid.h:96:5\n pragma Import (C, uuid_type, \"uuid_type\");\n\n function uuid_variant\n (arg1 : access unsigned_char) return int; -- uuid.h:97:5\n pragma Import (C, uuid_variant, \"uuid_variant\");\n\n end uuid_uuid_h;\n\n -----------------------------------------------------\n\n procedure Clear (this : in out UUID) is\n begin\n uuid_uuid_h.uuid_clear(this.data(this.data'First)'Unrestricted_Access);\n end Clear;\n\n function \"<\" (l, r : UUID) return Boolean is\n begin\n return uuid_uuid_h.uuid_compare (l.data (l.data'first)'Unrestricted_Access,\n r.data (r.data'first)'Unrestricted_Access) < 0;\n end \"<\";\n function \">\" (l, r : UUID) return Boolean is\n begin\n return uuid_uuid_h.uuid_compare (l.data (l.data'first)'Unrestricted_Access,\n r.data(r.data'first)'Unrestricted_Access) > 0;\n end \">\";\n\n function \"=\" (l, r : UUID) return Boolean is\n begin\n return uuid_uuid_h.uuid_compare (l.data (l.data'first)'Unrestricted_Access,\n r.data (r.data'first)'Unrestricted_Access) = 0;\n end \"=\";\n\n\n function Generate return UUID is\n begin\n return ret : UUID do\n uuid_uuid_h.uuid_generate (ret.data (ret.data'First)'Unrestricted_Access);\n end return;\n end Generate;\n\n procedure Generate (this : out UUID) is\n begin\n this := Generate;\n end Generate;\n\n function Generate_Random return UUID is\n begin\n return ret : UUID do\n uuid_uuid_h.uuid_generate_random (ret.data (ret.data'First)'Unrestricted_Access);\n end return;\n end Generate_Random;\n procedure Generate_Random (this : out UUID) is\n begin\n this := Generate_Random;" + }, + { + "function_def": "function conv is new ada.Unchecked_Conversion (system.Address, zlibVersion_Access);", + "function_body": "zlibVersion : zlibVersion_Access;\n begin\n p.open (File_Name => \"/lib/libz.so.1\");\n zlibVersion := conv (p.Sym (\"zlibVersion\"));\n declare\n version : constant string := Interfaces.C.Strings.Value (zlibVersion.all);\n begin\n test.Assert (Version (version'first + 1 ) = '.', \"Dont seem to be a version numnber\");\n test.Assert (Version (version'first + 3 ) = '.', \"Dont seem to be a version numnber\");" + }, + { + "function_def": "procedure Chat_Server is", + "function_body": "package ATI renames Ada.Text_IO;\n\tpackage CM renames Chat_Messages;\n\tpackage LLU renames Lower_Layer_UDP;\n\tpackage ACL renames Ada.Command_Line;\n\tpackage CC renames Client_Collections;\n\tpackage ASU renames Ada.Strings.Unbounded;\n\n\tuse type CM.Message_Type;\n\n \tServer_EP: \tLLU.End_Point_Type;\n \tEP: \t\tLLU.End_Point_Type;\n\tExpired: \tBoolean;\n\tPort: \t\tInteger; \n \tBuffer_In: \taliased LLU.Buffer_Type(1024);\n\tBuffer_Out: \taliased LLU.Buffer_Type(1024);\n\tCollection_W: \tCC.Collection_Type;\n\tCollection_R: \tCC.Collection_Type;\n\tUnique: \tBoolean;\n\tMess: \t\tCM.Message_Type;\n\tNick: \t\tASU.Unbounded_String;\n\tComment: \tASU.Unbounded_String;\n\tNick_Server:\tASU.Unbounded_String;\n\tPassword:\tASU.Unbounded_String;\n\tData: \t\tASU.Unbounded_String;\n\tAdmin_EP:\tLLU.End_Point_Type;\n\tAdmin_Pass:\tASU.Unbounded_String;\n\tShutdown:\tBoolean;\n\nbegin\n\t\n\t-- Asignaci\u00f3n y bindeado del Servidor\n\tPort := Integer'Value(ACL.Argument(1));\n\tPassword := ASU.To_Unbounded_String(ACL.Argument(2));\n\tServer_EP := LLU.Build (LLU.To_IP(LLU.Get_Host_Name), Port);\n\tLLU.Bind (Server_EP);\n\n\tShutdown := False;\n\n loop\n\tLLU.Reset (Buffer_In);\n\tLLU.Reset (Buffer_Out);\n\n \tLLU.Receive (Server_EP, Buffer_In'Access, 1000.0, Expired);\n\n\tif Expired then\n\t\tATI.Put_Line (\"Please, try again\");\n\telse\n\t\tMess := CM.Message_Type'Input (Buffer_In'Access);\n\t\n\t\tif Mess = CM.Init then\n\t\t\tEP := LLU.End_Point_Type'Input (Buffer_In'Access);\n\t\t\tNick := ASU.Unbounded_String'Input (Buffer_In'Access);\n\t\t\tATI.Put(\"INIT received from \" & ASU.To_String(Nick));\n\t\t\t\n\t\t\tif ASU.To_String (Nick) = \"reader\" then\n\t\t\t\t\n\t\t\t\tUnique := False; \n\t\t\t\n\t\t\t\tCC.Add_Client (Collection_R, EP, Nick, Unique);\n\t\t\telse\n\t\t\t\tUnique := True;\n\n\t\t\t\tbegin\n\t\t\t\t\tCC.Add_Client (Collection_W, EP, Nick, Unique);\n\t\t\t\t\n\t\t\t\t\t--Aviso de entrada al servidor\n\t\t\t\t\tMess := CM.Server;\n\t\t\t\t\tCM.Message_Type'Output(Buffer_Out'Access, Mess);\t\n\t\t\t\t\tNick_Server := ASU.To_Unbounded_String(\"server\");\n\t\t\t\t\tASU.Unbounded_String'Output(Buffer_Out'Access, \n\t\t\t\t\tNick_Server);\n\t\t\t\t\tComment := ASU.To_Unbounded_String(ASU.To_String(Nick) \n\t\t\t\t\t& \" joins the chat\");\n\t\t\t\t\tASU.Unbounded_String'Output(Buffer_Out'Access, Comment);\n\t\t\t\t\tCC.Send_To_All (Collection_R, Buffer_Out'Access);\n\t\t\t\t\n\t\t\t\texception\n\t\t\t\t\twhen CC.Client_Collection_Error =>\n\t\t\t\t\t\tATI.Put (\". IGNORED, nick already used\");" + }, + { + "function_def": "procedure lab2c is", + "function_body": "package Int_IO is new Ada.Text_IO.Integer_IO(Integer); use Int_IO;\n lower, upper, init, max : Integer;\n\n procedure Push(space : in out arrayTypes.stringArray; base : in out intArray; top : in out intArray; stack : in Integer; text : in charArray) is\n begin\n top(stack) := top(stack) + 1;\n if top(stack) > base(stack + 1) then\n Put_Line(\"PUSH OVERFLOW \"); New_Line;\n top(stack) := top(stack) - 1;\n for i in (init + 1)..max loop\n Put(i); Put(\": \");\n if (i > base(1) and i <= top(1)) or (i > base(2) and i <= top(2)) or (i > base(3) and i <= top(3)) or (i > base(4) and i <= top(4)) then\n for j in 1..space(i)'Length loop\n Put(space(i)(j));\n end loop;\n New_Line;\n else\n New_Line;\n end if;\n end loop;\n top(stack) := top(stack) + 1;\n reallocate.reallocate(max, init, stack, 4, base, top, 0.15, space, text);\n else\n space(top(stack)) := text;\n end if;\n end Push;\n\n procedure Pop(space : in out arrayTypes.stringArray; base : in out intArray; top : in out intArray; stack : in Integer; text : out charArray) is\n begin\n if top(stack) = base(stack) then\n Put_Line(\"POP OVERFLOW\");\n else\n text := space(top(stack));\n top(stack) := top(stack) - 1;\n end if;\n end Pop;\nbegin\n Put(\"Enter a lower bound: \"); Get(lower);\n Put(\"Enter an upper bound: \"); Get(upper);\n Put(\"Enter an initial location: \"); Get(init);\n Put(\"Enter the max: \"); Get(max);\n\n declare\n space : arrayTypes.stringArray(lower..upper);\n top : arrayTypes.intArray(1..4);\n base : arrayTypes.intArray(1..5);\n text : String(1..13);\n temp : arrayTypes.charArray(1..10);\n begin\n for j in 1..5 loop\n base(j) := Integer(Float'Floor(((Float(j) - 1.0) / 4.0 * Float(max - init)) + Float(init)));\n if j < 5 then\n top(j) := base(j);\n end if;\n end loop;\n New_Line;\n Put(\"Enter text: \"); Get(text);\n while text /= \"end \" loop\n for i in 4..13 loop\n temp(i - 3) := text(i);\n end loop;\n Put_Line(text);\n if text(1) = 'I' then\n Push(space, base, top, Integer'Value(text(2..2)), temp);\n elsif text(1) = 'D' then\n Pop(space, base, top, Integer'Value(text(2..2)), temp);\n New_Line;\n for i in 1..10 loop\n Put(temp(i));\n end loop;\n New_Line;\n end if;\n Put(\"Enter text: \"); Get(text);\n end loop;" + }, + { + "function_def": "procedure graphics is", + "function_body": "begin\n\tClear_Window;\n\tSet_Graphical_Mode(On);\n\tbackground;\n\tStart_screen(35, 12);\n\t--vinst(25, 12);\n\tSkip_Line;\n\tbackground;\n\tprotocoll_background(125, 4);\n\tlogo_background(24, 4);\n\tlogo(24, 4);\nend graphics;\n\n\nfunction Generate\n\treturn Integer is\n\n\tsubtype Nums is Integer range 1..6;\n\tpackage RN is\n\tnew Ada.Numerics.Discrete_Random(Nums);\n\tGen : RN.Generator;\nbegin\n\tRN.Reset(Gen);\n\treturn RN.Random(Gen);" + }, + { + "function_def": "function Triss(Rolls: Arr)", + "function_body": "return Integer is\n\n\tbegin\n\tfor I in 1..3 loop\n\t\tif Rolls(I) = Rolls(I+1) and Rolls(I) = Rolls(I+2) then\n\t\treturn 3 * Rolls(I);\n\t\tend if;\n\tend loop;\n\treturn 0;" + }, + { + "function_def": "procedure goto_prev is", + "function_body": "begin\n\t\t\t-- Clear screen\n\t\t\tfor X in 1..17 loop\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + X * 2);\n\t\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\t\tPut(\" \");\n\t\t\t\tGoto_XY(1000,1000);\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected = 1 then\n\t\t\t\tCurr_Index_Selected := 16;\n\t\t\tend if;\n\n\t\t\tloop\n\t\t\t\tCurr_Index_Selected := Curr_Index_Selected - 1;\n\t\t\t\tif avail_points(Curr_Index_Selected) >= 0 then\n\t\t\t\t\texit;\n\t\t\t\tend if;\n\t\t\t\tif Curr_Index_Selected = 1 then\n\t\t\t\t\tCurr_Index_Selected := 16;\n\t\t\t\tend if;\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected > 6 then\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2 + 4);\n\t\t\telse\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2);\n\t\t\tend if;\n\t\t\tSet_Foreground_Colour(Red);\n\t\t\tPut(\"=>\");\n\t\t\tSet_Foreground_Colour(Black);\n\t\t\tGoto_XY(1000,1000);\n\t\tend goto_prev;\n\n\t\tprocedure goto_next is\n\n\t\tbegin\n\t\t\t-- Clear screen\n\t\t\tfor X in 1..17 loop\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + X * 2);\n\t\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\t\tPut(\" \");\n\t\t\t\tGoto_XY(1000,1000);\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected = 15 then\n\t\t\t\tCurr_Index_Selected := 0;\n\t\t\tend if;\n\n\t\t\tloop\n\t\t\t\tCurr_Index_Selected := Curr_Index_Selected + 1;\n\t\t\t\tif avail_points(Curr_Index_Selected) >= 0 then\n\t\t\t\t\texit;\n\t\t\t\tend if;\n\t\t\t\tif Curr_Index_Selected = 15 then\n\t\t\t\t\tCurr_Index_Selected := 0;\n\t\t\t\tend if;\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected > 6 then\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2 + 4);\n\t\t\telse\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2);\n\t\t\tend if;\n\n\t\t\tSet_Foreground_Colour(Red);\n\t\t\tPut(\"=>\");\n\t\t\tSet_Foreground_Colour(Black);\n\t\t\tGoto_XY(1000,1000);\n\t\tend goto_next;\n\n\tbegin\n\t\t-- Build array of available slots\n\t\tfor x in 1..15 loop\n\t\t\tif avail_points(x) >= 0 then\n\t\t\t\ttemp_arraysize := temp_arraysize + 1;\n\t\t\tend if;\n\t\tend loop;\n\n\t\tdeclare\n\t\t\ttest_array : dynamic_array(0..temp_arraysize);\n\t\t\tbegin\n\t\t\tfor x in 1..15 loop\n\t\t\t\tif avail_points(x) >= 0 then\n\t\t\t\t\ttest_array(temp_array_index) := temp_array_index * 2;\n\t\t\t\t\ttemp_array_index := temp_array_index + 1;\n\t\t\t\tend if;\n\t\t\tend loop;" + }, + { + "function_def": "procedure background is", + "function_body": "begin\n\n\t-- Skriver ut bakgrundsf\u00e4rgen f\u00f6r hela terminalen\n\tfor X in 1..300 loop\n\t\tfor Y in 1..50 loop\n\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\tgoto_xy(X, Y);\n\t\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\tend background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure protocoll_background (X_Start, Y_Start: in Integer) is\n\n\tbegin\n\n\t-- Skriver ut ramen kring protokollet\n\tfor X in 1..31 loop\n\t\tfor Y in 1..41 loop\n\t\tPut(ASCII.ESC & protocoll_frame_bg);\n\t\tgoto_xy((X_Start - 3 + X), (Y_Start - 2 + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\t-- Skriver ut protokollets bakgrund\n\tfor X in 1..25 loop\n\t\tfor Y in 1..38 loop\n\t\tPut(ASCII.ESC & \"[48;5;15m\");\n\t\tgoto_xy(X_Start + X, Y_Start + Y);\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\tend protocoll_background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\tprocedure Start_screen (X_Start, Y_Start : in integer) is\n\n\tbegin\n\t\tSet_Foreground_Colour(white);\n\t\tSet_Graphical_Mode(off);\n\n\t\tgoto_xy(X_Start, Y_Start);\n\t\tPut(\"YYYYYYY YYYYYYY ttttttt \");\n\t\tgoto_xy(X_Start, Y_Start + 1);\n\t\tPut(\"Y:::::Y Y:::::Y t:::::t \");\n\t\tgoto_xy(X_Start, Y_Start + 2);\n\t\tPut(\"Y:::::Y Y:::::Y t:::::t \");\n\t\tgoto_xy(X_Start, Y_Start + 3);\n\t\tPut(\"Y::::::Y Y::::::Y t:::::t \");\n\t\tgoto_xy(X_Start, Y_Start + 4);\n\t\tPut(\" YY:::::Y Y:::::YY aaaaaaaaaaaaa ttttttt:::::ttttttt zzzzzzzzzzzzzzzzz yyyyyyy yyyyyyy \");\n\t\tgoto_xy(X_Start, Y_Start + 5);\n\t\tPut(\" Y:::::Y Y:::::Y a::::::::::::a t:::::::::::::::::t z:::::::::::::::z y:::::y y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 6);\n\t\tPut(\" Y:::::Y:::::Y aaaaaaaaa:::::a t:::::::::::::::::t z::::::::::::::z y:::::y y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 7);\n\t\tPut(\" Y:::::::::Y a::::a tttttt:::::::tttttt zzzzzzzz::::::z y:::::y y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 8);\n\t\tPut(\" Y:::::Y aa::::::::::::a t:::::t z::::::z y:::::y y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 9);\n\t\tPut(\" Y:::::Y a::::a a:::::a t:::::t tttttt z::::::z y:::::::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 10);\n\t\tPut(\" YYYY:::::YYYY a:::::aaaa::::::a tt::::::::::::::t z::::::::::::::z y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 11);\n\t\tPut(\" Y:::::::::::Y a::::::::::aa:::a tt:::::::::::tt z:::::::::::::::z y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 12);\n\t\tPut(\" YYYYYYYYYYYYY aaaaaaaaaa aaaa ttttttttttttt zzzzzzzzzzzzzzzzzz y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 13);\n\t\tPut(\" y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 14);\n\t\tPut(\" y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 15);\n\t\tPut(\" y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 16);\n\t\tPut(\" y:::::y \");\n\t\tgoto_xy(X_Start, Y_Start + 17);\n\t\tPut(\" yyyyyyy \");\n\n\t\tgoto_xy(X_Start + 20, Y_Start + 16);\n\t\tSet_Foreground_Colour(Red);\n\t\tPut(\"Tryck enter f\u00f6r att starta spelet...\");\n\n\n\n\tend Start_screen;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\tprocedure vinst (X_Start, Y_Start : in Integer) is\n\n\tbegin\n\n\tSet_Foreground_Colour(white);\n\tSet_Graphical_Mode(off);\n\tgoto_xy(X_Start, Y_Start);\n\n\tPut(\"DDDDDDDDDDDDD \");\n\tgoto_xy(X_Start, Y_Start + 1);\n\tPut(\"D::::::::::::DDD \");\n\tgoto_xy(X_Start, Y_Start + 2);\n\tPut(\"D:::::::::::::::DD \");\n\tgoto_xy(X_Start, Y_Start + 3);\n\tPut(\"DDD:::::DDDDD:::::D \");\n\tgoto_xy(X_Start, Y_Start + 4);\n\tPut(\"D:::::D D:::::D uuuuuu uuuuuu vvvvvvv vvvvvvv aaaaaaaaaaaaa nnnn nnnnnnnn nnnn nnnnnnnn \");\n\tgoto_xy(X_Start, Y_Start + 5);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v v:::::v a::::::::::::a n:::nn::::::::nn n:::nn::::::::nn \");\n\tgoto_xy(X_Start, Y_Start + 6);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v v:::::v aaaaaaaaa:::::a n::::::::::::::nn n::::::::::::::nn \");\n\tgoto_xy(X_Start, Y_Start + 7);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v v:::::v a::::a nn:::::::::::::::nnn:::::::::::::::n\");\n\tgoto_xy(X_Start, Y_Start + 8);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v v:::::v aaaaaaa:::::a n:::::nnnn:::::n n:::::nnnn:::::n\");\n\tgoto_xy(X_Start, Y_Start + 9);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v v:::::v aa::::::::::::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 10);\n\tPut(\"D:::::D D:::::D u::::u u::::u v:::::v:::::v a::::aaaa::::::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 11);\n\tPut(\" D:::::D D:::::D u:::::uuuu:::::u v:::::::::v a::::a a:::::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 12);\n\tPut(\"DDD:::::DDDDD:::::D u:::::::::::::::uu v:::::::v a::::a a:::::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 13);\n\tPut(\"D:::::::::::::::DD u:::::::::::::::u v:::::v a:::::aaaa::::::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 14);\n\tPut(\"D::::::::::::DDD uu::::::::uu:::u v:::v a::::::::::aa:::a n::::n n::::n n::::n n::::n\");\n\tgoto_xy(X_Start, Y_Start + 15);\n\tPut(\"DDDDDDDDDDDDD uuuuuuuu uuuu vvv aaaaaaaaaa aaaa nnnnnn nnnnnn nnnnnn nnnnnn\");\n\n\nend vinst;\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\tprocedure clear_protocoll(X_Start, Y_Start: in Integer; Which_Protocoll_Or_Both: in Integer) is\n\t\tx : Integer := X_Start;\n\t\ty : Integer := Y_Start;\n\t\twidthcol1 : constant Integer := 13;\n\t\twidthcol2 : constant Integer := 5;\n\tbegin\n\t\tif Which_Protocoll_Or_Both = 0 or Which_Protocoll_Or_Both = 1 then\n\t\t\tFor I in 1..19 loop\n\t\t\t\tGoto_XY(X_Start + 2 + widthcol1, Y_Start - 1 + I * 2);\n\t\t\t\tcase I is\n\t\t\t\twhen 1 => Set_Text_Modes(Off, Off, On);\n\t\t\t\twhen 2..7 => Put(\" \");\n\t\t\t\twhen 8 => null;\n\t\t\t\twhen 9 => null;\n\t\t\t\twhen 10..18 => Put(\" \");\n\t\t\t\twhen 19 => null;\n\n\t\t\t\twhen others => null;\n\t\t\t\tend case;\n\t\t\tend loop;\n\t\tend if;\n\n\t\tif Which_Protocoll_Or_Both = 0 or Which_Protocoll_Or_Both = 2 then\n\t\t\tFor I in 1..19 loop\n\t\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2, Y_Start - 1 + I * 2);\n\t\t\t\tcase I is\n\t\t\t\twhen 1 => Set_Text_Modes(Off, Off, On);\n\t\t\t\twhen 2..7 => Put(\" \");\n\t\t\t\twhen 8 => null;\n\t\t\t\twhen 9 => null;\n\t\t\t\twhen 10..18 => Put(\" \");\n\t\t\t\twhen 19 => null;\n\n\t\t\t\twhen others => null;\n\t\t\t\tend case;\n\t\t\tend loop;\n\t\tend if;\n\tend clear_protocoll;\n\n\tprocedure update_protocoll(X_Start, Y_Start: in Integer; prot1, prot2: in Protocoll_Type; Which_Protocoll_Or_Both: in Integer; Other_Color: in Integer) is\n\tx : Integer := X_Start;\n\ty : Integer := Y_Start;\n\twidthcol1 : constant Integer := 13;\n\twidthcol2 : constant Integer := 5;\n\twidthcol3 : constant Integer := 5;\n\theight: constant Integer := 39;\n\ttext_width: constant Integer := 12;\n\tpoints_width: constant Integer := 5;\n\tavail_place_text_color1: String := \"[38;5;208m\";\n\ttemp1, temp2 : Protocoll_Type;\n\n\tprocedure other_color_chk is\n\tbegin\n\t\tif Other_Color = 1 then\n\t\t\tPut(ASCII.ESC & avail_place_text_color1);\n\t\tend if;\n\tend other_color_chk;\n\n\tprocedure reset_black_color is\n\tbegin\n\t\tPut(ASCII.ESC & \"[38;5;0m\");\n\tend reset_black_color;\n\n\tbegin\n\t-- Frame\n\tSet_Background_Colour(White);\n\tSet_Foreground_Colour(Black);\n\t-- Skriver ut horisontella linjer\n\twhile y < Y_Start + height loop\n\t\tGoto_XY(X_Start + 1, y);\n\t\tPut(Horisontal_Line, Times => widthcol1);\n\t\tGoto_XY(X_Start + 2 + widthcol1, y);\n\t\tPut(Horisontal_Line, Times => widthcol2);\n\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2, y);\n\t\tPut(Horisontal_Line, Times => widthcol3);\n\t\tGoto_XY(X_Start + 4 + widthcol1 + widthcol2 + widthcol3, y);\n\t\ty := y + 2;\n\tend loop;\n\n\tfor I in Y_Start..(Y_Start+height -1) loop\n\t\tGoto_XY(X_Start,I);\n\t\tif (I + Y_Start) mod 2 /= 0 then\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\tPut(Vertical_Line);\n\t\telse\n\t\tif I = Y_Start then\n\t\t\tPut(Upper_Left_Corner);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Horisontal_Down);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Horisontal_Down);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Upper_Right_Corner);\n\t\telsif I = Y_Start+height - 1 then\n\t\t\tPut(Lower_Left_Corner);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Horisontal_Up);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Horisontal_Up);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Lower_Right_Corner);\n\t\telse\n\t\t\tPut(Vertical_Right);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Cross);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Cross);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Vertical_Left);\n\t\tend if;\n\t\tend if;\n\tend loop;\n\n\tSet_Graphical_Mode(Off);\n\n\tFor I in 1..19 loop\n\t\tGoto_XY(X_Start + 2, Y_Start - 1 + I * 2);\n\t\t--Set_Background_Colour(Blue);\n\t\tcase I is\n\t\t\twhen 1 => Set_Text_Modes(On, Off, Off); Put(\"Spelare:\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 2 => Put(\"Ettor\");\n\t\t\twhen 3 => Put(\"Tv\u00e5or\");\n\t\t\twhen 4 => Put(\"Treor\");\n\t\t\twhen 5 => Put(\"Fyror\");\n\t\t\twhen 6 => Put(\"Femmor\");\n\t\t\twhen 7 => Put(\"Sexor\"); Set_Text_Modes(On, Off, Off);\n\t\t\twhen 8 => Put(\"Summa:\");\n\t\t\twhen 9 => Put(\"BONUS\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 10 => Put(\"Par\");\n\t\t\twhen 11 => Put(\"Tv\u00e5 par\");\n\t\t\twhen 12 => Put(\"Triss\");\n\t\t\twhen 13 => Put(\"Fyrtal\");\n\t\t\twhen 14 => Put(\"K\u00e5k\");\n\t\t\twhen 15 => Put(\"Liten stege\");\n\t\t\twhen 16 => Put(\"Stor stege\");\n\t\t\twhen 17 => Put(\"Chans\");\n\t\t\twhen 18 => Put(\"Yatzy\"); Set_Text_Modes(On, Off, Off);\n\t\t\twhen 19 => Put(\"Summa:\");\n\n\t\t\twhen others => null;\n\t\tend case;\n\tend loop;\n\ttemp1 := Prot1;\n\ttemp2 := Prot2;\n\tif Which_Protocoll_Or_Both = 0 or Which_Protocoll_Or_Both = 1 then\n\t\tFor I in 1..19 loop\n\t\t\tGoto_XY(X_Start + 2 + widthcol1, Y_Start - 1 + I * 2);\n\n\n\n\t\t\tcase I is\n\t\t\twhen 1 => Set_Text_Modes(Off, Off, Off); Put(\"P1\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 2..7 => other_color_chk; if Prot1(I - 1) /= -1 then Put(Prot1(I - 1), 1 + widthcol2 / 2); end if;\n\n\t\t\twhen 8 => if Other_Color /= 1 then reset_black_color; Put(Calcfirstsum(temp1), 1 + widthcol2 / 2); end if;\n\t\t\twhen 9 => if Other_Color /= 1 then reset_black_color; Put(Bonus(temp1), 1 + widthcol2 / 2); end if;\n\t\t\twhen 10..18 => other_color_chk; if Prot1(I - 3) /= -1 then Put(Prot1(I - 3), 1 + widthcol2 / 2); end if;\n\t\t\twhen 19 => if Other_Color /= 1 then reset_black_color; Put(Calctotsum(temp1), 1 + widthcol2 / 2); end if;\n\n\t\t\twhen others => null;\n\t\t\tend case;\n\t\tend loop;\n\tend if;\n\n\tif Which_Protocoll_Or_Both = 0 or Which_Protocoll_Or_Both = 2 then\n\t\tFor I in 1..19 loop\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2, Y_Start - 1 + I * 2);\n\t\t\tcase I is\n\t\t\twhen 1 => Set_Text_Modes(Off, Off, Off); Put(\"P2\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 2..7 => other_color_chk; if Prot2(I - 1) /= -1 then Put(Prot2(I - 1), 1 + widthcol2 / 2); end if;\n\n\n\t\t\twhen 8 => if Other_Color /= 1 then reset_black_color; Put(Calcfirstsum(temp2), 1 + widthcol2 / 2); end if;\n\t\t\twhen 9 => if Other_Color /= 1 then reset_black_color; Put(Bonus(temp2), 1 + widthcol2 / 2); end if;\n\n\t\t\twhen 10..18 => other_color_chk; if Prot2(I - 3) /= -1 then Put(Prot2(I - 3), 1 + widthcol2 / 2); end if;\n\t\twhen 19 => if Other_Color /= 1 then reset_black_color; Put(Calctotsum(temp2), 1 + widthcol2 / 2); end if;\n\n\t\t\twhen others => null;\n\t\t\tend case;\n\t\tend loop;\n\tend if;\n\n\treset_black_color;\n\n\tend update_protocoll;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure dice (A, X_Start, Y_Start: in Integer) is\n\n\tbegin\n\tGoto_XY(X_Start, Y_Start);\n\tfor I in 1..5 loop\n\t\t--Set_Background_Colour(White);\n\t\tif I = 1 then\n\t\tPut(Upper_Left_Corner);\n\t\tPut(Horisontal_Very_High_Line, Times => 9);\n\t\tPut(Upper_Right_Corner);\n\t\tGoto_XY(X_Start, Y_Start + I);\n\t\telsif I = 5 then\n\t\tPut(Lower_Left_Corner);\n\t\tPut(Horisontal_Very_Low_Line, Times => 9);\n\t\tPut(Lower_Right_Corner);\n\t\telse\n\t\tcase A is\n\t\t\twhen 1 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 2 or I = 4 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 2 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 3 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 4 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 5 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 6 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\n\t\t\twhen others => null;\n\t\tend case;\n\t\tend if;\n\tend loop;\n\n\n\tend dice;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\nprocedure dice_placement (D1, D2, D3, D4, D5 : in Integer) is\n\nbegin\n\n\t-- Only update dice if input is bigger than 0\n\tif D1 > 0 then Dice(D1, 8 + 15 * 1, 38); end if;\n\tif D2 > 0 then Dice(D2, 8 + 15 * 2, 38); end if;\n\tif D3 > 0 then Dice(D3, 8 + 15 * 3, 38); end if;\n\tif D4 > 0 then Dice(D4, 8 + 15 * 4, 38); end if;\n\tif D5 > 0 then Dice(D5, 8 + 15 * 5, 38); end if;\n\nend dice_placement;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tProcedure logo_background (X_Start, Y_Start : in Integer) is\n\n\tbegin\n\tfor X in 1..76 loop\n\t\tfor Y in 1..9 loop\n\t\tPut(ASCII.ESC & logo_frame_bg);\n\t\tgoto_xy((X_Start - 3 + X), (Y_Start - 2 + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\tend logo_background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tProcedure logo (X_Start, Y_Start : in Integer) is\n\n\tbegin\n\tSet_Background_Colour(White);\n\tSet_Foreground_Colour(Blue);\n\tSet_Bold_Mode(on);\n\n\tgoto_xy(X_Start, Y_Start);\n\tPut(\" ____ ____ __ _________ ________ ____ ____ \");\n\tgoto_xy(X_Start, Y_Start + 1);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\"_ _\");\n\tPut(Vertical_Line, Times => 2);\n\tPut(\"_ _\");\n\tPut(Vertical_Line);\n\tPut(\" / \\ \");\n\tPut(Vertical_Line);\n\tPut(\" _ _ \");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\" __ __\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ _\");\n\tPut(Vertical_Line, Times => 2);\n\tPut(\"_ _\");\n\tPut(Vertical_Line);\n\tgoto_xy(X_Start, Y_Start + 2);\n\tPut(\" \\ \\ / / / /\\ \\ \");\n\tPut(Vertical_Line);\n\tPut(\"_/ \");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\" \\_\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_/ / / \\ \\ / / \");\n\tgoto_xy(X_Start, Y_Start + 3);\n\tPut(\" \\ \\/ / / ____ \\ \");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\" / / _ \\ \\/ / \");\n\tgoto_xy(X_Start, Y_Start + 4);\n\tPut(\" _\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ _/ / \\ \\_ _\");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\"_ / /__/ \");\n\tPut(Vertical_Line);\n\tPut(\" _\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ \");\n\tgoto_xy(X_Start, Y_Start + 5);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tgoto_xy(X_Start, Y_Start + 6);\n\tPut(\" \");\n\n\t-- ____ ____ __ _________ ________ ____ ____\n\t-- |_ _||_ _| / \\ | _ _ | | __ __| |_ _||_ _|\n\t-- \\ \\ / / / /\\ \\ |_/ | | \\_| |_/ / / \\ \\ / /\n\t-- \\ \\/ / / ____ \\ | | / / _ \\ \\/ /\n\t-- _| |_ _/ / \\ \\_ _| |_ / /__/ | _| |_\n\t-- |______| |____| |____| |_____| |_______| |______|\n\n\tend logo;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure message4 (X_Start, Y_Start : in Integer; S : in String) is\n\n\tbegin\n\n\tSet_Graphical_Mode(Off);\n\n\t-- reset white first\n\tfor X in 1..51 loop\n\t\tPut(ASCII.ESC & \"[38;5;0m\");\n\t\t\tgoto_xy((X_Start + X), Y_Start + 22);\n\t\tPut(' ');\n\tend loop;\n\n\tgoto_xy(X_Start + 3, Y_Start + 25);\n\tPut(S);\n\n\tend message4;\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure message3 (X_Start, Y_Start : in Integer; S : in String) is\n\n\tbegin\n\n\tSet_Graphical_Mode(Off);\n\n\t-- reset white first\n\tfor X in 1..51 loop\n\t\tPut(ASCII.ESC & \"[38;5;196m\");\n\t\t\tgoto_xy((X_Start + X), Y_Start + 25);\n\t\tPut(' ');\n\tend loop;\n\n\tgoto_xy(X_Start + 3, Y_Start + 25);\n\tPut(S);\n\n\tend message3;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\tprocedure message2 (X_Start, Y_Start : in Integer; S : in String) is\n\n\tbegin\n\n\tSet_Graphical_Mode(Off);\n\n\t-- White inner frame\n\tfor X in 1..51 loop\n\t\tfor Y in 1..9 loop\n\t\tPut(ASCII.ESC & \"[48;5;15m\");\n\t\tif Y /= 5 then\n\t\t\tgoto_xy((X_Start + X), (Y_Start + Y));\n\t\telse\n\t\t\tgoto_xy((X_Start + X), (Y_Start + Y + 1));\n\t\tend if;\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\tgoto_xy(X_Start + 3, Y_Start + 8);\n\tPut(S);\n\tend message2;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure message (X_Start, Y_Start : in Integer; S : in String) is\n\n\tbegin\n\n\tSet_Graphical_Mode(Off);\n\n\tfor Y in 1..11 loop\n\t\tfor X in 1..55 loop\n\n\t\t\t-- om inte f\u00f6rsta eller inte sista raden\n\t\t\tif Y = 1 OR Y = 11 then\n\t\t\t\t\tif X mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\tend if;\n\t\t\telse\n\t\t\t\tif X = 1 OR X = 55 then\n\t\t\t\t\tif Y mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\tend if;\n\t\t\t\telse\n\t\t\t\t\tif Y mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\tend if;\n\t\t\t\tend if;\n\t\t\tend if;\n\n\t\tgoto_xy((X_Start - 2 + X), (Y_Start - 1 + Y));\n\t\tPut(' ');\n\n\t\tend loop;\n\tend loop;\n\n\n\n\t-- White inner frame\n\tfor X in 1..51 loop\n\t\tfor Y in 1..9 loop\n\t\tPut(ASCII.ESC & \"[48;5;15m\");\n\t\tgoto_xy((X_Start + X), (Y_Start + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\tgoto_xy(X_Start + 3, Y_Start + 5);\n Set_Foreground_Colour(Black);\n\tPut(S);\n\tend message;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure Test_TJa is\n\n\tOwn_Protocoll, Other_Protocoll: Protocoll_Type;\n\tSelected_Place : Integer;\n\n\tbegin\n\tReset_Colours; -- Standard colours is supposed to be black on white ...\n\tClear_Window;\n\tSet_Graphical_Mode(On);\n\tbackground;\n\tprotocoll_background(125, 4);\n\tlogo_background(24, 4);\n\tmessage(38, 18, \"Hejsan\");\n\n\t-- Draw a rectangle on screen ...\n\t--Set_Graphical_Mode(On);\n\tfor I in 1..15 loop\n\t\tcase I is\n\t\t\twhen 1 => Own_Protocoll(I) := 1;\n\t\t\twhen 2 => Own_Protocoll(I) := 2;\n\t\t\twhen 3 => Own_Protocoll(I) := 3;\n\t\t\twhen 4 => Own_Protocoll(I) := 4;\n\t\t\twhen 5 => Own_Protocoll(I) := 5;\n\t\t\twhen 6 => Own_Protocoll(I) := -1;\n\t\t\twhen 7 => Own_Protocoll(I) := -1;\n\t\t\twhen 8 => Own_Protocoll(I) := -1;\n\t\t\twhen 9 => Own_Protocoll(I) := -1;\n\t\t\twhen 10 => Own_Protocoll(I) := -1;\n\t\t\twhen 11 => Own_Protocoll(I) := -1;\n\t\t\twhen 12 => Own_Protocoll(I) := 15;\n\t\t\twhen 13 => Own_Protocoll(I) := -1;\n\t\t\twhen 14 => Own_Protocoll(I) := 15;\n\t\t\twhen 15 => Own_Protocoll(I) := -1;\n\t\t\twhen others => null;\n\t\t\t-- Own_Protocoll(I) := I;\n\t\tend case;\n\tend loop;\n\tfor I in 1..15 loop\n\t\tOther_Protocoll(I) := I;\n\tend loop;\n\n\n\n\tupdate_protocoll(125, 4, Own_Protocoll, Other_Protocoll);\n\n\tfor x in 1..5 loop\n\t\tdice(x,8 + 15 * x, 38);\n\t\t--dice_placement;\n\tend loop;\n\n\n\n\tlogo(24, 4);\n\n\tSet_Graphical_Mode(Off);\n\n\tplace(Own_Protocoll, Selected_Place);\n\n\n\tReset_Colours;\n\tReset_Text_Modes; -- Resets boold mode ...\n\n\n\n\tend Test_TJa;\n\n\tbegin\n\t\tTest_TJa;\n\t\tSkip_Line;" + }, + { + "function_def": "procedure graphics is", + "function_body": "begin\n\tClear_Window;\n\tSet_Graphical_Mode(On);\n\tbackground;\n\tprotocoll_background(125, 4);\n\tlogo_background(24, 4);\n\tlogo(24, 4);\nend graphics;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nprocedure Start_Game(Socket: in Socket_Type; Player: out Positive; Prot1, Prot2: out Protocoll_Type) is\n\tTX : String(1..100);\n\tTL : Natural;\nbegin -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n\tfor I in 1..15 loop\n\t\tProt1(I) := -1;\n\tend loop;\n\t\n\tProt2 := Prot1;\n\tGet_Line(Socket, TX, TL);\n\n\tif TX(1) = '1' then\n\t\tmessage(33, 18, \"Du \u00e4r spelare 1, v\u00e4ntar p\u00e5 spelare 2\");\n\t\tPlayer := 1;\n\t\tGet_Line(Socket, TX, TL);\n\t\tNew_Line;\n\tif TX(1) = '3' then\n\t\tmessage(33, 18, \"B\u00e5da spelare anslutna\");\n\tend if;\n\n\telsif TX(1) = '2' then\n\t\tmessage(33, 18, \"Du \u00e4r spelare 2\");\n\t\tPlayer := 2;\n\telse\n\t\traise DATATYPE_ERROR;\n\tend if;\n\t\n\tNew_Line;\n\n\tmessage(33, 18, \"Nu startar spelet\");\n\tNew_Line;\n\nend Start_Game;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nfunction Read(C: in Character)\n\treturn Natural is\n\t\n\tS: String(1..1);\nbegin\n\tS(1) := C;\n\treturn Integer'Value(S);\nend Read;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nprocedure Get_Rolls(Socket: in Socket_Type; Roll: out Rolls_Type) is\n\tTX: String(1..100);\n\tTL: Natural;\nbegin\n\n\tGet_Line(Socket, TX, TL);\n\tNew_Line;\n\n\tif TX(1) = '4' then -- 4 betyder inkomande t\u00e4rningar\n\t\t\n\t\tRoll.I := Read(TX(2));\n\t\n\t\tfor X in 1..Roll.I loop -- A betyder h\u00e4r antalet t\u00e4rningar\n\t\t\tRoll.Rolls(X) := Read(TX(X+2));\n\t\tend loop;\n\n\telsif TX(1) = '5' then -- 5 betyder info om gamestate\n\t\tif TX(2) = '0' then -- Annan spelare sl\u00e5r\n\t\t\tRoll.I := 6;\n\t\telsif TX(2) = '1' then -- Annan spelare har slagit\n\t\t\tRoll.I := 7;\n\t\t\t\n\t\t\tfor X in 1..5 loop\n\t\t\t\tRoll.Rolls(X) := Read(TX(X+2));\n\t\t\tend loop;\n\t\telsif TX(2) = '2' then -- Annan spelare vill placera\n\t\t\tRoll.I := 8;\n\t\t\t\n\t\t\tfor X in 1..5 loop\n\t\t\t\tRoll.Rolls(X) := Read(TX(X+2));\n\t\t\tend loop;\n\t\tend if;\n\telse\n\t\traise DATATYPE_ERROR;\n\tend if;\nend Get_Rolls;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nfunction GetI(Roll: in Rolls_Type)\n\treturn Integer is\nbegin\n\treturn Roll.I;\nend GetI;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nfunction GetR(Roll: in Rolls_Type)\n\treturn Arr is\nbegin\n\treturn Roll.Rolls;\nend GetR;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nprocedure Playerroll(Socket: in Socket_Type) is\nbegin\n\tPut_Line(Socket, \"51\");\nend Playerroll;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\nprocedure Sort(Arrayen_Med_Talen: in out Arr) is\n\t\n\t-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\tprocedure Swap(Tal_1,Tal_2: in out Integer) is\n\t\tTal_B : Integer; -- Temporary buffer\n\tbegin\n\t\tTal_B := Tal_1;\n\t\tTal_1 := Tal_2;\n\t\tTal_2 := Tal_B;\n\tend Swap;\n\t-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\n\tMinsta_Talet, Minsta_Talet_Index : Integer;\nbegin\n\tMinsta_Talet := 0;\n\n\tfor IOuter in Arrayen_Med_Talen'Range loop\n\t\tfor I in IOuter..Arrayen_Med_Talen'Last loop\n\t\t\tif I = IOuter or Arrayen_Med_Talen(I) > Minsta_Talet then\n\t\t\t\tMinsta_Talet := Arrayen_Med_Talen(I);\n\t\t\t\tMinsta_Talet_Index := I;\n\t\t\tend if;\n\t\tend loop;\n\t\t\n\t\tSwap(Arrayen_Med_Talen(IOuter), Arrayen_Med_Talen(Minsta_Talet_Index));\n\tend loop;\nend Sort;\n\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\nfunction Calcpoints(Prot: Protocoll_Type; Rolls: Arr)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\treturn Protocoll_Type is\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tfunction Ental(I: Integer; Rolls: Arr)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\treturn Integer is\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\tC : Integer := 0;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tbegin\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\tfor X in 1..5 loop\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\tif Rolls(X) = I then\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\tC := C + I;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\tend if;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\tend loop;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\treturn C;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tend Ental;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tfunction FourPair(Rolls: Arr)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\treturn Integer is\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tbegin\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\tfor I in 1..2 loop\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\tif Rolls(I) = Rolls(I+1) and Rolls(I) = Rolls(I+2) and Rolls(I) = Rolls(I+3) then\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\treturn 4 * Rolls(I);\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\tend if;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\tend loop;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\treturn 0;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tend FourPair;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tfunction Pair(Rolls: Arr)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\t\treturn Integer is\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tbegin\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t -- -- --\n\tfor I in 1..4 loop\n\t\tif Rolls(I) = Rolls(I+1) then\n\t\treturn 2 * Rolls(I);\n\t\tend if;\n\tend loop;\n\treturn 0;" + }, + { + "function_def": "function Triss(Rolls: Arr)", + "function_body": "return Integer is\n\n\tbegin\n\tfor I in 1..3 loop\n\t\tif Rolls(I) = Rolls(I+1) and Rolls(I) = Rolls(I+2) then\n\t\treturn 3 * Rolls(I);\n\t\tend if;\n\tend loop;\n\treturn 0;" + }, + { + "function_def": "procedure goto_prev is", + "function_body": "begin\n\t\t\t-- Clear screen\n\t\t\tfor X in 1..17 loop\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + X * 2);\n\t\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\t\tPut(\" \");\n\t\t\t\tGoto_XY(1000,1000);\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected = 1 then\n\t\t\t\tCurr_Index_Selected := 16;\n\t\t\tend if;\n\n\t\t\tloop\n\t\t\t\tCurr_Index_Selected := Curr_Index_Selected - 1;\n\t\t\t\tif avail_points(Curr_Index_Selected) >= 0 then\n\t\t\t\t\texit;\n\t\t\t\tend if;\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected > 6 then\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2 + 4);\n\t\t\telse\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2);\n\t\t\tend if;\n\n\t\t\tPut(\"->\");\n\t\t\tGoto_XY(1000,1000);\n\t\tend goto_prev;\n\n\t\tprocedure goto_next is\n\n\t\tbegin\n\t\t\t-- Clear screen\n\t\t\tfor X in 1..17 loop\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + X * 2);\n\t\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\t\tPut(\" \");\n\t\t\t\tGoto_XY(1000,1000);\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected = 15 then\n\t\t\t\tCurr_Index_Selected := 0;\n\t\t\tend if;\n\n\t\t\tloop\n\t\t\t\tCurr_Index_Selected := Curr_Index_Selected + 1;\n\t\t\t\tif avail_points(Curr_Index_Selected) >= 0 then\n\t\t\t\t\texit;\n\t\t\t\tend if;\n\t\t\t\tif Curr_Index_Selected = 15 then\n\t\t\t\t\tCurr_Index_Selected := 0;\n\t\t\t\tend if;\n\t\t\tend loop;\n\n\t\t\tif Curr_Index_Selected > 6 then\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2 + 4);\n\t\t\telse\n\t\t\t\tGoto_XY(Coord_Config_X, Coord_Config_Y + Curr_Index_Selected * 2);\n\t\t\tend if;\n\n\t\t\tPut(\"->\");\n\t\t\tGoto_XY(1000,1000);\n\t\tend goto_next;\n\n\tbegin\n\t\tPut(\"a1\"); -- DEBUG\n\t\t-- Build array of available slots\n\t\tfor x in 1..15 loop\n\t\t\tif avail_points(x) >= 0 then\n\t\t\t\ttemp_arraysize := temp_arraysize + 1;\n\t\t\tend if;\n\t\tend loop;\n\n\t\tNew_Line; Put(\"a2\"); -- DEBUG\n\t\tdeclare\n\t\t\ttest_array : dynamic_array(0..temp_arraysize);\n\t\t\tbegin\n\t\t\tfor x in 1..15 loop\n\t\t\t\tif avail_points(x) >= 0 then\n\t\t\t\t\ttest_array(temp_array_index) := temp_array_index * 2;\n\t\t\t\t\ttemp_array_index := temp_array_index + 1;\n\t\t\t\tend if;\n\t\t\tend loop;" + }, + { + "function_def": "procedure background is", + "function_body": "begin\n\n\t-- Skriver ut bakgrundsf\u00e4rgen f\u00f6r hela terminalen\n\tfor X in 1..300 loop\n\t\tfor Y in 1..50 loop\n\t\t\tPut(ASCII.ESC & bg_color);\n\t\t\tgoto_xy(X, Y);\n\t\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\tend background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure protocoll_background (X_Start, Y_Start: in Integer) is\n\n\tbegin\n\n\t-- Skriver ut ramen kring protokollet\n\tfor X in 1..31 loop\n\t\tfor Y in 1..41 loop\n\t\tPut(ASCII.ESC & protocoll_frame_bg);\n\t\tgoto_xy((X_Start - 3 + X), (Y_Start - 2 + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\t-- Skriver ut protokollets bakgrund\n\tfor X in 1..25 loop\n\t\tfor Y in 1..38 loop\n\t\tPut(ASCII.ESC & \"[48;5;15m\");\n\t\tgoto_xy(X_Start + X, Y_Start + Y);\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\tend protocoll_background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure update_protocoll(X_Start, Y_Start: in Integer; prot1, prot2: in Protocoll_Type) is\n\tx : Integer := X_Start;\n\ty : Integer := Y_Start;\n\twidthcol1 : constant Integer := 13;\n\twidthcol2 : constant Integer := 5;\n\twidthcol3 : constant Integer := 5;\n\theight: constant Integer := 39;\n\ttext_width: constant Integer := 12;\n\tpoints_width: constant Integer := 5;\n\n\tbegin\n\t-- Frame\n\tSet_Background_Colour(White);\n\tSet_Foreground_Colour(Black);\n\t-- Skriver ut horisontella linjer\n\twhile y < Y_Start + height loop\n\t\tGoto_XY(X_Start + 1, y);\n\t\tPut(Horisontal_Line, Times => widthcol1);\n\t\tGoto_XY(X_Start + 2 + widthcol1, y);\n\t\tPut(Horisontal_Line, Times => widthcol2);\n\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2, y);\n\t\tPut(Horisontal_Line, Times => widthcol3);\n\t\tGoto_XY(X_Start + 4 + widthcol1 + widthcol2 + widthcol3, y);\n\t\ty := y + 2;\n\tend loop;\n\n\tfor I in Y_Start..(Y_Start+height -1) loop\n\t\tGoto_XY(X_Start,I);\n\t\tif (I + Y_Start) mod 2 /= 0 then\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\tPut(Vertical_Line);\n\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\tPut(Vertical_Line);\n\t\telse\n\t\tif I = Y_Start then\n\t\t\tPut(Upper_Left_Corner);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Horisontal_Down);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Horisontal_Down);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Upper_Right_Corner);\n\t\telsif I = Y_Start+height - 1 then\n\t\t\tPut(Lower_Left_Corner);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Horisontal_Up);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Horisontal_Up);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Lower_Right_Corner);\n\t\telse\n\t\t\tPut(Vertical_Right);\n\t\t\tGoto_XY(X_Start + 1 + widthcol1,I);\n\t\t\tPut(Cross);\n\t\t\tGoto_XY(X_Start + 2 + widthcol1 + widthcol2,I);\n\t\t\tPut(Cross);\n\t\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2 + widthcol3,I);\n\t\t\tPut(Vertical_Left);\n\t\tend if;\n\t\tend if;\n\tend loop;\n\n\tSet_Graphical_Mode(Off);\n\n\tFor I in 1..19 loop\n\t\tGoto_XY(X_Start + 2, Y_Start - 1 + I * 2);\n\t\t--Set_Background_Colour(Blue);\n\t\tcase I is\n\t\t\twhen 1 => Set_Text_Modes(On, Off, Off); Put(\"Spelare:\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 2 => Put(\"Ettor\");\n\t\t\twhen 3 => Put(\"Tv\u00e5or\");\n\t\t\twhen 4 => Put(\"Treor\");\n\t\t\twhen 5 => Put(\"Fyror\");\n\t\t\twhen 6 => Put(\"Femmor\");\n\t\t\twhen 7 => Put(\"Sexor\"); Set_Text_Modes(On, Off, Off);\n\t\t\twhen 8 => Put(\"Summa:\");\n\t\t\twhen 9 => Put(\"BONUS\"); Set_Text_Modes(Off, Off, On);\n\t\t\twhen 10 => Put(\"Par\");\n\t\t\twhen 11 => Put(\"Tv\u00e5 par\");\n\t\t\twhen 12 => Put(\"Triss\");\n\t\t\twhen 13 => Put(\"Fyrtal\");\n\t\t\twhen 14 => Put(\"K\u00e5k\");\n\t\t\twhen 15 => Put(\"Liten stege\");\n\t\t\twhen 16 => Put(\"Stor stege\");\n\t\t\twhen 17 => Put(\"Chans\");\n\t\t\twhen 18 => Put(\"Yatzy\"); Set_Text_Modes(On, Off, Off);\n\t\t\twhen 19 => Put(\"Summa:\");\n\n\t\t\twhen others => null;\n\t\tend case;\n\tend loop;\n\n\n\tFor I in 1..19 loop\n\t\tGoto_XY(X_Start + 2 + widthcol1, Y_Start - 1 + I * 2);\n\n\t\tcase I is\n\t\twhen 1 => Set_Text_Modes(Off, Off, Off); Put(\"P1\"); Set_Text_Modes(Off, Off, On);\n\t\twhen 2..7 => if Prot1(I - 1) /= -1 then Put(Prot1(I - 1), 1 + widthcol2 / 2); end if;\n\t\twhen 8 => Put(\"Sum:\");\n\t\twhen 9 => Put(\"BON\");\n\t\twhen 10..18 => if Prot1(I - 3) /= -1 then Put(Prot1(I - 3), 1 + widthcol2 / 2); end if;\n\t\twhen 19 => Put(\"Sum:\");\n\n\t\twhen others => null;\n\t\tend case;\n\tend loop;\n\n\tFor I in 1..19 loop\n\t\tGoto_XY(X_Start + 3 + widthcol1 + widthcol2, Y_Start - 1 + I * 2);\n\t\tcase I is\n\t\twhen 1 => Set_Text_Modes(Off, Off, Off); Put(\"P1\"); Set_Text_Modes(Off, Off, On);\n\t\twhen 2..7 => if Prot2(I - 1) /= -1 then Put(Prot2(I - 1), 1 + widthcol2 / 2); end if;\n\t\twhen 8 => Put(\"Sum:\");\n\t\twhen 9 => Put(\"BON\");\n\t\twhen 10..18 => if Prot2(I - 3) /= -1 then Put(Prot2(I - 3), 1 + widthcol2 / 2); end if;\n\t\twhen 19 => Put(\"Sum:\");\n\n\t\twhen others => null;\n\t\tend case;\n\tend loop;\n\n\tend update_protocoll;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure dice (A, X_Start, Y_Start: in Integer) is\n\n\tbegin\n\tGoto_XY(X_Start, Y_Start);\n\tfor I in 1..5 loop\n\t\t--Set_Background_Colour(White);\n\t\tif I = 1 then\n\t\tPut(Upper_Left_Corner);\n\t\tPut(Horisontal_Very_High_Line, Times => 9);\n\t\tPut(Upper_Right_Corner);\n\t\tGoto_XY(X_Start, Y_Start + I);\n\t\telsif I = 5 then\n\t\tPut(Lower_Left_Corner);\n\t\tPut(Horisontal_Very_Low_Line, Times => 9);\n\t\tPut(Lower_Right_Corner);\n\t\telse\n\t\tcase A is\n\t\t\twhen 1 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 2 or I = 4 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 2 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 3 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 4 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 5 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tif I = 2 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 3 then\n\t\t\tPut(\" \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\telsif I = 4 then\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\t\t\tend if;\n\n\t\t\twhen 6 =>\n\t\t\tPut(Vertical_Line);\n\t\t\tPut(\" \u2022 \u2022 \");\n\t\t\tPut(Vertical_Line);\n\t\t\tGoto_XY(X_Start, Y_Start + I);\n\n\t\t\twhen others => null;\n\t\tend case;\n\t\tend if;\n\tend loop;\n\n\n\tend dice;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\nprocedure dice_placement (D1, D2, D3, D4, D5 : in Integer) is\n\nbegin\n\n\t-- Only update dice if input is bigger than 0\n\tif D1 > 0 then Dice(D1, 8 + 15 * 1, 38); end if;\n\tif D2 > 0 then Dice(D2, 8 + 15 * 2, 38); end if;\n\tif D3 > 0 then Dice(D3, 8 + 15 * 3, 38); end if;\n\tif D4 > 0 then Dice(D4, 8 + 15 * 4, 38); end if;\n\tif D5 > 0 then Dice(D5, 8 + 15 * 5, 38); end if;\n\nend dice_placement;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tProcedure logo_background (X_Start, Y_Start : in Integer) is\n\n\tbegin\n\tfor X in 1..76 loop\n\t\tfor Y in 1..9 loop\n\t\tPut(ASCII.ESC & logo_frame_bg);\n\t\tgoto_xy((X_Start - 3 + X), (Y_Start - 2 + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\tend logo_background;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tProcedure logo (X_Start, Y_Start : in Integer) is\n\n\tbegin\n\tSet_Background_Colour(White);\n\tSet_Foreground_Colour(Blue);\n\tSet_Bold_Mode(on);\n\n\tgoto_xy(X_Start, Y_Start);\n\tPut(\" ____ ____ __ _________ ________ ____ ____ \");\n\tgoto_xy(X_Start, Y_Start + 1);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\"_ _\");\n\tPut(Vertical_Line, Times => 2);\n\tPut(\"_ _\");\n\tPut(Vertical_Line);\n\tPut(\" / \\ \");\n\tPut(Vertical_Line);\n\tPut(\" _ _ \");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\" __ __\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ _\");\n\tPut(Vertical_Line, Times => 2);\n\tPut(\"_ _\");\n\tPut(Vertical_Line);\n\tgoto_xy(X_Start, Y_Start + 2);\n\tPut(\" \\ \\ / / / /\\ \\ \");\n\tPut(Vertical_Line);\n\tPut(\"_/ \");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\" \\_\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_/ / / \\ \\ / / \");\n\tgoto_xy(X_Start, Y_Start + 3);\n\tPut(\" \\ \\/ / / ____ \\ \");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\" / / _ \\ \\/ / \");\n\tgoto_xy(X_Start, Y_Start + 4);\n\tPut(\" _\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ _/ / \\ \\_ _\");\n\tPut(Vertical_Line);\n\tPut(' ');\n\tPut(Vertical_Line);\n\tPut(\"_ / /__/ \");\n\tPut(Vertical_Line);\n\tPut(\" _\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_ \");\n\tgoto_xy(X_Start, Y_Start + 5);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_____\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"_______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tPut(Vertical_Line);\n\tPut(\"______\");\n\tPut(Vertical_Line);\n\tPut(\" \");\n\tgoto_xy(X_Start, Y_Start + 6);\n\tPut(\" \");\n\n\t-- ____ ____ __ _________ ________ ____ ____\n\t-- |_ _||_ _| / \\ | _ _ | | __ __| |_ _||_ _|\n\t-- \\ \\ / / / /\\ \\ |_/ | | \\_| |_/ / / \\ \\ / /\n\t-- \\ \\/ / / ____ \\ | | / / _ \\ \\/ /\n\t-- _| |_ _/ / \\ \\_ _| |_ / /__/ | _| |_\n\t-- |______| |____| |____| |_____| |_______| |______|\n\n\tend logo;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\n\tprocedure message (X_Start, Y_Start : in Integer; S : in String) is\n\n\tbegin\n\n\tSet_Graphical_Mode(Off);\n\n\tfor Y in 1..11 loop\n\t\tfor X in 1..55 loop\n\n\t\t\t-- om inte f\u00f6rsta eller inte sista raden\n\t\t\tif Y = 1 OR Y = 11 then\n\t\t\t\t\tif X mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\tend if;\n\t\t\telse\n\t\t\t\tif X = 1 OR X = 55 then\n\t\t\t\t\tif Y mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\tend if;\n\t\t\t\telse\n\t\t\t\t\tif Y mod 2 = 0 then\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color2);\n\t\t\t\t\telse\n\t\t\t\t\t\tPut(ASCII.ESC & message_frame_color1);\n\t\t\t\t\tend if;\n\t\t\t\tend if;\n\t\t\tend if;\n\n\t\tgoto_xy((X_Start - 2 + X), (Y_Start - 1 + Y));\n\t\tPut(' ');\n\n\t\tend loop;\n\tend loop;\n\n\n\n\t-- White inner frame\n\tfor X in 1..51 loop\n\t\tfor Y in 1..9 loop\n\t\tPut(ASCII.ESC & \"[48;5;15m\");\n\t\tgoto_xy((X_Start + X), (Y_Start + Y));\n\t\tPut(' ');\n\t\tend loop;\n\tend loop;\n\n\tgoto_xy(X_Start + 3, Y_Start + 5);\n Set_Foreground_Colour(Black);\n\tPut(S);\n\tend message;\n\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------\n\t---------------------------------------------------------------------------------------------" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure Test_TJa is\n\n\tOwn_Protocoll, Other_Protocoll: Protocoll_Type;\n\tSelected_Place : Integer;\n\n\tbegin\n\tReset_Colours; -- Standard colours is supposed to be black on white ...\n\tClear_Window;\n\tSet_Graphical_Mode(On);\n\tbackground;\n\tprotocoll_background(125, 4);\n\tlogo_background(24, 4);\n\tmessage(38, 18, \"Hejsan\");\n\n\t-- Draw a rectangle on screen ...\n\t--Set_Graphical_Mode(On);\n\tfor I in 1..15 loop\n\t\tcase I is\n\t\t\twhen 1 => Own_Protocoll(I) := 1;\n\t\t\twhen 2 => Own_Protocoll(I) := 2;\n\t\t\twhen 3 => Own_Protocoll(I) := 3;\n\t\t\twhen 4 => Own_Protocoll(I) := 4;\n\t\t\twhen 5 => Own_Protocoll(I) := 5;\n\t\t\twhen 6 => Own_Protocoll(I) := -1;\n\t\t\twhen 7 => Own_Protocoll(I) := -1;\n\t\t\twhen 8 => Own_Protocoll(I) := -1;\n\t\t\twhen 9 => Own_Protocoll(I) := -1;\n\t\t\twhen 10 => Own_Protocoll(I) := -1;\n\t\t\twhen 11 => Own_Protocoll(I) := -1;\n\t\t\twhen 12 => Own_Protocoll(I) := 15;\n\t\t\twhen 13 => Own_Protocoll(I) := -1;\n\t\t\twhen 14 => Own_Protocoll(I) := 15;\n\t\t\twhen 15 => Own_Protocoll(I) := -1;\n\t\t\twhen others => null;\n\t\t\t-- Own_Protocoll(I) := I;\n\t\tend case;\n\tend loop;\n\tfor I in 1..15 loop\n\t\tOther_Protocoll(I) := I;\n\tend loop;\n\n\n\n\tupdate_protocoll(125, 4, Own_Protocoll, Other_Protocoll);\n\n\tfor x in 1..5 loop\n\t\tdice(x,8 + 15 * x, 38);\n\t\t--dice_placement;\n\tend loop;\n\n\n\n\tlogo(24, 4);\n\n\tSet_Graphical_Mode(Off);\n\n\tplace(Own_Protocoll, Selected_Place);\n\n\n\tReset_Colours;\n\tReset_Text_Modes; -- Resets boold mode ...\n\n\n\n\tend Test_TJa;\n\n\tbegin\n\t\tTest_TJa;\n\t\tSkip_Line;" + }, + { + "function_def": "procedure Main is", + "function_body": "package Lines is new MyString(Max_MyString_Length => 2048);\n S : Lines.MyString;\n PM_Information : PasswordManager.Information;\n GETDB : constant String := \"get\";\n REMDB : constant String := \"rem\";\n PUTDB : constant String := \"put\";\n UNLOCK : constant String := \"unlock\";\n LOCK : constant String := \"lock\";\n TokensList : MyStringTokeniser.TokenArray(1..5):= (others => (Start => 1, Length => 0));\n NumTokens : Natural;\n\nbegin\n -- Program must initiate with 1 Pin input\n if (MyCommandLine.Argument_Count = 1) then\n declare\n Temp_Pin : String := MyCommandLine.Argument(1);\n begin\n -- Pin must meet specified Pin requirements prior to Password Manager\n -- initiation\n if (MyCommandLine.Argument(1)'Length = 4 and\n (for all I in Temp_Pin'Range => Temp_Pin(I)\n >= '0' and Temp_Pin(I) <= '9')) then\n PasswordManager.Init(MyCommandLine.Argument(1), PM_Information);\n else\n Put_Line(\"Invalid input, program will exit!\");\n return;\n end if;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E123 := E123 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"passworddatabase__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"ada__text_io__finalize_spec\");\n begin\n F2;" + }, + { + "function_def": "procedure F3;", + "function_body": "pragma Import (Ada, F3, \"system__storage_pools__subpools__finalize_spec\");\n begin\n F3;" + }, + { + "function_def": "procedure F4;", + "function_body": "pragma Import (Ada, F4, \"system__finalization_masters__finalize_spec\");\n begin\n F4;" + }, + { + "function_def": "procedure F5;", + "function_body": "pragma Import (Ada, F5, \"system__file_io__finalize_body\");\n begin\n E085 := E085 - 1;\n F5;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E012 := E012 + 1;\n System.Exceptions'Elab_Spec;\n E022 := E022 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E053 := E053 + 1;\n E014 := E014 + 1;\n Ada.Containers'Elab_Spec;\n E124 := E124 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E009 := E009 + 1;\n System.Os_Lib'Elab_Body;\n E090 := E090 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E070 := E070 + 1;\n Ada.Streams'Elab_Spec;\n E067 := E067 + 1;\n System.File_Control_Block'Elab_Spec;\n E093 := E093 + 1;\n System.Finalization_Root'Elab_Spec;\n E088 := E088 + 1;\n Ada.Finalization'Elab_Spec;\n E086 := E086 + 1;\n System.File_Io'Elab_Body;\n E085 := E085 + 1;\n System.Storage_Pools'Elab_Spec;\n E139 := E139 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E133 := E133 + 1;\n System.Storage_Pools.Subpools'Elab_Spec;\n E131 := E131 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E065 := E065 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E057 := E057 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E061 := E061 + 1;\n E115 := E115 + 1;\n E119 := E119 + 1;\n E121 := E121 + 1;\n Passworddatabase'Elab_Spec;\n E123 := E123 + 1;\n E147 := E147 + 1;\n E145 := E145 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure Simple_Benchmarking is", + "function_body": "CPU_MHz : Float := 2650.0;\n\n Verbose : constant Boolean := True;\n\n Results : Wavefile_Benchmark_Infos (1 .. 5);\n\n task type Wavefile_Benchmark\n with CPU => 1\n is\n entry Finish (Res : out Wavefile_Benchmark_Infos);\n end Wavefile_Benchmark;\n\n task body Wavefile_Benchmark is\n Local_Results : Wavefile_Benchmark_Infos (Results'Range);\n begin\n if Verbose then\n Display_Current_CPU : declare\n use System.Multiprocessors;\n use System.Multiprocessors.Dispatching_Domains;\n begin\n Put_Line (\"Current CPU : \" & CPU_Range'Image (Get_CPU));\n end Display_Current_CPU;\n end if;\n\n Benchm_CPU_Time (CPU_MHz, Local_Results);\n\n accept Finish (Res : out Wavefile_Benchmark_Infos) do\n Res := Local_Results;\n end Finish;\n end Wavefile_Benchmark;\n\n Benchmark_Using_Tasking : constant Boolean := False;\n\nbegin\n if Argument_Count >= 1 then\n CPU_MHz := Float'Value (Argument (1));\n end if;\n\n if Verbose then\n Put_Line (\"Using CPU @ \" & Float'Image (CPU_MHz) & \" MHz\");\n end if;\n\n if Benchmark_Using_Tasking then\n declare\n Wav_Benchmark : Wavefile_Benchmark;\n begin\n Wav_Benchmark.Finish (Results);" + }, + { + "function_def": "procedure Open_Wavefile;", + "function_body": "procedure Close_Wavefile;\n\n function kHz_Per_Sample\n (Elapsed_Time : Time_Span;\n CPU_MHz : Float;\n Number_Ch : Positive;\n Number_Samples : Long_Long_Integer) return Float;\n\n procedure Display_Info (Elapsed_Time : Time_Span;\n CPU_MHz : Float;\n Number_Ch : Positive;\n Number_Samples : Long_Long_Integer;\n Sample_Rate : Positive);\n\n -------------------\n -- Open_Wavefile --\n -------------------\n\n procedure Open_Wavefile is\n Wav_In_File_Name : constant String := \"2ch_long_noise.wav\";\n Wav_Out_File_Name : constant String := \"dummy.wav\";\n\n begin\n WF_In.Open (In_File, Wav_In_File_Name);\n\n WF_Out.Set_Format_Of_Wavefile\n (WF_In.Format_Of_Wavefile);\n\n WF_Out.Create (Out_File, Wav_Out_File_Name);\n end Open_Wavefile;\n\n --------------------\n -- Close_Wavefile --\n --------------------\n\n procedure Close_Wavefile is\n begin\n WF_In.Close;\n WF_Out.Close;\n end Close_Wavefile;\n\n --------------------\n -- kHz_Per_Sample --\n --------------------\n\n function kHz_Per_Sample\n (Elapsed_Time : Time_Span;\n CPU_MHz : Float;\n Number_Ch : Positive;\n Number_Samples : Long_Long_Integer) return Float\n is\n Factor : constant Long_Long_Float := (Long_Long_Float (Number_Samples)\n * Long_Long_Float (Number_Ch));\n begin\n return Time_Span_Conversions.To_kHz (Elapsed_Time, CPU_MHz, Factor);\n end kHz_Per_Sample;\n\n ------------------\n -- Display_Info --\n ------------------\n\n procedure Display_Info (Elapsed_Time : Time_Span;\n CPU_MHz : Float;\n Number_Ch : Positive;\n Number_Samples : Long_Long_Integer;\n Sample_Rate : Positive)\n is\n use Time_Span_Conversions;\n\n package F_IO is new Ada.Text_IO.Float_IO (Float);\n\n -- Duration_In_Seconds : Long_Long_Float :=\n -- Long_Long_Float (Number_Samples)\n -- / Long_Long_Float (Sample_Rate);\n\n Factor : constant Long_Long_Float := (Long_Long_Float (Number_Samples)\n * Long_Long_Float (Number_Ch));\n begin\n Put (\"CPU time: \");\n F_IO.Put (Item => To_Miliseconds (Elapsed_Time),\n Fore => 5, Aft => 4, Exp => 0);\n Put (\" miliseconds\");\n Put (\" for \" & Long_Long_Integer'Image (Number_Samples) & \" samples\");\n Put (\" on \" &\n Integer'Image (Number_Ch) & \" channels\");\n Put (\" at \" &\n Integer'Image (Sample_Rate) & \" Hz\");\n New_Line;\n\n Put (\"Overall Perf.: \");\n F_IO.Put (Item => (To_MHz (Elapsed_Time, CPU_MHz, Factor)\n * Float (Sample_Rate)),\n Fore => 5, Aft => 4, Exp => 0);\n Put (\" MHz (per channel @ \" & Positive'Image (Sample_Rate) & \" kHz)\");\n New_Line;\n\n Put (\"Overall Perf.: \");\n F_IO.Put (Item => To_kHz (Elapsed_Time, CPU_MHz, Factor),\n Fore => 5, Aft => 4, Exp => 0);\n Put (\" kHz (per channel and per sample)\");\n New_Line;\n end Display_Info;\n\n ---------------------\n -- Benchm_CPU_Time --\n ---------------------\n\n function Benchm_CPU_Time (CPU_MHz : Float) return Wavefile_Benchmark_kHz\n is\n Res : Wavefile_Benchmark_kHz;\n\n Start_Time, Stop_Time : CPU_Time;\n Elapsed_Time : Time_Span;\n\n Sample_Rate : Positive;\n\n package Wav_IO is new Audio.Wavefiles.Generic_Direct_Fixed_Wav_IO\n (Wav_Sample => Wav_Fixed_16,\n Channel_Range => Positive,\n Wav_MC_Sample => Wav_Buffer_Fixed_16);\n use Wav_IO;\n\n Cnt, Total_Cnt : Long_Long_Integer := 0;\n\n begin\n Write_Random_Noise_Wavefile;\n\n Open_Wavefile;\n\n Sample_Rate := To_Positive\n (WF_In.Format_Of_Wavefile.Samples_Per_Sec);\n\n pragma Assert\n (WF_In.Format_Of_Wavefile.Bits_Per_Sample = Bit_Depth_16\n and then not WF_In.Format_Of_Wavefile.Is_Float_Format);\n\n if Display_Debug_Info then\n Put_Line (\"========================================================\");\n Put_Line (\"= Read\");\n Put_Line (\"========================================================\");\n end if;\n\n Start_Time := Clock;\n\n loop\n Read_Wav_MC_Samples : declare\n Dummy_Wav_Buf : constant Wav_Buffer_Fixed_16 := Get (WF_In);\n begin\n Cnt := Cnt + 1;\n exit when End_Of_File (WF_In);\n end Read_Wav_MC_Samples;\n end loop;\n\n Stop_Time := Clock;\n Elapsed_Time := Stop_Time - Start_Time;\n\n -- Res (Wavefile_Read_Benchmark) := Elapsed_Time;\n Res (Wavefile_Read_Benchmark) :=\n kHz_Per_Sample (Elapsed_Time,\n CPU_MHz,\n Number_Of_Channels (WF_In),\n Cnt);\n\n if Display_Debug_Info then\n Display_Info (Elapsed_Time,\n CPU_MHz,\n Number_Of_Channels (WF_In),\n Cnt,\n Sample_Rate);\n\n Put_Line (\"========================================================\");\n Put_Line (\"= Write\");\n Put_Line (\"========================================================\");\n end if;\n\n Total_Cnt := Cnt;\n Cnt := 0;\n\n declare\n Wav_Buf : constant Wav_Buffer_Fixed_16\n (1 .. Number_Of_Channels (WF_In)) := (others => 0.5);\n begin\n Start_Time := Clock;\n\n loop\n Write_Wav_MC_Samples : declare\n begin\n Cnt := Cnt + 1;\n Put (WF_Out, Wav_Buf);\n exit when Cnt = Total_Cnt;\n\n end Write_Wav_MC_Samples;\n end loop;\n\n Stop_Time := Clock;\n Elapsed_Time := Stop_Time - Start_Time;\n\n -- Res (Wavefile_Write_Benchmark) := Elapsed_Time;\n Res (Wavefile_Write_Benchmark) :=\n kHz_Per_Sample (Elapsed_Time,\n CPU_MHz,\n Number_Of_Channels (WF_In),\n Cnt);" + }, + { + "function_def": "procedure Display_PCM_Vals", + "function_body": "(PCM_Vals : PCM_Buffer;\n Header : String);\n\n procedure Write_PCM_Vals\n (WF : in out Wavefile;\n PCM_Vals : PCM_Buffer);\n\n function PCM_Data_Is_OK\n (PCM_Ref, PCM_DUT : PCM_Buffer) return Boolean;\n\n function PCM_Data_Is_OK\n (Test_Bits : Wav_Bit_Depth;\n PCM_DUT : PCM_Buffer) return Boolean;\n\n function Wav_IO_OK_For_Audio_Resolution\n (Test_Bits : Wav_Bit_Depth;\n Wav_Test_File_Name : String) return Boolean;\n\n procedure Display_Info\n (WF : Wavefile;\n Header : String);\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth);\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer);\n\n function Image (B : Wav_Bit_Depth) return String renames\n Audio.RIFF.Wav.Formats.Report.Image;\n\n ----------------------\n -- Display_PCM_Vals --\n ----------------------\n\n procedure Display_PCM_Vals (PCM_Vals : PCM_Buffer;\n Header : String)\n is\n#if NUM_TYPE'Defined and then (NUM_TYPE = \"FLOAT\") then\n Display_Integer_Value : constant Boolean := False;\n#else\n Display_Integer_Value : constant Boolean := True;\n#end if;\n begin\n Put_Line (Header);\n for Sample_Count in PCM_Vals'Range loop\n declare\n#if NUM_TYPE'Defined and then (NUM_TYPE = \"FLOAT\") then\n PCM_Integer : array (1 .. 2) of Integer_64\n with\n Address => PCM_Vals (Sample_Count)'Address,\n Size => 128;\n#else\n PCM_Integer : Integer_64\n with\n Address => PCM_Vals (Sample_Count)'Address,\n Size => 64;\n#end if;\n begin\n\n Put (\" Val: \");\n PCM_Sample_Text_IO.Put (Item => PCM_Vals (Sample_Count),\n Fore => 5,\n Aft => 60,\n Exp => 5);\n if Display_Integer_Value then\n Put (\" - \");\n#if NUM_TYPE'Defined and then (NUM_TYPE = \"FLOAT\") then\n for I in PCM_Integer'Range loop\n Fixed_64_PCM_As_Integer_Text_IO.Put\n (PCM_Integer (I), Base => 2, Width => 68);\n end loop;\n#else\n Fixed_64_PCM_As_Integer_Text_IO.Put\n (PCM_Integer, Base => 2, Width => 68);\n#end if;\n end if;\n New_Line;" + }, + { + "function_def": "procedure Display_Info", + "function_body": "(WF : Wavefile;\n Header : String)\n is\n Separator : constant String\n := \"===========================================================\";\n begin\n Put_Line (Separator);\n Put_Line (Header);\n Display_Info (WF);\n Put_Line (Separator);\n end Display_Info;\n\n --------------------\n -- Write_Wavefile --\n --------------------\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth)\n is\n WF_Out : Wavefile;\n Wave_Format : Wave_Format_Extensible;\n begin\n Wave_Format := Init (Bit_Depth => Test_Bits,\n Sample_Rate => Sample_Rate_44100,\n Number_Of_Channels => 2,\n#if NUM_TYPE'Defined and then (NUM_TYPE = \"FLOAT\") then\n Use_Float => True);\n#else\n Use_Float => False);\n#end if;\n\n WF_Out.Set_Format_Of_Wavefile (Wave_Format);\n WF_Out.Create (Out_File, Wav_File_Name);\n\n Write_PCM_Vals (WF_Out, PCM_Ref);\n\n WF_Out.Close;\n end Write_Wavefile;\n\n -------------------\n -- Read_Wavefile --\n -------------------\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer)\n is\n WF_In : Wavefile;\n -- Wave_Format : Wave_Format_Extensible;\n EOF : Boolean;\n Samples : Integer := 0;\n begin\n WF_In.Open (In_File, Wav_File_Name);\n -- Wave_Format := WF_In.Format_Of_Wavefile;\n\n if Verbose then\n Display_Info (WF_In, \"Input File:\");\n end if;\n\n Samples := 0;\n PCM_DUT := (others => 0.0);\n loop\n Samples := Samples + 1;\n -- Put (\"[\" & Integer'Image (Samples) & \"]\");\n\n declare\n PCM_Buf : constant PCM_Buffer := Get (WF_In);\n begin\n PCM_DUT (Samples) := PCM_Buf (PCM_Buf'First);" + }, + { + "function_def": "procedure Display_PCM_Vals", + "function_body": "(PCM_Vals : PCM_Buffer;\n Header : String);\n\n procedure Write_PCM_Vals\n (WF : in out Wavefile;\n PCM_Vals : PCM_Buffer);\n\n function PCM_Data_Is_OK\n (PCM_Ref, PCM_DUT : PCM_Buffer) return Boolean;\n\n function PCM_Data_Is_OK\n (Test_Bits : Wav_Bit_Depth;\n PCM_DUT : PCM_Buffer) return Boolean;\n\n function Wav_IO_OK_For_Audio_Resolution\n (Test_Bits : Wav_Bit_Depth;\n Wav_Test_File_Name : String) return Boolean;\n\n procedure Display_Info\n (WF : Wavefile;\n Header : String);\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth);\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer);\n\n function Image (B : Wav_Bit_Depth) return String renames\n Audio.RIFF.Wav.Formats.Report.Image;\n\n ----------------------\n -- Display_PCM_Vals --\n ----------------------\n\n procedure Display_PCM_Vals (PCM_Vals : PCM_Buffer;\n Header : String)\n is\n Display_Integer_Value : constant Boolean := False;\n begin\n Put_Line (Header);\n for Sample_Count in PCM_Vals'Range loop\n declare\n PCM_Integer : array (1 .. 2) of Integer_64\n with\n Address => PCM_Vals (Sample_Count)'Address,\n Size => 128;\n begin\n\n Put (\" Val: \");\n PCM_Sample_Text_IO.Put (Item => PCM_Vals (Sample_Count),\n Fore => 5,\n Aft => 60,\n Exp => 5);\n if Display_Integer_Value then\n Put (\" - \");\n for I in PCM_Integer'Range loop\n Fixed_64_PCM_As_Integer_Text_IO.Put\n (PCM_Integer (I), Base => 2, Width => 68);\n end loop;\n end if;\n New_Line;" + }, + { + "function_def": "procedure Display_Info", + "function_body": "(WF : Wavefile;\n Header : String)\n is\n Separator : constant String\n := \"===========================================================\";\n begin\n Put_Line (Separator);\n Put_Line (Header);\n Display_Info (WF);\n Put_Line (Separator);\n end Display_Info;\n\n --------------------\n -- Write_Wavefile --\n --------------------\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth)\n is\n WF_Out : Wavefile;\n Wave_Format : Wave_Format_Extensible;\n begin\n Wave_Format := Init (Bit_Depth => Test_Bits,\n Sample_Rate => Sample_Rate_44100,\n Number_Of_Channels => 2,\n Use_Float => True);\n\n WF_Out.Set_Format_Of_Wavefile (Wave_Format);\n WF_Out.Create (Out_File, Wav_File_Name);\n\n Write_PCM_Vals (WF_Out, PCM_Ref);\n\n WF_Out.Close;\n end Write_Wavefile;\n\n -------------------\n -- Read_Wavefile --\n -------------------\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer)\n is\n WF_In : Wavefile;\n -- Wave_Format : Wave_Format_Extensible;\n EOF : Boolean;\n Samples : Integer := 0;\n begin\n WF_In.Open (In_File, Wav_File_Name);\n -- Wave_Format := WF_In.Format_Of_Wavefile;\n\n if Verbose then\n Display_Info (WF_In, \"Input File:\");\n end if;\n\n Samples := 0;\n PCM_DUT := (others => 0.0);\n loop\n Samples := Samples + 1;\n -- Put (\"[\" & Integer'Image (Samples) & \"]\");\n\n declare\n PCM_Buf : constant PCM_Buffer := Get (WF_In);\n begin\n PCM_DUT (Samples) := PCM_Buf (PCM_Buf'First);" + }, + { + "function_def": "procedure Display_PCM_Vals", + "function_body": "(PCM_Vals : PCM_Buffer;\n Header : String);\n\n procedure Write_PCM_Vals\n (WF : in out Wavefile;\n PCM_Vals : PCM_Buffer);\n\n function PCM_Data_Is_OK\n (PCM_Ref, PCM_DUT : PCM_Buffer) return Boolean;\n\n function PCM_Data_Is_OK\n (Test_Bits : Wav_Bit_Depth;\n PCM_DUT : PCM_Buffer) return Boolean;\n\n function Wav_IO_OK_For_Audio_Resolution\n (Test_Bits : Wav_Bit_Depth;\n Wav_Test_File_Name : String) return Boolean;\n\n procedure Display_Info\n (WF : Wavefile;\n Header : String);\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth);\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer);\n\n function Image (B : Wav_Bit_Depth) return String renames\n Audio.RIFF.Wav.Formats.Report.Image;\n\n ----------------------\n -- Display_PCM_Vals --\n ----------------------\n\n procedure Display_PCM_Vals (PCM_Vals : PCM_Buffer;\n Header : String)\n is\n Display_Integer_Value : constant Boolean := True;\n begin\n Put_Line (Header);\n for Sample_Count in PCM_Vals'Range loop\n declare\n PCM_Integer : Integer_64\n with\n Address => PCM_Vals (Sample_Count)'Address,\n Size => 64;\n begin\n\n Put (\" Val: \");\n PCM_Sample_Text_IO.Put (Item => PCM_Vals (Sample_Count),\n Fore => 5,\n Aft => 60,\n Exp => 5);\n if Display_Integer_Value then\n Put (\" - \");\n Fixed_64_PCM_As_Integer_Text_IO.Put\n (PCM_Integer, Base => 2, Width => 68);\n end if;\n New_Line;" + }, + { + "function_def": "procedure Display_Info", + "function_body": "(WF : Wavefile;\n Header : String)\n is\n Separator : constant String\n := \"===========================================================\";\n begin\n Put_Line (Separator);\n Put_Line (Header);\n Display_Info (WF);\n Put_Line (Separator);\n end Display_Info;\n\n --------------------\n -- Write_Wavefile --\n --------------------\n\n procedure Write_Wavefile\n (Wav_File_Name : String;\n Test_Bits : Wav_Bit_Depth)\n is\n WF_Out : Wavefile;\n Wave_Format : Wave_Format_Extensible;\n begin\n Wave_Format := Init (Bit_Depth => Test_Bits,\n Sample_Rate => Sample_Rate_44100,\n Number_Of_Channels => 2,\n Use_Float => False);\n\n WF_Out.Set_Format_Of_Wavefile (Wave_Format);\n WF_Out.Create (Out_File, Wav_File_Name);\n\n Write_PCM_Vals (WF_Out, PCM_Ref);\n\n WF_Out.Close;\n end Write_Wavefile;\n\n -------------------\n -- Read_Wavefile --\n -------------------\n\n procedure Read_Wavefile\n (Wav_File_Name : String;\n PCM_DUT : out PCM_Buffer)\n is\n WF_In : Wavefile;\n -- Wave_Format : Wave_Format_Extensible;\n EOF : Boolean;\n Samples : Integer := 0;\n begin\n WF_In.Open (In_File, Wav_File_Name);\n -- Wave_Format := WF_In.Format_Of_Wavefile;\n\n if Verbose then\n Display_Info (WF_In, \"Input File:\");\n end if;\n\n Samples := 0;\n PCM_DUT := (others => 0.0);\n loop\n Samples := Samples + 1;\n -- Put (\"[\" & Integer'Image (Samples) & \"]\");\n\n declare\n PCM_Buf : constant PCM_Buffer := Get (WF_In);\n begin\n PCM_DUT (Samples) := PCM_Buf (PCM_Buf'First);" + }, + { + "function_def": "procedure Gif2ada is", + "function_body": "use Interfaces;\n\n Image : GID.Image_descriptor;\nbegin\n if Ada.Command_Line.Argument_Count /= 2 then\n Ada.Text_IO.Put_Line (Ada.Text_IO.Standard_Error,\n \"Usage: gif2ada \");\n Ada.Text_IO.Put_Line (Ada.Text_IO.Standard_Error,\n \"Generate an Ada package that contains an GIF image\");\n Ada.Command_Line.Set_Exit_Status (2);\n return;\n end if;\n declare\n\n subtype Primary_color_range is Unsigned_8;\n\n procedure Get_Color (Red, Green, Blue : Interfaces.Unsigned_8);\n procedure Set_X_Y (X, Y : in Natural) is null;\n procedure Put_Pixel (Red, Green, Blue : Primary_color_range;\n Alpha : Primary_color_range) is null;\n procedure Feedback (Percents : Natural) is null;\n procedure Raw_Byte (B : in Interfaces.Unsigned_8);\n\n Name : constant String := Ada.Command_Line.Argument (1);\n Path : constant String := Ada.Command_Line.Argument (2);\n File : Ada.Streams.Stream_IO.File_Type;\n Color_Count : Natural := 0;\n Need_Sep : Boolean := False;\n Need_Line : Boolean := False;\n Count : Natural := 0;\n\n procedure Raw_Byte (B : in Interfaces.Unsigned_8) is\n begin\n if Need_Sep then\n Ada.Text_IO.Put (\",\");\n end if;\n if Need_Line then\n Need_Line := False;\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Set_Col (8);\n end if;\n Need_Sep := True;\n Ada.Text_IO.Put (Natural'Image (Natural (B)));\n Count := Count + 1;\n Need_Line := (Count mod 8) = 0;\n end Raw_Byte;\n\n procedure Load_Image is\n new GID.Load_image_contents (Primary_color_range, Set_X_Y,\n Put_Pixel, Raw_Byte, Feedback, GID.fast);\n\n procedure Get_Color (Red, Green, Blue : Interfaces.Unsigned_8) is\n Red_Image : constant String := Unsigned_8'Image (Red);\n begin\n if Color_Count > 0 then\n Ada.Text_IO.Put (\",\");\n end if;\n if Color_Count mod 4 = 3 then\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Set_Col (9);\n else\n Ada.Text_IO.Put (\" \");\n end if;\n Color_Count := Color_Count + 1;\n Ada.Text_IO.Put (\"(\");\n Ada.Text_IO.Put (Red_Image (Red_Image'First + 1 .. Red_Image'Last));\n Ada.Text_IO.Put (\",\");\n Ada.Text_IO.Put (Unsigned_8'Image (Green));\n Ada.Text_IO.Put (\",\");\n Ada.Text_IO.Put (Unsigned_8'Image (Blue));\n Ada.Text_IO.Put (\")\");\n end Get_Color;\n\n procedure Write_Palette is\n new GID.Get_palette (Get_Color);\n\n Next_Frame : Ada.Calendar.Day_Duration := 0.0;\n begin\n Ada.Streams.Stream_IO.Open (File, Ada.Streams.Stream_IO.In_File, Path);\n GID.Load_image_header (Image, Ada.Streams.Stream_IO.Stream (File).all);\n\n Ada.Text_IO.Put_Line (\"with UI.Images;\");\n Ada.Text_IO.Put_Line (\"package \" & Name & \" is\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put (\" \");\n Ada.Text_IO.Put_Line (\"Descriptor : constant UI.Images.Image_Descriptor;\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\"private\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\" Palette : aliased constant UI.Images.Color_Array := (\");\n Ada.Text_IO.Set_Col (8);\n Write_Palette (Image);\n Ada.Text_IO.Put_Line (\" );\");\n Ada.Text_IO.Put_Line (\" -- \" & Natural'Image (Color_Count) & \" colors\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\" Data : aliased constant UI.Images.Bitmap_Array := (\");\n Ada.Text_IO.Put (\" \");\n\n Load_Image (Image, Next_Frame);\n Ada.Streams.Stream_IO.Close (File);\n Ada.Text_IO.Put_Line (\" );\");\n Ada.Text_IO.Put_Line (\" -- \" & Natural'Image (Count) & \" bytes\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\" Descriptor : constant UI.Images.Image_Descriptor :=\");\n Ada.Text_IO.Put (\" (Width =>\");\n Ada.Text_IO.Put (Positive'Image (GID.Pixel_width (Image)));\n Ada.Text_IO.Put_Line (\",\");\n Ada.Text_IO.Put (\" Height =>\");\n Ada.Text_IO.Put (Positive'Image (GID.Pixel_height (Image)));\n Ada.Text_IO.Put_Line (\",\");\n Ada.Text_IO.Put_Line (\" Palette => Palette'Access,\");\n Ada.Text_IO.Put_Line (\" Bitmap => Data'Access);\");\n Ada.Text_IO.New_Line;\n Ada.Text_IO.Put_Line (\"end \" & Name & \";\");" + }, + { + "function_def": "procedure Big_endian is new Big_endian_number( U16 );", + "function_body": "procedure Read( image: in out Image_descriptor; sh: out Segment_head) is\n b: U8;\n id: constant array(JPEG_marker) of U8:=\n ( SOI => 16#D8#,\n --\n SOF_0 => 16#C0#, SOF_1 => 16#C1#, SOF_2 => 16#C2#, SOF_3 => 16#C3#,\n SOF_5 => 16#C5#, SOF_6 => 16#C6#, SOF_7 => 16#C7#, SOF_8 => 16#C8#,\n SOF_9 => 16#C9#, SOF_10 => 16#CA#, SOF_11 => 16#CB#, SOF_13 => 16#CD#,\n SOF_14 => 16#CE#, SOF_15 => 16#CF#,\n --\n DHT => 16#C4#,\n DAC => 16#CC#,\n DQT => 16#DB#,\n DRI => 16#DD#,\n --\n APP_0 => 16#E0#, APP_1 => 16#E1#, APP_2 => 16#E2#, APP_3 => 16#E3#,\n APP_4 => 16#E4#, APP_5 => 16#E5#, APP_6 => 16#E6#, APP_7 => 16#E7#,\n APP_8 => 16#E8#, APP_9 => 16#E9#, APP_10 => 16#EA#, APP_11 => 16#EB#,\n APP_12 => 16#EC#, APP_13 => 16#ED#, APP_14 => 16#EE#,\n --\n COM => 16#FE#,\n SOS => 16#DA#,\n EOI => 16#D9#\n );\n begin\n Get_Byte(image.buffer, b);\n if b /= 16#FF# then\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: expected marker here\"\n );\n end if;\n Get_Byte(image.buffer, b);\n for m in id'Range loop\n if id(m)= b then\n sh.kind:= m;\n Big_endian(image.buffer, sh.length);\n sh.length:= sh.length - 2;\n -- We consider length of contents, without the FFxx marker.\n if some_trace then\n Put_Line(\n \"Segment [\" & JPEG_marker'Image(sh.kind) &\n \"], length:\" & U16'Image(sh.length));\n end if;\n return;\n end if;\n end loop;\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: unknown marker here: FF, \" & U8'Image(b)\n );\n end Read;\n\n shift_arg: constant array(0..15) of Integer:=\n (1 => 0, 2 => 1, 4 => 2, 8 => 3, others => -1);\n\n -- SOF - Start Of Frame (the real header)\n procedure Read_SOF(image: in out Image_descriptor; sh: Segment_head) is\n use Bounded_255;\n b, bits_pp_primary, id_base: U8;\n w, h: U16;\n compo: JPEG_defs.Component;\n begin\n case sh.kind is\n when SOF_0 =>\n image.detailed_format:= To_Bounded_String(\"JPEG, Baseline DCT (SOF_0)\");\n when SOF_2 =>\n image.detailed_format:= To_Bounded_String(\"JPEG, Progressive DCT (SOF_2)\");\n image.interlaced:= True;\n when others =>\n Raise_Exception(\n unsupported_image_subformat'Identity,\n \"JPEG: image type not yet supported: \" & JPEG_marker'Image(sh.kind)\n );\n end case;\n Get_Byte(image.buffer, bits_pp_primary);\n if bits_pp_primary /= 8 then\n Raise_Exception(\n unsupported_image_subformat'Identity,\n \"Bits per primary color=\" & U8'Image(bits_pp_primary)\n );\n end if;\n image.bits_per_pixel:= 3 * Positive(bits_pp_primary);\n Big_endian(image.buffer, h);\n Big_endian(image.buffer, w);\n image.width:= Natural(w);\n image.height:= Natural(h);\n -- Number of components:\n Get_Byte(image.buffer, b);\n image.subformat_id:= Integer(b);\n --\n image.JPEG_stuff.max_samples_hor:= 0;\n image.JPEG_stuff.max_samples_ver:= 0;\n id_base := 1;\n -- For each component: 3 bytes information: ID, sampling factors, quantization table number\n for i in 1..image.subformat_id loop\n -- Component ID (1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q)\n Get_Byte(image.buffer, b);\n if b = 0 then\n -- Workaround for a bug in some encoders, for instance Intel(R) JPEG Library,\n -- version [2.0.18.50] as in some Photoshop versions : IDs are numbered 0, 1, 2.\n id_base := 0;\n end if;\n if b - id_base > Component'Pos(Component'Last) then\n Raise_Exception(error_in_image_data'Identity, \"SOF: invalid component ID: \" & U8'Image(b));\n end if;\n compo:= JPEG_defs.Component'Val(b - id_base);\n image.JPEG_stuff.components(compo):= True;\n declare\n stuff: JPEG_stuff_type renames image.JPEG_stuff;\n info: JPEG_defs.Info_per_component_A renames stuff.info(compo);\n begin\n -- Sampling factors (bit 0-3 vert., 4-7 hor.)\n Get_Byte(image.buffer, b);\n info.samples_ver:= Natural(b mod 16);\n info.samples_hor:= Natural(b / 16);\n stuff.max_samples_hor:=\n Integer'Max(stuff.max_samples_hor, info.samples_hor);\n stuff.max_samples_ver:=\n Integer'Max(stuff.max_samples_ver, info.samples_ver);\n -- Quantization table number\n Get_Byte(image.buffer, b);\n info.qt_assoc:= Natural(b);" + }, + { + "function_def": "procedure Color_transformation_and_output;", + "function_body": "--\n procedure Color_transformation_and_output is\n y_val, cb_val, cr_val, c_val, m_val, w_val: Integer;\n y_val_8: U8;\n begin\n for ymb in flat'Range(3) loop\n exit when y0+ymb >= image.height;\n Set_X_Y(x0, image.height-1-(y0+ymb));\n for xmb in flat'Range(2) loop\n exit when x0+xmb >= image.width;\n case color_space is\n when YCbCr =>\n y_val := flat(Y, xmb, ymb) * 256;\n cb_val:= flat(Cb, xmb, ymb) - 128;\n cr_val:= flat(Cr, xmb, ymb) - 128;\n Out_Pixel_8(\n br => U8(Clip((y_val + 359 * cr_val + 128) / 256)),\n bg => U8(Clip((y_val - 88 * cb_val - 183 * cr_val + 128) / 256)),\n bb => U8(Clip((y_val + 454 * cb_val + 128) / 256))\n );\n when Y_Grey =>\n y_val_8:= U8(flat(Y, xmb, ymb));\n Out_Pixel_8(y_val_8, y_val_8, y_val_8);\n when CMYK =>\n -- !! find a working conversion formula.\n -- perhaps it is more complicated (APP_2\n -- color profile must be used ?)\n c_val:= flat(Y, xmb, ymb);\n m_val:= flat(Cb, xmb, ymb);\n y_val:= flat(Cr, xmb, ymb);\n w_val:= flat(I, xmb, ymb)-255;\n Out_Pixel_8(\n br => U8(255-Clip(c_val+w_val)),\n bg => U8(255-Clip(m_val+w_val)),\n bb => U8(255-Clip(y_val+w_val))\n );\n end case;\n end loop;\n end loop;\n end Color_transformation_and_output;\n --\n procedure Ct_YCbCr is new Color_transformation_and_output(YCbCr);\n procedure Ct_Y_Grey is new Color_transformation_and_output(Y_Grey);\n procedure Ct_CMYK is new Color_transformation_and_output(CMYK);\n\n blk_idx: Integer;\n upsx, upsy: Natural;\n begin\n -- Step 4 happens here: Upsampling\n for c in Component loop\n if image.JPEG_stuff.components(c) then\n upsx:= info_A(c).up_factor_x;\n upsy:= info_A(c).up_factor_y;\n for x in reverse 1..info_A(c).samples_hor loop\n for y in reverse 1..info_A(c).samples_ver loop\n -- We are at the 8x8 block level\n blk_idx:= 63;\n for y8 in reverse 0..7 loop\n for x8 in reverse 0..7 loop\n declare\n val: constant Integer:= m(c,x,y)(blk_idx);\n big_pixel_x: constant Natural:= upsx * (x8 + 8*(x-1));\n big_pixel_y: constant Natural:= upsy * (y8 + 8*(y-1));\n begin\n -- Repeat pixels for component c, sample (x,y),\n -- position (x8,y8).\n for rx in reverse 0..upsx-1 loop\n for ry in reverse 0..upsy-1 loop\n flat(c, rx + big_pixel_x, ry + big_pixel_y):= val;\n end loop;\n end loop;" + }, + { + "function_def": "procedure Read_SOS is", + "function_body": "components, b, id_base: U8;\n compo: Component:= Component'First;\n mbx, mby: Natural:= 0;\n mbsizex, mbsizey, mbwidth, mbheight: Natural;\n rstcount: Natural:= image.JPEG_stuff.restart_interval;\n nextrst: U16:= 0;\n w: U16;\n start_spectral_selection,\n end_spectral_selection,\n successive_approximation: U8;\n begin\n Get_Byte(image.buffer, components);\n if some_trace then\n Put_Line(\n \"Start of Scan (SOS), with\" & U8'Image(components) & \" components\"\n );\n end if;\n if image.subformat_id /= Natural(components) then\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: components mismatch in Scan segment\"\n );\n end if;\n id_base := 1;\n for i in 1..components loop\n Get_Byte(image.buffer, b);\n if b = 0 then\n -- Workaround for bugged encoder (see above)\n id_base := 0;\n end if;\n if b - id_base > Component'Pos(Component'Last) then\n Raise_Exception(error_in_image_data'Identity, \"Scan: invalid ID: \" & U8'Image(b));\n end if;\n compo:= Component'Val(b - id_base);\n if not image.JPEG_stuff.components(compo) then\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: component \" & Component'Image(compo) &\n \" has not been defined in the header (SOF) segment\"\n );\n end if;\n -- Huffman table selection\n Get_Byte(image.buffer, b);\n info_B(compo).ht_idx_AC:= Natural(b mod 16);\n info_B(compo).ht_idx_DC:= Natural(b / 16);\n end loop;\n -- Parameters for progressive display format (SOF_2)\n Get_Byte(image.buffer, start_spectral_selection);\n Get_Byte(image.buffer, end_spectral_selection);\n Get_Byte(image.buffer, successive_approximation);\n --\n -- End of SOS segment, image data follow.\n --\n mbsizex:= ssxmax * 8; -- pixels in a row of a macro-block\n mbsizey:= ssymax * 8; -- pixels in a column of a macro-block\n mbwidth := (image.width + mbsizex - 1) / mbsizex;\n -- width in macro-blocks\n mbheight:= (image.height + mbsizey - 1) / mbsizey;\n -- height in macro-blocks\n if some_trace then\n Put_Line(\" mbsizex = \" & Integer'Image(mbsizex));\n Put_Line(\" mbsizey = \" & Integer'Image(mbsizey));\n Put_Line(\" mbwidth = \" & Integer'Image(mbwidth));\n Put_Line(\" mbheight = \" & Integer'Image(mbheight));\n end if;\n for c in Component loop\n if image.JPEG_stuff.components(c) then\n info_B(c).width := (image.width * info_A(c).samples_hor + ssxmax - 1) / ssxmax;\n info_B(c).height:= (image.height * info_A(c).samples_ver + ssymax - 1) / ssymax;\n info_B(c).stride:= (mbwidth * mbsizex * info_A(c).samples_hor) / ssxmax;\n if some_trace then\n Put_Line(\" Details for component \" & Component'Image(c));\n Put_Line(\" samples in x \" & Integer'Image(info_A(c).samples_hor));\n Put_Line(\" samples in y \" & Integer'Image(info_A(c).samples_ver));\n Put_Line(\" width \" & Integer'Image(info_B(c).width));\n Put_Line(\" height \" & Integer'Image(info_B(c).height));\n Put_Line(\" stride \" & Integer'Image(info_B(c).stride));\n Put_Line(\n \" AC/DC table index \" &\n Integer'Image(info_B(compo).ht_idx_AC) & \", \" &\n Integer'Image(info_B(compo).ht_idx_DC)\n );\n end if;\n if (info_B(c).width < 3 and info_A(c).samples_hor /= ssxmax) or\n (info_B(c).height < 3 and info_A(c).samples_ver /= ssymax)\n then\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: component \" & Component'Image(c) &\n \": sample dimension mismatch\"\n );\n end if;\n end if;\n end loop;\n --\n if image.interlaced then\n Raise_Exception(\n unsupported_image_subformat'Identity,\n \"JPEG: progressive format not yet functional\"\n );\n end if;\n declare\n mb: Macro_block(Component, 1..ssxmax, 1..ssymax);\n x0, y0: Integer:= 0;\n begin\n macro_blocks_loop:\n loop\n components_loop:\n for c in Component loop\n if image.JPEG_stuff.components(c) then\n samples_y_loop:\n for sby in 1..info_A(c).samples_ver loop\n samples_x_loop:\n for sbx in 1..info_A(c).samples_hor loop\n Decode_Block(c, mb(c, sbx, sby));\n end loop samples_x_loop;\n end loop samples_y_loop;\n end if;\n end loop components_loop;\n -- All components of the current macro-block are decoded.\n -- Step 4, 5, 6 happen here: Upsampling, color transformation, output\n Upsampling_and_output(mb, x0, y0);\n --\n mbx:= mbx + 1;\n x0:= x0 + ssxmax * 8;\n if mbx >= mbwidth then\n mbx:= 0;\n x0:= 0;\n mby:= mby + 1;\n y0:= y0 + ssymax * 8;\n Feedback((100*mby)/mbheight);\n exit macro_blocks_loop when mby >= mbheight;\n end if;\n if image.JPEG_stuff.restart_interval > 0 then\n rstcount:= rstcount - 1;\n if rstcount = 0 then\n -- Here begins the restart.\n bufbits:= Natural(U32(bufbits) and 16#F8#); -- byte alignment\n -- Now the restart marker. We expect a\n w:= U16(Get_bits(16));\n if some_trace then\n Put_Line(\n \" Restart #\" & U16'Image(nextrst) &\n \" Code \" & U16'Image(w) &\n \" after\" & Natural'Image(image.JPEG_stuff.restart_interval) &\n \" macro blocks\"\n );\n end if;\n if w not in 16#FFD0# .. 16#FFD7# or (w and 7) /= nextrst then\n Raise_Exception(\n error_in_image_data'Identity,\n \"JPEG: expected RST (restart) marker Nb \" & U16'Image(nextrst)\n );\n end if;\n nextrst:= (nextrst + 1) and 7;\n rstcount:= image.JPEG_stuff.restart_interval;\n -- Block-to-block predictor variables are reset.\n for c in Component loop\n info_B(c).dcpred:= 0;\n end loop;\n end if;\n end if;\n end loop macro_blocks_loop;" + }, + { + "function_def": "procedure Dispose is new", + "function_body": "Ada.Unchecked_Deallocation( HufT_table, p_HufT_table );\n procedure Dispose is new\n Ada.Unchecked_Deallocation( Table_list, p_Table_list );\n\n current: p_Table_list;\n tcount : Natural:= 0; -- just a stat. Idea: replace table_list with an array\n tot_length: Natural:= 0;\n\n begin\n if full_trace then\n Ada.Text_IO.Put(\"[HufT_Free... \");\n end if;\n while tl /= null loop\n if full_trace then\n tcount:= tcount+1;\n tot_length:= tot_length + tl.table'Length;\n end if;\n Dispose( tl.table ); -- destroy the Huffman table\n current:= tl;\n tl := tl.next;\n Dispose( current ); -- destroy the current node\n end loop;\n if full_trace then\n Ada.Text_IO.Put_Line(\n Integer'Image(tcount)& \" tables, of\" &\n Integer'Image(tot_length)& \" tot. length]\"\n );\n end if;\n end HufT_free;\n\n -- Build huffman table from code lengths given by array b\n\n procedure HufT_build ( b : Length_array;\n s : Integer;\n d, e : Length_array;\n tl : out p_Table_list;\n m : in out Integer;\n huft_incomplete : out Boolean)\n is\n b_max : constant:= 16;\n b_maxp1: constant:= b_max + 1;\n\n -- bit length count table\n count : array( 0 .. b_maxp1 ) of Integer:= (others=> 0);\n\n f : Integer; -- i repeats in table every f entries\n g : Integer; -- max. code length\n i, -- counter, current code\n j : Integer; -- counter\n kcc : Integer; -- number of bits in current code\n\n c_idx, v_idx: Natural; -- array indices\n\n current_table_ptr : p_HufT_table:= null;\n current_node_ptr : p_Table_list:= null; -- curr. node for the curr. table\n new_node_ptr : p_Table_list; -- new node for the new table\n\n new_entry: HufT; -- table entry for structure assignment\n\n u : array( 0..b_max ) of p_HufT_table; -- table stack\n\n n_max : constant:= 288;\n -- values in order of bit length\n v : array( 0..n_max ) of Integer:= (others=> 0);\n el_v, el_v_m_s: Integer;\n\n w : Natural:= 0; -- bits before this table\n\n offset, code_stack : array( 0..b_maxp1 ) of Integer;\n\n table_level : Integer:= -1;\n bits : array( Integer'(-1)..b_maxp1 ) of Integer;\n -- ^bits(table_level) = # bits in table of level table_level\n\n y : Integer; -- number of dummy codes added\n z : Natural:= 0; -- number of entries in current table\n el : Integer; -- length of eob code=code 256\n\n no_copy_length_array: constant Boolean:= d'Length=0 or e'Length=0;\n\n begin\n if full_trace then\n Ada.Text_IO.Put(\"[HufT_Build...\");\n end if;\n tl:= null;\n\n if b'Length > 256 then -- set length of EOB code, if any\n el := Natural(b(256));\n else\n el := b_max;\n end if;\n\n -- Generate counts for each bit length\n\n for k in b'Range loop\n if b(k) > b_max then\n -- m := 0; -- GNAT 2005 doesn't like it (warning).\n raise huft_error;\n end if;\n count( Natural(b(k)) ):= count( Natural(b(k)) ) + 1;\n end loop;\n\n if count(0) = b'Length then\n m := 0;\n huft_incomplete:= False; -- spotted by Tucker Taft, 19-Aug-2004\n return; -- complete\n end if;\n\n -- Find minimum and maximum length, bound m by those\n\n j := 1;\n while j <= b_max and then count(j) = 0 loop\n j:= j + 1;\n end loop;\n kcc := j;\n if m < j then\n m := j;\n end if;\n i := b_max;\n while i > 0 and then count(i) = 0 loop\n i:= i - 1;\n end loop;\n g := i;\n if m > i then\n m := i;\n end if;\n\n -- Adjust last length count to fill out codes, if needed\n\n y := Integer( Shift_Left(Unsigned_32'(1), j) ); -- y:= 2 ** j;\n while j < i loop\n y := y - count(j);\n if y < 0 then\n raise huft_error;\n end if;\n y:= y * 2;\n j:= j + 1;\n end loop;\n\n y:= y - count(i);\n if y < 0 then\n raise huft_error;\n end if;\n count(i):= count(i) + y;\n\n -- Generate starting offsets into the value table for each length\n\n offset(1) := 0;\n j:= 0;\n for idx in 2..i loop\n j:= j + count( idx-1 );\n offset( idx ) := j;\n end loop;\n\n -- Make table of values in order of bit length\n\n for idx in b'Range loop\n j := Natural(b(idx));\n if j /= 0 then\n v( offset(j) ) := idx-b'First;\n offset(j):= offset(j) + 1;\n end if;\n end loop;\n\n -- Generate huffman codes and for each, make the table entries\n\n code_stack(0) := 0;\n i := 0;\n v_idx:= v'First;\n bits(-1) := 0;\n\n -- go through the bit lengths (kcc already is bits in shortest code)\n for k in kcc .. g loop\n\n for am1 in reverse 0 .. count(k)-1 loop -- a counts codes of length k\n\n -- here i is the huffman code of length k bits for value v(v_idx)\n while k > w + bits(table_level) loop\n\n w:= w + bits(table_level); -- Length of tables to this position\n table_level:= table_level+ 1;\n z:= g - w; -- Compute min size table <= m bits\n if z > m then\n z := m;\n end if;\n j := k - w;\n f := Integer(Shift_Left(Unsigned_32'(1), j)); -- f:= 2 ** j;\n if f > am1 + 2 then -- Try a k-w bit table\n f:= f - (am1 + 2);\n c_idx:= k;\n loop -- Try smaller tables up to z bits\n j:= j + 1;\n exit when j >= z;\n f := f * 2;\n c_idx:= c_idx + 1;\n exit when f - count(c_idx) <= 0;\n f:= f - count(c_idx);\n end loop;\n end if;\n\n if w + j > el and then w < el then\n j:= el - w; -- Make EOB code end at table\n end if;\n if w = 0 then\n j := m; -- Fix: main table always m bits!\n end if;\n z:= Integer(Shift_Left(Unsigned_32'(1), j)); -- z:= 2 ** j;\n bits(table_level) := j;\n\n -- Allocate and link new table\n\n begin\n current_table_ptr := new HufT_table ( 0..z );\n new_node_ptr := new Table_list'( current_table_ptr, null );\n exception\n when Storage_Error =>\n raise huft_out_of_memory;" + }, + { + "function_def": "procedure Big_endian is new Big_endian_number( U32 );", + "function_body": "use Ada.Exceptions;\n\n ----------\n -- Read --\n ----------\n\n procedure Read (image: in out Image_descriptor; ch: out Chunk_head) is\n str4: String(1..4);\n b: U8;\n begin\n Big_endian(image.buffer, ch.length);\n for i in str4'Range loop\n Buffering.Get_Byte(image.buffer, b);\n str4(i):= Character'Val(b);\n end loop;\n begin\n ch.kind:= PNG_Chunk_tag'Value(str4);\n if some_trace then\n Ada.Text_IO.Put_Line(\n \"Chunk [\" & str4 &\n \"], length:\" & U32'Image(ch.length)\n );\n end if;\n exception\n when Constraint_Error =>\n Raise_Exception(\n error_in_image_data'Identity,\n \"PNG chunk unknown: \" &\n Integer'Image(Character'Pos(str4(1))) &\n Integer'Image(Character'Pos(str4(2))) &\n Integer'Image(Character'Pos(str4(3))) &\n Integer'Image(Character'Pos(str4(4))) &\n \" (\" & str4 & ')'\n );" + }, + { + "function_def": "procedure Prepare_table is", + "function_body": "-- CRC-32 algorithm, ISO-3309\n Seed: constant:= 16#EDB88320#;\n l: Unsigned_32;\n begin\n for i in CRC32_Table'Range loop\n l:= i;\n for bit in 0..7 loop\n if (l and 1) = 0 then\n l:= Shift_Right(l,1);\n else\n l:= Shift_Right(l,1) xor Seed;\n end if;\n end loop;\n CRC32_Table(i):= l;\n end loop;\n end Prepare_table;\n\n procedure Update( CRC: in out Unsigned_32; InBuf: Byte_array ) is\n local_CRC: Unsigned_32;\n begin\n local_CRC:= CRC ;\n for i in InBuf'Range loop\n local_CRC :=\n CRC32_Table( 16#FF# and ( local_CRC xor Unsigned_32( InBuf(i) ) ) )\n xor\n Shift_Right( local_CRC , 8 );\n end loop;\n CRC:= local_CRC;\n end Update;\n\n table_empty: Boolean:= True;\n\n procedure Init( CRC: out Unsigned_32 ) is\n begin\n if table_empty then\n Prepare_table;\n table_empty:= False;\n end if;\n CRC:= 16#FFFF_FFFF#;\n end Init;\n\n function Final( CRC: Unsigned_32 ) return Unsigned_32 is\n begin\n return not CRC;\n end Final;\n\n end CRC32;\n\n ----------\n -- Load --\n ----------\n\n procedure Load (image: in out Image_descriptor) is\n\n ----------------------\n -- Load_specialized --\n ----------------------\n\n generic\n -- These values are invariant through the whole picture,\n -- so we can make them generic parameters. As a result, all\n -- \"if\", \"case\", etc. using them at the center of the decoding\n -- are optimized out at compile-time.\n interlaced : Boolean;\n bits_per_pixel : Positive;\n bytes_to_unfilter : Positive;\n -- ^ amount of bytes to unfilter at a time\n -- = Integer'Max(1, bits_per_pixel / 8);\n subformat_id : Natural;\n procedure Load_specialized;\n --\n procedure Load_specialized is\n\n use GID.Buffering;\n\n subtype Mem_row_bytes_array is Byte_array(0..image.width*8);\n --\n mem_row_bytes: array(0..1) of Mem_row_bytes_array;\n -- We need to memorize two image rows, for un-filtering\n curr_row: Natural:= 1;\n -- either current is 1 and old is 0, or the reverse\n\n subtype X_range is Integer range -1..image.width-1;\n subtype Y_range is Integer range 0..image.height-1;\n -- X position -1 is for the row's filter methode code\n\n x: X_range:= X_range'First;\n y: Y_range:= Y_range'First;\n\n x_max: X_range; -- for non-interlaced images: = X_range'Last\n y_max: Y_range; -- for non-interlaced images: = Y_range'Last\n\n pass: Positive range 1..7:= 1;\n\n --------------------------\n -- ** 9: Unfiltering ** --\n --------------------------\n -- http://www.w3.org/TR/PNG/#9Filters\n\n type Filter_method_0 is (None, Sub, Up, Average, Paeth);\n\n current_filter: Filter_method_0;\n\n procedure Unfilter_bytes(\n f: in Byte_array; -- filtered\n u: out Byte_array -- unfiltered\n )\n is\n pragma Inline(Unfilter_bytes);\n -- Byte positions (f is the byte to be unfiltered):\n --\n -- c b\n -- a f\n a,b,c, p,pa,pb,pc,pr: Integer;\n j: Integer:= 0;\n begin\n if full_trace and then x = 0 then\n if y = 0 then\n Ada.Text_IO.New_Line;\n end if;\n Ada.Text_IO.Put_Line(\n \"row\" & Integer'Image(y) & \": filter= \" &\n Filter_method_0'Image(current_filter)\n );\n end if;\n --\n -- !! find a way to have f99n0g04.png decoded correctly...\n -- seems a filter issue.\n --\n case current_filter is\n when None =>\n -- Recon(x) = Filt(x)\n u:= f;\n when Sub =>\n -- Recon(x) = Filt(x) + Recon(a)\n if x > 0 then\n for i in f'Range loop\n u(u'First+j):= f(i) + mem_row_bytes(curr_row)((x-1)*bytes_to_unfilter+j);\n j:= j + 1;\n end loop;\n else\n u:= f;\n end if;\n when Up =>\n -- Recon(x) = Filt(x) + Recon(b)\n if y > 0 then\n for i in f'Range loop\n u(u'First+j):= f(i) + mem_row_bytes(1-curr_row)(x*bytes_to_unfilter+j);\n j:= j + 1;\n end loop;\n else\n u:= f;\n end if;\n when Average =>\n -- Recon(x) = Filt(x) + floor((Recon(a) + Recon(b)) / 2)\n for i in f'Range loop\n if x > 0 then\n a:= Integer(mem_row_bytes(curr_row)((x-1)*bytes_to_unfilter+j));\n else\n a:= 0;\n end if;\n if y > 0 then\n b:= Integer(mem_row_bytes(1-curr_row)(x*bytes_to_unfilter+j));\n else\n b:= 0;\n end if;\n u(u'First+j):= U8((Integer(f(i)) + (a+b)/2) mod 256);\n j:= j + 1;\n end loop;\n when Paeth =>\n -- Recon(x) = Filt(x) + PaethPredictor(Recon(a), Recon(b), Recon(c))\n for i in f'Range loop\n if x > 0 then\n a:= Integer(mem_row_bytes(curr_row)((x-1)*bytes_to_unfilter+j));\n else\n a:= 0;\n end if;\n if y > 0 then\n b:= Integer(mem_row_bytes(1-curr_row)(x*bytes_to_unfilter+j));\n else\n b:= 0;\n end if;\n if x > 0 and y > 0 then\n c:= Integer(mem_row_bytes(1-curr_row)((x-1)*bytes_to_unfilter+j));\n else\n c:= 0;\n end if;\n p := a + b - c;\n pa:= abs(p - a);\n pb:= abs(p - b);\n pc:= abs(p - c);\n if pa <= pb and then pa <= pc then\n pr:= a;\n elsif pb <= pc then\n pr:= b;\n else\n pr:= c;\n end if;\n u(u'First+j):= f(i) + U8(pr);\n j:= j + 1;\n end loop;\n end case;\n j:= 0;\n for i in u'Range loop\n mem_row_bytes(curr_row)(x*bytes_to_unfilter+j):= u(i);\n j:= j + 1;\n end loop;\n -- if u'Length /= bytes_to_unfilter then\n -- raise Constraint_Error;\n -- end if;\n end Unfilter_bytes;\n\n filter_stat: array(Filter_method_0) of Natural:= (others => 0);\n\n ----------------------------------------------\n -- ** 8: Interlacing and pass extraction ** --\n ----------------------------------------------\n -- http://www.w3.org/TR/PNG/#8Interlace\n\n -- Output bytes from decompression\n --\n procedure Output_uncompressed(\n data : in Byte_array;\n reject: out Natural\n -- amount of bytes to be resent here next time,\n -- in order to have a full multi-byte pixel\n )\n is\n -- Display of pixels coded on 8 bits per channel in the PNG stream\n procedure Out_Pixel_8(br, bg, bb, ba: U8) is\n pragma Inline(Out_Pixel_8);\n function Times_257(x: Primary_color_range) return Primary_color_range is\n pragma Inline(Times_257);\n begin\n return 16 * (16 * x) + x; -- this is 257 * x, = 16#0101# * x\n -- Numbers 8-bit -> no OA warning at instanciation. Returns x if type Primary_color_range is mod 2**8.\n end Times_257;\n begin\n case Primary_color_range'Modulus is\n when 256 =>\n Put_Pixel(\n Primary_color_range(br),\n Primary_color_range(bg),\n Primary_color_range(bb),\n Primary_color_range(ba)\n );\n when 65_536 =>\n Put_Pixel(\n Times_257(Primary_color_range(br)),\n Times_257(Primary_color_range(bg)),\n Times_257(Primary_color_range(bb)),\n Times_257(Primary_color_range(ba))\n -- Times_257 makes max intensity FF go to FFFF\n );\n when others =>\n raise invalid_primary_color_range;\n end case;\n end Out_Pixel_8;\n\n procedure Out_Pixel_Palette(ix: U8) is\n pragma Inline(Out_Pixel_Palette);\n color_idx: constant Natural:= Integer(ix);\n begin\n Out_Pixel_8(\n image.palette(color_idx).red,\n image.palette(color_idx).green,\n image.palette(color_idx).blue,\n 255\n );\n end Out_Pixel_Palette;\n\n -- Display of pixels coded on 16 bits per channel in the PNG stream\n procedure Out_Pixel_16(br, bg, bb, ba: U16) is\n pragma Inline(Out_Pixel_16);\n begin\n case Primary_color_range'Modulus is\n when 256 =>\n Put_Pixel(\n Primary_color_range(br / 256),\n Primary_color_range(bg / 256),\n Primary_color_range(bb / 256),\n Primary_color_range(ba / 256)\n );\n when 65_536 =>\n Put_Pixel(\n Primary_color_range(br),\n Primary_color_range(bg),\n Primary_color_range(bb),\n Primary_color_range(ba)\n );\n when others =>\n raise invalid_primary_color_range;\n end case;\n end Out_Pixel_16;\n\n procedure Inc_XY is\n pragma Inline(Inc_XY);\n xm, ym: Integer;\n begin\n if x < x_max then\n x:= x + 1;\n if interlaced then\n -- Position of pixels depending on pass:\n --\n -- 1 6 4 6 2 6 4 6\n -- 7 7 7 7 7 7 7 7\n -- 5 6 5 6 5 6 5 6\n -- 7 7 7 7 7 7 7 7\n -- 3 6 4 6 3 6 4 6\n -- 7 7 7 7 7 7 7 7\n -- 5 6 5 6 5 6 5 6\n -- 7 7 7 7 7 7 7 7\n case pass is\n when 1 =>\n Set_X_Y( x*8, Y_range'Last - y*8);\n when 2 =>\n Set_X_Y(4 + x*8, Y_range'Last - y*8);\n when 3 =>\n Set_X_Y( x*4, Y_range'Last - 4 - y*8);\n when 4 =>\n Set_X_Y(2 + x*4, Y_range'Last - y*4);\n when 5 =>\n Set_X_Y( x*2, Y_range'Last - 2 - y*4);\n when 6 =>\n Set_X_Y(1 + x*2, Y_range'Last - y*2);\n when 7 =>\n null; -- nothing to to, pixel are contiguous\n end case;\n end if;\n else\n x:= X_range'First; -- New row\n if y < y_max then\n y:= y + 1;\n curr_row:= 1-curr_row; -- swap row index for filtering\n if not interlaced then\n Feedback((y*100)/image.height);\n end if;\n elsif interlaced then -- last row has beed displayed\n while pass < 7 loop\n pass:= pass + 1;\n y:= 0;\n case pass is\n when 1 =>\n null;\n when 2 =>\n xm:= (image.width+3)/8 - 1;\n ym:= (image.height+7)/8 - 1;\n when 3 =>\n xm:= (image.width+3)/4 - 1;\n ym:= (image.height+3)/8 - 1;\n when 4 =>\n xm:= (image.width+1)/4 - 1;\n ym:= (image.height+3)/4 - 1;\n when 5 =>\n xm:= (image.width+1)/2 - 1;\n ym:= (image.height+1)/4 - 1;\n when 6 =>\n xm:= (image.width )/2 - 1;\n ym:= (image.height+1)/2 - 1;\n when 7 =>\n xm:= image.width - 1;\n ym:= image.height/2 - 1;\n end case;\n if xm >=0 and xm <= X_range'Last and ym in Y_range then\n -- This pass is not empty (otherwise, we will continue\n -- to the next one, if any).\n x_max:= xm;\n y_max:= ym;\n exit;\n end if;\n end loop;\n end if;\n end if;\n end Inc_XY;\n\n uf: Byte_array(0..15); -- unfiltered bytes for a pixel\n w1, w2: U16;\n i: Integer;\n\n begin\n if some_trace then\n Ada.Text_IO.Put(\"[UO]\");\n end if;\n -- Depending on the row size, bpp, etc., we can have\n -- several rows, or less than one, being displayed\n -- with the present uncompressed data batch.\n --\n i:= data'First;\n if i > data'Last then\n reject:= 0;\n return; -- data is empty, do nothing\n end if;\n --\n -- Main loop over data\n --\n loop\n if x = X_range'First then -- pseudo-column for filter method\n exit when i > data'Last;\n begin\n current_filter:= Filter_method_0'Val(data(i));\n if some_trace then\n filter_stat(current_filter):= filter_stat(current_filter) + 1;\n end if;\n exception\n when Constraint_Error =>\n Raise_Exception(\n error_in_image_data'Identity,\n \"PNG: wrong filter code, row #\" &\n Integer'Image(y) & \" code:\" & U8'Image(data(i))\n );" + }, + { + "function_def": "procedure Jump_IDAT is", + "function_body": "dummy: U32;\n begin\n Big_endian(image.buffer, dummy); -- ending chunk's CRC\n -- New chunk begins here.\n loop\n Read(image, ch);\n exit when ch.kind /= IDAT or ch.length > 0;\n end loop;\n if ch.kind /= IDAT then\n Raise_Exception(\n error_in_image_data'Identity,\n \"PNG additional data chunk must be an IDAT\"\n );\n end if;\n end Jump_IDAT;\n\n ---------------------------------------------------------------------\n -- ** 10: Decompression ** --\n -- Excerpt and simplification from UnZip.Decompress (Inflate only) --\n ---------------------------------------------------------------------\n -- http://www.w3.org/TR/PNG/#10Compression\n\n -- Size of sliding dictionary and circular output buffer\n wsize: constant:= 16#10000#;\n\n --------------------------------------\n -- Specifications of UnZ_* packages --\n --------------------------------------\n\n package UnZ_Glob is\n -- I/O Buffers\n -- > Sliding dictionary for unzipping, and output buffer as well\n slide: Byte_array( 0..wsize );\n slide_index: Integer:= 0; -- Current Position in slide\n Zip_EOF : constant Boolean:= False;\n crc32val : Unsigned_32; -- crc calculated from data\n end UnZ_Glob;\n\n package UnZ_IO is\n\n procedure Init_Buffers;\n\n procedure Read_raw_byte ( bt : out U8 );\n pragma Inline(Read_raw_byte);\n\n package Bit_buffer is\n procedure Init;\n -- Read at least n bits into the bit buffer, returns the n first bits\n function Read ( n: Natural ) return Integer;\n pragma Inline(Read);\n function Read_U32 ( n: Natural ) return Unsigned_32;\n pragma Inline(Read_U32);\n -- Dump n bits no longer needed from the bit buffer\n procedure Dump ( n: Natural );\n pragma Inline(Dump);\n procedure Dump_to_byte_boundary;\n function Read_and_dump( n: Natural ) return Integer;\n pragma Inline(Read_and_dump);\n function Read_and_dump_U32( n: Natural ) return Unsigned_32;\n pragma Inline(Read_and_dump_U32);\n end Bit_buffer;\n\n procedure Flush ( x: Natural ); -- directly from slide to output stream\n\n procedure Flush_if_full(W: in out Integer);\n pragma Inline(Flush_if_full);\n\n procedure Copy(\n distance, length: Natural;\n index : in out Natural );\n pragma Inline(Copy);\n\n end UnZ_IO;\n\n package UnZ_Meth is\n deflate_e_mode: constant Boolean:= False;\n procedure Inflate;\n end UnZ_Meth;\n\n ------------------------------\n -- Bodies of UnZ_* packages --\n ------------------------------\n package body UnZ_IO is\n\n procedure Init_Buffers is\n begin\n UnZ_Glob.slide_index := 0;\n Bit_buffer.Init;\n CRC32.Init( UnZ_Glob.crc32val );\n end Init_Buffers;\n\n procedure Read_raw_byte ( bt : out U8 ) is\n begin\n if ch.length = 0 then\n -- We hit the end of a PNG 'IDAT' chunk, so we go to the next one\n -- - in petto, it's strange design, but well...\n -- This \"feature\" has taken some time (and nerves) to be addressed.\n -- Incidentally, I have reprogrammed the whole Huffman\n -- decoding, and looked at many other wrong places to solve\n -- the mystery.\n Jump_IDAT;\n end if;\n Buffering.Get_Byte(image.buffer, bt);\n ch.length:= ch.length - 1;\n end Read_raw_byte;\n\n package body Bit_buffer is\n B : Unsigned_32;\n K : Integer;\n\n procedure Init is\n begin\n B := 0;\n K := 0;\n end Init;\n\n procedure Need( n : Natural ) is\n pragma Inline(Need);\n bt: U8;\n begin\n while K < n loop\n Read_raw_byte( bt );\n B:= B or Shift_Left( Unsigned_32( bt ), K );\n K:= K + 8;\n end loop;\n end Need;\n\n procedure Dump ( n : Natural ) is\n begin\n B := Shift_Right(B, n );\n K := K - n;\n end Dump;\n\n procedure Dump_to_byte_boundary is\n begin\n Dump ( K mod 8 );\n end Dump_to_byte_boundary;\n\n function Read_U32 ( n: Natural ) return Unsigned_32 is\n begin\n Need(n);\n return B and (Shift_Left(1,n) - 1);\n end Read_U32;\n\n function Read ( n: Natural ) return Integer is\n begin\n return Integer(Read_U32(n));\n end Read;\n\n function Read_and_dump( n: Natural ) return Integer is\n res: Integer;\n begin\n res:= Read(n);\n Dump(n);\n return res;\n end Read_and_dump;\n\n function Read_and_dump_U32( n: Natural ) return Unsigned_32 is\n res: Unsigned_32;\n begin\n res:= Read_U32(n);\n Dump(n);\n return res;\n end Read_and_dump_U32;\n\n end Bit_buffer;\n\n old_bytes: Natural:= 0;\n -- how many bytes to be resent from last Inflate output\n byte_mem: Byte_array(1..8);\n\n procedure Flush ( x: Natural ) is\n begin\n if full_trace then\n Ada.Text_IO.Put(\"[Flush...\" & Integer'Image(x));\n end if;\n CRC32.Update( UnZ_Glob.crc32val, UnZ_Glob.slide( 0..x-1 ) );\n if old_bytes > 0 then\n declare\n app: constant Byte_array:=\n byte_mem(1..old_bytes) & UnZ_Glob.slide(0..x-1);\n begin\n Output_uncompressed(app, old_bytes);\n -- In extreme cases (x very small), we might have some of\n -- the rejected bytes from byte_mem.\n if old_bytes > 0 then\n byte_mem(1..old_bytes):= app(app'Last-(old_bytes-1)..app'Last);\n end if;" + }, + { + "function_def": "procedure Inflate_stored_block is -- Actually, nothing to inflate", + "function_body": "N : Integer;\n begin\n if full_trace then\n Ada.Text_IO.Put_Line(\"Begin Inflate_stored_block\");\n end if;\n UnZ_IO.Bit_buffer.Dump_to_byte_boundary;\n\n -- Get the block length and its complement\n N:= UnZ_IO.Bit_buffer.Read_and_dump( 16 );\n if N /= Integer(\n (not UnZ_IO.Bit_buffer.Read_and_dump_U32(16))\n and 16#ffff#)\n then\n raise error_in_image_data;\n end if;\n while N > 0 and then not UnZ_Glob.Zip_EOF loop\n -- Read and output the non-compressed data\n N:= N - 1;\n UnZ_Glob.slide ( UnZ_Glob.slide_index ) :=\n U8( UnZ_IO.Bit_buffer.Read_and_dump(8) );\n UnZ_Glob.slide_index:= UnZ_Glob.slide_index + 1;\n UnZ_IO.Flush_if_full(UnZ_Glob.slide_index);\n end loop;\n if full_trace then\n Ada.Text_IO.Put_Line(\"End Inflate_stored_block\");\n end if;\n end Inflate_stored_block;\n\n -- Copy lengths for literal codes 257..285\n\n copy_lengths_literal : Length_array( 0..30 ) :=\n ( 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,\n 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 );\n\n -- Extra bits for literal codes 257..285\n\n extra_bits_literal : Length_array( 0..30 ) :=\n ( 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\n 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid, invalid );\n\n -- Copy offsets for distance codes 0..29 (30..31: deflate_e)\n\n copy_offset_distance : constant Length_array( 0..31 ) :=\n ( 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\n 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\n 8193, 12289, 16385, 24577, 32769, 49153 );\n\n -- Extra bits for distance codes\n\n extra_bits_distance : constant Length_array( 0..31 ) :=\n ( 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,\n 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14 );\n\n max_dist: Integer:= 29; -- changed to 31 for deflate_e\n\n procedure Inflate_fixed_block is\n Tl, -- literal/length code table\n Td : p_Table_list; -- distance code table\n Bl, Bd : Integer; -- lookup bits for tl/bd\n huft_incomplete : Boolean;\n\n -- length list for HufT_build (literal table)\n L: constant Length_array( 0..287 ):=\n ( 0..143=> 8, 144..255=> 9, 256..279=> 7, 280..287=> 8);\n\n begin\n if full_trace then\n Ada.Text_IO.Put_Line(\"Begin Inflate_fixed_block\");\n end if;\n\n -- make a complete, but wrong code set\n Bl := 7;\n HufT_build(\n L, 257, copy_lengths_literal, extra_bits_literal,\n Tl, Bl, huft_incomplete\n );\n\n -- Make an incomplete code set\n Bd := 5;\n begin\n HufT_build(\n (0..max_dist => 5), 0,\n copy_offset_distance, extra_bits_distance,\n Td, Bd, huft_incomplete\n );\n if huft_incomplete then\n if full_trace then\n Ada.Text_IO.Put_Line(\n \"td is incomplete, pointer=null: \" &\n Boolean'Image(Td=null)\n );\n end if;\n end if;\n exception\n when huft_out_of_memory | huft_error =>\n HufT_free( Tl );\n raise error_in_image_data;" + }, + { + "function_def": "procedure Inflate_dynamic_block is", + "function_body": "bit_order : constant array ( 0..18 ) of Natural :=\n ( 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 );\n\n Lbits : constant:= 9;\n Dbits : constant:= 6;\n\n current_length: Natural:= 0;\n defined, number_of_lengths: Natural;\n\n Tl, -- literal/length code tables\n Td : p_Table_list; -- distance code tables\n\n CT_dyn_idx : Integer; -- current table element\n\n Bl, Bd : Integer; -- lookup bits for tl/bd\n Nb : Natural; -- number of bit length codes\n Nl : Natural; -- number of literal length codes\n Nd : Natural; -- number of distance codes\n\n -- literal/length and distance code lengths\n Ll: Length_array( 0 .. 288+32-1 ):= (others=> 0);\n\n huft_incomplete : Boolean;\n\n procedure Repeat_length_code( amount: Natural ) is\n begin\n if defined + amount > number_of_lengths then\n raise error_in_image_data;\n end if;\n for c in reverse 1..amount loop\n Ll ( defined ) := Natural_M32(current_length);\n defined:= defined + 1;\n end loop;\n end Repeat_length_code;\n\n begin\n if full_trace then\n Ada.Text_IO.Put_Line(\"Begin Inflate_dynamic_block\");\n end if;\n\n -- Read in table lengths\n Nl := 257 + UnZ_IO.Bit_buffer.Read_and_dump(5);\n Nd := 1 + UnZ_IO.Bit_buffer.Read_and_dump(5);\n Nb := 4 + UnZ_IO.Bit_buffer.Read_and_dump(4);\n\n if Nl > 288 or else Nd > 32 then\n raise error_in_image_data;\n end if;\n\n -- Read in bit-length-code lengths.\n -- The rest, Ll( Bit_Order( Nb .. 18 ) ), is already = 0\n for J in 0 .. Nb - 1 loop\n Ll ( bit_order( J ) ) := Natural_M32(UnZ_IO.Bit_buffer.Read_and_dump(3));\n end loop;\n\n -- Build decoding table for trees--single level, 7 bit lookup\n Bl := 7;\n begin\n HufT_build (\n Ll( 0..18 ), 19, empty, empty, Tl, Bl, huft_incomplete\n );\n if huft_incomplete then\n HufT_free(Tl);\n raise error_in_image_data;\n end if;\n exception\n when others =>\n raise error_in_image_data;" + }, + { + "function_def": "procedure Inflate is", + "function_body": "is_last_block: Boolean;\n blocks: Positive:= 1;\n begin\n if deflate_e_mode then\n copy_lengths_literal(28):= 3; -- instead of 258\n extra_bits_literal(28):= 16; -- instead of 0\n max_dist:= 31;\n end if;\n loop\n Inflate_Block ( is_last_block );\n exit when is_last_block;\n blocks:= blocks+1;\n end loop;\n UnZ_IO.Flush( UnZ_Glob.slide_index );\n UnZ_Glob.slide_index:= 0;\n if some_trace then\n Ada.Text_IO.Put(\"# blocks:\" & Integer'Image(blocks));\n end if;\n UnZ_Glob.crc32val := CRC32.Final( UnZ_Glob.crc32val );\n end Inflate;\n\n end UnZ_Meth;\n\n --------------------------------------------------------------------\n -- End of the Decompression part, and of UnZip.Decompress excerpt --\n --------------------------------------------------------------------\n\n b: U8;\n z_crc, dummy: U32;\n\n begin -- Load_specialized\n --\n -- For optimization reasons, bytes_to_unfilter is passed as a\n -- generic parameter but should be always as below right to \"/=\" :\n --\n if bytes_to_unfilter /= Integer'Max(1, bits_per_pixel / 8) then\n raise Program_Error;\n end if;\n if interlaced then\n x_max:= (image.width+7)/8 - 1;\n y_max:= (image.height+7)/8 - 1;\n else\n x_max:= X_range'Last;\n y_max:= Y_range'Last;\n end if;\n main_chunk_loop:\n loop\n loop\n Read(image, ch);\n exit when ch.kind = IEND or ch.length > 0;\n end loop;\n case ch.kind is\n when IEND => -- 11.2.5 IEND Image trailer\n exit main_chunk_loop;\n when IDAT => -- 11.2.4 IDAT Image data\n --\n -- NB: the compressed data may hold on several IDAT chunks.\n -- It means that right in the middle of compressed data, you\n -- can have a chunk crc, and a new IDAT header!...\n --\n UnZ_IO.Read_raw_byte(b); -- zlib compression method/flags code\n UnZ_IO.Read_raw_byte(b); -- Additional flags/check bits\n --\n UnZ_IO.Init_Buffers;\n -- ^ we indicate that we have a byte reserve of chunk's length,\n -- minus both zlib header bytes.\n UnZ_Meth.Inflate;\n z_crc:= 0;\n for i in 1..4 loop\n begin\n UnZ_IO.Read_raw_byte(b);\n exception\n when error_in_image_data =>\n -- vicious IEND at the wrong place\n -- basi4a08.png test image (corrupt imho)\n exit main_chunk_loop;" + }, + { + "function_def": "procedure Read_Intel is new Read_Intel_x86_number( U16 );", + "function_body": "type GIFDescriptor is record\n ImageLeft,\n ImageTop,\n ImageWidth,\n ImageHeight : U16;\n Depth : U8;\n end record;\n\n -- For loading from the GIF file\n Descriptor : GIFDescriptor;\n\n -- Coordinates\n X, tlX, brX : Natural;\n Y, tlY, brY : Natural;\n\n -- Code information\n subtype Code_size_range is Natural range 2..12;\n CurrSize : Code_size_range;\n\n subtype Color_type is U8;\n Transp_color : Color_type:= 0;\n\n -- GIF data is stored in blocks and sub-blocks.\n -- We initialize block_read and block_size to force\n -- reading and buffering the next sub-block\n block_size : Natural:= 0;\n block_read : Natural:= 0;\n\n function Read_Byte return U8 is\n pragma Inline(Read_Byte);\n b: U8;\n begin\n if block_read >= block_size then\n Get_Byte(image.buffer, b);\n Raw_Byte (b);\n block_size:= Natural(b);\n block_read:= 0;\n end if;\n Get_Byte(image.buffer, b);\n Raw_Byte (b);\n block_read:= block_read + 1;\n return b;\n end Read_Byte;\n\n -- Used while reading the codes\n bits_in : U8:= 8;\n bits_buf: U8;\n\n -- Local procedure to read the next code from the file\n function Read_Code return Natural is\n bit_mask: Natural:= 1;\n code: Natural:= 0;\n begin\n -- Read the code, bit by bit\n for Counter in reverse 0..CurrSize - 1 loop\n -- Next bit\n bits_in:= bits_in + 1;\n -- Maybe, a new byte needs to be loaded with a further 8 bits\n if bits_in = 9 then\n bits_buf:= Read_Byte;\n bits_in := 1;\n end if;\n -- Add the current bit to the code\n if (bits_buf and 1) > 0 then\n code:= code + bit_mask;\n end if;\n bit_mask := bit_mask * 2;\n bits_buf := bits_buf / 2;\n end loop;\n return code;\n end Read_Code;\n\n generic\n -- Parameter(s) that are constant through\n -- the whole image. Macro-expanded generics and\n -- some optimization will trim corresponding \"if's\"\n interlaced : Boolean;\n transparency : Boolean;\n pixel_mask : U32;\n --\n procedure GIF_Decode;\n\n procedure GIF_Decode is\n\n procedure Pixel_with_palette(b: U8) is\n pragma Inline(Pixel_with_palette);\n function Times_257(x: Primary_color_range) return Primary_color_range is\n pragma Inline(Times_257);\n begin\n return 16 * (16 * x) + x; -- this is 257 * x, = 16#0101# * x\n -- Numbers 8-bit -> no OA warning at instanciation. Returns x if type Primary_color_range is mod 2**8.\n end Times_257;\n full_opaque: constant Primary_color_range:= Primary_color_range'Last;\n begin\n if transparency and then b = Transp_color then\n Put_Pixel(0,0,0, 0);\n return;\n end if;\n case Primary_color_range'Modulus is\n when 256 =>\n Put_Pixel(\n Primary_color_range(local.palette(Integer(b)).red),\n Primary_color_range(local.palette(Integer(b)).green),\n Primary_color_range(local.palette(Integer(b)).blue),\n full_opaque\n );\n when 65_536 =>\n Put_Pixel(\n Times_257(Primary_color_range(local.palette(Integer(b)).red)),\n Times_257(Primary_color_range(local.palette(Integer(b)).green)),\n Times_257(Primary_color_range(local.palette(Integer(b)).blue)),\n -- Times_257 makes max intensity FF go to FFFF\n full_opaque\n );\n when others =>\n raise invalid_primary_color_range;\n end case;\n end Pixel_with_palette;\n\n -- Interlacing\n Interlace_pass : Natural range 1..4:= 1;\n Span : Natural:= 7;\n\n -- Local procedure to draw a pixel\n procedure Next_Pixel(code: Natural) is\n pragma Inline(Next_Pixel);\n c : constant Color_type:= Color_type(U32(code) and pixel_mask);\n begin\n -- Actually draw the pixel on screen buffer\n if X < image.width then\n if interlaced and mode = nice then\n for i in reverse 0..Span loop\n if Y+i < image.height then\n Set_X_Y(X, image.height - (Y+i) - 1);\n Pixel_with_palette(c);\n end if;\n end loop;\n elsif Y < image.height then\n Pixel_with_palette(c);\n end if;\n end if;\n\n -- Move on to next pixel\n X:= X + 1;\n\n -- Or next row, if necessary\n if X = brX then\n X:= tlX;\n if interlaced then\n case Interlace_pass is\n when 1 =>\n Y:= Y + 8;\n if Y >= brY then\n Y:= 4;\n Interlace_pass:= 2;\n Span:= 3;\n Feedback((Interlace_pass*100)/4);\n end if;\n when 2 =>\n Y:= Y + 8;\n if Y >= brY then\n Y:= 2;\n Interlace_pass:= 3;\n Span:= 1;\n Feedback((Interlace_pass*100)/4);\n end if;\n when 3 =>\n Y:= Y + 4;\n if Y >= brY then\n Y:= 1;\n Interlace_pass:= 4;\n Span:= 0;\n Feedback((Interlace_pass*100)/4);\n end if;\n when 4 =>\n Y:= Y + 2;\n end case;\n if mode = fast and then Y < image.height then\n Set_X_Y(X, image.height - Y - 1);\n end if;\n else -- not interlaced\n Y:= Y + 1;\n if Y < image.height then\n Set_X_Y(X, image.height - Y - 1);\n end if;\n if Y mod 32 = 0 then\n Feedback((Y*100)/image.height);\n end if;\n end if;\n end if;\n end Next_Pixel;\n\n -- The string table\n Prefix : array ( 0..4096 ) of Natural:= (others => 0);\n Suffix : array ( 0..4096 ) of Natural:= (others => 0);\n -- Top of Stack was 1024 until files from\n -- https://www.kaggle.com/c/carvana-image-masking-challenge\n -- broke it (July 2017)...\n Stack : array ( 0..2048 ) of Natural;\n\n -- Special codes (specific to GIF's flavour of LZW)\n ClearCode : constant Natural:= 2 ** CurrSize; -- Reset code\n EndingCode: constant Natural:= ClearCode + 1; -- End of file\n FirstFree : constant Natural:= ClearCode + 2; -- Strings start here\n\n Slot : Natural:= FirstFree; -- Last read code\n InitCodeSize : constant Code_size_range:= CurrSize + 1;\n TopSlot : Natural:= 2 ** InitCodeSize; -- Highest code for current size\n Code : Natural;\n StackPtr : Integer:= 0;\n Fc : Integer:= 0;\n Oc : Integer:= 0;\n C : Integer;\n BadCodeCount : Natural:= 0; -- the number of bad codes found\n\n begin -- GIF_Decode\n -- The decoder source and the cool comments are kindly donated by\n -- Andr\u00e9 van Splunter.\n --\n CurrSize:= InitCodeSize;\n -- This is the main loop. For each code we get we pass through the\n -- linked list of prefix codes, pushing the corresponding \"character\"\n -- for each code onto the stack. When the list reaches a single\n -- \"character\" we push that on the stack too, and then start unstacking\n -- each character for output in the correct order. Special handling is\n -- included for the clear code, and the whole thing ends when we get\n -- an ending code.\n C := Read_Code;\n while C /= EndingCode loop\n -- If the code is a clear code, reinitialize all necessary items.\n if C = ClearCode then\n CurrSize := InitCodeSize;\n Slot := FirstFree;\n TopSlot := 2 ** CurrSize;\n -- Continue reading codes until we get a non-clear code\n -- (Another unlikely, but possible case...)\n C := Read_Code;\n while C = ClearCode loop\n C := Read_Code;\n end loop;\n -- If we get an ending code immediately after a clear code\n -- (Yet another unlikely case), then break out of the loop.\n exit when C = EndingCode;\n -- Finally, if the code is beyond the range of already set codes,\n -- (This one had better NOT happen... I have no idea what will\n -- result from this, but I doubt it will look good...) then set\n -- it to color zero.\n if C >= Slot then\n C := 0;\n end if;\n Oc := C;\n Fc := C;\n -- And let us not forget to output the char...\n Next_Pixel(C);\n else -- C /= ClearCode\n -- In this case, it's not a clear code or an ending code, so\n -- it must be a code code... So we can now decode the code into\n -- a stack of character codes. (Clear as mud, right?)\n Code := C;\n -- Here we go again with one of those off chances... If, on the\n -- off chance, the code we got is beyond the range of those\n -- already set up (Another thing which had better NOT happen...)\n -- we trick the decoder into thinking it actually got the last\n -- code read. (Hmmn... I'm not sure why this works...\n -- But it does...)\n if Code >= Slot then\n if Code > Slot then\n BadCodeCount := BadCodeCount + 1;\n end if;\n Code := Oc;\n Stack (StackPtr) := Fc rem 256;\n StackPtr := StackPtr + 1;\n end if;\n -- Here we scan back along the linked list of prefixes, pushing\n -- helpless characters (ie. suffixes) onto the stack as we do so.\n while Code >= FirstFree loop\n Stack (StackPtr) := Suffix (Code);\n StackPtr := StackPtr + 1;\n Code := Prefix (Code);\n end loop;\n -- Push the last character on the stack, and set up the new\n -- prefix and suffix, and if the required slot number is greater\n -- than that allowed by the current bit size, increase the bit\n -- size. (NOTE - If we are all full, we *don't* save the new\n -- suffix and prefix... I'm not certain if this is correct...\n -- it might be more proper to overwrite the last code...\n Stack (StackPtr) := Code rem 256;\n if Slot < TopSlot then\n Suffix (Slot) := Code rem 256;\n Fc := Code;\n Prefix (Slot) := Oc;\n Slot := Slot + 1;\n Oc := C;\n end if;\n if Slot >= TopSlot then\n if CurrSize < 12 then\n TopSlot := TopSlot * 2;\n CurrSize := CurrSize + 1;\n end if;\n end if;\n -- Now that we've pushed the decoded string (in reverse order)\n -- onto the stack, lets pop it off and output it...\n loop\n Next_Pixel(Stack (StackPtr));\n exit when StackPtr = 0;\n StackPtr := StackPtr - 1;\n end loop;\n end if;\n C := Read_Code;\n end loop;\n if full_trace and then BadCodeCount > 0 then\n Ada.Text_IO.Put_Line(\n \"Found\" & Integer'Image(BadCodeCount) &\n \" bad codes\"\n );\n end if;\n end GIF_Decode;\n\n -- Here we have several specialized instances of GIF_Decode,\n -- with parameters known at compile-time -> optimizing compilers\n -- will do expensive tests about interlacing and transparency at compile-time,\n -- not at run-time.\n --\n procedure GIF_Decode_interlaced_transparent_8 is\n new GIF_Decode(interlaced => True, transparency => True, pixel_mask => 255);\n procedure GIF_Decode_straight_transparent_8 is\n new GIF_Decode(interlaced => False, transparency => True, pixel_mask => 255);\n procedure GIF_Decode_interlaced_opaque_8 is\n new GIF_Decode(interlaced => True, transparency => False, pixel_mask => 255);\n procedure GIF_Decode_straight_opaque_8 is\n new GIF_Decode(interlaced => False, transparency => False, pixel_mask => 255);\n --\n procedure Skip_sub_blocks is\n temp: U8;\n begin\n sub_blocks_sequence:\n loop\n Get_Byte(image.buffer, temp ); -- load sub-block length byte\n Raw_Byte(temp);\n exit sub_blocks_sequence when temp = 0;\n -- null sub-block = end of sub-block sequence\n for i in 1..temp loop\n Get_Byte(image.buffer, temp ); -- load sub-block byte\n Raw_Byte(temp);\n end loop;\n end loop sub_blocks_sequence;\n end Skip_sub_blocks;\n\n temp, temp2, label: U8;\n delay_frame: U16;\n c: Character;\n frame_interlaced: Boolean;\n frame_transparency: Boolean:= False;\n local_palette : Boolean;\n --\n separator : Character ;\n -- Colour information\n new_num_of_colours : Natural;\n pixel_mask : U32;\n BitsPerPixel : Natural;\n\n begin -- Load\n next_frame:= 0.0;\n -- Scan various GIF blocks, until finding an image\n loop\n Get_Byte(image.buffer, temp);\n Raw_Byte(temp);\n separator:= Character'Val(temp);\n if full_trace then\n Ada.Text_IO.Put(\n \"GIF separator [\" & separator &\n \"][\" & U8'Image(temp) & ']'\n );\n end if;\n case separator is\n when ',' => -- 16#2C#\n exit;\n -- Image descriptor will begin\n -- See: 20. Image Descriptor\n when ';' => -- 16#3B#\n if full_trace then\n Ada.Text_IO.Put(\" - End of GIF\");\n end if;\n image.next_frame:= 0.0;\n next_frame:= image.next_frame;\n return; -- End of GIF image\n when '!' => -- 16#21# Extensions\n if full_trace then\n Ada.Text_IO.Put(\" - Extension\");\n end if;\n Get_Byte(image.buffer, label );\n Raw_Byte (label);\n case label is\n when 16#F9# => -- See: 23. Graphic Control Extension\n if full_trace then\n Ada.Text_IO.Put_Line(\" - 16#F9#: Graphic Control Extension\");\n end if;\n Get_Byte(image.buffer, temp );\n Raw_Byte(temp);\n if temp /= 4 then\n Raise_Exception(\n error_in_image_data'Identity,\n \"GIF: error in Graphic Control Extension\"\n );\n end if;\n Get_Byte(image.buffer, temp );\n Raw_Byte(temp);\n -- Reserved 3 Bits\n -- Disposal Method 3 Bits\n -- User Input Flag 1 Bit\n -- Transparent Color Flag 1 Bit\n frame_transparency:= (temp and 1) = 1;\n Read_Intel(image.buffer, delay_frame);\n image.next_frame:=\n image.next_frame + Ada.Calendar.Day_Duration(delay_frame) / 100.0;\n next_frame:= image.next_frame;\n Get_Byte(image.buffer, temp );\n Raw_Byte(temp);\n Transp_color:= Color_type(temp);\n -- zero sub-block:\n Get_Byte(image.buffer, temp );\n Raw_Byte(temp);\n when 16#FE# => -- See: 24. Comment Extension\n if full_trace then\n Ada.Text_IO.Put_Line(\" - 16#FE#: Comment Extension\");\n sub_blocks_sequence:\n loop\n Get_Byte(image.buffer, temp ); -- load sub-block length byte\n Raw_Byte(temp);\n exit sub_blocks_sequence when temp = 0;\n -- null sub-block = end of sub-block sequence\n for i in 1..temp loop\n Get_Byte(image.buffer, temp2);\n Raw_Byte(temp2);\n c:= Character'Val(temp2);\n Ada.Text_IO.Put(c);\n end loop;\n end loop sub_blocks_sequence;\n Ada.Text_IO.New_Line;\n else\n Skip_sub_blocks;\n end if;\n when 16#01# => -- See: 25. Plain Text Extension\n if full_trace then\n Ada.Text_IO.Put_Line(\" - 16#01#: Plain Text Extension\");\n end if;\n Skip_sub_blocks;\n when 16#FF# => -- See: 26. Application Extension\n if full_trace then\n Ada.Text_IO.Put_Line(\" - 16#FF#: Application Extension\");\n end if;\n Skip_sub_blocks;\n when others =>\n if full_trace then\n Ada.Text_IO.Put_Line(\" - Unused extension:\" & U8'Image(label));\n end if;\n Skip_sub_blocks;\n end case;\n when ASCII.NUL =>\n -- Occurs in some buggy GIFs (2016).\n -- Seems a 2nd zero, the 1st marking the end of sub-block list.\n if full_trace then\n Ada.Text_IO.Put_Line(\" - Wrong separator, skip and hope for the better...\");\n end if;\n when others =>\n Raise_Exception(\n error_in_image_data'Identity,\n \"Unknown GIF separator: [\" & separator &\n \"] code:\" & Integer'Image(Character'Pos(separator))\n );\n end case;\n end loop;\n\n -- Load the image descriptor\n Read_Intel(image.buffer, Descriptor.ImageLeft);\n Read_Intel(image.buffer, Descriptor.ImageTop);\n Read_Intel(image.buffer, Descriptor.ImageWidth);\n Read_Intel(image.buffer, Descriptor.ImageHeight);\n Get_Byte(image.buffer, Descriptor.Depth);\n Raw_Byte(Descriptor.Depth);\n\n -- Get image corner coordinates\n tlX := Natural(Descriptor.ImageLeft);\n tlY := Natural(Descriptor.ImageTop);\n brX := tlX + Natural(Descriptor.ImageWidth);\n brY := tlY + Natural(Descriptor.ImageHeight);\n\n -- Local Color Table Flag 1 Bit\n -- Interlace Flag 1 Bit\n -- Sort Flag 1 Bit\n -- Reserved 2 Bits\n -- Size of Local Color Table 3 Bits\n --\n frame_interlaced:= (Descriptor.Depth and 64) = 64;\n local_palette:= (Descriptor.Depth and 128) = 128;\n local.format:= GIF;\n local.stream:= image.stream;\n local.buffer:= image.buffer;\n if local_palette then\n -- Get amount of colours in image\n BitsPerPixel := 1 + Natural(Descriptor.Depth and 7);\n new_num_of_colours:= 2 ** BitsPerPixel;\n -- 21. Local Color Table\n local.palette:= new Color_table(0..new_num_of_colours-1);\n Color_tables.Load_palette(local);\n image.buffer:= local.buffer;\n elsif image.palette = null then\n Raise_Exception(\n error_in_image_data'Identity,\n \"GIF: neither local, nor global palette\"\n );\n else\n -- Use global palette\n new_num_of_colours:= 2 ** image.subformat_id;\n -- usually <= 2** image.bits_per_pixel\n -- Just copy main palette\n local.palette:= new Color_table'(image.palette.all);\n end if;\n pixel_mask:= U32(new_num_of_colours - 1);\n\n if full_trace then\n Ada.Text_IO.Put_Line(\n \" - Image, interlaced: \" & Boolean'Image(frame_interlaced) &\n \"; local palette: \" & Boolean'Image(local_palette) &\n \"; transparency: \" & Boolean'Image(frame_transparency) &\n \"; transparency index:\" & Color_type'Image(Transp_color)\n );\n end if;\n\n -- Get initial code size\n Get_Byte(image.buffer, temp );\n Raw_Byte(temp);\n if Natural(temp) not in Code_size_range then\n Raise_Exception(\n error_in_image_data'Identity,\n \"GIF: wrong LZW code size (must be in 2..12), is\" &\n U8'Image(temp)\n );\n end if;\n CurrSize := Natural(temp);\n\n -- Start at top left of image\n X := Natural(Descriptor.ImageLeft);\n Y := Natural(Descriptor.ImageTop);\n Set_X_Y(X, image.height - Y - 1);\n --\n if new_num_of_colours < 256 then\n -- \"Rare\" formats -> no need of best speed\n declare\n -- We create an instance with dynamic parameters\n procedure GIF_Decode_general is\n new GIF_Decode(frame_interlaced, frame_transparency, pixel_mask);\n begin\n GIF_Decode_general;" + }, + { + "function_def": "procedure Register_Tests (T : in out TC) is", + "function_body": "use AUnit.Test_Cases.Registration;\n begin\n Register_Routine\n (T, Test_One_String'Access, \"One string\");\n Register_Routine\n (T, Test_Two_Strings'Access, \"Two strings\");\n end Register_Tests;\n\n procedure Set_Up (T : in out TC) is\n begin\n T.P.Create (128);\n end Set_Up;\n\n function Name (T : TC) return Message_String is\n pragma Unreferenced (T);\n begin\n return AUnit.Format (\"Chunk tests for String_Pool\");\n end Name;\n\n procedure Test_One_String (T : in out Test_Cases.Test_Case'Class) is\n Test_Data : constant String := \"123456\";\n C : constant Reference := TC (T).P.From_String (Test_Data);\n begin\n Ada.Text_IO.Put_Line (\"Test one string, chunk content:\");\n Ada.Text_IO.Put_Line (TC (T).P.Current_Chunk_As_String);\n Assert (C = Test_Data, \"Data mismatch!\");\n declare\n C2 : constant Reference := C;\n begin\n Ada.Text_IO.Put_Line (\"Range after copy: (\" & C2.Data.all'First'Img &\n \" ..\" & C2.Data.all'Last'Img & ')');" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(String, Buffer_Type);\n\n subtype Line_End is Character with Static_Predicate =>\n Line_End in Line_Feed | Carriage_Return | End_Of_Input;\n\n procedure Init (Object : in out Instance; Input : Source.Pointer;\n Initial_Buffer_Size : Positive :=\n Default_Initial_Buffer_Size) is\n begin\n Object.Internal.Input := Input;\n Object.Buffer := new String (1 .. Initial_Buffer_Size);\n Object.Internal.Sentinel := Initial_Buffer_Size + 1;\n Refill_Buffer (Object);\n end Init;\n\n procedure Init (Object : in out Instance; Input : String) is\n begin\n Object.Internal.Input := null;\n Object.Buffer := new String (1 .. Input'Length + 1);\n Object.Internal.Sentinel := Input'Length + 2;\n Object.Buffer.all := Input & End_Of_Input;\n end Init;\n\n function Next (Object : in out Instance) return Character is\n begin\n return C : constant Character := Object.Buffer (Object.Pos) do\n Object.Pos := Object.Pos + 1;\n end return;\n end Next;\n\n procedure Refill_Buffer (L : in out Instance) is\n Bytes_To_Copy : constant Natural := L.Buffer'Last + 1 - L.Internal.Sentinel;\n Fill_At : Positive := Bytes_To_Copy + 1;\n Bytes_Read : Positive;\n\n function Search_Sentinel return Boolean with Inline is\n Peek : Positive := L.Buffer'Last;\n begin\n while not (L.Buffer (Peek) in Line_End) loop\n if Peek = Fill_At then\n return False;\n else\n Peek := Peek - 1;\n end if;\n end loop;\n L.Internal.Sentinel := Peek + 1;\n return True;\n end Search_Sentinel;\n begin\n if Bytes_To_Copy > 0 then\n L.Buffer (1 .. Bytes_To_Copy) :=\n L.Buffer (L.Internal.Sentinel .. L.Buffer'Last);\n end if;\n loop\n L.Internal.Input.Read_Data\n (L.Buffer (Fill_At .. L.Buffer'Last), Bytes_Read);\n if Bytes_Read < L.Buffer'Last - Fill_At then\n L.Internal.Sentinel := Fill_At + Bytes_Read + 1;\n L.Buffer (L.Internal.Sentinel - 1) := End_Of_Input;\n exit;\n else\n exit when Search_Sentinel;\n Fill_At := L.Buffer'Last + 1;\n declare\n New_Buffer : constant Buffer_Type :=\n new String (1 .. 2 * L.Buffer'Last);\n begin\n New_Buffer.all (L.Buffer'Range) := L.Buffer.all;\n Free (L.Buffer);\n L.Buffer := New_Buffer;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(System.Address, Header_Access);\n use System.Storage_Elements;\n begin\n return Convert (S.all'Address - Storage_Offset (Header_Size));\n end Header_Of;\n\n function Value (Object : Reference) return Accessor is\n (Accessor'(Data => Object.Data, Hold => Object));\n\n function Length (Object : Reference) return Natural is\n (Object.Data'Length);\n\n function \"&\" (Left, Right : Reference) return String is\n (Left.Data.all & Right.Data.all);\n\n function \"&\" (Left : Reference; Right : String) return String is\n (Left.Data.all & Right);\n\n function \"&\" (Left : Reference; Right : Character) return String is\n (Left.Data.all & Right);\n\n function \"&\" (Left : String; Right : Reference) return String is\n (Left & Right.Data.all);\n\n function \"&\" (Left : Character; Right : Reference) return String is\n (Left & Right.Data.all);\n\n function \"=\" (Left, Right : Reference) return Boolean is\n (Left.Data = Right.Data or else\n (Left.Data /= null and then Right.Data /= null and then\n Left.Data.all = Right.Data.all));\n\n function \"=\" (Left : Reference; Right : String) return Boolean is\n (Left.Data.all = Right);\n\n function Hash (Object : Reference) return Ada.Containers.Hash_Type is\n (Ada.Strings.Hash (Object.Data.all));\n\n function \"=\" (Left : String; Right : Reference) return Boolean is\n (Left = Right.Data.all);\n\n function Element (Object : Reference; Position : Positive) return Character\n is (Object.Data (Position));\n\n function Hold (Content : String) return Constant_Instance is\n Ret : Constant_Instance :=\n (Length => Content'Length + Positive (Header_Size) + 1,\n Data => <>);\n H : Header with Import;\n for H'Address use Ret.Data (1)'Address;\n begin\n H.Pool := null;\n H.Refcount := 1;\n H.First := 1;\n H.Last := Content'Length;\n Ret.Data (Positive (Header_Size) + 1 .. Ret.Data'Last) :=\n Content & Character'Val (0);\n return Ret;\n end Hold;\n\n procedure Adjust (Object : in out Reference) is\n begin\n if Object.Data /= null then\n declare\n H : constant access Header := Header_Of (Object.Data);\n begin\n if H.Pool /= null then\n H.Refcount := H.Refcount + 1;\n end if;" + }, + { + "function_def": "procedure Free_Chunk is new Ada.Unchecked_Deallocation", + "function_body": "(Pool_Array, Chunk);\n procedure Free_Data is new Ada.Unchecked_Deallocation\n (Pool_Data, Pool_Data_Access);\n begin\n Pool.Usage (Chunk_Index) := Pool.Usage (Chunk_Index) - 1;\n if Pool.Usage (Chunk_Index) = 0 then\n Free_Chunk (Pool.Chunks (Chunk_Index));\n for I in Chunk_Index_Type loop\n if Pool.Chunks (I) /= null then\n return;\n end if;\n end loop;\n Free_Data (Pool);\n end if;\n end Decrease_Usage;\n\n procedure Finalize (Object : in out Reference) is\n Reference : constant UTF_8_String_Access := Object.Data;\n begin\n Object.Data := null;\n if Reference /= null then\n declare\n H : constant not null access Header := Header_Of (Reference);\n begin\n if H.Pool /= null then\n H.Refcount := H.Refcount - 1;\n if H.Refcount = 0 then\n H.Last := Round_To_Header_Size (H.Last + 1);\n Decrease_Usage (H.Pool, H.Chunk_Index);\n end if;\n end if;" + }, + { + "function_def": "procedure test_Conversion_Type is", + "function_body": "package conversion_float is new Conversion_Type(T_Element => float);\n use conversion_float;\n\n -- Tester la procedure de conversion en entier\n procedure test_To_Integer is\n useless : Integer;\n\n begin\n -- Test avec un entier long\n useless := To_Integer(To_Unbounded_String(\"10000\"));\n pragma assert(useless=10000);\n\n -- Test avec 0\n pragma assert(To_Integer(To_Unbounded_String(\"0\"))=0);\n\n -- Test avec un character\n begin\n useless := To_Integer(To_Unbounded_String(\"z\"));\n pragma assert (False);\n exception\n when Bad_Type_Conversion_Error => pragma assert( True);" + }, + { + "function_def": "procedure test_To_reel is", + "function_body": "useless : float;\n\n begin\n\n -- Test avec un r\u00e9el sur 10 digit\n useless := conversion_float.To_reel(To_Unbounded_String(\"0.85000002384\"));\n pragma assert (useless=float(0.85000002384));\n\n -- Test avec un entier de taille 1\n begin\n useless := conversion_float.To_reel(To_Unbounded_String(\"3\"));\n pragma assert (False);\n exception\n when Bad_Type_Conversion_Error => pragma assert( True);" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E101 := E101 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"ada__strings__unbounded__finalize_spec\");\n begin\n F2;" + }, + { + "function_def": "procedure F3;", + "function_body": "pragma Import (Ada, F3, \"system__storage_pools__subpools__finalize_spec\");\n begin\n F3;" + }, + { + "function_def": "procedure F4;", + "function_body": "pragma Import (Ada, F4, \"system__finalization_masters__finalize_spec\");\n begin\n F4;" + }, + { + "function_def": "procedure F5;", + "function_body": "pragma Import (Ada, F5, \"system__file_io__finalize_body\");\n begin\n E113 := E113 - 1;\n F5;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E070 := E070 + 1;\n Ada.Strings'Elab_Spec;\n E055 := E055 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E057 := E057 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E061 := E061 + 1;\n Interfaces.C'Elab_Spec;\n E045 := E045 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E081 := E081 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E050 := E050 + 1;\n System.Os_Lib'Elab_Body;\n E075 := E075 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E017 := E017 + 1;\n E015 := E015 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E011 := E011 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E105 := E105 + 1;\n Ada.Streams'Elab_Spec;\n E103 := E103 + 1;\n System.File_Control_Block'Elab_Spec;\n E117 := E117 + 1;\n System.Finalization_Root'Elab_Spec;\n E116 := E116 + 1;\n Ada.Finalization'Elab_Spec;\n E114 := E114 + 1;\n System.File_Io'Elab_Body;\n E113 := E113 + 1;\n System.Storage_Pools'Elab_Spec;\n E168 := E168 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E164 := E164 + 1;\n System.Storage_Pools.Subpools'Elab_Spec;\n E162 := E162 + 1;\n Ada.Strings.Unbounded'Elab_Spec;\n E154 := E154 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E101 := E101 + 1;\n System.Assertions'Elab_Spec;\n E184 := E184 + 1;\n E176 := E176 + 1;\n E178 := E178 + 1;\n E180 := E180 + 1;\n E182 := E182 + 1;\n E187 := E187 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_pagerank\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "function puissance_10 (exposant : in Integer) return ultra_precis is", + "function_body": "resultat : ultra_precis;\n Exponant_Too_Big_error : exception;\n begin\n\n if exposant > 16 then -- la pr\u00e9cision du r\u00e9sultat ne serait pas assez bonne !\n raise Exponant_Too_Big_error;\n else\n resultat := ultra_precis(0.1);\n for i in 1..exposant-1 loop\n resultat := ultra_precis(0.1)*resultat;\n end loop;\n return resultat;\n end if;\n end puissance_10;\n\n\n taille_chaine : Integer; -- taille de la chaine de caract\u00e8res rentr\u00e9e\n chaine_partie_entiere : Unbounded_String; -- partie enti\u00e8re du T_Element sous forme d'une chaine\n partie_entiere : Integer; -- partie enti\u00e8re du T_Element\n partie_decimal : T_Element; -- partie d\u00e9cimale du T_Element\n position_virgule : Integer; -- indice de la position occup\u00e9e par la virgule\n virgule_trouvee : Boolean; -- Indique si la chaine comporte bien une virgule\n chaine_partie_decimal : Unbounded_String; -- Chaine repr\u00e9sentant la partie d\u00e9cimale\n taille_partie_decimal : Integer; -- Taille de la chaine\n\n begin\n\n -- Traiter le cas \u00e9vident ou la chaine est trop petite\n taille_chaine := Length(chaine);\n if taille_chaine < 3 then\n raise Bad_Type_Conversion_Error;\n\n -- Essayer de convertir la chaine en T_Element\n else\n\n -- Trouver la place de la virgule\n position_virgule := 1;\n virgule_trouvee := False;\n while not virgule_trouvee loop\n if To_string(chaine)(position_virgule) = '.' then\n virgule_trouvee := True;\n end if;\n position_virgule := position_virgule + 1 ;\n end loop ;\n position_virgule := position_virgule -1; -- la sortie du while se fait avec position + 1\n\n -- Extraire la partie enti\u00e8re du nombre\n for i in 1..position_virgule-1 loop\n chaine_partie_entiere := chaine_partie_entiere & To_string(chaine)(i) ;\n end loop;\n\n -- Convertir la partie enti\u00e8re en T_Element\n partie_entiere := To_Integer(chaine_partie_entiere);\n\n -- Extraire la partie d\u00e9cimale\n chaine_partie_decimal := To_Unbounded_String(To_String(chaine)(position_virgule+1..Taille_chaine));\n taille_partie_decimal := Length(chaine_partie_decimal);\n\n -- Convertir la partie d\u00e9cimale\n if taille_partie_decimal <= 8 then -- cette condition est due au fait que les r\u00e9els <= 10\u2078en ADA\n\n partie_decimal:= T_Element(To_Integer(chaine_partie_decimal));\n partie_decimal := partie_decimal*T_Element(puissance_10(taille_partie_decimal));\n else\n -- D\u00e9couper la partie d\u00e9cimale en deux pour convertir des entiers de plus de 8 digits !\n partie_decimal := T_Element(To_Integer(To_Unbounded_String(To_String(chaine_partie_decimal)(1..8))));\n partie_decimal := partie_decimal*T_Element(puissance_10(8)); -- partie \"gauche\"\n partie_decimal := partie_decimal + T_Element(To_Integer(To_Unbounded_String(To_String(chaine_partie_decimal)(9..taille_partie_decimal))))*T_Element(puissance_10(taille_partie_decimal));\n end if;\n\n\n return partie_decimal + T_Element(partie_entiere);\n end if;\n end To_reel;\n\n\n procedure Integer_or_reel( chaine : in Unbounded_String; reel : out T_Element;\n entier : out Integer; indicateur : out Character) is\n\n begin\n entier:= -1;\n -- D\u00e9terminer si c'est un r\u00e9el\n begin\n reel := To_reel(chaine);\n indicateur := 'f';\n exception\n when Bad_Type_Conversion_Error|CONSTRAINT_ERROR => -- le constraint error apparait si on cherche la virgule dans un r\u00e9el !\n -- D\u00e9terminer si c'est un entier\n begin\n entier := To_Integer(chaine);\n indicateur := 'i';\n exception\n -- D\u00e9terminer si c'est autre choses\n when Bad_Type_Conversion_Error =>indicateur := 'o';" + }, + { + "function_def": "procedure pagerank is", + "function_body": "type T_precision is digits 6; -- type r\u00e9el des coefficients\n\n taille_tableau : constant Integer := 10000; -- \u00e0 adapter selon l'exemple test\u00e9 !\n\n -- Import de tous les paquets n\u00c3\u00a9cessaires\n package Real_IO is new Ada.Text_IO.Float_IO(T_precision); use Real_IO; -- pour afficher les coeffs\n\n package vecteur is new Google_Naive(nombre_max_ligne => 1 , -- pour stocker et traiter PI\n\t\t\t\t nombre_max_colonne => taille_tableau,\n\t\t\t\t T_Element => T_precision);\n\n package tri is new Tri_par_tas(1,taille_tableau ,T_precision,vecteur); -- pour trier\n\n package recup is new Recuperation_Argument(T_alpha => T_precision); -- pour r\u00e9cup\u00e9rer les arguments de la ligne de commande\n\n -- Proc\u00c3\u00a9dures utiles pour le debugage et l'affichage des matrices\n --procedure Afficher_element (nombre : T_precision ) is\n --begin\n -- Put(nombre,1,16);\n --end Afficher_element;\n\n\n\n -- Nom : Creer_vect_occurrence\n -- Semantique : Construire le vecteur avec les occurences de chaque noeud\n -- Param\u00c3\u00a8tres :\n -- noeuds_occurence : out matrice_pleine.T_Google_Naive; -- vecteur occurence\n -- N : in Integer; -- nombre de noeuds\n -- fichier_net : in Ada.Text_IO.File_Type; -- objet fichier pas le nom\n\n -- Pre : True;\n -- Post : trop complexe pour \u00c3\u00aatre exprim\u00c3\u00a9e;\n -- Tests\n -- Entr\u00c3\u00a9e : Sujet; Sortie : [2,0,3,2,2,1]\n -- Exception : Aucune\n procedure Creer_vect_occurence(noeuds_occurence : out vecteur.T_Google_Naive;\n\t\t\t\t N : in Integer;\n\t\t\t\t fichier_net : in Ada.Text_IO.File_Type ) is\n\n entier : Integer; -- coefficient sur la premi\u00c3\u00a8re colonne d'un fichier .net\n useless : Integer; -- coefficient sur la deuxi\u00c3\u00a8me colonne d'un fichier .net\n ancien_coefficient : T_precision; -- occurence \u00c3\u00a0 incr\u00c3\u00a9menter\n\n begin\n -- Initialiser le vecteur \u00c3\u00a0 0\n vecteur.Initialiser(noeuds_occurence,1,N);\n for i in 1..N loop\n\t vecteur.Enregistrer_coefficient(noeuds_occurence,1,i,T_precision(0));\n end loop;\n\n -- Si un noeud apparait une fois on incr\u00c3\u00a9mente l'occurence de ce noeud\n while not end_of_File(fichier_net) loop\n\t Get(fichier_net,entier);\n\t ancien_coefficient := vecteur.Get_coefficient(noeuds_occurence,1,entier+1);\n\t vecteur.Enregistrer_coefficient(noeuds_occurence,1,(entier+1),ancien_coefficient + T_precision(1));\n\t Get(fichier_net,useless);\n end loop;\n\n end Creer_vect_occurence;\n ------------------------------------------------------------------------------------------------------------------------------------IMPLANTATION NAIVE\n -- Nom : pagerank_t\n -- Semantique : Produire le vecteur PI d\u00e9fini dans le sujet avec des matrices pleines\n -- Param\u00c3\u00a8tres :\n -- Nom_fichier_net : in Unbounded_String; -- fichier .net\n -- alpha : in T_precision; -- coefficient de pond\u00c3\u00a9ration\n -- N : in Integer; -- nombre de noeuds\n -- iter_max : in Integer; -- nombre d'iteration\n -- PI : out vecteur.T_Google_Naive; -- cf sujet\n\n -- Pre : True;\n -- Post : trop complexe pour \u00c3\u00aatre exprim\u00c3\u00a9e;\n -- Tests\n -- voir exemple_sujet\n -- Exception : Aucune (\u00e0 part un storage error si le fichier.net est grand, pensez \u00e0 changer la stack size)\n procedure pagerank_t (alpha : in T_precision;\n\t\t\t Nom_fichier_net : in Unbounded_String;\n\t\t\t N : out Integer;\n\t\t\t iter_max : in Integer;\n\t\t\t PI : out vecteur.T_Google_Naive ) is\n\n\n package matrice_pleine is new Google_Naive(nombre_max_ligne => taille_tableau ,\n\t\t\t\t\t\t nombre_max_colonne => taille_tableau,\n\t\t\t\t\t\t T_Element => T_precision);\n\n --procedure Affichage_vecteur is new Matrice_Pleine.Affichage (Afficher=>Afficher_element);\n\n\n\n --procedure Affichage_matrice_pleine is new matrice_pleine.Affichage (Afficher=>Afficher_element);\n\n\n -- Nom : Creer_H\n -- Semantique : Construire la matrice_pleine H d\u00c3\u00a9finie dans le sujet\n -- Param\u00c3\u00a8tres :\n -- Nom_fichier_net : in Unbounded_String; -- nom du fichier.net\n -- H : out matrice_pleine.T_Google_Naive; -- cf sujet\n -- N : in Integer; -- nombre de noeuds\n\n -- Pre : True;\n -- Post : trop complexe pour \u00c3\u00aatre exprim\u00c3\u00a9e;\n -- Tests\n -- voir exemple_sujet\n -- Exception : Aucune\n procedure Creer_H(Nom_fichier_net : in Unbounded_String;\n\t\t\tH : out matrice_pleine.T_Google_Naive;\n\t\t\tN : out Integer) is\n\n\n\t entier : Integer; -- coefficient sur la premi\u00c3\u00a8re colonne d'un fichier .net\n\t fichier_net : Ada.Text_IO.File_Type;\n\t noeuds_occurence : vecteur.T_Google_Naive; -- vecteur avec l'occurence de chaque noeud -\n\t coeff_i : Integer; -- num\u00e9ro de ligne\n\t coeff_j : Integer; -- num\u00c3\u00a9ro de colonne\n\n begin\n\n\t -- Ouvrir le fichier\n\t begin\n\t open(fichier_net, In_File, To_String(Nom_fichier_net));\n\t exception\n\t when ADA.IO_EXCEPTIONS.NAME_ERROR => raise recup.File_Absent_Error;" + }, + { + "function_def": "--procedure Affichage_matrice_creuse is new matrice_creuse.Affichage (Afficher=>Afficher_element);", + "function_body": "-- Nom : Creer_H\n -- Semantique : Construire la matrice_creuse H d\u00c3\u00a9finie dans le sujet\n -- Param\u00c3\u00a8tres :\n -- Nom_fichier : in Unbounded_String; -- nom du fichier .net\n -- H : out matrice_creuse.T_Google_Creuse;\n -- N : in Integer; -- nombre de noeuds\n\n -- Pre : True;\n -- Post : trop complexe pour \u00c3\u00aatre exprim\u00c3\u00a9e;\n -- Tests\n -- voir exemple_sujet\n -- Exception : Aucune\n procedure Creer_H(Nom_fichier_net : in Unbounded_String;\n\t\t\tH : out matrice_creuse.T_Google_Creuse;\n\t\t\tN : out Integer) is\n\n\n\n\t entier : Integer; -- coefficient sur la premi\u00c3\u00a8re colonne d'un fichier .net\n\t fichier_net : Ada.Text_IO.File_Type;\n\t noeuds_occurence : vecteur.T_Google_Naive; -- vecteur avec l'occurence de chaque noeud -- taille de la matrice_creuse\n\t coeff_i : Integer;\n\t coeff_j : Integer; -- num\u00c3\u00a9ro de colonne\n\n begin\n\n\t -- Ouvrir le fichier\n\t begin\n\t open(fichier_net, In_File, To_String(Nom_fichier_net));\n\t exception\n\t when ADA.IO_EXCEPTIONS.NAME_ERROR => raise recup.File_Absent_Error;" + }, + { + "function_def": "procedure test_pagerank is", + "function_body": "type T_Double is digits 6;\n\n package Real_IO is new Ada.Text_IO.Float_IO(T_Double); use Real_IO; -- pour afficher les coeffs\n\n -- Testons sur les matrices du sujet, les tests peuvent se g\u00e9n\u00e9raliser \u00e0 (n x n)\n package matrice_pleine is new Google_Naive(nombre_max_ligne => 6 ,\n nombre_max_colonne => 6,\n T_Element => T_Double);\n\n\n package vecteur is new Google_Naive(nombre_max_ligne => 1 , -- pour stocker et traiter PI\n nombre_max_colonne => 6,\n T_Element => T_Double);\n\n alpha : constant T_Double := T_Double(0.85000002384);\n\n\n procedure Creer_vect_occurence(noeuds_occurence : out vecteur.T_Google_Naive;\n N : in Integer;\n fichier_net : in Ada.Text_IO.File_Type ) is\n\n entier : Integer; -- coefficient sur la premi\u00c3\u00a8re colonne d'un fichier .net\n useless : Integer; -- coefficient sur la deuxi\u00c3\u00a8me colonne d'un fichier .net\n ancien_coefficient : T_Double; -- occurence \u00c3\u00a0 incr\u00c3\u00a9menter\n\n begin\n -- Initialiser le vecteur \u00c3\u00a0 0\n vecteur.Initialiser(noeuds_occurence,1,N);\n for i in 1..N loop\n vecteur.Enregistrer_coefficient(noeuds_occurence,1,i,T_Double(0));\n end loop;\n\n -- Si un noeud apparait une fois on incr\u00c3\u00a9mente l'occurence de ce noeud\n while not end_of_File(fichier_net) loop\n Get(fichier_net,entier);\n ancien_coefficient := vecteur.Get_coefficient(noeuds_occurence,1,entier+1);\n vecteur.Enregistrer_coefficient(noeuds_occurence,1,(entier+1),ancien_coefficient + T_Double(1));\n Get(fichier_net,useless);\n end loop;\n\n end Creer_vect_occurence;\n\n -------------------------------Les sous-programmes de pagerank n'\u00e9tant pas accessible nous n'avons d'autres solutions que de les copier ici : \n\n\t\n procedure Creer_H(Nom_fichier_net : in Unbounded_String;\n H : out matrice_pleine.T_Google_Naive;\n N : out Integer) is\n\n\n entier : Integer; -- coefficient sur la premi\u00c3\u00a8re colonne d'un fichier .net\n fichier_net : Ada.Text_IO.File_Type;\n noeuds_occurence : vecteur.T_Google_Naive; -- vecteur avec l'occurence de chaque noeud -\n coeff_i : Integer; -- num\u00e9ro de ligne\n coeff_j : Integer; -- num\u00c3\u00a9ro de colonne\n\n File_Absent_Error : exception;\n begin\n\n -- Ouvrir le fichier\n begin\n open(fichier_net, In_File, To_String(Nom_fichier_net));\n exception\n when ADA.IO_EXCEPTIONS.NAME_ERROR => raise File_Absent_Error;" + }, + { + "function_def": "procedure Command_Line_Vectorisee(vect_arg : out vecteur) is", + "function_body": "N : Integer;\n begin\n N := Argument_Count;\n vect_arg.taille := N;\n\n for i in 1..N loop\n vect_arg.tableau(i) := To_Unbounded_String(Argument(i));\n end loop;\n\n end Command_Line_Vectorisee;\n\n -- Nom : Afficher_erreur\n -- s\u00e9mantique : Afficher un message d'erreur et lever une exception pour aider l'utilisateur selon le code rentr\u00e9\n -- param\u00e8tres :\n -- nombre : in Integer; -- code d'erreur\n -- Pre : True\n -- Post : True\n -- Tests :\n -- Entr\u00e9e : 1 ; Sortie : \"Le format autoris\u00e9 est : -P -I [integer] -A [T_alpha] filename.net\"\n --\n -- \"L'exception et le message ci-dessous devraient vous aider ;)\");\n -- \" Option inconnue \"\n -- raised RECUPERATION_ARGUMENT.INVALID_NAME_OPTION_ERROR : recuperation_argument.adb:112\n\n -- Exception : voir les exceptions ci-dessous\n procedure Afficher_erreur (nombre : in Integer ) is\n\n begin\n\n -- Afficher un message pr\u00e9cisant le format\n New_line;\n Put(\"Le format autoris\u00e9 est : -P -I [integer] -A [T_alpha] filename.net\");\n New_Line;\n New_line;\n Put(\"L'exception et le message ci-dessous devraient vous aider ;)\");\n New_Line;\n New_line;\n\n -- Afficher un message plus pr\u00e9cis sur la cause de l'erreur\n case nombre is\n\n when 1\n =>Put(\"Option inconnue\");\n raise Invalid_Name_Option_Error;\n\n when 2\n => Put(\" Veuillez r\u00e9esayer avec des valeurs valides pour les options\");\n raise Invalid_Type_Arguments_Error;\n when 3\n => Put(\"Trop d'arguments !\");\n raise Too_Many_Argument_Error;\n\n when 4\n => Put( \"Vous avez oubli\u00e9 de pr\u00e9ciser les options !\");\n raise Missing_Options_Error;\n when 5\n => Put(\"Essayez avec un nom de fichier valide\");\n raise File_Absent_Error;\n\n when 6\n => Put(\"il manque une valeur d'option\");\n raise Missing_Arguments_Value_Error;\n\n when 7\n => Put( \"Vous avez oubli\u00e9 de pr\u00e9ciser le fichier\");\n raise File_Absent_Error;\n\n when 8\n => Put(\"Pensez \u00e0 rentrer un nom de fichier correct en .net\");\n raise File_Absent_Error;\n\n when others => NUll;\n end case;\n end Afficher_erreur;\n\n\n -- Nom : Is_number_Arguments_Correct\n -- s\u00e9mantique : V\u00e9rifier qu'il n'y a aucune erreur sur le nombre d'arguments\n -- param\u00e8tres :\n -- N : in Integer; -- nombre d'arguments\n -- nb_max_argument : in Integer; -- nombre max th\u00e9orique d'arguments\n -- Nom_fichier : out Unbounded_String; -- nom \u00e9ventellement r\u00e9cup\u00e9r\u00e9 du fichier\n -- nb_correct_argument : out Boolean; -- le nombre d'argument \u00e9tait correct ?\n -- Pre : True\n -- Post : le nom de fichier finit en .net\n -- Tests :\n -- Entr\u00e9e : N = 7, nb_max_argument = 6 ; Sortie : Too_Many_Arguments\n -- Entr\u00e9e : N = 5, nb_max_argument = 6 ; Sortie nb_correct_argument = True et potentiellement Nom_fichier =... .net\n\n -- Exception : File_Absent_Error; Too_Many_Argument_Error\n procedure Is_number_Arguments_Correct ( N : in Integer;\n nb_max_argument : in Integer;\n Nom_fichier : out Unbounded_String;\n nb_correct_argument: out Boolean ) is\n begin\n\n\n if N = 0 then -- Aucun argument rentr\u00e9 !\n\n Afficher_erreur(7);\n\n elsif N = 1 then\n\n -- V\u00e9rifier que c'est bien le fichier qui a \u00e9t\u00e9 rentr\u00e9 comme argument unique\n\n if Is_file_name(To_Unbounded_String(Argument(1))) then\n Nom_fichier := To_Unbounded_String(Argument(1));\n nb_correct_argument := False; -- ne plus chercher \u00e0 r\u00e9cup\u00e9rer d'autres arguments\n else\n Afficher_erreur(8);\n end if;\n\n elsif N > nb_max_argument then -- trop d'argument\n Afficher_erreur(3);\n\n else\n nb_correct_argument := True;\n end if;\n\n end Is_number_Arguments_Correct;\n\n\n -- Nom : recuperer_chaque_option\n -- s\u00e9mantique : R\u00e9cup\u00e9rer les valeurs des options I, A, P et le nom de fichier\n -- param\u00e8tres :\n -- N N : in Integer;\n -- vect_arg : in vecteur;\n -- iteration : out Integer;\n -- alpha : out T_alpha;\n -- naive :out Boolean;\n -- Nom_fichier : out Unbounded_String ;\n\n -- Pre : True\n -- Post : le nom de fichier finit en .net, alpha > 1 and alpha < 0 and iteration > 1\n\n -- Tests : Aucun\n -- Exception : voir sous-programme afficher_erreur pour la liste exhaustive\n procedure recuperer_chaque_option (N : in Integer;\n vect_arg : in vecteur;\n iteration : in out Integer;\n alpha : in out T_alpha;\n naive : in out Boolean;\n Nom_fichier : out Unbounded_String) is\n\n -- Nom : detecter_option\n -- s\u00e9mantique : Marquer la lecture d'une option par un indicateur nomm\u00e9 option\n -- param\u00e8tres :\n -- vect_arg : in vecteur; -- vecteur des arguments\n -- option : in out Character;\n -- i : in Integer; -- iteration courante\n -- type de retour : Character;\n\n -- Pre : True\n -- Post : detecter_option'Result = 'o' or detecter_option'Result = 'I' or detecter_option'Result = 'P'\n -- or detecter_option'Result = 'A'\n\n -- Tests : Aucun\n -- Exception : voir sous-programme afficher_erreur avec code d'erreur 2, 1 et 6\n procedure detecter_option(vect_arg : in vecteur;i : in Integer; option : in out Character) is\n\n begin\n\n -- Y a-t-il une option valide ?\n if length(vect_arg.tableau(i)) /=2 then\n Afficher_erreur(2);\n else\n if option = 'o' then\n\n -- V\u00e9rifier qu'une option est possible\n case To_String(vect_arg.tableau(i))(2) is\n when 'I' => option := 'I';\n when 'A' => option :='A';\n when 'P' =>\n option := 'o';\n naive := True;\n when others => Afficher_erreur(1);\n\n end case;\n else\n Afficher_erreur(6);\n end if;\n end if;\n end detecter_option;\n\n\n -- Nom : Rentrer_alpha\n -- s\u00e9mantique : Obtenir un alpha compatible\n -- param\u00e8tres :\n -- alpha : out T_alpha;\n -- nombre_reel : in T_alpha; -- valeur potentielle de alpha\n -- indicateur_type : in Character; -- type de l'argument courant\n -- option : in Character; -- option rencontr\u00e9e ?\n -- Pre : True\n -- Post : alpha > T_alpha(1) and alpha < T_alpha(0) and option = 'o'\n\n -- Tests : Aucun\n -- Exception : voir sous-programme afficher_erreur avec code d'erreur 2 et 1\n procedure Rentrer_alpha(alpha : in out T_alpha;\n nombre_reel : in T_alpha;\n indicateur_type : in Character;\n option : in out Character) is\n\n begin\n\n if indicateur_type /= 'f' then -- erreur sur le type de alpha\n Afficher_erreur(2);\n else\n alpha := nombre_reel;\n\n -- Demander une saisie robuste entre 0 et 1\n while alpha > T_alpha(1) or alpha < T_alpha(0) loop\n begin\n -- Donner la consigne\n Put(\" Alpha doit \u00eatre compris entre 1 et 0 svp : \");\n Real_IO.Get(alpha);\n Skip_Line;\n exception\n when ADA.IO_EXCEPTIONS.DATA_ERROR => Skip_Line; -- SI l'utilisateur ne rentre m\u00eame pas un r\u00e9el !" + }, + { + "function_def": "function histEQUAL(img: in imge; hist: in histogram) return imge is", + "function_body": "equalimg : imge;\n cumsum : array (1..256) of float;\nbegin\n -- calculate the cumulative sum of the histogram values\n for i in 1..256 loop\n if i = 1 then\n cumsum(i) := float(hist.count(i));\n else\n cumsum(i) := cumsum(i-1) + float(hist.count(i));\n end if;\n end loop;\n\n -- normalize the cumulative sum by dividing by the total number of pixels\n -- then multiply by the maximum grayscale value (i.e., 255)\n for i in 1..256 loop\n cumsum(i) := 255.0 * cumsum(i) / (float(img.dx) * float(img.dy));\n end loop;\n\n -- map the original values to the results of the array above to calculate histogram equalization\n for i in 1..img.dx loop\n for j in 1..img.dy loop\n equalimg.pixel(i,j) := integer(cumsum(img.pixel(i,j)));\n end loop;\n end loop;\n\n return equalimg;" + }, + { + "function_def": "procedure Main is", + "function_body": "pragma Suppress(All_Checks);\n\n\tMatrix_Size : constant := 3200;\n\ttype Matrix_Range is range 0 .. Matrix_Size - 1;\n\tBound_High, Bound_Low : Matrix_Range;\n\n\ttype Pile is range 0..7 with Size=>8;\n\ttype Pile_Pointer is access all Pile;\n\n\ttype Generic_Matrix_Row is array (Matrix_Range range <>) of aliased Pile with Pack;\n\tsubtype Matrix_Row is Generic_Matrix_Row(Matrix_Range);\n\tsubtype Matrix_Sub_Row is Generic_Matrix_Row(0..7);\n\ttype Matrix is array (Matrix_Range) of Matrix_Row with Pack;\n\ttype Matrix_Pointer is access all Matrix;\n\n\ttype m128i is array (0 .. 15) of Pile with Pack, Alignment=>16;\n\tpragma Machine_Attribute (m128i, \"vector_type\");\n\tpragma Machine_Attribute (m128i, \"may_alias\");\n\n----------------------------------------------------------------------\n\n\tfunction ia32_Add (X, Y : m128i) return m128i with Inline;\n\tpragma Import (Intrinsic, ia32_Add, \"__builtin_ia32_paddb128\");\n\tfunction ia32_Load (X : Pile_Pointer) return m128i with Inline;\n\tpragma Import (Intrinsic, ia32_Load, \"__builtin_ia32_loaddqu\");\n\tprocedure ia32_Store (X : Pile_Pointer; Y : m128i) with Inline;\n\tpragma Import (Intrinsic, ia32_Store, \"__builtin_ia32_storedqu\");\n\n\tprocedure Print (Map : in Matrix; Name : in String) is\n\tbegin\n\t\tPut_Line(Name);\n\t\tfor I in Bound_Low .. Bound_High loop\n\t\t\tfor J in Bound_Low .. Bound_High loop\n\t\t\t\tPut(Pile'Image(Map(I)(J)));\n\t\t\tend loop;\n\t\t\tNew_Line(1);\n\t\tend loop;\n\t\tPut_Line(\"------------\");" + }, + { + "function_def": "function Move is new Ada.Unchecked_Conversion (Source=>Mod_64, Target=>Matrix_Sub_Row);", + "function_body": "function Move is new Ada.Unchecked_Conversion (Source=>Matrix_Sub_Row, Target=>Mod_64);\n\n\t\tChanged : Boolean := False;\n\t\tLocal_Bound_High : constant Matrix_Range := Bound_High;\n\t\tLocal_Bound_Low : constant Matrix_Range := Bound_Low;\n\t\tI : Matrix_Range := Bound_Low;\n\t\tTemp_Values : Mod_64_Array;\n\n\tbegin\n\t\twhile I <= Local_Bound_High loop\n\t\t\tdeclare\n\t\t\t\tJ : Matrix_Range := Local_Bound_Low - (Local_Bound_Low mod 16);\n\t\t\t\tTemp : m128i;\n\t\t\t\tSum_m128i_Buffer : m128i;\n\t\t\t\tUpper_Sum_m128i_Buffer : m128i;\n\t\t\t\tLower_Sum_m128i_Buffer : m128i;\n\t\t\tbegin\n\t\t\t\twhile J <= Local_Bound_High loop\n\t\t\t\t\tTemp_Values(0) := (Move(Base(I)(J..J+7)) / 2**2) AND 16#0F0F0F0F0F0F0F0F#;\n\t\t\t\t\tTemp_Values(1) := (Move(Base(I)(J+8..J+15)) / 2**2) AND 16#0F0F0F0F0F0F0F0F#;\n\n\t\t\t\t\tif (Temp_Values(0) OR Temp_Values(1)) /= 0 then\n\t\t\t\t\t\tChanged := True;\n\t\t\t\t\t\tif I - 1 < Bound_Low then\n\t\t\t\t\t\t\tBound_Low := Bound_Low - 1;\n\t\t\t\t\t\t\tBound_High := Bound_High + 1;\n\t\t\t\t\t\tend if;\n\t\t\t\t\t\tTemp := ia32_Load(Temp_Values(0)'Access);\n\n\t\t\t\t\t\tUpper_Sum_m128i_Buffer := ia32_Load(Base(I-1)(J)'Access);\n\t\t\t\t\t\tia32_Store(Base(I-1)(J)'Access, ia32_Add(Upper_Sum_m128i_Buffer, Temp));\n\n\t\t\t\t\t\tLower_Sum_m128i_Buffer := ia32_Load(Base(I+1)(J)'Access);\n\t\t\t\t\t\tia32_Store(Base(I+1)(J)'Access, ia32_Add(Lower_Sum_m128i_Buffer, Temp));\n\n\t\t\t\t\t\tSum_m128i_Buffer := ia32_Load(Base(I)(J-1)'Access);\n\t\t\t\t\t\tia32_Store(Base(I)(J-1)'Access, ia32_Add(Sum_m128i_Buffer, Temp));\n\n\t\t\t\t\t\tSum_m128i_Buffer := ia32_Load(Base(I)(J+1)'Access);\n\t\t\t\t\t\tia32_Store(Base(I)(J+1)'Access, ia32_Add(Sum_m128i_Buffer, Temp));\n\n\t\t\t\t\t\tBase(I)(J..J+7) := Move(Move(Base(I)(J..J+7)) - (Temp_Values(0) * 4));\n\t\t\t\t\t\tBase(I)(J+8..J+15) := Move(Move(Base(I)(J+8..J+15)) - (Temp_Values(1) * 4));\n\t\t\t\t\tend if;\n\n\t\t\t\t\tJ := J + 16;\n\t\t\t\tend loop;" + }, + { + "function_def": "procedure Update_Rates is", + "function_body": "Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;\n begin\n if Deadline < Now then\n declare\n Dt : constant Ada.Real_Time.Time_Span := Now - Prev_Time;\n MS : constant Integer := Dt / ONE_MS;\n begin\n EtherScope.Analyzer.Ethernet.Update_Rates (Ethernet, Prev_Ethernet, MS);\n EtherScope.Analyzer.IPv4.Update_Rates (IPv4, Prev_IPv4, MS);\n EtherScope.Analyzer.IGMP.Update_Rates (IGMP_Groups, Prev_Groups, MS);\n EtherScope.Analyzer.TCP.Update_Rates (TCP_Ports, Prev_TCP, MS);\n Prev_Time := Now;\n Deadline := Deadline + Ada.Real_Time.Seconds (1);" + }, + { + "function_def": "procedure Initialize is", + "function_body": "begin\n STM32.Board.Display.Initialize;\n STM32.Board.Display.Initialize_Layer (1, HAL.Bitmap.ARGB_1555);\n\n -- Initialize touch panel\n STM32.Board.Touch_Panel.Initialize;\n\n for I in Graphs'Range loop\n EtherScope.Display.Use_Graph.Initialize (Graphs (I),\n X => 100,\n Y => 200,\n Width => 380,\n Height => 72,\n Rate => Ada.Real_Time.Milliseconds (1000));\n end loop;\n end Initialize;\n\n -- ------------------------------\n -- Draw the layout presentation frame.\n -- ------------------------------\n procedure Draw_Frame (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class) is\n begin\n Buffer.Set_Source (UI.Texts.Background);\n Buffer.Fill;\n Draw_Buttons (Buffer);\n Buffer.Set_Source (Line_Color);\n Buffer.Draw_Vertical_Line (Pt => (98, 0),\n Height => Buffer.Height);\n end Draw_Frame;\n\n -- ------------------------------\n -- Draw the display buttons.\n -- ------------------------------\n procedure Draw_Buttons (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class) is\n begin\n UI.Buttons.Draw_Buttons (Buffer => Buffer,\n List => Buttons,\n X => 0,\n Y => 0,\n Width => 95,\n Height => 34);\n end Draw_Buttons;\n\n -- ------------------------------\n -- Refresh the graph and draw it.\n -- ------------------------------\n procedure Refresh_Graphs (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class;\n Graph_Mode : in EtherScope.Stats.Graph_Kind) is\n Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;\n Samples : EtherScope.Stats.Graph_Samples;\n begin\n EtherScope.Analyzer.Base.Update_Graph_Samples (Samples, True);\n for I in Samples'Range loop\n Use_Graph.Add_Sample (Graphs (I), Samples (I), Now);\n end loop;\n Use_Graph.Draw (Buffer, Graphs (Graph_Mode));\n end Refresh_Graphs;\n\n -- ------------------------------\n -- Display devices found on the network.\n -- ------------------------------\n procedure Display_Devices (Buffer : in out HAL.Bitmap.Bitmap_Buffer'Class) is\n use EtherScope.Analyzer.Base;\n\n Y : Natural := 15;\n begin\n EtherScope.Analyzer.Base.Get_Devices (Devices);\n Buffer.Set_Source (UI.Texts.Background);\n Buffer.Fill_Rect (Area => (Position => (100, 0),\n Width => Buffer.Width - 100,\n Height => Buffer.Height));\n for I in 1 .. Devices.Count loop\n declare\n Ethernet : EtherScope.Analyzer.Ethernet.Device_Stats renames Devices.Ethernet (I);\n IP : EtherScope.Analyzer.IPv4.Device_Stats renames Devices.IPv4 (I);\n begin\n UI.Texts.Draw_String (Buffer, (100, Y), 200, Net.Utils.To_String (Ethernet.Mac));\n UI.Texts.Draw_String (Buffer, (300, Y), 150, Net.Utils.To_String (IP.Ip), RIGHT);\n UI.Texts.Draw_String (Buffer, (100, Y + 20), 100, Format_Packets (Ethernet.Stats.Packets), RIGHT);\n UI.Texts.Draw_String (Buffer, (200, Y + 20), 200, Format_Bytes (Ethernet.Stats.Bytes), RIGHT);\n UI.Texts.Draw_String (Buffer, (400, Y + 20), 80, Format_Bandwidth (Ethernet.Stats.Bandwidth));" + }, + { + "function_def": "procedure Lab6 is", + "function_body": "Input, Output : File_Type;\n\tI: Integer;\n\tWasLastTab: Integer;\n\tWasLastSpace: Integer;\n\tTmpStr: Unbounded_String;\n\n\tbegin\n\n\t\tOpen (File => Input, Mode => In_File, Name => \"REG.BIN\");\n\t\t\n\t\tCreate (File => Output, Mode => Out_File, Name => \"output.txt\");\n\n\n\t\t\t-- Denna loop loopar igenom filen rad f\u00f6r rad\n\t\t\tloop\n\t\t\t\tdeclare\n\t\t\t\t\t-- Deklarera en variabel som h\u00e5ller varje rad i minnet varje g\u00e5ng loopen k\u00f6rs\n\t\t\t\t\tInputLine : String := Get_Line (Input);\n\n\t\t\t\tbegin\n\t\t\t\t\tI := 0;\n\t\t\t\t\tWasLastTab := 0;\n\t\t\t\t\tWasLastSpace := 0;\n\t\t\t\t\tTmpStr := To_Unbounded_String(\"\");\n\n\t\t\t\t\t-- Loopa igenom varje tecken p\u00e5 raden och h\u00e4mta ut varje element n\u00e4r flera mellanrum kommer i f\u00f6ljd\n\n\t\t\t\t\tPut(\"---------------------------------------------\"); New_Line;\n\n\t\t\t\t\tfor I in 1..InputLine'Last loop\n\t\t\t\t\t\t-- Kolla om tecknet \u00e4r mellanslag\n\t\t\t\t\t\t--Put(InputLine(I));\n\t\t\t\t\t\t--Put(\" > \");\n\t\t\t\t\t\t--Put( Character'Pos(InputLine(I)) );\n\t\t\t\t\t\t--New_Line;\n\n\t\t\t\t\t\tif(Character'Pos(InputLine(I)) = 32) then\n\t\t\t\t\t\t\t-- Tecknet var mellanrum!\n\n\t\t\t\t\t\t\t-- Kolla om n\u00e4sta tecknen ocks\u00e5 \u00e4r mellanrum\n\t\t\t\t\t\t\tif(Character'Pos(InputLine(I+1)) = 32) then\n\t\t\t\t\t\t\t\t-- Vi ska avsluta elementet!\n\t\t\t\t\t\t\t\tWasLastTab := 1;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t-- N\u00e4sta tecken var inte ett mellanrum\n\t\t\t\t\t\t\t\t-- Kolla s\u00e5 att f\u00f6reg\u00e5ende tecknen inte var ett mellanrum\n\t\t\t\t\t\t\t\tif(Character'Pos(InputLine(I-1)) /= 32) then\n\t\t\t\t\t\t\t\t\t-- Endast ett mellanrum, del av elementet!\n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \" \");\n\t\t\t\t\t\t\t\t\t--Put(\"SPACE\"); New_Line;\n\t\t\t\t\t\t\t\telse \n\t\t\t\t\t\t\t\t-- F\u00f6reg\u00e5ende tecken var ett mellanrum, avsluta elementet!\n\t\t\t\t\t\t\t\t\tNew_Line;\n\t\t\t\t\t\t\t\t\tPut(\"|\");\n\t\t\t\t\t\t\t\t\tPut(TmpStr);\n\t\t\t\t\t\t\t\t\tPut(\"|\");\n\t\t\t\t\t\t\t\t\tNew_Line;New_Line;\n\t\t\t\t\t\t\t\t\t--Put(\"_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\");\n\t\t\t\t\t\t\t\t\t-- T\u00f6m elementet\n\t\t\t\t\t\t\t\t\tTmpStr := To_Unbounded_String(\"\");\n\t\t\t\t\t\t\t\t\t----New_Line;\n\t\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tWasLastTab := 0;\n\t\t\t\t\t\t\t-- Put( String(I) );\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\tcase Character'Pos(InputLine(I)) is\n\t\t\t\t\t\t\t\twhen 0..32 => null; Put(\"->\"); Put( Character'Pos(InputLine(I)) ); New_Line;\n\t\t\t\t\t\t\t\twhen 196 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00c4\"); Put( \"\u00c4\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen 197 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00c5\"); Put( \"\u00c5\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen 214 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00d6\"); Put( \"\u00d6\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen 228 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00e4\"); Put( \"\u00e4\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen 229 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00e5\"); Put( \"\u00e5\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen 246 => \n\t\t\t\t\t\t\t\t\tAppend(TmpStr, \"\u00e5\"); Put( \"\u00e5\" ); Put(\" === \"); Put( Character'Pos( InputLine(I) ) ); New_Line;\n\t\t\t\t\t\t\t\twhen others =>\t\t\n\t\t\t\t\t\t\t\t\tAppend(TmpStr, InputLine(I));\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t--Put( InputLine(I) );\n\t\t\t\t\t\t\t\t\t--Put(\" === \");\n\t\t\t\t\t\t\t\t\t--Put( Character'Pos( InputLine(I) ) );\n\t\t\t\t\t\t\t\t\t--New_Line;\n\t\t\t\t\t\t\t\tend case;\n\t\t\t\t\t\tend if;\n\t\t\t\t\tend loop;\n\n\t\t\t\t\t-- Put_Line (Output, Line);\n\t\t\t\t\t\n\n\t\t\t\t\t--Put(Line);\n\t\t\t\t\t--Skip_Line;" + }, + { + "function_def": "procedure Lab4e is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n\tprocedure Sort(Arrayen_Med_Talen: in out Dates) is\n\t\tprocedure Swap(Tal_1,Tal_2: in out Date_Type) is \n Tal_B : Date_Type; -- Temporary buffer\n begin\n Tal_B := Tal_1;\n Tal_1 := Tal_2;\n Tal_2 := Tal_B;\n \n -- DEBUG New_Line; Put(\"SWAP IS RUNNING! INDEXES INPUT: \"); Put(Tal_1); Put(\"+\"); Put(Tal_2); New_Line;\n end Swap;\n Minsta_Talet: Date_Type;\n Minsta_Talet_Index: Integer;\n begin\n --Minsta_Talet.Year := 0;\n\t\t --Minsta_Talet.Month := 0;\n\t\t --Minsta_Talet.Day := 0;\n \n-- -- Loopa antalet g\u00e5nger som arrayens l\u00e4ngd\n for IOuter in Arrayen_Med_Talen'Range loop\n-- \t -- DEBUG Put(\"> \"); Put(IOuter); Put(\" <\"); New_Line;\n--\t -- Loopa arrayen med start fr\u00e5n yttra loopens v\u00e4rde varje g\u00e5ng. 1..20, 2..20, ... , 20..20\n for I in IOuter..Arrayen_Med_Talen'Last loop\n--\t --DEBUG Put(\">>>\"); Put(I); New_Line;\n\t if I = IOuter or Arrayen_Med_Talen(I) < Minsta_Talet then\n\t Minsta_Talet := Arrayen_Med_Talen(I);\n\t Minsta_Talet_Index := I;\n\t end if;\n end loop;\n--\t \n\t Swap(Arrayen_Med_Talen(IOuter), Arrayen_Med_Talen(Minsta_Talet_Index));\n--\t --DEBUG New_Line; Put(\"Vi swappar \"); Put(Iouter); Put(\" och \"); Put(Minsta_Talet_Index); New_Line;\n end loop;\n\tend Sort;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Lab4a is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Lab4 is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n\tprocedure Sort(Arrayen_Med_Talen: in out Dates) is\n\t\tprocedure Swap(Tal_1,Tal_2: in out Date_Type) is \n Tal_B : Date_Type; -- Temporary buffer\n begin\n Tal_B := Tal_1;\n Tal_1 := Tal_2;\n Tal_2 := Tal_B;\n \n -- DEBUG New_Line; Put(\"SWAP IS RUNNING! INDEXES INPUT: \"); Put(Tal_1); Put(\"+\"); Put(Tal_2); New_Line;\n end Swap;\n Minsta_Talet: Date_Type;\n Minsta_Talet_Index: Integer;\n begin\n --Minsta_Talet.Year := 0;\n\t\t --Minsta_Talet.Month := 0;\n\t\t --Minsta_Talet.Day := 0;\n \n-- -- Loopa antalet g\u00e5nger som arrayens l\u00e4ngd\n for IOuter in Arrayen_Med_Talen'Range loop\n-- \t -- DEBUG Put(\"> \"); Put(IOuter); Put(\" <\"); New_Line;\n--\t -- Loopa arrayen med start fr\u00e5n yttra loopens v\u00e4rde varje g\u00e5ng. 1..20, 2..20, ... , 20..20\n for I in IOuter..Arrayen_Med_Talen'Last loop\n--\t --DEBUG Put(\">>>\"); Put(I); New_Line;\n\t if I = IOuter or Arrayen_Med_Talen(I) < Minsta_Talet then\n\t Minsta_Talet := Arrayen_Med_Talen(I);\n\t Minsta_Talet_Index := I;\n\t end if;\n end loop;\n--\t \n\t Swap(Arrayen_Med_Talen(IOuter), Arrayen_Med_Talen(Minsta_Talet_Index));\n--\t --DEBUG New_Line; Put(\"Vi swappar \"); Put(Iouter); Put(\" och \"); Put(Minsta_Talet_Index); New_Line;\n end loop;\n\tend Sort;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Lab4d is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Lab4fg is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n procedure Sort(Arrayen_Med_Talen: in out Dates) is\n\t\tprocedure Swap(Tal_1,Tal_2: in out Date_Type) is \n Tal_B : Date_Type; -- Temporary buffer\n begin\n Tal_B := Tal_1;\n Tal_1 := Tal_2;\n Tal_2 := Tal_B;\n end Swap;\n Minsta_Talet: Date_Type;\n Minsta_Talet_Index: Integer;\n begin\n \n\t\t -- Loopa antalet g\u00e5nger som arrayens l\u00e4ngd\n for IOuter in Arrayen_Med_Talen'Range loop\n\t\t -- Loopa arrayen med start fr\u00e5n yttra loopens v\u00e4rde varje g\u00e5ng. 1..20, 2..20, ... , 20..20\n for I in IOuter..Arrayen_Med_Talen'Last loop\n\n\t if I = IOuter or Arrayen_Med_Talen(I) < Minsta_Talet then\n\t Minsta_Talet := Arrayen_Med_Talen(I);\n\t Minsta_Talet_Index := I;\n\t end if;\n\n end loop;\n\n\t\t\tSwap(Arrayen_Med_Talen(IOuter), Arrayen_Med_Talen(Minsta_Talet_Index));\n end loop;\n\tend Sort;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Lab4b is", + "function_body": "type Dates is array (1..10) of Date_Type;\n\n\tprocedure Test_Get(Date: out Date_Type) is\n\t\tbegin\n\t\t\tloop\n\t\t\t\tbegin\n\t\t\t\t\tGet(Date);\n\t\t\t\t\texit;\n\t\t\t\texception\n\t\t\t\t\twhen YEAR_ERROR => Put_Line(\"FEL: YEAR_ERROR\");\n\t\t\t\t\twhen MONTH_ERROR => Put_Line(\"FEL: MONTH_ERROR\");\n\t\t\t\t\twhen DAY_ERROR => Put_Line(\"FEL: DAY_ERROR\");\n\t\t\t\t\twhen FORMAT_ERROR => Put_Line(\"FEL: FORMAT_ERROR\");" + }, + { + "function_def": "procedure Upg1 is", + "function_body": "procedure Print(A, B: in Integer) is\n \n Spaces: Integer;\n begin\n if A < B then\n\t Spaces := (B - A) * 4;\n\t for I in 1..Spaces loop\n\t Put(' ');\n\t end loop;\n end if;\n for X in 1..A loop\n\t Put(B,1); Put(' ');\n\t if A = X then\n\t Put(\"= \"); Put(A * B, 1);\n\t else\n\t Put(\"+ \");\n\t end if;\n\t\n end loop;\n New_Line;" + }, + { + "function_def": "procedure Upg4 is", + "function_body": "type Ints is\n array(1..10) of Integer;\n type Arrs is\n array(1..20) of Ints;\n \n procedure Extract(Data: out Arrs) is \n File : File_Type;\n begin\n Open(File, In_File, \"NUMMER.TXT\");\n for X in Data'Range loop\t \n\t for I in Ints'Range loop\n\t Get(File, Data(X)(I));\n\t end loop;\t \n end loop;\n Close(File);" + }, + { + "function_def": "procedure Upg3 is", + "function_body": "function Count\n return Integer is\n S : String(1..3);\n C : Character;\n A, B : Integer;\n begin\n Get(S);\n Get(A);\n Get(C); Get(C);\n Get(B);\n return (B - A + 1);" + }, + { + "function_def": "procedure Upg2 is", + "function_body": "function Generate\n return Integer is\n subtype Nums is Integer range 0..99;\n package RN is\n\t new Ada.Numerics.Discrete_Random(Nums);\n Gen : RN.Generator;\n begin\n RN.Reset(Gen);\n return RN.Random(Gen);" + }, + { + "function_def": "procedure Upg3 is", + "function_body": "Syl_Arr : constant array(1..100) of String(1..4) := (\n \"ach \", \"tun \", \"ep \", \"tur \", \"tash\",\n \"ine \", \"me \", \"arr \", \"et \", \"ze \",\n \"cre \", \"uss \", \"dar \", \"ien \", \"her \",\n \"cant\", \"jol \", \"nar \", \"kam \", \"dorn\",\n \"li \", \"sis \", \"maal\", \"uk \", \"mec \",\n \"at \", \"ol \", \"mi \", \"ra \", \"ge \",\n \"mor \", \"dai \", \"nest\", \"phar\", \"rag \",\n \"ret \", \"ill \", \"on \", \"dru \", \"ah \",\n \"quin\", \"sha \", \"loq \", \"tre \", \"lak \",\n \"sum \", \"eri \", \"an \", \"tsi \", \"win \",\n \"ter \", \"arch\", \"on \", \"ren \", \"i \",\n \"pri \", \"tau \", \"cu \", \"ry \", \"ven \",\n \"us \", \"mar \", \"jup \", \"it \", \"er \",\n \"sat \", \"uh \", \"un \", \"plu \", \"gol \",\n \"kar \", \"lam \", \"wel \", \"pik \", \"chu \",\n \"cha \", \"man \", \"der \", \"za \", \"bla \",\n \"sto \", \"id \", \"sau \", \"tan \", \"sin \",\n \"cos \", \"chut\", \"stri\", \"stra\", \"stru\",\n \"skro\", \"skre\", \"cet \", \"nya \", \"nyu \",\n \"ple \", \"pra \", \"ble \", \"glu \", \"geo \");\n \n Num, I: Integer;\n Index: Integer := 1;\n Ut: String(1..200);\n Stav: String(1..4);\n Ver: Boolean := True;\nbegin\n Put(\"Mata in antal stavelser: \"); Get(Num);\n Put(\"Mata in stavelseindex: \");\n for X in 1..Num loop\n Get(I);\n if I < 0 then\n\t Stav := Syl_Arr(-I);\n\t Ut(Index) := '-';\n\t Ver := True;\n\t Index := Index + 1;\n else\n\t Stav := Syl_Arr(I);\n end if;\n \n for Z in 1..4 loop\n\t if Stav(Z) /= ' ' then\n\t if Ver = True then\n\t Ut(Index) := Ada.Characters.Handling.To_Upper(Stav(Z));\n\t else\n\t Ut(Index) := Stav(Z);\n\t end if;\n\t Ver := False;\n\t Index := Index + 1;\n\t end if;\n end loop;\n end loop;\n Put(\"Genererat planetnamn: \");\n Put(Ut(1..Index));" + }, + { + "function_def": "procedure Stone is", + "function_body": "I: Integer;\n C: Character;\nbegin\n --kollar om 2 argument finns\n if Argument_Count = 2 then\n --Tar in tecknet\n C := Argument(1)(1);\n --Omvandlar tecknet till integer\n I := Character'Pos(C);\n -- L\u00e4gger till argument 2 till integern\n I := I + Integer'Value(Argument(2));\n \n Put(Character'Val(I));\n end if;\n null;" + }, + { + "function_def": "procedure Henge is", + "function_body": "function Read\n return Integer is\n C : Character;\n begin\n Get(C);\n if C = 'h' then\n\t return 0;\n else\n\t for I in 1..4 loop\n\t Get(C);\n\t end loop;\n\t return Read + 12;\n end if;" + }, + { + "function_def": "function Exists ( Check_Value : Character; Values : Backpack_Pocket_T; Range_Max: Pocket_Size_T) return Boolean is", + "function_body": "(for some Idx in Backpack_Pocket_T'First .. Range_Max => Values (Idx) = Check_Value);\n\n begin\n for Char_Idx in Pocket_Size_T'First .. pack.Pocket_Size loop\n if Char_Idx = Backpack_Pocket_T'First or else \n not Exists (pack.Pocket_A_Content (Char_Idx), pack.Pocket_A_Content, Char_Idx - 1) then\n\n if Exists (pack.Pocket_A_Content (Char_Idx), pack.Pocket_B_Content, pack.Pocket_Size) then\n Running_Total := Running_Total + Get_Item_Prioirty (pack.Pocket_A_Content (Char_Idx));\n end if;\n end if;\n \n pragma Loop_Variant (Increases => Char_Idx);\n pragma Loop_Invariant (Running_Total <= Backpack_Priority_Score_T(Char_Idx) * Max_Item_Priority);\n end loop;\n\n return Running_Total;" + }, + { + "function_def": "function Exists ( Check_Value : Character; Values : Input_String; Range_Max: Input_Size_T) return Boolean is", + "function_body": "(for some Idx in Backpack_Pocket_T'First .. Range_Max => Values (Idx) = Check_Value);\n \n begin\n Search_Loop : for Char_Idx in Input_String'First .. 2 * Packs(1).Pocket_Size loop \n if Char_Idx = Input_String'First or else \n not Exists (Packs(1).Pack_Content (Char_Idx), Packs(1).Pack_Content, Char_Idx - 1) then\n \n if Exists (Packs(1).Pack_Content (Char_Idx), Packs(2).Pack_Content, 2 * Packs(2).Pocket_Size) and then\n Exists (Packs(1).Pack_Content (Char_Idx), Packs(3).Pack_Content, 2 * Packs(3).Pocket_Size) then\n Running_Total := Running_Total + Get_Item_Prioirty (Packs(1).Pack_Content (Char_Idx));\n exit Search_Loop when True;\n end if;\n end if;\n \n pragma Loop_Variant (Increases => Char_Idx);\n pragma Loop_Invariant (Running_Total <= Max_Item_Priority);\n end loop Search_Loop;\n \n return Running_Total;" + }, + { + "function_def": "procedure Stack_Init is", + "function_body": "begin\n for i in Stack_Row_Index'Range loop\n for j in Stack_Column_Index'Range loop\n Crate_Stack(i, j) := '-';\n end loop;\n end loop;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (Void_Ptr, chars_ptr);", + "function_body": "Message : constant String_List := Split (Value (Convert (Signal_Data)), Maximum => 4);\n\n From_User : SU.Unbounded_String renames Message (1);\n Primitive : SU.Unbounded_String renames Message (2);\n Channel : SU.Unbounded_String renames Message (3);\n Text : SU.Unbounded_String renames Message (4);\n pragma Assert (Primitive = \"PRIVMSG\");\n\n Is_Private_Message : constant Boolean := Channel = Nick_Name;\n Is_Highlighted : constant Boolean := SU.Index (Text, \":\" & Nick_Name & \": \") > 0;\n\n Is_Away : constant Boolean := Clock - Last_Key_Press > Away_Duration;\n begin\n if Is_Private_Message or Is_Highlighted then\n if not Is_Away then\n Play_Async (Sound_Message);\n Play_Async (Sound_Message_Highlight);\n else\n Is_Highlighted_While_Away := True;\n\n if Seconds (Clock) in Office_Hour_Start .. Office_Hour_End then\n if Reminder_Timer /= No_Timer then\n Cancel_Timer (Reminder_Timer);\n Reminder_Timer := No_Timer;\n end if;\n Play_Async (Sound_Message_Highlight_Away);\n else\n declare\n Current_Time : constant Time := Clock;\n Wake_Up_Date : constant Time := Current_Time - Seconds (Current_Time)\n + (if Seconds (Clock) >= Office_Hour_End then Day_Duration'Last else 0.0)\n + Office_Hour_Start;\n\n In_Time : constant Duration := Wake_Up_Date - Current_Time;\n Sender : constant String := Get_Nick (Host => +From_User);\n begin\n if Reminder_Timer = No_Timer then\n Reminder_Timer := Set_Timer\n (Plugin, In_Time, 60, 1, Reminder_First_Call_Handler'Access);\n\n Send_Message\n (Plugin, +Server_Name,\n (if Is_Private_Message then Sender else +Channel),\n (if Is_Private_Message then \"\" else Sender & \": \") &\n \"I'm currently away since \" & Image_Date (Last_Key_Press) &\n \". I will try to notify myself in about \" &\n Image_Time (In_Time) & \" hours\");\n end if;" + }, + { + "function_def": "procedure Main is", + "function_body": "procedure del_int(obj: Integer) is\n begin\n null;\n end del_int;\n\n package Integer_List is new lists(Integer,Integer'Image,\"=\",del_int);\n use Integer_List;\n\n\n procedure Test_List_Package(L1:in out List) is\n begin\n Put_Line(\"Image: \" & L1.Image);\n Put_Line(Integer'Image(L1.Index(2)));\n Put_Line(\"Length: \" & Integer'Image(L1.Length));\n Put_Line(Boolean'Image(L1 = L1));\n begin\n Put_Line(\"Get 3rd item: \" & Integer'Image(L1.get(3)));\n\n exception\n when Get_Index_Value_Outside_the_list =>\n Put_Line(\"Index_Get_Value_Outside_the_list\");" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E006 := E006 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E109 := E109 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n Interfaces.C'Elab_Spec;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n Ada.Strings.Maps'Elab_Spec;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Object_Reader'Elab_Spec;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n E078 := E078 + 1;\n E054 := E054 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E080 := E080 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E101 := E101 + 1;\n Ada.Streams'Elab_Spec;\n E099 := E099 + 1;\n System.File_Control_Block'Elab_Spec;\n E113 := E113 + 1;\n System.Finalization_Root'Elab_Spec;\n E112 := E112 + 1;\n Ada.Finalization'Elab_Spec;\n E110 := E110 + 1;\n System.File_Io'Elab_Body;\n E109 := E109 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E006 := E006 + 1;\n E115 := E115 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure Main is", + "function_body": "type Common_Axis_Type is range 0..20;\n type Common_Button_Type is range 0..20;\n package LJS is new Linux_Joystick(Button_Type => Common_Button_Type,\n Axis_Type => Common_Axis_Type);\n\n generic\n with package JSP is new Linux_Joystick (<>);\n procedure Put(Js_Event : in JSP.Js_Event_Type);\n \n procedure Put(Js_Event : in JSP.Js_Event_Type) is\n\n package Millisecinds_IO is new Text_IO.Integer_IO(JSP.Milliseconds_Type);\n package Value_IO is new Text_IO.Integer_IO(JSP.Value_Type);\n\n begin\n Text_IO.Put(if Js_Event.Is_Init_Event then \"I\" else \" \");\n Text_IO.Put(Ada.Characters.Latin_1.HT);\n\n Millisecinds_IO.Put(Js_Event.Time);\n Text_IO.Put(Ada.Characters.Latin_1.HT);\n\n Text_IO.Put(JSP.Event_Type_Type'Image(Js_Event.Event_Type));\n Text_IO.Put(Ada.Characters.Latin_1.HT);\n\n case Js_Event.Event_Type is \n when JSP.JS_EVENT_BUTTON =>\n Text_IO.Put(JSP.Button_Type'Image(Js_Event.Button));\n Text_IO.Put(Ada.Characters.Latin_1.HT); \n \n Text_IO.Put(JSP.Button_Action_Type'Image(Js_Event.Button_Action));\n\n when JSP.JS_EVENT_AXIS =>\n \n Text_IO.Put(JSP.Axis_Type'Image(Js_Event.Axis));\n Text_IO.Put(Ada.Characters.Latin_1.HT);\n\n Value_IO.Put(Js_Event.Value);\n end case; \n\n Text_IO.New_Line;" + }, + { + "function_def": "procedure Put_LJS is new Put(LJS);", + "function_body": "begin\n\n declare\n -- It is also possible to use Open without parameters, it will automatically locate\n -- an available \"js*\" file.\n --\n Opended_Device_Path : String := \"/dev/input/js1\";\n \n begin\n LJS.Open(Opended_Device_Path);\n Text_IO.Put_Line(\"Opended device at: \" & Opended_Device_Path);\n\n loop\n declare\n Js_Event : LJS.Js_Event_Type := LJS.Read;\n begin\n Put_LJS(Js_Event);" + }, + { + "function_def": "procedure Close is", + "function_body": "begin\n SIO.Close(Input_File);" + }, + { + "function_def": "procedure Demo is", + "function_body": "function Pad (S : String; Len : Positive) return String is\n (S & (1 .. Len - S'Length => ' '));\n\n procedure Title (Text : String) is\n begin\n New_Line;\n Put_Line (Style_Wrap (Text => \"=== \" & Text & \"===\",\n Style => Bright));\n end Title;\nbegin\n Put_Line (Reset_All);\n\n Title (\"BASIC COLOR TEST\");\n -- Named color tests: best seen in a 96-column term\n for Fg in Colors'Range loop\n for Bg in Colors'Range loop\n if Fg /= Bg then\n Put (Color_Wrap (Text => Fg'Img & \" on \" & Bg'Img,\n Foreground => Foreground (Fg),\n Background => Background (Bg)));\n end if;\n end loop;\n end loop;\n New_Line;\n\n Title (\"PALETTE COLOR TEST (subsample)\");\n declare\n Palette : constant array (Positive range <>) of Palette_RGB :=\n (0, 1, 3, 5);\n begin\n for R of Palette loop\n for G of Palette loop\n for B of Palette loop\n for BR of Palette loop\n for BG of Palette loop\n for BB of Palette loop\n Put (Color_Wrap\n (Text => \"X\",\n Foreground => Palette_Fg (R, G, B),\n Background => Palette_Bg (BR, BG, BB)));\n end loop;\n end loop;\n end loop;\n end loop;\n end loop;\n end loop;\n New_Line;" + }, + { + "function_def": "procedure Reset_Board is", + "function_body": "begin -- Reset_Board\n\t\tfor I of Our_Board loop\n\t\t\tI := (others=>Empty_Piece);\n\t\tend loop;\n\n\t\tfor I of Our_Board(Position'First + 1) loop\n\t\t\tI := Player_1_Pawn;\n\t\tend loop;\n\t\tOur_Board(Position'First) := Starting_Backrow_Order(1);\n\n\t\tfor I of Our_Board(Position'Last - 1) loop\n\t\t\tI := Player_2_Pawn;\n\t\tend loop;\n\t\tOur_Board(Position'Last) := Starting_Backrow_Order(2);\n\n\t\tKing_Status(0) := (X=>3, Y=>0);\n\t\tKing_Status(1) := (X=>3, Y=>7);\n\t\tLast_Moved := (0, 0);\n\n\tend Reset_Board;\n\n\tprocedure Print_Board is\n\t\tSmall_String : String(1..6);\n\tbegin -- Print_Board\n\t\tClear;\n\t\tAttribute_On(1);\n\t\tPretty_Print_Line_Window(Owner_Type'Image(Owner_Type'Val(Turn)));\n\t\tfor I in reverse Our_Board'Range loop\n\t\t\tPretty_Print_Line_Window(\" -------------------------------------------------------------------------\");\n\t\t\tPretty_Print_Line_Window(\" | | | | | | | | | \");\n\t\t\tPretty_Print_Window(Integer'Image(Integer(I) + 1) & \" | \");\n\t\t\tfor J of Our_Board(I) loop\n\t\t\t\tif J /= Empty_Piece then\n\t\t\t\t\tif J.Owner = Player_1 then\n\t\t\t\t\t\tAttribute_On(2);\n\t\t\t\t\tend if;\n\t\t\t\t\tPut(To=>Small_String, Item=>J.Name);\n\t\t\t\t\tPretty_Print_Window(Small_String);\n\t\t\t\t\tAttribute_On(1);\n\t\t\t\telse\n\t\t\t\t\tPretty_Print_Window(\" \");\n\t\t\t\tend if;\n\t\t\t\tPretty_Print_Window(\" | \");\n\t\t\tend loop;\n\t\t\tPretty_Print_Line_Window(ASCII.lf & \" | | | | | | | | | \");\n\t\tend loop;\n\t\tPretty_Print_Line_Window(\" -------------------------------------------------------------------------\");\n\t\tPretty_Print_Line_Window(\" A B C D E F G H \");\n\t\tRefresh;\n\tend Print_Board;\n\n\tprocedure Move (From, To : in Cordinate_Type) is\n\tbegin -- Move\n\n\t\tif Our_Board(From.Y)(From.X).Owner /= Owner_Type'Val(Turn) then -- check if it's their piece\n\t\t\traise Not_Allowed;\n\t\tend if;\n\n\t\tcase Our_Board(From.Y)(From.X).Name is\n\t\t\t-- check to see if move if possible\n\t\t\twhen Pawn => --since the pawn move logic is so complex, it's best to do it all here\n\t\t\t\t\t\tdeclare\n\t\t\t\t\t\t\tTurn_Test : Integer;\n\t\t\t\t\t\t\tfunction \"+\" (Left: in Position; Right : in Integer) return Position is\n\t\t\t\t\t\t\t\t(Position(Integer(Left) + Right));\n\t\t\t\t\t\tbegin\n\t\t\t\t\t\t\tTurn_Test := (if Turn = 0 then -1 else 1);\n\n\t\t\t\t\t\t\tif Integer(From.X - To.X) = 0 then -- advance\n\t\t\t\t\t\t\t\tif Our_Board(To.Y)(To.X).Owner = None and -- can't attack forward\n\t\t\t\t\t\t\t\t\tthen (Integer(From.Y - To.Y) = Turn_Test or (Integer(From.Y - To.Y) = Turn_Test*2 and Our_Board(From.Y)(From.X).Has_Moved = No and Our_Board(To.Y + Turn_Test)(To.X).Owner = None)) then --check if move is valid\n\t\t\t\t\t\t\t\t\t\tTake_Space(From, To);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\traise Not_Allowed;\n\t\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\t\telsif Integer(From.X - To.X) in -1..1 then -- attack move\n\t\t\t\t\t\t\t\tif Integer(From.Y - To.Y) = Turn_Test then --check if move is valid\n\t\t\t\t\t\t\t\t\tif Our_Board(To.Y)(To.X).Owner /= None then\n\t\t\t\t\t\t\t\t\t\t\tTake_Space(From, To);\t\t\t\n\t\t\t\t\t\t\t\t\telsif Our_Board(Last_Moved.Y)(Last_Moved.X).Name = Pawn and -- en passent\n\t\t\t\t\t\t\t\t\t\tthen Last_Moved = (X=>To.X, Y=>To.Y + Turn_Test) then\n\t\t\t\t\t\t\t\t\t\t\tOur_Board(Last_Moved.Y)(Last_Moved.X) := Empty_Piece;\n\t\t\t\t\t\t\t\t\t\t\tTake_Space(From, To);\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\traise Not_Allowed;\n\t\t\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\traise Not_Allowed;\n\t\t\t\t\t\t\t\tend if;\t\t\t\t\t\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\traise Not_Allowed;\n\t\t\t\t\t\t\tend if;" + }, + { + "function_def": "procedure Chess is", + "function_body": "-- pragma Suppress(All_Checks);\n\n\ttype Game_Options is (None, Network, Local);\n\n\tprocedure Print_and_Clear (Item : in String) with Inline is\n\tbegin\n\t\tAttribute_On(3);\n\t\tPretty_Print_Line_Window(Item);\n\t\tRefresh;\n\t\tdelay 1.0;\n\t\tPrint_Board;\n\tend Print_and_Clear;\n\n\tPlayer_Select_Request : Cordinate_Type;\n\tPlayer_Move_Request : Cordinate_Type;\n\tTemp : Byte;\n\tGame_Status : Game_Options := None;\n\tPort : Port_Type := 0;\n\tIs_Host : Boolean := False;\n\t-- Address_String : String (1..15) := (others=>' ');\n\tAddress_String : String := \"192.168.1.53\";\n\n\tClient : Socket_Type;\n\tAddress : Sock_Addr_Type;\n\tChannel : Stream_Access; \n\n\tReceiver : Socket_Type;\n\tConnection : Socket_Type;\n\n\tInitial_Move : Boolean := True;\n\nbegin\n\n\tloop\n\t\tcase Getopt (\"l n h p: i:\") is\n\t\t\twhen 'l' =>\n\t\t\t\tif Game_Status = None then\n\t\t\t\t\tGame_Status := Local;\n\t\t\t\telse\n\t\t\t\t\tAda.Text_IO.Put_Line(\"Conflicting agument : '-l'\");\n\t\t\t\t\treturn;\n\t\t\t\tend if;\n\t\t\twhen 'n' =>\n\t\t\t\tif Game_Status = None then\n\t\t\t\t\tGame_Status := Network;\n\t\t\t\telse\n\t\t\t\t\tAda.Text_IO.Put_Line(\"Conflicting agument : '-n'\");\n\t\t\t\t\treturn;\n\t\t\t\tend if;\n\t\t\twhen 'p' =>\n\t\t\t\tPort := Port_Type'Value(Parameter);\n\t\t\twhen 'h' =>\n\t\t\t\tIs_Host := True;\n\t\t\twhen 'i' =>\n\t\t\t\t Move(Parameter, Address_String);\n\t\t\twhen others =>\n\t\t\t\texit;\n\t\tend case;\n\tend loop;\n\n\tif Game_Status = Network then\n\t\tif (Port = 0 or Address_String = 15*' ') then\n\t\t\tAda.Text_IO.Put_Line(\"Argument Error\");\n\t\t\treturn;\n\t\tend if;\n\t\tif Is_Host then\n\t\t\tCreate_Socket (Receiver);\n\t\t\tSet_Socket_Option\n\t\t\t\t(Socket => Receiver,\n\t\t\t\t Option => (Name=>Reuse_Address, Enabled => True));\n\t\t\tBind_Socket\n\t\t\t\t(Socket => Receiver,\n\t\t\t\t Address => (Family=>Family_Inet,\n\t\t\t\t\t\t\t Addr=>Inet_Addr (Address_String),\n\t\t\t\t\t\t\t Port=>Port));\n\t\t\tListen_Socket (Socket => Receiver);\n\t\t\tAccept_Socket\n\t\t\t\t(Server => Receiver,\n\t\t\t\t Socket => Connection,\n\t\t\t\t Address => Address);\n\t\t\t-- Put_Line(\"Client connected from \" & Image (Address));\n\t\t\tChannel := Stream (Connection);\n\t\telse\n\t\t\tCreate_Socket (Client);\n\t\t\tAddress.Addr := Inet_Addr(Address_String);\n\t\t\tAddress.Port := Port;\n\n\t\t\tConnect_Socket (Client, Address);\n\t\t\tChannel := Stream (Client);\n\n\t\tend if;\n\tend if;\n\n\n\tInit_Scr;\n\tStart_Color_Init;\n\tReset_Board;\n\tPrint_Board;\n\n\tGame_Loop : loop\n\t\tif Initial_Move then\n\t\t\tInitial_Move := False;\n\t\t\tif Is_Host then\n\t\t\t\tgoto HOST_START;\n\t\t\tend if;\n\t\tend if;\n\n\t\tWait_For_Input : loop\n\t\t\tbegin\n\t\t\t\tif Game_Status = Network then\n\t\t\t\t\tGet_Variables(Channel);\n\t\t\t\tend if;\n\t\t\t\tPrint_Board;\n\t\t\t\tif Is_Winner in 1..2 then\n\t\t\t\t\tPrint_and_Clear(\"Player\" & Integer'Image(Is_Winner) & \" is the winner\");\n\t\t\t\t\tgoto FINISH;\n\t\t\t\tend if;\n\t\t\t\texit;\n\t\t\texception\n\t\t\t\twhen others => Print_Board;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => AWA.Users.Principals.Principal'Class,\n Name => AWA.Users.Principals.Principal_Access);\n\n -- ------------------------------\n -- Initialize the service context.\n -- ------------------------------\n procedure Initialize (Principal : in out Test_User) is\n begin\n -- Setup the service context.\n Principal.Context.Set_Context (AWA.Tests.Get_Application, null);\n\n if Principal.Manager = null then\n Principal.Manager := AWA.Users.Modules.Get_User_Manager;\n if Principal.Manager = null then\n Log.Error (\"There is no User_Manager in the application.\");\n end if;\n end if;\n end Initialize;\n\n -- ------------------------------\n -- Create a test user associated with the given email address.\n -- Get an open session for that user. If the user already exists, no error is reported.\n -- ------------------------------\n procedure Create_User (Principal : in out Test_User;\n Email : in String) is\n DB : ADO.Sessions.Session;\n Query : ADO.SQL.Query;\n Found : Boolean;\n Key : AWA.Users.Models.Access_Key_Ref;\n begin\n Initialize (Principal);\n\n DB := Principal.Manager.Get_Session;\n\n -- Find the user\n Query.Set_Join (\"inner join awa_email e on e.user_id = o.id\");\n Query.Set_Filter (\"e.email = ?\");\n Query.Bind_Param (1, Email);\n Principal.User.Find (DB, Query, Found);\n if not Found then\n Principal.User.Set_First_Name (\"Joe\");\n Principal.User.Set_Last_Name (\"Pot\");\n Principal.User.Set_Password (\"admin\");\n Principal.Email.Set_Email (Email);\n Principal.Manager.Create_User (Principal.User, Principal.Email);\n\n Find_Access_Key (Principal, Email, Key);\n\n -- Run the verification and get the user and its session\n Principal.Manager.Verify_User (Key.Get_Access_Key, \"192.168.1.1\",\n Principal.Principal);\n else\n Principal.Manager.Authenticate (Email => Email,\n Password => \"admin\",\n IpAddr => \"192.168.1.1\",\n Principal => Principal.Principal);\n end if;\n Principal.User := Principal.Principal.Get_User;\n Principal.Session := Principal.Principal.Get_Session;\n end Create_User;\n\n -- ------------------------------\n -- Create a test user for a new test and get an open session.\n -- ------------------------------\n procedure Create_User (Principal : in out Test_User) is\n Key : AWA.Users.Models.Access_Key_Ref;\n Email : constant String := \"Joe-\" & Util.Tests.Get_Uuid & \"@gmail.com\";\n begin\n Initialize (Principal);\n Principal.User.Set_First_Name (\"Joe\");\n Principal.User.Set_Last_Name (\"Pot\");\n Principal.User.Set_Password (\"admin\");\n Principal.Email.Set_Email (Email);\n Principal.Manager.Create_User (Principal.User, Principal.Email);\n\n Find_Access_Key (Principal, Email, Key);\n\n -- Run the verification and get the user and its session\n Principal.Manager.Verify_User (Key.Get_Access_Key, \"192.168.1.1\",\n Principal.Principal);\n Principal.User := Principal.Principal.Get_User;\n Principal.Session := Principal.Principal.Get_Session;\n end Create_User;\n\n -- ------------------------------\n -- Find the access key associated with a user (if any).\n -- ------------------------------\n procedure Find_Access_Key (Principal : in out Test_User;\n Email : in String;\n Key : in out AWA.Users.Models.Access_Key_Ref) is\n DB : ADO.Sessions.Session;\n Query : ADO.SQL.Query;\n Found : Boolean;\n Signup_Kind : constant Integer\n := AWA.Users.Models.Key_Type'Pos (AWA.Users.Models.SIGNUP_KEY);\n Password_Kind : constant Integer\n := AWA.Users.Models.Key_Type'Pos (AWA.Users.Models.RESET_PASSWORD_KEY);\n begin\n Initialize (Principal);\n\n DB := Principal.Manager.Get_Session;\n\n -- Find the access key\n Query.Set_Join (\"inner join awa_email e on e.user_id = o.user_id\");\n Query.Set_Filter (\"e.email = ? AND o.kind = ?\");\n Query.Bind_Param (1, Email);\n Query.Bind_Param (2, Signup_Kind);\n Key.Find (DB, Query, Found);\n if not Found then\n Query.Bind_Param (2, Password_Kind);\n Key.Find (DB, Query, Found);\n if not Found then\n Log.Error (\"Cannot find access key for email {0}\", Email);\n end if;\n end if;\n end Find_Access_Key;\n\n -- ------------------------------\n -- Login a user and create a session\n -- ------------------------------\n procedure Login (Principal : in out Test_User) is\n begin\n Initialize (Principal);\n Principal.Manager.Authenticate (Email => Principal.Email.Get_Email,\n Password => \"admin\",\n IpAddr => \"192.168.1.1\",\n Principal => Principal.Principal);\n Principal.User := Principal.Principal.Get_User;\n Principal.Session := Principal.Principal.Get_Session;\n end Login;\n\n -- ------------------------------\n -- Logout the user and closes the current session.\n -- ------------------------------\n procedure Logout (Principal : in out Test_User) is\n begin\n Initialize (Principal);\n Principal.Manager.Close_Session (Principal.Session.Get_Id, True);\n end Logout;\n\n -- ------------------------------\n -- Simulate a user login in the given service context.\n -- ------------------------------\n procedure Login (Context : in out AWA.Services.Contexts.Service_Context'Class;\n Sec_Context : in out Security.Contexts.Security_Context;\n Email : in String) is\n User : Test_User;\n Principal : AWA.Users.Principals.Principal_Access;\n App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;\n begin\n AWA.Tests.Set_Application_Context;\n Create_User (User, Email);\n Principal := AWA.Users.Principals.Create (User.User, User.Session);\n Context.Set_Context (App, Principal);\n Sec_Context.Set_Context (Manager => App.Get_Security_Manager,\n Principal => Principal.all'Access);\n\n -- Keep track of the Principal instance so that Tear_Down will release it.\n -- Most tests will call Login but don't call Logout because there is no real purpose\n -- for the test in doing that and it allows to keep the unit test simple. This creates\n -- memory leak because the Principal instance is not freed.\n for I in Logged_Users'Range loop\n if Logged_Users (I) = null then\n Logged_Users (I) := Principal;\n exit;\n end if;\n end loop;\n end Login;\n\n -- ------------------------------\n -- Simulate a user login on the request. Upon successful login, a session that is\n -- authentified is associated with the request object.\n -- ------------------------------\n procedure Login (Email : in String;\n Request : in out ASF.Requests.Mockup.Request) is\n User : Test_User;\n Reply : ASF.Responses.Mockup.Response;\n begin\n Create_User (User, Email);\n ASF.Tests.Do_Get (Request, Reply, \"/auth/login.html\", \"login-user-1.html\");\n\n Request.Set_Parameter (\"email\", Email);\n Request.Set_Parameter (\"password\", \"admin\");\n Request.Set_Parameter (\"login\", \"1\");\n Request.Set_Parameter (\"login-button\", \"1\");\n ASF.Tests.Do_Post (Request, Reply, \"/auth/login.html\", \"login-user-2.html\");\n end Login;\n\n -- ------------------------------\n -- Setup the context and security context to simulate an anonymous user.\n -- ------------------------------\n procedure Anonymous (Context : in out AWA.Services.Contexts.Service_Context'Class;\n Sec_Context : in out Security.Contexts.Security_Context) is\n App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;\n begin\n AWA.Tests.Set_Application_Context;\n Context.Set_Context (App, null);\n Sec_Context.Set_Context (Manager => App.Get_Security_Manager,\n Principal => null);\n end Anonymous;\n\n -- ------------------------------\n -- Simulate the recovery password process for the given user.\n -- ------------------------------\n procedure Recover_Password (Email : in String) is\n use type ASF.Principals.Principal_Access;\n\n Request : ASF.Requests.Mockup.Request;\n Reply : ASF.Responses.Mockup.Response;\n begin\n Request.Set_Parameter (\"email\", Email);\n Request.Set_Parameter (\"lost-password\", \"1\");\n Request.Set_Parameter (\"lost-password-button\", \"1\");\n ASF.Tests.Do_Post (Request, Reply, \"/auth/lost-password.html\", \"lost-password-2.html\");\n\n if Reply.Get_Status /= ASF.Responses.SC_MOVED_TEMPORARILY then\n Log.Error (\"Invalid redirect after lost password\");\n end if;\n\n -- Now, get the access key and simulate a click on the reset password link.\n declare\n Principal : AWA.Tests.Helpers.Users.Test_User;\n Key : AWA.Users.Models.Access_Key_Ref;\n begin\n AWA.Tests.Set_Application_Context;\n AWA.Tests.Helpers.Users.Find_Access_Key (Principal, Email, Key);\n if not Key.Is_Null then\n Log.Error (\"There is no access key associated with the user\");\n end if;\n\n -- Simulate user clicking on the reset password link.\n -- This verifies the key, login the user and redirect him to the change-password page\n Request.Set_Parameter (\"key\", Key.Get_Access_Key);\n Request.Set_Parameter (\"password\", \"admin\");\n Request.Set_Parameter (\"reset-password\", \"1\");\n ASF.Tests.Do_Post (Request, Reply, \"/auth/change-password.html\", \"reset-password-2.html\");\n\n if Reply.Get_Status /= ASF.Responses.SC_MOVED_TEMPORARILY then\n Log.Error (\"Invalid response\");\n end if;\n\n -- Check that the user is logged and we have a user principal now.\n if Request.Get_User_Principal = null then\n Log.Error (\"A user principal should be defined\");\n end if;" + }, + { + "function_def": "function Get is new AWA.Modules.Get (Tag_Module, Tag_Module_Access, NAME);", + "function_body": "begin\n return Get;\n end Get_Tag_Module;\n\n -- ------------------------------\n -- Add a tag on the database entity referenced by Id in the table identified\n -- by Entity_Type. The permission represented by Permission is checked\n -- to make sure the current user can add the tag. If the permission is granted, the\n -- tag represented by Tag is associated with the said database entity.\n -- ------------------------------\n procedure Add_Tag (Model : in Tag_Module;\n Id : in ADO.Identifier;\n Entity_Type : in String;\n Permission : in String;\n Tag : in String) is\n pragma Unreferenced (Model);\n\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n Ident : constant String := Entity_Type & ADO.Identifier'Image (Id);\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Kind : ADO.Entity_Type;\n begin\n -- Check that the user has the permission on the given object.\n AWA.Permissions.Check (Permission => Security.Permissions.Get_Permission_Index (Permission),\n Entity => Id);\n\n Log.Info (\"User {0} add tag {1} on {2}\",\n ADO.Identifier'Image (User.Get_Id), Tag, Ident);\n\n Ctx.Start;\n Kind := ADO.Sessions.Entities.Find_Entity_Type (DB, Entity_Type);\n Add_Tag (DB, Id, Kind, Tag);\n Ctx.Commit;\n end Add_Tag;\n\n -- ------------------------------\n -- Remove the tag identified by Tag and associated with the database entity\n -- referenced by Id in the table identified by Entity_Type.\n -- The permission represented by Permission is checked to make sure the current user\n -- can remove the tag.\n -- ------------------------------\n procedure Remove_Tag (Model : in Tag_Module;\n Id : in ADO.Identifier;\n Entity_Type : in String;\n Permission : in String;\n Tag : in String) is\n pragma Unreferenced (Model);\n\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n Ident : constant String := Entity_Type & ADO.Identifier'Image (Id);\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Kind : ADO.Entity_Type;\n begin\n -- Check that the user has the permission on the given object.\n AWA.Permissions.Check (Permission => Security.Permissions.Get_Permission_Index (Permission),\n Entity => Id);\n\n Log.Info (\"User {0} removes tag {1} on {2}\",\n ADO.Identifier'Image (User.Get_Id), Tag, Ident);\n\n Ctx.Start;\n Kind := ADO.Sessions.Entities.Find_Entity_Type (DB, Entity_Type);\n Remove_Tag (DB, Id, Kind, Tag);\n Ctx.Commit;\n end Remove_Tag;\n\n -- ------------------------------\n -- Remove the tags defined by the Deleted tag list and add the tags defined\n -- in the Added tag list. The tags are associated with the database entity\n -- referenced by Id in the table identified by Entity_Type.\n -- The permission represented by Permission is checked to make sure the current user\n -- can remove or add the tag.\n -- ------------------------------\n procedure Update_Tags (Model : in Tag_Module;\n Id : in ADO.Identifier;\n Entity_Type : in String;\n Permission : in String;\n Added : in Util.Strings.Vectors.Vector;\n Deleted : in Util.Strings.Vectors.Vector) is\n pragma Unreferenced (Model);\n\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n Ident : constant String := Entity_Type & ADO.Identifier'Image (Id);\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Kind : ADO.Entity_Type;\n Iter : Util.Strings.Vectors.Cursor;\n begin\n -- Check that the user has the permission on the given object.\n AWA.Permissions.Check (Permission => Security.Permissions.Get_Permission_Index (Permission),\n Entity => Id);\n\n Ctx.Start;\n Kind := ADO.Sessions.Entities.Find_Entity_Type (DB, Entity_Type);\n\n -- Delete the tags that have been removed.\n Iter := Deleted.First;\n while Util.Strings.Vectors.Has_Element (Iter) loop\n declare\n Tag : constant String := Util.Strings.Vectors.Element (Iter);\n begin\n Log.Info (\"User {0} removes tag {1} on {2}\",\n ADO.Identifier'Image (User.Get_Id), Tag, Ident);\n\n Remove_Tag (DB, Id, Kind, Tag);" + }, + { + "function_def": "procedure Set_Permission (Into : in out Tag_List_Bean;", + "function_body": "Permission : in String) is\n begin\n Into.Permission := Ada.Strings.Unbounded.To_Unbounded_String (Permission);\n end Set_Permission;\n\n -- ------------------------------\n -- Load the tags associated with the given database identifier.\n -- ------------------------------\n procedure Load_Tags (Into : in out Tag_List_Bean;\n Session : in ADO.Sessions.Session;\n For_Entity_Id : in ADO.Identifier) is\n use ADO.Sessions.Entities;\n\n Entity_Type : constant String := Ada.Strings.Unbounded.To_String (Into.Entity_Type);\n Kind : constant ADO.Entity_Type := Find_Entity_Type (Session, Entity_Type);\n Query : ADO.Queries.Context;\n begin\n Query.Set_Query (AWA.Tags.Models.Query_Tag_List);\n Query.Bind_Param (\"entity_type\", Kind);\n Query.Bind_Param (\"entity_id\", For_Entity_Id);\n declare\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n begin\n Stmt.Execute;\n\n while Stmt.Has_Elements loop\n Into.List.Append (Util.Beans.Objects.To_Object (Stmt.Get_String (0)));\n Stmt.Next;\n end loop;" + }, + { + "function_def": "function Create_Tag_List_Bean (Module : in AWA.Tags.Modules.Tag_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n Result : constant Tag_List_Bean_Access := new Tag_List_Bean;\n begin\n Result.Module := Module;\n return Result.all'Access;\n end Create_Tag_List_Bean;\n\n -- ------------------------------\n -- Search the tags that match the search string.\n -- ------------------------------\n procedure Search_Tags (Into : in out Tag_Search_Bean;\n Session : in ADO.Sessions.Session;\n Search : in String) is\n use ADO.Sessions.Entities;\n\n Entity_Type : constant String := Ada.Strings.Unbounded.To_String (Into.Entity_Type);\n Kind : constant ADO.Entity_Type := Find_Entity_Type (Session, Entity_Type);\n Query : ADO.Queries.Context;\n begin\n Query.Set_Query (AWA.Tags.Models.Query_Tag_Search);\n Query.Bind_Param (\"entity_type\", Kind);\n Query.Bind_Param (\"search\", Search & \"%\");\n declare\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n begin\n Stmt.Execute;\n\n while Stmt.Has_Elements loop\n Into.List.Append (Util.Beans.Objects.To_Object (Stmt.Get_String (0)));\n Stmt.Next;\n end loop;" + }, + { + "function_def": "function Create_Tag_Info_List_Bean (Module : in AWA.Tags.Modules.Tag_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n Result : constant Tag_Info_List_Bean_Access := new Tag_Info_List_Bean;\n begin\n Result.Module := Module;\n return Result.all'Access;\n end Create_Tag_Info_List_Bean;\n\n -- ------------------------------\n -- Get the list of tags associated with the given entity.\n -- Returns null if the entity does not have any tag.\n -- ------------------------------\n function Get_Tags (From : in Entity_Tag_Map;\n For_Entity : in ADO.Identifier)\n return Util.Beans.Lists.Strings.List_Bean_Access is\n Pos : constant Entity_Tag_Maps.Cursor := From.Tags.Find (For_Entity);\n begin\n if Entity_Tag_Maps.Has_Element (Pos) then\n return Entity_Tag_Maps.Element (Pos);\n else\n return null;\n end if;\n end Get_Tags;\n\n -- ------------------------------\n -- Get the list of tags associated with the given entity.\n -- Returns a null object if the entity does not have any tag.\n -- ------------------------------\n function Get_Tags (From : in Entity_Tag_Map;\n For_Entity : in ADO.Identifier)\n return Util.Beans.Objects.Object is\n Pos : constant Entity_Tag_Maps.Cursor := From.Tags.Find (For_Entity);\n begin\n if Entity_Tag_Maps.Has_Element (Pos) then\n return Util.Beans.Objects.To_Object (Value => Entity_Tag_Maps.Element (Pos).all'Access,\n Storage => Util.Beans.Objects.STATIC);\n else\n return Util.Beans.Objects.Null_Object;\n end if;\n end Get_Tags;\n\n -- ------------------------------\n -- Load the list of tags associated with a list of entities.\n -- ------------------------------\n procedure Load_Tags (Into : in out Entity_Tag_Map;\n Session : in out ADO.Sessions.Session'Class;\n Entity_Type : in String;\n List : in ADO.Utils.Identifier_Vector) is\n Query : ADO.Queries.Context;\n Kind : ADO.Entity_Type;\n begin\n Into.Clear;\n if List.Is_Empty then\n return;\n end if;\n Kind := ADO.Sessions.Entities.Find_Entity_Type (Session, Entity_Type);\n Query.Set_Query (AWA.Tags.Models.Query_Tag_List_For_Entities);\n Query.Bind_Param (\"entity_id_list\", List);\n Query.Bind_Param (\"entity_type\", Kind);\n declare\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n Id : ADO.Identifier;\n List : Util.Beans.Lists.Strings.List_Bean_Access;\n Pos : Entity_Tag_Maps.Cursor;\n begin\n Stmt.Execute;\n while Stmt.Has_Elements loop\n Id := Stmt.Get_Identifier (0);\n Pos := Into.Tags.Find (Id);\n if not Entity_Tag_Maps.Has_Element (Pos) then\n List := new Util.Beans.Lists.Strings.List_Bean;\n Into.Tags.Insert (Id, List);\n else\n List := Entity_Tag_Maps.Element (Pos);\n end if;\n List.List.Append (Stmt.Get_String (1));\n Stmt.Next;\n end loop;" + }, + { + "function_def": "procedure Dispatch (List : in out Tag_Info_Array);", + "function_body": "-- ------------------------------\n -- Create an Tag_UIInput component\n -- ------------------------------\n function Create_Tag return ASF.Components.Base.UIComponent_Access is\n begin\n return new Tag_UIInput;\n end Create_Tag;\n\n -- ------------------------------\n -- Create an Tag_UICloud component\n -- ------------------------------\n function Create_Cloud return ASF.Components.Base.UIComponent_Access is\n begin\n return new Tag_UICloud;\n end Create_Cloud;\n\n URI : aliased constant String := \"http://code.google.com/p/ada-awa/jsf\";\n TAG_LIST_TAG : aliased constant String := \"tagList\";\n TAG_CLOUD_TAG : aliased constant String := \"tagCloud\";\n\n AWA_Bindings : aliased constant ASF.Factory.Binding_Array\n := (1 => (Name => TAG_CLOUD_TAG'Access,\n Component => Create_Cloud'Access,\n Tag => ASF.Views.Nodes.Create_Component_Node'Access),\n 2 => (Name => TAG_LIST_TAG'Access,\n Component => Create_Tag'Access,\n Tag => ASF.Views.Nodes.Create_Component_Node'Access)\n );\n\n AWA_Factory : aliased constant ASF.Factory.Factory_Bindings\n := (URI => URI'Access, Bindings => AWA_Bindings'Access);\n\n -- ------------------------------\n -- Get the Tags component factory.\n -- ------------------------------\n function Definition return ASF.Factory.Factory_Bindings_Access is\n begin\n return AWA_Factory'Access;\n end Definition;\n\n -- ------------------------------\n -- Returns True if the tag component must be rendered as readonly.\n -- ------------------------------\n function Is_Readonly (UI : in Tag_UIInput;\n Context : in ASF.Contexts.Faces.Faces_Context'Class) return Boolean is\n pragma Unreferenced (Context);\n use type ASF.Components.Html.Forms.UIForm_Access;\n begin\n return UI.Get_Form = null;\n end Is_Readonly;\n\n -- ------------------------------\n -- Render the javascript to enable the tag edition.\n -- ------------------------------\n procedure Render_Script (UI : in Tag_UIInput;\n Id : in String;\n Writer : in Response_Writer_Access;\n Context : in out ASF.Contexts.Faces.Faces_Context'Class) is\n Auto_Complete : constant String := UI.Get_Attribute (\"autoCompleteUrl\", Context);\n Allow_Edit : constant Boolean := UI.Get_Attribute (\"allowEdit\", Context);\n begin\n Writer.Queue_Script (\"$('#\");\n Writer.Queue_Script (Id);\n Writer.Queue_Script (\" input').tagedit({\");\n Writer.Queue_Script (\"allowEdit: \");\n if Allow_Edit then\n Writer.Queue_Script (\"true\");\n else\n Writer.Queue_Script (\"false\");\n end if;\n if Auto_Complete'Length > 0 then\n Writer.Queue_Script (\", autocompleteURL: '\");\n Writer.Queue_Script (Auto_Complete);\n Writer.Queue_Script (\"'\");\n end if;\n Writer.Queue_Script (\"});\");\n end Render_Script;\n\n -- ------------------------------\n -- Get the tag after convertion with the optional converter.\n -- ------------------------------\n function Get_Tag (UI : in Tag_UIInput;\n Tag : in Util.Beans.Objects.Object;\n Context : in ASF.Contexts.Faces.Faces_Context'Class) return String is\n begin\n if not Util.Beans.Objects.Is_Null (Tag) then\n declare\n Convert : constant access ASF.Converters.Converter'Class\n := Tag_UIInput'Class (UI).Get_Converter;\n begin\n if Convert /= null then\n return Convert.To_String (Value => Tag,\n Component => UI,\n Context => Context);\n else\n return Util.Beans.Objects.To_String (Value => Tag);\n end if;" + }, + { + "function_def": "procedure Dispatch (List : in out Tag_Info_Array) is", + "function_body": "Middle : constant Natural := List'First + List'Length / 2;\n Quarter : Natural := List'Length / 4;\n Target : Natural := Middle;\n Pos : Natural := 0;\n begin\n while Target <= List'Last and List'First + Pos < Middle and Quarter /= 0 loop\n Swap (List (List'First + Pos), List (Target));\n Pos := Pos + 1;\n if Target <= Middle then\n Target := List'Last - Quarter;\n else\n Target := List'First + Quarter;\n Quarter := Quarter / 2;\n end if;\n end loop;\n end Dispatch;\n\n -- ------------------------------\n -- Render the tag cloud component.\n -- ------------------------------\n overriding\n procedure Encode_Children (UI : in Tag_UICloud;\n Context : in out ASF.Contexts.Faces.Faces_Context'Class) is\n\n procedure Free is\n new Ada.Unchecked_Deallocation (Object => Tag_Info_Array,\n Name => Tag_Info_Array_Access);\n\n Table : Tag_Info_Array_Access := null;\n begin\n if not UI.Is_Rendered (Context) then\n return;\n end if;\n\n declare\n use type Util.Beans.Basic.List_Bean_Access;\n\n Max : constant Integer := UI.Get_Attribute (\"rows\", Context, 1000);\n Layout : constant String := UI.Get_Attribute (\"layout\", Context);\n Bean : constant Util.Beans.Basic.List_Bean_Access\n := ASF.Components.Utils.Get_List_Bean (UI, \"value\", Context);\n Count : Natural;\n Tags : AWA.Tags.Beans.Tag_Ordered_Sets.Set;\n List : AWA.Tags.Beans.Tag_Info_List_Bean_Access;\n begin\n -- Check that we have a List_Bean but do not complain if we have a null value.\n if Bean = null or Max <= 0 then\n return;\n end if;\n\n if not (Bean.all in AWA.Tags.Beans.Tag_Info_List_Bean'Class) then\n ASF.Components.Base.Log_Error (UI, \"Invalid tag list bean: it does not \"\n & \"implement 'Tag_Info_List_Bean' interface\");\n return;\n end if;\n\n List := AWA.Tags.Beans.Tag_Info_List_Bean'Class (Bean.all)'Unchecked_Access;\n Count := List.Get_Count;\n if Count = 0 then\n return;\n end if;\n\n -- Pass 1: Collect the tags and keep the most used.\n for I in 1 .. Count loop\n Tags.Insert (List.List.Element (I - 1));\n if Integer (Tags.Length) > Max then\n Tags.Delete_Last;\n end if;\n end loop;\n\n Count := Natural (Tags.Length);\n Table := new Tag_Info_Array (1 .. Count);\n for I in 1 .. Count loop\n Table (I) := Tags.First_Element;\n Tags.Delete_First;\n end loop;\n\n -- Pass 2: Assign weight to each tag.\n UI.Compute_Cloud_Weight (Table.all, Context);\n\n -- Pass 3: Dispatch the tags using some layout algorithm.\n if Layout = \"dispatch\" then\n Dispatch (Table.all);\n end if;\n\n -- Pass 4: Render each tag.\n UI.Render_Cloud (Table.all, Context);\n\n Free (Table);\n\n exception\n when others =>\n Free (Table);\n raise;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Tag_Impl, Tag_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Tag_Impl_Ptr := Tag_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Tag_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TAG_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Tag_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Tag_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (TAG_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Tag_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TAG_DEF'Access);\n begin\n Stmt.Execute;\n Tag_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Tag_Ref;\n Impl : constant Tag_Access := new Tag_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Tagged_Entity_Impl, Tagged_Entity_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Tagged_Entity_Impl_Ptr := Tagged_Entity_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Tagged_Entity_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TAGGED_ENTITY_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Tagged_Entity_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Tagged_Entity_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (TAGGED_ENTITY_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- for_entity_id\n Value => Object.For_Entity_Id);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- tag_id\n Value => Object.Tag);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Tagged_Entity_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TAGGED_ENTITY_DEF'Access);\n begin\n Stmt.Execute;\n Tagged_Entity_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Tagged_Entity_Ref;\n Impl : constant Tagged_Entity_Access := new Tagged_Entity_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "function Create_Tag_List_Bean (Module : in Tag_Module_Access)", + "function_body": "return AWA.Tags.Beans.Tag_List_Bean_Access;\n\n procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is\n begin\n Caller.Add_Test (Suite, \"Test AWA.Tags.Modules.Add_Tag\",\n Test_Add_Tag'Access);\n Caller.Add_Test (Suite, \"Test AWA.Tags.Modules.Remove_Tag\",\n Test_Remove_Tag'Access);\n Caller.Add_Test (Suite, \"Test AWA.Tags.Modules.Update_Tags\",\n Test_Remove_Tag'Access);\n end Add_Tests;\n\n function Create_Tag_List_Bean (Module : in Tag_Module_Access)\n return AWA.Tags.Beans.Tag_List_Bean_Access is\n Bean : constant Util.Beans.Basic.Readonly_Bean_Access\n := AWA.Tags.Beans.Create_Tag_List_Bean (Module);\n begin\n return AWA.Tags.Beans.Tag_List_Bean'Class (Bean.all)'Access;\n end Create_Tag_List_Bean;\n\n -- ------------------------------\n -- Test tag creation.\n -- ------------------------------\n procedure Test_Add_Tag (T : in out Test) is\n Sec_Ctx : Security.Contexts.Security_Context;\n Context : AWA.Services.Contexts.Service_Context;\n begin\n AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, \"test-add-tag@test.com\");\n\n declare\n Tag_Manager : constant Tag_Module_Access := Get_Tag_Module;\n User : constant AWA.Users.Models.User_Ref := Context.Get_User;\n List : AWA.Tags.Beans.Tag_List_Bean_Access;\n Cleanup : Util.Beans.Objects.Object;\n begin\n T.Assert (Tag_Manager /= null, \"There is no tag module\");\n\n List := Create_Tag_List_Bean (Tag_Manager);\n Cleanup := Util.Beans.Objects.To_Object (List.all'Access);\n List.Set_Value (\"entity_type\", Util.Beans.Objects.To_Object (String '(\"awa_user\")));\n\n -- Create a tag.\n Tag_Manager.Add_Tag (User.Get_Id, \"awa_user\", \"workspaces-create\", \"user-tag\");\n Tag_Manager.Add_Tag (User.Get_Id, \"awa_user\", \"workspaces-create\", \"user-tag\");\n\n -- Load the list.\n List.Load_Tags (Tag_Manager.Get_Session, User.Get_Id);\n\n Util.Tests.Assert_Equals (T, 1, Integer (List.Get_Count), \"Invalid number of tags\");\n T.Assert (not Util.Beans.Objects.Is_Null (Cleanup), \"Cleanup instance is null\");" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Image_Impl, Image_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Image_Impl_Ptr := Image_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Image_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, IMAGE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Image_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Image_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (IMAGE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- width\n Value => Object.Width);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- height\n Value => Object.Height);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- thumb_width\n Value => Object.Thumb_Width);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- thumb_height\n Value => Object.Thumb_Height);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- path\n Value => Object.Path);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- public\n Value => Object.Public);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- thumbnail_id\n Value => Object.Thumbnail);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_1_NAME, -- folder_id\n Value => Object.Folder);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_1_NAME, -- owner_id\n Value => Object.Owner);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_1_NAME, -- storage_id\n Value => Object.Storage);\n Object.Clear_Modified (12);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Image_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, IMAGE_DEF'Access);\n begin\n Stmt.Execute;\n Image_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Image_Ref;\n Impl : constant Image_Access := new Image_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "function Get is new AWA.Modules.Get (Question_Module, Question_Module_Access, NAME);", + "function_body": "begin\n return Get;\n end Get_Question_Module;\n\n -- ------------------------------\n -- Create or save the question.\n -- ------------------------------\n procedure Save_Question (Model : in Question_Module;\n Question : in out AWA.Questions.Models.Question_Ref'Class) is\n pragma Unreferenced (Model);\n\n function To_Wide (Item : in String) return Wide_Wide_String\n renames Ada.Characters.Conversions.To_Wide_Wide_String;\n\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n WS : AWA.Workspaces.Models.Workspace_Ref;\n begin\n Ctx.Start;\n if Question.Is_Inserted then\n Log.Info (\"Updating question {0}\", ADO.Identifier'Image (Question.Get_Id));\n\n WS := AWA.Workspaces.Models.Workspace_Ref (Question.Get_Workspace);\n else\n Log.Info (\"Creating new question {0}\", String '(Question.Get_Title));\n\n AWA.Workspaces.Modules.Get_Workspace (DB, Ctx, WS);\n\n -- Check that the user has the create permission on the given workspace.\n AWA.Permissions.Check (Permission => ACL_Create_Questions.Permission,\n Entity => WS);\n Question.Set_Workspace (WS);\n Question.Set_Author (User);\n end if;\n\n declare\n Text : constant String := Wiki.Utils.To_Text (To_Wide (Question.Get_Description),\n Wiki.SYNTAX_MIX);\n Last : Natural;\n begin\n if Text'Length < SHORT_DESCRIPTION_LENGTH then\n Last := Text'Last;\n else\n Last := SHORT_DESCRIPTION_LENGTH;\n end if;\n Question.Set_Short_Description (Text (Text'First .. Last) & \"...\");" + }, + { + "function_def": "procedure Load_List (Into : in out Question_List_Bean) is", + "function_body": "use AWA.Questions.Models;\n use AWA.Services;\n use type ADO.Identifier;\n\n Session : ADO.Sessions.Session := Into.Service.Get_Session;\n Query : ADO.Queries.Context;\n Tag_Id : ADO.Identifier;\n begin\n AWA.Tags.Modules.Find_Tag_Id (Session, Ada.Strings.Unbounded.To_String (Into.Tag), Tag_Id);\n if Tag_Id /= ADO.NO_IDENTIFIER then\n Query.Set_Query (AWA.Questions.Models.Query_Question_Tag_List);\n Query.Bind_Param (Name => \"tag\", Value => Tag_Id);\n else\n Query.Set_Query (AWA.Questions.Models.Query_Question_List);\n end if;\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Questions.Models.QUESTION_TABLE,\n Session => Session);\n AWA.Questions.Models.List (Into.Questions, Session, Query);\n declare\n List : ADO.Utils.Identifier_Vector;\n Iter : Question_Info_Vectors.Cursor := Into.Questions.List.First;\n begin\n while Question_Info_Vectors.Has_Element (Iter) loop\n List.Append (Question_Info_Vectors.Element (Iter).Id);\n Question_Info_Vectors.Next (Iter);\n end loop;\n Into.Tags.Load_Tags (Session, AWA.Questions.Models.QUESTION_TABLE.Table.all,\n List);" + }, + { + "function_def": "function Create_Question_List_Bean (Module : in AWA.Questions.Modules.Question_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n use AWA.Questions.Models;\n use AWA.Services;\n\n Object : constant Question_List_Bean_Access := new Question_List_Bean;\n-- Session : ADO.Sessions.Session := Module.Get_Session;\n-- Query : ADO.Queries.Context;\n begin\n Object.Service := Module;\n Object.Questions_Bean := Object.Questions'Unchecked_Access;\n-- Query.Set_Query (AWA.Questions.Models.Query_Question_List);\n-- ADO.Sessions.Entities.Bind_Param (Params => Query,\n-- Name => \"entity_type\",\n-- Table => AWA.Questions.Models.QUESTION_TABLE,\n-- Session => Session);\n-- AWA.Questions.Models.List (Object.Questions, Session, Query);\n Object.Load_List;\n return Object.all'Access;\n end Create_Question_List_Bean;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Question_Display_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"answers\" then\n return Util.Beans.Objects.To_Object (Value => From.Answer_List_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"question\" then\n return Util.Beans.Objects.To_Object (Value => From.Question_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"tags\" then\n return Util.Beans.Objects.To_Object (Value => From.Tags_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n else\n return Util.Beans.Objects.Null_Object;\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Question_Display_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n if Name = \"id\" and not Util.Beans.Objects.Is_Empty (Value) then\n declare\n package ASC renames AWA.Services.Contexts;\n use AWA.Questions.Models;\n use AWA.Services;\n\n Session : ADO.Sessions.Session := From.Service.Get_Session;\n Query : ADO.Queries.Context;\n List : AWA.Questions.Models.Question_Display_Info_List_Bean;\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value);\n begin\n Query.Set_Query (AWA.Questions.Models.Query_Question_Info);\n Query.Bind_Param (\"question_id\", Id);\n Query.Bind_Param (\"user_id\", Ctx.Get_User_Identifier);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Questions.Models.QUESTION_TABLE,\n Session => Session);\n AWA.Questions.Models.List (List, Session, Query);\n if not List.List.Is_Empty then\n From.Question := List.List.Element (0);\n end if;\n Query.Clear;\n Query.Bind_Param (\"question_id\", Util.Beans.Objects.To_Integer (Value));\n Query.Bind_Param (\"user_id\", Ctx.Get_User_Identifier);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Questions.Models.ANSWER_TABLE,\n Session => Session);\n\n Query.Set_Query (AWA.Questions.Models.Query_Answer_List);\n AWA.Questions.Models.List (From.Answer_List, Session, Query);\n\n -- Load the tags if any.\n From.Tags.Load_Tags (Session, Id);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Question_Impl, Question_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Question_Impl_Ptr := Question_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Question_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, QUESTION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Question_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Question_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (QUESTION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- title\n Value => Object.Title);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- description\n Value => Object.Description);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- edit_date\n Value => Object.Edit_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- short_description\n Value => Object.Short_Description);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- rating\n Value => Object.Rating);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- author_id\n Value => Object.Author);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_1_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_1_NAME, -- accepted_answer_id\n Value => Object.Accepted_Answer);\n Object.Clear_Modified (11);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Answer_Impl, Answer_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Answer_Impl_Ptr := Answer_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Answer_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ANSWER_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Answer_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Answer_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (ANSWER_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- edit_date\n Value => Object.Edit_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- answer\n Value => Object.Answer);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- rank\n Value => Object.Rank);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_2_NAME, -- author_id\n Value => Object.Author);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_2_NAME, -- question_id\n Value => Object.Question);\n Object.Clear_Modified (8);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Rating_Impl, Rating_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Rating_Impl_Ptr := Rating_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Rating_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, RATING_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Rating_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Rating_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (RATING_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- rating\n Value => Object.Rating);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- vote_count\n Value => Object.Vote_Count);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- for_entity_id\n Value => Object.For_Entity_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- for_entity_type\n Value => Object.For_Entity_Type);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Vote_Impl, Vote_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Vote_Impl_Ptr := Vote_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Vote_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, VOTE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Vote_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"user_id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Vote_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (VOTE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- rating\n Value => Object.Rating);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- entity_id\n Value => Object.Entity);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- user_id\n Value => Object.Get_Key);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"user_id = ? AND entity_id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Entity);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Finish (From : in out Application;", + "function_body": "Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n begin\n Log.Info (\"Finish configuration\");\n From.Save (Outcome);\n From.Status.Set (STARTING);\n end Finish;\n\n -- ------------------------------\n -- This bean provides some methods that can be used in a Method_Expression\n -- ------------------------------\n overriding\n function Get_Method_Bindings (From : in Application)\n return Util.Beans.Methods.Method_Binding_Array_Access is\n pragma Unreferenced (From);\n begin\n return Binding_Array'Access;\n end Get_Method_Bindings;\n\n -- ------------------------------\n -- Enter in the application setup\n -- ------------------------------\n procedure Setup (App : in out Application;\n Config : in String;\n Server : in out ASF.Server.Container'Class) is\n Path : constant String := AWA.Applications.Configs.Get_Config_Path (Config);\n Dir : constant String := Ada.Directories.Containing_Directory (Path);\n Done : constant String := Ada.Directories.Compose (Dir, \".initialized\");\n begin\n Log.Info (\"Entering configuration for {0}\", Path);\n App.Path := Ada.Strings.Unbounded.To_Unbounded_String (Path);\n begin\n App.Config.Load_Properties (Path);\n Util.Log.Loggers.Initialize (Path);\n\n exception\n when Ada.IO_Exceptions.Name_Error =>\n Log.Error (\"Cannot read application configuration file: {0}\", Path);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Changelog_Impl, Changelog_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Changelog_Impl_Ptr := Changelog_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Changelog_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, CHANGELOG_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Changelog_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Changelog_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (CHANGELOG_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- date\n Value => Object.Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- text\n Value => Object.Text);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- for_entity_id\n Value => Object.For_Entity_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (6);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Status_Type);\n Impl : Comment_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 7, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Comment_Ref)\n return AWA.Comments.Models.Status_Type is\n Impl : constant Comment_Access\n := Comment_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Format (Object : in out Comment_Ref;\n Value : in AWA.Comments.Models.Format_Type) is\n procedure Set_Field_Enum is\n new ADO.Objects.Set_Field_Operation (Format_Type);\n Impl : Comment_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 8, Impl.Format, Value);\n end Set_Format;\n\n function Get_Format (Object : in Comment_Ref)\n return AWA.Comments.Models.Format_Type is\n Impl : constant Comment_Access\n := Comment_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Format;\n end Get_Format;\n\n\n procedure Set_Author (Object : in out Comment_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Comment_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.Author, Value);\n end Set_Author;\n\n function Get_Author (Object : in Comment_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Comment_Access\n := Comment_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Author;\n end Get_Author;\n\n -- Copy of the object.\n procedure Copy (Object : in Comment_Ref;\n Into : in out Comment_Ref) is\n Result : Comment_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Comment_Access\n := Comment_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Comment_Access\n := new Comment_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Create_Date := Impl.Create_Date;\n Copy.Message := Impl.Message;\n Copy.Entity_Id := Impl.Entity_Id;\n Copy.Version := Impl.Version;\n Copy.Entity_Type := Impl.Entity_Type;\n Copy.Status := Impl.Status;\n Copy.Format := Impl.Format;\n Copy.Author := Impl.Author;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Comment_Impl, Comment_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Comment_Impl_Ptr := Comment_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Comment_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, COMMENT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Comment_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Comment_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (COMMENT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- message\n Value => Object.Message);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- entity_id\n Value => Object.Entity_Id);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- status\n Value => Integer (Status_Type'Pos (Object.Status)));\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- format\n Value => Integer (Format_Type'Pos (Object.Format)));\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- author_id\n Value => Object.Author);\n Object.Clear_Modified (9);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List_Comments (T : in out Test;", + "function_body": "User : in ADO.Identifier;\n Into : out Util.Beans.Objects.Object) is\n Comment_Manager : constant Comment_Module_Access := Get_Comment_Module;\n Bean : Util.Beans.Basic.Readonly_Bean_Access;\n List : AWA.Comments.Beans.Comment_List_Bean_Access;\n begin\n Bean := Beans.Create_Comment_List_Bean (Comment_Manager);\n Into := Util.Beans.Objects.To_Object (Bean.all'Access);\n List := AWA.Comments.Beans.Comment_List_Bean'Class (Bean.all)'Access;\n List.Set_Value (\"entity_type\", Util.Beans.Objects.To_Object (String '(\"awa_user\")));\n Util.Tests.Assert_Equals (T, 0, Integer (List.Get_Count), \"Invalid number of comments\");\n\n -- Load the existing comments.\n List.Load_Comments (User);\n end List_Comments;\n\n -- ------------------------------\n -- Create a comment and return the list of comments before and after the creation.\n -- ------------------------------\n procedure Create_Comment (T : in out Test;\n Status : in AWA.Comments.Models.Status_Type;\n Before : out Util.Beans.Objects.Object;\n After : out Util.Beans.Objects.Object;\n Id : out ADO.Identifier) is\n Sec_Ctx : Security.Contexts.Security_Context;\n Context : AWA.Services.Contexts.Service_Context;\n begin\n AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, \"test-add-comment@test.com\");\n\n declare\n Comment_Manager : constant Comment_Module_Access := Get_Comment_Module;\n User : constant AWA.Users.Models.User_Ref := Context.Get_User;\n Bean : Util.Beans.Basic.Readonly_Bean_Access;\n Comment : AWA.Comments.Beans.Comment_Bean_Access;\n Cleanup : Util.Beans.Objects.Object;\n Outcome : Ada.Strings.Unbounded.Unbounded_String;\n begin\n T.Assert (Comment_Manager /= null, \"There is no comment module\");\n\n T.List_Comments (User.Get_Id, Before);\n\n -- Create a new comment associated with the current user.\n Bean := Beans.Create_Comment_Bean (Comment_Manager);\n Cleanup := Util.Beans.Objects.To_Object (Bean.all'Access);\n Comment := AWA.Comments.Beans.Comment_Bean'Class (Bean.all)'Access;\n Comment.Set_Value (\"entity_type\", Util.Beans.Objects.To_Object (String '(\"awa_user\")));\n Comment.Set_Value (\"permission\", Util.Beans.Objects.To_Object (String '(\"logged-user\")));\n Comment.Set_Status (Status);\n Comment.Set_Entity_Id (User.Get_Id);\n\n -- Create the comment.\n Comment.Set_Message (\"the comment message for the current user \" &\n AWA.Comments.Models.Status_Type'Image (Status));\n Comment.Create (Outcome);\n Id := Comment.Get_Id;\n T.Assert (Id /= ADO.NO_IDENTIFIER, \"Invalid new comment identifier\");\n\n -- Load again the comments.\n T.List_Comments (User.Get_Id, After);\n T.Assert (not Util.Beans.Objects.Is_Null (Cleanup), \"Comment bean is null\");" + }, + { + "function_def": "procedure Test_Create_Published_Comment (T : in out Test) is", + "function_body": "Before : Util.Beans.Objects.Object;\n After : Util.Beans.Objects.Object;\n Id : ADO.Identifier;\n begin\n T.Create_Comment (AWA.Comments.Models.COMMENT_PUBLISHED, Before, After, Id);\n declare\n Before_Count : constant Natural := Get_Count (Before);\n After_Count : constant Natural := Get_Count (After);\n begin\n Util.Tests.Assert_Equals (T, Before_Count + 1, After_Count,\n \"The new comment does not appear in the list\");" + }, + { + "function_def": "procedure Test_Publish_Comment (T : in out Test) is", + "function_body": "Before : Util.Beans.Objects.Object;\n After : Util.Beans.Objects.Object;\n Sec_Ctx : Security.Contexts.Security_Context;\n Context : AWA.Services.Contexts.Service_Context;\n Id : ADO.Identifier;\n begin\n T.Create_Comment (AWA.Comments.Models.COMMENT_WAITING, Before, After, Id);\n Util.Tests.Assert_Equals (T, Get_Count (Before), Get_Count (After),\n \"The new comment MUST not be in the list\");\n\n -- Now, simulate a user that logs in and publishes the comment.\n AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, \"test-add-comment@test.com\");\n declare\n Comment_Manager : constant Comment_Module_Access := Get_Comment_Module;\n User : constant AWA.Users.Models.User_Ref := Context.Get_User;\n Comment : AWA.Comments.Beans.Comment_Bean;\n begin\n T.Assert (Comment_Manager /= null, \"There is no comment module\");\n\n Comment_Manager.Publish_Comment (\"logged-user\", Id, AWA.Comments.Models.COMMENT_PUBLISHED,\n Comment);\n T.Assert (not Comment.Is_Null, \"Comment bean is null\");\n\n T.List_Comments (User.Get_Id, After);" + }, + { + "function_def": "function Get is new AWA.Modules.Get (Setting_Module, Setting_Module_Access, NAME);", + "function_body": "begin\n return Get;\n end Get_Setting_Module;\n\n -- ------------------------------\n -- Load the setting value for the current user.\n -- Return the default value if there is no such setting.\n -- ------------------------------\n procedure Load (Name : in String;\n Default : in String;\n Value : out Ada.Strings.Unbounded.Unbounded_String) is\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Query : ADO.Queries.Context;\n Setting : AWA.Settings.Models.User_Setting_Ref;\n Found : Boolean;\n begin\n Query.Set_Join (\"INNER JOIN awa_setting AS a ON o.setting_id = a.id \");\n Query.Set_Filter (\"a.name = :name AND o.user_id = :user\");\n Query.Bind_Param (\"name\", Name);\n Query.Bind_Param (\"user\", User.Get_Id);\n Setting.Find (DB, Query, Found);\n if not Found then\n Value := Ada.Strings.Unbounded.To_Unbounded_String (Default);\n else\n Value := Setting.Get_Value;\n end if;\n end Load;\n\n -- Save the setting value for the current user.\n procedure Save (Name : in String;\n Value : in String) is\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Setting : AWA.Settings.Models.User_Setting_Ref;\n Query : ADO.Queries.Context;\n Found : Boolean;\n begin\n Ctx.Start;\n Query.Set_Join (\"INNER JOIN awa_setting AS a ON o.setting_id = a.id \");\n Query.Set_Filter (\"a.name = :name AND o.user_id = :user\");\n Query.Bind_Param (\"name\", Name);\n Query.Bind_Param (\"user\", User.Get_Id);\n Setting.Find (DB, Query, Found);\n if not Found then\n declare\n Setting_Def : AWA.Settings.Models.Setting_Ref;\n begin\n Query.Clear;\n Query.Set_Filter (\"o.name = :name\");\n Query.Bind_Param (\"name\", Name);\n Setting_Def.Find (DB, Query, Found);\n if not Found then\n Setting_Def.Set_Name (Name);\n Setting_Def.Save (DB);\n end if;\n Setting.Set_Setting (Setting_Def);" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation (Object => Setting_Data,", + "function_body": "Name => Setting_Data_Access);\n\n use Ada.Strings.Unbounded;\n\n protected body Settings is\n\n procedure Get (Name : in String;\n Default : in String;\n Value : out Ada.Strings.Unbounded.Unbounded_String) is\n Item : Setting_Data_Access := First;\n Previous : Setting_Data_Access := null;\n begin\n while Item /= null loop\n if Item.Name = Name then\n Value := Item.Value;\n if Previous /= null then\n Previous.Next_Setting := Item.Next_Setting;\n First := Item;\n end if;\n return;\n end if;\n Previous := Item;\n Item := Item.Next_Setting;\n end loop;\n Load (Name, Default, Value);\n Item := new Setting_Data;\n Item.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);\n Item.Value := Value;\n Item.Next_Setting := First;\n First := Item;\n end Get;\n\n procedure Set (Name : in String;\n Value : in String) is\n Item : Setting_Data_Access := First;\n Previous : Setting_Data_Access := null;\n begin\n while Item /= null loop\n if Item.Name = Name then\n if Previous /= null then\n Previous.Next_Setting := Item.Next_Setting;\n First := Item;\n end if;\n if Item.Value = Value then\n return;\n end if;\n Item.Value := Ada.Strings.Unbounded.To_Unbounded_String (Value);\n Save (Name, Value);\n return;\n end if;\n Previous := Item;\n Item := Item.Next_Setting;\n end loop;\n Item := new Setting_Data;\n Item.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);\n Item.Value := Ada.Strings.Unbounded.To_Unbounded_String (Value);\n Item.Next_Setting := First;\n First := Item;\n Save (Name, Value);\n end Set;\n\n procedure Clear is\n begin\n while First /= null loop\n declare\n Item : Setting_Data_Access := First;\n begin\n First := Item.Next_Setting;\n Free (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Setting_Impl, Setting_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Setting_Impl_Ptr := Setting_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Setting_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SETTING_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Setting_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Setting_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SETTING_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Setting_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SETTING_DEF'Access);\n begin\n Stmt.Execute;\n Setting_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Setting_Ref;\n Impl : constant Setting_Access := new Setting_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Global_Setting_Impl, Global_Setting_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Global_Setting_Impl_Ptr := Global_Setting_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Global_Setting_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, GLOBAL_SETTING_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Global_Setting_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Global_Setting_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (GLOBAL_SETTING_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- value\n Value => Object.Value);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- server_id\n Value => Object.Server_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- setting_id\n Value => Object.Setting);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Global_Setting_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, GLOBAL_SETTING_DEF'Access);\n begin\n Stmt.Execute;\n Global_Setting_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Global_Setting_Ref;\n Impl : constant Global_Setting_Access := new Global_Setting_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(User_Setting_Impl, User_Setting_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : User_Setting_Impl_Ptr := User_Setting_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out User_Setting_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, USER_SETTING_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out User_Setting_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out User_Setting_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (USER_SETTING_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- value\n Value => Object.Value);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- setting_id\n Value => Object.Setting);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "function Create_From_Format is", + "function_body": "new AWA.Helpers.Selectors.Create_From_Enum (AWA.Wikis.Models.Format_Type,\n \"wiki_format_\");\n\n -- ------------------------------\n -- Get a select item list which contains a list of wiki formats.\n -- ------------------------------\n function Create_Format_List_Bean (Module : in AWA.Wikis.Modules.Wiki_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n pragma Unreferenced (Module);\n use AWA.Helpers;\n begin\n return Selectors.Create_Selector_Bean (Bundle => \"wikis\",\n Context => null,\n Create => Create_From_Format'Access).all'Access;\n end Create_Format_List_Bean;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Wiki_Space_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if From.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return AWA.Wikis.Models.Wiki_Space_Bean (From).Get_Value (Name);\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Wiki_Space_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n if Name /= \"id\" then\n AWA.Wikis.Models.Wiki_Space_Bean (From).Set_Value (Name, Value);\n elsif Name = \"id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Module.Load_Wiki_Space (From, ADO.Utils.To_Identifier (Value));\n end if;\n end Set_Value;\n\n -- ------------------------------\n -- Create or save the wiki space.\n -- ------------------------------\n overriding\n procedure Save (Bean : in out Wiki_Space_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n pragma Unreferenced (Outcome);\n begin\n if Bean.Is_Inserted then\n Bean.Module.Save_Wiki_Space (Bean);\n else\n Bean.Module.Create_Wiki_Space (Bean);\n end if;\n end Save;\n\n -- ------------------------------\n -- Load the wiki space information.\n -- ------------------------------\n overriding\n procedure Load (Bean : in out Wiki_Space_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n begin\n Bean.Module.Load_Wiki_Space (Bean, Bean.Get_Id);\n Outcome := Ada.Strings.Unbounded.To_Unbounded_String (\"loaded\");\n end Load;\n\n -- Delete the wiki space.\n procedure Delete (Bean : in out Wiki_Space_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n begin\n null;\n end Delete;\n\n -- ------------------------------\n -- Create the Wiki_Space_Bean bean instance.\n -- ------------------------------\n function Create_Wiki_Space_Bean (Module : in AWA.Wikis.Modules.Wiki_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Wiki_Space_Bean_Access := new Wiki_Space_Bean;\n begin\n Object.Module := Module;\n return Object.all'Access;\n end Create_Wiki_Space_Bean;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Wiki_Page_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"wiki_id\" then\n if From.Wiki_Space.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return ADO.Utils.To_Object (From.Wiki_Space.Get_Id);\n end if;\n elsif Name = \"text\" then\n if From.Has_Content then\n return Util.Beans.Objects.To_Object (From.New_Content);\n elsif From.Content.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return Util.Beans.Objects.To_Object (String '(From.Content.Get_Content));\n end if;\n elsif Name = \"date\" then\n if From.Content.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return From.Content.Get_Value (\"create_date\");\n end if;\n elsif Name = \"format\" then\n if not From.Content.Is_Null then\n return From.Content.Get_Value (\"format\");\n elsif not From.Wiki_Space.Is_Null then\n return From.Wiki_Space.Get_Value (\"format\");\n else\n return Util.Beans.Objects.Null_Object;\n end if;\n elsif Name = \"comment\" then\n if From.Content.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return Util.Beans.Objects.To_Object (String '(From.Content.Get_Save_Comment));\n end if;\n elsif Name = \"tags\" then\n return Util.Beans.Objects.To_Object (From.Tags_Bean, Util.Beans.Objects.STATIC);\n elsif Name = \"is_public\" then\n if not From.Is_Null then\n return AWA.Wikis.Models.Wiki_Page_Bean (From).Get_Value (Name);\n elsif not From.Wiki_Space.Is_Null then\n return From.Wiki_Space.Get_Value (Name);\n else\n return Util.Beans.Objects.Null_Object;\n end if;\n elsif From.Is_Null then\n return Util.Beans.Objects.Null_Object;\n else\n return AWA.Wikis.Models.Wiki_Page_Bean (From).Get_Value (Name);\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Wiki_Page_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n if Name = \"id\" then\n if not Util.Beans.Objects.Is_Empty (Value) then\n declare\n Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value);\n begin\n From.Module.Load_Page (From, From.Content, From.Tags, Id);" + }, + { + "function_def": "procedure Load_List (Into : in out Wiki_List_Bean) is", + "function_body": "use AWA.Wikis.Models;\n use AWA.Services;\n use type Ada.Strings.Unbounded.Unbounded_String;\n use type ADO.Identifier;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := Into.Module.Get_Session;\n Query : ADO.Queries.Context;\n Count_Query : ADO.Queries.Context;\n Tag_Id : ADO.Identifier;\n First : constant Natural := (Into.Page - 1) * Into.Page_Size;\n Tag : constant String := Ada.Strings.Unbounded.To_String (Into.Tag);\n begin\n if Into.Wiki_Id = ADO.NO_IDENTIFIER then\n return;\n end if;\n Into.Wiki_Space.Set_Id (Into.Wiki_Id);\n if Tag'Length > 0 then\n AWA.Tags.Modules.Find_Tag_Id (Session, Tag, Tag_Id);\n if Tag_Id = ADO.NO_IDENTIFIER then\n return;\n end if;\n Query.Set_Query (AWA.Wikis.Models.Query_Wiki_Page_Tag_List);\n Query.Bind_Param (Name => \"tag\", Value => Tag_Id);\n Count_Query.Set_Count_Query (AWA.Wikis.Models.Query_Wiki_Page_Tag_List);\n Count_Query.Bind_Param (Name => \"tag\", Value => Tag_Id);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"page_table\",\n Table => AWA.Wikis.Models.WIKI_PAGE_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Count_Query,\n Name => \"page_table\",\n Table => AWA.Wikis.Models.WIKI_PAGE_TABLE,\n Session => Session);\n else\n Query.Set_Query (AWA.Wikis.Models.Query_Wiki_Page_List);\n Count_Query.Set_Count_Query (AWA.Wikis.Models.Query_Wiki_Page_List);\n end if;\n if Into.Sort = \"name\" then\n Query.Bind_Param (Name => \"order1\",\n Value => ADO.Parameters.Token '(\"page.name\"));\n elsif Into.Sort = \"recent\" then\n Query.Bind_Param (Name => \"order1\",\n Value => ADO.Parameters.Token '(\"content.create_date DESC\"));\n elsif Into.Sort = \"popular\" then\n Query.Bind_Param (Name => \"order1\",\n Value => ADO.Parameters.Token '(\"page.read_count DESC\"));\n else\n return;\n end if;\n Query.Bind_Param (Name => \"first\", Value => First);\n Query.Bind_Param (Name => \"count\", Value => Into.Page_Size);\n Query.Bind_Param (Name => \"wiki_id\", Value => Into.Wiki_Id);\n Query.Bind_Param (Name => \"user_id\", Value => User);\n Count_Query.Bind_Param (Name => \"wiki_id\", Value => Into.Wiki_Id);\n Count_Query.Bind_Param (Name => \"user_id\", Value => User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Wikis.Models.WIKI_SPACE_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Count_Query,\n Name => \"table\",\n Table => AWA.Wikis.Models.WIKI_SPACE_TABLE,\n Session => Session);\n AWA.Wikis.Models.List (Into.Pages, Session, Query);\n Into.Count := ADO.Datasets.Get_Count (Session, Count_Query);\n declare\n List : ADO.Utils.Identifier_Vector;\n Iter : Wiki_Page_Info_Vectors.Cursor := Into.Pages.List.First;\n begin\n while Wiki_Page_Info_Vectors.Has_Element (Iter) loop\n List.Append (Wiki_Page_Info_Vectors.Element (Iter).Id);\n Wiki_Page_Info_Vectors.Next (Iter);\n end loop;\n Into.Tags.Load_Tags (Session, AWA.Wikis.Models.WIKI_PAGE_TABLE.Table.all,\n List);" + }, + { + "function_def": "function Create_Wiki_List_Bean (Module : in AWA.Wikis.Modules.Wiki_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Wiki_List_Bean_Access := new Wiki_List_Bean;\n begin\n Object.Module := Module;\n Object.Pages_Bean := Object.Pages'Access;\n Object.Page_Size := 20;\n Object.Page := 1;\n Object.Count := 0;\n Object.Wiki_Id := ADO.NO_IDENTIFIER;\n Object.Wiki_Space := Get_Wiki_Space_Bean (\"adminWikiSpace\");\n return Object.all'Access;\n end Create_Wiki_List_Bean;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Wiki_Version_List_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"versions\" then\n return Util.Beans.Objects.To_Object (Value => From.Versions_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"page_count\" then\n return Util.Beans.Objects.To_Object ((From.Count + From.Page_Size - 1) / From.Page_Size);\n else\n return AWA.Wikis.Models.Wiki_Version_List_Bean (From).Get_Value (Name);\n end if;\n end Get_Value;\n\n -- ------------------------------\n -- Set the value identified by the name.\n -- ------------------------------\n overriding\n procedure Set_Value (From : in out Wiki_Version_List_Bean;\n Name : in String;\n Value : in Util.Beans.Objects.Object) is\n begin\n if Name = \"page\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Page := Util.Beans.Objects.To_Integer (Value);\n elsif Name = \"wiki_id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Wiki_Id := ADO.Utils.To_Identifier (Value);\n elsif Name = \"page_id\" and not Util.Beans.Objects.Is_Empty (Value) then\n From.Page_Id := ADO.Utils.To_Identifier (Value);\n end if;\n\n exception\n when Constraint_Error =>\n From.Wiki_Id := ADO.NO_IDENTIFIER;\n From.Page_Id := ADO.NO_IDENTIFIER;\n\n end Set_Value;\n\n overriding\n procedure Load (Into : in out Wiki_Version_List_Bean;\n Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is\n use AWA.Wikis.Models;\n use AWA.Services;\n use type ADO.Identifier;\n use type Ada.Strings.Unbounded.Unbounded_String;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := Into.Module.Get_Session;\n Query : ADO.Queries.Context;\n Count_Query : ADO.Queries.Context;\n First : constant Natural := (Into.Page - 1) * Into.Page_Size;\n Page : constant Wiki_View_Bean_Access := Get_Wiki_View_Bean (\"wikiView\");\n begin\n if Into.Wiki_Id = ADO.NO_IDENTIFIER or Into.Page_Id = ADO.NO_IDENTIFIER then\n return;\n end if;\n\n -- Load the wiki page first.\n Page.Id := Into.Page_Id;\n Page.Set_Wiki_Id (Into.Wiki_Id);\n Page.Load (Outcome);\n if Outcome /= \"loaded\" then\n return;\n end if;\n Page.Wiki_Space.Set_Id (Into.Wiki_Id);\n\n -- Get the list of versions associated with the wiki page.\n Query.Set_Query (AWA.Wikis.Models.Query_Wiki_Version_List);\n Count_Query.Set_Count_Query (AWA.Wikis.Models.Query_Wiki_Version_List);\n Query.Bind_Param (Name => \"first\", Value => First);\n Query.Bind_Param (Name => \"count\", Value => Into.Page_Size);\n Query.Bind_Param (Name => \"wiki_id\", Value => Into.Wiki_Id);\n Query.Bind_Param (Name => \"page_id\", Value => Into.Page_Id);\n Query.Bind_Param (Name => \"user_id\", Value => User);\n Count_Query.Bind_Param (Name => \"wiki_id\", Value => Into.Wiki_Id);\n Count_Query.Bind_Param (Name => \"page_id\", Value => Into.Page_Id);\n Count_Query.Bind_Param (Name => \"user_id\", Value => User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Wikis.Models.WIKI_SPACE_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Count_Query,\n Name => \"table\",\n Table => AWA.Wikis.Models.WIKI_SPACE_TABLE,\n Session => Session);\n AWA.Wikis.Models.List (Into.Versions, Session, Query);\n Into.Count := ADO.Datasets.Get_Count (Session, Count_Query);\n end Load;\n\n -- ------------------------------\n -- Create the Post_List_Bean bean instance.\n -- ------------------------------\n function Create_Wiki_Version_List_Bean (Module : in AWA.Wikis.Modules.Wiki_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Wiki_Version_List_Bean_Access := new Wiki_Version_List_Bean;\n begin\n Object.Module := Module;\n Object.Versions_Bean := Object.Versions'Access;\n Object.Page_Size := 20;\n Object.Page := 1;\n Object.Count := 0;\n Object.Wiki_Id := ADO.NO_IDENTIFIER;\n Object.Page_Id := ADO.NO_IDENTIFIER;\n return Object.all'Access;\n end Create_Wiki_Version_List_Bean;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- ------------------------------\n overriding\n function Get_Value (From : in Wiki_Page_Info_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"words\" then\n return Util.Beans.Objects.To_Object (Value => From.Words_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"pages\" then\n return Util.Beans.Objects.To_Object (Value => From.Links_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"links\" then\n return Util.Beans.Objects.To_Object (Value => From.Ext_Links_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"images\" then\n return Util.Beans.Objects.To_Object (Value => From.Page.Links_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"templates\" then\n return Util.Beans.Objects.To_Object (Value => From.Page.Plugins_Bean,\n Storage => Util.Beans.Objects.STATIC);\n elsif Name = \"imageThumbnail\" then\n declare\n URI : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;\n W : Natural := 64;\n H : Natural := 64;\n begin\n if Image_Info_Maps.Has_Element (From.Page.Links.Pos) then\n From.Page.Links.Make_Image_Link\n (Link => Image_Info_Maps.Key (From.Page.Links.Pos),\n Info => Image_Info_Maps.Element (From.Page.Links.Pos),\n URI => URI,\n Width => W,\n Height => H);\n end if;\n return Util.Beans.Objects.To_Object (URI);" + }, + { + "function_def": "procedure Load_Wikis (List : in Wiki_Admin_Bean) is", + "function_body": "use AWA.Wikis.Models;\n use AWA.Services;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := List.Module.Get_Session;\n Query : ADO.Queries.Context;\n begin\n Query.Set_Query (AWA.Wikis.Models.Query_Wiki_List);\n Query.Bind_Param (\"user_id\", User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Wikis.Models.WIKI_SPACE_TABLE,\n Session => Session);\n AWA.Wikis.Models.List (List.Wiki_List_Bean.all, Session, Query);\n List.Flags (INIT_WIKI_LIST) := True;\n end Load_Wikis;\n\n -- ------------------------------\n -- Get the wiki space identifier.\n -- ------------------------------\n function Get_Wiki_Id (List : in Wiki_Admin_Bean) return ADO.Identifier is\n use type ADO.Identifier;\n begin\n if List.Wiki_Id = ADO.NO_IDENTIFIER then\n if not List.Flags (INIT_WIKI_LIST) then\n Load_Wikis (List);\n end if;\n if not List.Wiki_List.List.Is_Empty then\n return List.Wiki_List.List.Element (0).Id;\n end if;\n end if;\n return List.Wiki_Id;\n end Get_Wiki_Id;\n\n overriding\n function Get_Value (List : in Wiki_Admin_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"wikis\" then\n if not List.Init_Flags (INIT_WIKI_LIST) then\n Load_Wikis (List);\n end if;\n return Util.Beans.Objects.To_Object (Value => List.Wiki_List_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"id\" then\n declare\n use type ADO.Identifier;\n\n Id : constant ADO.Identifier := List.Get_Wiki_Id;\n begin\n if Id = ADO.NO_IDENTIFIER then\n return Util.Beans.Objects.Null_Object;\n else\n return Util.Beans.Objects.To_Object (Long_Long_Integer (Id));\n end if;" + }, + { + "function_def": "function Get is new AWA.Modules.Get (Wiki_Module, Wiki_Module_Access, NAME);", + "function_body": "begin\n return Get;\n end Get_Wiki_Module;\n\n -- ------------------------------\n -- Create the wiki space.\n -- ------------------------------\n procedure Create_Wiki_Space (Module : in Wiki_Module;\n Wiki : in out AWA.Wikis.Models.Wiki_Space_Ref'Class) is\n\n procedure Copy_Page (Item : in String;\n Done : out Boolean);\n\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n WS : AWA.Workspaces.Models.Workspace_Ref;\n\n procedure Copy_Page (Item : in String;\n Done : out Boolean) is\n begin\n Module.Copy_Page (DB, Wiki, ADO.Identifier'Value (Item));\n Done := False;\n\n exception\n when Constraint_Error =>\n Log.Error (\"Invalid configuration wiki page id {0}\", Item);\n\n end Copy_Page;\n\n begin\n Log.Info (\"Creating new wiki space {0}\", String '(Wiki.Get_Name));\n\n Ctx.Start;\n AWA.Workspaces.Modules.Get_Workspace (DB, Ctx, WS);\n\n -- Check that the user has the create permission on the given workspace.\n AWA.Permissions.Check (Permission => ACL_Create_Wiki_Space.Permission,\n Entity => WS);\n Wiki.Set_Workspace (WS);\n Wiki.Set_Create_Date (Ada.Calendar.Clock);\n Wiki.Save (DB);\n\n -- Add the permission for the user to use the new wiki space.\n AWA.Workspaces.Modules.Add_Permission (Session => DB,\n User => User,\n Entity => Wiki,\n Workspace => WS.Get_Id,\n List => (ACL_Update_Wiki_Space.Permission,\n ACL_Delete_Wiki_Space.Permission,\n ACL_Create_Wiki_Pages.Permission,\n ACL_Delete_Wiki_Pages.Permission,\n ACL_Update_Wiki_Pages.Permission,\n ACL_View_Wiki_Page.Permission));\n\n Util.Strings.Tokenizers.Iterate_Tokens (Content => Module.Get_Config (PARAM_WIKI_COPY_LIST),\n Pattern => \",\",\n Process => Copy_Page'Access,\n Going => Ada.Strings.Forward);\n\n Ctx.Commit;\n\n Log.Info (\"Wiki {0} created for user {1}\",\n ADO.Identifier'Image (Wiki.Get_Id), ADO.Identifier'Image (User));\n end Create_Wiki_Space;\n\n -- ------------------------------\n -- Save the wiki space.\n -- ------------------------------\n procedure Save_Wiki_Space (Module : in Wiki_Module;\n Wiki : in out AWA.Wikis.Models.Wiki_Space_Ref'Class) is\n pragma Unreferenced (Module);\n\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n begin\n Log.Info (\"Updating wiki space {0}\", String '(Wiki.Get_Name));\n\n Ctx.Start;\n\n -- Check that the user has the update permission on the given wiki space.\n AWA.Permissions.Check (Permission => ACL_Update_Wiki_Space.Permission,\n Entity => Wiki);\n Wiki.Save (DB);\n Ctx.Commit;\n end Save_Wiki_Space;\n\n -- ------------------------------\n -- Load the wiki space.\n -- ------------------------------\n procedure Load_Wiki_Space (Module : in Wiki_Module;\n Wiki : in out AWA.Wikis.Models.Wiki_Space_Ref'Class;\n Id : in ADO.Identifier) is\n pragma Unreferenced (Module);\n\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Session := AWA.Services.Contexts.Get_Session (Ctx);\n Found : Boolean;\n begin\n Wiki.Load (DB, Id, Found);\n end Load_Wiki_Space;\n\n -- ------------------------------\n -- Create the wiki page into the wiki space.\n -- ------------------------------\n procedure Create_Wiki_Page (Model : in Wiki_Module;\n Into : in AWA.Wikis.Models.Wiki_Space_Ref'Class;\n Page : in out AWA.Wikis.Models.Wiki_Page_Ref'Class;\n Content : in out AWA.Wikis.Models.Wiki_Content_Ref'Class) is\n begin\n Log.Info (\"Create wiki page {0}\", String '(Page.Get_Name));\n\n -- Check that the user has the create wiki page permission on the given wiki space.\n AWA.Permissions.Check (Permission => ACL_Create_Wiki_Pages.Permission,\n Entity => Into);\n\n Page.Set_Wiki (Into);\n Model.Save_Wiki_Content (Page, Content);\n end Create_Wiki_Page;\n\n -- ------------------------------\n -- Save the wiki page.\n -- ------------------------------\n procedure Save (Model : in Wiki_Module;\n Page : in out AWA.Wikis.Models.Wiki_Page_Ref'Class) is\n pragma Unreferenced (Model);\n\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n begin\n -- Check that the user has the update wiki page permission on the given wiki space.\n AWA.Permissions.Check (Permission => ACL_Update_Wiki_Pages.Permission,\n Entity => Page);\n\n Ctx.Start;\n Page.Save (DB);\n Ctx.Commit;\n end Save;\n\n -- ------------------------------\n -- Delete the wiki page as well as all its versions.\n -- ------------------------------\n procedure Delete (Model : in Wiki_Module;\n Page : in out AWA.Wikis.Models.Wiki_Page_Ref'Class) is\n Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n begin\n -- Check that the user has the delete wiki page permission on the given wiki page.\n AWA.Permissions.Check (Permission => ACL_Delete_Wiki_Pages.Permission,\n Entity => Page);\n\n Ctx.Start;\n\n -- Before deleting the wiki page, delete the version content.\n declare\n Stmt : ADO.Statements.Delete_Statement\n := DB.Create_Statement (AWA.Wikis.Models.WIKI_CONTENT_TABLE);\n begin\n Stmt.Set_Filter (Filter => \"page_id = ?\");\n Stmt.Add_Param (Value => Page);\n Stmt.Execute;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Format_Type);\n Impl : Wiki_Space_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 8, Impl.Format, Value);\n end Set_Format;\n\n function Get_Format (Object : in Wiki_Space_Ref)\n return AWA.Wikis.Models.Format_Type is\n Impl : constant Wiki_Space_Access\n := Wiki_Space_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Format;\n end Get_Format;\n\n\n procedure Set_Workspace (Object : in out Wiki_Space_Ref;\n Value : in AWA.Workspaces.Models.Workspace_Ref'Class) is\n Impl : Wiki_Space_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.Workspace, Value);\n end Set_Workspace;\n\n function Get_Workspace (Object : in Wiki_Space_Ref)\n return AWA.Workspaces.Models.Workspace_Ref'Class is\n Impl : constant Wiki_Space_Access\n := Wiki_Space_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Workspace;\n end Get_Workspace;\n\n -- Copy of the object.\n procedure Copy (Object : in Wiki_Space_Ref;\n Into : in out Wiki_Space_Ref) is\n Result : Wiki_Space_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Wiki_Space_Access\n := Wiki_Space_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Wiki_Space_Access\n := new Wiki_Space_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Name := Impl.Name;\n Copy.Is_Public := Impl.Is_Public;\n Copy.Version := Impl.Version;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Left_Side := Impl.Left_Side;\n Copy.Right_Side := Impl.Right_Side;\n Copy.Format := Impl.Format;\n Copy.Workspace := Impl.Workspace;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Wiki_Space_Impl, Wiki_Space_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Wiki_Space_Impl_Ptr := Wiki_Space_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Wiki_Space_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WIKI_SPACE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Wiki_Space_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Wiki_Space_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WIKI_SPACE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- is_public\n Value => Object.Is_Public);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- left_side\n Value => Object.Left_Side);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- right_side\n Value => Object.Right_Side);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- format\n Value => Integer (Format_Type'Pos (Object.Format)));\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (9);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Wiki_Page_Impl, Wiki_Page_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Wiki_Page_Impl_Ptr := Wiki_Page_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Wiki_Page_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WIKI_PAGE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Wiki_Page_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Wiki_Page_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WIKI_PAGE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- last_version\n Value => Object.Last_Version);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- is_public\n Value => Object.Is_Public);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- title\n Value => Object.Title);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_2_NAME, -- read_count\n Value => Object.Read_Count);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_2_NAME, -- preview_id\n Value => Object.Preview);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_2_NAME, -- wiki_id\n Value => Object.Wiki);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_2_NAME, -- content_id\n Value => Object.Content);\n Object.Clear_Modified (10);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Format_Type);\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 4, Impl.Format, Value);\n end Set_Format;\n\n function Get_Format (Object : in Wiki_Content_Ref)\n return AWA.Wikis.Models.Format_Type is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Format;\n end Get_Format;\n\n\n procedure Set_Save_Comment (Object : in out Wiki_Content_Ref;\n Value : in String) is\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 5, Impl.Save_Comment, Value);\n end Set_Save_Comment;\n\n procedure Set_Save_Comment (Object : in out Wiki_Content_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 5, Impl.Save_Comment, Value);\n end Set_Save_Comment;\n\n function Get_Save_Comment (Object : in Wiki_Content_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Save_Comment);\n end Get_Save_Comment;\n function Get_Save_Comment (Object : in Wiki_Content_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Save_Comment;\n end Get_Save_Comment;\n\n\n function Get_Version (Object : in Wiki_Content_Ref)\n return Integer is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Page_Version (Object : in out Wiki_Content_Ref;\n Value : in Integer) is\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 7, Impl.Page_Version, Value);\n end Set_Page_Version;\n\n function Get_Page_Version (Object : in Wiki_Content_Ref)\n return Integer is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Page_Version;\n end Get_Page_Version;\n\n\n procedure Set_Page (Object : in out Wiki_Content_Ref;\n Value : in AWA.Wikis.Models.Wiki_Page_Ref'Class) is\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 8, Impl.Page, Value);\n end Set_Page;\n\n function Get_Page (Object : in Wiki_Content_Ref)\n return AWA.Wikis.Models.Wiki_Page_Ref'Class is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Page;\n end Get_Page;\n\n\n procedure Set_Author (Object : in out Wiki_Content_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Wiki_Content_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.Author, Value);\n end Set_Author;\n\n function Get_Author (Object : in Wiki_Content_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Author;\n end Get_Author;\n\n -- Copy of the object.\n procedure Copy (Object : in Wiki_Content_Ref;\n Into : in out Wiki_Content_Ref) is\n Result : Wiki_Content_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Wiki_Content_Access\n := Wiki_Content_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Wiki_Content_Access\n := new Wiki_Content_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Create_Date := Impl.Create_Date;\n Copy.Content := Impl.Content;\n Copy.Format := Impl.Format;\n Copy.Save_Comment := Impl.Save_Comment;\n Copy.Version := Impl.Version;\n Copy.Page_Version := Impl.Page_Version;\n Copy.Page := Impl.Page;\n Copy.Author := Impl.Author;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Wiki_Content_Impl, Wiki_Content_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Wiki_Content_Impl_Ptr := Wiki_Content_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Wiki_Content_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WIKI_CONTENT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Wiki_Content_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Wiki_Content_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WIKI_CONTENT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_3_NAME, -- page_version\n Value => Object.Page_Version);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_3_NAME, -- page_id\n Value => Object.Page);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_3_NAME, -- author_id\n Value => Object.Author);\n Object.Clear_Modified (9);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => AWS.SMTP.Recipients,\n Name => Recipients_Access);\n\n -- Get a printable representation of the email recipients.\n function Image (Recipients : in AWS.SMTP.Recipients) return String;\n\n -- ------------------------------\n -- Set the From part of the message.\n -- ------------------------------\n overriding\n procedure Set_From (Message : in out AWS_Mail_Message;\n Name : in String;\n Address : in String) is\n begin\n Message.From := AWS.SMTP.E_Mail (Name => Name,\n Address => Address);\n end Set_From;\n\n -- ------------------------------\n -- Add a recipient for the message.\n -- ------------------------------\n overriding\n procedure Add_Recipient (Message : in out AWS_Mail_Message;\n Kind : in Recipient_Type;\n Name : in String;\n Address : in String) is\n pragma Unreferenced (Kind);\n begin\n if Message.To = null then\n Message.To := new AWS.SMTP.Recipients (1 .. 1);\n else\n declare\n To : constant Recipients_Access := new AWS.SMTP.Recipients (1 .. Message.To'Last + 1);\n begin\n To (Message.To'Range) := Message.To.all;\n Free (Message.To);\n Message.To := To;" + }, + { + "function_def": "procedure Import_Country is", + "function_body": "use Ada.Text_IO;\n use Util.Serialize.IO.CSV;\n use AWA.Countries.Models;\n use Ada.Containers;\n\n use Util.Log;\n\n Log : constant Loggers.Logger := Loggers.Create (\"Import_Country\");\n\n Country : AWA.Countries.Models.Country_Ref;\n DB : ADO.Sessions.Master_Session;\n\n package Country_Map is\n new Ada.Containers.Indefinite_Hashed_Maps (Key_Type => String,\n Element_Type => AWA.Countries.Models.Country_Ref,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\");\n\n package Neighbors_Map is\n new Ada.Containers.Indefinite_Hashed_Maps (Key_Type => String,\n Element_Type => String,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\");\n\n Countries : Country_Map.Map;\n Neighbors : Neighbors_Map.Map;\n\n type CSV_Parser is new Util.Serialize.IO.CSV.Parser with null record;\n\n overriding\n procedure Set_Cell (Parser : in out CSV_Parser;\n Value : in String;\n Row : in Util.Serialize.IO.CSV.Row_Type;\n Column : in Util.Serialize.IO.CSV.Column_Type);\n\n overriding\n procedure Set_Cell (Parser : in out CSV_Parser;\n Value : in String;\n Row : in Util.Serialize.IO.CSV.Row_Type;\n Column : in Util.Serialize.IO.CSV.Column_Type) is\n pragma Unreferenced (Parser, Row);\n\n Query : ADO.SQL.Query;\n Found : Boolean;\n begin\n case Column is\n when 1 =>\n -- The ISO code is unique, find the country\n Query.Bind_Param (1, Value);\n Query.Set_Filter (\"iso_code = ?\");\n Country.Find (DB, Query, Found);\n if not Found then\n -- Build a new country object\n Country := AWA.Countries.Models.Null_Country;\n Country.Set_Iso_Code (Value);\n end if;\n Countries.Insert (Value, Country);\n\n when 2 =>\n -- Ada.Text_IO.Put_Line (\"ISO3: \" & Value);\n null;\n\n when 3 =>\n -- Ada.Text_IO.Put_Line (\"ISON: \" & Value);\n null;\n\n when 4 =>\n -- Ada.Text_IO.Put_Line (\"FIPS: \" & Value);\n null;\n\n -- Country name\n when 5 =>\n Country.Set_Name (Value);\n\n when 6 =>\n -- Ada.Text_IO.Put_Line (\"Capital: \" & Value);\n null;\n\n when 7 | 8 => -- Area, Population\n null;\n\n -- Country continent\n when 9 =>\n Country.Set_Continent (Value);\n\n -- Country TLD\n when 10 =>\n Country.Set_Tld (Value);\n\n -- Country CurrencyCode\n when 11 =>\n Country.Set_Currency_Code (Value);\n\n -- Country CurrencyName\n when 12 =>\n Country.Set_Currency (Value);\n\n when 13 | 14 => -- Phone, postal code format\n null;\n\n when 15 =>\n -- Ada.Text_IO.Put_Line (\"Postal regex: \" & Value);\n null;\n\n -- Country languages\n when 16 =>\n Country.Set_Languages (Value);\n\n -- Country unique geonameid\n when 17 =>\n if Value /= \"\" then\n Country.Set_Geonameid (Integer'Value (Value));\n end if;\n\n when 18 =>\n Country.Save (DB);\n Neighbors.Insert (Country.Get_Iso_Code, Value);\n\n when 19 => -- EquivalentFipsCode\n null;\n\n when others =>\n null;\n\n end case;\n\n exception\n when E : others =>\n Log.Error (\"Column \" & Util.Serialize.IO.CSV.Column_Type'Image (Column)\n & \" value: \" & Value, E, True);\n raise;\n end Set_Cell;\n\n procedure Build_Neighbors is\n Stmt : ADO.Statements.Delete_Statement\n := DB.Create_Statement (AWA.Countries.Models.COUNTRY_NEIGHBOR_TABLE);\n Iter : Neighbors_Map.Cursor := Neighbors.First;\n Count : Natural := 0;\n begin\n Stmt.Execute;\n\n while Neighbors_Map.Has_Element (Iter) loop\n declare\n Name : constant String := Neighbors_Map.Key (Iter);\n List : constant String := Neighbors_Map.Element (Iter);\n Pos : Natural := List'First;\n N : Natural;\n begin\n Country := Countries.Element (Name);\n while Pos < List'Last loop\n N := Util.Strings.Index (List, ',', Pos);\n if N = 0 then\n N := List'Last;\n else\n N := N - 1;\n end if;\n if Pos < N and then Countries.Contains (List (Pos .. N)) then\n declare\n Neighbor : AWA.Countries.Models.Country_Neighbor_Ref;\n begin\n Neighbor.Set_Neighbor_Of (Country);\n Neighbor.Set_Neighbor (Countries.Element (List (Pos .. N)));\n Neighbor.Save (DB);\n Count := Count + 1;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Country_Impl, Country_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Country_Impl_Ptr := Country_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Country_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, COUNTRY_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Country_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Country_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (COUNTRY_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- continent\n Value => Object.Continent);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- currency\n Value => Object.Currency);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- iso_code\n Value => Object.Iso_Code);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- geonameid\n Value => Object.Geonameid);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- languages\n Value => Object.Languages);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- tld\n Value => Object.Tld);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- currency_code\n Value => Object.Currency_Code);\n Object.Clear_Modified (9);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(City_Impl, City_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : City_Impl_Ptr := City_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out City_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, CITY_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out City_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out City_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (CITY_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- zip_code\n Value => Object.Zip_Code);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- latitude\n Value => Object.Latitude);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- longitude\n Value => Object.Longitude);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_2_NAME, -- region_id\n Value => Object.Region);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_2_NAME, -- country_id\n Value => Object.Country);\n Object.Clear_Modified (7);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Country_Neighbor_Impl, Country_Neighbor_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Country_Neighbor_Impl_Ptr := Country_Neighbor_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Country_Neighbor_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, COUNTRY_NEIGHBOR_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Country_Neighbor_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Country_Neighbor_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (COUNTRY_NEIGHBOR_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- neighbor_of_id\n Value => Object.Neighbor_Of);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- neighbor_id\n Value => Object.Neighbor);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Region_Impl, Region_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Region_Impl_Ptr := Region_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Region_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, REGION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Region_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Region_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (REGION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_4_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_4_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_4_NAME, -- geonameid\n Value => Object.Geonameid);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_4_NAME, -- country_id\n Value => Object.Country);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Publish (Service : in Storage_Service;", + "function_body": "Id : in ADO.Identifier;\n State : in Boolean;\n File : in out AWA.Storages.Models.Storage_Ref'Class) is\n pragma Unreferenced (Service);\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n begin\n Ctx.Start;\n\n -- Check that the user has the permission to publish for the given comment.\n AWA.Permissions.Check (Permission => ACL_Delete_Storage.Permission,\n Entity => Id);\n\n File.Load (DB, Id);\n File.Set_Is_Public (State);\n File.Save (DB);\n declare\n Update : ADO.Statements.Update_Statement\n := DB.Create_Statement (AWA.Storages.Models.STORAGE_TABLE);\n begin\n Update.Set_Filter (Filter => \"original_id = ?\");\n Update.Save_Field (\"is_public\", State);\n Update.Add_Param (Id);\n Update.Execute;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Storage_Data_Impl, Storage_Data_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Storage_Data_Impl_Ptr := Storage_Data_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Storage_Data_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, STORAGE_DATA_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Storage_Data_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Storage_Data_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (STORAGE_DATA_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- data\n Value => Object.Data);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Storage_Folder_Impl, Storage_Folder_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Storage_Folder_Impl_Ptr := Storage_Folder_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Storage_Folder_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, STORAGE_FOLDER_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Storage_Folder_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Storage_Folder_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (STORAGE_FOLDER_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_2_NAME, -- owner_id\n Value => Object.Owner);\n Object.Clear_Modified (6);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Storage_Type);\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 1, Impl.Storage, Value);\n end Set_Storage;\n\n function Get_Storage (Object : in Storage_Ref)\n return AWA.Storages.Models.Storage_Type is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Storage;\n end Get_Storage;\n\n\n procedure Set_Create_Date (Object : in out Storage_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 2, Impl.Create_Date, Value);\n end Set_Create_Date;\n\n function Get_Create_Date (Object : in Storage_Ref)\n return Ada.Calendar.Time is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Create_Date;\n end Get_Create_Date;\n\n\n procedure Set_Name (Object : in out Storage_Ref;\n Value : in String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 3, Impl.Name, Value);\n end Set_Name;\n\n procedure Set_Name (Object : in out Storage_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 3, Impl.Name, Value);\n end Set_Name;\n\n function Get_Name (Object : in Storage_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Name);\n end Get_Name;\n function Get_Name (Object : in Storage_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Name;\n end Get_Name;\n\n\n procedure Set_File_Size (Object : in out Storage_Ref;\n Value : in Integer) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 4, Impl.File_Size, Value);\n end Set_File_Size;\n\n function Get_File_Size (Object : in Storage_Ref)\n return Integer is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.File_Size;\n end Get_File_Size;\n\n\n procedure Set_Mime_Type (Object : in out Storage_Ref;\n Value : in String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 5, Impl.Mime_Type, Value);\n end Set_Mime_Type;\n\n procedure Set_Mime_Type (Object : in out Storage_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 5, Impl.Mime_Type, Value);\n end Set_Mime_Type;\n\n function Get_Mime_Type (Object : in Storage_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Mime_Type);\n end Get_Mime_Type;\n function Get_Mime_Type (Object : in Storage_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Mime_Type;\n end Get_Mime_Type;\n\n\n procedure Set_Uri (Object : in out Storage_Ref;\n Value : in String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 6, Impl.Uri, Value);\n end Set_Uri;\n\n procedure Set_Uri (Object : in out Storage_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 6, Impl.Uri, Value);\n end Set_Uri;\n\n function Get_Uri (Object : in Storage_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Uri);\n end Get_Uri;\n function Get_Uri (Object : in Storage_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Uri;\n end Get_Uri;\n\n\n function Get_Version (Object : in Storage_Ref)\n return Integer is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Id (Object : in out Storage_Ref;\n Value : in ADO.Identifier) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Key_Value (Impl.all, 8, Value);\n end Set_Id;\n\n function Get_Id (Object : in Storage_Ref)\n return ADO.Identifier is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Object.all)'Access;\n begin\n return Impl.Get_Key_Value;\n end Get_Id;\n\n\n procedure Set_Is_Public (Object : in out Storage_Ref;\n Value : in Boolean) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Boolean (Impl.all, 9, Impl.Is_Public, Value);\n ADO.Objects.Set_Field_Boolean (Impl.all, 9, Impl.Is_Public, Value);\n end Set_Is_Public;\n\n function Get_Is_Public (Object : in Storage_Ref)\n return Boolean is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Is_Public;\n end Get_Is_Public;\n\n\n procedure Set_Original (Object : in out Storage_Ref;\n Value : in AWA.Storages.Models.Storage_Ref'Class) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 10, Impl.Original, Value);\n end Set_Original;\n\n function Get_Original (Object : in Storage_Ref)\n return AWA.Storages.Models.Storage_Ref'Class is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Original;\n end Get_Original;\n\n\n procedure Set_Store_Data (Object : in out Storage_Ref;\n Value : in AWA.Storages.Models.Storage_Data_Ref'Class) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 11, Impl.Store_Data, Value);\n end Set_Store_Data;\n\n function Get_Store_Data (Object : in Storage_Ref)\n return AWA.Storages.Models.Storage_Data_Ref'Class is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Store_Data;\n end Get_Store_Data;\n\n\n procedure Set_Owner (Object : in out Storage_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 12, Impl.Owner, Value);\n end Set_Owner;\n\n function Get_Owner (Object : in Storage_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Owner;\n end Get_Owner;\n\n\n procedure Set_Workspace (Object : in out Storage_Ref;\n Value : in AWA.Workspaces.Models.Workspace_Ref'Class) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 13, Impl.Workspace, Value);\n end Set_Workspace;\n\n function Get_Workspace (Object : in Storage_Ref)\n return AWA.Workspaces.Models.Workspace_Ref'Class is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Workspace;\n end Get_Workspace;\n\n\n procedure Set_Folder (Object : in out Storage_Ref;\n Value : in AWA.Storages.Models.Storage_Folder_Ref'Class) is\n Impl : Storage_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 14, Impl.Folder, Value);\n end Set_Folder;\n\n function Get_Folder (Object : in Storage_Ref)\n return AWA.Storages.Models.Storage_Folder_Ref'Class is\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Folder;\n end Get_Folder;\n\n -- Copy of the object.\n procedure Copy (Object : in Storage_Ref;\n Into : in out Storage_Ref) is\n Result : Storage_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Storage_Access\n := Storage_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Storage_Access\n := new Storage_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Storage := Impl.Storage;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Name := Impl.Name;\n Copy.File_Size := Impl.File_Size;\n Copy.Mime_Type := Impl.Mime_Type;\n Copy.Uri := Impl.Uri;\n Copy.Version := Impl.Version;\n Copy.Is_Public := Impl.Is_Public;\n Copy.Original := Impl.Original;\n Copy.Store_Data := Impl.Store_Data;\n Copy.Owner := Impl.Owner;\n Copy.Workspace := Impl.Workspace;\n Copy.Folder := Impl.Folder;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Storage_Impl, Storage_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Storage_Impl_Ptr := Storage_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Storage_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, STORAGE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Storage_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Storage_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (STORAGE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- storage\n Value => Integer (Storage_Type'Pos (Object.Storage)));\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- file_size\n Value => Object.File_Size);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- mime_type\n Value => Object.Mime_Type);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- uri\n Value => Object.Uri);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_3_NAME, -- is_public\n Value => Object.Is_Public);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_3_NAME, -- original_id\n Value => Object.Original);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_3_NAME, -- store_data_id\n Value => Object.Store_Data);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_3_NAME, -- owner_id\n Value => Object.Owner);\n Object.Clear_Modified (12);\n end if;\n if Object.Is_Modified (13) then\n Stmt.Save_Field (Name => COL_12_3_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (13);\n end if;\n if Object.Is_Modified (14) then\n Stmt.Save_Field (Name => COL_13_3_NAME, -- folder_id\n Value => Object.Folder);\n Object.Clear_Modified (14);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Store_Local_Impl, Store_Local_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Store_Local_Impl_Ptr := Store_Local_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Store_Local_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, STORE_LOCAL_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Store_Local_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Store_Local_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (STORE_LOCAL_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_4_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_4_NAME, -- store_version\n Value => Object.Store_Version);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_4_NAME, -- shared\n Value => Object.Shared);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_4_NAME, -- path\n Value => Object.Path);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_4_NAME, -- expire_date\n Value => Object.Expire_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_4_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_4_NAME, -- storage_id\n Value => Object.Storage);\n Object.Clear_Modified (8);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Job_Status_Type);\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 2, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Job_Ref)\n return AWA.Jobs.Models.Job_Status_Type is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Name (Object : in out Job_Ref;\n Value : in String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 3, Impl.Name, Value);\n end Set_Name;\n\n procedure Set_Name (Object : in out Job_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 3, Impl.Name, Value);\n end Set_Name;\n\n function Get_Name (Object : in Job_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Name);\n end Get_Name;\n function Get_Name (Object : in Job_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Name;\n end Get_Name;\n\n\n procedure Set_Start_Date (Object : in out Job_Ref;\n Value : in ADO.Nullable_Time) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 4, Impl.Start_Date, Value);\n end Set_Start_Date;\n\n function Get_Start_Date (Object : in Job_Ref)\n return ADO.Nullable_Time is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Start_Date;\n end Get_Start_Date;\n\n\n procedure Set_Create_Date (Object : in out Job_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 5, Impl.Create_Date, Value);\n end Set_Create_Date;\n\n function Get_Create_Date (Object : in Job_Ref)\n return Ada.Calendar.Time is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Create_Date;\n end Get_Create_Date;\n\n\n procedure Set_Finish_Date (Object : in out Job_Ref;\n Value : in ADO.Nullable_Time) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 6, Impl.Finish_Date, Value);\n end Set_Finish_Date;\n\n function Get_Finish_Date (Object : in Job_Ref)\n return ADO.Nullable_Time is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Finish_Date;\n end Get_Finish_Date;\n\n\n procedure Set_Progress (Object : in out Job_Ref;\n Value : in Integer) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 7, Impl.Progress, Value);\n end Set_Progress;\n\n function Get_Progress (Object : in Job_Ref)\n return Integer is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Progress;\n end Get_Progress;\n\n\n procedure Set_Parameters (Object : in out Job_Ref;\n Value : in String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 8, Impl.Parameters, Value);\n end Set_Parameters;\n\n procedure Set_Parameters (Object : in out Job_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 8, Impl.Parameters, Value);\n end Set_Parameters;\n\n function Get_Parameters (Object : in Job_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Parameters);\n end Get_Parameters;\n function Get_Parameters (Object : in Job_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Parameters;\n end Get_Parameters;\n\n\n procedure Set_Results (Object : in out Job_Ref;\n Value : in String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 9, Impl.Results, Value);\n end Set_Results;\n\n procedure Set_Results (Object : in out Job_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 9, Impl.Results, Value);\n end Set_Results;\n\n function Get_Results (Object : in Job_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Results);\n end Get_Results;\n function Get_Results (Object : in Job_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Results;\n end Get_Results;\n\n\n function Get_Version (Object : in Job_Ref)\n return Integer is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Priority (Object : in out Job_Ref;\n Value : in Integer) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 11, Impl.Priority, Value);\n end Set_Priority;\n\n function Get_Priority (Object : in Job_Ref)\n return Integer is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Priority;\n end Get_Priority;\n\n\n procedure Set_User (Object : in out Job_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 12, Impl.User, Value);\n end Set_User;\n\n function Get_User (Object : in Job_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User;\n end Get_User;\n\n\n procedure Set_Event (Object : in out Job_Ref;\n Value : in AWA.Events.Models.Message_Ref'Class) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 13, Impl.Event, Value);\n end Set_Event;\n\n function Get_Event (Object : in Job_Ref)\n return AWA.Events.Models.Message_Ref'Class is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Event;\n end Get_Event;\n\n\n procedure Set_Session (Object : in out Job_Ref;\n Value : in AWA.Users.Models.Session_Ref'Class) is\n Impl : Job_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 14, Impl.Session, Value);\n end Set_Session;\n\n function Get_Session (Object : in Job_Ref)\n return AWA.Users.Models.Session_Ref'Class is\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Session;\n end Get_Session;\n\n -- Copy of the object.\n procedure Copy (Object : in Job_Ref;\n Into : in out Job_Ref) is\n Result : Job_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Job_Access\n := Job_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Job_Access\n := new Job_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Status := Impl.Status;\n Copy.Name := Impl.Name;\n Copy.Start_Date := Impl.Start_Date;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Finish_Date := Impl.Finish_Date;\n Copy.Progress := Impl.Progress;\n Copy.Parameters := Impl.Parameters;\n Copy.Results := Impl.Results;\n Copy.Version := Impl.Version;\n Copy.Priority := Impl.Priority;\n Copy.User := Impl.User;\n Copy.Event := Impl.Event;\n Copy.Session := Impl.Session;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Job_Impl, Job_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Job_Impl_Ptr := Job_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Job_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, JOB_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Job_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Job_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (JOB_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- status\n Value => Integer (Job_Status_Type'Pos (Object.Status)));\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- start_date\n Value => Object.Start_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- finish_date\n Value => Object.Finish_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- progress\n Value => Object.Progress);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- parameters\n Value => Object.Parameters);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- results\n Value => Object.Results);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_1_NAME, -- priority\n Value => Object.Priority);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_1_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (12);\n end if;\n if Object.Is_Modified (13) then\n Stmt.Save_Field (Name => COL_12_1_NAME, -- event_id\n Value => Object.Event);\n Object.Clear_Modified (13);\n end if;\n if Object.Is_Modified (14) then\n Stmt.Save_Field (Name => COL_13_1_NAME, -- session_id\n Value => Object.Session);\n Object.Clear_Modified (14);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Load_List (Into : in out Post_List_Bean) is", + "function_body": "use AWA.Blogs.Models;\n use AWA.Services;\n\n Session : ADO.Sessions.Session := Into.Service.Get_Session;\n Query : ADO.Queries.Context;\n Count_Query : ADO.Queries.Context;\n Tag_Id : ADO.Identifier;\n First : constant Natural := (Into.Page - 1) * Into.Page_Size;\n begin\n AWA.Tags.Modules.Find_Tag_Id (Session, Ada.Strings.Unbounded.To_String (Into.Tag), Tag_Id);\n if Tag_Id /= ADO.NO_IDENTIFIER then\n Query.Set_Query (AWA.Blogs.Models.Query_Blog_Post_Tag_List);\n Query.Bind_Param (Name => \"tag\", Value => Tag_Id);\n Count_Query.Set_Count_Query (AWA.Blogs.Models.Query_Blog_Post_Tag_List);\n Count_Query.Bind_Param (Name => \"tag\", Value => Tag_Id);\n else\n Query.Set_Query (AWA.Blogs.Models.Query_Blog_Post_List);\n Count_Query.Set_Count_Query (AWA.Blogs.Models.Query_Blog_Post_List);\n end if;\n Query.Bind_Param (Name => \"first\", Value => First);\n Query.Bind_Param (Name => \"count\", Value => Into.Page_Size);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Blogs.Models.POST_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Count_Query,\n Name => \"entity_type\",\n Table => AWA.Blogs.Models.POST_TABLE,\n Session => Session);\n AWA.Blogs.Models.List (Into.Posts, Session, Query);\n Into.Count := ADO.Datasets.Get_Count (Session, Count_Query);\n declare\n List : ADO.Utils.Identifier_Vector;\n Iter : Post_Info_Vectors.Cursor := Into.Posts.List.First;\n begin\n while Post_Info_Vectors.Has_Element (Iter) loop\n List.Append (Post_Info_Vectors.Element (Iter).Id);\n Post_Info_Vectors.Next (Iter);\n end loop;\n Into.Tags.Load_Tags (Session, AWA.Blogs.Models.POST_TABLE.Table.all,\n List);" + }, + { + "function_def": "function Create_Post_List_Bean (Module : in AWA.Blogs.Modules.Blog_Module_Access)", + "function_body": "return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Post_List_Bean_Access := new Post_List_Bean;\n begin\n Object.Service := Module;\n Object.Posts_Bean := Object.Posts'Access;\n Object.Page_Size := 20;\n Object.Page := 1;\n Object.Count := 0;\n Object.Counter_Bean := Object.Counter'Access;\n Object.Counter.Counter := AWA.Blogs.Modules.Read_Counter.Index;\n return Object.all'Access;\n end Create_Post_List_Bean;\n\n -- ------------------------------\n -- Create the Blog_List_Bean bean instance.\n -- ------------------------------\n function Create_Blog_Admin_Bean (Module : in AWA.Blogs.Modules.Blog_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n Object : constant Blog_Admin_Bean_Access := new Blog_Admin_Bean;\n begin\n Object.Module := Module;\n Object.Flags := Object.Init_Flags'Access;\n Object.Post_List_Bean := Object.Post_List'Access;\n Object.Blog_List_Bean := Object.Blog_List'Access;\n Object.Comment_List_Bean := Object.Comment_List'Access;\n return Object.all'Access;\n end Create_Blog_Admin_Bean;\n\n function Create_From_Status is\n new AWA.Helpers.Selectors.Create_From_Enum (AWA.Blogs.Models.Post_Status_Type,\n \"blog_status_\");\n\n -- ------------------------------\n -- Get a select item list which contains a list of post status.\n -- ------------------------------\n function Create_Status_List (Module : in AWA.Blogs.Modules.Blog_Module_Access)\n return Util.Beans.Basic.Readonly_Bean_Access is\n pragma Unreferenced (Module);\n use AWA.Helpers;\n begin\n return Selectors.Create_Selector_Bean (Bundle => \"blogs\",\n Context => null,\n Create => Create_From_Status'Access).all'Access;\n end Create_Status_List;\n\n -- ------------------------------\n -- Load the list of blogs.\n -- ------------------------------\n procedure Load_Blogs (List : in Blog_Admin_Bean) is\n use AWA.Blogs.Models;\n use AWA.Services;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := List.Module.Get_Session;\n Query : ADO.Queries.Context;\n begin\n Query.Set_Query (AWA.Blogs.Models.Query_Blog_List);\n Query.Bind_Param (\"user_id\", User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Blogs.Models.BLOG_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Blogs.Models.POST_TABLE,\n Session => Session);\n AWA.Blogs.Models.List (List.Blog_List_Bean.all, Session, Query);\n List.Flags (INIT_BLOG_LIST) := True;\n end Load_Blogs;\n\n -- ------------------------------\n -- Get the blog identifier.\n -- ------------------------------\n function Get_Blog_Id (List : in Blog_Admin_Bean) return ADO.Identifier is\n begin\n if List.Blog_Id = ADO.NO_IDENTIFIER then\n if not List.Flags (INIT_BLOG_LIST) then\n Load_Blogs (List);\n end if;\n if not List.Blog_List.List.Is_Empty then\n return List.Blog_List.List.Element (0).Id;\n end if;\n end if;\n return List.Blog_Id;\n end Get_Blog_Id;\n\n -- ------------------------------\n -- Load the posts associated with the current blog.\n -- ------------------------------\n procedure Load_Posts (List : in Blog_Admin_Bean) is\n use AWA.Blogs.Models;\n use AWA.Services;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := List.Module.Get_Session;\n Query : ADO.Queries.Context;\n Blog_Id : constant ADO.Identifier := List.Get_Blog_Id;\n begin\n if Blog_Id /= ADO.NO_IDENTIFIER then\n Query.Set_Query (AWA.Blogs.Models.Query_Blog_Admin_Post_List);\n Query.Bind_Param (\"blog_id\", Blog_Id);\n Query.Bind_Param (\"user_id\", User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Blogs.Models.BLOG_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Blogs.Models.POST_TABLE,\n Session => Session);\n\n AWA.Blogs.Models.List (List.Post_List_Bean.all, Session, Query);\n List.Flags (INIT_POST_LIST) := True;\n end if;\n end Load_Posts;\n\n -- ------------------------------\n -- Load the comments associated with the current blog.\n -- ------------------------------\n procedure Load_Comments (List : in Blog_Admin_Bean) is\n use AWA.Blogs.Models;\n use AWA.Services;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n Session : ADO.Sessions.Session := List.Module.Get_Session;\n Query : ADO.Queries.Context;\n Blog_Id : constant ADO.Identifier := List.Get_Blog_Id;\n begin\n if Blog_Id /= ADO.NO_IDENTIFIER then\n Query.Set_Query (AWA.Blogs.Models.Query_Comment_List);\n Query.Bind_Param (\"blog_id\", Blog_Id);\n Query.Bind_Param (\"user_id\", User);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"table\",\n Table => AWA.Blogs.Models.BLOG_TABLE,\n Session => Session);\n ADO.Sessions.Entities.Bind_Param (Params => Query,\n Name => \"entity_type\",\n Table => AWA.Blogs.Models.POST_TABLE,\n Session => Session);\n\n AWA.Blogs.Models.List (List.Comment_List_Bean.all, Session, Query);\n List.Flags (INIT_COMMENT_LIST) := True;\n end if;\n end Load_Comments;\n\n overriding\n function Get_Value (List : in Blog_Admin_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n begin\n if Name = \"blogs\" then\n if not List.Init_Flags (INIT_BLOG_LIST) then\n Load_Blogs (List);\n end if;\n return Util.Beans.Objects.To_Object (Value => List.Blog_List_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"posts\" then\n if not List.Init_Flags (INIT_POST_LIST) then\n Load_Posts (List);\n end if;\n return Util.Beans.Objects.To_Object (Value => List.Post_List_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"comments\" then\n if not List.Init_Flags (INIT_COMMENT_LIST) then\n Load_Comments (List);\n end if;\n return Util.Beans.Objects.To_Object (Value => List.Comment_List_Bean,\n Storage => Util.Beans.Objects.STATIC);\n\n elsif Name = \"id\" then\n declare\n Id : constant ADO.Identifier := List.Get_Blog_Id;\n begin\n if Id = ADO.NO_IDENTIFIER then\n return Util.Beans.Objects.Null_Object;\n else\n return Util.Beans.Objects.To_Object (Long_Long_Integer (Id));\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Blog_Impl, Blog_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Blog_Impl_Ptr := Blog_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Blog_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, BLOG_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Blog_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Blog_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (BLOG_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- uid\n Value => Object.Uid);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- update_date\n Value => Object.Update_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- url\n Value => Object.Url);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (8);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Blog_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, BLOG_DEF'Access);\n begin\n Stmt.Execute;\n Blog_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Blog_Ref;\n Impl : constant Blog_Access := new Blog_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Set_Publish_Date (Object : in out Post_Ref;", + "function_body": "Value : in ADO.Nullable_Time) is\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 7, Impl.Publish_Date, Value);\n end Set_Publish_Date;\n\n function Get_Publish_Date (Object : in Post_Ref)\n return ADO.Nullable_Time is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Publish_Date;\n end Get_Publish_Date;\n\n\n procedure Set_Status (Object : in out Post_Ref;\n Value : in AWA.Blogs.Models.Post_Status_Type) is\n procedure Set_Field_Enum is\n new ADO.Objects.Set_Field_Operation (Post_Status_Type);\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 8, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Post_Ref)\n return AWA.Blogs.Models.Post_Status_Type is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Allow_Comments (Object : in out Post_Ref;\n Value : in Boolean) is\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Boolean (Impl.all, 9, Impl.Allow_Comments, Value);\n ADO.Objects.Set_Field_Boolean (Impl.all, 9, Impl.Allow_Comments, Value);\n end Set_Allow_Comments;\n\n function Get_Allow_Comments (Object : in Post_Ref)\n return Boolean is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Allow_Comments;\n end Get_Allow_Comments;\n\n\n procedure Set_Read_Count (Object : in out Post_Ref;\n Value : in Integer) is\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 10, Impl.Read_Count, Value);\n end Set_Read_Count;\n\n function Get_Read_Count (Object : in Post_Ref)\n return Integer is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Read_Count;\n end Get_Read_Count;\n\n\n procedure Set_Author (Object : in out Post_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 11, Impl.Author, Value);\n end Set_Author;\n\n function Get_Author (Object : in Post_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Author;\n end Get_Author;\n\n\n procedure Set_Blog (Object : in out Post_Ref;\n Value : in AWA.Blogs.Models.Blog_Ref'Class) is\n Impl : Post_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 12, Impl.Blog, Value);\n end Set_Blog;\n\n function Get_Blog (Object : in Post_Ref)\n return AWA.Blogs.Models.Blog_Ref'Class is\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Blog;\n end Get_Blog;\n\n -- Copy of the object.\n procedure Copy (Object : in Post_Ref;\n Into : in out Post_Ref) is\n Result : Post_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Post_Access\n := Post_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Post_Access\n := new Post_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Title := Impl.Title;\n Copy.Text := Impl.Text;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Uri := Impl.Uri;\n Copy.Version := Impl.Version;\n Copy.Publish_Date := Impl.Publish_Date;\n Copy.Status := Impl.Status;\n Copy.Allow_Comments := Impl.Allow_Comments;\n Copy.Read_Count := Impl.Read_Count;\n Copy.Author := Impl.Author;\n Copy.Blog := Impl.Blog;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Post_Impl, Post_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Post_Impl_Ptr := Post_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Post_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, POST_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Post_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Post_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (POST_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- title\n Value => Object.Title);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- text\n Value => Object.Text);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- uri\n Value => Object.Uri);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_2_NAME, -- publish_date\n Value => Object.Publish_Date);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_2_NAME, -- status\n Value => Integer (Post_Status_Type'Pos (Object.Status)));\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_2_NAME, -- allow_comments\n Value => Object.Allow_Comments);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_2_NAME, -- read_count\n Value => Object.Read_Count);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_2_NAME, -- author_id\n Value => Object.Author);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_2_NAME, -- blog_id\n Value => Object.Blog);\n Object.Clear_Modified (12);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "function Get_Owner_Permissions (Manager : in Workspace_Module) return Permission_Index_Array is", + "function_body": "use Ada.Strings.Unbounded;\n begin\n return Security.Permissions.Get_Permission_Array (To_String (Manager.Owner_Permissions));\n end Get_Owner_Permissions;\n\n -- Get the workspace module.\n function Get_Workspace_Module return Workspace_Module_Access is\n function Get is new AWA.Modules.Get (Workspace_Module, Workspace_Module_Access, NAME);\n begin\n return Get;\n end Get_Workspace_Module;\n\n -- ------------------------------\n -- Get the current workspace associated with the current user.\n -- If the user has not workspace, create one.\n -- ------------------------------\n procedure Get_Workspace (Session : in out ADO.Sessions.Master_Session;\n Context : in AWA.Services.Contexts.Service_Context_Access;\n Workspace : out AWA.Workspaces.Models.Workspace_Ref) is\n User : constant AWA.Users.Models.User_Ref := Context.Get_User;\n WS : AWA.Workspaces.Models.Workspace_Ref;\n Member : AWA.Workspaces.Models.Workspace_Member_Ref;\n Query : ADO.SQL.Query;\n Found : Boolean;\n Plugin : constant Workspace_Module_Access := Get_Workspace_Module;\n begin\n if User.Is_Null then\n Log.Error (\"There is no current user. The workspace cannot be identified\");\n Workspace := AWA.Workspaces.Models.Null_Workspace;\n return;\n end if;\n\n -- Find the workspace associated with the current user.\n Query.Add_Param (User.Get_Id);\n Query.Set_Filter (\"o.owner_id = ?\");\n WS.Find (Session, Query, Found);\n if Found then\n Workspace := WS;\n return;\n end if;\n\n -- Check that the user has the permission to create a new workspace.\n AWA.Permissions.Check (Permission => ACL_Create_Workspace.Permission,\n Entity => User);\n\n -- Create a workspace for this user.\n WS.Set_Owner (User);\n WS.Set_Create_Date (Ada.Calendar.Clock);\n WS.Save (Session);\n\n -- Create the member instance for this user.\n Member.Set_Workspace (WS);\n Member.Set_Member (User);\n Member.Set_Role (\"Owner\");\n Member.Set_Join_Date (ADO.Nullable_Time '(Is_Null => False, Value => WS.Get_Create_Date));\n Member.Save (Session);\n\n -- And give full control of the workspace for this user\n Add_Permission (Session => Session,\n User => User.Get_Id,\n Entity => WS,\n Workspace => WS.Get_Id,\n List => Plugin.Get_Owner_Permissions);\n\n Workspace := WS;\n end Get_Workspace;\n\n -- ------------------------------\n -- Create a workspace for the user.\n -- ------------------------------\n procedure Create_Workspace (Module : in Workspace_Module;\n Workspace : out AWA.Workspaces.Models.Workspace_Ref) is\n Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n WS : AWA.Workspaces.Models.Workspace_Ref;\n Member : AWA.Workspaces.Models.Workspace_Member_Ref;\n begin\n if User.Is_Null then\n Log.Error (\"There is no current user. The workspace cannot be identified\");\n Workspace := AWA.Workspaces.Models.Null_Workspace;\n return;\n end if;\n\n -- Check that the user has the permission to create a new workspace.\n AWA.Permissions.Check (Permission => ACL_Create_Workspace.Permission,\n Entity => User);\n\n DB.Begin_Transaction;\n\n -- Create a workspace for this user.\n WS.Set_Owner (User);\n WS.Set_Create_Date (Ada.Calendar.Clock);\n WS.Save (DB);\n\n -- Create the member instance for this user.\n Member.Set_Workspace (WS);\n Member.Set_Member (User);\n Member.Set_Role (\"Owner\");\n Member.Set_Join_Date (ADO.Nullable_Time '(Is_Null => False, Value => WS.Get_Create_Date));\n Member.Save (DB);\n\n -- And give full control of the workspace for this user\n Add_Permission (Session => DB,\n User => User.Get_Id,\n Entity => WS,\n Workspace => WS.Get_Id,\n List => Module.Get_Owner_Permissions);\n\n Workspace := WS;\n DB.Commit;\n end Create_Workspace;\n\n -- ------------------------------\n -- Load the invitation from the access key and verify that the key is still valid.\n -- ------------------------------\n procedure Load_Invitation (Module : in Workspace_Module;\n Key : in String;\n Invitation : in out AWA.Workspaces.Models.Invitation_Ref'Class;\n Inviter : in out AWA.Users.Models.User_Ref) is\n pragma Unreferenced (Module);\n use type Ada.Calendar.Time;\n\n Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Query : ADO.SQL.Query;\n DB_Key : AWA.Users.Models.Access_Key_Ref;\n Found : Boolean;\n begin\n Log.Debug (\"Loading invitation from key {0}\", Key);\n\n Query.Set_Filter (\"o.access_key = :key\");\n Query.Bind_Param (\"key\", Key);\n DB_Key.Find (DB, Query, Found);\n if not Found then\n Log.Info (\"Invitation key {0} does not exist\");\n raise Not_Found;\n end if;\n if DB_Key.Get_Expire_Date < Ada.Calendar.Clock then\n Log.Info (\"Invitation key {0} has expired\");\n raise Not_Found;\n end if;\n Query.Set_Filter (\"o.invitee_id = :user\");\n Query.Bind_Param (\"user\", DB_Key.Get_User.Get_Id);\n Invitation.Find (DB, Query, Found);\n if not Found then\n Log.Warn (\"Invitation key {0} has been withdawn\");\n raise Not_Found;\n end if;\n Inviter := AWA.Users.Models.User_Ref (Invitation.Get_Inviter);\n end Load_Invitation;\n\n -- ------------------------------\n -- Accept the invitation identified by the access key.\n -- ------------------------------\n procedure Accept_Invitation (Module : in Workspace_Module;\n Key : in String) is\n use type Ada.Calendar.Time;\n\n Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;\n DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Query : ADO.SQL.Query;\n DB_Key : AWA.Users.Models.Access_Key_Ref;\n Found : Boolean;\n Invitation : AWA.Workspaces.Models.Invitation_Ref;\n Invitee_Id : ADO.Identifier;\n Workspace_Id : ADO.Identifier;\n Member : AWA.Workspaces.Models.Workspace_Member_Ref;\n User_Member : AWA.Workspaces.Models.Workspace_Member_Ref;\n Now : constant Ada.Calendar.Time := Ada.Calendar.Clock;\n begin\n Log.Debug (\"Accept invitation with key {0}\", Key);\n Ctx.Start;\n\n -- Get the access key and verify its validity.\n Query.Set_Filter (\"o.access_key = :key\");\n Query.Bind_Param (\"key\", Key);\n DB_Key.Find (DB, Query, Found);\n if not Found then\n Log.Info (\"Invitation key {0} does not exist\", Key);\n raise Not_Found;\n end if;\n if DB_Key.Get_Expire_Date < Now then\n Log.Info (\"Invitation key {0} has expired\", Key);\n raise Not_Found;\n end if;\n\n -- Find the invitation associated with the access key.\n Invitee_Id := DB_Key.Get_User.Get_Id;\n Query.Set_Filter (\"o.invitee_id = :user\");\n Query.Bind_Param (\"user\", Invitee_Id);\n Invitation.Find (DB, Query, Found);\n if not Found then\n Log.Warn (\"Invitation key {0} has been withdawn\", Key);\n raise Not_Found;\n end if;\n Member := AWA.Workspaces.Models.Workspace_Member_Ref (Invitation.Get_Member);\n Workspace_Id := Invitation.Get_Workspace.Get_Id;\n\n -- Update the workspace member relation.\n Member.Set_Join_Date (ADO.Nullable_Time '(Is_Null => False,\n Value => Now));\n Invitation.Set_Acceptance_Date (ADO.Nullable_Time '(Is_Null => False,\n Value => Now));\n\n -- The user who received the invitation is different from the user who is\n -- logged and accepted the validation. Since the key is verified, this is\n -- the same user but the user who accepted the invitation registered using\n -- another email address.\n if Invitee_Id /= User.Get_Id then\n -- Check whether the user is not already part of the workspace.\n Query.Clear;\n Query.Set_Filter (\"o.member_id = ? AND o.workspace_id = ?\");\n Query.Add_Param (User.Get_Id);\n Query.Add_Param (Workspace_Id);\n User_Member.Find (DB, Query, Found);\n if Found then\n Member.Delete (DB);\n Invitation.Delete (DB);\n Log.Info (\"Invitation accepted by user who is already a member\");\n else\n Member.Set_Member (User);\n Log.Info (\"Invitation accepted by user with another email address\");\n Invitation.Set_Invitee (User);\n end if;\n end if;\n if not Member.Is_Null then\n Member.Save (DB);\n end if;\n DB_Key.Delete (DB);\n if not Invitation.Is_Null then\n Invitation.Save (DB);\n\n -- Send the accepted invitation event.\n declare\n Event : AWA.Events.Module_Event;\n begin\n Event.Set_Parameter (\"invitee_email\", User.Get_Email.Get_Email);\n Event.Set_Parameter (\"invitee_name\", User.Get_Name);\n Event.Set_Parameter (\"message\", Invitation.Get_Message);\n Event.Set_Parameter (\"inviter_email\", Invitation.Get_Inviter.Get_Email.Get_Email);\n Event.Set_Parameter (\"inviter_name\", Invitation.Get_Inviter.Get_Name);\n Event.Set_Event_Kind (Accept_Invitation_Event.Kind);\n Module.Send_Event (Event);" + }, + { + "function_def": "procedure Add_Permission (Session : in out ADO.Sessions.Master_Session;", + "function_body": "User : in ADO.Identifier;\n Entity : in ADO.Objects.Object_Ref'Class;\n Workspace : in ADO.Identifier;\n List : in Security.Permissions.Permission_Index_Array) is\n Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current;\n Key : constant ADO.Objects.Object_Key := Entity.Get_Key;\n Id : constant ADO.Identifier := ADO.Objects.Get_Value (Key);\n Kind : constant ADO.Entity_Type\n := ADO.Sessions.Entities.Find_Entity_Type (Session => Session,\n Object => Key);\n Manager : constant AWA.Permissions.Services.Permission_Manager_Access\n := AWA.Permissions.Services.Get_Permission_Manager (Ctx);\n begin\n for Perm of List loop\n declare\n Member : ADO.Identifier;\n Query : ADO.Queries.Context;\n Names : constant Security.Policies.Roles.Role_Name_Array\n := Manager.Get_Role_Names (Perm);\n Need_Sep : Boolean := False;\n User_Added : Boolean := False;\n begin\n if Names'Length > 0 then\n Query.Set_Query (AWA.Workspaces.Models.Query_Member_In_Role);\n ADO.SQL.Append (Query.Filter, \"user_member.workspace_id = :workspace_id\");\n ADO.SQL.Append (Query.Filter, \" AND user_member.member_id IN (\");\n for Name of Names loop\n ADO.SQL.Append (Query.Filter, (if Need_Sep then \",?\" else \"?\"));\n Query.Add_Param (Name.all);\n Need_Sep := True;\n end loop;\n Query.Bind_Param (\"workspace_id\", Workspace);\n ADO.SQL.Append (Query.Filter, \")\");\n declare\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n begin\n Stmt.Execute;\n while Stmt.Has_Elements loop\n Member := Stmt.Get_Identifier (0);\n if Member = User then\n User_Added := True;\n end if;\n Manager.Add_Permission (Session => Session,\n User => Member,\n Entity => Id,\n Kind => Kind,\n Workspace => Workspace,\n Permission => Perm);\n Stmt.Next;\n end loop;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Workspace_Impl, Workspace_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Workspace_Impl_Ptr := Workspace_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Workspace_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WORKSPACE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Workspace_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Workspace_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WORKSPACE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- owner_id\n Value => Object.Owner);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Workspace_Member_Impl, Workspace_Member_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Workspace_Member_Impl_Ptr := Workspace_Member_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Workspace_Member_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WORKSPACE_MEMBER_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Workspace_Member_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Workspace_Member_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WORKSPACE_MEMBER_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- join_date\n Value => Object.Join_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- role\n Value => Object.Role);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- member_id\n Value => Object.Member);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Invitation_Impl, Invitation_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Invitation_Impl_Ptr := Invitation_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Invitation_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, INVITATION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Invitation_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Invitation_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (INVITATION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- email\n Value => Object.Email);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- message\n Value => Object.Message);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- acceptance_date\n Value => Object.Acceptance_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_3_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_3_NAME, -- access_key_id\n Value => Object.Access_Key);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_3_NAME, -- invitee_id\n Value => Object.Invitee);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_3_NAME, -- inviter_id\n Value => Object.Inviter);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_3_NAME, -- member_id\n Value => Object.Member);\n Object.Clear_Modified (11);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Workspace_Feature_Impl, Workspace_Feature_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Workspace_Feature_Impl_Ptr := Workspace_Feature_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Workspace_Feature_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, WORKSPACE_FEATURE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Workspace_Feature_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Workspace_Feature_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (WORKSPACE_FEATURE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_4_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_4_NAME, -- limit\n Value => Object.Limit);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_4_NAME, -- workspace_id\n Value => Object.Workspace);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "function Get_Invitation_Bean is", + "function_body": "new ASF.Helpers.Beans.Get_Request_Bean (Element_Type => Beans.Invitation_Bean,\n Element_Access => Beans.Invitation_Bean_Access);\n\n package Caller is new Util.Test_Caller (Test, \"Workspaces.Beans\");\n\n procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is\n begin\n Caller.Add_Test (Suite, \"Test AWA.Workspaces.Beans.Send\",\n Test_Invite_User'Access);\n Caller.Add_Test (Suite, \"Test AWA.Workspaces.Beans.Delete\",\n Test_Delete_Member'Access);\n Caller.Add_Test (Suite, \"Test AWA.Workspaces.Beans.Accept\",\n Test_Accept_Invitation'Access);\n Caller.Add_Test (Suite, \"Test AWA.Workspaces.Beans.Member_List\",\n Test_List_Members'Access);\n end Add_Tests;\n\n -- ------------------------------\n -- Verify the anonymous access for the invitation page.\n -- ------------------------------\n procedure Verify_Anonymous (T : in out Test;\n Key : in String) is\n Request : ASF.Requests.Mockup.Request;\n Reply : ASF.Responses.Mockup.Response;\n begin\n ASF.Tests.Do_Get (Request, Reply, \"/auth/invitation.html\", \"invitation-view.html\");\n ASF.Tests.Assert_Contains (T, \"Bad or invalid invitation\", Reply,\n \"This invitation is invalid\");\n\n ASF.Tests.Do_Get (Request, Reply, \"/auth/invitation.html?key=test\", \"invitation-bad.html\");\n ASF.Tests.Assert_Contains (T, \"This invitation is invalid or has expired\", Reply,\n \"This invitation is invalid (key)\");\n\n ASF.Tests.Do_Get (Request, Reply, \"/auth/invitation.html?key=x\" & key,\n \"invitation-bad2.html\");\n ASF.Tests.Assert_Contains (T, \"This invitation is invalid or has expired\",\n Reply, \"This invitation is invalid (key)\");\n\n if Key = \"\" then\n return;\n end if;\n\n ASF.Tests.Do_Get (Request, Reply, \"/auth/invitation.html?key=\" & Key, \"invitation-ok.html\");\n ASF.Tests.Assert_Contains (T, \"Accept invitation\", Reply,\n \"Accept invitation page is invalid\");\n\n end Verify_Anonymous;\n\n -- ------------------------------\n -- Test sending an invitation.\n -- ------------------------------\n procedure Test_Invite_User (T : in out Test) is\n use type ADO.Identifier;\n use type AWA.Workspaces.Beans.Invitation_Bean_Access;\n\n Request : ASF.Requests.Mockup.Request;\n Reply : ASF.Responses.Mockup.Response;\n Invite : AWA.Workspaces.Beans.Invitation_Bean_Access;\n begin\n AWA.Tests.Helpers.Users.Login (\"test-invite@test.com\", Request);\n Request.Set_Parameter (\"email\", \"invited-user@test.com\");\n Request.Set_Parameter (\"message\", \"I invite you to this application\");\n Request.Set_Parameter (\"send\", \"1\");\n Request.Set_Parameter (\"invite\", \"1\");\n ASF.Tests.Do_Post (Request, Reply, \"/workspaces/invite.html\", \"invite.html\");\n\n T.Assert (Reply.Get_Status = ASF.Responses.SC_MOVED_TEMPORARILY,\n \"Invalid response after invitation creation\");\n\n -- Verify the invitation by looking at the inviteUser bean.\n Invite := Get_Invitation_Bean (Request, \"inviteUser\");\n T.Assert (Invite /= null, \"Null inviteUser bean\");\n T.Assert (Invite.Get_Id /= ADO.NO_IDENTIFIER, \"The invite ID is invalid\");\n T.Assert (not Invite.Get_Access_Key.Is_Null, \"The invite access key is null\");\n T.Assert (Invite.Get_Member.Is_Inserted, \"The invitation has a workspace member\");\n T.Key := Invite.Get_Access_Key.Get_Access_Key;\n T.Verify_Anonymous (Invite.Get_Access_Key.Get_Access_Key);\n\n T.Member_ID := Invite.Get_Member.Get_Id;\n end Test_Invite_User;\n\n -- ------------------------------\n -- Test deleting the member.\n -- ------------------------------\n procedure Test_Delete_Member (T : in out Test) is\n Request : ASF.Requests.Mockup.Request;\n Reply : ASF.Responses.Mockup.Response;\n begin\n T.Test_Invite_User;\n AWA.Tests.Helpers.Users.Login (\"test-invite@test.com\", Request);\n declare\n Id : constant String := ADO.Identifier'Image (T.Member_Id);\n begin\n Request.Set_Parameter (\"member-id\", Id);\n Request.Set_Parameter (\"delete\", \"1\");\n Request.Set_Parameter (\"delete-member-form\", \"1\");\n ASF.Tests.Do_Post (Request, Reply, \"/workspaces/forms/delete-member.html\",\n \"delete-member.html\");\n\n T.Assert (Reply.Get_Status = ASF.Responses.SC_OK,\n \"Invalid response after delete member operation\");\n ASF.Tests.Assert_Contains (T, \"deleteDialog_\" & Id (Id'First + 1 .. Id'Last), Reply,\n \"Delete member dialog operation response is invalid\");" + }, + { + "function_def": "function Get is new AWA.Modules.Get (Counter_Module, Counter_Module_Access, NAME);", + "function_body": "begin\n return Get;\n end Get_Counter_Module;\n\n -- ------------------------------\n -- Increment the counter identified by Counter and associated with the\n -- database object Object.\n -- ------------------------------\n procedure Increment (Plugin : in out Counter_Module;\n Counter : in Counter_Index_Type;\n Object : in ADO.Objects.Object_Ref'Class) is\n Key : constant ADO.Objects.Object_Key := Object.Get_Key;\n begin\n if Plugin.Counters.Need_Flush (Plugin.Counter_Limit, Plugin.Age_Limit) then\n Plugin.Flush;\n end if;\n Plugin.Counters.Increment (Counter, Key);\n end Increment;\n\n -- ------------------------------\n -- Increment the counter identified by Counter and associated with the\n -- database object key Key.\n -- ------------------------------\n procedure Increment (Plugin : in out Counter_Module;\n Counter : in Counter_Index_Type;\n Key : in ADO.Objects.Object_Key) is\n begin\n if Plugin.Counters.Need_Flush (Plugin.Counter_Limit, Plugin.Age_Limit) then\n Plugin.Flush;\n end if;\n Plugin.Counters.Increment (Counter, Key);\n end Increment;\n\n -- ------------------------------\n -- Increment the counter identified by Counter.\n -- ------------------------------\n procedure Increment (Plugin : in out Counter_Module;\n Counter : in Counter_Index_Type) is\n Key : ADO.Objects.Object_Key (ADO.Objects.KEY_INTEGER, null);\n begin\n if Plugin.Counters.Need_Flush (Plugin.Counter_Limit, Plugin.Age_Limit) then\n Plugin.Flush;\n end if;\n Plugin.Counters.Increment (Counter, Key);\n end Increment;\n\n -- ------------------------------\n -- Get the current counter value.\n -- ------------------------------\n procedure Get_Counter (Plugin : in out Counter_Module;\n Counter : in AWA.Counters.Counter_Index_Type;\n Object : in ADO.Objects.Object_Ref'Class;\n Result : out Natural) is\n Id : constant ADO.Identifier := ADO.Objects.Get_Value (Object.Get_Key);\n DB : ADO.Sessions.Master_Session := Plugin.Get_Master_Session;\n Stmt : ADO.Statements.Query_Statement\n := DB.Create_Statement (\"SELECT SUM(counter) FROM awa_counter WHERE \"\n & \"object_id = :id AND definition_id = :definition_id\");\n Def_Id : Natural;\n begin\n Plugin.Counters.Get_Definition (DB, Counter, Def_Id);\n Stmt.Bind_Param (\"id\", Id);\n Stmt.Bind_Param (\"definition_id\", Def_Id);\n Stmt.Execute;\n Result := Stmt.Get_Result_Integer;\n end Get_Counter;\n\n protected body Counter_Table is\n\n -- ------------------------------\n -- Increment the counter identified by Counter and associated with the\n -- database object Key.\n -- ------------------------------\n procedure Increment (Counter : in Counter_Index_Type;\n Key : in ADO.Objects.Object_Key) is\n\n procedure Increment (Key : in ADO.Objects.Object_Key;\n Element : in out Positive);\n\n procedure Increment (Key : in ADO.Objects.Object_Key;\n Element : in out Positive) is\n pragma Unreferenced (Key);\n begin\n Element := Element + 1;\n end Increment;\n\n Pos : Counter_Maps.Cursor;\n begin\n if Counters = null then\n Counters := new Counter_Map_Array (1 .. Counter_Arrays.Get_Last);\n Day := Ada.Calendar.Clock;\n Day_End := Util.Dates.Get_Day_End (Day);\n end if;\n Pos := Counters (Counter).Find (Key);\n if Counter_Maps.Has_Element (Pos) then\n Counters (Counter).Update_Element (Pos, Increment'Access);\n else\n Counters (Counter).Insert (Key, 1);\n Nb_Counters := Nb_Counters + 1;\n end if;\n end Increment;\n\n -- ------------------------------\n -- Get the counters that have been collected with the date and prepare to collect\n -- new counters.\n -- ------------------------------\n procedure Steal_Counters (Result : out Counter_Map_Array_Access;\n Date : out Ada.Calendar.Time) is\n begin\n Result := Counters;\n Date := Day;\n Counters := null;\n Nb_Counters := 0;\n end Steal_Counters;\n\n -- ------------------------------\n -- Check if we must flush the counters.\n -- ------------------------------\n function Need_Flush (Limit : in Natural;\n Seconds : in Duration) return Boolean is\n use type Ada.Calendar.Time;\n begin\n if Counters = null then\n return False;\n elsif Nb_Counters > Limit then\n return True;\n else\n declare\n Now : constant Ada.Calendar.Time := Ada.Calendar.Clock;\n begin\n return Now > Day_End or Now - Day >= Seconds;" + }, + { + "function_def": "procedure Free is new", + "function_body": "Ada.Unchecked_Deallocation (Object => Counter_Map_Array,\n Name => Counter_Map_Array_Access);\n\n Day : Ada.Calendar.Time;\n Counters : Counter_Map_Array_Access;\n begin\n Plugin.Counters.Steal_Counters (Counters, Day);\n if Counters = null then\n return;\n end if;\n declare\n DB : ADO.Sessions.Master_Session := Plugin.Get_Master_Session;\n Date : constant Ada.Calendar.Time := Util.Dates.Get_Day_Start (Day);\n Def_Id : Natural;\n begin\n DB.Begin_Transaction;\n for I in Counters'Range loop\n if not Counters (I).Is_Empty then\n declare\n Counter : constant Counter_Def := Counter_Arrays.Get_Element (I).all;\n begin\n Plugin.Counters.Get_Definition (DB, I, Def_Id);\n Flush (DB, Counter, Def_Id, Counters (I), Date);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Counter_Impl, Counter_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Counter_Impl_Ptr := Counter_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Counter_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, COUNTER_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Counter_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"definition_id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Counter_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (COUNTER_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- object_id\n Value => Object.Object_Id);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- date\n Value => Object.Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- counter\n Value => Object.Counter);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- definition_id\n Value => Object.Get_Key);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"definition_id = ? AND object_id = ? AND date = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Object_Id);\n Stmt.Add_Param (Value => Object.Date);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Counter_Definition_Impl, Counter_Definition_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Counter_Definition_Impl_Ptr := Counter_Definition_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Counter_Definition_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, COUNTER_DEFINITION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Counter_Definition_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Counter_Definition_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (COUNTER_DEFINITION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "function Visit_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key is", + "function_body": "Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,\n Of_Class => VISIT_DEF'Access);\n begin\n ADO.Objects.Set_Value (Result, Id);\n return Result;\n end Visit_Key;\n\n function Visit_Key (Id : in String) return ADO.Objects.Object_Key is\n Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,\n Of_Class => VISIT_DEF'Access);\n begin\n ADO.Objects.Set_Value (Result, Id);\n return Result;\n end Visit_Key;\n\n function \"=\" (Left, Right : Visit_Ref'Class) return Boolean is\n begin\n return ADO.Objects.Object_Ref'Class (Left) = ADO.Objects.Object_Ref'Class (Right);\n end \"=\";\n\n procedure Set_Field (Object : in out Visit_Ref'Class;\n Impl : out Visit_Access) is\n Result : ADO.Objects.Object_Record_Access;\n begin\n Object.Prepare_Modify (Result);\n Impl := Visit_Impl (Result.all)'Access;\n end Set_Field;\n\n -- Internal method to allocate the Object_Record instance\n procedure Allocate (Object : in out Visit_Ref) is\n Impl : Visit_Access;\n begin\n Impl := new Visit_Impl;\n Impl.Object_Id := ADO.NO_IDENTIFIER;\n Impl.Counter := 0;\n Impl.Date := ADO.DEFAULT_TIME;\n Impl.User := ADO.NO_IDENTIFIER;\n ADO.Objects.Set_Object (Object, Impl.all'Access);\n end Allocate;\n\n -- ----------------------------------------\n -- Data object: Visit\n -- ----------------------------------------\n\n procedure Set_Object_Id (Object : in out Visit_Ref;\n Value : in ADO.Identifier) is\n Impl : Visit_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Identifier (Impl.all, 1, Impl.Object_Id, Value);\n end Set_Object_Id;\n\n function Get_Object_Id (Object : in Visit_Ref)\n return ADO.Identifier is\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Object_Id;\n end Get_Object_Id;\n\n\n procedure Set_Counter (Object : in out Visit_Ref;\n Value : in Integer) is\n Impl : Visit_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 2, Impl.Counter, Value);\n end Set_Counter;\n\n function Get_Counter (Object : in Visit_Ref)\n return Integer is\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Counter;\n end Get_Counter;\n\n\n procedure Set_Date (Object : in out Visit_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Visit_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 3, Impl.Date, Value);\n end Set_Date;\n\n function Get_Date (Object : in Visit_Ref)\n return Ada.Calendar.Time is\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Date;\n end Get_Date;\n\n\n procedure Set_User (Object : in out Visit_Ref;\n Value : in ADO.Identifier) is\n Impl : Visit_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Identifier (Impl.all, 4, Impl.User, Value);\n end Set_User;\n\n function Get_User (Object : in Visit_Ref)\n return ADO.Identifier is\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User;\n end Get_User;\n\n\n procedure Set_Definition_Id (Object : in out Visit_Ref;\n Value : in ADO.Identifier) is\n Impl : Visit_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Key_Value (Impl.all, 5, Value);\n end Set_Definition_Id;\n\n function Get_Definition_Id (Object : in Visit_Ref)\n return ADO.Identifier is\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Object.all)'Access;\n begin\n return Impl.Get_Key_Value;\n end Get_Definition_Id;\n\n -- Copy of the object.\n procedure Copy (Object : in Visit_Ref;\n Into : in out Visit_Ref) is\n Result : Visit_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Visit_Access\n := Visit_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Visit_Access\n := new Visit_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Object_Id := Impl.Object_Id;\n Copy.Counter := Impl.Counter;\n Copy.Date := Impl.Date;\n Copy.User := Impl.User;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Visit_Impl, Visit_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Visit_Impl_Ptr := Visit_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Visit_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, VISIT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Visit_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"definition_id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Visit_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (VISIT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- object_id\n Value => Object.Object_Id);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- counter\n Value => Object.Counter);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- date\n Value => Object.Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- user\n Value => Object.User);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- definition_id\n Value => Object.Get_Key);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"definition_id = ? AND object_id = ? AND user = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Object_Id);\n Stmt.Add_Param (Value => Object.User);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Visit_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, VISIT_DEF'Access);\n begin\n Stmt.Execute;\n Visit_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Visit_Ref;\n Impl : constant Visit_Access := new Visit_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Register_Functions is", + "function_body": "new ASF.Applications.Main.Register_Functions (AWA.Permissions.Services.Set_Functions);\n begin\n Log.Info (\"Initializing application components\");\n\n ASF.Applications.Main.Application (App).Initialize_Components;\n App.Add_Components (AWA.Components.Factory.Definition);\n Register_Functions (App);\n end Initialize_Components;\n\n -- ------------------------------\n -- Read the application configuration file awa.xml. This is called after the servlets\n -- and filters have been registered in the application but before the module registration.\n -- ------------------------------\n procedure Load_Configuration (App : in out Application;\n Files : in String) is\n procedure Load_Config (File : in String;\n Done : out Boolean);\n\n Paths : constant String := App.Get_Config (P_Module_Dir.P);\n Ctx : aliased EL.Contexts.Default.Default_Context;\n\n procedure Load_Config (File : in String;\n Done : out Boolean) is\n Path : constant String := Util.Files.Find_File_Path (File, Paths);\n begin\n Done := False;\n AWA.Applications.Configs.Read_Configuration (App, Path, Ctx'Unchecked_Access, True);\n\n exception\n when Ada.IO_Exceptions.Name_Error =>\n Log.Warn (\"Application configuration file '{0}' does not exist\", Path);\n\n end Load_Config;\n\n begin\n Util.Files.Iterate_Path (Files, Load_Config'Access);\n end Load_Configuration;\n\n -- ------------------------------\n -- Initialize the AWA modules provided by the application.\n -- This procedure is called by Initialize.\n -- It should register the modules used by the application.\n -- ------------------------------\n procedure Initialize_Modules (App : in out Application) is\n begin\n null;\n end Initialize_Modules;\n\n -- ------------------------------\n -- Start the application. This is called by the server container when the server is started.\n -- ------------------------------\n overriding\n procedure Start (App : in out Application) is\n Manager : constant Security.Policies.Policy_Manager_Access\n := App.Get_Security_Manager;\n begin\n -- Start the security manager.\n AWA.Permissions.Services.Permission_Manager'Class (Manager.all).Start;\n\n -- Start the event service.\n App.Events.Start;\n\n -- Start the application.\n ASF.Applications.Main.Application (App).Start;\n\n -- Dump the route and filters to help in configuration issues.\n App.Dump_Routes (Util.Log.INFO_LEVEL);\n end Start;\n\n -- ------------------------------\n -- Close the application.\n -- ------------------------------\n overriding\n procedure Close (App : in out Application) is\n begin\n App.Events.Stop;\n ASF.Applications.Main.Application (App).Close;\n end Close;\n\n -- ------------------------------\n -- Register the module in the application\n -- ------------------------------\n procedure Register (App : in Application_Access;\n Module : access AWA.Modules.Module'Class;\n Name : in String;\n URI : in String := \"\") is\n begin\n App.Register (Module.all'Unchecked_Access, Name, URI);\n end Register;\n\n -- ------------------------------\n -- Get the database connection for reading\n -- ------------------------------\n function Get_Session (App : Application)\n return ADO.Sessions.Session is\n begin\n return App.DB_Factory.Get_Session;\n end Get_Session;\n\n -- ------------------------------\n -- Get the database connection for writing\n -- ------------------------------\n function Get_Master_Session (App : Application)\n return ADO.Sessions.Master_Session is\n begin\n return App.DB_Factory.Get_Master_Session;\n end Get_Master_Session;\n\n -- ------------------------------\n -- Find the module with the given name\n -- ------------------------------\n function Find_Module (App : in Application;\n Name : in String) return AWA.Modules.Module_Access is\n begin\n return AWA.Modules.Find_By_Name (App.Modules, Name);\n end Find_Module;\n\n -- ------------------------------\n -- Register the module in the application\n -- ------------------------------\n procedure Register (App : in out Application;\n Module : in AWA.Modules.Module_Access;\n Name : in String;\n URI : in String := \"\") is\n begin\n AWA.Modules.Register (App.Modules'Unchecked_Access, App'Unchecked_Access, Module, Name, URI);\n end Register;\n\n -- ------------------------------\n -- Send the event in the application event queues.\n -- ------------------------------\n procedure Send_Event (App : in Application;\n Event : in AWA.Events.Module_Event'Class) is\n begin\n App.Events.Send (Event);\n end Send_Event;\n\n -- ------------------------------\n -- Execute the Process procedure with the event manager used by the application.\n -- ------------------------------\n procedure Do_Event_Manager (App : in out Application;\n Process : access procedure\n (Events : in out AWA.Events.Services.Event_Manager)) is\n begin\n Process (App.Events);\n end Do_Event_Manager;\n\n -- ------------------------------\n -- Initialize the parser represented by Parser to recognize the configuration\n -- that are specific to the plugins that have been registered so far.\n -- ------------------------------\n procedure Initialize_Parser (App : in out Application'Class;\n Parser : in out Util.Serialize.IO.Parser'Class) is\n procedure Process (Module : in out AWA.Modules.Module'Class);\n\n procedure Process (Module : in out AWA.Modules.Module'Class) is\n begin\n Module.Initialize_Parser (Parser);\n end Process;\n begin\n AWA.Modules.Iterate (App.Modules, Process'Access);\n end Initialize_Parser;\n\n -- ------------------------------\n -- Get the current application from the servlet context or service context.\n -- ------------------------------\n function Current return Application_Access is\n use type AWA.Services.Contexts.Service_Context_Access;\n\n Ctx : constant AWA.Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n begin\n if Ctx /= null then\n return Ctx.Get_Application;\n end if;\n\n -- If there is no service context, look in the servlet current context.\n declare\n use type ASF.Servlets.Servlet_Registry_Access;\n\n Ctx : constant ASF.Servlets.Servlet_Registry_Access := ASF.Server.Current;\n begin\n if Ctx = null then\n Log.Warn (\"There is no service context\");\n return null;\n end if;\n if not (Ctx.all in AWA.Applications.Application'Class) then\n Log.Warn (\"The servlet context is not an application\");\n return null;\n end if;\n return AWA.Applications.Application'Class (Ctx.all)'Access;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => Consumer_Array,\n Name => Consumer_Array_Access);\n begin\n if Manager.Workers /= null then\n Log.Info (\"Stopping the event dispatcher tasks\");\n\n for I in Manager.Workers'Range loop\n if Manager.Workers (I)'Callable then\n Manager.Workers (I).Stop;\n else\n Log.Error (\"Event consumer task terminated abnormally\");\n end if;\n end loop;\n Free (Manager.Workers);\n end if;\n end Stop;\n\n procedure Add_Queue (Manager : in out Task_Dispatcher;\n Queue : in AWA.Events.Queues.Queue_Ref;\n Added : out Boolean) is\n begin\n Log.Info (\"Adding queue {0} to the task dispatcher\", Queue.Get_Name);\n\n Manager.Queues.Enqueue (Queue);\n Added := True;\n end Add_Queue;\n\n function Create_Dispatcher (Service : in AWA.Events.Services.Event_Manager_Access;\n Match : in String;\n Count : in Positive;\n Priority : in Positive) return Dispatcher_Access is\n Result : constant Task_Dispatcher_Access := new Task_Dispatcher;\n begin\n Result.Task_Count := Count;\n Result.Priority := Priority;\n Result.Match := To_Unbounded_String (Match);\n Result.Manager := Service.all'Access;\n return Result.all'Access;\n end Create_Dispatcher;\n\n task body Consumer is\n Dispatcher : Task_Dispatcher_Access;\n Time : Duration := 0.01;\n Do_Work : Boolean := True;\n Context : AWA.Services.Contexts.Service_Context;\n begin\n Log.Info (\"Event consumer is ready\");\n select\n accept Start (D : in Task_Dispatcher_Access) do\n Dispatcher := D;\n end Start;\n Log.Info (\"Event consumer is started\");\n\n -- Set the service context.\n Context.Set_Context (Application => Dispatcher.Manager.Get_Application.all'Access,\n Principal => null);\n while Do_Work loop\n declare\n Nb_Queues : constant Natural := Dispatcher.Queues.Get_Count;\n Queue : AWA.Events.Queues.Queue_Ref;\n Nb_Events : Natural := 0;\n begin\n -- We can have several tasks that dispatch events from several queues.\n -- Each queue in the list must be given the same polling quota.\n -- Pick a queue and dispatch some pending events.\n -- Put back the queue in the fifo.\n for I in 1 .. Nb_Queues loop\n Dispatcher.Queues.Dequeue (Queue);\n begin\n Dispatcher.Dispatch (Queue, Nb_Events);\n\n exception\n when E : others =>\n Log.Error (\"Exception when dispatching events\", E, True);" + }, + { + "function_def": "procedure Register_User (Data : in out Authenticate_Bean;", + "function_body": "Outcome : in out Unbounded_String) is\n User : User_Ref;\n Email : Email_Ref;\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Flash : constant ASF.Contexts.Faces.Flash_Context_Access := Ctx.Get_Flash;\n begin\n Email.Set_Email (Data.Email);\n User.Set_First_Name (Data.First_Name);\n User.Set_Last_Name (Data.Last_Name);\n User.Set_Password (Data.Password);\n Data.Manager.Create_User (User => User,\n Email => Email);\n Outcome := To_Unbounded_String (\"success\");\n\n -- Add a message to the flash context so that it will be displayed on the next page.\n Flash.Set_Keep_Messages (True);\n Messages.Factory.Add_Message (Ctx.all, \"users.message_signup_sent\", Messages.INFO);\n\n exception\n when Services.User_Exist =>\n Outcome := To_Unbounded_String (\"failure\");\n\n Messages.Factory.Add_Message (Ctx.all, \"users.signup_error_message\");\n end Register_User;\n\n -- ------------------------------\n -- Action to verify the user after the registration\n -- ------------------------------\n procedure Verify_User (Data : in out Authenticate_Bean;\n Outcome : in out Unbounded_String) is\n Principal : AWA.Users.Principals.Principal_Access;\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Flash : constant ASF.Contexts.Faces.Flash_Context_Access := Ctx.Get_Flash;\n begin\n Data.Manager.Verify_User (Key => To_String (Data.Access_Key),\n IpAddr => \"\",\n Principal => Principal);\n\n Data.Set_Session_Principal (Principal);\n Outcome := To_Unbounded_String (\"success\");\n\n -- Add a message to the flash context so that it will be displayed on the next page.\n Flash.Set_Keep_Messages (True);\n Messages.Factory.Add_Message (Ctx.all, \"users.message_registration_done\", Messages.INFO);\n\n exception\n when Services.Not_Found =>\n Outcome := To_Unbounded_String (\"failure\");\n Messages.Factory.Add_Message (Ctx.all, \"users.error_verify_register_key\");\n end Verify_User;\n\n\n -- ------------------------------\n -- Action to trigger the lost password email process.\n -- ------------------------------\n procedure Lost_Password (Data : in out Authenticate_Bean;\n Outcome : in out Unbounded_String) is\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Flash : constant ASF.Contexts.Faces.Flash_Context_Access := Ctx.Get_Flash;\n begin\n Data.Manager.Lost_Password (Email => To_String (Data.Email));\n Outcome := To_Unbounded_String (\"success\");\n\n -- Add a message to the flash context so that it will be displayed on the next page.\n Flash.Set_Keep_Messages (True);\n Messages.Factory.Add_Message (Ctx.all, \"users.message_lost_password_sent\", Messages.INFO);\n\n exception\n when Services.Not_Found =>\n Messages.Factory.Add_Message (Ctx.all, \"users.error_email_not_found\");\n\n end Lost_Password;\n\n -- ------------------------------\n -- Action to validate the reset password key and set a new password.\n -- ------------------------------\n procedure Reset_Password (Data : in out Authenticate_Bean;\n Outcome : in out Unbounded_String) is\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Flash : constant ASF.Contexts.Faces.Flash_Context_Access := Ctx.Get_Flash;\n Principal : AWA.Users.Principals.Principal_Access;\n begin\n Data.Manager.Reset_Password (Key => To_String (Data.Access_Key),\n Password => To_String (Data.Password),\n IpAddr => \"\",\n Principal => Principal);\n Data.Set_Session_Principal (Principal);\n Outcome := To_Unbounded_String (\"success\");\n\n -- Add a message to the flash context so that it will be displayed on the next page.\n Flash.Set_Keep_Messages (True);\n Messages.Factory.Add_Message (Ctx.all, \"users.message_reset_password_done\", Messages.INFO);\n\n exception\n when Services.Not_Found =>\n Messages.Factory.Add_Message (Ctx.all, \"users.error_reset_password\");\n end Reset_Password;\n\n\n procedure Set_Session_Principal (Data : in Authenticate_Bean;\n Principal : in AWA.Users.Principals.Principal_Access) is\n pragma Unreferenced (Data);\n\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Session : ASF.Sessions.Session := Ctx.Get_Session (Create => True);\n begin\n Session.Set_Principal (Principal.all'Access);\n end Set_Session_Principal;\n\n procedure Set_Authenticate_Cookie (Data : in out Authenticate_Bean;\n Principal : in AWA.Users.Principals.Principal_Access) is\n Id : constant ADO.Identifier := Principal.Get_Session_Identifier;\n Cookie : constant String := Data.Manager.Get_Authenticate_Cookie (Id);\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n C : ASF.Cookies.Cookie := ASF.Cookies.Create (ASF.Security.Filters.AID_COOKIE, Cookie);\n begin\n ASF.Cookies.Set_Path (C, Ctx.Get_Request.Get_Context_Path);\n ASF.Cookies.Set_Max_Age (C, 15 * 86400);\n Ctx.Get_Response.Add_Cookie (Cookie => C);\n end Set_Authenticate_Cookie;\n\n -- ------------------------------\n -- Action to authenticate a user (password authentication).\n -- ------------------------------\n procedure Authenticate_User (Data : in out Authenticate_Bean;\n Outcome : in out Unbounded_String) is\n Principal : AWA.Users.Principals.Principal_Access;\n begin\n Data.Manager.Authenticate (Email => To_String (Data.Email),\n Password => To_String (Data.Password),\n IpAddr => \"\",\n Principal => Principal);\n Outcome := To_Unbounded_String (\"success\");\n\n Data.Set_Session_Principal (Principal);\n Data.Set_Authenticate_Cookie (Principal);\n\n exception\n when Services.Not_Found =>\n Outcome := To_Unbounded_String (\"failure\");\n\n ASF.Applications.Messages.Factory.Add_Message (\"users.login_signup_fail_message\");\n end Authenticate_User;\n\n -- ------------------------------\n -- Helper to send a remove cookie in the current response\n -- ------------------------------\n procedure Remove_Cookie (Name : in String) is\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n C : ASF.Cookies.Cookie := ASF.Cookies.Create (Name, \"\");\n begin\n ASF.Cookies.Set_Path (C, Ctx.Get_Request.Get_Context_Path);\n ASF.Cookies.Set_Max_Age (C, 0);\n Ctx.Get_Response.Add_Cookie (Cookie => C);\n end Remove_Cookie;\n\n -- ------------------------------\n -- Logout the user and closes the session.\n -- ------------------------------\n procedure Logout_User (Data : in out Authenticate_Bean;\n Outcome : in out Unbounded_String) is\n use type ASF.Principals.Principal_Access;\n\n Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;\n Session : ASF.Sessions.Session := Ctx.Get_Session (Create => False);\n begin\n Outcome := To_Unbounded_String (\"success\");\n\n -- If there is no session, we are done.\n if not Session.Is_Valid then\n return;\n end if;\n\n declare\n Principal : constant ASF.Principals.Principal_Access := Session.Get_Principal;\n begin\n if Principal /= null and then Principal.all in AWA.Users.Principals.Principal'Class then\n declare\n P : constant AWA.Users.Principals.Principal_Access :=\n AWA.Users.Principals.Principal'Class (Principal.all)'Access;\n begin\n Data.Manager.Close_Session (Id => P.Get_Session_Identifier,\n Logout => True);\n\n exception\n when others =>\n Log.Error (\"Exception when closing user session...\");" + }, + { + "function_def": "procedure Dispatch (Manager : in Event_Manager;", + "function_body": "Queue : in AWA.Events.Queues.Queue_Ref;\n Event : in Module_Event'Class) is\n procedure Find_Queue (List : in Queue_Dispatcher);\n\n Found : Boolean := False;\n\n procedure Find_Queue (List : in Queue_Dispatcher) is\n begin\n if List.Queue = Queue then\n List.Dispatcher.Dispatch (Event);\n Found := True;\n end if;\n end Find_Queue;\n\n Name : constant Name_Access := Get_Event_Type_Name (Event.Kind);\n begin\n if Name = null then\n Log.Error (\"Cannot dispatch event type {0}\", Event_Index'Image (Event.Kind));\n raise Not_Found;\n end if;\n\n declare\n Pos : Queue_Dispatcher_Lists.Cursor := Manager.Actions (Event.Kind).Queues.First;\n begin\n if not Queue_Dispatcher_Lists.Has_Element (Pos) then\n Log.Debug (\"Dispatching event {0} but there is no listener\", Name.all);\n else\n Log.Debug (\"Dispatching event {0}\", Name.all);\n loop\n Queue_Dispatcher_Lists.Query_Element (Pos, Find_Queue'Access);\n exit when Found;\n Queue_Dispatcher_Lists.Next (Pos);\n if not Queue_Dispatcher_Lists.Has_Element (Pos) then\n Log.Debug (\"Dispatched event {0} but there was no listener\", Name.all);\n exit;\n end if;\n end loop;\n end if;" + }, + { + "function_def": "procedure Add_Dispatcher (Manager : in out Event_Manager;", + "function_body": "Match : in String;\n Count : in Positive;\n Priority : in Positive) is\n use type AWA.Events.Dispatchers.Dispatcher_Access;\n begin\n Log.Info (\"Adding event dispatcher with {0} tasks prio {1} and dispatching queues '{2}'\",\n Positive'Image (Count), Positive'Image (Priority), Match);\n\n for I in Manager.Dispatchers'Range loop\n if Manager.Dispatchers (I) = null then\n Manager.Dispatchers (I) :=\n AWA.Events.Dispatchers.Tasks.Create_Dispatcher (Manager'Unchecked_Access,\n Match, Count, Priority);\n return;\n end if;\n end loop;\n Log.Error (\"Implementation limit is reached. Too many dispatcher.\");\n end Add_Dispatcher;\n\n -- ------------------------------\n -- Initialize the event manager.\n -- ------------------------------\n procedure Initialize (Manager : in out Event_Manager;\n App : in Application_Access) is\n procedure Set_Events (Msg : in AWA.Events.Models.Message_Type_Ref);\n\n Msg_Types : AWA.Events.Models.Message_Type_Vector;\n\n Query : ADO.SQL.Query;\n\n procedure Set_Events (Msg : in AWA.Events.Models.Message_Type_Ref) is\n Name : constant String := Msg.Get_Name;\n begin\n declare\n Index : constant Event_Index := Find_Event_Index (Name);\n begin\n Manager.Actions (Index).Event := Msg;" + }, + { + "function_def": "procedure Associate_Dispatcher (Key : in String;", + "function_body": "Queue : in out AWA.Events.Queues.Queue_Ref);\n\n -- ------------------------------\n -- Dispatch the event queues to the dispatcher according to the dispatcher configuration.\n -- ------------------------------\n procedure Associate_Dispatcher (Key : in String;\n Queue : in out AWA.Events.Queues.Queue_Ref) is\n pragma Unreferenced (Key);\n\n Added : Boolean := False;\n begin\n for I in reverse Manager.Dispatchers'Range loop\n if Manager.Dispatchers (I) /= null then\n Manager.Dispatchers (I).Add_Queue (Queue, Added);\n exit when Added;\n end if;\n end loop;\n end Associate_Dispatcher;\n\n Iter : AWA.Events.Queues.Maps.Cursor := Manager.Queues.First;\n begin\n Log.Info (\"Starting the event manager\");\n\n while AWA.Events.Queues.Maps.Has_Element (Iter) loop\n Manager.Queues.Update_Element (Iter, Associate_Dispatcher'Access);\n AWA.Events.Queues.Maps.Next (Iter);\n end loop;\n\n -- Start the dispatchers.\n for I in Manager.Dispatchers'Range loop\n exit when Manager.Dispatchers (I) = null;\n Manager.Dispatchers (I).Start;\n end loop;\n end Start;\n\n -- ------------------------------\n -- Stop the event manager.\n -- ------------------------------\n procedure Stop (Manager : in out Event_Manager) is\n use type AWA.Events.Dispatchers.Dispatcher_Access;\n begin\n Log.Info (\"Stopping the event manager\");\n\n -- Stop the dispatchers.\n for I in Manager.Dispatchers'Range loop\n exit when Manager.Dispatchers (I) = null;\n Manager.Dispatchers (I).Stop;\n end loop;\n end Stop;\n\n -- ------------------------------\n -- Get the application associated with the event manager.\n -- ------------------------------\n function Get_Application (Manager : in Event_Manager) return Application_Access is\n begin\n return Manager.Application;\n end Get_Application;\n\n -- ------------------------------\n -- Finalize the queue dispatcher releasing the dispatcher memory.\n -- ------------------------------\n procedure Finalize (Object : in out Queue_Dispatcher) is\n procedure Free is\n new Ada.Unchecked_Deallocation (Object => AWA.Events.Dispatchers.Dispatcher'Class,\n Name => AWA.Events.Dispatchers.Dispatcher_Access);\n begin\n Free (Object.Dispatcher);\n end Finalize;\n\n -- ------------------------------\n -- Finalize the event queues and the dispatchers.\n -- ------------------------------\n procedure Finalize (Object : in out Event_Queues) is\n begin\n loop\n declare\n Pos : constant Queue_Dispatcher_Lists.Cursor := Object.Queues.First;\n begin\n exit when not Queue_Dispatcher_Lists.Has_Element (Pos);\n\n Object.Queues.Update_Element (Position => Pos,\n Process => Finalize'Access);\n Object.Queues.Delete_First;" + }, + { + "function_def": "function Has_Permission (Handler : in Entity_Controller;", + "function_body": "Context : in Security.Contexts.Security_Context'Class;\n Permission : in Security.Permissions.Permission'Class)\n return Boolean is\n use AWA.Permissions.Services;\n use AWA.Users.Principals;\n use type ADO.Identifier;\n use type ADO.Entity_Type;\n\n Manager : constant Permission_Manager_Access := Get_Permission_Manager (Context);\n User_Id : constant ADO.Identifier := Get_User_Identifier (Context.Get_User_Principal);\n Entity_Id : ADO.Identifier;\n begin\n -- If there is no permission manager, permission is denied.\n if Manager = null or else User_Id = ADO.NO_IDENTIFIER then\n return False;\n end if;\n\n -- If the user is not logged, permission is denied.\n if Manager = null or else User_Id = ADO.NO_IDENTIFIER then\n Log.Info (\"No user identifier in the security context. Permission is denied\");\n return False;\n end if;\n\n if not (Permission in Entity_Permission'Class) then\n Log.Info (\"Permission {0} denied because the entity is not given.\",\n Security.Permissions.Permission_Index'Image (Permission.Id));\n return False;\n end if;\n Entity_Id := Entity_Permission'Class (Permission).Entity;\n\n -- If the security context does not contain the entity identifier, permission is denied.\n if Entity_Id = ADO.NO_IDENTIFIER then\n Log.Info (\"No entity identifier in the security context. Permission is denied\");\n return False;\n end if;\n\n declare\n function Get_Session return ADO.Sessions.Session;\n\n -- ------------------------------\n -- Get a database session from the AWA application.\n -- There is no guarantee that a AWA.Services.Contexts be available.\n -- But if we are within a service context, we must use the current session so\n -- that we are part of the current transaction.\n -- ------------------------------\n function Get_Session return ADO.Sessions.Session is\n package ASC renames AWA.Services.Contexts;\n use type ASC.Service_Context_Access;\n\n Ctx : constant ASC.Service_Context_Access := ASC.Current;\n begin\n if Ctx /= null then\n return AWA.Services.Contexts.Get_Session (Ctx);\n else\n return Manager.Get_Application.Get_Session;\n end if;\n end Get_Session;\n\n Session : constant ADO.Sessions.Session := Get_Session;\n Query : ADO.Statements.Query_Statement := Session.Create_Statement (Handler.SQL);\n Result : Integer;\n begin\n -- Build the query\n Query.Bind_Param (Name => \"entity_id\", Value => Entity_Id);\n Query.Bind_Param (Name => \"user_id\", Value => User_Id);\n if Handler.Entities (2) /= ADO.NO_ENTITY_TYPE then\n for I in Handler.Entities'Range loop\n exit when Handler.Entities (I) = ADO.NO_ENTITY_TYPE;\n Query.Bind_Param (Name => \"entity_type_\" & Util.Strings.Image (I),\n Value => Handler.Entities (I));\n end loop;\n else\n Query.Bind_Param (Name => \"entity_type\", Value => Handler.Entities (1));\n end if;\n\n -- Run the query. We must get a single row result and the value must be > 0.\n Query.Execute;\n\n Result := Query.Get_Result_Integer;\n if Result >= 0 and Query.Has_Elements then\n Log.Info (\"Permission granted to {0} on entity {1}\",\n ADO.Identifier'Image (User_Id),\n ADO.Identifier'Image (Entity_Id));\n return True;\n else\n Log.Info (\"Permission denied to {0} on entity {1}\",\n ADO.Identifier'Image (User_Id),\n ADO.Identifier'Image (Entity_Id));\n return False;\n end if;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => AWA.Events.Module_Event'Class,\n Name => AWA.Events.Module_Event_Access);\n\n -- ------------------------------\n -- Get the queue name.\n -- ------------------------------\n overriding\n function Get_Name (From : in Fifo_Queue) return String is\n begin\n return From.Name;\n end Get_Name;\n\n -- ------------------------------\n -- Get the model queue reference object.\n -- Returns a null object if the queue is not persistent.\n -- ------------------------------\n overriding\n function Get_Queue (From : in Fifo_Queue) return AWA.Events.Models.Queue_Ref is\n pragma Unreferenced (From);\n begin\n return AWA.Events.Models.Null_Queue;\n end Get_Queue;\n\n -- ------------------------------\n -- Queue the event.\n -- ------------------------------\n procedure Enqueue (Into : in out Fifo_Queue;\n Event : in AWA.Events.Module_Event'Class) is\n E : constant Module_Event_Access := Copy (Event);\n begin\n Log.Debug (\"Enqueue event on queue {0}\", Into.Name);\n\n E.Set_Event_Kind (Event.Get_Event_Kind);\n Into.Fifo.Enqueue (E);\n end Enqueue;\n\n -- ------------------------------\n -- Dequeue an event and process it with the Process procedure.\n -- ------------------------------\n procedure Dequeue (From : in out Fifo_Queue;\n Process : access procedure (Event : in Module_Event'Class)) is\n E : Module_Event_Access;\n begin\n Log.Debug (\"Dequeue event queue {0}\", From.Name);\n\n From.Fifo.Dequeue (E, 0.0);\n begin\n Process (E.all);\n\n exception\n when E : others =>\n Log.Error (\"Exception when processing event\", E);" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => Name_Pair_Array,\n Name => Name_Pair_Array_Access);\n procedure Free is\n new Ada.Unchecked_Deallocation (Object => Name_Array,\n Name => Name_Array_Access);\n\n Left : Index_Type := Index_Type'First + 1;\n Right : Index_Type := Last_Index;\n begin\n -- Check the storage and allocate it if necessary.\n if Indexes = null then\n Indexes := new Name_Pair_Array (Index_Type'First + 1 .. Index_Type'First + 10);\n Names := new Name_Array (Index_Type'First + 1 .. Index_Type'First + 10);\n elsif Indexes'Last = Last_Index then\n declare\n E : constant Name_Pair_Array_Access\n := new Name_Pair_Array (1 .. Last_Index + 10);\n N : constant Name_Array_Access := new Name_Array (1 .. Last_Index + 10);\n begin\n E (Indexes'Range) := Indexes.all;\n N (Names'Range) := Names.all;\n Free (Indexes);\n Free (Names);\n Names := N;\n Indexes := E;" + }, + { + "function_def": "procedure Update_User;", + "function_body": "OpenId : constant String := Security.Auth.Get_Claimed_Id (Auth);\n Email : constant String := Security.Auth.Get_Email (Auth);\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Query : ADO.SQL.Query;\n Found : Boolean;\n User : User_Ref;\n Session : Session_Ref;\n\n -- ------------------------------\n -- Update the user first name/last name\n -- ------------------------------\n procedure Update_User is\n Name : constant String := Security.Auth.Get_Full_Name (Auth);\n First_Name : constant String := Security.Auth.Get_First_Name (Auth);\n Last_Name : constant String := Security.Auth.Get_Last_Name (Auth);\n Sep : constant Natural := Util.Strings.Index (Name, ' ');\n begin\n if Name'Length > 0 and Name /= String '(User.Get_Name) then\n User.Set_Name (Name);\n end if;\n if First_Name'Length > 0 and First_Name /= String '(User.Get_First_Name) then\n User.Set_First_Name (First_Name);\n end if;\n if Last_Name'Length > 0 and Last_Name /= String '(User.Get_Last_Name) then\n User.Set_Last_Name (Last_Name);\n end if;\n if Sep > 0 and String '(User.Get_First_Name) = \"\" then\n User.Set_First_Name (Name (Name'First .. Sep - 1));\n end if;\n if Sep > 0 and String '(User.Get_Last_Name) = \"\" then\n User.Set_Last_Name (Name (Sep + 1 .. Name'Last));\n end if;\n if Name'Length > 0 and String '(User.Get_First_Name) = \"\" then\n User.Set_First_Name (Name);\n end if;\n if Name'Length = 0 then\n User.Set_Name (Get_Name_From_Email (Email => Email));\n end if;\n User.Save (DB);\n end Update_User;\n\n begin\n Log.Info (\"Authenticated user {0}\", Email);\n\n Ctx.Start;\n\n -- Find the user registered under the given OpenID identifier.\n Query.Bind_Param (1, OpenId);\n Query.Set_Filter (\"o.open_id = ?\");\n User.Find (DB, Query, Found);\n if not Found then\n Log.Info (\"User {0} is not known\", Email);\n declare\n E : Email_Ref;\n begin\n E.Set_Email (Email);\n E.Set_User_Id (0);\n E.Save (DB);\n\n User.Set_Email (E);\n User.Set_Open_Id (OpenId);\n Update_User;\n E.Set_User_Id (User.Get_Id);\n E.Save (DB);" + }, + { + "function_def": "procedure Register (Plugin : in out Module;", + "function_body": "Name : in String;\n Bind : in ASF.Beans.Class_Binding_Access) is\n begin\n Plugin.App.Register_Class (Name, Bind);\n end Register;\n\n -- ------------------------------\n -- Finalize the module.\n -- ------------------------------\n overriding\n procedure Finalize (Plugin : in out Module) is\n begin\n null;\n end Finalize;\n\n procedure Initialize (Manager : in out Module_Manager;\n Module : in AWA.Modules.Module'Class) is\n begin\n Manager.Module := Module.Self;\n end Initialize;\n\n function Get_Value (Manager : in Module_Manager;\n Name : in String) return Util.Beans.Objects.Object is\n pragma Unreferenced (Manager, Name);\n begin\n return Util.Beans.Objects.Null_Object;\n end Get_Value;\n\n -- Module manager\n --\n -- ------------------------------\n -- Get the database connection for reading\n -- ------------------------------\n function Get_Session (Manager : Module_Manager)\n return ADO.Sessions.Session is\n begin\n return Manager.Module.Get_Session;\n end Get_Session;\n\n -- ------------------------------\n -- Get the database connection for writing\n -- ------------------------------\n function Get_Master_Session (Manager : Module_Manager)\n return ADO.Sessions.Master_Session is\n begin\n return Manager.Module.Get_Master_Session;\n end Get_Master_Session;\n\n -- ------------------------------\n -- Send the event to the module. The module identified by To is\n -- found and the event is posted on its event channel.\n -- ------------------------------\n procedure Send_Event (Manager : in Module_Manager;\n Content : in AWA.Events.Module_Event'Class) is\n begin\n Manager.Module.Send_Event (Content);\n end Send_Event;\n\n procedure Initialize (Plugin : in out Module;\n App : in Application_Access;\n Props : in ASF.Applications.Config) is\n pragma Unreferenced (Props);\n begin\n Plugin.Self := Plugin'Unchecked_Access;\n Plugin.App := App;\n end Initialize;\n\n -- ------------------------------\n -- Initialize the registry\n -- ------------------------------\n procedure Initialize (Registry : in out Module_Registry;\n Config : in ASF.Applications.Config) is\n begin\n Registry.Config := Config;\n end Initialize;\n\n -- ------------------------------\n -- Register the module in the registry.\n -- ------------------------------\n procedure Register (Registry : in Module_Registry_Access;\n App : in Application_Access;\n Plugin : in Module_Access;\n Name : in String;\n URI : in String) is\n procedure Copy (Params : in Util.Properties.Manager'Class);\n\n procedure Copy (Params : in Util.Properties.Manager'Class) is\n begin\n Plugin.Config.Copy (From => Params, Prefix => Name & \".\", Strip => True);\n end Copy;\n\n Paths : constant String := Registry.Config.Get (Applications.P_Module_Dir.P);\n begin\n Log.Info (\"Register module '{0}' under URI '{1}'\", Name, URI);\n\n if Plugin.Registry /= null then\n Log.Error (\"Module '{0}' is already attached to a registry\", Name);\n\n raise Program_Error with \"Module '\" & Name & \"' already registered\";\n end if;\n Plugin.App := App;\n Plugin.Registry := Registry;\n Plugin.Name := To_Unbounded_String (Name);\n Plugin.URI := To_Unbounded_String (URI);\n Plugin.Registry.Name_Map.Insert (Name, Plugin);\n if URI /= \"\" then\n Plugin.Registry.URI_Map.Insert (URI, Plugin);\n end if;\n\n -- Load the module configuration file\n Log.Debug (\"Module search path: {0}\", Paths);\n declare\n Base : constant String := Name & \".properties\";\n Path : constant String := Util.Files.Find_File_Path (Base, Paths);\n begin\n Plugin.Config.Load_Properties (Path => Path, Prefix => Name & \".\", Strip => True);\n\n exception\n when Ada.IO_Exceptions.Name_Error =>\n Log.Info (\"Module configuration file '{0}' does not exist\", Path);" + }, + { + "function_def": "procedure Add_Listener (Into : in out Module;", + "function_body": "Item : in Util.Listeners.Listener_Access) is\n begin\n Util.Listeners.Add_Listener (Into.Listeners, Item);\n end Add_Listener;\n\n -- ------------------------------\n -- Find the module with the given name in the application and add the listener to the\n -- module listener list.\n -- ------------------------------\n procedure Add_Listener (Plugin : in Module;\n Name : in String;\n Item : in Util.Listeners.Listener_Access) is\n M : constant Module_Access := Plugin.App.Find_Module (Name);\n begin\n if M = null then\n Log.Error (\"Cannot find module {0} to add a lifecycle listener\", Name);\n else\n M.Add_Listener (Item);\n end if;\n end Add_Listener;\n\n -- ------------------------------\n -- Remove a listener from the module listener list.\n -- ------------------------------\n procedure Remove_Listener (Into : in out Module;\n Item : in Util.Listeners.Listener_Access) is\n begin\n Util.Listeners.Remove_Listener (Into.Listeners, Item);\n end Remove_Listener;\n\n -- Get per request manager => look in Request\n -- Get per session manager => look in Request.Get_Session\n -- Get per application manager => look in Application\n -- Get per pool manager => look in pool attached to Application\n function Get_Manager return Manager_Type_Access is\n\n procedure Process (Request : in out ASF.Requests.Request'Class;\n Response : in out ASF.Responses.Response'Class);\n\n Value : Util.Beans.Objects.Object;\n\n procedure Process (Request : in out ASF.Requests.Request'Class;\n Response : in out ASF.Responses.Response'Class) is\n pragma Unreferenced (Response);\n begin\n Value := Request.Get_Attribute (Name);\n if Util.Beans.Objects.Is_Null (Value) then\n declare\n M : constant Manager_Type_Access := new Manager_Type;\n begin\n Value := Util.Beans.Objects.To_Object (M.all'Unchecked_Access);\n Request.Set_Attribute (Name, Value);" + }, + { + "function_def": "function Has_Permission (Name : in Util.Beans.Objects.Object;", + "function_body": "Entity : in Util.Beans.Objects.Object)\n return Util.Beans.Objects.Object is\n use type Security.Contexts.Security_Context_Access;\n\n Context : constant Security.Contexts.Security_Context_Access := Security.Contexts.Current;\n Perm : constant String := Util.Beans.Objects.To_String (Name);\n Result : Boolean;\n begin\n if Util.Beans.Objects.Is_Empty (Name) or Context = null then\n Result := False;\n\n elsif Util.Beans.Objects.Is_Empty (Entity) then\n Result := Context.Has_Permission (Perm);\n\n else\n declare\n P : Entity_Permission (Security.Permissions.Get_Permission_Index (Perm));\n begin\n P.Entity := ADO.Identifier (Util.Beans.Objects.To_Long_Long_Integer (Entity));\n Result := Context.Has_Permission (P);" + }, + { + "function_def": "function Get_Permission_Manager (Context : in Security.Contexts.Security_Context'Class)", + "function_body": "return Permission_Manager_Access is\n use type Security.Policies.Policy_Manager_Access;\n\n M : constant Security.Policies.Policy_Manager_Access\n := Context.Get_Permission_Manager;\n begin\n if M = null then\n Log.Info (\"There is no permission manager\");\n return null;\n\n elsif not (M.all in Permission_Manager'Class) then\n Log.Info (\"Permission manager is not a AWA permission manager\");\n return null;\n\n else\n return Permission_Manager'Class (M.all)'Access;\n end if;\n end Get_Permission_Manager;\n\n -- ------------------------------\n -- Get the permission manager associated with the security context.\n -- Returns null if there is none.\n -- ------------------------------\n function Get_Permission_Manager (Context : in ASC.Service_Context_Access)\n return Permission_Manager_Access is\n Manager : constant Security.Policies.Policy_Manager_Access\n := Context.Get_Application.Get_Security_Manager;\n begin\n return Permission_Manager'Class (Manager.all)'Access;\n end Get_Permission_Manager;\n\n -- ------------------------------\n -- Get the application instance.\n -- ------------------------------\n function Get_Application (Manager : in Permission_Manager)\n return AWA.Applications.Application_Access is\n begin\n return Manager.App;\n end Get_Application;\n\n -- ------------------------------\n -- Set the application instance.\n -- ------------------------------\n procedure Set_Application (Manager : in out Permission_Manager;\n App : in AWA.Applications.Application_Access) is\n begin\n Manager.App := App;\n end Set_Application;\n\n -- ------------------------------\n -- Initialize the permissions.\n -- ------------------------------\n procedure Start (Manager : in out Permission_Manager) is\n package Perm renames Security.Permissions;\n\n DB : ADO.Sessions.Master_Session := Manager.App.Get_Master_Session;\n Cache : constant Permission_Cache.Cache_Type_Access := new Permission_Cache.Cache_Type;\n Count : constant Perm.Permission_Index := Perm.Get_Last_Permission_Index;\n Last : ADO.Identifier := 0;\n Insert : ADO.Statements.Insert_Statement;\n Stmt : ADO.Statements.Query_Statement;\n Load_Count : Natural := 0;\n Add_Count : Natural := 0;\n begin\n Log.Info (\"Initializing {0} permissions\", Perm.Permission_Index'Image (Count));\n\n DB.Begin_Transaction;\n\n -- Step 1: load the permissions from the database.\n Stmt := DB.Create_Statement (\"SELECT id, name FROM awa_permission\");\n Stmt.Execute;\n while Stmt.Has_Elements loop\n declare\n Id : constant Integer := Stmt.Get_Integer (0);\n Name : constant String := Stmt.Get_String (1);\n begin\n Log.Debug (\"Loaded permission {0} as {1}\", Name, Util.Strings.Image (Id));\n Permission_Cache.Insert (Cache.all, Name, Id);\n Load_Count := Load_Count + 1;\n if ADO.Identifier (Id) > Last then\n Last := ADO.Identifier (Id);\n end if;" + }, + { + "function_def": "procedure Add_Permission (Manager : in Permission_Manager;", + "function_body": "Entity : in ADO.Identifier;\n Kind : in ADO.Entity_Type;\n Workspace : in ADO.Identifier;\n Permission : in Security.Permissions.Permission_Index) is\n Ctx : constant AWA.Services.Contexts.Service_Context_Access\n := AWA.Services.Contexts.Current;\n DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);\n Perm : AWA.Permissions.Models.ACL_Ref;\n begin\n Log.Info (\"Adding permission\");\n\n Ctx.Start;\n Perm.Set_Entity_Type (Kind);\n Perm.Set_User_Id (Ctx.Get_User_Identifier);\n Perm.Set_Entity_Id (Entity);\n Perm.Set_Writeable (False);\n Perm.Set_Workspace_Id (Workspace);\n Perm.Set_Permission (Manager.Map (Permission));\n Perm.Save (DB);\n Ctx.Commit;\n end Add_Permission;\n\n -- ------------------------------\n -- Check that the current user has the specified permission.\n -- Raise NO_PERMISSION exception if the user does not have the permission.\n -- ------------------------------\n procedure Check_Permission (Manager : in Permission_Manager;\n Entity : in ADO.Identifier;\n Kind : in ADO.Entity_Type;\n Permission : in Permission_Type) is\n pragma Unreferenced (Manager, Permission);\n use AWA.Services;\n\n Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;\n User : constant ADO.Identifier := Ctx.Get_User_Identifier;\n DB : constant Session := AWA.Services.Contexts.Get_Session (Ctx);\n Query : ADO.Queries.Context;\n begin\n Query.Set_Query (AWA.Permissions.Models.Query_Check_Entity_Permission);\n Query.Bind_Param (\"user_id\", User);\n Query.Bind_Param (\"entity_id\", Entity);\n Query.Bind_Param (\"entity_type\", Integer (Kind));\n declare\n Stmt : ADO.Statements.Query_Statement := DB.Create_Statement (Query);\n begin\n Stmt.Execute;\n if not Stmt.Has_Elements then\n Log.Info (\"User {0} does not have permission to access entity {1}/{2}\",\n ADO.Identifier'Image (User), ADO.Identifier'Image (Entity),\n ADO.Entity_Type'Image (Kind));\n raise NO_PERMISSION;\n end if;" + }, + { + "function_def": "procedure Dispatch (Manager : in Action_Dispatcher;", + "function_body": "Event : in Module_Event'Class) is\n\n use Util.Beans.Objects;\n\n -- Dispatch the event to the event action identified by Action.\n procedure Dispatch_One (Action : in Event_Action);\n\n type Event_Bean is new Util.Beans.Basic.Readonly_Bean with null record;\n\n overriding\n function Get_Value (From : in Event_Bean;\n Name : in String) return Util.Beans.Objects.Object;\n\n -- ------------------------------\n -- Get the value identified by the name.\n -- If the name cannot be found, the method should return the Null object.\n -- ------------------------------\n overriding\n function Get_Value (From : in Event_Bean;\n Name : in String) return Util.Beans.Objects.Object is\n pragma Unreferenced (From);\n begin\n return Event.Get_Value (Name);\n end Get_Value;\n\n Variables : aliased EL.Variables.Default.Default_Variable_Mapper;\n\n -- ------------------------------\n -- Default Resolver\n -- ------------------------------\n type Event_ELResolver is limited new EL.Contexts.ELResolver with record\n Request : ASF.Requests.Request_Access;\n Application : AWA.Applications.Application_Access;\n end record;\n\n overriding\n function Get_Value (Resolver : Event_ELResolver;\n Context : EL.Contexts.ELContext'Class;\n Base : access Util.Beans.Basic.Readonly_Bean'Class;\n Name : Unbounded_String) return Util.Beans.Objects.Object;\n overriding\n procedure Set_Value (Resolver : in out Event_ELResolver;\n Context : in EL.Contexts.ELContext'Class;\n Base : access Util.Beans.Basic.Bean'Class;\n Name : in Unbounded_String;\n Value : in Util.Beans.Objects.Object);\n\n -- ------------------------------\n -- Get the value associated with a base object and a given property.\n -- ------------------------------\n overriding\n function Get_Value (Resolver : Event_ELResolver;\n Context : EL.Contexts.ELContext'Class;\n Base : access Util.Beans.Basic.Readonly_Bean'Class;\n Name : Unbounded_String) return Util.Beans.Objects.Object is\n use Util.Beans.Basic;\n use EL.Variables;\n use type ASF.Requests.Request_Access;\n\n Result : Object;\n Bean : Util.Beans.Basic.Readonly_Bean_Access;\n Scope : ASF.Beans.Scope_Type;\n Key : constant String := To_String (Name);\n begin\n if Base /= null then\n return Base.Get_Value (Key);\n end if;\n\n if Resolver.Request /= null then\n Result := Resolver.Request.Get_Attribute (Key);\n if not Util.Beans.Objects.Is_Null (Result) then\n return Result;\n end if;\n\n -- If there is a session, look if the attribute is defined there.\n declare\n Session : constant ASF.Sessions.Session := Resolver.Request.Get_Session;\n begin\n if Session.Is_Valid then\n Result := Session.Get_Attribute (Key);\n if not Util.Beans.Objects.Is_Null (Result) then\n return Result;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (MailDeliveryStatus);\n Impl : Email_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 2, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Email_Ref)\n return AWA.Users.Models.MailDeliveryStatus is\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Last_Error_Date (Object : in out Email_Ref;\n Value : in Ada.Calendar.Time) is\n Impl : Email_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 3, Impl.Last_Error_Date, Value);\n end Set_Last_Error_Date;\n\n function Get_Last_Error_Date (Object : in Email_Ref)\n return Ada.Calendar.Time is\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Last_Error_Date;\n end Get_Last_Error_Date;\n\n\n function Get_Version (Object : in Email_Ref)\n return Integer is\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Id (Object : in out Email_Ref;\n Value : in ADO.Identifier) is\n Impl : Email_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Key_Value (Impl.all, 5, Value);\n end Set_Id;\n\n function Get_Id (Object : in Email_Ref)\n return ADO.Identifier is\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Object.all)'Access;\n begin\n return Impl.Get_Key_Value;\n end Get_Id;\n\n\n procedure Set_User_Id (Object : in out Email_Ref;\n Value : in ADO.Identifier) is\n Impl : Email_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Identifier (Impl.all, 6, Impl.User_Id, Value);\n end Set_User_Id;\n\n function Get_User_Id (Object : in Email_Ref)\n return ADO.Identifier is\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User_Id;\n end Get_User_Id;\n\n -- Copy of the object.\n procedure Copy (Object : in Email_Ref;\n Into : in out Email_Ref) is\n Result : Email_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Email_Access\n := Email_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Email_Access\n := new Email_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Email := Impl.Email;\n Copy.Status := Impl.Status;\n Copy.Last_Error_Date := Impl.Last_Error_Date;\n Copy.Version := Impl.Version;\n Copy.User_Id := Impl.User_Id;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Email_Impl, Email_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Email_Impl_Ptr := Email_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Email_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, EMAIL_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Email_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Email_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (EMAIL_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- email\n Value => Object.Email);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- status\n Value => Integer (MailDeliveryStatus'Pos (Object.Status)));\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- last_error_date\n Value => Object.Last_Error_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- user_id\n Value => Object.User_Id);\n Object.Clear_Modified (6);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(User_Impl, User_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : User_Impl_Ptr := User_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out User_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, USER_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out User_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out User_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (USER_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- first_name\n Value => Object.First_Name);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- last_name\n Value => Object.Last_Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- password\n Value => Object.Password);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- open_id\n Value => Object.Open_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- country\n Value => Object.Country);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_2_NAME, -- salt\n Value => Object.Salt);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_2_NAME, -- email_id\n Value => Object.Email);\n Object.Clear_Modified (10);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Key_Type);\n Impl : Access_Key_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 5, Impl.Kind, Value);\n end Set_Kind;\n\n function Get_Kind (Object : in Access_Key_Ref)\n return AWA.Users.Models.Key_Type is\n Impl : constant Access_Key_Access\n := Access_Key_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Kind;\n end Get_Kind;\n\n\n procedure Set_User (Object : in out Access_Key_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Access_Key_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 6, Impl.User, Value);\n end Set_User;\n\n function Get_User (Object : in Access_Key_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Access_Key_Access\n := Access_Key_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User;\n end Get_User;\n\n -- Copy of the object.\n procedure Copy (Object : in Access_Key_Ref;\n Into : in out Access_Key_Ref) is\n Result : Access_Key_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Access_Key_Access\n := Access_Key_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Access_Key_Access\n := new Access_Key_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Access_Key := Impl.Access_Key;\n Copy.Expire_Date := Impl.Expire_Date;\n Copy.Version := Impl.Version;\n Copy.Kind := Impl.Kind;\n Copy.User := Impl.User;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Access_Key_Impl, Access_Key_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Access_Key_Impl_Ptr := Access_Key_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Access_Key_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ACCESS_KEY_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Access_Key_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Access_Key_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (ACCESS_KEY_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- access_key\n Value => Object.Access_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- expire_date\n Value => Object.Expire_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- kind\n Value => Integer (Key_Type'Pos (Object.Kind)));\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (6);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Session_Type);\n Impl : Session_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 4, Impl.Stype, Value);\n end Set_Stype;\n\n function Get_Stype (Object : in Session_Ref)\n return AWA.Users.Models.Session_Type is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Stype;\n end Get_Stype;\n\n\n function Get_Version (Object : in Session_Ref)\n return Integer is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Server_Id (Object : in out Session_Ref;\n Value : in Integer) is\n Impl : Session_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Integer (Impl.all, 6, Impl.Server_Id, Value);\n end Set_Server_Id;\n\n function Get_Server_Id (Object : in Session_Ref)\n return Integer is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Server_Id;\n end Get_Server_Id;\n\n\n procedure Set_Id (Object : in out Session_Ref;\n Value : in ADO.Identifier) is\n Impl : Session_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Key_Value (Impl.all, 7, Value);\n end Set_Id;\n\n function Get_Id (Object : in Session_Ref)\n return ADO.Identifier is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Object.all)'Access;\n begin\n return Impl.Get_Key_Value;\n end Get_Id;\n\n\n procedure Set_Auth (Object : in out Session_Ref;\n Value : in AWA.Users.Models.Session_Ref'Class) is\n Impl : Session_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 8, Impl.Auth, Value);\n end Set_Auth;\n\n function Get_Auth (Object : in Session_Ref)\n return AWA.Users.Models.Session_Ref'Class is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Auth;\n end Get_Auth;\n\n\n procedure Set_User (Object : in out Session_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Session_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.User, Value);\n end Set_User;\n\n function Get_User (Object : in Session_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User;\n end Get_User;\n\n -- Copy of the object.\n procedure Copy (Object : in Session_Ref;\n Into : in out Session_Ref) is\n Result : Session_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Session_Access\n := Session_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Session_Access\n := new Session_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Start_Date := Impl.Start_Date;\n Copy.End_Date := Impl.End_Date;\n Copy.Ip_Address := Impl.Ip_Address;\n Copy.Stype := Impl.Stype;\n Copy.Version := Impl.Version;\n Copy.Server_Id := Impl.Server_Id;\n Copy.Auth := Impl.Auth;\n Copy.User := Impl.User;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Session_Impl, Session_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Session_Impl_Ptr := Session_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SESSION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SESSION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_4_NAME, -- start_date\n Value => Object.Start_Date);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_4_NAME, -- end_date\n Value => Object.End_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_4_NAME, -- ip_address\n Value => Object.Ip_Address);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_4_NAME, -- stype\n Value => Integer (Session_Type'Pos (Object.Stype)));\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_4_NAME, -- server_id\n Value => Object.Server_Id);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_4_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_4_NAME, -- auth_id\n Value => Object.Auth);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_4_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (9);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Permission (Object : in out Acl_Ref;", + "function_body": "Value : in ADO.Identifier) is\n Impl : Acl_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Identifier (Impl.all, 7, Impl.Permission, Value);\n end Set_Permission;\n\n function Get_Permission (Object : in Acl_Ref)\n return ADO.Identifier is\n Impl : constant Acl_Access\n := Acl_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Permission;\n end Get_Permission;\n\n -- Copy of the object.\n procedure Copy (Object : in Acl_Ref;\n Into : in out Acl_Ref) is\n Result : Acl_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Acl_Access\n := Acl_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Acl_Access\n := new Acl_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Entity_Id := Impl.Entity_Id;\n Copy.Writeable := Impl.Writeable;\n Copy.User_Id := Impl.User_Id;\n Copy.Workspace_Id := Impl.Workspace_Id;\n Copy.Entity_Type := Impl.Entity_Type;\n Copy.Permission := Impl.Permission;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Acl_Impl, Acl_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Acl_Impl_Ptr := Acl_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Acl_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, ACL_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Acl_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Acl_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (ACL_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- entity_id\n Value => Object.Entity_Id);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- writeable\n Value => Object.Writeable);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- user_id\n Value => Object.User_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- workspace_id\n Value => Object.Workspace_Id);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- permission\n Value => Object.Permission);\n Object.Clear_Modified (7);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "function Permission_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key is", + "function_body": "Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,\n Of_Class => PERMISSION_DEF'Access);\n begin\n ADO.Objects.Set_Value (Result, Id);\n return Result;\n end Permission_Key;\n\n function Permission_Key (Id : in String) return ADO.Objects.Object_Key is\n Result : ADO.Objects.Object_Key (Of_Type => ADO.Objects.KEY_INTEGER,\n Of_Class => PERMISSION_DEF'Access);\n begin\n ADO.Objects.Set_Value (Result, Id);\n return Result;\n end Permission_Key;\n\n function \"=\" (Left, Right : Permission_Ref'Class) return Boolean is\n begin\n return ADO.Objects.Object_Ref'Class (Left) = ADO.Objects.Object_Ref'Class (Right);\n end \"=\";\n\n procedure Set_Field (Object : in out Permission_Ref'Class;\n Impl : out Permission_Access) is\n Result : ADO.Objects.Object_Record_Access;\n begin\n Object.Prepare_Modify (Result);\n Impl := Permission_Impl (Result.all)'Access;\n end Set_Field;\n\n -- Internal method to allocate the Object_Record instance\n procedure Allocate (Object : in out Permission_Ref) is\n Impl : Permission_Access;\n begin\n Impl := new Permission_Impl;\n ADO.Objects.Set_Object (Object, Impl.all'Access);\n end Allocate;\n\n -- ----------------------------------------\n -- Data object: Permission\n -- ----------------------------------------\n\n procedure Set_Id (Object : in out Permission_Ref;\n Value : in ADO.Identifier) is\n Impl : Permission_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Key_Value (Impl.all, 1, Value);\n end Set_Id;\n\n function Get_Id (Object : in Permission_Ref)\n return ADO.Identifier is\n Impl : constant Permission_Access\n := Permission_Impl (Object.Get_Object.all)'Access;\n begin\n return Impl.Get_Key_Value;\n end Get_Id;\n\n\n procedure Set_Name (Object : in out Permission_Ref;\n Value : in String) is\n Impl : Permission_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_String (Impl.all, 2, Impl.Name, Value);\n end Set_Name;\n\n procedure Set_Name (Object : in out Permission_Ref;\n Value : in Ada.Strings.Unbounded.Unbounded_String) is\n Impl : Permission_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Unbounded_String (Impl.all, 2, Impl.Name, Value);\n end Set_Name;\n\n function Get_Name (Object : in Permission_Ref)\n return String is\n begin\n return Ada.Strings.Unbounded.To_String (Object.Get_Name);\n end Get_Name;\n function Get_Name (Object : in Permission_Ref)\n return Ada.Strings.Unbounded.Unbounded_String is\n Impl : constant Permission_Access\n := Permission_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Name;\n end Get_Name;\n\n -- Copy of the object.\n procedure Copy (Object : in Permission_Ref;\n Into : in out Permission_Ref) is\n Result : Permission_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Permission_Access\n := Permission_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Permission_Access\n := new Permission_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Name := Impl.Name;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Permission_Impl, Permission_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Permission_Impl_Ptr := Permission_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Permission_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, PERMISSION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Permission_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Permission_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (PERMISSION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Message_Type_Impl, Message_Type_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Message_Type_Impl_Ptr := Message_Type_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Message_Type_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, MESSAGE_TYPE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Message_Type_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Message_Type_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (MESSAGE_TYPE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Message_Type_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, MESSAGE_TYPE_DEF'Access);\n begin\n Stmt.Execute;\n Message_Type_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Message_Type_Ref;\n Impl : constant Message_Type_Access := new Message_Type_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Queue_Impl, Queue_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Queue_Impl_Ptr := Queue_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Queue_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, QUEUE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Queue_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Queue_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (QUEUE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- server_id\n Value => Object.Server_Id);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Message_Status_Type);\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 8, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Message_Ref)\n return AWA.Events.Models.Message_Status_Type is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Processing_Date (Object : in out Message_Ref;\n Value : in ADO.Nullable_Time) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 9, Impl.Processing_Date, Value);\n end Set_Processing_Date;\n\n function Get_Processing_Date (Object : in Message_Ref)\n return ADO.Nullable_Time is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Processing_Date;\n end Get_Processing_Date;\n\n\n function Get_Version (Object : in Message_Ref)\n return Integer is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Version;\n end Get_Version;\n\n\n procedure Set_Entity_Id (Object : in out Message_Ref;\n Value : in ADO.Identifier) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Identifier (Impl.all, 11, Impl.Entity_Id, Value);\n end Set_Entity_Id;\n\n function Get_Entity_Id (Object : in Message_Ref)\n return ADO.Identifier is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Entity_Id;\n end Get_Entity_Id;\n\n\n procedure Set_Entity_Type (Object : in out Message_Ref;\n Value : in ADO.Entity_Type) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Entity_Type (Impl.all, 12, Impl.Entity_Type, Value);\n end Set_Entity_Type;\n\n function Get_Entity_Type (Object : in Message_Ref)\n return ADO.Entity_Type is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Entity_Type;\n end Get_Entity_Type;\n\n\n procedure Set_Finish_Date (Object : in out Message_Ref;\n Value : in ADO.Nullable_Time) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Time (Impl.all, 13, Impl.Finish_Date, Value);\n end Set_Finish_Date;\n\n function Get_Finish_Date (Object : in Message_Ref)\n return ADO.Nullable_Time is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Finish_Date;\n end Get_Finish_Date;\n\n\n procedure Set_Queue (Object : in out Message_Ref;\n Value : in AWA.Events.Models.Queue_Ref'Class) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 14, Impl.Queue, Value);\n end Set_Queue;\n\n function Get_Queue (Object : in Message_Ref)\n return AWA.Events.Models.Queue_Ref'Class is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Queue;\n end Get_Queue;\n\n\n procedure Set_Message_Type (Object : in out Message_Ref;\n Value : in AWA.Events.Models.Message_Type_Ref'Class) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 15, Impl.Message_Type, Value);\n end Set_Message_Type;\n\n function Get_Message_Type (Object : in Message_Ref)\n return AWA.Events.Models.Message_Type_Ref'Class is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Message_Type;\n end Get_Message_Type;\n\n\n procedure Set_User (Object : in out Message_Ref;\n Value : in AWA.Users.Models.User_Ref'Class) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 16, Impl.User, Value);\n end Set_User;\n\n function Get_User (Object : in Message_Ref)\n return AWA.Users.Models.User_Ref'Class is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.User;\n end Get_User;\n\n\n procedure Set_Session (Object : in out Message_Ref;\n Value : in AWA.Users.Models.Session_Ref'Class) is\n Impl : Message_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 17, Impl.Session, Value);\n end Set_Session;\n\n function Get_Session (Object : in Message_Ref)\n return AWA.Users.Models.Session_Ref'Class is\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Session;\n end Get_Session;\n\n -- Copy of the object.\n procedure Copy (Object : in Message_Ref;\n Into : in out Message_Ref) is\n Result : Message_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Message_Access\n := Message_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Message_Access\n := new Message_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Create_Date := Impl.Create_Date;\n Copy.Priority := Impl.Priority;\n Copy.Count := Impl.Count;\n Copy.Parameters := Impl.Parameters;\n Copy.Server_Id := Impl.Server_Id;\n Copy.Task_Id := Impl.Task_Id;\n Copy.Status := Impl.Status;\n Copy.Processing_Date := Impl.Processing_Date;\n Copy.Version := Impl.Version;\n Copy.Entity_Id := Impl.Entity_Id;\n Copy.Entity_Type := Impl.Entity_Type;\n Copy.Finish_Date := Impl.Finish_Date;\n Copy.Queue := Impl.Queue;\n Copy.Message_Type := Impl.Message_Type;\n Copy.User := Impl.User;\n Copy.Session := Impl.Session;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Message_Impl, Message_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Message_Impl_Ptr := Message_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Message_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, MESSAGE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Message_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Message_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (MESSAGE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- priority\n Value => Object.Priority);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- count\n Value => Object.Count);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- parameters\n Value => Object.Parameters);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- server_id\n Value => Object.Server_Id);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_3_NAME, -- task_id\n Value => Object.Task_Id);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_3_NAME, -- status\n Value => Integer (Message_Status_Type'Pos (Object.Status)));\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_3_NAME, -- processing_date\n Value => Object.Processing_Date);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_3_NAME, -- entity_id\n Value => Object.Entity_Id);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_3_NAME, -- entity_type\n Value => Object.Entity_Type);\n Object.Clear_Modified (12);\n end if;\n if Object.Is_Modified (13) then\n Stmt.Save_Field (Name => COL_12_3_NAME, -- finish_date\n Value => Object.Finish_Date);\n Object.Clear_Modified (13);\n end if;\n if Object.Is_Modified (14) then\n Stmt.Save_Field (Name => COL_13_3_NAME, -- queue_id\n Value => Object.Queue);\n Object.Clear_Modified (14);\n end if;\n if Object.Is_Modified (15) then\n Stmt.Save_Field (Name => COL_14_3_NAME, -- message_type_id\n Value => Object.Message_Type);\n Object.Clear_Modified (15);\n end if;\n if Object.Is_Modified (16) then\n Stmt.Save_Field (Name => COL_15_3_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (16);\n end if;\n if Object.Is_Modified (17) then\n Stmt.Save_Field (Name => COL_16_3_NAME, -- session_id\n Value => Object.Session);\n Object.Clear_Modified (17);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Message_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, MESSAGE_DEF'Access);\n begin\n Stmt.Execute;\n Message_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Message_Ref;\n Impl : constant Message_Access := new Message_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Application_Impl, Application_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Application_Impl_Ptr := Application_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Application_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, APPLICATION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Application_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Application_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (APPLICATION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- secret_key\n Value => Object.Secret_Key);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- client_id\n Value => Object.Client_Id);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_1_NAME, -- update_date\n Value => Object.Update_Date);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_1_NAME, -- title\n Value => Object.Title);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_1_NAME, -- description\n Value => Object.Description);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_1_NAME, -- app_login_url\n Value => Object.App_Login_Url);\n Object.Clear_Modified (10);\n end if;\n if Object.Is_Modified (11) then\n Stmt.Save_Field (Name => COL_10_1_NAME, -- app_logo_url\n Value => Object.App_Logo_Url);\n Object.Clear_Modified (11);\n end if;\n if Object.Is_Modified (12) then\n Stmt.Save_Field (Name => COL_11_1_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (12);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Application_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, APPLICATION_DEF'Access);\n begin\n Stmt.Execute;\n Application_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Application_Ref;\n Impl : constant Application_Access := new Application_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Callback_Impl, Callback_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Callback_Impl_Ptr := Callback_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Callback_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, CALLBACK_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Callback_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Callback_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (CALLBACK_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- url\n Value => Object.Url);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- application_id\n Value => Object.Application);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Callback_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, CALLBACK_DEF'Access);\n begin\n Stmt.Execute;\n Callback_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Callback_Ref;\n Impl : constant Callback_Access := new Callback_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Session_Impl, Session_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Session_Impl_Ptr := Session_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SESSION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Session_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SESSION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_3_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- salt\n Value => Object.Salt);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- expire_date\n Value => Object.Expire_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- application_id\n Value => Object.Application);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- user_id\n Value => Object.User);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_3_NAME, -- session_id\n Value => Object.Session);\n Object.Clear_Modified (7);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Session_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SESSION_DEF'Access);\n begin\n Stmt.Execute;\n Session_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Session_Ref;\n Impl : constant Session_Access := new Session_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Dispatch_Event (T : in out Test;", + "function_body": "Kind : in Event_Index;\n Expect_Count : in Natural;\n Expect_Prio : in Natural) is\n\n Factory : AWA.Applications.Factory.Application_Factory;\n Conf : ASF.Applications.Config;\n Ctx : aliased EL.Contexts.Default.Default_Context;\n Path : constant String := Util.Tests.Get_Test_Path (\"regtests/config/event-test.xml\");\n Action : aliased Action_Bean;\n begin\n Conf.Set (\"database\", Util.Tests.Get_Parameter (\"database\"));\n\n declare\n App : aliased AWA.Tests.Test_Application;\n S : Util.Measures.Stamp;\n Faces : aliased ASF.Servlets.Faces.Faces_Servlet;\n SC : AWA.Services.Contexts.Service_Context;\n begin\n App.Initialize (Conf => Conf,\n Factory => Factory);\n App.Set_Global (\"event_test\",\n Util.Beans.Objects.To_Object (Action'Unchecked_Access,\n Util.Beans.Objects.STATIC));\n\n SC.Set_Context (App'Unchecked_Access, null);\n\n App.Add_Servlet (Name => \"faces\", Server => Faces'Unchecked_Access);\n App.Register_Class (\"AWA.Events.Tests.Event_Action\",\n Create_Action_Bean'Access);\n AWA.Applications.Configs.Read_Configuration (App => App,\n File => Path,\n Context => Ctx'Unchecked_Access,\n Override_Context => True);\n Util.Measures.Report (S, \"Initialize AWA application and read config\");\n App.Start;\n Util.Measures.Report (S, \"Start event tasks\");\n\n for I in 1 .. 100 loop\n declare\n Event : Module_Event;\n begin\n Event.Set_Event_Kind (Kind);\n Event.Set_Parameter (\"prio\", \"3\");\n Event.Set_Parameter (\"template\", \"def\");\n App.Send_Event (Event);" + }, + { + "function_def": "function Create_From_Color is new Create_From_Enum (Color, \"color_\");", + "function_body": "procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is\n begin\n Caller.Add_Test (Suite, \"Test AWA.Helpers.Selectors.Create_From_Query\",\n Test_Create_From_Query'Access);\n Caller.Add_Test (Suite, \"Test AWA.Helpers.Selectors.Create_From_Enum\",\n Test_Create_From_Enum'Access);\n end Add_Tests;\n\n -- ------------------------------\n -- Test creation of selector from an SQL query\n -- ------------------------------\n procedure Test_Create_From_Query (T : in out Test) is\n Session : constant ADO.Sessions.Session := AWA.Tests.Get_Application.Get_Session;\n Query : constant String := \"SELECT id, name from entity_type order by id\";\n Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);\n Result : ASF.Models.Selects.Select_Item_List;\n Found_User : Boolean := False;\n begin\n Append_From_Query (Result, Stmt);\n T.Assert (Result.Length > 0, \"The list should not be empty\");\n\n for I in 1 .. Result.Length loop\n declare\n Item : constant ASF.Models.Selects.Select_Item := Result.Get_Select_Item (I);\n begin\n -- The SQL query will return two different columns.\n -- Just check that label and values are different.\n T.Assert (Item.Get_Value /= Item.Get_Label, \"Item and label are equals\");\n\n -- To make this test simple, check only for one known entry in the list.\n if Item.Get_Label = \"awa_user\" then\n Found_User := True;\n end if;" + }, + { + "function_def": "procedure Day02 is", + "function_body": "package ASU renames Ada.Strings.Unbounded;\n -- for convenience purpose\n\n type US_Array is array(Positive range <>) of ASU.Unbounded_String;\n -- The IDs in the input data are all the same length, so we could use a\n -- fixed-length String array, but it would not be very generic, and it would\n -- not be suited for examples either.\n\n type Natural_Couple is array(1..2) of Natural;\n -- This data structure will be used to store two things:\n -- * IDs that have exactly 2 of any letter and exactly 3 of any letter;\n -- * the absolute count of IDs for the previous item.\n -- I could/should use a record for that, but meh, later maybe.\n\n type Character_Count is array(Character range 'a' .. 'z') of Natural;\n -- An array indexed on characters that will be used to count occurrences.\n -- This is not very generic (cough), but it will do for the input.\n\n -- Creates the \"String\" array from the file name\n function Read_Input(file_name : in String) return US_Array is\n -- Tail-call recursion to create the final array.\n function Read_Input_Rec(input : in Ada.Text_IO.File_Type; acc : in US_Array) return US_Array is\n begin\n if Ada.Text_IO.End_Of_File(input) then\n return acc;\n else\n return Read_Input_Rec\n (\n input,\n acc & (1 => ASU.To_Unbounded_String(Ada.Text_IO.Get_Line(input)))\n );\n end if;\n end Read_Input_Rec;\n\n F : Ada.Text_IO.File_Type;\n acc : US_Array(1 .. 0);\n begin\n Ada.Text_IO.Open\n (\n File => F,\n Mode => Ada.Text_IO.In_File,\n Name => file_name\n );\n declare\n result : US_Array := Read_Input_Rec(F, acc);\n begin\n Ada.Text_IO.Close(F);\n return result;" + }, + { + "function_def": "procedure Day01 is", + "function_body": "type Integer_Array is array(Positive range <>) of Integer;\n -- The data structure to store the input.\n\n function Hash is new Ada.Unchecked_Conversion\n (\n Source => Integer,\n Target => Ada.Containers.Hash_Type\n );\n -- Creates a hash value from integers.\n -- Supposes that integers and Hash_Type have the same size.\n\n package Integer_Sets is new Ada.Containers.Hashed_Sets\n (\n Element_Type => Integer,\n Hash => Hash,\n Equivalent_Elements => \"=\"\n );\n -- For part 2: using a set to store frequencies.\n\n -- Creates the integer array from the name of the input file.\n function Read_Input(file_name : in String) return Integer_Array is\n -- Tail-call recursion to create the array of Integers.\n -- Using an accumulator allows to generate arbitrary length arrays.\n function Read_Input_Rec(input : in Ada.Text_IO.File_Type; acc : in Integer_Array) return Integer_Array is\n begin\n -- The stop condition.\n -- Not using End_Of_File will make the compiler issue a warning, which\n -- can prevent you from running the code if -Werror flag is enabled.\n if Ada.Text_IO.End_Of_File(input) then\n return acc;\n else\n return Read_Input_Rec\n (\n input,\n acc & (1 => Integer'Value(Ada.Text_IO.Get_Line(input)))\n );\n end if;\n end Read_Input_Rec;\n\n F : Ada.Text_IO.File_Type;\n acc : Integer_Array(1 .. 0);\n begin\n Ada.Text_IO.Open\n (\n File => F,\n Mode => Ada.Text_IO.In_File,\n Name => file_name\n );\n declare\n result : Integer_Array := Read_Input_Rec(F, acc);\n begin\n Ada.Text_IO.Close(F);\n return result;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(Source => Key_Kind, Target => Key_Code);\n begin\n return Convert (Kind);\n end To_Code;\n\n function To_Key (Code : Key_Code) return Key_Kind is\n begin\n for Kind in Key_Kind'Range loop\n if Code = To_Code (Kind) then\n return Kind;\n end if;\n end loop;\n\n return Key_Unknown;\n end To_Key;\n\n function Hex_Image (Value : Unsigned_8) return String is\n Hex : constant array (Unsigned_8 range 0 .. 15) of Character := \"0123456789abcdef\";\n begin\n return Hex (Value / 16) & Hex (Value mod 16);\n end Hex_Image;\n\n function Hex_Image (Value : Unsigned_16; Bit_Order : System.Bit_Order) return String is\n Low : constant Unsigned_8 := Unsigned_8 (16#FF# and Value);\n High : constant Unsigned_8 := Unsigned_8 (16#FF# and (Value / 256));\n\n use type System.Bit_Order;\n begin\n if System.Default_Bit_Order = Bit_Order then\n return Hex_Image (Low) & Hex_Image (High);\n else\n return Hex_Image (High) & Hex_Image (Low);\n end if;\n end Hex_Image;\n\n function Hex_Image (Value : Unsigned_16) return String is\n (Hex_Image (Value, System.High_Order_First));\n\n function GUID (ID : Device_ID) return String is\n (Hex_Image (ID.Bus, System.Low_Order_First) & \"0000\" &\n Hex_Image (ID.Vendor, System.Low_Order_First) & \"0000\" &\n Hex_Image (ID.Product, System.Low_Order_First) & \"0000\" &\n Hex_Image (ID.Version, System.Low_Order_First) & \"0000\");\n\n ----------------------------------------------------------------------------\n\n use all type Event_Device.Input_Dev.Access_Mode;\n use type Event_Device.Input_Dev.Unsigned_14;\n\n function ID (Object : Input_Device) return Device_ID is\n Result : aliased Device_ID;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#02#, Result'Size / System.Storage_Unit), Result'Address);\n begin\n return (if Error_Code /= -1 then Result else (others => 0));\n end ID;\n\n function Location (Object : Input_Device) return String is\n Result : aliased String (1 .. 128) := (others => ' ');\n\n Length : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#07#, Result'Length), Result'Address);\n begin\n return (if Length > 0 then Result (1 .. Length - 1) else \"\");\n end Location;\n\n function Unique_ID (Object : Input_Device) return String is\n Result : aliased String (1 .. 128) := (others => ' ');\n\n Length : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#08#, Result'Length), Result'Address);\n begin\n return (if Length > 0 then Result (1 .. Length - 1) else \"\");\n end Unique_ID;\n\n ----------------------------------------------------------------------------\n\n function Properties (Object : Input_Device) return Device_Properties is\n Result : aliased Device_Properties;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#09#, Result'Size / System.Storage_Unit), Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Properties;\n\n function Events (Object : Input_Device) return Device_Events is\n Result : aliased Device_Events;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#20#, Result'Size / System.Storage_Unit), Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Events;\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Event_Kind, Target => Interfaces.C.unsigned_short);\n\n function Features (Object : Input_Device) return Synchronization_Features is\n Result : aliased Synchronization_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#20# + Unsigned_8 (Convert (Synchronization)),\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Key_Features is\n Result : aliased Key_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#20# + Unsigned_8 (Convert (Key)),\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Relative_Axis_Features is\n Result : aliased Internal_Relative_Axis_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Relative)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n\n return\n (X => Result.X,\n Y => Result.Y,\n Z => Result.Z,\n Rx => Result.Rx,\n Ry => Result.Ry,\n Rz => Result.Rz,\n Horizontal_Wheel => Result.Horizontal_Wheel,\n Diagonal => Result.Diagonal,\n Wheel => Result.Wheel,\n Misc => Result.Misc,\n Wheel_High_Res => Result.Wheel_High_Res,\n Horizontal_Wheel_High_Res => Result.Horizontal_Wheel_High_Res);\n end Features;\n\n function Features (Object : Input_Device) return Absolute_Axis_Features is\n Result : aliased Internal_Absolute_Axis_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Absolute)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n\n return\n (X => Result.X,\n Y => Result.Y,\n Z => Result.Z,\n Rx => Result.Rx,\n Ry => Result.Ry,\n Rz => Result.Rz,\n Throttle => Result.Throttle,\n Rudder => Result.Rudder,\n Wheel => Result.Wheel,\n Gas => Result.Gas,\n Brake => Result.Brake,\n Hat_0X => Result.Hat_0X,\n Hat_0Y => Result.Hat_0Y,\n Hat_1X => Result.Hat_1X,\n Hat_1Y => Result.Hat_1Y,\n Hat_2X => Result.Hat_2X,\n Hat_2Y => Result.Hat_2Y,\n Hat_3X => Result.Hat_3X,\n Hat_3Y => Result.Hat_3Y,\n Pressure => Result.Pressure,\n Distance => Result.Distance,\n Tilt_X => Result.Tilt_X,\n Tilt_Y => Result.Tilt_Y,\n Tool_Width => Result.Tool_Width,\n Volume => Result.Volume,\n Misc => Result.Misc,\n MT_Slot => Result.MT_Slot,\n MT_Touch_Major => Result.MT_Touch_Major,\n MT_Touch_Minor => Result.MT_Touch_Minor,\n MT_Width_Major => Result.MT_Width_Major,\n MT_Width_Minor => Result.MT_Width_Minor,\n MT_Orientation => Result.MT_Orientation,\n MT_Position_X => Result.MT_Position_X,\n MT_Position_Y => Result.MT_Position_Y,\n MT_Tool_Type => Result.MT_Tool_Type,\n MT_Blob_ID => Result.MT_Blob_ID,\n MT_Tracking_ID => Result.MT_Tracking_ID,\n MT_Pressure => Result.MT_Pressure,\n MT_Distance => Result.MT_Distance,\n MT_Tool_X => Result.MT_Tool_X,\n MT_Tool_Y => Result.MT_Tool_Y);\n end Features;\n\n function Features (Object : Input_Device) return Switch_Features is\n Result : aliased Switch_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Switch)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Miscellaneous_Features is\n Result : aliased Miscellaneous_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Miscellaneous)),\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return LED_Features is\n Result : aliased LED_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (LED)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Repeat_Features is\n Result : aliased Repeat_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Repeat)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Sound_Features is\n Result : aliased Sound_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Sound)), Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Features;\n\n function Features (Object : Input_Device) return Force_Feedback_Features is\n Result : aliased Internal_Force_Feedback_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#20# + Unsigned_8 (Convert (Force_Feedback)),\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n\n return\n (Rumble => Result.Rumble,\n Periodic => Result.Periodic,\n Constant_V => Result.Constant_V,\n Spring => Result.Spring,\n Friction => Result.Friction,\n Damper => Result.Damper,\n Inertia => Result.Inertia,\n Ramp => Result.Ramp,\n Square => Result.Square,\n Triangle => Result.Triangle,\n Sine => Result.Sine,\n Saw_Up => Result.Saw_Up,\n Saw_Down => Result.Saw_Down,\n Custom => Result.Custom,\n Gain => Result.Gain,\n Auto_Center => Result.Auto_Center);\n end Features;\n\n ----------------------------------------------------------------------------\n\n function Axis (Object : Input_Device; Axis : Absolute_Axis_Kind) return Axis_Info is\n Result : aliased Axis_Info;\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Absolute_Axis_Info_Kind, Target => Unsigned_64);\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#40# + Unsigned_8 (Convert (Absolute_Axis_Info_Kind (Axis))),\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Axis;\n\n function Key_Statuses (Object : Input_Device) return Key_Features is\n Result : aliased Key_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#18#,\n Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n\n return Result;\n end Key_Statuses;\n\n function LED_Statuses (Object : Input_Device) return LED_Features is\n Result : aliased LED_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#19#, Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end LED_Statuses;\n\n function Sound_Statuses (Object : Input_Device) return Sound_Features is\n Result : aliased Sound_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#1A#, Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Sound_Statuses;\n\n function Switch_Statuses (Object : Input_Device) return Switch_Features is\n Result : aliased Switch_Features;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD,\n (Read, 'E', 16#1B#, Result'Size / System.Storage_Unit),\n Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Switch_Statuses;\n\n function Force_Feedback_Effects (Object : Input_Device) return Natural is\n Result : aliased Integer;\n\n Error_Code : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#84#, Result'Size / System.Storage_Unit), Result'Address);\n begin\n pragma Assert (Error_Code /= -1);\n return Result;\n end Force_Feedback_Effects;\n\n procedure Set_Force_Feedback_Gain\n (Object : Input_Device;\n Value : Force_Feedback_Gain)\n is\n FF_Gain_Code : constant := 16#60#;\n\n Event : constant Input_Dev.Input_Event :=\n (Time => (0, 0),\n Event => Force_Feedback,\n Code => FF_Gain_Code,\n Value => Interfaces.C.int (16#FF_FF.00# * Value));\n\n Result_Unused : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);\n begin\n -- Ignore any possible errors. If the device has been disconnected\n -- then playing a force-feedback effect will fail, which can be\n -- detected by the boolean returned by Play_Force_Feedback_Effect.\n null;\n end Set_Force_Feedback_Gain;\n\n procedure Set_Force_Feedback_Auto_Center\n (Object : Input_Device;\n Value : Force_Feedback_Auto_Center)\n is\n FF_Auto_Center_Code : constant := 16#61#;\n\n Event : constant Input_Dev.Input_Event :=\n (Time => (0, 0),\n Event => Force_Feedback,\n Code => FF_Auto_Center_Code,\n Value => Interfaces.C.int (16#FF_FF.00# * Value));\n\n Result_Unused : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);\n begin\n -- Ignore any possible errors. If the device has been disconnected\n -- then playing a force-feedback effect will fail, which can be\n -- detected by the boolean returned by Play_Force_Feedback_Effect.\n null;\n end Set_Force_Feedback_Auto_Center;\n\n function Play_Force_Feedback_Effect\n (Object : Input_Device;\n Identifier : Uploaded_Force_Feedback_Effect_ID;\n Count : Natural := 1) return Boolean\n is\n Event : constant Input_Dev.Input_Event :=\n (Time => (0, 0),\n Event => Force_Feedback,\n Code => Interfaces.C.unsigned_short (Identifier),\n Value => Interfaces.C.int (Count));\n\n Result : constant Input_Dev.Result := Input_Dev.Write (Object.FD, Event);\n begin\n return Result.Is_Success;\n end Play_Force_Feedback_Effect;\n\n function Name (Object : Input_Device) return String is\n Result : aliased String (1 .. 128) := (others => ' ');\n\n Length : constant Integer := Event_Device.Input_Dev.IO_Control\n (Object.FD, (Read, 'E', 16#06#, Result'Length), Result'Address);\n begin\n return (if Length > 0 then Result (1 .. Length - 1) else \"\");\n end Name;\n\n function Is_Open (Object : Input_Device) return Boolean is\n (Object.Open);\n\n function Open\n (Object : in out Input_Device;\n File_Name : String;\n Blocking : Boolean := True) return Boolean\n is\n Result : constant Input_Dev.Result := Input_Dev.Open (File_Name, Blocking => Blocking);\n begin\n if Result.Is_Success then\n Object.FD := Result.FD;\n end if;\n Object.Open := Result.Is_Success;\n return Object.Open;\n end Open;\n\n procedure Close (Object : in out Input_Device) is\n Result : constant Input_Dev.Result := Input_Dev.Close (Object.FD);\n begin\n Object.FD := -1;\n Object.Open := not Result.Is_Success;\n end Close;\n\n overriding procedure Finalize (Object : in out Input_Device) is\n begin\n if Object.Is_Open then\n Object.Close;\n end if;\n end Finalize;\n\n function Read\n (Object : Input_Device;\n Value : out State) return Read_Result\n is\n use Event_Device.Input_Dev;\n use type Interfaces.C.unsigned_short;\n use type Interfaces.C.int;\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Interfaces.C.unsigned_short, Target => Synchronization_Kind);\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Interfaces.C.unsigned_short, Target => Unsigned_16);\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Interfaces.C.unsigned_short, Target => Relative_Axis_Info_Kind);\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Unsigned_64, Target => Absolute_Axis_Info_Kind);\n -- Convert to Absolute_Axis_Info_Kind first before converting to\n -- Absolute_Axis_Kind, because the former has a representation clause\n\n Event : Input_Event;\n Result : Input_Dev.Result;\n\n Has_Dropped : Boolean := False;\n begin\n loop\n Result := Input_Dev.Read (Object.FD, Event);\n\n if not Result.Is_Success then\n if Result.Error = Would_Block then\n return Would_Block;\n else\n Value := (others => <>);\n return Error;\n end if;\n end if;\n\n case Event.Event is\n when Key =>\n declare\n Code : constant Key_Code := Key_Code (Unsigned_16'(Convert (Event.Code)));\n begin\n Value.Keys (Key_Code_Index (Code)) :=\n (if Event.Value /= 0 then Pressed else Released);" + }, + { + "function_def": "procedure Info is", + "function_body": "package ACL renames Ada.Command_Line;\n\n EF : Event_Device.Input_Device;\n\n Do_Rumble : constant Boolean :=\n ACL.Argument_Count = 2 and then ACL.Argument (2) = \"--ff=rumble\";\n Do_Periodic : constant Boolean :=\n ACL.Argument_Count = 2 and then ACL.Argument (2) = \"--ff=periodic\";\n Do_Read : constant Boolean :=\n ACL.Argument_Count = 2 and then ACL.Argument (2) = \"--read\";\nbegin\n if ACL.Argument_Count /= 1 and not (Do_Rumble or Do_Periodic or Do_Read) then\n Ada.Text_IO.Put_Line (\"Usage: [--read|--ff=rumble|periodic]\");\n ACL.Set_Exit_Status (ACL.Failure);\n return;\n end if;\n\n if not EF.Open (ACL.Argument (1)) then\n Ada.Text_IO.Put_Line (\"Cannot open device \" & ACL.Argument (1));\n ACL.Set_Exit_Status (ACL.Failure);\n return;\n end if;\n\n Ada.Text_IO.Put_Line (\"Device name: '\" & EF.Name & \"'\");\n Ada.Text_IO.Put_Line (\"Location: '\" & EF.Location & \"'\");\n Ada.Text_IO.Put_Line (\"Uniq ID: '\" & EF.Unique_ID & \"'\");\n declare\n ID : constant Event_Device.Device_ID := EF.ID;\n Props : constant Event_Device.Device_Properties := EF.Properties;\n Events : constant Event_Device.Device_Events := EF.Events;\n\n ID_A : constant String := Event_Device.Hex_Image (ID.Bus);\n ID_B : constant String := Event_Device.Hex_Image (ID.Vendor);\n ID_C : constant String := Event_Device.Hex_Image (ID.Product);\n ID_D : constant String := Event_Device.Hex_Image (ID.Version);\n begin\n Ada.Text_IO.Put_Line (\"Bus ven pro ver: \" &\n ID_A & \" \" & ID_B & \" \" & ID_C & \" \" & ID_D);\n Ada.Text_IO.Put_Line (\"GUID: \" & Event_Device.GUID (ID));\n Ada.Text_IO.Put_Line (\"Properties:\");\n Ada.Text_IO.Put_Line (\" Pointer: \" & Props.Pointer'Image);\n Ada.Text_IO.Put_Line (\" Direct: \" & Props.Direct'Image);\n Ada.Text_IO.Put_Line (\" Button pad: \" & Props.Button_Pad'Image);\n Ada.Text_IO.Put_Line (\" Semi mt: \" & Props.Semi_Multi_Touch'Image);\n Ada.Text_IO.Put_Line (\" Top button pad: \" & Props.Top_Button_Pad'Image);\n Ada.Text_IO.Put_Line (\" Pointing stick: \" & Props.Pointing_Stick'Image);\n Ada.Text_IO.Put_Line (\" Accelerometer: \" & Props.Accelerometer'Image);\n\n Ada.Text_IO.Put_Line (\"Events:\");\n Ada.Text_IO.Put_Line (\" Synchronization: \" & Events.Synchronization'Image);\n if Events.Synchronization then\n declare\n Features : constant Event_Device.Synchronization_Features := EF.Features;\n begin\n for K in Event_Device.Synchronization_Kind'Range loop\n if Features (K) then\n Ada.Text_IO.Put_Line (\" \" & K'Image);\n end if;\n end loop;" + }, + { + "function_def": "procedure Register_Tests (T : in out TC) is", + "function_body": "use AUnit.Test_Cases.Registration;\n begin\n Register_Routine\n (T, Test_Get_String_Flag_OK_With_Default'Access, \"Test CLI get string with default values\");\n Register_Routine\n (T, Test_Get_String_Flag_Throws_No_Flag_Or_Short'Access, \"Test CLI get string throws when no flag and short\");\n Register_Routine\n (T, Test_Get_String_Flag_Throws_When_Required'Access, \"Test CLI get string when required argument not found\");\n end Register_Tests;\n\n function Name (T : TC) return Message_String is\n pragma Unreferenced (T);\n begin\n return AUnit.Format (\"CLI Get_String_Flag\");\n end Name;\n\n procedure Set_Up (T : in out TC) is\n begin\n null;\n end Set_Up;\n\n -- Test_Get_String_Flag_OK_With_Default\n -- ------------------------------------\n\n procedure Test_Get_String_Flag_OK_With_Default (T : in out Test_Cases.Test_Case'Class) is\n Required_Flag : constant String := \"--test-switch\";\n Default_Value : constant String := \"this is the default value\";\n begin\n declare\n Res : String := Cli.Get_String_Flag(Flag => Required_Flag, Required => false, DefaultValue => Default_Value);\n begin\n Assert(Res = Default_Value, \"Expected didn't match received: expected=\" & Default_Value & \", received=\" & Res);" + }, + { + "function_def": "procedure Main is", + "function_body": "begin\n begin\n declare\n GrossSalaryValue : Float := Get_Float_Flag(Flag => \"--gross\", Short => \"-g\", Required => true);\n GrossMode : String := Get_String_Flag(Flag => \"--mode\", Short => \"-m\", DefaultValue => \"annual\");\n begin\n Put_Line(\"Hello, World... gross=\" & Float'Image(GrossSalaryValue) & \", mode=\" & GrossMode);" + }, + { + "function_def": "procedure Represent is", + "function_body": "use Ada;\n \n type Byte is mod 2**8 with Size => 8;\n \n type T_Instruction is (Load, Store, Clear, Move)\n with Size => 2;\n \n for T_Instruction use (Load => 2#00#,\n\t\t\t Store => 2#01#,\n\t\t\t Clear => 2#10#,\n\t\t\t Move => 2#11#);\n \n type T_Register is mod 2**3 with Size => 3;\n \n type Command is record\n Instruction : T_Instruction;\n Source : T_Register;\n Dest : T_Register;\n end record \n with \n Size => 8,\n Bit_Order => System.Low_Order_First;\n \n for Command use record\n Instruction at 0 range 6 .. 7;\n Source at 0 range 3 .. 5;\n Dest at 0 range 0 .. 2;\n end record;\n \n function To_Byte is new Unchecked_Conversion\n (Source => Command,\n Target => Byte);\n \n procedure Put_Instruction\n (Instruction : T_Instruction;\n Src, Dest : T_Register) \n is\n Instr : Command := (Instruction, Src, Dest);\n begin\n Put_Line (Byte'Image (To_Byte (Instr)));" + }, + { + "function_def": "procedure Task_Queue is", + "function_body": "-- cf. Barnes, J., \"Programming in Ada 2012\" (Chapter 20)\n task Buffer is\n entry Put (X : in Integer);\n entry Get (X : out Integer);" + }, + { + "function_def": "procedure represent2 is", + "function_body": "type Action_Type is (Load, \n\t\t\tStore, \n\t\t\tCopy, \n\t\t\tAdd, \n\t\t\tClear,\n\t\t\tJump,\n\t\t\tRet)\n with Size => 4;\n \n for Action_Type use \n (Load => 2#1000#,\n Store => 2#1001#,\n Copy => 2#1010#,\n Add => 2#1011#,\n Clear => 2#1100#,\n Jump => 2#1101#,\n Ret => 2#1110#);\n \n type Register_Type is mod 2**4 with Size => 4;\n type Ref_Register_Type is mod 2**2\n with Size => 2;\n \n \n type Mode_Type is (Direct, Register, Indirect)\n with Size => 2;\n \n for Mode_Type use\n (Direct => 2#01#,\n Register => 2#10#,\n Indirect => 2#11#);\n \n \n type Mult_Factor_Type is mod 2**2 \n with Size => 2;\n \n type Long_Reg (Mode : Mode_Type := Direct) is record\n Action : Action_Type; -- 4\n case Mode is\n\t when Direct =>\n\t Bit_Fill : Mult_Factor_Type; -- 2\n\t Address : Unsigned_8; -- 8\n\t when Register =>\n\t Mult_Factor : Mult_Factor_Type; -- 2\n\t Reg1 : Register_Type; -- 4\n\t Reg2 : Register_Type; -- 4\n\t when Indirect =>\n\t Ref_Reg : Ref_Register_Type; -- 2\n\t Offset : Unsigned_8; -- 8\n end case;\n end record with\n Size => 16, -- Pack, \n Bit_Order => System.Low_Order_First;\n \n -- This works.\n for Long_Reg use record\n Action at 0 range 12 .. 15;\n Mode at 0 range 10 .. 11;\n \n Bit_Fill at 0 range 8 .. 9;\n Address at 0 range 0 .. 7;\n \n Mult_Factor at 0 range 8 .. 9;\n Reg1 at 0 range 4 .. 7;\n Reg2 at 0 range 0 .. 3;\n Ref_Reg at 0 range 8 .. 9;\n Offset at 0 range 0 .. 7;\n end record;\n \n type Word is new Interfaces.Unsigned_16;\n \n function To_Word is\n new Unchecked_Conversion (Long_Reg, Word);\n \n procedure Put_Word (S : Long_Reg) is\n begin\n Put_Line (Word'Image (To_Word (S)));" + }, + { + "function_def": "procedure Protect2 is", + "function_body": "procedure Put_Time_Diff (D : in Time) is\n T : Duration := Clock - D;\n begin\n Put (Duration'Image (T));\n end Put_Time_Diff;\n \n \n protected One_A_Time is\n function Read (Id : String) return Integer;\n procedure Write (X : Integer);\n private\n V : Integer := 2;\n T : Time := Clock;\n end One_A_Time;\n \n protected body One_A_Time is\n \n function Read (Id : String) return Integer is\n begin\n\t Put_Time_Diff (T); Put_Line (\" OAT reads for \" & Id);\n\t return V;\n end Read;\n \n procedure Write (X : Integer) is\n begin\n\t Put_Time_Diff (T); Put_Line (\" OAT starts writing...\");\t \n\t delay 5.0;\n\t V := X;\n\t Put_Time_Diff (T); Put_Line (\" OAT ended writing...\");\n end Write;\n \n end One_A_Time;\n \n task Reader1;\n task Reader2;\n \n task body Reader1 is\n I : Integer := One_A_Time.Read (\"R1\");\n begin\n loop\n\t exit when I = 0;\n\t I := One_A_Time.Read (\"R1\");\n\t delay 0.5;\n end loop;\n end Reader1;\n \n task body Reader2 is\n I : Integer := One_A_Time.Read (\"R2\");\n begin\n loop\n\t exit when I = 0;\n\t I := One_A_Time.Read (\"R2\");\n\t delay 0.5;\n end loop; \n end Reader2;\n \n T : Time := Clock;\nbegin\n -- The main writes\n Put_Time_Diff (T); Put_Line (\" ET writes 1...\");\n One_A_Time.Write (1);\n Put_Time_Diff (T); Put_Line (\" ET has written 1\");\n delay 5.0;\n Put_Time_Diff (T); Put_Line (\" ET writes 0...\");\n One_A_Time.Write (0);\n Put_Time_Diff (T); Put_Line (\" ET has written 0\");" + }, + { + "function_def": "procedure Protect is", + "function_body": "procedure Put_Time_Diff (D : in Time) is\n T : Duration := Clock - D;\n begin\n Put (Duration'Image (T));\n end Put_Time_Diff;\n \n \n protected One_A_Time is\n function Read return Integer;\n -- Reading takes 3s\n \n procedure Write (X : Integer);\n -- Writing takes 5s \n private\n V : Integer := 0;\n T : Time := Clock;\n end One_A_Time;\n \n \n \n protected body One_A_Time is\n \n function Read return Integer is\n begin\n\t Put_Time_Diff (T); Put_Line (\" OAT starts reading...\");\n\t delay 3.0;\n\t Put_Time_Diff (T); Put_Line (\" OAT ended read\");\n\t return V;\n end Read;\n \n procedure Write (X : Integer) is\n begin\n\t Put_Time_Diff (T); Put_Line (\" OAT starts writing...\");\t \n\t delay 5.0;\n\t V := X;\n\t Put_Time_Diff (T); Put_Line (\" OAT ended writing...\");\n end Write;\n \n end One_A_Time;\n \n task Reader1;\n task Reader2;\n \n task body Reader1 is\n I : Integer;\n T : Time := Clock;\n begin\n Put_Time_Diff (T);\n Put_Line (\" R1 reading...\");\n I := One_A_Time.Read;\n Put_Time_Diff (T);\n Put_Line (\" ...R1 read\" & Integer'Image (I));\n delay 5.0;\n -- try to read with R2\n I := One_A_Time.Read;\n Put_Time_Diff (T); Put_Line (\"*** R1 exit ***\");\n end Reader1;\n \n task body Reader2 is\n I : Integer;\n T : Time := Clock;\n begin\n Put_Time_Diff (T);\n Put_Line (\" R2 works for 2s\");\n delay 2.0;\n Put_Time_Diff (T);\n Put_Line (\" R2 reading...\");\n I := One_A_Time.Read;\n Put_Time_Diff (T);\n Put_Line (\" ...R2 read\" & Integer'Image (I));\n Put_Line (\"*** R2 exit ***\");\n end Reader2;\n \n T : Time := Clock;\nbegin\n -- The main writes\n Put_Time_Diff (T);\n Put_Line (\" ET writes 1...\");\n One_A_Time.Write (1);\n Put_Time_Diff (T);\n Put_Line (\" ET has written 1\");" + }, + { + "function_def": "procedure Mandel_UTF is", + "function_body": "package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Float);\n use Complex_Types;\n\n -- Configuration constants.\n Bitmap_Size : constant := 128; -- pixels\n Max_Iterations : constant := 32;\n Num_Of_Threads : constant := 4;\n \n ------------------------------------------------------\n -- This part replaces Given's glyphs table\n subtype Brush_Levels is Integer range 0 .. 255;\n type Brushes is array (Brush_Levels) of Wide_Character;\n \n function Generate_Glyphs return Brushes is\n First_Code_Point : constant := 10240;\n begin\n return E : Brushes do\n\t for I in Brush_Levels'Range loop\n\t E (I) := Wide_Character'Val (First_Code_Point + I);\n\t end loop;\n end return;\n end Generate_Glyphs;\n \n Glyphs : constant Brushes := Generate_Glyphs;\n ------------------------------------------------------\n \n -- Returns the intensity of a single point in the Mandelbrot set.\n function Render_Pixel (C : Complex) return Float is\n Z : Complex := Complex'(0.0, 0.0);\n begin\n for N in Integer range 0 .. Max_Iterations loop\n\t Z := Z*Z + C;\n\t if (abs Z > 2.0) then\n return Float (N) / Float (Max_Iterations);\n\t end if;\n end loop;\n return 0.0;" + }, + { + "function_def": "procedure Free_Bitmap is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Bitmap, Name => Bitmap_Ref);\n\n -- Encapsulates the multithreaded render: creates a bunch of workers\n -- and a scheduler, which hands out work units to the renderers.\n procedure Mandelbrot\n (Data : Bitmap_Ref;\n R1, I1, R2, I2 : Float) \n is\n Width : Integer := Data'Length (1);\n Height : Integer := Data'Length (2);\n Xdelta : Float := (R2-R1) / Float (Width);\n Ydelta : Float := (I2-I1) / Float (Height);\n\n task Scheduler is\n\t -- Each worker calls this to find out what it needs to do.\n\t entry Request_Work_Unit (Y : out Integer; I : out Float);" + }, + { + "function_def": "procedure MandelPNG is", + "function_body": "package C renames Interfaces.C;\n \n \n package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Float);\n use Complex_Types;\n \n -- Configuration constants.\n Width : constant := 800;\n Height : constant := 600; \n \n Max_Iterations : constant := 32;\n \n -- Returns the intensity of a single point in the Mandelbrot set.\n function Render_Pixel (C : Complex) return Float is\n Z : Complex := Complex'(0.0, 0.0);\n begin\n for N in Integer range 0 .. Max_Iterations loop\n Z := Z*Z + C;\n if (abs Z > 2.0) then\n return Float (N) / Float (Max_Iterations);\n end if;\n end loop;\n return 0.0;" + }, + { + "function_def": "procedure Free_Bitmap is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Bitmap, Name => Bitmap_Ref);\n \n \n procedure Mandelbrot\n (Data : Bitmap_Ref;\n R1, I1, R2, I2 : Float) \n is\n Width : Integer := Data'Length (1);\n Height : Integer := Data'Length (2);\n Xdelta : Float := (R2-R1) / Float (Width);\n Ydelta : Float := (I2-I1) / Float (Height);\n\n I : Float;\n C : Complex;\n begin\n Put_Line (\"Width: \" & Integer'Image (Width));\n Put_Line (\"Height: \" & Integer'Image (Height));\n Put_Line (\"Xdelta: \" & Float'Image (Xdelta));\n Put_Line (\"Ydelta: \" & Float'Image (Ydelta));\n \n for Y in Data'Range (2) loop\n I := I1 + Float (Y) * Ydelta;\n for X in Data'Range (1) loop\n C := Complex'(R1 + Float (X) * Xdelta, I);\n Data (X, Y) := Render_Pixel (C);\n end loop;\n end loop;" + }, + { + "function_def": "procedure Main_Lab1 is", + "function_body": "n: Integer := 5 ;\n package data1 is new data (n);\n use data1;\n\n CPU0: CPU_Range :=0;\n CPU1: CPU_Range :=1;\n CPU2: CPU_Range :=2;\n f1, f2, f3:Integer;\n\n procedure tasks is\n task T1 is\n pragma Priority(1);\n pragma CPU(CPU0);" + }, + { + "function_def": "procedure Ada_Lexer_Test is", + "function_body": "type File_Source is new Incr.Lexers.Batch_Lexers.Abstract_Source with record\n Text : League.Strings.Universal_String;\n Index : Positive := 1;\n end record;\n\n overriding function Get_Next (Self : not null access File_Source)\n return Wide_Wide_Character;\n\n function Debug_Image\n (Value : Incr.Ada_Lexers.Token) return Wide_Wide_String;\n\n function Debug_Image\n (Value : Incr.Ada_Lexers.Token) return Wide_Wide_String\n is\n use Incr.Ada_Lexers;\n begin\n case Value is\n when Arrow_Token => return \"Arrow_Token\";\n when Double_Dot_Token => return \"Double_Dot_Token\";\n when Double_Star_Token => return \"Double_Star_Token\";\n when Assignment_Token => return \"Assignment_Token\";\n when Inequality_Token => return \"Inequality_Token\";\n when Greater_Or_Equal_Token => return \"Greater_Or_Equal_Token\";\n when Less_Or_Equal_Token => return \"Less_Or_Equal_Token\";\n when Left_Label_Token => return \"Left_Label_Token\";\n when Right_Label_Token => return \"Right_Label_Token\";\n when Box_Token => return \"Box_Token\";\n when Ampersand_Token => return \"Ampersand_Token\";\n when Apostrophe_Token => return \"Apostrophe_Token\";\n when Left_Parenthesis_Token => return \"Left_Parenthesis_Token\";\n when Right_Parenthesis_Token => return \"Right_Parenthesis_Token\";\n when Star_Token => return \"Star_Token\";\n when Plus_Token => return \"Plus_Token\";\n when Comma_Token => return \"Comma_Token\";\n when Hyphen_Token => return \"Hyphen_Token\";\n when Dot_Token => return \"Dot_Token\";\n when Slash_Token => return \"Slash_Token\";\n when Colon_Token => return \"Colon_Token\";\n when Semicolon_Token => return \"Semicolon_Token\";\n when Less_Token => return \"Less_Token\";\n when Equal_Token => return \"Equal_Token\";\n when Greater_Token => return \"Greater_Token\";\n when Vertical_Line_Token => return \"Vertical_Line_Token\";\n when Identifier_Token => return \"Identifier_Token\";\n when Numeric_Literal_Token => return \"Numeric_Literal_Token\";\n when Character_Literal_Token => return \"Character_Literal_Token\";\n when String_Literal_Token => return \"String_Literal_Token\";\n when Comment_Token => return \"Comment_Token\";\n when Space_Token => return \"Space_Token\";\n when New_Line_Token => return \"New_Line_Token\";\n when Error_Token => return \"Error_Token\";\n when Abort_Token => return \"Abort_Token\";\n when Abs_Token => return \"Abs_Token\";\n when Abstract_Token => return \"Abstract_Token\";\n when Accept_Token => return \"Accept_Token\";\n when Access_Token => return \"Access_Token\";\n when Aliased_Token => return \"Aliased_Token\";\n when All_Token => return \"All_Token\";\n when And_Token => return \"And_Token\";\n when Array_Token => return \"Array_Token\";\n when At_Token => return \"At_Token\";\n when Begin_Token => return \"Begin_Token\";\n when Body_Token => return \"Body_Token\";\n when Case_Token => return \"Case_Token\";\n when Constant_Token => return \"Constant_Token\";\n when Declare_Token => return \"Declare_Token\";\n when Delay_Token => return \"Delay_Token\";\n when Delta_Token => return \"Delta_Token\";\n when Digits_Token => return \"Digits_Token\";\n when Do_Token => return \"Do_Token\";\n when Else_Token => return \"Else_Token\";\n when Elsif_Token => return \"Elsif_Token\";\n when End_Token => return \"End_Token\";\n when Entry_Token => return \"Entry_Token\";\n when Exception_Token => return \"Exception_Token\";\n when Exit_Token => return \"Exit_Token\";\n when For_Token => return \"For_Token\";\n when Function_Token => return \"Function_Token\";\n when Generic_Token => return \"Generic_Token\";\n when Goto_Token => return \"Goto_Token\";\n when If_Token => return \"If_Token\";\n when In_Token => return \"In_Token\";\n when Interface_Token => return \"Interface_Token\";\n when Is_Token => return \"Is_Token\";\n when Limited_Token => return \"Limited_Token\";\n when Loop_Token => return \"Loop_Token\";\n when Mod_Token => return \"Mod_Token\";\n when New_Token => return \"New_Token\";\n when Not_Token => return \"Not_Token\";\n when Null_Token => return \"Null_Token\";\n when Of_Token => return \"Of_Token\";\n when Or_Token => return \"Or_Token\";\n when Others_Token => return \"Others_Token\";\n when Out_Token => return \"Out_Token\";\n when Overriding_Token => return \"Overriding_Token\";\n when Package_Token => return \"Package_Token\";\n when Pragma_Token => return \"Pragma_Token\";\n when Private_Token => return \"Private_Token\";\n when Procedure_Token => return \"Procedure_Token\";\n when Protected_Token => return \"Protected_Token\";\n when Raise_Token => return \"Raise_Token\";\n when Range_Token => return \"Range_Token\";\n when Record_Token => return \"Record_Token\";\n when Rem_Token => return \"Rem_Token\";\n when Renames_Token => return \"Renames_Token\";\n when Requeue_Token => return \"Requeue_Token\";\n when Return_Token => return \"Return_Token\";\n when Reverse_Token => return \"Reverse_Token\";\n when Select_Token => return \"Select_Token\";\n when Separate_Token => return \"Separate_Token\";\n when Some_Token => return \"Some_Token\";\n when Subtype_Token => return \"Subtype_Token\";\n when Synchronized_Token => return \"Synchronized_Token\";\n when Tagged_Token => return \"Tagged_Token\";\n when Task_Token => return \"Task_Token\";\n when Terminate_Token => return \"Terminate_Token\";\n when Then_Token => return \"Then_Token\";\n when Type_Token => return \"Type_Token\";\n when Until_Token => return \"Until_Token\";\n when Use_Token => return \"Use_Token\";\n when When_Token => return \"When_Token\";\n when While_Token => return \"While_Token\";\n when With_Token => return \"With_Token\";\n when Xor_Token => return \"Xor_Token\";\n when others =>\n return Token'Wide_Wide_Image (Value);\n end case;\n end Debug_Image;\n\n --------------\n -- Get_Next --\n --------------\n\n overriding function Get_Next (Self : not null access File_Source)\n return Wide_Wide_Character is\n begin\n if Self.Index < Self.Text.Length then\n return Result : constant Wide_Wide_Character :=\n Self.Text.Element (Self.Index).To_Wide_Wide_Character\n do\n Self.Index := Self.Index + 1;\n end return;\n else\n return Incr.Lexers.Batch_Lexers.End_Of_Input;\n end if;\n end Get_Next;\n\n use type Incr.Ada_Lexers.Token;\n Token : Incr.Ada_Lexers.Token;\n Source : aliased File_Source;\n Batch_Lexer : constant Incr.Lexers.Batch_Lexers.Batch_Lexer_Access :=\n new Incr.Ada_Lexers.Batch_Lexer;\n\nbegin\n while not Ada.Wide_Wide_Text_IO.End_Of_File loop\n declare\n Line : constant Wide_Wide_String := Ada.Wide_Wide_Text_IO.Get_Line;\n begin\n Source.Text.Append (Line);\n Source.Text.Append (Ada.Characters.Wide_Wide_Latin_1.LF);" + }, + { + "function_def": "overriding procedure Discard (Self : in out Joint) is", + "function_body": "Now : constant Version_Trees.Version := Self.Document.History.Changing;\n Diff : Integer := 0;\n begin\n Versioned_Booleans.Discard (Self.Exist, Now, Diff);\n\n for J in Self.Kids'Range loop\n Versioned_Nodes.Discard (Self.Kids (J), Now, Diff);\n Self.Child (J, Now).Discard_Parent;\n end loop;\n\n Self.Update_Local_Changes (Diff);\n end Discard;\n\n --------------\n -- Is_Token --\n --------------\n\n overriding function Is_Token (Self : Joint) return Boolean is\n pragma Unreferenced (Self);\n begin\n return False;\n end Is_Token;\n\n ----------\n -- Kind --\n ----------\n\n overriding function Kind (Self : Joint) return Node_Kind is\n begin\n return Self.Kind;\n end Kind;\n\n --------------------\n -- Nested_Changes --\n --------------------\n\n overriding function Nested_Changes\n (Self : Joint;\n From : Version_Trees.Version;\n To : Version_Trees.Version) return Boolean\n is\n use type Version_Trees.Version;\n\n Time : Version_Trees.Version := To;\n begin\n if Self.Document.History.Is_Changing (To) then\n if Self.Nested_Changes > 0 then\n return True;\n elsif Time = From then\n return False;\n end if;\n\n Time := Self.Document.History.Parent (Time);\n end if;\n\n while Time /= From loop\n if Versioned_Booleans.Get (Self.NC, Time) then\n return True;\n end if;\n\n Time := Self.Document.History.Parent (Time);\n end loop;\n\n return False;\n end Nested_Changes;\n\n -------------------\n -- Nested_Errors --\n -------------------\n\n overriding function Nested_Errors\n (Self : Joint;\n Time : Version_Trees.Version) return Boolean is\n begin\n return Versioned_Booleans.Get (Self.NE, Time);\n end Nested_Errors;\n\n ---------------\n -- On_Commit --\n ---------------\n\n overriding procedure On_Commit\n (Self : in out Joint;\n Parent : Node_Access)\n is\n Now : constant Version_Trees.Version := Self.Document.History.Changing;\n\n Prev : constant Version_Trees.Version :=\n Self.Document.History.Parent (Now);\n Child : Nodes.Node_Access;\n Errors : Boolean := False;\n Ignore : Integer := 0;\n begin\n if Self.Local_Changes > 0 and then Self.Exists (Prev) then\n Mark_Deleted_Children (Self);\n end if;\n\n Versioned_Booleans.Set\n (Self => Self.NC,\n Value => Self.Nested_Changes > 0,\n Time => Self.Document.History.Changing,\n Changes => Ignore);\n\n Node_With_Parent (Self).On_Commit (Parent);\n\n for J in Self.Kids'Range loop\n Child := Self.Child (J, Now);\n\n if Child.Nested_Errors (Now) or else Child.Local_Errors (Now) then\n Errors := True;\n exit;\n end if;\n end loop;\n\n Versioned_Booleans.Set (Self.NE, Errors, Now, Ignore);\n end On_Commit;\n\n ---------------\n -- Set_Child --\n ---------------\n\n overriding procedure Set_Child\n (Self : aliased in out Joint;\n Index : Positive;\n Value : Node_Access)\n is\n Diff : Integer := 0;\n Now : constant Version_Trees.Version := Self.Document.History.Changing;\n Old : constant Node_Access := Self.Child (Index, Now);\n begin\n if Old /= null then\n Old.Set_Parent (null);\n end if;\n\n Versioned_Nodes.Set (Self.Kids (Index), Value, Now, Diff);\n Self.Update_Local_Changes (Diff);\n\n if Value /= null then\n declare\n Parent : constant Node_Access := Value.Parent (Now);\n begin\n if Parent /= null then\n declare\n Index : constant Natural :=\n Parent.Child_Index (Constant_Node_Access (Value), Now);\n begin\n Value.Set_Parent (null);\n Parent.Set_Child (Index, null);\n Value.Set_Parent (Self'Unchecked_Access);" + }, + { + "function_def": "procedure Right_Breakdown;", + "function_body": "procedure Recover (LA : out Nodes.Node_Access);\n procedure Recover_2 (LA : out Nodes.Node_Access);\n\n Stack : Parser_Stack;\n State : Parser_State := 1;\n Now : constant Version_Trees.Version := Document.History.Changing;\n\n Previous : constant Version_Trees.Version :=\n Document.History.Parent (Now);\n Next_Action : constant Action_Table_Access := Provider.Actions;\n Next_State : constant State_Table_Access := Provider.States;\n Counts : constant Parts_Count_Table_Access := Provider.Part_Counts;\n\n procedure Clear (Self : out Parser_Stack) is\n begin\n Self.Top := 0;\n end Clear;\n\n --------------\n -- Do_Shift --\n --------------\n\n procedure Do_Shift (Node : Nodes.Node_Access) is\n begin\n if Node.Is_Token then\n -- Next_Action should be shift\n On_Shift (State, Next_Action (State, Node.Kind).State, Node);\n else\n On_Shift (State, Next_State (State, Node.Kind), Node);\n end if;\n end Do_Shift;\n\n --------------------\n -- Left_Breakdown --\n --------------------\n\n function Left_Breakdown\n (Node : Nodes.Node_Access) return Nodes.Node_Access is\n begin\n if Node.Arity > 0 then\n return Node.Child (1, Reference);\n else\n return Node.Next_Subtree (Reference);\n end if;\n end Left_Breakdown;\n\n ---------------\n -- On_Reduce --\n ---------------\n\n procedure On_Reduce (Parts : Production_Index) is\n Count : constant Natural := Counts (Parts);\n subtype First_Nodes is Nodes.Node_Array (1 .. Count);\n\n Kind : Nodes.Node_Kind;\n begin\n Stack.Top := Stack.Top - Count + 1;\n\n Factory.Create_Node\n (Parts,\n First_Nodes (Stack.Node (Stack.Top .. Stack.Top + Count - 1)),\n Stack.Node (Stack.Top),\n Kind);\n\n if Count = 0 then\n Stack.State (Stack.Top) := State;\n end if;\n\n State := Next_State (Stack.State (Stack.Top), Kind);\n end On_Reduce;\n\n --------------\n -- On_Shift --\n --------------\n\n procedure On_Shift\n (State : in out Parser_State;\n New_State : Parser_State;\n Node : access Nodes.Node'Class) is\n begin\n Push (Stack, State, Nodes.Node_Access (Node));\n State := New_State;\n end On_Shift;\n\n ---------\n -- Pop --\n ---------\n\n procedure Pop\n (Self : in out Parser_Stack;\n State : out Parser_State;\n Node : out Nodes.Node_Access) is\n begin\n State := Self.State (Self.Top);\n Node := Self.Node (Self.Top);\n Self.Top := Self.Top - 1;\n end Pop;\n\n ----------\n -- Push --\n ----------\n\n procedure Push\n (Self : in out Parser_Stack;\n State : Parser_State;\n Node : Nodes.Node_Access) is\n begin\n Self.Top := Self.Top + 1;\n Self.State (Self.Top) := State;\n Self.Node (Self.Top) := Node;\n Node.Set_Local_Errors (False);\n end Push;\n\n -------------\n -- Recover --\n -------------\n\n procedure Recover (LA : out Nodes.Node_Access) is\n begin\n if Stack.Top > 1 then\n -- Remove any default reductions from the parse stack\n Right_Breakdown;\n end if;\n\n Recover_2 (LA);\n end Recover;\n\n ---------------\n -- Recover_2 --\n ---------------\n\n procedure Recover_2 (LA : out Nodes.Node_Access) is\n\n type Offset_Array is array (Positive range <>) of Natural;\n\n function Is_Valid_Isolation\n (Node : Nodes.Node_Access;\n Offset : Natural;\n State : Parser_State) return Boolean;\n\n function Node_Offset\n (Node : Nodes.Node_Access;\n Time : Version_Trees.Version) return Natural;\n -- Compute offset of Node in given Time\n\n function Get_Cut\n (Node : Nodes.Node_Access;\n Offset : Offset_Array;\n Top : Positive) return Natural;\n -- Compute stack entry corresponding to leading edge of node\u2019s\n -- subtree in the previous version. Returns False if no entry is\n -- so aligned. Top limits stack depth search.\n\n procedure Isolate (Node : Nodes.Node_Access; Top : Positive);\n -- Resets configuration so parsing can continue.\n\n procedure Refine (Node : Nodes.Node_Access);\n -- Isolate the argument and recursively recover the subtree that it\n -- roots.\n\n procedure Discard_Changes_And_Mark_Errors\n (Node : access Nodes.Node'Class);\n\n Jam_Offset : Natural;\n\n -------------------------------------\n -- Discard_Changes_And_Mark_Errors --\n -------------------------------------\n\n procedure Discard_Changes_And_Mark_Errors\n (Node : access Nodes.Node'Class) is\n begin\n Node.Discard;\n\n if Node.Local_Changes (Reference, Now) then\n Node.Set_Local_Errors (True);\n end if;\n end Discard_Changes_And_Mark_Errors;\n\n -------------\n -- Get_Cut --\n -------------\n\n function Get_Cut\n (Node : Nodes.Node_Access;\n Offset : Offset_Array;\n Top : Positive) return Natural\n is\n Old_Offset : constant Natural := Node_Offset (Node, Previous);\n begin\n for J in 1 .. Top loop\n if Offset (J) > Old_Offset then\n return 0;\n elsif Offset (J) = Old_Offset then\n for K in J + 1 .. Top loop\n if Offset (K) /= Offset (J) then\n return K - 1;\n end if;\n end loop;\n\n return J;\n end if;\n end loop;\n\n return 0;\n end Get_Cut;\n\n ------------------------\n -- Is_Valid_Isolation --\n ------------------------\n\n function Is_Valid_Isolation\n (Node : Nodes.Node_Access;\n Offset : Natural;\n State : Parser_State) return Boolean\n is\n Old_Offset : constant Natural := Node_Offset (Node, Previous);\n begin\n if Offset /= Old_Offset then\n -- The starting offset of the subtree must be the same in both\n -- the previous and current versions.\n -- I have no idea how this could fail???\n return False;\n elsif Offset > Jam_Offset then\n -- Cannot be to the right of the point where the error was\n -- detected by the parser.\n return False;\n elsif Offset + Node.Span (Nodes.Text_Length, Previous) <=\n Jam_Offset\n then\n -- The ending offset must meet or exceed the detection point.\n return False;\n elsif Node.Span (Nodes.Text_Length, Previous) /=\n Node.Span (Nodes.Text_Length, Now)\n then\n -- The subtree span must the same in current and prev versions.\n return False;\n end if;\n\n declare\n Right : constant Nodes.Tokens.Token_Access :=\n Node.Last_Token (Previous);\n Next : constant Nodes.Tokens.Token_Access :=\n Right.Next_Token (Previous);\n begin\n -- Check if lexical analysis cross right edge of Node\n if Right.Get_Flag (Nodes.Need_Analysis) and\n (Next not in null and then\n Next.Get_Flag (Nodes.Need_Analysis))\n then\n return False;\n end if;" + }, + { + "function_def": "procedure Right_Breakdown is", + "function_body": "Node : Nodes.Node_Access;\n Limit : constant Natural := Stack.Top - 1;\n begin\n loop\n Pop (Stack, State, Node);\n\n exit when Node.Is_Token;\n\n for J in 1 .. Node.Arity loop\n Do_Shift (Node.Child (J, Now));\n end loop;\n\n if Stack.Top = Limit then\n -- Empty subtree was on the top of the stack\n return;\n end if;\n end loop;\n\n Do_Shift (Node);\n end Right_Breakdown;\n\n Verify : Boolean := False;\n Lexing : Boolean := False;\n EOF : Boolean := False;\n Term : Nodes.Tokens.Token_Access;\n\n LA : access Nodes.Node'Class := Document.Start_Of_Stream;\n Next : Action;\n begin\n Document.Start_Of_Stream.Set_Text\n (League.Strings.Empty_Universal_String);\n Document.End_Of_Stream.Set_Text\n (League.Strings.Empty_Universal_String);\n\n Lexer.Prepare_Document (Document, Reference);\n Clear (Stack);\n Push (Stack, State, Nodes.Node_Access (Document.Start_Of_Stream));\n\n if not LA.Get_Flag (Nodes.Need_Analysis) then\n LA := LA.Next_Subtree (Reference);\n end if;\n\n loop\n if LA.Is_Token then\n if not Lexing\n and then LA.Get_Flag (Nodes.Need_Analysis)\n and then not EOF\n then\n Term := Lexer.First_New_Token (Nodes.Tokens.Token_Access (LA));\n LA := Term;\n Lexing := True;\n else\n Term := Nodes.Tokens.Token_Access (LA);\n end if;\n\n Next := Next_Action (State, Term.Kind);\n\n case Next.Kind is\n when Finish =>\n if Term.Kind = 0 then -- End_Of_Stream\n declare\n Node : Nodes.Node_Access;\n begin\n Pop (Stack, State, Node);\n Document.Ultra_Root.Set_Child (2, Node);\n\n return;" + }, + { + "function_def": "overriding function Exists", + "function_body": "(Self : Node_With_Exist;\n Time : Version_Trees.Version) return Boolean is\n begin\n return Versioned_Booleans.Get (Self.Exist, Time);\n end Exists;\n\n -----------------\n -- Child_Index --\n -----------------\n\n function Child_Index\n (Self : Node'Class;\n Child : Constant_Node_Access;\n Time : Version_Trees.Version) return Natural is\n begin\n for J in 1 .. Self.Arity loop\n if Constant_Node_Access (Self.Child (J, Time)) = Child then\n return J;\n end if;\n end loop;\n\n return 0;\n end Child_Index;\n\n --------------------\n -- Discard_Parent --\n --------------------\n\n overriding procedure Discard_Parent (Self : in out Node_With_Parent) is\n Changed : Boolean;\n Ignore : Integer := 0;\n Now : constant Version_Trees.Version :=\n Self.Document.History.Changing;\n begin\n Changed := Self.Local_Changes > 0 or Self.Nested_Changes > 0;\n\n if Changed then\n Self.Propagate_Nested_Changes (-1);\n end if;\n\n Versioned_Nodes.Discard (Self.Parent, Now, Ignore);\n\n if Changed then\n Self.Propagate_Nested_Changes (1);\n end if;\n end Discard_Parent;\n\n -----------------\n -- First_Token --\n -----------------\n\n function First_Token\n (Self : aliased in out Node'Class;\n Time : Version_Trees.Version)\n return Tokens.Token_Access\n is\n Child : Node_Access;\n begin\n if Self.Arity > 0 then\n Child := Self.Child (1, Time);\n\n if Child.Is_Token then\n return Tokens.Token_Access (Child);\n else\n return Child.First_Token (Time);\n end if;\n elsif Self.Is_Token then\n return Tokens.Token'Class (Self)'Access;\n else\n return null;\n end if;\n end First_Token;\n\n --------------\n -- Get_Flag --\n --------------\n\n overriding function Get_Flag\n (Self : Node_With_Exist;\n Flag : Transient_Flags) return Boolean is\n begin\n return Self.Flag (Flag);\n end Get_Flag;\n\n ----------------\n -- Last_Token --\n ----------------\n\n function Last_Token\n (Self : aliased in out Node'Class;\n Time : Version_Trees.Version) return Tokens.Token_Access\n is\n Child : Node_Access;\n begin\n if Self.Arity > 0 then\n Child := Self.Child (Self.Arity, Time);\n\n if Child.Is_Token then\n return Tokens.Token_Access (Child);\n else\n return Child.Last_Token (Time);\n end if;\n elsif Self.Is_Token then\n return Tokens.Token'Class (Self)'Access;\n else\n return null;\n end if;\n end Last_Token;\n\n -------------------\n -- Local_Changes --\n -------------------\n\n overriding function Local_Changes\n (Self : Node_With_Exist;\n From : Version_Trees.Version;\n To : Version_Trees.Version) return Boolean\n is\n use type Version_Trees.Version;\n\n Time : Version_Trees.Version := To;\n begin\n if Self.Document.History.Is_Changing (To) then\n -- Self.LC doesn't contain Local_Changes for Is_Changing version yet\n -- Take it from Self.Nested_Changes\n if Self.Local_Changes > 0 then\n return True;\n elsif Time = From then\n return False;\n end if;\n\n Time := Self.Document.History.Parent (Time);\n end if;\n\n while Time /= From loop\n if Versioned_Booleans.Get (Self.LC, Time) then\n return True;\n end if;\n\n Time := Self.Document.History.Parent (Time);\n end loop;\n\n return False;\n end Local_Changes;\n\n ---------------------------\n -- Mark_Deleted_Children --\n ---------------------------\n\n procedure Mark_Deleted_Children (Self : in out Node'Class) is\n\n function Find_Root (Node : Node_Access) return Node_Access;\n -- Find top root accessible from the Node\n\n procedure Delete_Tree\n (Node : not null Node_Access;\n Parent : Node_Access;\n Index : Positive);\n -- Check Node if it's disjointed from ultra-root.\n -- Delete a subtree rooted from Node if so.\n -- If Parent /= null also set Parent.Child(Index) to null.\n\n Now : constant Version_Trees.Version := Self.Document.History.Changing;\n\n -----------------\n -- In_The_Tree --\n -----------------\n\n function Find_Root (Node : Node_Access) return Node_Access is\n Child : not null Nodes.Node_Access := Node;\n begin\n loop\n declare\n Parent : constant Nodes.Node_Access := Child.Parent (Now);\n begin\n if Parent = null then\n return Child;\n else\n Child := Parent;\n end if;" + }, + { + "function_def": "procedure Main is", + "function_body": "begin\n -- Guide: http://archive.adaic.com/standards/83lrm/html/lrm-11-01.html\n declare\n PP : Positive;\n P2 : Positive;\n begin\n P2 := 5;\n PP := 3 - P2; -- intentionally violate Positive range constraint\n exception\n when Constraint_Error =>\n Put_Line(\"HANDLED: violate range constraint gives Constraint_Error\");" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Agent_Impl, Agent_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Agent_Impl_Ptr := Agent_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Agent_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, AGENT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Agent_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Agent_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (AGENT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- hostname\n Value => Object.Hostname);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- ip\n Value => Object.Ip);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_1_NAME, -- key\n Value => Object.Key);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Snapshot_Impl, Snapshot_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Snapshot_Impl_Ptr := Snapshot_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Snapshot_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SNAPSHOT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Snapshot_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Snapshot_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SNAPSHOT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_1_NAME, -- start_date\n Value => Object.Start_Date);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- end_date\n Value => Object.End_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_1_NAME, -- host_id\n Value => Object.Host);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Snapshot_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SNAPSHOT_DEF'Access);\n begin\n Stmt.Execute;\n Snapshot_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Snapshot_Ref;\n Impl : constant Snapshot_Access := new Snapshot_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Source_Impl, Source_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Source_Impl_Ptr := Source_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Source_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SOURCE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Source_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Source_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SOURCE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- label\n Value => Object.Label);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- host_id\n Value => Object.Host);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure List (Object : in out Source_Vector;", + "function_body": "Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SOURCE_DEF'Access);\n begin\n Stmt.Execute;\n Source_Vectors.Clear (Object);\n while Stmt.Has_Elements loop\n declare\n Item : Source_Ref;\n Impl : constant Source_Access := new Source_Impl;\n begin\n Impl.Load (Stmt, Session);\n ADO.Objects.Set_Object (Item, Impl.all'Access);\n Object.Append (Item);" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Format_Type);\n Impl : Series_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 8, Impl.Format, Value);\n end Set_Format;\n\n function Get_Format (Object : in Series_Ref)\n return Hyperion.Monitoring.Models.Format_Type is\n Impl : constant Series_Access\n := Series_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Format;\n end Get_Format;\n\n\n procedure Set_Source (Object : in out Series_Ref;\n Value : in Hyperion.Monitoring.Models.Source_Ref'Class) is\n Impl : Series_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 9, Impl.Source, Value);\n end Set_Source;\n\n function Get_Source (Object : in Series_Ref)\n return Hyperion.Monitoring.Models.Source_Ref'Class is\n Impl : constant Series_Access\n := Series_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Source;\n end Get_Source;\n\n\n procedure Set_Snapshot (Object : in out Series_Ref;\n Value : in Hyperion.Monitoring.Models.Snapshot_Ref'Class) is\n Impl : Series_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 10, Impl.Snapshot, Value);\n end Set_Snapshot;\n\n function Get_Snapshot (Object : in Series_Ref)\n return Hyperion.Monitoring.Models.Snapshot_Ref'Class is\n Impl : constant Series_Access\n := Series_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Snapshot;\n end Get_Snapshot;\n\n -- Copy of the object.\n procedure Copy (Object : in Series_Ref;\n Into : in out Series_Ref) is\n Result : Series_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Series_Access\n := Series_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Series_Access\n := new Series_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Version := Impl.Version;\n Copy.Start_Date := Impl.Start_Date;\n Copy.End_Date := Impl.End_Date;\n Copy.Content := Impl.Content;\n Copy.Count := Impl.Count;\n Copy.First_Value := Impl.First_Value;\n Copy.Format := Impl.Format;\n Copy.Source := Impl.Source;\n Copy.Snapshot := Impl.Snapshot;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Series_Impl, Series_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Series_Impl_Ptr := Series_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Series_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SERIES_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Series_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Series_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SERIES_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- start_date\n Value => Object.Start_Date);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- end_date\n Value => Object.End_Date);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- content\n Value => Object.Content);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_3_NAME, -- count\n Value => Object.Count);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_3_NAME, -- first_value\n Value => Object.First_Value);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_3_NAME, -- format\n Value => Integer (Format_Type'Pos (Object.Format)));\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_3_NAME, -- source_id\n Value => Object.Source);\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_3_NAME, -- snapshot_id\n Value => Object.Snapshot);\n Object.Clear_Modified (10);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Description_Impl, Description_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Description_Impl_Ptr := Description_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Description_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, DESCRIPTION_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Description_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Description_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (DESCRIPTION_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_1_NAME, -- content\n Value => Object.Content);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Set_Field_Enum is", + "function_body": "new ADO.Objects.Set_Field_Operation (Status_Type);\n Impl : Host_Access;\n begin\n Set_Field (Object, Impl);\n Set_Field_Enum (Impl.all, 9, Impl.Status, Value);\n end Set_Status;\n\n function Get_Status (Object : in Host_Ref)\n return Hyperion.Hosts.Models.Status_Type is\n Impl : constant Host_Access\n := Host_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Status;\n end Get_Status;\n\n\n procedure Set_Agent (Object : in out Host_Ref;\n Value : in Hyperion.Agents.Models.Agent_Ref'Class) is\n Impl : Host_Access;\n begin\n Set_Field (Object, Impl);\n ADO.Objects.Set_Field_Object (Impl.all, 10, Impl.Agent, Value);\n end Set_Agent;\n\n function Get_Agent (Object : in Host_Ref)\n return Hyperion.Agents.Models.Agent_Ref'Class is\n Impl : constant Host_Access\n := Host_Impl (Object.Get_Load_Object.all)'Access;\n begin\n return Impl.Agent;\n end Get_Agent;\n\n -- Copy of the object.\n procedure Copy (Object : in Host_Ref;\n Into : in out Host_Ref) is\n Result : Host_Ref;\n begin\n if not Object.Is_Null then\n declare\n Impl : constant Host_Access\n := Host_Impl (Object.Get_Load_Object.all)'Access;\n Copy : constant Host_Access\n := new Host_Impl;\n begin\n ADO.Objects.Set_Object (Result, Copy.all'Access);\n Copy.Copy (Impl.all);\n Copy.Version := Impl.Version;\n Copy.Name := Impl.Name;\n Copy.Ip := Impl.Ip;\n Copy.Key := Impl.Key;\n Copy.Create_Date := Impl.Create_Date;\n Copy.Serial := Impl.Serial;\n Copy.Description := Impl.Description;\n Copy.Status := Impl.Status;\n Copy.Agent := Impl.Agent;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Host_Impl, Host_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Host_Impl_Ptr := Host_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Host_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, HOST_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Host_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Host_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (HOST_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_2_NAME, -- name\n Value => Object.Name);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_2_NAME, -- ip\n Value => Object.Ip);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_2_NAME, -- key\n Value => Object.Key);\n Object.Clear_Modified (5);\n end if;\n if Object.Is_Modified (6) then\n Stmt.Save_Field (Name => COL_5_2_NAME, -- create_date\n Value => Object.Create_Date);\n Object.Clear_Modified (6);\n end if;\n if Object.Is_Modified (7) then\n Stmt.Save_Field (Name => COL_6_2_NAME, -- serial\n Value => Object.Serial);\n Object.Clear_Modified (7);\n end if;\n if Object.Is_Modified (8) then\n Stmt.Save_Field (Name => COL_7_2_NAME, -- description\n Value => Object.Description);\n Object.Clear_Modified (8);\n end if;\n if Object.Is_Modified (9) then\n Stmt.Save_Field (Name => COL_8_2_NAME, -- status\n Value => Integer (Status_Type'Pos (Object.Status)));\n Object.Clear_Modified (9);\n end if;\n if Object.Is_Modified (10) then\n Stmt.Save_Field (Name => COL_9_2_NAME, -- agent_id\n Value => Object.Agent);\n Object.Clear_Modified (10);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Host_Info_Impl, Host_Info_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Host_Info_Impl_Ptr := Host_Info_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n procedure Find (Object : in out Host_Info_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, HOST_INFO_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Host_Info_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n procedure Save (Object : in out Host_Info_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (HOST_INFO_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_3_NAME, -- index\n Value => Object.Index);\n Object.Clear_Modified (3);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- host_id\n Value => Object.Host);\n Object.Clear_Modified (4);\n end if;\n if Object.Is_Modified (5) then\n Stmt.Save_Field (Name => COL_4_3_NAME, -- desc_id\n Value => Object.Desc);\n Object.Clear_Modified (5);\n end if;\n if Stmt.Has_Save_Fields then\n Object.Version := Object.Version + 1;\n Stmt.Save_Field (Name => \"version\",\n Value => Object.Version);\n Stmt.Set_Filter (Filter => \"id = ? and version = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Version - 1);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n else\n raise ADO.Objects.LAZY_LOCK;\n end if;\n end if;" + }, + { + "function_def": "procedure Main is", + "function_body": "Config : Command_Line_Configuration;\n\nbegin\n\n Util.Define_CLI_Switches(Config);\n Getopt(Config);\n\n Util.Process_Command_Arguments;\n\nexception\n when E : Util.Execution_Error =>\n Put(\"Execution error: \");\n Put_Line(Exception_Message(E));\n Put_Line(\"... stopping.\");\n\n when E : Util.Argument_Error =>\n Put(\"Invalid argument: \");\n Put_Line(Exception_Message(E));\n Display_Help(Config);\n\n when Exit_From_Command_Line =>\n return;" + }, + { + "function_def": "procedure Process_Command_Arguments;", + "function_body": "" + }, + { + "function_def": "procedure Put_Im_Instance_Info is", + "function_body": "new Put_Instance_Info(Image_WFC);\n\n procedure Put_Ch_Instance_Info is\n new Put_Instance_Info(Character_WFC);\n\n Input_Image, Output_Image : IL_Image;\n\n Input_File : File_Type;\n Output_File : File_Type;\n\n Im_Instance : Im_Instance_Access;\n Ch_Instance : Ch_Instance_Access;\n\n type Input_Kind is (None, Pictoral, Textual);\n -- The type of the last received input sample.\n -- We want to be able to process both actual images\n -- as well as simpler, textual files, for ease of use.\n\n Last_Input_Kind : Input_Kind := None;\n -- Remember whether we've had an input yet, and if so,\n -- what type it was.\n\n N, M : aliased Integer := 2;\n -- The width and height of the tiles\n -- to be used in the instantiation.\n\n Rot, Ref : aliased Boolean := False;\n -- Whether to include rotations, and reflections,\n -- respectively, in the instantiation tileset.\n\n Use_Stdout : aliased Boolean := False;\n -- Whether to output text-only instance results\n -- on stdout rather than using a separate file.\n\n Output_Scale : aliased Integer := 1;\n -- When in image mode, how much to scale up the output image.\n\n Out_Name : XString;\n -- The name of the file we will produce as output (sans extension, size info, id)\n\n Out_Ct : Natural := 0;\n -- How many outputs we've handled so far.\n\n procedure Parse_Output_Command (Spec : String; W, H : out Natural) is\n use Ada.Strings.Maps;\n use Ada.Strings.Fixed;\n \n Separator_Set : constant Character_Set := To_Set(\"xX,/:\");\n Separator_Ix : constant Natural := Index(Spec, Separator_Set);\n Last : Natural;\n begin\n if Separator_Ix = 0 then\n raise Argument_Error with \"Cannot parse argument: (\" & Spec & \")\";\n end if;\n declare\n Prefix : String renames Spec (Spec'First .. Separator_Ix - 1);\n Suffix : String renames Spec (Separator_Ix + 1 .. Spec'Last); \n begin\n Get(Prefix, Item => W, Last => Last);\n if Last /= Prefix'Last then\n raise Argument_Error with \"Cannot parse integer: (\" & Prefix & \")\";\n end if;\n Get(Suffix, Item => H, Last => Last);\n if Last /= Suffix'Last then\n raise Argument_Error with \"Cannot parse integer: (\" & Suffix & \")\";\n end if;" + }, + { + "function_def": "procedure Process_Command_Arguments is", + "function_body": "type Output_Handler_Type is\n access procedure (W, H : Natural);\n \n function Handle_Arg (Handler : not null Output_Handler_Type) return Boolean is\n Arg : constant String := Get_Argument;\n Out_W, Out_H : Natural;\n begin\n if Arg = \"\" then\n return False;\n end if;\n\n Parse_Output_Command(Arg, Out_W, Out_H);\n Handler(Out_W, Out_H);\n\n return True;" + }, + { + "function_def": "function Rotate_Clockwise (Matrix : in Element_Matrix) return Element_Matrix", + "function_body": "with Inline\n is\n Out_Matrix : Element_Matrix (Matrix'Range(2), Matrix'Range(1));\n Out_X : Natural;\n begin\n for The_X in Matrix'Range(1) loop\n for The_Y in Matrix'Range(2) loop\n Out_X := Matrix'First(2) + Matrix'Last(2) - The_Y;\n Out_Matrix(Out_X, The_X) := Matrix(The_X, The_Y);\n end loop;\n end loop;\n return Out_Matrix;" + }, + { + "function_def": "function Collapse is new", + "function_body": "Extended.Generic_Collapse_Within\n ( Set_Resulting_Element => Set_Resulting_Element\n , Upon_Collapse => Upon_Collapse\n );\n\n begin\n return Collapse(Parameters);" + }, + { + "function_def": "function Log_Frequency_Noise return Float is", + "function_body": "use Ada.Numerics.Float_Random;\n G : Generator;\n begin\n Reset(G);\n return Random(G) * 1.0E-4;" + }, + { + "function_def": "procedure Put_Debug_Info is", + "function_body": "begin\n Put_Line(Standard_Error, \"Tile_ID_Bytes =>\" & Integer'Image(Tile_ID_Range'Object_Size / 8));\n Put_Line(Standard_Error, \" Small_Bytes =>\" & Integer'Image(Small_Integer'Object_Size / 8));\n Put_Line(Standard_Error, \" Cell_Bytes =>\" & Integer'Image(Wave_Function_Cell'Object_Size / 8));\n Put_Line(Standard_Error, \" Wave_Bytes =>\" & Integer'Image(Wave_Function'Object_Size / 8));\n Put_Line(Standard_Error, \"Enabler_Bytes =>\" & Integer'Image(Init_Enablers'Size / 8));\n Put_Line(Standard_Error, \" Matrix_Bytes =>\" & Integer'Image(Wave_Function_Matrix.all'Size / 8));\n New_Line(Standard_Error, 1);\n\n for Y in Y_Dim loop\n for X in X_Dim loop\n declare\n Collapsed_Tile : constant Tile_ID_Range := Collapsed_Tile_Choices(X, Y);\n begin\n Put(Standard_Error, Tail(Tile_ID'Image(Collapsed_Tile), 4));" + }, + { + "function_def": "procedure Polling is", + "function_body": "use Raspio.GPIO;\nbegin\n Raspio.Initialize;\n declare\n -- connect button from pin 12 to ground\n Button : constant Pin_Type :=\n Create\n (Pin_ID => GPIO_P1_12, Mode => Input, Internal_Resistor => Pull_Up);\n\n State : Pin_State := Off;\n begin\n loop\n State := Read (Button);\n Ada.Text_IO.Put_Line (State'Image);\n delay 0.2;\n end loop;" + }, + { + "function_def": "procedure awordcount is", + "function_body": "-- *** Variable declarations *** \nbegin\n \n New_Line;\n\n if Ada.Command_Line.Argument_Count = 0 then\n Put_Line(Item => \" ERROR! Filename required.\");\n Put_Line(Item => \" USAGE: awordcount file-to-get-counts-for.txt\");\n else\n declare\n -- *** Variable declarations *** \n FileName : String(1..Ada.Command_Line.Argument(1)'length);\n FileNameLength : Natural := Ada.Command_Line.Argument(1)'length;\n SourceFile : Ada.Text_IO.File_Type;\n begin\n FileName := Ada.Command_Line.Argument(1);\n Put(Item => \"Parsing file: \");\n Put_Line(Item => FileName); \n if GNAT.IO_Aux.File_Exists(FileName) then\n \n Open(SourceFile, In_File, FileName);\n declare\n package UStrings renames Ada.Strings.Unbounded;\n package UnboundedIO renames Ada.Strings.Unbounded.Text_IO;\n CurrentLine : UStrings.Unbounded_String := UStrings.Null_Unbounded_String;\n CurrentLineLength : Integer := 0;\n CharacterCount : Integer := 0;\n LineCount : Integer := 0;\n LineWordCount : GNAT.String_Split.Slice_Number; \n SplitArr : GNAT.String_Split.Slice_Set;\n WordSeparators : String := \" \";\n WordCount : Integer := 0;\n begin\n while not End_Of_File(SourceFile)\n loop\n CurrentLine := UnboundedIO.Get_Line(File => SourceFile);\n LineCount := LineCount + 1;\n CurrentLineLength := UStrings.To_String(CurrentLine)'Length;\n CharacterCount := CharacterCount + CurrentLineLength;\n GNAT.String_Split.Create(SplitArr, UStrings.To_String(CurrentLine), WordSeparators, Mode => GNAT.String_Split.Multiple);\n LineWordCount := GNAT.String_Split.Slice_Count(S => SplitArr);\n WordCount := WordCount + Integer(LineWordCount);\n end loop;\n Put(Item => \"Characters: \");\n Ada.Integer_Text_IO.Put(CharacterCount);\n New_Line;\n Put(Item => \"Lines: \");\n Ada.Integer_Text_IO.Put(LineCount);\n New_Line;\n Put(Item => \"Words: \");\n Ada.Integer_Text_IO.Put(WordCount);" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(Source => Watch_Bits, Target => Interfaces.C.unsigned);\n\n Result : constant Interfaces.C.int := Inotify_Add_Watch\n (Object.Instance, Interfaces.C.To_C (Path), Convert (Mask));\n begin\n if Result = -1 then\n raise Program_Error;\n end if;\n\n Object.Watches.Include (Result, Path);\n return (Watch => Result);\n end Add_Watch;\n\n procedure Add_Watch\n (Object : in out Instance;\n Path : String;\n Mask : Watch_Bits := All_Events)\n is\n Result : constant Watch := Instance'Class (Object).Add_Watch (Path, Mask);\n begin\n pragma Assert (Result.Watch /= -1);\n end Add_Watch;\n\n procedure Remove_Watch (Object : in out Instance; Subject : Watch) is\n function Inotify_Remove_Watch\n (Instance : GNAT.OS_Lib.File_Descriptor;\n Watch : Interfaces.C.int) return Interfaces.C.int\n with Import, Convention => C, External_Name => \"inotify_rm_watch\";\n begin\n -- Procedure Process_Events might read multiple events for a specific\n -- watch and the callback for the first event may immediately try to\n -- remove the watch\n if Object.Defer_Remove then\n if not Object.Pending_Removals.Contains (Subject) then\n Object.Pending_Removals.Append (Subject);\n end if;\n return;\n end if;\n\n if Inotify_Remove_Watch (Object.Instance, Subject.Watch) = -1 then\n raise Program_Error;\n end if;\n\n Object.Watches.Delete (Subject.Watch);\n end Remove_Watch;\n\n function Has_Watches (Object : in out Instance) return Boolean is\n (not Object.Watches.Is_Empty);\n\n function Name (Object : Instance; Subject : Watch) return String is\n (Object.Watches.Element (Subject.Watch));\n\n -----------------------------------------------------------------------------\n\n type Inotify_Event is record\n Watch : Interfaces.C.int; -- -1 if event queue has overflowed\n Mask : Interfaces.C.unsigned;\n Cookie : Interfaces.C.unsigned;\n Length : Interfaces.C.unsigned;\n end record\n with Convention => C,\n Alignment => 4;\n\n type Event_Bits is record\n Event : Event_Kind;\n\n Queue_Overflowed : Boolean := False;\n Ignored : Boolean := False;\n Is_Directory : Boolean := False;\n end record;\n\n for Event_Bits use record\n Event at 0 range 0 .. 13;\n\n Queue_Overflowed at 0 range 14 .. 14;\n Ignored at 0 range 15 .. 15;\n Is_Directory at 0 range 30 .. 30;\n end record;\n for Event_Bits'Size use Interfaces.C.unsigned'Size;\n for Event_Bits'Alignment use Interfaces.C.unsigned'Alignment;\n\n procedure Process_Events\n (Object : in out Instance;\n Handle : not null access procedure\n (Subject : Watch;\n Event : Event_Kind;\n Is_Directory : Boolean;\n Name : String);\n Move_Handle : not null access procedure\n (Subject : Watch;\n Is_Directory : Boolean;\n From, To : String))\n is\n use Ada.Streams;\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Stream_Element_Array, Target => Inotify_Event);\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Interfaces.C.unsigned, Target => Event_Bits);\n\n Event_In_Bytes : constant Stream_Element_Offset\n := Inotify_Event'Size / System.Storage_Unit;\n\n Length : Stream_Element_Offset;\n Buffer : Stream_Element_Array (1 .. 4096)\n with Alignment => 4;\n\n function Find_Move (Cookie : Interfaces.C.unsigned) return Move_Vectors.Cursor is\n Cursor : Move_Vectors.Cursor := Move_Vectors.No_Element;\n\n procedure Reverse_Iterate (Position : Move_Vectors.Cursor) is\n use type Interfaces.C.unsigned;\n begin\n if Cookie = Object.Moves (Position).Key then\n Cursor := Position;\n end if;\n end Reverse_Iterate;\n begin\n Object.Moves.Reverse_Iterate (Reverse_Iterate'Access);\n return Cursor;\n end Find_Move;\n\n use type Ada.Containers.Count_Type;\n begin\n if Object.Watches.Is_Empty then\n return;\n end if;\n\n Length := Stream_Element_Offset (GNAT.OS_Lib.Read\n (Object.Instance, Buffer'Address, Buffer'Length));\n\n if Length = -1 then\n raise Read_Error;\n end if;\n\n if Length = 0 then\n return;\n end if;\n\n declare\n Index : Stream_Element_Offset := Buffer'First;\n begin\n Object.Defer_Remove := True;\n\n while Index < Buffer'First + Length loop\n declare\n Event : constant Inotify_Event\n := Convert (Buffer (Index .. Index + Event_In_Bytes - 1));\n Mask : constant Event_Bits := Convert (Event.Mask);\n\n Name_Length : constant Stream_Element_Offset\n := Stream_Element_Offset (Event.Length);\n begin\n if Mask.Queue_Overflowed then\n raise Queue_Overflow_Error;\n end if;\n pragma Assert (Event.Watch /= -1);\n\n if Mask.Ignored then\n Object.Watches.Exclude (Event.Watch);\n else\n declare\n Directory : constant String := Object.Watches.Element (Event.Watch);\n begin\n if Name_Length > 0 then\n declare\n subtype Name_Array is Interfaces.C.char_array\n (1 .. Interfaces.C.size_t (Event.Length));\n subtype Name_Buffer is Stream_Element_Array\n (1 .. Name_Length);\n\n function Convert is new Ada.Unchecked_Conversion\n (Source => Name_Buffer, Target => Name_Array);\n\n Name_Index : constant Stream_Element_Offset\n := Index + Event_In_Bytes;\n\n Name : constant String := Interfaces.C.To_Ada (Convert\n (Buffer (Name_Index .. Name_Index + Name_Length - 1)));\n begin\n Handle\n ((Watch => Event.Watch), Mask.Event,\n Mask.Is_Directory, Directory & \"/\" & Name);\n\n case Mask.Event is\n when Moved_From =>\n if Object.Moves.Length = Object.Moves.Capacity then\n Object.Moves.Delete_First;\n end if;\n Object.Moves.Append ((Event.Cookie,\n (From => SU.To_Unbounded_String (Directory & \"/\" & Name),\n To => <>)));\n -- If inode is moved to outside watched directory,\n -- then there will never be a Moved_To or Moved_Self\n -- if instance is not recursive\n when Moved_To =>\n declare\n Cursor : Move_Vectors.Cursor := Find_Move (Event.Cookie);\n use type Move_Vectors.Cursor;\n begin\n if Cursor /= Move_Vectors.No_Element then\n -- It's a rename\n Move_Handle\n (Subject => (Watch => Event.Watch),\n Is_Directory => Mask.Is_Directory,\n From => SU.To_String\n (Object.Moves (Cursor).Value.From),\n To => Directory & \"/\" & Name);\n Object.Moves.Delete (Cursor);\n else\n Move_Handle\n (Subject => (Watch => Event.Watch),\n Is_Directory => Mask.Is_Directory,\n From => \"\",\n To => Directory & \"/\" & Name);\n end if;" + }, + { + "function_def": "procedure Main is", + "function_body": "task type Sieve is\n entry Pass_On(Int: Integer);\n end Sieve;\n\n type Sieve_Ptr is access Sieve;\n\n function Get_New_Sieve return Sieve_Ptr is\n begin\n return new Sieve;\n end Get_New_Sieve;\n\n task Odd;\n task body Odd is\n Limit : constant Positive := 1000;\n Num: Positive;\n S: Sieve_Ptr := Get_New_Sieve;\n begin\n Num := 3;\n while Num < Limit loop\n S.Pass_On(Num);\n Num := Num + 2;\n end loop;\n end Odd;\n\n task body Sieve is\n New_Sieve : Sieve_Ptr;\n Prime, Num: Natural;\n begin\n accept Pass_On(Int : Integer) do\n Prime := Int;\n end Pass_On;\n Text_IO.Put(Prime'Img & \", \");\n -- Prime is a prime number, which coud be output\n loop\n accept Pass_On(Int : Integer) do\n Num := Int;\n end Pass_On;\n exit when Num rem Prime /= 0;\n end loop;\n\n New_Sieve := Get_New_Sieve;\n New_Sieve.Pass_On(Num);\n\n loop\n accept Pass_On (Int : Integer) do\n Num := Int;\n end Pass_On;\n if Num rem Prime /= 0 then\n New_Sieve.Pass_On(Num);\n end if;\n end loop;\n end Sieve;\n\nbegin\n null;" + }, + { + "function_def": "procedure Toggle_LedR is", + "function_body": "begin\n null;" + }, + { + "function_def": "procedure Toggle_LedL is", + "function_body": "begin\n null;" + }, + { + "function_def": "procedure Off_LedR is", + "function_body": "begin\n null;" + }, + { + "function_def": "procedure Off_LedL is", + "function_body": "begin\n null;" + }, + { + "function_def": "procedure Main is", + "function_body": "--pragma Priority(Priority'Last);\n\n Stop : Boolean := False;\n S: String(1..5) := (others => ASCII.NUL);\n --CMD : BControl.Command_Type := (1 => 'b', 2 => 'l', 3 => 's');\n CMD : BControl.Command_Type;\nbegin\n-- Init;\n-- Gio.Gio_Set_Direction(Reg_Het.hetPort1'Access, 16#FFFFFFFF#);\n\n loop\n --Control.Put_Line(\"Before Get_Line\");\n S := Control.Get_Line;\n Control.Put_Line(\"Got Data\");\n Control.Put_Line(S);\n --CMD := Bcontrol.Command_Type(S(1..3));\n CMD := BControl.Command_Type'Value(S(1..3));\n\n Bcontrol.Command.Send(CMD);\n end loop;\n\n\n -- Blinker_Control.Blink_Stop;" + }, + { + "function_def": "procedure Main is", + "function_body": "task type Blinker_Type is\n entry Start(S : String);\n entry Stop;\n end Blinker_Type;\n\n task Blinker_Control is\n entry Blink_Left;\n entry Blink_Right;\n entry Blink_Emergency;\n entry Blink_Stop;\n end Blinker_Control;\n\n Left_Blinker, Right_Blinker: Blinker_Type;\n\n task body Blinker_Control is\n Blinker_Left_Started : Boolean := False;\n Blinker_Right_Started : Boolean := False;\n begin\n loop\n select\n when not Blinker_Left_Started =>\n accept Blink_Left;\n Left_Blinker.Start(\"left \");\n Blinker_Left_Started := True;\n or\n when not Blinker_Right_Started =>\n accept Blink_Right;\n Right_Blinker.Start(\"right\");\n Blinker_Right_Started := True;\n or\n accept Blink_Emergency;\n Left_Blinker.Start(\"left \");\n Right_Blinker.Start(\"right\");\n Blinker_Left_Started := True;\n Blinker_Right_Started := True;\n\n or\n when Blinker_Left_Started or Blinker_Right_Started =>\n accept Blink_Stop;\n if Blinker_Left_Started then\n Left_Blinker.Stop;\n end if;\n if Blinker_Right_Started then\n Right_Blinker.Stop;\n end if;\n or\n terminate;\n end select;\n end loop;\n end Blinker_Control;\n\n\n task body Blinker_Type is\n Id : String(1..5);\n begin\n loop\n select\n accept Start(S : String) do\n Id := S;\n end Start;\n\n loop\n select\n accept Stop;\n exit;\n or\n delay 0.5;\n Text_Io.Put_Line(\"Blinker \" & Id & \" toggling\");\n end select;\n end loop;\n or terminate;\n end select;\n\n end loop;\n end Blinker_Type;\n\n\n\nbegin\n Blinker_Control.Blink_Left;\n delay 3.0;\n Blinker_Control.Blink_Stop;\n delay 3.0;\n Blinker_Control.Blink_Emergency;\n delay 3.0;\n Blinker_Control.Blink_Stop;" + }, + { + "function_def": "procedure LSP_Test is", + "function_body": "function \"+\" (Text : Wide_Wide_String)\n return League.Strings.Universal_String renames\n League.Strings.To_Universal_String;\n\n package Document_Maps is new Ada.Containers.Hashed_Maps\n (Key_Type => LSP.Messages.DocumentUri,\n Element_Type => LSP_Documents.Document,\n Hash => League.Strings.Hash,\n Equivalent_Keys => League.Strings.\"=\",\n \"=\" => LSP_Documents.\"=\");\n\n type Message_Handler (Server : access LSP.Servers.Server) is limited\n new LSP.Message_Handlers.Request_Handler\n and LSP.Message_Handlers.Notification_Handler with record\n Documents : Document_Maps.Map;\n Checker : Checkers.Checker;\n XRef : Cross_References.Database;\n end record;\n\n overriding procedure Initialize_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.InitializeParams;\n Response : in out LSP.Messages.Initialize_Response);\n\n overriding procedure Exit_Notification\n (Self : access Message_Handler);\n\n overriding procedure Text_Document_Definition_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.TextDocumentPositionParams;\n Response : in out LSP.Messages.Location_Response);\n\n overriding procedure Text_Document_Did_Open\n (Self : access Message_Handler;\n Value : LSP.Messages.DidOpenTextDocumentParams);\n\n overriding procedure Text_Document_Did_Change\n (Self : access Message_Handler;\n Value : LSP.Messages.DidChangeTextDocumentParams);\n\n overriding procedure Text_Document_Did_Close\n (Self : access Message_Handler;\n Value : LSP.Messages.DidCloseTextDocumentParams);\n\n overriding procedure Text_Document_Did_Save\n (Self : access Message_Handler;\n Value : LSP.Messages.DidSaveTextDocumentParams);\n\n overriding procedure Text_Document_Completion_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.TextDocumentPositionParams;\n Response : in out LSP.Messages.Completion_Response);\n\n overriding procedure Text_Document_Code_Action_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.CodeActionParams;\n Response : in out LSP.Messages.CodeAction_Response);\n\n overriding procedure Text_Document_Highlight_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.TextDocumentPositionParams;\n Response : in out LSP.Messages.Highlight_Response);\n\n overriding procedure Text_Document_Hover_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.TextDocumentPositionParams;\n Response : in out LSP.Messages.Hover_Response);\n\n overriding procedure Text_Document_References_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.ReferenceParams;\n Response : in out LSP.Messages.Location_Response);\n\n overriding procedure Text_Document_Signature_Help_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.TextDocumentPositionParams;\n Response : in out LSP.Messages.SignatureHelp_Response);\n\n overriding procedure Text_Document_Symbol_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.DocumentSymbolParams;\n Response : in out LSP.Messages.Symbol_Response);\n\n overriding procedure Workspace_Did_Change_Configuration\n (Self : access Message_Handler;\n Value : LSP.Messages.DidChangeConfigurationParams);\n\n overriding procedure Workspace_Execute_Command_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.ExecuteCommandParams;\n Response : in out LSP.Messages.ExecuteCommand_Response);\n\n overriding procedure Workspace_Symbol_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.WorkspaceSymbolParams;\n Response : in out LSP.Messages.Symbol_Response);\n\n ------------------------\n -- Initialize_Request --\n ------------------------\n\n overriding procedure Initialize_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.InitializeParams;\n Response : in out LSP.Messages.Initialize_Response)\n is\n use type LSP.Types.LSP_String;\n\n Completion_Characters : LSP.Types.LSP_String_Vector;\n Commands : LSP.Types.LSP_String_Vector;\n Signature_Keys : LSP.Types.LSP_String_Vector;\n begin\n Self.XRef.Initialize (Value.rootUri & \"/source/protocol/\");\n Completion_Characters.Append (+\"'\");\n Commands.Append (+\"Text_Edit\");\n Signature_Keys.Append (+\"(\");\n Signature_Keys.Append (+\",\");\n\n Response.result.capabilities.textDocumentSync :=\n (Is_Set => True, Is_Number => True, Value => LSP.Messages.Full);\n\n Response.result.capabilities.completionProvider :=\n (Is_Set => True, Value =>\n (resolveProvider => LSP.Types.Optional_False,\n triggerCharacters => Completion_Characters));\n\n Response.result.capabilities.codeActionProvider :=\n LSP.Types.Optional_True;\n\n Response.result.capabilities.executeCommandProvider :=\n (commands => Commands);\n\n Response.result.capabilities.hoverProvider := LSP.Types.Optional_True;\n Response.result.capabilities.signatureHelpProvider :=\n (True, (triggerCharacters => Signature_Keys));\n Response.result.capabilities.definitionProvider :=\n LSP.Types.Optional_True;\n Response.result.capabilities.referencesProvider :=\n LSP.Types.Optional_True;\n Response.result.capabilities.documentSymbolProvider :=\n LSP.Types.Optional_True;\n Response.result.capabilities.workspaceSymbolProvider :=\n LSP.Types.Optional_True;\n end Initialize_Request;\n\n ---------------------------------------\n -- Text_Document_Code_Action_Request --\n ---------------------------------------\n\n overriding procedure Text_Document_Code_Action_Request\n (Self : access Message_Handler;\n Value : LSP.Messages.CodeActionParams;\n Response : in out LSP.Messages.CodeAction_Response)\n is\n use type League.Strings.Universal_String;\n begin\n for Item of Value.context.diagnostics loop\n if Item.message = +\"missing \"\";\"\"\" then\n declare\n Edit : LSP.Messages.TextDocumentEdit;\n Command : LSP.Messages.Command;\n JS : aliased League.JSON.Streams.JSON_Stream;\n Insert : constant LSP.Messages.TextEdit :=\n (Value.span, +\";\");\n begin\n Edit.textDocument :=\n (Value.textDocument with\n version => Self.Documents (Value.textDocument.uri).Version);\n Edit.edits.Append (Insert);\n LSP.Messages.TextDocumentEdit'Write (JS'Access, Edit);\n Command.title := +\"Insert semicolon\";\n Command.command := +\"Text_Edit\";\n Command.arguments :=\n JS.Get_JSON_Document.To_JSON_Array.To_JSON_Value;\n Response.result.Append (Command);" + }, + { + "function_def": "procedure Initialize is", + "function_body": "JSON : constant League.JSON.Documents.JSON_Document :=\n League.JSON.Documents.From_JSON (Read_File (\"tests/wellknown.json\"));\n Attr_List : constant League.JSON.Arrays.JSON_Array :=\n JSON.To_JSON_Object.Value (+\"Attributes\").To_Array;\n Hover : constant League.JSON.Objects.JSON_Object :=\n JSON.To_JSON_Object.Value (+\"Hover\").To_Object;\n Hover_Keys : constant League.String_Vectors.Universal_String_Vector :=\n Hover.Keys;\n Sign : constant League.JSON.Objects.JSON_Object :=\n JSON.To_JSON_Object.Value (+\"Signatures\").To_Object;\n Sign_Keys : constant League.String_Vectors.Universal_String_Vector :=\n Sign.Keys;\n begin\n for J in 1 .. Attr_List.Length loop\n declare\n function \"-\" (Name : Wide_Wide_String) return LSP.Types.LSP_String;\n\n function \"-\" (Name : Wide_Wide_String)\n return LSP.Types.LSP_String is\n begin\n return Attr_List (J).To_Object.Value (+Name).To_String;\n end \"-\";\n\n Item : LSP.Messages.CompletionItem;\n begin\n Item.label := -\"label\";\n Item.detail := (True, -\"detail\");\n Item.documentation := (True, -\"documentation\");\n Item.sortText := (True, -\"sortText\");\n Item.filterText := (True, -\"filterText\");\n Item.insertText := (True, -\"insertText\");\n\n if Item.insertText.Value.Index ('$') > 0 then\n Item.insertTextFormat := (True, LSP.Messages.Snippet);\n end if;\n\n Attr.Append (Item);" + }, + { + "function_def": "overriding procedure Fill_Completion_List", + "function_body": "(Self : Completion_Handler;\n Context : Ada_LSP.Completions.Context'Class;\n Result : in out LSP.Messages.CompletionList)\n is\n use Incr.Parsers.Incremental.Parser_Data_Providers;\n-- use type Incr.Nodes.Node_Access;\n\n Provider : constant Ada_LSP.Ada_Parser_Data.Provider_Access :=\n Self.Context.Get_Parser_Data_Provider;\n Next_Action : constant Action_Table_Access := Provider.Actions;\n Next_State : constant State_Table_Access := Provider.States;\n State : Parser_State := 1;\n Token : constant Incr.Nodes.Tokens.Token_Access := Context.Token;\n Doc : constant Ada_LSP.Documents.Constant_Document_Access :=\n Context.Document;\n Start : constant Incr.Nodes.Node_Access :=\n Incr.Nodes.Node_Access (Doc.Start_Of_Stream);\n Now : constant Incr.Version_Trees.Version := Doc.History.Changing;\n List : Node_Lists.List;\n Subtree : Incr.Nodes.Node_Access := Token.Previous_Subtree (Now);\n begin\n while Subtree not in Start | null loop\n List.Prepend (Subtree);\n Subtree := Subtree.Previous_Subtree (Now);\n end loop;\n\n for Node of List loop\n State := Next_State (State, Node.Kind);\n end loop;\n\n for J in Incr.Nodes.Node_Kind'(1) .. 108 loop\n if Next_Action (State, J).Kind /= Error then\n declare\n Item : LSP.Messages.CompletionItem;\n begin\n Item.label := +Provider.Kind_Image (J);\n Item.kind := (True, LSP.Messages.Keyword);\n Result.items.Append (Item);" + }, + { + "function_def": "not overriding procedure Read_dynamicRegistration", + "function_body": "(S : access Ada.Streams.Root_Stream_Type'Class;\n V : out dynamicRegistration)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n JS.Start_Object;\n Read_Optional_Boolean\n (JS, +\"dynamicRegistration\", Optional_Boolean (V));\n JS.End_Object;\n end Read_dynamicRegistration;\n\n -------------------------------\n -- Read_ExecuteCommandParams --\n -------------------------------\n\n not overriding procedure Read_ExecuteCommandParams\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out ExecuteCommandParams)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n JS.Start_Object;\n Read_String (JS, +\"command\", V.command);\n JS.Key (+\"arguments\");\n V.arguments := JS.Read;\n JS.End_Object;\n end Read_ExecuteCommandParams;\n\n ---------------------------\n -- Read_InitializeParams --\n ---------------------------\n\n procedure Read_InitializeParams\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out InitializeParams)\n is\n use type League.Strings.Universal_String;\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n Trace : LSP.Types.Optional_String;\n begin\n JS.Start_Object;\n Read_Optional_Number (JS, +\"processId\", V.processId);\n Read_String (JS, +\"rootPath\", V.rootPath);\n Read_IRI (JS, +\"rootUri\", V.rootUri);\n JS.Key (+\"capabilities\");\n LSP.Messages.ClientCapabilities'Read (S, V.capabilities);\n Read_Optional_String (JS, +\"trace\", Trace);\n\n if not Trace.Is_Set then\n V.trace := LSP.Types.Unspecified;\n elsif Trace.Value = +\"off\" then\n V.trace := LSP.Types.Off;\n elsif Trace.Value = +\"messages\" then\n V.trace := LSP.Types.Messages;\n elsif Trace.Value = +\"verbose\" then\n V.trace := LSP.Types.Verbose;\n end if;\n\n JS.End_Object;\n end Read_InitializeParams;\n\n --------------------------\n -- Read_synchronization --\n --------------------------\n\n not overriding procedure Read_synchronization\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out synchronization)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n JS.Start_Object;\n Read_Optional_Boolean\n (JS, +\"dynamicRegistration\", V.dynamicRegistration);\n Read_Optional_Boolean (JS, +\"willSave\", V.willSave);\n Read_Optional_Boolean (JS, +\"willSaveWaitUntil\", V.willSaveWaitUntil);\n Read_Optional_Boolean (JS, +\"didSave\", V.didSave);\n JS.End_Object;\n end Read_synchronization;\n\n -----------------------------------------\n -- Read_TextDocumentClientCapabilities --\n -----------------------------------------\n\n not overriding procedure Read_TextDocumentClientCapabilities\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out TextDocumentClientCapabilities)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n JS.Start_Object;\n JS.Key (+\"synchronization\");\n synchronization'Read (S, V.synchronization);\n JS.Key (+\"completion\");\n completion'Read (S, V.completion);\n JS.Key (+\"hover\");\n dynamicRegistration'Read (S, V.hover);\n JS.Key (+\"signatureHelp\");\n dynamicRegistration'Read (S, V.signatureHelp);\n JS.Key (+\"references\");\n dynamicRegistration'Read (S, V.references);\n JS.Key (+\"documentHighlight\");\n dynamicRegistration'Read (S, V.documentHighlight);\n JS.Key (+\"documentSymbol\");\n dynamicRegistration'Read (S, V.documentSymbol);\n JS.Key (+\"formatting\");\n dynamicRegistration'Read (S, V.formatting);\n JS.Key (+\"rangeFormatting\");\n dynamicRegistration'Read (S, V.rangeFormatting);\n JS.Key (+\"onTypeFormatting\");\n dynamicRegistration'Read (S, V.onTypeFormatting);\n JS.Key (+\"definition\");\n dynamicRegistration'Read (S, V.definition);\n JS.Key (+\"codeAction\");\n dynamicRegistration'Read (S, V.codeAction);\n JS.Key (+\"codeLens\");\n dynamicRegistration'Read (S, V.codeLens);\n JS.Key (+\"documentLink\");\n dynamicRegistration'Read (S, V.documentLink);\n JS.Key (+\"rename\");\n dynamicRegistration'Read (S, V.rename);\n JS.End_Object;\n end Read_TextDocumentClientCapabilities;\n\n -----------------------------------------\n -- Read_TextDocumentContentChangeEvent --\n -----------------------------------------\n\n not overriding procedure Read_TextDocumentContentChangeEvent\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out TextDocumentContentChangeEvent)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n JS.Start_Object;\n JS.Key (+\"range\");\n Optional_Span'Read (S, V.span);\n Read_Optional_Number (JS, +\"rangeLength\", V.rangeLength);\n Read_String (JS, +\"text\", V.text);\n JS.End_Object;\n end Read_TextDocumentContentChangeEvent;\n\n ------------------------------------------------\n -- Read_TextDocumentContentChangeEvent_Vector --\n ------------------------------------------------\n\n not overriding procedure Read_TextDocumentContentChangeEvent_Vector\n (S : access Ada.Streams.Root_Stream_Type'Class;\n V : out TextDocumentContentChangeEvent_Vector)\n is\n JS : League.JSON.Streams.JSON_Stream'Class renames\n League.JSON.Streams.JSON_Stream'Class (S.all);\n begin\n V.Clear;\n JS.Start_Array;\n while not JS.End_Of_Array loop\n declare\n Item : TextDocumentContentChangeEvent;\n begin\n TextDocumentContentChangeEvent'Read (S, Item);\n V.Append (Item);" + }, + { + "function_def": "procedure Create_Filename is", + "function_body": "File : Stream_IO.File_Type;\n begin\n Ada.Text_IO.Put_Line (Source_Location & \":\" & Enclosing_Entity);\n Stream_IO.Create (File, Stream_IO.Out_File, Filename);\n Stream_IO.Close (File);\n end Create_Filename;\n\n overriding\n function End_Of_File (Resource : Pump_Stream) return Boolean is\n begin\n return not Resource.Is_Open;" + }, + { + "function_def": "procedure Create_Filename;", + "function_body": "Filename : constant String := \"dm_file.data\";\n URI : Services.Dispatchers.URI.Handler;\n Handler : Services.Dispatchers.Linker.Handler;\n Conf : Config.Object := Config.Get_Current;\n WS : Server.HTTP;\n type Pump_Stream is limited new AWS.Resources.Streams.Memory.Stream_Type with private;\n\n\n procedure Open (S : in out Pump_Stream);\n overriding\n function End_Of_File (Resource : Pump_Stream) return Boolean;\n\n overriding\n procedure Read\n (Resource : in out Pump_Stream;\n Buffer : out Stream_Element_Array;\n Last : out Stream_Element_Offset);\n\n overriding\n procedure Close (Resource : in out Pump_Stream);\n\n overriding\n procedure Reset (Resource : in out Pump_Stream) is null;\n\n overriding\n procedure Set_Index\n (Resource : in out Pump_Stream;\n To : Stream_Element_Offset) is null;\n\n\nprivate\n not overriding\n procedure Real_Read\n (Resource : in out Pump_Stream;\n Buffer : out Stream_Element_Array;\n Last : out Stream_Element_Offset);\n type Pump_Stream is limited new AWS.Resources.Streams.Memory.Stream_Type with record\n Is_Open : Boolean := False;\n end record;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E65 := E65 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E73 := E73 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E25 := E25 + 1;\n System.Exceptions'Elab_Spec;\n E27 := E27 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E21 := E21 + 1;\n E13 := E13 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E68 := E68 + 1;\n System.Os_Lib'Elab_Body;\n E78 := E78 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E06 := E06 + 1;\n Ada.Streams'Elab_Spec;\n E67 := E67 + 1;\n System.File_Control_Block'Elab_Spec;\n E81 := E81 + 1;\n System.Finalization_Root'Elab_Spec;\n E76 := E76 + 1;\n Ada.Finalization'Elab_Spec;\n E74 := E74 + 1;\n System.File_Io'Elab_Body;\n E73 := E73 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E65 := E65 + 1;\n Rasp_Code'Elab_Spec;\n E83 := E83 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure computus_test is", + "function_body": "NL : constant String := CR & LF ;\n Prompter : constant String := \"Type command and figure, or H for Help:\";\n Help_text : constant String :=\n \"This line mode program challenges the Milesian Easter computation method\"\n & NL & \"with standard Meeus methods.\" & NL &\n \"Copyright Louis-A. de Fouquieres, Miletus, 2015-2017.\" & NL &\n \"More at www.calendriermilesien.org.\" & NL &\n \"Syntax: .\" & NL &\n \" is one character as described hereunder.\" & NL &\n \" is an integer, the final year for the test.\" & NL &\n \"Tests begin with year 0 for both Julian and Gregorian algorithms, \" & NL &\n \"although there is no historical sense\" & NL &\n \"before around 525 (julian) or 1583 (gregorian).\" & NL &\n \"Result of Eater computation is Easter day rank, i.e. \" & NL &\n \"number of days after March 21st when Easter Sunday occurs.\" & NL &\n \"Available commands:\" & NL &\n \"S: Silent mode (by default), list discrepancies only.\" & NL &\n \"V: Verbose mode, report year per year results.\" & NL &\n \"J : test Julian calendar computus from 0 to .\" & NL &\n \"G .\" & NL &\n \"H: Help, display this text.\" & NL &\n \"X: Exit program.\";\n\n Command : Character := ' ';\n Verbose : Boolean := False;\n Level, D1, D2 : Natural := 0;\n\n Help_request, Command_error : exception;\n\n\nbegin\n Put (\"Copyright Louis-A. de Fouquieres, Miletus, 2015-2019, calendriermilesien.org\");\n New_Line;\n loop\n begin -- a block with exception handler\n Put (Prompter); New_Line;\n Get (Command);\n case Command is\n when 'X' => Put (\"Bye !\");\n when 'H' => Skip_Line; raise Help_request;\n when 'V' => Verbose := True; Put (\"Verbose mode on\");\n when 'S' => Verbose := False; Put (\"Verbose mode off\");\n when 'G' | 'J' =>\n Get (Level);\n Put(\"Calendar: \"); Put (Command);\n Put (\", final year: \"); Put (Level, 7);\n\n case Command is\n when 'G' =>\n For Year in 0 .. Level loop\n D1 := Butcher (Year); D2 := Easter_days (Year, Gregorian);\n if Verbose or D1 /= D2 then\n New_Line; Put (\"Year: \"); Put (Year);\n Put (\", Butcher: \"); Put (D1,2);\n Put (\", Milesian: \"); Put (D2,2);\n end if;\n end loop;\n when 'J' =>\n For Year in 0 .. Level loop\n D1 := Delambre (Year); D2 := Easter_days (Year, Julian);\n if Verbose or D1 /= D2 then\n New_Line; Put (\"Year: \"); Put (Year);\n Put (\", Delambre: \"); Put (D1,2);\n Put (\", Milesian: \"); Put (D2,2);\n end if;\n end loop;\n when others => raise Command_error;\n end case;\n New_Line; Put (\"== End comparison ==\");\n\n when others => raise Command_error;\n end case;\n exception\n when Help_request => Put (Help_text);\n when Command_error => Put (\" Invalid command !\"); Skip_Line;\n when others => Put (\" Unknown error !\"); Skip_Line;" + }, + { + "function_def": "procedure Milesian_converter is", + "function_body": "NL : constant String := CR & LF ;\n Licence_text : constant String :=\n \"Date converter and moon phase computer using the Milesian calendar.\" & NL &\n \"Written by Louis A. de Fouquieres, Miletus,\" & NL &\n \"Initial version M2015-09-30, actual version M2019-01-16.\" & NL &\n \"Generated with the GNAT Programming Studio GPL Edition 2014.\" & NL &\n \"No warranty of any kind arising from or in connection with this application.\"\n & NL & \"Library sources available on demand under GP licence.\"\n & NL & \"No commercial usage allowed - inquiries: www.calendriermilesien.org\";\n\n Prompter : constant String := \"Type command and figures, or H for Help:\";\n\n Help_text : constant String :=\n \"This line mode program converts dates from and to \"\n & NL &\n \"Julian day, Milesian, Gregorian, and Julian calendars.\" & NL &\n \"Mean Moon age, residue and lunar time are also computed, \" & NL &\n \"as well as yearly key figures.\"\n & NL &\n \"Syntax: <1 to 6 numbers separated with spaces>.\" & NL &\n \" is one character as described hereunder.\" & NL &\n \"Numbers are decimal possibly beginning with + or -, without spaces,\" & NL &\n \"with a dot (.) as decimal separator when applicable.\" & NL &\n \"When a date is expected, it must be entered as: year (-4800 to 9999),\"\n & NL &\n \"month number (1 to 12, by default: 1), day number (1 to 31, by default: 1),\"\n & NL &\n \"hours (0 to 23, default 12), minutes and seconds (default 0, max 59).\"\n & NL & \"Time of day is Terrestrial Time (64,184 s ahead of UTC in 2000).\"\n & NL &\n \"Lunar time is time of day where the mean Moon stands\" & NL &\n \"at the same azimuth than the mean Sun at this solar time.\" & NL &\n \"Yearly key figures ('Y' command) include\" & NL &\n \"- doomsday, i.e. day of the week that falls at same dates every year,\" & NL &\n \"- lunar figures at new year's eve at 7h30 UTC,\" & NL &\n \"- Milesian epact and yearly lunar residue, in half-integer,\" & NL &\n \"- spring full moon residue in integer value,\" & NL &\n \"- for years A.D., days between 21st March and Easter\"\n & NL &\n \"following the Gregorian and Julian Catholic ecclesiastical computus,\" & NL &\n \"and finally the delay, in days, of dates in Julian compared to Gregorian.\"\n & NL &\n \"Available commands:\" & NL &\n \"D : Julian day;\" & NL &\n \"G : Date in Gregorian calendar (even before 1582);\" & NL &\n \"J : Date in Julian calendar;\" & NL &\n \"M : Date in Milesian calendar;\" & NL &\n \"Y : Yearly key figures (see above);\"\n & NL &\n \"A [ [ []]]: Add days, hours, mins, secs\"\n & NL & \"to current date, each figure is a signed integer, 0 by default;\"\n & NL &\n \"H: display this text;\" & NL &\n \"L: display licence notice;\" & NL &\n \"X: exit program.\";\n\n Command : Character := ' ';\n Roman_calendar_type : Calendar_type := Unspecified;\n\n -- Duration to substract to Julian Day of first day of a year, in order\n -- to obtain time of \"doomsday\" at which the moon phase is computed.\n To_Doomsday_time_duration : constant Historical_Duration\n := 86_400.0 + 4*3600.0 + 30*60.0;\n\n -- To substract to Milesian epact to obtain a good estimate\n -- of Easter full moon residue\n To_Spring_Full_Moon : Constant := 12.52 * 86_400;\n\n This_year : Historical_year_number := 0;\n\n M_date: Milesian_date := (4, 12, -4713);\n R_date : Roman_date := (1, 1, -4712);\n This_Julian_day: Julian_day := 0; -- in integer days\n This_historical_time: Historical_Time := 0.0; -- in seconds\n Displayed_time: Fractional_day_duration := 0.0; -- in fractional days\n This_hour : Hour_Number := 12;\n This_minute : Minute_Number := 0;\n This_second : Second_Number :=0;\n\n Day_time : Day_Duration := 0.0;\n Julian_hour : Day_Historical_Duration := 0.0;\n\n Day_Number_in_Week : Integer range 0..6;\n\n Moon_time, Moon_time_shift : H24_Historical_Duration;\n Moon_hour : Hour_Number;\n Moon_minute: Minute_Number;\n Moon_second: Second_Number;\n Moon_subsecond: Second_Duration;\n\n Help_request, Licence_request : Exception;\n\nbegin\n Put (Licence_text); New_Line;\n loop\n begin -- a block with exception handler\n Put (Prompter); New_Line;\n Get (Command);\n case Command is\n when 'H' => Skip_Line; raise Help_request;\n when 'L' => Skip_Line; raise Licence_request;\n when 'D' =>\n --Get section\n Get (Displayed_time); Skip_Line;\n -- Conversion section\n This_historical_time := Convert_from_julian_day (Displayed_time);\n This_Julian_day := Julian_Day_Of (This_historical_time);\n M_date := jd_to_milesian (This_Julian_day);\n Julian_hour := This_historical_time - Julian_Duration_Of (This_Julian_day);\n Day_time := Day_Offset (Julian_hour);\n This_hour := Integer (Day_time) / 3600;\n This_minute := Integer (Day_time) / 60 - This_hour*60;\n This_second := Integer (Day_time) - This_hour*3600 - This_minute*60;\n\n when 'G' | 'J' =>\n -- Get section.\n case Command is\n when 'G' => Roman_calendar_type := Gregorian;\n when 'J' => Roman_calendar_type := Julian;\n when others => Roman_calendar_type := Unspecified;\n end case;\n R_date := (1, 1, -4712);\n This_hour := 12; This_minute := 0; This_second := 0;\n Get (R_date.year);\n if not End_Of_Line then Get (R_date.month); end if;\n if not End_Of_Line then Get (R_date.day); end if;\n if not End_Of_Line then Get (This_hour); end if;\n if not End_Of_Line then Get (This_minute); end if;\n if not End_Of_Line then Get (This_second); end if;\n Skip_Line;\n -- Conversion section;\n This_Julian_day := Roman_to_JD (R_date, Roman_calendar_type);\n -- This function raises Time_Error if date is improper\n Day_time := 3600.0 * This_hour + 60.0 * This_minute + 1.0 * This_second;\n This_historical_time := Julian_Duration_Of (This_Julian_day) + Day_Julian_Offset (Day_time);\n Displayed_time := Fractionnal_day_of (This_historical_time);\n M_date := JD_to_Milesian (This_Julian_day);\n\n when 'M' =>\n M_Date := (1, 1, -4712);\n This_hour := 12; This_minute := 0; This_second := 0;\n Get (M_date.year);\n if not End_Of_Line then Get (M_date.month); end if;\n if not End_Of_Line then Get (M_date.day); end if;\n if not End_Of_Line then Get (This_hour); end if;\n if not End_Of_Line then Get (This_minute); end if;\n if not End_Of_Line then Get (This_second); end if;\n Skip_Line;\n -- Conversion section;\n This_Julian_day := Milesian_to_JD (M_date);\n -- This function raises Time_Error if date is improper\n Day_time := 3600.0 * This_hour + 60.0 * This_minute + 1.0 * This_second;\n This_historical_time := Julian_Duration_Of (This_Julian_day) + Day_Julian_Offset (Day_time);\n Displayed_time := Fractionnal_day_of (This_historical_time);\n M_date := JD_to_Milesian (This_Julian_day);\n\n when 'Y' =>\n M_Date := (1, 1, -4712);\n This_hour := 12; This_minute := 0; This_second := 0;\n Get (This_year); M_date.year := This_year;\n Skip_Line;\n -- Conversion section: compute \"doomsday\"\n This_Julian_day := Milesian_to_JD (M_date);\n -- Set to \"doomsday\"\n Day_time := 3600.0 * This_hour + 60.0 * This_minute + 1.0 * This_second;\n This_historical_time := Julian_Duration_Of (This_Julian_day)\n + Day_Julian_Offset (Day_time)\n - To_Doomsday_time_duration;\n This_Julian_day := Julian_Day_Of (This_historical_time);\n M_date := jd_to_milesian (This_Julian_day);\n Displayed_time := Fractionnal_day_of (This_historical_time);\n\n when 'A' =>\n declare\n Days : Julian_Day_Duration := 0;\n Hour_Offset, Minute_Offset, Second_Offset : Integer := 0;\n Julian_Time_Offset : Historical_Duration := 0.0;\n\n begin\n -- Get section\n Get (Days);\n if not End_Of_Line then Get (Hour_Offset); end if;\n if not End_Of_Line then Get (Minute_Offset); end if;\n if not End_Of_Line then Get (Second_Offset); end if;\n Skip_Line;\n -- Conversion section\n Julian_Time_Offset := Julian_Duration_Of\n (3600.0 * Hour_Offset\n + 60.0 * Minute_Offset\n + 1.0 * Second_Offset);\n This_historical_time :=\n This_historical_time + Julian_Duration_Of (Days) + Julian_Time_Offset ;\n This_Julian_day := Julian_Day_Of (This_historical_time);\n M_date := jd_to_milesian (This_Julian_day);\n Julian_hour := This_historical_time - Julian_Duration_Of (This_Julian_day);\n Displayed_time := Fractionnal_day_of (This_historical_time);\n begin\n Day_time := Day_Offset (Julian_hour);\n exception\n when Constraint_Error =>\n Put(\"Day time out of bounds - correcting\"); New_Line;\n Day_time := 86_399.88;\n -- avoids out of bounds." + }, + { + "function_def": "procedure match is", + "function_body": "type Edge_Record is record\n id : Natural;\n conf : Configuration;\n end record;\n\n package Edge_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => Line_Value,\n Element_Type => Edge_Record,\n Hash => line_hash,\n Equivalent_Keys => \"=\");\n use Edge_Maps;\n\n edge_map : Edge_Maps.Map := Edge_Maps.Empty_Map;\n begin\n for c in tiles.Iterate loop\n declare\n t : Tile := tiles(c);\n es : constant Edge_Sets.Set := get_edges(t.id);\n begin\n for val of es loop\n if edge_map.contains(val) then\n declare\n matched_edge : constant Edge_Record := edge_map(val);\n matched_tile : Tile := tiles(matched_edge.id);\n begin\n matched_tile.neighbors.include(t.id); \n tiles(matched_tile.id) := matched_tile;\n t.neighbors.include(matched_tile.id);\n tiles(c) := t;" + }, + { + "function_def": "procedure rotate_complete_image is", + "function_body": "max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;\n new_image : Complete_Image_Sets.Set := Complete_Image_Sets.Empty_Set;\n begin\n for pixel of complete_image loop\n new_image.insert(Position'(x=>pixel.y, y=>max-pixel.x));\n end loop;\n complete_image := new_image;\n end rotate_complete_image;\n\n procedure flip_complete_image is\n max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;\n new_image : Complete_Image_Sets.Set := Complete_Image_Sets.Empty_Set;\n begin\n for pixel of complete_image loop\n new_image.insert(Position'(x=>max-pixel.x, y=>pixel.y));\n end loop;\n complete_image := new_image;\n end flip_complete_image;\n\n pragma Warnings (Off, \"procedure \"\"put_line\"\" is not referenced\");\n procedure put_line(i : in Complete_Image_Sets.Set) is\n pragma Warnings (On, \"procedure \"\"put_line\"\" is not referenced\");\n max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;\n begin\n for y in 0..max loop\n for x in 0..max loop\n if i.contains(Position'(x=>x, y=>y)) then\n TIO.put(\"#\");\n else\n TIO.put(\".\");\n end if;\n end loop;\n TIO.new_line;\n end loop;\n end put_line;\n\n function dragon_pixel(x, y : in Natural) return Boolean is\n begin\n return complete_image.contains(Position'(x=>x, y=>y));\n end dragon_pixel;\n\n function dragon_start(x, y : in Natural) return Boolean is\n begin\n return\n dragon_pixel(x+0, y+1) and then\n dragon_pixel(x+1, y+2) and then\n dragon_pixel(x+4, y+2) and then\n dragon_pixel(x+5, y+1) and then\n dragon_pixel(x+6, y+1) and then\n dragon_pixel(x+7, y+2) and then\n dragon_pixel(x+10, y+2) and then\n dragon_pixel(x+11, y+1) and then\n dragon_pixel(x+12, y+1) and then\n dragon_pixel(x+13, y+2) and then\n dragon_pixel(x+16, y+2) and then\n dragon_pixel(x+17, y+1) and then\n dragon_pixel(x+18, y+0) and then\n dragon_pixel(x+18, y+1) and then\n dragon_pixel(x+19, y+1);\n end dragon_start;\n\n function count_dragon_pixels return Natural is\n max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;\n cnt : Natural := 0;\n begin\n for rot in 0..3 loop\n for y in 0..max loop\n for x in 0..max loop\n if dragon_start(x, y) then\n cnt := cnt + 1;\n end if;\n end loop;\n end loop;\n TIO.put_line(\"Found dragons: \" & cnt'IMAGE);\n if cnt /= 0 then\n return cnt * 15;\n end if;\n TIO.put_line(\"Rotating...\");\n rotate_complete_image;\n end loop;\n TIO.put_line(\"Flipping...\");\n flip_complete_image;\n return count_dragon_pixels;\n end count_dragon_pixels;\n\n procedure layout is\n type Candidate is record\n id : Natural;\n orientation : Configuration;\n left, right, up, down : Natural;\n end record;\n\n package Natural_Vectors is new Ada.Containers.Vectors\n (Index_Type => Natural,\n Element_Type => Natural);\n use Natural_Vectors;\n\n package Candidate_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => Natural,\n Element_Type => Candidate,\n Hash => id_hash,\n Equivalent_Keys => \"=\");\n use Candidate_Maps;\n\n function update_neighbor_links(id : in Natural; state : in out Candidate_Maps.Map) return Boolean is\n c : Candidate := state(id);\n es : constant Edge_Array := edges(c.id, c.orientation);\n t : constant Tile := tiles(c.id);\n begin\n for n of t.neighbors loop\n if state.contains(n) then\n declare\n neigh_cand : Candidate := state(n);\n neigh_es : constant Edge_Array := edges(neigh_cand.id, neigh_cand.orientation);\n begin\n if es(0) = neigh_es(2) then\n c.up := neigh_cand.id;\n neigh_cand.down := id;\n elsif es(1) = neigh_es(3) then\n c.right := neigh_cand.id;\n neigh_cand.left := id;\n elsif es(2) = neigh_es(0) then\n c.down := neigh_cand.id;\n neigh_cand.up := id;\n elsif es(3) = neigh_es(1) then\n c.left := neigh_cand.id;\n neigh_cand.right := id;\n else\n return false;\n end if;\n\n state(c.id) := c;\n state(neigh_cand.id) := neigh_cand;" + }, + { + "function_def": "procedure flatten_allergens is", + "function_body": "s : String_Sets.Set;\n begin\n for c in allergen_ingredients.Iterate loop\n s.clear;\n for v of allergen_ingredients(c) loop\n s := s or v;\n end loop;\n allergens.insert(key(c), s);\n end loop;\n end flatten_allergens;\n\n function all_length_one return Boolean is\n begin\n for c in allergens.iterate loop\n if allergens(c).length /= 1 then\n return false;\n end if;\n end loop;\n return true;\n end all_length_one;\n\n function all_singles return String_Sets.Set is\n s : String_Sets.Set := String_Sets.Empty_Set;\n begin\n for c in allergens.iterate loop\n if allergens(c).length = 1 then\n s.include(allergens(c).first_element);\n end if;\n end loop;\n return s;\n end all_singles;\n\n procedure reduce_allergens is\n begin\n loop\n if all_length_one then\n exit;\n end if;\n declare\n singles : constant String_Sets.Set := all_singles;\n begin\n if singles.is_empty then\n TIO.put_line(\"No single element sets!\");\n exit;\n end if;\n for k of allergen_keys loop\n if allergens(to_string(k)).length > 1 then\n allergens(to_string(k)) := allergens(to_string(k)) - singles;\n end if;\n end loop;" + }, + { + "function_def": "procedure Test_Create_Decoder is", + "function_body": "Decoder_Mono_8_kHz : Decoder_Data;\n begin\n Decoder_Mono_8_kHz := Create (Rate_8_kHz, Mono);\n Assert (Get_Sample_Rate (Decoder_Mono_8_kHz) = Rate_8_kHz, Unexpected_Sampling_Rate_Message);\n end Test_Create_Decoder;\n\n procedure Test_Destroy_Decoder is\n Decoder : constant Decoder_Data := Create (Rate_8_kHz, Mono);\n begin\n Destroy (Decoder);\n end Test_Destroy_Decoder;\n\n procedure Test_Reset_State is\n Decoder : constant Decoder_Data := Create (Rate_8_kHz, Stereo);\n begin\n Reset_State (Decoder);\n end Test_Reset_State;\n\n procedure Test_Default_Configuration is\n Decoder : constant Decoder_Data := Create (Rate_8_kHz, Mono);\n begin\n Assert (Get_Sample_Rate (Decoder) = Rate_8_kHz, Unexpected_Configuration_Message);\n Assert (Get_Channels (Decoder) = Mono, Unexpected_Configuration_Message);\n Assert (Get_Pitch (Decoder) = 0, Unexpected_Configuration_Message);\n Assert (Get_Gain (Decoder) = 0, Unexpected_Configuration_Message);\n Assert (Get_Last_Packet_Duration (Decoder) = 0, Unexpected_Configuration_Message);\n\n declare\n Unused_Result : Bandwidth;\n begin\n Unused_Result := Get_Bandwidth (Decoder);\n Fail (Expected_No_Packets_Decoded_Message);\n exception\n when No_Packets_Decoded =>\n null;" + }, + { + "function_def": "procedure Chess_Main is", + "function_body": "use type Common_Types.Colour_Type;\n \nbegin\n \n Game.Initialize (Game_Board => Board.Make);\n \n while not Game.Is_Game_Over loop\n \n Game.Get_Board.Print;\n \n declare\n The_Move : constant Move.Object := Move.Get_Move (Game.Get_Turn);\n begin\n The_Move.Perform_Move;" + }, + { + "function_def": "procedure Dg_Loada is", + "function_body": "SemVer : constant String := \"1.4.3\"; -- TODO Update SemVer on each release\n\n Dump_File_Name : Unbounded_String;\n Extracting : Boolean := False;\n Ignoring_Errors : Boolean := False;\n Listing : Boolean := False;\n Summary : Boolean := True;\n Verbose : Boolean := False;\n\n ArgIx : Integer := 1;\n Dump_File : File_Type;\n Dump_File_Stream : Stream_Access;\n Write_File : File_Type;\n\n -- dump images can legally contain 'too many' directory pops, so we\n -- store the starting directory and never traverse above it...\n Base_Dir : constant String := Current_Directory;\n Working_Dir : Unbounded_String := To_Unbounded_String (Base_Dir);\n\n Buffer : array (1 .. MaxBlockSize) of Unsigned_8;\n FSB_Type_Indicator : Integer;\n Current_File_Name : Unbounded_String;\n\n SOD : SOD_Type;\n Record_Header : Record_Header_Type;\n Total_File_Size, Padding_Size : Unsigned_32 := 0;\n Done, In_A_File, Load_It : Boolean := False;\n File_Count : Natural := 0;\n\n Cannot_Create_Link : exception;\n\n function symlink (fname, linkname : String) return Integer;\n pragma Import (C, symlink);\n\n procedure Print_Help is\n begin\n Ada.Text_IO.Put_Line (\"Usage of dg_loada:\");\n Ada.Text_IO.Put_Line (\" -dumpfile DUMP_II or DUMP_III file to read/load (required)\");\n Ada.Text_IO.Put_Line (\" -extract extract the files from the DUMP_II/III into the current directory\");\n Ada.Text_IO.Put_Line (\" -ignoreErrors do not exit if a file or link cannot be created\");\n Ada.Text_IO.Put_Line (\" -list list the contents of the DUMP_II/III file\");\n Ada.Text_IO.Put_Line (\" -summary concise summary of the DUMP_II/III file contents (default true)\");\n Ada.Text_IO.Put_Line (\" -verbose be rather wordy about what dg_loada is doing\");\n Ada.Text_IO.Put_Line (\" -version show the version number of dg_loada and exit\");\n\n Set_Exit_Status (Failure);\n end Print_Help;\n\n procedure Load_Buffer (Num_Bytes : Integer; Reason : String)\n is\n Tmp_Blob : Blob_Type (1 .. Num_Bytes);\n begin\n Tmp_Blob := Read_Blob (Num_Bytes, Dump_File_Stream, Reason);\n for B in 1 .. Num_Bytes loop\n Buffer (B) := Tmp_Blob (B);\n end loop;\n end Load_Buffer;\n\n function Process_Name_Block (Record_Header : Record_Header_Type) return Unbounded_String\n is\n Name_Bytes : Blob_Type (1 .. Record_Header.Record_Length);\n File_Name, Write_Path, Display_Path : Unbounded_String;\n This_Entry_Type : Fstat_Entry_Rec;\n begin\n Name_Bytes :=\n Read_Blob (Record_Header.Record_Length, Dump_File_Stream, \"File Name\");\n File_Name := Extract_First_String (Name_Bytes);\n File_Name := To_Linux_Filename (File_Name);\n if Summary and Verbose then\n Ada.Text_IO.Put_Line (\"\");\n end if;\n This_Entry_Type := Known_Fstat_Entry_Types (FSB_Type_Indicator);\n\n Load_It := This_Entry_Type.Has_Payload;\n if This_Entry_Type.Is_Dir then\n Working_Dir := Working_Dir & \"/\" & File_Name;\n if Extracting then\n Create_Directory (To_String (Working_Dir));\n end if;\n end if;\n\n if Listing then\n if Working_Dir = \"\" then\n Display_Path := File_Name;\n else\n Display_Path := Working_Dir & \"/\" & File_Name;\n end if;\n Ada.Text_IO.Put\n (To_String (This_Entry_Type.Desc) & \" \" &\n To_String (Display_Path));\n if Verbose or else This_Entry_Type.Is_Dir then\n Ada.Text_IO.Put_Line (\"\");\n else\n Ada.Text_IO.Put (\" \");\n end if;\n end if;\n\n File_Count := File_Count + 1;\n\n if Extracting and Load_It then\n if Working_Dir = \"\" then\n Write_Path := File_Name;\n else\n Write_Path := Working_Dir & \"/\" & File_Name;\n end if;\n if Verbose then\n Ada.Text_IO.Put_Line (\" Creating file: \" & To_String (Write_Path));\n end if;\n Create (Write_File, Out_File, To_String (Write_Path));\n -- Ada.Text_IO.Put_Line (\"DEBUG: Output file created\" );\n end if;\n\n return File_Name;\n end Process_Name_Block;\n\n procedure Process_Data_Block is\n DHB : Data_Header_Type;\n FourBytes : Blob_Type (1 .. 4);\n TwoBytes : Blob_Type (1 .. 2);\n begin\n -- first get the address and length\n FourBytes := Read_Blob (4, Dump_File_Stream, \"Byte Addr\");\n DHB.Byte_Address := Unsigned_32 (FourBytes (1));\n DHB.Byte_Address :=\n Shift_Left (DHB.Byte_Address, 8) + Unsigned_32 (FourBytes (2));\n DHB.Byte_Address :=\n Shift_Left (DHB.Byte_Address, 8) + Unsigned_32 (FourBytes (3));\n DHB.Byte_Address :=\n Shift_Left (DHB.Byte_Address, 8) + Unsigned_32 (FourBytes (4));\n\n FourBytes := Read_Blob (4, Dump_File_Stream, \"Byte Length\");\n DHB.Byte_Length := Unsigned_32 (FourBytes (1));\n DHB.Byte_Length :=\n Shift_Left (DHB.Byte_Length, 8) + Unsigned_32 (FourBytes (2));\n DHB.Byte_Length :=\n Shift_Left (DHB.Byte_Length, 8) + Unsigned_32 (FourBytes (3));\n DHB.Byte_Length :=\n Shift_Left (DHB.Byte_Length, 8) + Unsigned_32 (FourBytes (4));\n\n if DHB.Byte_Length > Unsigned_32 (MaxBlockSize) then\n Ada.Text_IO.Put_Line\n (Ada.Text_IO.Standard_Error,\n \"ERROR: Maximum Block Size Exceeded.\");\n Set_Exit_Status (Failure);\n Abort_Task (Current_Task);\n end if;\n\n if Verbose then\n Ada.Text_IO.Put_Line\n (\" Data block: \" & Unsigned_32'Image (DHB.Byte_Length) &\n \" (bytes)\");\n end if;\n\n TwoBytes := Read_Blob (2, Dump_File_Stream, \"Alignment Count\");\n DHB.Alighnment_Count := Unsigned_16 (TwoBytes (1));\n DHB.Alighnment_Count :=\n Shift_Left (DHB.Alighnment_Count, 8) + Unsigned_16 (TwoBytes (2));\n\n -- skip any alignment bytes - usually just one\n if DHB.Alighnment_Count /= 0 then\n if Verbose then\n Ada.Text_IO.Put_Line\n (\" Skipping \" & Unsigned_16'Image (DHB.Alighnment_Count) &\n \" alignment byte(s)\");\n end if;\n declare\n Dummy_Blob : Blob_Type (1 .. Integer (DHB.Alighnment_Count));\n begin\n Dummy_Blob := Read_Blob (Integer (DHB.Alighnment_Count), Dump_File_Stream, \"Alignment\");" + }, + { + "function_def": "procedure Process_End_Block is", + "function_body": "begin\n if Is_Open (Write_File) then\n Close (Write_File);\n if Verbose then\n Ada.Text_IO.Put_Line (\" File Closed\");\n end if;\n end if;\n if In_A_File then\n if Listing then\n Ada.Text_IO.Put_Line (\" \" & Unsigned_32'Image (Total_File_Size) & \" bytes\");\n end if;\n Total_File_Size := 0;\n In_A_File := False;\n else\n if Working_Dir /= Base_Dir then -- Don't go up from start dir\n declare lastSlash : constant Natural := Ada.Strings.Unbounded.Index (Working_Dir, \"/\", Ada.Strings.Backward);\n begin\n Working_Dir := Head (Working_Dir, lastSlash - 1);" + }, + { + "function_def": "procedure Ada_Split is", + "function_body": "src : File_Type;\n\n max_recurse_depth : Constant := 10;\n recurse_depth : Integer := 0;\n\n src_file_name : String := read_command_arg ('i',\"\");\n out_file_name : String := read_command_arg ('o',\"\");\n\n type tag_type is (beg_tag, end_tag, neither);\n\n function Path_Exists (the_path_name : string) return boolean renames Ada.Directories.Exists;\n function File_Exists (the_file_name : string) return boolean renames Ada.Directories.Exists;\n\n procedure write_file\n (parent : String; -- \" -- beg03: foo/bah/cat.tex\"\n child : String) -- \" --- beg04: foo/bah/moo/cow/dog.tex\"\n is\n\n re_beg_tag : String := \"^[\\t ]*(--|#|%) beg[0-9]{2}:\";\n re_end_tag : String := \"^[\\t ]*(--|#|%) end[0-9]{2}:\";\n\n function full_dir (text : String) return String is -- text := \" -- beg01: ./foo/bah/cat.tex\"\n re_dirname : String := \"([_a-zA-Z0-9./-]*\\/)\"; -- as per dirname in bash\n begin\n return grep (text,re_dirname,1,fail => \"\"); -- returns \"./foo/bah/\"\n end full_dir;\n\n function full_file (text : String) return String is -- text := \" -- beg01: ./foo/bah/cat.tex\"\n re_file : String := re_beg_tag & \" (.+)\";\n begin\n return grep (text,re_file,2,fail => \"\"); -- returns \"./foo/bah/cat.tex\"\n end full_file;\n\n function relative_path\n (parent : String; -- \" -- beg03: foo/bah/cat.tex\"\n child : String) -- \" -- beg04: foo/bah/moo/cow/dog.tex\"\n Return String -- relative path of the child to the parent, e.g., \"moo/cow/dog.tex\"\n is\n re_dirname : String := \"([_a-zA-Z0-9./-]*\\/)\"; -- as per dirname in bash\n re_basename : String := re_beg_tag & \" \" &re_dirname & \"(.+)\"; -- as per basename in bash\n parent_dir : String := trim ( grep (parent,re_dirname,1,fail => \"./\") ); -- \"foo/bah/\"\n child_dir : String := trim ( grep (child,re_dirname,1,fail => \"./\") ); -- \"foo/bah/moo/cow/\"\n child_file : String := trim ( grep (child,re_basename,3,fail => \"??.txt\") ); -- \"dog.tex\"\n begin\n -- strip parent_directory from front of child\n return trim ( child_dir(child_dir'first+get_strlen(parent_dir)..child_dir'last)&str(child_file) ); -- \"moo/cow/dog.tex\"\n end relative_path;\n\n function absolute_indent (text : String) return Integer is\n indent : Integer;\n begin\n indent := 0;\n for i in text'Range loop\n if text (i) /= ' ' then\n indent := max(0,i-1);\n exit;\n end if;\n end loop;\n return indent;\n end absolute_indent;\n\n function relative_indent\n (parent : String;\n child : String)\n Return Integer\n is\n begin\n return absolute_indent(child) - absolute_indent(parent);\n end relative_indent;\n\n function classify (the_line : String) return tag_type is\n begin\n if grep (the_line,re_beg_tag) then return beg_tag;\n elsif grep (the_line,re_end_tag) then return end_tag;\n else return neither;\n end if;\n end classify;\n\n begin\n\n recurse_depth := recurse_depth + 1;\n\n if recurse_depth > max_recurse_depth then\n Put_Line (\"> split-mrg: Recursion limit reached (max = \"&str(max_recurse_depth)&\"), exit\");\n halt(1);\n end if;\n\n declare\n txt : File_Type;\n the_dir : String := full_dir (child);\n the_file : String := full_file (child);\n the_path : String := relative_path (parent, child);\n the_indent : Integer := absolute_indent (child);\n\n procedure write_path (parent : String; child : String) is\n the_path : String := relative_path (parent, child);\n the_indent : Integer := relative_indent (parent, child);\n begin\n put_line (txt,spc(the_indent)&\"$Input{\"\"\"&the_path&\"\"\"}\");\n end write_path;\n\n procedure write_line (the_line : String; the_indent : Integer) is\n begin\n if the_indent > get_strlen(the_line)\n then put_line (txt, str(the_line));\n else put_line (txt, str(the_line(the_indent+1..the_line'last)));\n end if;\n end write_line;\n\n begin\n\n if not Path_Exists (the_dir) then\n Ada.Directories.Create_Path (the_dir);\n end if;\n\n if File_Exists (the_file)\n then Open (txt, out_file, the_file);\n else Create (txt, out_file, the_file);\n end if;\n\n loop\n begin\n declare\n the_line : String := Get_Line (src);\n begin\n case classify (the_line) is\n when beg_tag => write_path (child, the_line);\n write_file (child, the_line);\n when end_tag => exit;\n when others => write_line (the_line, the_indent);\n end case;" + }, + { + "function_def": "procedure cdb2ada is", + "function_body": "target_line_length : constant := 256;\n\n src_file_name : String := read_command_arg ('i',\"foo.c\");\n txt_file_name : String := read_command_arg ('o',\"foo.ad\");\n procedure_name : String := read_command_arg ('n',\"foo\");\n\n symbol : Character := read_command_arg ('s','t'); -- the 'x' in vars like x0123 or\n -- the 't' in t321\n\n -----------------------------------------------------------------------------\n\n procedure rewrite_cdb is\n txt : File_Type;\n src : File_Type;\n start_line : Boolean;\n finished : Boolean;\n this_lead_in : Integer;\n break_at : integer;\n found_at : integer;\n found : Boolean;\n beg_at : integer;\n end_at : integer;\n var_beg : integer;\n var_end : integer;\n rhs_beg : integer;\n rhs_end : integer;\n tail_beg : integer;\n tail_end : integer;\n max_xvars_width : Integer;\n\n procedure write_procedure_begin is\n re_name : String := \"([a-zA-Z0-9_-]+)\";\n the_name : String := grep (procedure_name, re_name, 1, fail => \"no_name\");\n begin\n\n for i in the_name'range loop\n if the_name (i) = '-' then\n the_name (i) := '_';\n end if;\n end loop;\n\n Put_Line (txt, \"Procedure \"&the_name&\" is\");\n\n end write_procedure_begin;\n\n procedure write_procedure_end is\n re_name : String := \"([a-zA-Z0-9_-]+)\";\n the_name : String := grep (procedure_name, re_name, 1, fail => \"no_name\");\n begin\n\n for i in the_name'range loop\n if the_name (i) = '-' then\n the_name (i) := '_';\n end if;\n end loop;\n\n Put_Line (txt, \"end \"&the_name&\";\");\n\n end write_procedure_end;\n\n procedure add_declarations is\n\n src : File_Type;\n count : integer;\n max_count : integer;\n width : integer;\n target : integer;\n lead_in : integer;\n num_chars : integer;\n tmp_xvars : Integer;\n num_xvars : Integer;\n max_width : Integer;\n\n type action_list is (wrote_xvar, wrote_type, wrote_space);\n last_action : action_list;\n\n begin\n\n -- first pass: count the number of xvars and record max width\n\n Open (src, In_File, src_file_name);\n\n num_xvars := 0; -- number of xvars\n max_width := 0; -- maximum widt of the xvars\n\n loop\n begin\n declare\n re_numb : String := \"^ *\"&symbol&\"([0-9]+) +=\";\n this_line : String := get_line (src);\n this_numb : String := grep (this_line, re_numb, 1, fail => \"\");\n begin\n if this_numb /= \"\" then\n num_xvars := num_xvars + 1;\n max_width := max (max_width, this_numb'length);\n end if;" + }, + { + "function_def": "procedure Ada_Merge is", + "function_body": "txt : File_Type;\n\n max_recurse_depth : Constant := 10;\n recurse_depth : Integer := 0;\n\n src_file_name : String := read_command_arg ('i',\"\");\n out_file_name : String := read_command_arg ('o',\"\");\n\n silent : Boolean := find_command_arg ('S'); -- true: do not wrap include text in beg/end pairs\n markup : Boolean := not silent; -- true: do wrap include text in beg/end pairs\n\n function File_Exists (the_file_name : string) return boolean renames Ada.Directories.Exists;\n\n procedure include_files\n (prev_path : String;\n this_line : String;\n prev_indent : Integer)\n is\n\n -- allow simple variations of the Input syntax:\n -- \\Input for TeX, use \\Input to avoid confusion with \\input\n -- $Input for Ada/Python/Cadabra\n -- note that this is only for convenience, the comment string will be deduced\n -- from the file extension of the Input'ed file\n re_inc_file : String := \"^[\\t ]*(\\\\|\\$)Input\\{\"\"([_a-zA-Z0-9./-]+)\"\"\\}\";\n\n -- this function is not used\n function not_tex_comment\n (the_line : String)\n return Boolean\n is\n re_tex_comment : String := \"^\\s*%\";\n begin\n return (not grep (the_line, re_tex_comment));\n end not_tex_comment;\n\n function is_include_file\n (the_line : String)\n Return Boolean\n is\n begin\n return grep (the_line,re_inc_file);\n end is_include_file;\n\n function absolute_path\n (the_path : String; -- full path to most recent include file, e.g. foo/bah/cow.tex\n the_line : String) -- contains relative path to new include file, e.g., \\Input{\"cat/dot/fly.tex\"}\n Return String -- full path to new include file, e.g., foo/bah/cat/dog/fly.tex\n is\n re_dirname : String := \"([_a-zA-Z0-9./-]*\\/)\"; -- as per dirname in bash\n tmp_path : String (1..the_path'last+the_line'last); -- overestimate length of string\n new_path : String (1..the_path'last+the_line'last);\n begin\n -- drop the simple file name from the existing path\n writestr (tmp_path, trim ( grep (the_path,re_dirname,1,fail => \"\") ));\n -- append new file path to the path\n writestr (new_path, cut(tmp_path)&trim ( grep (the_line,re_inc_file,2,fail => \"\") ));\n return cut(new_path);\n end absolute_path;\n\n function absolute_indent\n (indent : Integer;\n the_line : String)\n Return Integer\n is\n start : Integer;\n begin\n start := 0;\n for i in the_line'Range loop\n if the_line (i) /= ' ' then\n start := max(0,i-1);\n exit;\n end if;\n end loop;\n return indent + start;\n end absolute_indent;\n\n function set_comment (the_line : String) return String\n is\n re_file_ext : String := \"(\\.[a-z]+)\"\"\";\n the_ext : String := grep (the_line,re_file_ext,1,fail => \"?\");\n begin\n if markup then\n if the_ext = \".tex\" then return \"%\";\n elsif the_ext = \".py\" then return \"#\";\n elsif the_ext = \".cdb\" then return \"#\";\n elsif the_ext = \".ads\" then return \"--\";\n elsif the_ext = \".adb\" then return \"--\";\n elsif the_ext = \".adt\" then return \"--\";\n elsif the_ext = \".ad\" then return \"--\";\n else return \"#\";\n end if;\n else\n return \"#\";\n end if;\n end set_comment;\n\n function filter (the_line : String) return String\n is\n tmp_line : String := the_line;\n re_uuid : String := \"(uuid):([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12})\";\n the_beg, the_end : Integer;\n found : Boolean;\n begin\n -- \"uuid\" is reserved for the original source\n -- the new file being created by this job must use a prefix other than \"uuid\"\n -- replace the prefix \"uuid\" with \"file\"\n if regex_match (the_line, re_uuid) then\n grep (the_beg, the_end, found, the_line, re_uuid, 1);\n tmp_line (the_beg..the_end) := \"file\";\n end if;\n return tmp_line;\n end filter;\n\n begin\n\n recurse_depth := recurse_depth + 1;\n\n if recurse_depth > max_recurse_depth then\n Put_Line (\"> merge-src: Too many nested Input{...}'s (max = \"&str(max_recurse_depth)&\"), exit\");\n halt(1);\n end if;\n\n declare\n src : File_Type;\n the_path : String := absolute_path (prev_path, this_line);\n the_indent : Integer := absolute_indent (prev_indent, this_line);\n comment : String := set_comment (this_line);\n begin\n\n if markup then\n Put_Line (txt, spc(the_indent)&comment&\" beg\"&make_str(recurse_depth,2)&\": ./\" & the_path);\n end if;\n\n if File_Exists (the_path)\n then Open (src, In_File, the_path);\n else raise Name_Error with \"Could not find the file \"&\"\"\"\"&str(the_path)&\"\"\"\";\n end if;\n\n loop\n begin\n declare\n the_line : String := filter (Get_Line (src));\n begin\n if is_include_file (the_line)\n then include_files (the_path, the_line, the_indent);\n else Put_Line (txt, spc(the_indent)&the_line);\n end if;" + }, + { + "function_def": "procedure evolve_data is", + "function_body": "looping : Boolean;\n\n task type SlaveTask is\n entry resume;\n entry pause;\n entry release;\n entry set_params (slave_params : SlaveParams);\n end SlaveTask;\n\n task body SlaveTask is\n params : SlaveParams;\n begin\n\n -- collect parameters for this task ------------------------\n\n accept set_params (slave_params : SlaveParams) do\n params := slave_params;" + }, + { + "function_def": "procedure write_results is", + "function_body": "num_loop_str : String := fill_str (num_loop, 5, '0');\n begin\n\n set_constraints;\n\n Ada.Directories.create_path (results_directory & \"/xy/\");\n Ada.Directories.create_path (results_directory & \"/xz/\");\n Ada.Directories.create_path (results_directory & \"/yz/\");\n\n write_results (xy_index_list, xy_index_num, results_directory & \"/xy/\" & num_loop_str & \".txt\");\n write_results (xz_index_list, xz_index_num, results_directory & \"/xz/\" & num_loop_str & \".txt\");\n write_results (yz_index_list, yz_index_num, results_directory & \"/yz/\" & num_loop_str & \".txt\");\n\n end write_results;\n\n procedure write_history (point : GridPoint;\n file_name : String)\n is\n txt : File_Type;\n\n i, j, k : Integer;\n x, y, z : Real;\n\n gab : MetricPointArray;\n Kab : ExtcurvPointArray;\n begin\n\n i := sample_point.i;\n j := sample_point.j;\n k := sample_point.k;\n\n x := sample_point.x;\n y := sample_point.y;\n z := sample_point.z;\n\n begin\n\n Open (txt, Append_File, file_name);\n\n exception when Name_Error =>\n\n Create (txt, Out_File, file_name);\n\n Put_Line (txt, \"# 4 more lines before the data\");\n\n Put_Line (txt, \"# 13 columns of data\");\n\n Put_Line (txt,\"# (\" & str (i,0) & \", \" &\n str (j,0) & \", \" &\n str (k,0) & \") = grid indices of target\");\n\n Put_Line (txt,\"# (\" & str (x,10) & \", \" &\n str (y,10) & \", \" &\n str (z,10) & \") = grid coords of target\");\n Put_Line (txt, \"# \" &\n centre (\"Time\",10) &\n centre (\"gxx\",11) &\n centre (\"gyy\",11) &\n centre (\"gzz\",11) &\n centre (\"Kxx\",11) &\n centre (\"Kyy\",11) &\n centre (\"Kzz\",11) &\n centre (\"Ham\",11) &\n centre (\"Mom(x)\",11) &\n centre (\"Mom(y)\",11) &\n centre (\"Mom(z)\",11) &\n centre (\"detg\",11) &\n centre (\"trABar\",11));" + }, + { + "function_def": "procedure echo_command_name is", + "function_body": "begin\n Put_Line (echo_command_name);\n end echo_command_name;\n\n procedure echo_command_line is\n begin\n Put_Line (echo_command_line);\n end echo_command_line;\n\n procedure echo_command_line_args is\n begin\n Put_Line (echo_command_line_args);\n end echo_command_line_args;\n\n ----------------------------------------------------------------------------\n\n procedure get_command_args\n is\n begin\n\n for i in 1 .. Argument_Count loop\n declare\n the_arg : String := Argument (i);\n the_len : Integer := the_arg'last;\n the_flag : flags;\n begin\n if the_len > 1 then\n if the_arg (1) = '-' then\n the_flag := to_flags (the_arg (2));\n cmd_args (the_flag) := (exists => True,\n image => the_arg (2),\n index => i,\n value => str (the_arg (3..the_len),max_arg_length));\n end if;\n end if;" + }, + { + "function_def": "procedure write_results is", + "function_body": "num_loop_str : String := fill_str (num_loop, 5, '0');\n begin\n\n set_constraints;\n\n Ada.Directories.create_path (results_directory & \"/xy/\");\n Ada.Directories.create_path (results_directory & \"/xz/\");\n Ada.Directories.create_path (results_directory & \"/yz/\");\n\n write_results (xy_index_list, xy_index_num, results_directory & \"/xy/\" & num_loop_str & \".txt\");\n write_results (xz_index_list, xz_index_num, results_directory & \"/xz/\" & num_loop_str & \".txt\");\n write_results (yz_index_list, yz_index_num, results_directory & \"/yz/\" & num_loop_str & \".txt\");\n\n end write_results;\n\n procedure write_history (point : GridPoint;\n file_name : String)\n is\n txt : File_Type;\n\n i, j, k : Integer;\n x, y, z : Real;\n begin\n\n i := sample_point.i;\n j := sample_point.j;\n k := sample_point.k;\n\n x := sample_point.x;\n y := sample_point.y;\n z := sample_point.z;\n\n begin\n\n Open (txt, Append_File, file_name);\n\n exception when Name_Error =>\n\n Create (txt, Out_File, file_name);\n\n Put_Line (txt, \"# 4 more lines before the data\");\n\n Put_Line (txt, \"# 11 columns of data\");\n\n Put_Line (txt,\"# (\" & str (i,0) & \", \" &\n str (j,0) & \", \" &\n str (k,0) & \") = grid indices of target\");\n\n Put_Line (txt,\"# (\" & str (x,10) & \", \" &\n str (y,10) & \", \" &\n str (z,10) & \") = grid coords of target\");\n Put_Line (txt, \"# \" &\n centre (\"Time\",10) &\n centre (\"gxx\",11) &\n centre (\"gyy\",11) &\n centre (\"gzz\",11) &\n centre (\"Kxx\",11) &\n centre (\"Kyy\",11) &\n centre (\"Kzz\",11) &\n centre (\"Ham\",11) &\n centre (\"Mom(x)\",11) &\n centre (\"Mom(y)\",11) &\n centre (\"Mom(z)\",11));" + }, + { + "function_def": "procedure evolve_data is", + "function_body": "looping : Boolean;\n\n task type SlaveTask is\n entry resume;\n entry pause;\n entry release;\n entry set_params (slave_params : SlaveParams);\n end SlaveTask;\n\n task body SlaveTask is\n params : SlaveParams;\n begin\n\n -- collect parameters for this task ------------------------\n\n accept set_params (slave_params : SlaveParams) do\n params := slave_params;" + }, + { + "function_def": "procedure Parse_Command_Line;", + "function_body": "procedure Print_Help;\n\n procedure Increment_Total (Ignore : Ada.Directories.Directory_Entry_Type);\n\n procedure Each_Torrents\n (Dir : League.Strings.Universal_String;\n Proc : not null access procedure\n (Item : Ada.Directories.Directory_Entry_Type));\n\n Cmd : constant League.String_Vectors.Universal_String_Vector :=\n League.Application.Arguments;\n\n Log_Option : constant Wide_Wide_String := \"--log=\";\n Out_Option : constant Wide_Wide_String := \"--output=\";\n Dir_Option : constant Wide_Wide_String := \"--torrent-dir=\";\n Port_Option : constant Wide_Wide_String := \"--port=\";\n Help_Option : constant Wide_Wide_String := \"--help\";\n\n Port : Positive := 33411;\n Path : League.Strings.Universal_String := +\"result\";\n Input_Path : League.Strings.Universal_String := +\"torrents\";\n Total : Ada.Containers.Count_Type := 0;\n\n procedure Set_Peer_Id (Value : out SHA1);\n\n -----------------\n -- Set_Peer_Id --\n -----------------\n\n procedure Set_Peer_Id (Value : out SHA1) is\n Settings : League.Settings.Settings;\n Context : GNAT.SHA1.Context;\n Element : League.Strings.Universal_String;\n Vector : League.Stream_Element_Vectors.Stream_Element_Vector;\n\n Key : constant League.Strings.Universal_String := +\"torrent/peer_id\";\n Now : constant String := Ada.Calendar.Formatting.Image\n (Ada.Calendar.Clock);\n begin\n if Settings.Contains (Key) then\n Element := League.Holders.Element (Settings.Value (Key));\n Vector := League.Base_Codecs.From_Base_64 (Element);\n Value := Vector.To_Stream_Element_Array;\n else\n GNAT.SHA1.Update (Context, Path.To_UTF_8_String);\n GNAT.SHA1.Update (Context, Now);\n GNAT.SHA1.Update (Context, GNAT.Sockets.Host_Name);\n\n Value := GNAT.SHA1.Digest (Context);\n Vector.Append (Value);\n Element := League.Base_Codecs.To_Base_64 (Vector);\n Settings.Set_Value (Key, League.Holders.To_Holder (Element));\n end if;\n end Set_Peer_Id;\n\n ---------------------\n -- Increment_Total --\n ---------------------\n\n procedure Increment_Total (Ignore : Ada.Directories.Directory_Entry_Type) is\n use type Ada.Containers.Count_Type;\n begin\n Total := Total + 1;\n end Increment_Total;\n\n -------------------\n -- Each_Torrents --\n -------------------\n\n procedure Each_Torrents\n (Dir : League.Strings.Universal_String;\n Proc : not null access procedure\n (Item : Ada.Directories.Directory_Entry_Type))\n is\n begin\n Ada.Directories.Search\n (Directory => Dir.To_UTF_8_String,\n Pattern => \"*.torrent\",\n Filter => (Ada.Directories.Ordinary_File => True, others => False),\n Process => Proc);\n end Each_Torrents;\n\n ------------------------\n -- Parse_Command_Line --\n ------------------------\n\n procedure Parse_Command_Line is\n Arg : League.Strings.Universal_String;\n begin\n for J in 1 .. Cmd.Length loop\n Arg := Cmd.Element (J);\n\n if Arg.Starts_With (Port_Option) then\n Port := Positive'Wide_Wide_Value\n (Arg.Tail_From (Port_Option'Length + 1).To_Wide_Wide_String);\n elsif Arg.Starts_With (Out_Option) then\n Path := Arg.Tail_From (Out_Option'Length + 1);\n elsif Arg.Starts_With (Dir_Option) then\n Input_Path := Arg.Tail_From (Dir_Option'Length + 1);\n elsif Arg.Starts_With (Help_Option) then\n Print_Help;\n elsif Arg.Starts_With (Log_Option) then\n Torrent.Logs.Initialize\n (Arg.Tail_From (Log_Option'Length + 1));\n end if;\n end loop;\n end Parse_Command_Line;\n\n ----------------\n -- Print_Help --\n ----------------\n\n procedure Print_Help is\n begin\n Ada.Wide_Wide_Text_IO.Put_Line (\"Usage: torrent-run \");\n Ada.Wide_Wide_Text_IO.Put_Line (\"Options are\");\n Ada.Wide_Wide_Text_IO.Put_Line\n (\" \" & Port_Option & \"int - a port to listen\");\n Ada.Wide_Wide_Text_IO.Put_Line\n (\" \" & Out_Option & \"path - a directory to save downloaded files\");\n Ada.Wide_Wide_Text_IO.Put_Line\n (\" \" & Dir_Option & \"path - a directory with torrent files\");\n Ada.Wide_Wide_Text_IO.Put_Line\n (\" \" & Log_Option & \"path - a trace file, if you need it\");\n end Print_Help;\n\nbegin\n if Cmd.Is_Empty then\n Print_Help;\n return;\n end if;\n\n League.Application.Set_Application_Name (+\"Torrent Client\");\n League.Application.Set_Application_Version (+\"0.1\");\n League.Application.Set_Organization_Name (+\"Matreshka Project\");\n League.Application.Set_Organization_Domain (+\"forge.ada-ru.org\");\n\n Parse_Command_Line;\n Each_Torrents (Input_Path, Increment_Total'Access);\n\n declare\n procedure Add (Item : Ada.Directories.Directory_Entry_Type);\n\n Recycle : aliased Torrent.Connections.Queues.Queue;\n\n Context : Torrent.Contexts.Context\n (Capacity => Total,\n Port => Port,\n Recycle => Recycle'Unchecked_Access);\n\n ---------\n -- Add --\n ---------\n\n procedure Add (Item : Ada.Directories.Directory_Entry_Type) is\n Meta : constant Torrent.Metainfo_Files.Metainfo_File_Access :=\n new Torrent.Metainfo_Files.Metainfo_File;\n begin\n Meta.Read\n (League.Strings.From_UTF_8_String\n (Ada.Directories.Full_Name (Item)));\n\n Context.Add_Metainfo_File (Meta);\n end Add;\n\n Peer_Id : Torrent.SHA1;\n Next_Update : Ada.Calendar.Time;\n begin\n Set_Peer_Id (Peer_Id);\n Context.Initialize (Peer_Id, Path);\n Each_Torrents (Input_Path, Add'Access);\n Context.Start (Next_Update);\n\n loop\n select\n Torrent.Shutdown.Signal.Wait_SIGINT;\n Ada.Wide_Wide_Text_IO.Put_Line (\"Ctrl+C!\");\n exit;\n or\n delay until Next_Update;\n Context.Update (Next_Update);\n end select;\n end loop;\n\n Context.Stop;" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(Torrent.Connections.Connection'Class,\n Torrent.Connections.Connection_Access);\n\n ---------------\n -- Initiator --\n ---------------\n\n task body Initiator is\n use type Ada.Streams.Stream_Element_Offset;\n\n type Socket_Connection is record\n Socket : GNAT.Sockets.Socket_Type;\n Addr : GNAT.Sockets.Sock_Addr_Type;\n Job : Torrent.Downloaders.Downloader_Access;\n end record;\n\n package Socket_Connection_Vectors is new Ada.Containers.Vectors\n (Positive, Socket_Connection);\n\n type Planned_Connection is record\n Time : Ada.Calendar.Time;\n Addr : GNAT.Sockets.Sock_Addr_Type;\n Job : Torrent.Downloaders.Downloader_Access;\n end record;\n\n function Less (Left, Right : Planned_Connection) return Boolean;\n\n package Planned_Connection_Sets is new Ada.Containers.Ordered_Sets\n (Element_Type => Planned_Connection,\n \"<\" => Less);\n\n type Accepted_Connection is record\n Socket : GNAT.Sockets.Socket_Type;\n Address : GNAT.Sockets.Sock_Addr_Type;\n Data : Torrent.Handshakes.Handshake_Image;\n Last : Ada.Streams.Stream_Element_Count;\n Done : Boolean;\n Session : Torrent.Connections.Connection_Access;\n end record;\n\n package Accepted_Connection_Vectors is new Ada.Containers.Vectors\n (Positive, Accepted_Connection);\n\n procedure Accept_Connection\n (Server : GNAT.Sockets.Socket_Type;\n Accepted : in out Accepted_Connection_Vectors.Vector);\n\n procedure Read_Handshake (Item : in out Accepted_Connection);\n\n function Hash (Item : Torrent.Connections.Connection_Access)\n return Ada.Containers.Hash_Type;\n\n package Connection_Sets is new Ada.Containers.Hashed_Sets\n (Element_Type => Torrent.Connections.Connection_Access,\n Hash => Hash,\n Equivalent_Elements => Torrent.Connections.\"=\",\n \"=\" => Torrent.Connections.\"=\");\n\n function \"+\"\n (Value : Torrent.Connections.Connection_Access)\n return System.Storage_Elements.Integer_Address;\n\n ---------\n -- \"+\" --\n ---------\n\n function \"+\"\n (Value : Torrent.Connections.Connection_Access)\n return System.Storage_Elements.Integer_Address\n is\n package Conv is new System.Address_To_Access_Conversions\n (Object => Torrent.Connections.Connection'Class);\n begin\n return System.Storage_Elements.To_Integer\n (Conv.To_Address (Conv.Object_Pointer (Value)));\n end \"+\";\n\n -----------------------\n -- Accept_Connection --\n -----------------------\n\n procedure Accept_Connection\n (Server : GNAT.Sockets.Socket_Type;\n Accepted : in out Accepted_Connection_Vectors.Vector)\n is\n Address : GNAT.Sockets.Sock_Addr_Type;\n Socket : GNAT.Sockets.Socket_Type;\n begin\n GNAT.Sockets.Accept_Socket (Server, Socket, Address);\n\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print (\"Accepted: \" & GNAT.Sockets.Image (Address)));\n\n GNAT.Sockets.Set_Socket_Option\n (Socket => Socket,\n Level => GNAT.Sockets.Socket_Level,\n Option => (GNAT.Sockets.Receive_Timeout, 0.0));\n\n Accepted.Append\n ((Socket,\n Last => 0,\n Done => False,\n Address => Address,\n others => <>));\n end Accept_Connection;\n\n ----------\n -- Hash --\n ----------\n\n function Hash (Item : Torrent.Connections.Connection_Access)\n return Ada.Containers.Hash_Type is\n begin\n return Ada.Containers.Hash_Type'Mod (+Item);\n end Hash;\n\n ----------\n -- Less --\n ----------\n\n function Less (Left, Right : Planned_Connection) return Boolean is\n use type Ada.Calendar.Time;\n function \"+\" (V : GNAT.Sockets.Sock_Addr_Type) return String\n renames GNAT.Sockets.Image;\n\n begin\n return Left.Time < Right.Time\n or else (Left.Time = Right.Time and +Left.Addr < +Right.Addr);\n end Less;\n\n --------------------\n -- Read_Handshake --\n --------------------\n\n procedure Read_Handshake (Item : in out Accepted_Connection) is\n use Torrent.Handshakes;\n use type Ada.Streams.Stream_Element;\n Last : Ada.Streams.Stream_Element_Count;\n Job : Torrent.Downloaders.Downloader_Access;\n begin\n GNAT.Sockets.Receive_Socket\n (Item.Socket,\n Item.Data (Item.Last + 1 .. Item.Data'Last),\n Last);\n\n if Last <= Item.Last then\n Item.Done := True; -- Connection closed\n elsif Last = Item.Data'Last then\n declare\n Value : constant Handshake_Type := -Item.Data;\n begin\n Job := Context.Find_Download (Value.Info_Hash);\n Item.Done := True;\n\n if Value.Length = Header'Length\n and then Value.Head = Header\n and then Job not in null\n then\n Item.Session := Job.Create_Session (Item.Address);\n\n Item.Session.Do_Handshake\n (Item.Socket, Job.Completed, Inbound => True);\n end if;" + }, + { + "function_def": "procedure Check_Intrested;", + "function_body": "procedure Send_Initial_Requests;\n function Get_Handshake\n (Data : Ada.Streams.Stream_Element_Array) return Boolean;\n\n function Get_Length\n (Data : Ada.Streams.Stream_Element_Array)\n return Ada.Streams.Stream_Element_Offset;\n\n procedure Read_Messages\n (Data : in out Ada.Streams.Stream_Element_Array;\n Last : out Ada.Streams.Stream_Element_Count);\n\n procedure On_Message (Data : Ada.Streams.Stream_Element_Array);\n\n procedure Save_Piece\n (Index : Piece_Index;\n Offset : Natural;\n Data : Ada.Streams.Stream_Element_Array);\n\n ---------------------\n -- Check_Intrested --\n ---------------------\n\n procedure Check_Intrested is\n begin\n if not Self.We_Intrested\n and then Self.Listener.We_Are_Intrested (Self.Piece_Map)\n then\n Self.Send_Message ((00, 00, 00, 01, 02)); -- interested\n Self.We_Intrested := True;\n end if;\n end Check_Intrested;\n\n -------------------\n -- Get_Handshake --\n -------------------\n\n function Get_Handshake\n (Data : Ada.Streams.Stream_Element_Array) return Boolean\n is\n function \"+\" is new Ada.Unchecked_Conversion\n (Handshake_Image, Handshake_Type);\n\n HS : constant Handshake_Type := +Data (1 .. Handshake_Image'Length);\n begin\n if HS.Length = Header'Length\n and then HS.Head = Header\n and then HS.Info_Hash = Self.Meta.Info_Hash\n then\n Self.Got_Handshake := True;\n Self.Unparsed.Clear;\n Self.Unparsed.Append\n (Data (Handshake_Image'Length + 1 .. Data'Last));\n\n return True;\n else\n return False;\n end if;\n end Get_Handshake;\n\n ----------------\n -- Get_Length --\n ----------------\n\n function Get_Length\n (Data : Ada.Streams.Stream_Element_Array)\n return Ada.Streams.Stream_Element_Offset\n is\n subtype X is Ada.Streams.Stream_Element_Offset;\n begin\n return ((X (Data (Data'First)) * 256\n + X (Data (Data'First + 1))) * 256\n + X (Data (Data'First + 2))) * 256\n + X (Data (Data'First + 3));\n end Get_Length;\n\n ----------------\n -- On_Message --\n ----------------\n\n procedure On_Message (Data : Ada.Streams.Stream_Element_Array) is\n function Get_Int\n (From : Ada.Streams.Stream_Element_Count := 0) return Natural\n is (Get_Int (Data, From));\n\n Index : Piece_Index;\n begin\n case Data (Data'First) is\n when 0 => -- choke\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print\n (GNAT.Sockets.Image (Self.Peer) & \" choke\"));\n\n Self.We_Choked := True;\n Self.Unreserve_Intervals;\n when 1 => -- unchoke\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print\n (GNAT.Sockets.Image (Self.Peer) & \" unchoke\"));\n\n Self.We_Choked := False;\n Send_Initial_Requests;\n when 2 => -- interested\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print\n (GNAT.Sockets.Image (Self.Peer) & \" interested\"));\n\n Self.He_Intrested := True;\n when 3 => -- not interested\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print\n (GNAT.Sockets.Image (Self.Peer) & \" not interested\"));\n\n Self.He_Intrested := False;\n when 4 => -- have\n\n declare\n Index : constant Piece_Index :=\n Piece_Index (Get_Int (1) + 1);\n begin\n if Index in Self.Piece_Map'Range then\n pragma Debug\n (Torrent.Logs.Enabled,\n Torrent.Logs.Print\n (GNAT.Sockets.Image (Self.Peer)\n & \" have\" & (Index'Img)));\n\n Self.Piece_Map (Index) := True;\n Check_Intrested;\n end if;" + }, + { + "function_def": "procedure Send_Initial_Requests is", + "function_body": "Length : Piece_Interval_Count;\n begin\n if Self.Current_Piece.Intervals.Is_Empty then\n Self.Listener.Reserve_Intervals\n (Map => Self.Piece_Map,\n Value => Self.Current_Piece);\n end if;\n\n Length := Piece_Interval_Count'Min\n (Piece_Interval_Count'Last,\n Self.Current_Piece.Intervals.Last_Index);\n\n Self.Pipelined :=\n (Length => Length,\n Expire => (1 .. Length => Length * Expire_Loops),\n Request => (Length, others => <>));\n\n for J in 1 .. Length loop\n declare\n Last : constant Interval :=\n Self.Current_Piece.Intervals.Last_Element;\n Index : constant Piece_Index := Self.Current_Piece.Piece;\n Offset : constant Piece_Offset := Last.From;\n Length : constant Piece_Offset := Last.To - Offset + 1;\n begin\n Self.Send_Message\n ((00, 00, 00, 13, 06) &\n To_Int (Natural (Index - 1)) &\n To_Int (Natural (Offset)) &\n To_Int (Natural (Length)));\n\n Self.Pipelined.Request.List (J) :=\n (Piece => Self.Current_Piece.Piece,\n Span => (Offset, Last.To));\n\n Self.Current_Piece.Intervals.Delete_Last;" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation", + "function_body": "(Metainfo, Metainfo_Access);\n\n --------------\n -- Announce --\n --------------\n\n not overriding function Announce\n (Self : Metainfo_File) return League.IRIs.IRI is\n begin\n return Self.Data.Announce;\n end Announce;\n\n -------------------\n -- Announce_List --\n -------------------\n\n not overriding function Announce_List\n (Self : Metainfo_File) return String_Vector_Array is\n begin\n return Self.Data.Announces;\n end Announce_List;\n\n ----------------\n -- File_Count --\n ----------------\n\n not overriding function File_Count (Self : Metainfo_File) return Positive is\n begin\n return Self.Data.File_Count;\n end File_Count;\n\n -----------------\n -- File_Length --\n -----------------\n\n not overriding function File_Length\n (Self : Metainfo_File;\n Index : Positive) return Ada.Streams.Stream_Element_Count is\n begin\n return Self.Data.Files (Index).Length;\n end File_Length;\n\n ---------------\n -- File_Path --\n ---------------\n\n not overriding function File_Path\n (Self : Metainfo_File;\n Index : Positive) return League.String_Vectors.Universal_String_Vector\n is\n begin\n return Self.Data.Files (Index).Path;\n end File_Path;\n\n --------------\n -- Finalize --\n --------------\n\n procedure Finalize (Self : in out Metainfo_File) is\n begin\n Free (Self.Data);\n end Finalize;\n\n ---------------\n -- Info_Hash --\n ---------------\n\n not overriding function Info_Hash (Self : Metainfo_File) return SHA1 is\n begin\n return Self.Data.Info_Hash;\n end Info_Hash;\n\n -----------------------\n -- Last_Piece_Length --\n -----------------------\n\n not overriding function Last_Piece_Length\n (Self : Metainfo_File) return Piece_Offset is\n begin\n return Self.Data.Last_Piece;\n end Last_Piece_Length;\n\n ----------\n -- Name --\n ----------\n\n not overriding function Name\n (Self : Metainfo_File) return League.Strings.Universal_String is\n begin\n return Self.Data.Name;\n end Name;\n\n -----------------\n -- Piece_Count --\n -----------------\n\n not overriding function Piece_Count\n (Self : Metainfo_File) return Piece_Index is\n begin\n return Self.Data.Piece_Count;\n end Piece_Count;\n\n ------------------\n -- Piece_Length --\n ------------------\n\n not overriding function Piece_Length\n (Self : Metainfo_File) return Piece_Offset is\n begin\n return Self.Data.Piece_Length;\n end Piece_Length;\n\n ----------------\n -- Piece_SHA1 --\n ----------------\n\n not overriding function Piece_SHA1\n (Self : Metainfo_File;\n Index : Piece_Index) return SHA1\n is\n begin\n return Self.Data.Hashes (Index);\n end Piece_SHA1;\n\n ----------\n -- Read --\n ----------\n\n not overriding procedure Read\n (Self : in out Metainfo_File;\n File_Name : League.Strings.Universal_String)\n is\n use type Ada.Streams.Stream_Element;\n use type Ada.Streams.Stream_Element_Offset;\n use type League.Strings.Universal_String;\n\n package File_Vectors is new Ada.Containers.Vectors\n (Index_Type => Positive,\n Element_Type => File_Information);\n\n package String_Vector_Vectors is new Ada.Containers.Vectors\n (Index_Type => Positive,\n Element_Type => League.String_Vectors.Universal_String_Vector,\n \"=\" => League.String_Vectors.\"=\");\n\n function \"+\"\n (Text : Wide_Wide_String) return League.Strings.Universal_String\n renames League.Strings.To_Universal_String;\n\n function Parse_Top_Dictionary return Metainfo;\n\n procedure Parse_Int (Value : out Ada.Streams.Stream_Element_Offset);\n\n procedure Parse_String (Value : out League.Strings.Universal_String);\n\n procedure Parse_Pieces\n (Value : out League.Stream_Element_Vectors.Stream_Element_Vector);\n\n procedure Parse_String_List\n (Value : out League.String_Vectors.Universal_String_Vector);\n\n procedure Parse_String_Vector_Vector\n (Value : out String_Vector_Vectors.Vector);\n\n procedure Skip_Value;\n procedure Skip_List;\n procedure Skip_Dictionary;\n procedure Skip_String;\n procedure Skip_Int;\n\n procedure Parse_Files (Value : out File_Vectors.Vector);\n\n procedure Expect (Char : Ada.Streams.Stream_Element);\n\n procedure Parse_File\n (Path : out League.String_Vectors.Universal_String_Vector;\n Length : out Ada.Streams.Stream_Element_Count);\n\n procedure Parse_Info\n (Name : out League.Strings.Universal_String;\n Piece_Len : out Ada.Streams.Stream_Element_Count;\n Files : out File_Vectors.Vector;\n Pieces : out League.Stream_Element_Vectors.Stream_Element_Vector);\n\n procedure Read_Buffer;\n\n subtype Digit is Ada.Streams.Stream_Element\n range Character'Pos ('0') .. Character'Pos ('9');\n\n Input : Ada.Streams.Stream_IO.File_Type;\n Buffer : Ada.Streams.Stream_Element_Array (1 .. 1024);\n Last : Ada.Streams.Stream_Element_Count := 0;\n Next : Ada.Streams.Stream_Element_Count := 1;\n Error : constant String := \"Can't parse torrent file.\";\n SHA_From : Ada.Streams.Stream_Element_Count := Buffer'Last + 1;\n Context : GNAT.SHA1.Context := GNAT.SHA1.Initial_Context;\n Codec : constant League.Text_Codecs.Text_Codec :=\n League.Text_Codecs.Codec (+\"utf-8\");\n\n package Constants is\n Announce : constant League.Strings.Universal_String := +\"announce\";\n Files : constant League.Strings.Universal_String := +\"files\";\n Info : constant League.Strings.Universal_String := +\"info\";\n Length : constant League.Strings.Universal_String := +\"length\";\n Name : constant League.Strings.Universal_String := +\"name\";\n Path : constant League.Strings.Universal_String := +\"path\";\n Pieces : constant League.Strings.Universal_String := +\"pieces\";\n\n Announce_List : constant League.Strings.Universal_String :=\n +\"announce-list\";\n Piece_Length : constant League.Strings.Universal_String :=\n +\"piece length\";\n end Constants;\n\n -----------------\n -- Read_Buffer --\n -----------------\n\n procedure Read_Buffer is\n begin\n if SHA_From <= Last then\n GNAT.SHA1.Update (Context, Buffer (SHA_From .. Last));\n\n SHA_From := 1;\n end if;\n\n Ada.Streams.Stream_IO.Read (Input, Buffer, Last);\n Next := 1;\n end Read_Buffer;\n\n ------------\n -- Expect --\n ------------\n\n procedure Expect (Char : Ada.Streams.Stream_Element) is\n begin\n if Buffer (Next) = Char then\n\n Next := Next + 1;\n\n if Next > Last then\n Read_Buffer;\n end if;\n else\n raise Constraint_Error with Error;\n end if;\n end Expect;\n\n ----------------\n -- Parse_File --\n ----------------\n\n procedure Parse_File\n (Path : out League.String_Vectors.Universal_String_Vector;\n Length : out Ada.Streams.Stream_Element_Count)\n is\n Key : League.Strings.Universal_String;\n begin\n Expect (Character'Pos ('d'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_String (Key);\n\n if Key = Constants.Length then\n Parse_Int (Length);\n\n elsif Key = Constants.Path then\n Parse_String_List (Path);\n\n else\n Skip_Value;\n end if;\n end loop;\n\n Expect (Character'Pos ('e'));\n end Parse_File;\n\n -----------------\n -- Parse_Files --\n -----------------\n\n procedure Parse_Files (Value : out File_Vectors.Vector) is\n Path : League.String_Vectors.Universal_String_Vector;\n Length : Ada.Streams.Stream_Element_Count;\n begin\n Value.Clear;\n Expect (Character'Pos ('l'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_File (Path, Length);\n Value.Append ((Length, Path));\n end loop;\n\n Expect (Character'Pos ('e'));\n end Parse_Files;\n\n ----------------\n -- Parse_Info --\n ----------------\n\n procedure Parse_Info\n (Name : out League.Strings.Universal_String;\n Piece_Len : out Ada.Streams.Stream_Element_Count;\n Files : out File_Vectors.Vector;\n Pieces : out League.Stream_Element_Vectors.Stream_Element_Vector)\n is\n Key : League.Strings.Universal_String;\n Length : Ada.Streams.Stream_Element_Count := 0;\n begin\n Files.Clear;\n SHA_From := Next; -- Activate SHA1 calculation\n Expect (Character'Pos ('d'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_String (Key);\n\n if Key = Constants.Name then\n declare\n Path : League.String_Vectors.Universal_String_Vector;\n begin\n Parse_String (Name);\n\n if Length > 0 then\n -- There is a key length or a key files, but not both\n -- or neither. If length is present then the download\n -- represents a single file, otherwise it represents a\n -- set of files which go in a directory structure.\n\n Path.Append (Name);\n Files.Append ((Length, Path));\n end if;" + }, + { + "function_def": "procedure Parse_String_List", + "function_body": "(Value : out League.String_Vectors.Universal_String_Vector)\n is\n Text : League.Strings.Universal_String;\n begin\n Value.Clear;\n Expect (Character'Pos ('l'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_String (Text);\n Value.Append (Text);\n end loop;\n\n Expect (Character'Pos ('e'));\n end Parse_String_List;\n\n --------------------------------\n -- Parse_String_Vector_Vector --\n --------------------------------\n\n procedure Parse_String_Vector_Vector\n (Value : out String_Vector_Vectors.Vector)\n is\n Item : League.String_Vectors.Universal_String_Vector;\n begin\n Value.Clear;\n Expect (Character'Pos ('l'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_String_List (Item);\n Value.Append (Item);\n end loop;\n\n Expect (Character'Pos ('e'));\n end Parse_String_Vector_Vector;\n\n ---------------------\n -- Skip_Dictionary --\n ---------------------\n\n procedure Skip_Dictionary is\n Key : League.Strings.Universal_String;\n begin\n Expect (Character'Pos ('d'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Parse_String (Key);\n Skip_Value;\n end loop;\n\n Expect (Character'Pos ('e'));\n\n end Skip_Dictionary;\n\n --------------\n -- Skip_Int --\n --------------\n\n procedure Skip_Int is\n begin\n Expect (Character'Pos ('i'));\n\n if Buffer (Next) = Character'Pos ('-') then\n Expect (Buffer (Next));\n end if;\n\n while Buffer (Next) in Digit loop\n Expect (Buffer (Next));\n end loop;\n\n Expect (Character'Pos ('e'));\n end Skip_Int;\n\n ---------------\n -- Skip_List --\n ---------------\n\n procedure Skip_List is\n begin\n Expect (Character'Pos ('l'));\n\n while Buffer (Next) /= Character'Pos ('e') loop\n Skip_Value;\n end loop;\n\n Expect (Character'Pos ('e'));\n end Skip_List;\n\n -----------------\n -- Skip_String --\n -----------------\n\n procedure Skip_String is\n Len : Ada.Streams.Stream_Element_Count := 0;\n begin\n while Buffer (Next) in Digit loop\n Len := Len * 10\n + Ada.Streams.Stream_Element_Count (Buffer (Next))\n - Character'Pos ('0');\n\n Expect (Buffer (Next));\n end loop;\n\n declare\n To : Ada.Streams.Stream_Element_Count := 0;\n begin\n Expect (Character'Pos (':'));\n\n while Last - Next + 1 <= Len loop\n To := To + Last - Next + 1;\n Len := Len - (Last - Next + 1);\n Read_Buffer;\n end loop;\n\n if Len > 0 then\n Next := Next + Len;\n end if;" + }, + { + "function_def": "procedure AgenTests is", + "function_body": "begin\n Testing.Start(\"Agen\");\n\n declare\n Param : Parameter;\n begin\n Is_Equal(\"Try_Parse(\"\"name:string\"\")\", Try_Parse(\"name:string\", Param), True);\n Is_Equal(\"Parameter\", Param, \"name\", \"string\");" + }, + { + "function_def": "procedure Help is", + "function_body": "begin\n Put_Line(\" (func|function) name:return_type [parameter:type]* - Print the generated function\");\n end Help;\n\n function Try_Act return Boolean is\n Func : Parameter;\n begin\n if Argument_Stack.Is_Empty then goto Fail; end if;\n declare\n Action : constant String := Argument_Stack.Pop;\n begin\n if To_Upper(Action) /= \"FUNC\" and To_Upper(Action) /= \"FUNCTION\" then\n goto Fail;\n end if;" + }, + { + "function_def": "procedure Help is", + "function_body": "begin\n Put_Line(\" (new|init)\");\n Put_Line(\" project - create a project from a basic template\");\n Put_Line(\" gpr - create a GPR from a basic template\");\n end Help;\n\n function Try_Act return Boolean is\n begin\n if Argument_Stack.Is_Empty then goto Fail; end if;\n declare\n Action : constant String := Argument_Stack.Pop;\n begin\n if To_Upper(Action) /= \"NEW\" and To_Upper(Action) /= \"INIT\" then\n goto Fail;\n end if;" + }, + { + "function_def": "procedure Help is", + "function_body": "begin\n Put_Line(\" (cmm|comment)\");\n Put_Line(\" (desc|description) - Print a description doc comment\");\n Put_Line(\" (ex|exception) - Print an exception doc comment\");\n Put_Line(\" field - Print a field doc comment\");\n Put_Line(\" param - Print a param doc comment\");\n Put_Line(\" (ret|return) - Prints a return doc comment\");\n Put_Line(\" (summ|summary) - Print a summary doc comment\");\n Put_Line(\" value - Print a value doc comment\");\n end Help;\n\n function Try_Act return Boolean is\n begin\n if Argument_Stack.Is_Empty then goto Fail; end if;\n declare\n Action : constant String := Argument_Stack.Pop;\n begin\n if To_Upper(Action) /= \"CMM\" and To_Upper(Action) /= \"COMMENT\" then\n goto Fail;\n end if;" + }, + { + "function_def": "procedure Help is", + "function_body": "begin\n Put_Line(\" (proc|procedure) [parameter:type]* - Print the generated procedure\");\n end Help;\n\n function Try_Act return Boolean is\n begin\n if Argument_Stack.Is_Empty then goto Fail; end if;\n declare\n Action : constant String := Argument_Stack.Pop;\n begin\n if To_Upper(Action) /= \"PROC\" and To_Upper(Action) /= \"PROCEDURE\" then\n goto Fail;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Index_Impl, Index_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Index_Impl_Ptr := Index_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Index_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, INDEX_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Index_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Index_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (INDEX_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_1_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Document_Impl, Document_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Document_Impl_Ptr := Document_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Document_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, DOCUMENT_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Document_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Document_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (DOCUMENT_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_2_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_2_NAME, -- index_id\n Value => Object.Index);\n Object.Clear_Modified (2);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Field_Impl, Field_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Field_Impl_Ptr := Field_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Field_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, FIELD_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Field_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Field_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (FIELD_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_3_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (4) then\n Stmt.Save_Field (Name => COL_3_3_NAME, -- document_id\n Value => Object.Document);\n Object.Clear_Modified (4);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Sequence_Impl, Sequence_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Sequence_Impl_Ptr := Sequence_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Sequence_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, SEQUENCE_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Sequence_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"field = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Sequence_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (SEQUENCE_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_4_NAME, -- positions\n Value => Object.Positions);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (2) then\n Stmt.Save_Field (Name => COL_1_4_NAME, -- token\n Value => Object.Token);\n Object.Clear_Modified (2);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_4_NAME, -- field\n Value => Object.Get_Key);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"field = ? AND token = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n Stmt.Add_Param (Value => Object.Token);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Unchecked_Free is new Ada.Unchecked_Deallocation", + "function_body": "(Token_Impl, Token_Impl_Ptr);\n pragma Warnings (Off, \"*redundant conversion*\");\n Ptr : Token_Impl_Ptr := Token_Impl (Object.all)'Access;\n pragma Warnings (On, \"*redundant conversion*\");\n begin\n Unchecked_Free (Ptr);\n end Destroy;\n\n overriding\n procedure Find (Object : in out Token_Impl;\n Session : in out ADO.Sessions.Session'Class;\n Query : in ADO.SQL.Query'Class;\n Found : out Boolean) is\n Stmt : ADO.Statements.Query_Statement\n := Session.Create_Statement (Query, TOKEN_DEF'Access);\n begin\n Stmt.Execute;\n if Stmt.Has_Elements then\n Object.Load (Stmt, Session);\n Stmt.Next;\n Found := not Stmt.Has_Elements;\n else\n Found := False;\n end if;\n end Find;\n\n overriding\n procedure Load (Object : in out Token_Impl;\n Session : in out ADO.Sessions.Session'Class) is\n Found : Boolean;\n Query : ADO.SQL.Query;\n Id : constant ADO.Identifier := Object.Get_Key_Value;\n begin\n Query.Bind_Param (Position => 1, Value => Id);\n Query.Set_Filter (\"id = ?\");\n Object.Find (Session, Query, Found);\n if not Found then\n raise ADO.Objects.NOT_FOUND;\n end if;\n end Load;\n\n overriding\n procedure Save (Object : in out Token_Impl;\n Session : in out ADO.Sessions.Master_Session'Class) is\n Stmt : ADO.Statements.Update_Statement\n := Session.Create_Statement (TOKEN_DEF'Access);\n begin\n if Object.Is_Modified (1) then\n Stmt.Save_Field (Name => COL_0_5_NAME, -- id\n Value => Object.Get_Key);\n Object.Clear_Modified (1);\n end if;\n if Object.Is_Modified (3) then\n Stmt.Save_Field (Name => COL_2_5_NAME, -- index_id\n Value => Object.Index);\n Object.Clear_Modified (3);\n end if;\n if Stmt.Has_Save_Fields then\n Stmt.Set_Filter (Filter => \"id = ?\");\n Stmt.Add_Param (Value => Object.Get_Key);\n declare\n Result : Integer;\n begin\n Stmt.Execute (Result);\n if Result /= 1 then\n if Result /= 0 then\n raise ADO.Objects.UPDATE_ERROR;\n end if;\n end if;" + }, + { + "function_def": "procedure Indexer is", + "function_body": "Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create (\"Indexer\");\n\n Factory : ADO.Sessions.Factory.Session_Factory;\n Count : constant Natural := Ada.Command_Line.Argument_Count;\nbegin\n ADO.SQLite.Initialize;\n Factory.Create (\"sqlite:///search.db?synchronous=OFF&encoding='UTF-8'\");\n\n if Count < 1 then\n Ada.Text_IO.Put_Line (\"Usage: indexer file...\");\n return;\n end if;\n declare\n DB : ADO.Sessions.Master_Session := Factory.Get_Master_Session;\n Indexer : Search.Indexers.Databases.Indexer_Type;\n Analyzer : Search.Analyzers.French.Analyzer_Type;\n Tokenizer : Search.Tokenizers.Tokenizer_Type;\n begin\n Indexer.Initialize (DB, ADO.NO_IDENTIFIER);\n for I in 1 .. Count loop\n declare\n Path : constant String := Ada.Command_Line.Argument (I);\n Doc : Search.Documents.Document_Type;\n begin\n Doc.Add_Field (\"path\", Path, Search.Fields.F_PATH);\n Indexer.Add_Document (Doc, Analyzer, Tokenizer);" + }, + { + "function_def": "procedure Finder is", + "function_body": "Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create (\"Indexer\");\n\n Factory : ADO.Sessions.Factory.Session_Factory;\n Count : constant Natural := Ada.Command_Line.Argument_Count;\nbegin\n ADO.SQLite.Initialize;\n Factory.Create (\"sqlite:///search.db?synchronous=OFF&encoding='UTF-8'\");\n\n if Count < 1 then\n Ada.Text_IO.Put_Line (\"Usage: finder query...\");\n return;\n end if;\n declare\n DB : ADO.Sessions.Master_Session := Factory.Get_Master_Session;\n Indexer : Search.Indexers.Databases.Indexer_Type;\n Analyzer : Search.Analyzers.French.Analyzer_Type;\n Tokenizer : Search.Tokenizers.Tokenizer_Type;\n begin\n Indexer.Initialize (DB, ADO.NO_IDENTIFIER);\n for I in 1 .. Count loop\n declare\n Query : constant String := Ada.Command_Line.Argument (I);\n\t Result : Search.Results.Result_Vector;\n begin\n Indexer.Find (Query, Analyzer, Tokenizer, Result);\n\t for Item of Result loop\n\t declare\n\t\t Doc : Search.Documents.Document_Type;\n\t\t Field : Search.Fields.Field_Type;\n\t begin\n\t\t Indexer.Load (Doc, Item.Doc_Id);\n\t\t Field := Doc.Get_Field (\"path\");\n\t\t Ada.Text_IO.Put_Line (Search.Fields.Get_Value (Field));" + }, + { + "function_def": "procedure Remove_Node is new Ada.Unchecked_Deallocation (Node_Type, Node_Access_Type);", + "function_body": "procedure Remove_List is new Ada.Unchecked_Deallocation (List_Header_Type, List_Header_Access_Type);\n\n---------------------------------------------------------------------\n function Initialise return List_Header_Access_Type is\n\n Temp_Entry: List_Header_Access_Type;\n\n begin\n --\n -- allocate new memory for the header information\n --\n Temp_Entry := new List_Header_Type;\n --\n -- and set the fields up. These could be replaced by default values in the\n -- record declaration.\n --\n Temp_Entry.First_Entry := null;\n Temp_Entry.Count := 0;\n Temp_Entry.Free_List := null;\n Temp_Entry.Free_List_Count := 0;\n\n -- DEFECT 262 set Stepping_Pointer to null.\n Temp_Entry.Stepping_Pointer := null;\n\n return Temp_Entry; \n\n end Initialise;\n\n ---------------------------------------------------------------------\n\n function Count_Of (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Count;\n end Count_Of;\n\n ---------------------------------------------------------------------\n\n function Count_Of_Free_List (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Free_List_Count;\n end Count_Of_Free_List;\n\n ---------------------------------------------------------------------\n\n function Max_Count_Of (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Max_Count;\n end Max_Count_Of;\n\n ---------------------------------------------------------------------\n\n function First_Entry_Of (Target_List : List_Header_Access_Type) return Node_Access_Type is\n begin\n Target_List.Stepping_Pointer := Target_List.First_Entry;\n return Target_List.Stepping_Pointer;\n end First_Entry_Of;\n\n ---------------------------------------------------------------------\n\n function Next_Entry_Of (Target_List : List_Header_Access_Type) return Node_Access_Type is\n begin\n Target_List.Stepping_Pointer := Target_List.Stepping_Pointer.Next;\n return Target_List.Stepping_Pointer;\n end Next_Entry_Of;\n\n ---------------------------------------------------------------------\n\n procedure Insert (New_Item : in Element_Type;\n On_To : in List_Header_Access_Type) is\n\n New_Cell: Node_Access_Type;\n\n begin\n\n if On_To.Free_List = null then\n -- \n -- there are no 'old' entries available for reuse\n --\n begin\n New_Cell:= new Node_Type;\n \n exception\n when Storage_Error => raise List_Storage_Error ;" + }, + { + "function_def": "procedure Register_M1_End_Class (M1_Instance: in Ada.Tags.Tag) is", + "function_body": "begin\n M1_Side := M1_Instance;\n M1_Single_M2_Multiple.Register_Single_End_Class (M1_Instance);\n M2_Single_M1_Multiple.Register_Multiple_End_Class (M1_Instance);\n end Register_M1_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_M1_End_Class return Ada.Tags.Tag is\n begin\n return M1_Side;\n end Report_M1_End_Class;\n\n-----------------------------------------------------------------------\n\n procedure Register_M2_End_Class (M2_Instance: in Ada.Tags.Tag) is\n begin\n M2_Side := M2_Instance;\n M1_Single_M2_Multiple.Register_Multiple_End_Class (M2_Instance);\n M2_Single_M1_Multiple.Register_Single_End_Class (M2_Instance);\n end Register_M2_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_M2_End_Class return Ada.Tags.Tag is\n begin\n return M2_Side;\n end Report_M2_End_Class;\n\n-----------------------------------------------------------------------\n\n procedure Register_Associative_End_Class (Associative_Instance: in Ada.Tags.Tag) is\n begin\n Associative_Side := Associative_Instance;\n M1_Single_M2_Multiple.Register_Associative_End_Class (Associative_Instance);\n M2_Single_M1_Multiple.Register_Associative_End_Class (Associative_Instance);\n end Register_Associative_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_Associative_End_Class return Ada.Tags.Tag is\n begin\n return Associative_Side;\n end Report_Associative_End_Class;\n\n---------------------------------------------------------------------\n\n procedure Link (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n Using : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Link (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n Using => Using);\n\n M2_Single_M1_Multiple.Link (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n Using => Using);\n\n end Link;\n-----------------------------------------------------------------------\n procedure Unassociate (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n From : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Unassociate (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n From => From);\n\n M2_Single_M1_Multiple.Unassociate (\n A_Instance => B_Instance,\n B_Instance => A_Instance,\n From => From);\n\n end Unassociate;\n\n-----------------------------------------------------------------------\n\n procedure Unlink (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Unlink (\n A_Instance => A_Instance,\n B_Instance => B_Instance);\n\n M2_Single_M1_Multiple.Unlink (\n A_Instance => B_Instance,\n B_Instance => A_Instance);\n\n end Unlink;\n\n-----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_List.List_Header_Access_Type;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n The_A_Instance: Root_Object.Object_Access;\n\n begin\n\n The_A_Instance := Root_Object.Object_List.First_Entry_Of (From).Item;\n\n if The_A_Instance /= null then\n\n if The_A_Instance.all'tag = M1_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif The_A_Instance.all'tag = M2_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif The_A_Instance.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n end if;\n\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n --\n -- navigate from a single to a set\n -- valid for:\n -- M1 -> M2\n -- M1 -> A\n -- M2 -> M1\n -- M2 -> A\n --\n begin\n\n if From.all'tag = M1_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif From.all'tag = M2_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif From.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n --\n -- navigate from a single to a single\n -- valid for:\n -- A -> M1\n -- A -> M2\n --\n begin\n\n if From.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n\n -- associative correlated navigation\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Also : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n --\n -- navigate from two singles to a single\n -- valid for:\n -- M1 and M2 -> A\n -- M1 and M2 -> A\n\n Temp_Associative_One, Temp_Associative_Two : Root_Object.Object_Access := null;\n\n Assoc_Set_One : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n Assoc_Set_Two : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n\n Matched, Inner_Matched : Boolean := FALSE;\n\n begin\n\n -- Reset the output pointer to null so that if we don't find anything\n -- useful, the caller can check for it.\n To := null;\n\n if ((( From.all'tag = M1_Side) and then\n ( Also.all'Tag = M2_Side))\n or else (( From.all'tag = M2_Side) and then\n ( Also.all'Tag = M1_Side)))\n then\n\n -- Navigate from single instance of first object\n -- returns a set.\n Navigate (\n From => Also,\n Class => Class,\n To => Assoc_Set_One);\n\n -- Navigate from single instance of second object\n -- returns a set.\n Navigate (\n From => From,\n Class => Class,\n To => Assoc_Set_Two);\n\n -- Compare results of the two sets from the above navigations.\n -- A nice simple find operation on a set would be appropriate here, but\n -- there isn't one available, so do it the hard way.\n\n -- Outer loop\n declare\n use type Root_Object.Object_List.Node_Access_Type;\n Temp_Entry : Root_Object.Object_List.Node_Access_Type;\n Matched : boolean := FALSE;\n begin\n -- Grab the first entry of the set\n Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_One);\n -- While the set is not empty and the entry does not match the\n -- assoc instance already found, burn rubber\n\n while (not Matched) and (Temp_Entry /= null) loop\n\n Temp_Associative_One := Temp_Entry.Item;\n -- Compare this entry against the other set.\n\n -- Inner loop\n declare\n use type Root_Object.Object_List.Node_Access_Type;\n Inner_Temp_Entry : Root_Object.Object_List.Node_Access_Type;\n begin\n\n -- Grab the first entry of the set\n Inner_Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_Two);\n\n -- While the set is not empty and the entry does not match the\n -- assoc instance already found, smoke 'em\n\n while (not matched) and (Inner_Temp_Entry /= null) loop\n\n\t\t\t\t\t\t\tTemp_Associative_Two := Inner_Temp_Entry.Item;\n -- If M-M:M associative was ever implemented,\n -- it would be easy to add the matched instance into a set for\n -- return from this procedure.\n\n\t\t\t\t\t\t\tMatched := Temp_Associative_One = Temp_Associative_Two;\n\n\t\t\t\t\t\t\tif not Matched then\n Inner_Temp_Entry := Root_Object.Object_List.Next_Entry_Of(Assoc_Set_Two);\n end if;\n\n end loop; -- end of (Temp_Entry /= null) or else Matched loop" + }, + { + "function_def": "procedure Remove_Pair is new Ada.Unchecked_Deallocation (", + "function_body": "Relationship_Pair_Type, Relationship_Pair_Access_Type);\n\n --\n -- 'Major' element\n --\n type Relationship_Entry_Type;\n type Relationship_Entry_Access_Type is access all Relationship_Entry_Type;\n\n type Relationship_Entry_Type is record\n Single : Root_Object.Object_Access;\n Completion_List : Relationship_Pair_Access_Type;\n Next : Relationship_Entry_Access_Type;\n Previous : Relationship_Entry_Access_Type;\n end record;\n\n procedure Remove_Entry is new Ada.Unchecked_Deallocation (\n Relationship_Entry_Type, Relationship_Entry_Access_Type);\n\n ------------------------------------------------------------------------\n The_Relationship_List: Relationship_Entry_Access_Type;\n\n\n subtype Role_Phrase_Type is string (1 .. Application_Types.Maximum_Number_Of_Characters_In_String);\n\n Multiple_Side : Ada.Tags.Tag;\n Multiple_Side_Role : Role_Phrase_Type;\n Multiple_Side_Role_Length : Natural;\n\n Single_Side : Ada.Tags.Tag;\n Single_Side_Role : Role_Phrase_Type;\n Single_Side_Role_Length : Natural;\n\n Associative_Side : Ada.Tags.Tag;\n Associative_Side_Role : Role_Phrase_Type;\n Associative_Side_Role_Length : Natural;\n --\n -- A = LEFT = MULTIPLE\n -- B = RIGHT = SINGLE\n --\n ------------------------------------------------------------------------\n procedure Check_List_For_Multiple (\n Multiple_Instance : in Root_Object.Object_Access;\n Associative_Instance : out Root_Object.Object_Access;\n Single_Instance : out Root_Object.Object_Access;\n Multiple_Instance_Found : out Boolean) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n\n begin\n\n\n Multiple_Instance_Found := False;\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while (not Multiple_Instance_Found) and then Temp_Major_Pointer /= null loop\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while (not Multiple_Instance_Found) and then Temp_Minor_Pointer /= null loop\n\n Multiple_Instance_Found := (Temp_Minor_Pointer.Multiple = Multiple_Instance);\n\n if Multiple_Instance_Found then\n Associative_Instance := Temp_Minor_Pointer.Associative;\n Single_Instance := Temp_Major_Pointer.Single;\n else\n -- Prevent access if we have got what we are after\n -- Bailing out of the search loop is a neater solution, but test team defects\n -- have been raised against this sort of thing.\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n end if;\n\n end loop Minor_Loop;\n\n -- Prevent the possibility that the next entry in the major queue is null causing an access error\n if not Multiple_Instance_Found then\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop Major_Loop;\n\n end Check_List_For_Multiple;\n\n ------------------------------------------------------------------------\n procedure Check_List_For_Associative (\n Associative_Instance : in Root_Object.Object_Access;\n Multiple_Instance : out Root_Object.Object_Access;\n Single_Instance : out Root_Object.Object_Access;\n Associative_Instance_Found : out Boolean) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n\n begin\n\n Associative_Instance_Found := False;\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while (not Associative_Instance_Found) and then Temp_Major_Pointer /= null loop\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while (not Associative_Instance_Found) and then Temp_Minor_Pointer /= null loop\n\n Associative_Instance_Found := (Temp_Minor_Pointer.Associative = Associative_Instance);\n\n if Associative_Instance_Found then\n Multiple_Instance := Temp_Minor_Pointer.Multiple;\n Single_Instance := Temp_Major_Pointer.Single;\n else\n -- Prevent access if we have got what we are after\n -- Bailing out of the search loop is a neater solution, but test team defects\n -- have been raised against this sort of thing.\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n end if;\n\n end loop Minor_Loop;\n\n -- Prevent the possibility that the next entry in the major queue is null causing an access error\n if not Associative_Instance_Found then\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop Major_Loop;\n\n end Check_List_For_Associative;\n\n -----------------------------------------------------------------------\n\n procedure Do_Link (\n Multiple_Instance : in Root_Object.Object_Access;\n Single_Instance : in Root_Object.Object_Access;\n Associative_Instance : in Root_Object.Object_Access) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n Found : Boolean := False;\n\n begin\n Temp_Major_Pointer := The_Relationship_List;\n\n while (not Found) and then Temp_Major_Pointer /= null loop\n\n Found := (Temp_Major_Pointer.Single = Single_Instance);\n\n if not Found then -- grab the next item\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop;\n\n if not Found then\n Temp_Major_Pointer := new Relationship_Entry_Type;\n Temp_Major_Pointer.Single := Single_Instance;\n Temp_Major_Pointer.Completion_List := null;\n Temp_Major_Pointer.Previous := null;\n Temp_Major_Pointer.Next := The_Relationship_List;\n\n if The_Relationship_List /= null then\n The_Relationship_List.Previous := Temp_Major_Pointer;\n end if;\n\n The_Relationship_List := Temp_Major_Pointer;\n\n end if;\n\n Temp_Minor_Pointer := new Relationship_Pair_Type;\n Temp_Minor_Pointer.Multiple := Multiple_Instance;\n Temp_Minor_Pointer.Associative := Associative_Instance;\n Temp_Minor_Pointer.Previous := null;\n Temp_Minor_Pointer.Next := Temp_Major_Pointer.Completion_List;\n\n if Temp_Major_Pointer.Completion_List /= null then\n Temp_Major_Pointer.Completion_List.Previous := Temp_Minor_Pointer;\n end if;\n\n Temp_Major_Pointer.Completion_List := Temp_Minor_Pointer;\n\n end Do_Link;\n\n -----------------------------------------------------------------------\n\n procedure Do_Unlink (\n Left_Instance : in Root_Object.Object_Access;\n Right_Instance : in Root_Object.Object_Access) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n Delete_List : Boolean := False;\n\n begin\n\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while Temp_Major_Pointer /= null loop\n\n if Temp_Major_Pointer.Single = Left_Instance then\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while Temp_Minor_Pointer /= null loop\n if Temp_Minor_Pointer.Multiple = Right_Instance then\n if Temp_Minor_Pointer.Previous = null then\n --\n -- first instance in list\n --\n Temp_Major_Pointer.Completion_List := Temp_Minor_Pointer.Next;\n --\n -- it's also the last and only instance in list\n -- So we're going to delete the whole relationship instance\n -- (but not just yet)\n --\n Delete_List := (Temp_Minor_Pointer.Next = null);\n\n end if;\n\n if Temp_Minor_Pointer.Next /= null then\n --\n -- there are more instances following in the list\n --\n Temp_Minor_Pointer.Next.Previous := Temp_Minor_Pointer.Previous;\n end if;\n\n if Temp_Minor_Pointer.Previous /= null then\n --\n -- there are more instances previous in the list\n --\n Temp_Minor_Pointer.Previous.Next := Temp_Minor_Pointer.Next;\n end if;\n\n Remove_Pair (Temp_Minor_Pointer);\n exit Major_Loop;\n\n end if;\n\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n\n end loop Minor_Loop;\n\n end if;\n\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n\n end loop Major_Loop;\n --\n -- if needed, now delete the list\n -- the same logic applies\n --\n if Delete_List then\n\n if Temp_Major_Pointer.Previous = null then\n --\n -- first instance in list\n --\n The_Relationship_List := Temp_Major_Pointer.Next;\n end if;\n\n if Temp_Major_Pointer.Next /= null then\n --\n -- there are more instances following in the list\n --\n Temp_Major_Pointer.Next.Previous := Temp_Major_Pointer.Previous;\n end if;\n\n if Temp_Major_Pointer.Previous /= null then\n --\n -- there are more instances previous in the list\n --\n Temp_Major_Pointer.Previous.Next := Temp_Major_Pointer.Next;\n end if;\n\n Remove_Entry (Temp_Major_Pointer);\n\n end if;\n\n end Do_Unlink;\n\n -------------------------------------------------------------------------\n procedure Register_Multiple_End_Class (Multiple_Instance : in Ada.Tags.Tag) is\n begin\n Multiple_Side := Multiple_Instance;\n end Register_Multiple_End_Class;\n\n ---------------------------------------------------------------------\n procedure Register_Multiple_End_Role (Multiple_Role : in String) is\n begin\n Multiple_Side_Role (1 .. Multiple_Role'Length) := Multiple_Role;\n Multiple_Side_Role_Length := Multiple_Role'Length;\n end Register_Multiple_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Register_Single_End_Class (Single_Instance : in Ada.Tags.Tag) is\n begin\n Single_Side := Single_Instance;\n end Register_Single_End_Class;\n\n ---------------------------------------------------------------------\n\n procedure Register_Single_End_Role (Single_Role : in String) is\n begin\n\n Single_Side_Role (1..Single_Role'Length) := Single_Role;\n Single_Side_Role_Length := Single_Role'Length;\n end Register_Single_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Register_Associative_End_Class (Associative_Instance : in Ada.Tags.Tag) is\n begin\n Associative_Side := Associative_Instance;\n end Register_Associative_End_Class;\n\n ---------------------------------------------------------------------\n\n procedure Register_Associative_End_Role (Associative_Role : in String) is\n begin\n Associative_Side_Role (1 .. Associative_Role'Length) := Associative_Role;\n Associative_Side_Role_Length := Associative_Role'Length;\n end Register_Associative_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Link (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n Using : in Root_Object.Object_Access) is\n\n begin\n\n if Using.all'Tag = Associative_Side then\n\n if A_Instance.all'Tag = Multiple_Side then\n\n Do_Link (\n Multiple_Instance => A_Instance,\n Single_Instance => B_Instance,\n Associative_Instance => Using);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships + 1;\n\n elsif A_Instance.all'Tag = Single_Side then\n\n Do_Link (\n Multiple_Instance => B_Instance,\n Single_Instance => A_Instance,\n Associative_Instance => Using);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships + 1;\n\n end if;\n end if; -- Using.all'tag /= Associative_Side\n\n end Link;\n\n -----------------------------------------------------------------------\n\n procedure Unassociate (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n From : in Root_Object.Object_Access) is\n begin\n null;\n end Unassociate;\n\n -----------------------------------------------------------------------\n\n procedure Unlink (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access) is\n\n begin\n\n if A_Instance.all'Tag = Multiple_Side then\n\n Do_Unlink (\n Left_Instance => B_Instance,\n Right_Instance => A_Instance);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships - 1;\n\n elsif A_Instance.all'Tag = Single_Side then\n --\n Do_Unlink (\n Left_Instance => A_Instance,\n Right_Instance => B_Instance);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships - 1;\n\n end if;\n\n end Unlink;\n\n -----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_List.List_Header_Access_Type;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n Source_Instance: Root_Object.Object_Access;\n Temp_Node: Root_Object.Object_List.Node_Access_Type;\n Temp_Instance: Root_Object.Object_Access;\n --Temp_Single: Root_Object.Object_Access;\n --Temp_Associative: Root_Object.Object_Access;\n --Temp_Multiple: Root_Object.Object_Access;\n\n begin\n\n Temp_Node := Root_Object.Object_List.First_Entry_Of (From);\n\n while Temp_Node /= null loop\n\n Source_Instance := Temp_Node.Item;\n\n if Source_Instance.all'Tag = Multiple_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => Temp_Instance);\n\n if Temp_Instance /= null then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Instance,\n On_To => To );\n\n end if;\n --\n elsif Source_Instance.all'Tag = Single_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => To);\n --\n\n elsif Source_Instance.all'Tag = Associative_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => Temp_Instance);\n\n if Temp_Instance /= null then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Instance,\n On_To => To );\n\n end if;\n --\n\n end if;\n\n Temp_Node := Root_Object.Object_List.Next_Entry_Of (From);\n\n end loop;\n\n end Navigate;\n\n -----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n --\n -- navigate from a single to a single\n -- valid for:\n -- A -> M\n -- A -> S\n -- M -> S\n -- M -> A\n --\n Temp_Single: Root_Object.Object_Access;\n Temp_Associative: Root_Object.Object_Access;\n Temp_Multiple: Root_Object.Object_Access;\n Found: Boolean;\n\n begin\n\n -- PILOT_0000_1422\n -- Defaulting the return parameter ensures that if an attempt\n -- is made to navigate this type of one to many associative\n -- without having linked it, the correct null parameter is\n -- returned. This relationship mechanism relies on the link\n -- operation to sort out all the tags. We can't rely on that\n -- happening in all cases.\n To := null;\n\n if From.all'Tag = Multiple_Side then\n --\n\n Check_List_For_Multiple (\n Multiple_Instance => From,\n Associative_Instance => Temp_Associative,\n Single_Instance => Temp_Single,\n Multiple_Instance_Found => Found);\n\n if Found then\n --\n if Class = Single_Side then\n\n To := Temp_Single;\n\n\n elsif Class = Associative_Side then\n\n To := Temp_Associative;\n\n end if;\n --\n\n end if;\n --\n\n elsif From.all'Tag = Associative_Side then\n\n\n Check_List_For_Associative (\n Associative_Instance => From,\n Multiple_Instance => Temp_Multiple,\n Single_Instance => Temp_Single,\n Associative_Instance_Found => Found);\n\n if Found then\n --\n if Class = Single_Side then\n\n To := Temp_Single;\n\n elsif Class = Multiple_Side then\n\n To := Temp_Multiple;\n\n end if;\n\n end if;\n\n end if;\n\n end Navigate;\n\n ---------------------------------------------------------------------\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n --\n -- navigate from a single to a set\n -- valid for:\n -- S -> M\n -- S -> A\n --\n\n Temp_Minor_Pointer: Relationship_Pair_Access_Type;\n Temp_Major_Pointer: Relationship_Entry_Access_Type;\n\n begin\n\n if From.all'Tag = Single_Side then\n\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n\n while Temp_Major_Pointer /= null loop\n\n if Temp_Major_Pointer.Single = From then\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n\n while Temp_Minor_Pointer /= null loop\n\n if Class = Multiple_Side then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Minor_Pointer.Multiple,\n On_To => To);\n\n elsif Class = Associative_Side then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Minor_Pointer.Associative,\n On_To => To);\n\n end if;\n\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n\n end loop Minor_Loop;\n\n exit Major_Loop;\n\n end if;\n\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n\n end loop Major_Loop;\n --\n end if;\n\n end Navigate;\n\n\n------------------------------------------------------------------------\n\n\n -- associative correlated navigation\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Also : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n\n -- navigate from two singles to a single\n -- valid for:\n -- M and S -> A\n -- S and M -> A\n\n Temp_Single,\n Single_Side_Source ,\n Multiple_Side_Source,\n Temp_Associative_Multiple,\n Temp_Associative_Single : Root_Object.Object_Access := null;\n\n Assoc_Set : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n\n Found,\n Tags_Correct : Boolean := FALSE;\n\n begin\n\n -- Reset the output pointer to null so that if we don't find anything\n -- useful, the caller can check for it.\n To := null;\n\n Tags_Correct := ((( From.all'Tag = Multiple_Side) and then\n ( Also.all'Tag = Single_Side))\n or else ((( From.all'Tag = Single_Side) and then\n ( Also.all'Tag = Multiple_Side)))) ;\n\n if Tags_Correct then\n\n if From.all'Tag = Multiple_Side then\n\n Multiple_Side_Source := From;\n Single_Side_Source := Also;\n else\n Multiple_Side_Source := Also;\n Single_Side_Source := From;\n end if;\n\n -- Do the navigations now, all is correct.\n\n -- Navigate from multiple side to associative side.\n Check_List_For_Multiple (\n Multiple_Instance => Multiple_Side_Source,\n Associative_Instance => Temp_Associative_Multiple,\n Single_Instance => Temp_Single,\n Multiple_Instance_Found => Found);\n\n\n -- Navigate from single side to associative side.\n if Found then\n\n -- do the navigation\n\n declare\n Input_List : Root_Object.Object_List.List_Header_Access_Type;\n begin\n Input_List := Root_Object.Object_List.Initialise;\n\n Root_Object.Object_List.Clear(Assoc_Set);\n\n Root_Object.Object_List.Insert (\n New_Item => Single_Side_Source,\n On_To => Input_List);\n\n Navigate(\n From => Input_List,\n Class => Class,\n To => Assoc_Set);\n\n Root_Object.Object_List.Destroy_List(Input_List);" + }, + { + "function_def": "procedure Remove_Node is new Ada.Unchecked_Deallocation (Node_Type, Node_Access_Type);", + "function_body": "procedure Remove_List is new Ada.Unchecked_Deallocation (List_Header_Type, List_Header_Access_Type);\n\n---------------------------------------------------------------------\n function Initialise return List_Header_Access_Type is\n\n Temp_Entry: List_Header_Access_Type;\n\n begin\n --\n -- allocate new memory for the header information\n --\n Temp_Entry := new List_Header_Type;\n --\n -- and set the fields up. These could be replaced by default values in the\n -- record declaration.\n --\n Temp_Entry.First_Entry := null;\n Temp_Entry.Count := 0;\n Temp_Entry.Free_List := null;\n Temp_Entry.Free_List_Count := 0;\n\n -- DEFECT 262 set Stepping_Pointer to null.\n Temp_Entry.Stepping_Pointer := null;\n\n return Temp_Entry; \n\n end Initialise;\n\n ---------------------------------------------------------------------\n\n function Count_Of (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Count;\n end Count_Of;\n\n ---------------------------------------------------------------------\n\n function Count_Of_Free_List (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Free_List_Count;\n end Count_Of_Free_List;\n\n ---------------------------------------------------------------------\n\n function Max_Count_Of (Target_List : List_Header_Access_Type) return Application_Types.Base_Integer_Type is\n begin\n return Target_List.Max_Count;\n end Max_Count_Of;\n\n ---------------------------------------------------------------------\n\n function First_Entry_Of (Target_List : List_Header_Access_Type) return Node_Access_Type is\n begin\n Target_List.Stepping_Pointer := Target_List.First_Entry;\n return Target_List.Stepping_Pointer;\n end First_Entry_Of;\n\n ---------------------------------------------------------------------\n\n function Next_Entry_Of (Target_List : List_Header_Access_Type) return Node_Access_Type is\n begin\n Target_List.Stepping_Pointer := Target_List.Stepping_Pointer.Next;\n return Target_List.Stepping_Pointer;\n end Next_Entry_Of;\n\n ---------------------------------------------------------------------\n\n procedure Insert (New_Item : in Element_Type;\n On_To : in List_Header_Access_Type) is\n\n New_Cell: Node_Access_Type;\n\n begin\n\n if On_To.Free_List = null then\n -- \n -- there are no 'old' entries available for reuse\n --\n begin\n New_Cell:= new Node_Type;\n \n exception\n when Storage_Error => raise List_Storage_Error ;" + }, + { + "function_def": "procedure Register_M1_End_Class (M1_Instance: in Ada.Tags.Tag) is", + "function_body": "begin\n M1_Side := M1_Instance;\n M1_Single_M2_Multiple.Register_Single_End_Class (M1_Instance);\n M2_Single_M1_Multiple.Register_Multiple_End_Class (M1_Instance);\n end Register_M1_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_M1_End_Class return Ada.Tags.Tag is\n begin\n return M1_Side;\n end Report_M1_End_Class;\n\n-----------------------------------------------------------------------\n\n procedure Register_M2_End_Class (M2_Instance: in Ada.Tags.Tag) is\n begin\n M2_Side := M2_Instance;\n M1_Single_M2_Multiple.Register_Multiple_End_Class (M2_Instance);\n M2_Single_M1_Multiple.Register_Single_End_Class (M2_Instance);\n end Register_M2_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_M2_End_Class return Ada.Tags.Tag is\n begin\n return M2_Side;\n end Report_M2_End_Class;\n\n-----------------------------------------------------------------------\n\n procedure Register_Associative_End_Class (Associative_Instance: in Ada.Tags.Tag) is\n begin\n Associative_Side := Associative_Instance;\n M1_Single_M2_Multiple.Register_Associative_End_Class (Associative_Instance);\n M2_Single_M1_Multiple.Register_Associative_End_Class (Associative_Instance);\n end Register_Associative_End_Class;\n\n---------------------------------------------------------------------\n\n function Report_Associative_End_Class return Ada.Tags.Tag is\n begin\n return Associative_Side;\n end Report_Associative_End_Class;\n\n---------------------------------------------------------------------\n\n procedure Link (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n Using : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Link (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n Using => Using);\n\n M2_Single_M1_Multiple.Link (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n Using => Using);\n\n end Link;\n-----------------------------------------------------------------------\n procedure Unassociate (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n From : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Unassociate (\n A_Instance => A_Instance,\n B_Instance => B_Instance,\n From => From);\n\n M2_Single_M1_Multiple.Unassociate (\n A_Instance => B_Instance,\n B_Instance => A_Instance,\n From => From);\n\n end Unassociate;\n\n-----------------------------------------------------------------------\n\n procedure Unlink (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access) is\n\n begin\n\n M1_Single_M2_Multiple.Unlink (\n A_Instance => A_Instance,\n B_Instance => B_Instance);\n\n M2_Single_M1_Multiple.Unlink (\n A_Instance => B_Instance,\n B_Instance => A_Instance);\n\n end Unlink;\n\n-----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_List.List_Header_Access_Type;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n The_A_Instance: Root_Object.Object_Access;\n\n begin\n\n The_A_Instance := Root_Object.Object_List.First_Entry_Of (From).Item;\n\n if The_A_Instance /= null then\n\n if The_A_Instance.all'tag = M1_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif The_A_Instance.all'tag = M2_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif The_A_Instance.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n end if;\n\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n --\n -- navigate from a single to a set\n -- valid for:\n -- M1 -> M2\n -- M1 -> A\n -- M2 -> M1\n -- M2 -> A\n --\n begin\n\n if From.all'tag = M1_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif From.all'tag = M2_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif From.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n --\n -- navigate from a single to a single\n -- valid for:\n -- A -> M1\n -- A -> M2\n --\n begin\n\n if From.all'tag = Associative_Side then\n\n if Class = M2_Side then\n\n M1_Single_M2_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n elsif Class = M1_Side then\n\n M2_Single_M1_Multiple.Navigate (\n From => From,\n Class => Class,\n To => To);\n\n end if;\n\n end if;\n\n\n end Navigate;\n\n---------------------------------------------------------------------\n\n\n -- associative correlated navigation\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Also : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n --\n -- navigate from two singles to a single\n -- valid for:\n -- M1 and M2 -> A\n -- M1 and M2 -> A\n\n Temp_Associative_One, Temp_Associative_Two : Root_Object.Object_Access := null;\n\n Assoc_Set_One : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n Assoc_Set_Two : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n\n Matched, Inner_Matched : Boolean := FALSE;\n\n begin\n\n -- Reset the output pointer to null so that if we don't find anything\n -- useful, the caller can check for it.\n To := null;\n\n if ((( From.all'tag = M1_Side) and then\n ( Also.all'Tag = M2_Side))\n or else (( From.all'tag = M2_Side) and then\n ( Also.all'Tag = M1_Side)))\n then\n\n -- Navigate from single instance of first object\n -- returns a set.\n Navigate (\n From => Also,\n Class => Class,\n To => Assoc_Set_One);\n\n -- Navigate from single instance of second object\n -- returns a set.\n Navigate (\n From => From,\n Class => Class,\n To => Assoc_Set_Two);\n\n -- Compare results of the two sets from the above navigations.\n -- A nice simple find operation on a set would be appropriate here, but\n -- there isn't one available, so do it the hard way.\n\n -- Outer loop\n declare\n use type Root_Object.Object_List.Node_Access_Type;\n Temp_Entry : Root_Object.Object_List.Node_Access_Type;\n Matched : boolean := FALSE;\n begin\n -- Grab the first entry of the set\n Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_One);\n -- While the set is not empty and the entry does not match the\n -- assoc instance already found, burn rubber\n\n while (not Matched) and (Temp_Entry /= null) loop\n\n Temp_Associative_One := Temp_Entry.Item;\n -- Compare this entry against the other set.\n\n -- Inner loop\n declare\n use type Root_Object.Object_List.Node_Access_Type;\n Inner_Temp_Entry : Root_Object.Object_List.Node_Access_Type;\n begin\n\n -- Grab the first entry of the set\n Inner_Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_Two);\n\n -- While the set is not empty and the entry does not match the\n -- assoc instance already found, smoke 'em\n\n while (not matched) and (Inner_Temp_Entry /= null) loop\n\n\t\t\t\t\t\t\tTemp_Associative_Two := Inner_Temp_Entry.Item;\n -- If M-M:M associative was ever implemented,\n -- it would be easy to add the matched instance into a set for\n -- return from this procedure.\n\n\t\t\t\t\t\t\tMatched := Temp_Associative_One = Temp_Associative_Two;\n\n\t\t\t\t\t\t\tif not Matched then\n Inner_Temp_Entry := Root_Object.Object_List.Next_Entry_Of(Assoc_Set_Two);\n end if;\n\n end loop; -- end of (Temp_Entry /= null) or else Matched loop" + }, + { + "function_def": "procedure Remove_Pair is new Ada.Unchecked_Deallocation (", + "function_body": "Relationship_Pair_Type, Relationship_Pair_Access_Type);\n\n --\n -- 'Major' element\n --\n type Relationship_Entry_Type;\n type Relationship_Entry_Access_Type is access all Relationship_Entry_Type;\n\n type Relationship_Entry_Type is record\n Single : Root_Object.Object_Access;\n Completion_List : Relationship_Pair_Access_Type;\n Next : Relationship_Entry_Access_Type;\n Previous : Relationship_Entry_Access_Type;\n end record;\n\n procedure Remove_Entry is new Ada.Unchecked_Deallocation (\n Relationship_Entry_Type, Relationship_Entry_Access_Type);\n\n ------------------------------------------------------------------------\n The_Relationship_List: Relationship_Entry_Access_Type;\n\n\n subtype Role_Phrase_Type is string (1 .. Application_Types.Maximum_Number_Of_Characters_In_String);\n\n Multiple_Side : Ada.Tags.Tag;\n Multiple_Side_Role : Role_Phrase_Type;\n Multiple_Side_Role_Length : Natural;\n\n Single_Side : Ada.Tags.Tag;\n Single_Side_Role : Role_Phrase_Type;\n Single_Side_Role_Length : Natural;\n\n Associative_Side : Ada.Tags.Tag;\n Associative_Side_Role : Role_Phrase_Type;\n Associative_Side_Role_Length : Natural;\n --\n -- A = LEFT = MULTIPLE\n -- B = RIGHT = SINGLE\n --\n ------------------------------------------------------------------------\n procedure Check_List_For_Multiple (\n Multiple_Instance : in Root_Object.Object_Access;\n Associative_Instance : out Root_Object.Object_Access;\n Single_Instance : out Root_Object.Object_Access;\n Multiple_Instance_Found : out Boolean) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n\n begin\n\n\n Multiple_Instance_Found := False;\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while (not Multiple_Instance_Found) and then Temp_Major_Pointer /= null loop\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while (not Multiple_Instance_Found) and then Temp_Minor_Pointer /= null loop\n\n Multiple_Instance_Found := (Temp_Minor_Pointer.Multiple = Multiple_Instance);\n\n if Multiple_Instance_Found then\n Associative_Instance := Temp_Minor_Pointer.Associative;\n Single_Instance := Temp_Major_Pointer.Single;\n else\n -- Prevent access if we have got what we are after\n -- Bailing out of the search loop is a neater solution, but test team defects\n -- have been raised against this sort of thing.\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n end if;\n\n end loop Minor_Loop;\n\n -- Prevent the possibility that the next entry in the major queue is null causing an access error\n if not Multiple_Instance_Found then\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop Major_Loop;\n\n end Check_List_For_Multiple;\n\n ------------------------------------------------------------------------\n procedure Check_List_For_Associative (\n Associative_Instance : in Root_Object.Object_Access;\n Multiple_Instance : out Root_Object.Object_Access;\n Single_Instance : out Root_Object.Object_Access;\n Associative_Instance_Found : out Boolean) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n\n begin\n\n Associative_Instance_Found := False;\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while (not Associative_Instance_Found) and then Temp_Major_Pointer /= null loop\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while (not Associative_Instance_Found) and then Temp_Minor_Pointer /= null loop\n\n Associative_Instance_Found := (Temp_Minor_Pointer.Associative = Associative_Instance);\n\n if Associative_Instance_Found then\n Multiple_Instance := Temp_Minor_Pointer.Multiple;\n Single_Instance := Temp_Major_Pointer.Single;\n else\n -- Prevent access if we have got what we are after\n -- Bailing out of the search loop is a neater solution, but test team defects\n -- have been raised against this sort of thing.\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n end if;\n\n end loop Minor_Loop;\n\n -- Prevent the possibility that the next entry in the major queue is null causing an access error\n if not Associative_Instance_Found then\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop Major_Loop;\n\n end Check_List_For_Associative;\n\n -----------------------------------------------------------------------\n\n procedure Do_Link (\n Multiple_Instance : in Root_Object.Object_Access;\n Single_Instance : in Root_Object.Object_Access;\n Associative_Instance : in Root_Object.Object_Access) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n Found : Boolean := False;\n\n begin\n Temp_Major_Pointer := The_Relationship_List;\n\n while (not Found) and then Temp_Major_Pointer /= null loop\n\n Found := (Temp_Major_Pointer.Single = Single_Instance);\n\n if not Found then -- grab the next item\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n end if;\n\n end loop;\n\n if not Found then\n Temp_Major_Pointer := new Relationship_Entry_Type;\n Temp_Major_Pointer.Single := Single_Instance;\n Temp_Major_Pointer.Completion_List := null;\n Temp_Major_Pointer.Previous := null;\n Temp_Major_Pointer.Next := The_Relationship_List;\n\n if The_Relationship_List /= null then\n The_Relationship_List.Previous := Temp_Major_Pointer;\n end if;\n\n The_Relationship_List := Temp_Major_Pointer;\n\n end if;\n\n Temp_Minor_Pointer := new Relationship_Pair_Type;\n Temp_Minor_Pointer.Multiple := Multiple_Instance;\n Temp_Minor_Pointer.Associative := Associative_Instance;\n Temp_Minor_Pointer.Previous := null;\n Temp_Minor_Pointer.Next := Temp_Major_Pointer.Completion_List;\n\n if Temp_Major_Pointer.Completion_List /= null then\n Temp_Major_Pointer.Completion_List.Previous := Temp_Minor_Pointer;\n end if;\n\n Temp_Major_Pointer.Completion_List := Temp_Minor_Pointer;\n\n end Do_Link;\n\n -----------------------------------------------------------------------\n\n procedure Do_Unlink (\n Left_Instance : in Root_Object.Object_Access;\n Right_Instance : in Root_Object.Object_Access) is\n\n Temp_Minor_Pointer : Relationship_Pair_Access_Type;\n Temp_Major_Pointer : Relationship_Entry_Access_Type;\n Delete_List : Boolean := False;\n\n begin\n\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n while Temp_Major_Pointer /= null loop\n\n if Temp_Major_Pointer.Single = Left_Instance then\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n while Temp_Minor_Pointer /= null loop\n if Temp_Minor_Pointer.Multiple = Right_Instance then\n if Temp_Minor_Pointer.Previous = null then\n --\n -- first instance in list\n --\n Temp_Major_Pointer.Completion_List := Temp_Minor_Pointer.Next;\n --\n -- it's also the last and only instance in list\n -- So we're going to delete the whole relationship instance\n -- (but not just yet)\n --\n Delete_List := (Temp_Minor_Pointer.Next = null);\n\n end if;\n\n if Temp_Minor_Pointer.Next /= null then\n --\n -- there are more instances following in the list\n --\n Temp_Minor_Pointer.Next.Previous := Temp_Minor_Pointer.Previous;\n end if;\n\n if Temp_Minor_Pointer.Previous /= null then\n --\n -- there are more instances previous in the list\n --\n Temp_Minor_Pointer.Previous.Next := Temp_Minor_Pointer.Next;\n end if;\n\n Remove_Pair (Temp_Minor_Pointer);\n exit Major_Loop;\n\n end if;\n\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n\n end loop Minor_Loop;\n\n end if;\n\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n\n end loop Major_Loop;\n --\n -- if needed, now delete the list\n -- the same logic applies\n --\n if Delete_List then\n\n if Temp_Major_Pointer.Previous = null then\n --\n -- first instance in list\n --\n The_Relationship_List := Temp_Major_Pointer.Next;\n end if;\n\n if Temp_Major_Pointer.Next /= null then\n --\n -- there are more instances following in the list\n --\n Temp_Major_Pointer.Next.Previous := Temp_Major_Pointer.Previous;\n end if;\n\n if Temp_Major_Pointer.Previous /= null then\n --\n -- there are more instances previous in the list\n --\n Temp_Major_Pointer.Previous.Next := Temp_Major_Pointer.Next;\n end if;\n\n Remove_Entry (Temp_Major_Pointer);\n\n end if;\n\n end Do_Unlink;\n\n -------------------------------------------------------------------------\n procedure Register_Multiple_End_Class (Multiple_Instance : in Ada.Tags.Tag) is\n begin\n Multiple_Side := Multiple_Instance;\n end Register_Multiple_End_Class;\n\n ---------------------------------------------------------------------\n procedure Register_Multiple_End_Role (Multiple_Role : in String) is\n begin\n Multiple_Side_Role (1 .. Multiple_Role'Length) := Multiple_Role;\n Multiple_Side_Role_Length := Multiple_Role'Length;\n end Register_Multiple_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Register_Single_End_Class (Single_Instance : in Ada.Tags.Tag) is\n begin\n Single_Side := Single_Instance;\n end Register_Single_End_Class;\n\n ---------------------------------------------------------------------\n\n procedure Register_Single_End_Role (Single_Role : in String) is\n begin\n\n Single_Side_Role (1..Single_Role'Length) := Single_Role;\n Single_Side_Role_Length := Single_Role'Length;\n end Register_Single_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Register_Associative_End_Class (Associative_Instance : in Ada.Tags.Tag) is\n begin\n Associative_Side := Associative_Instance;\n end Register_Associative_End_Class;\n\n ---------------------------------------------------------------------\n\n procedure Register_Associative_End_Role (Associative_Role : in String) is\n begin\n Associative_Side_Role (1 .. Associative_Role'Length) := Associative_Role;\n Associative_Side_Role_Length := Associative_Role'Length;\n end Register_Associative_End_Role;\n\n ---------------------------------------------------------------------\n\n procedure Link (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n Using : in Root_Object.Object_Access) is\n\n begin\n\n if Using.all'Tag = Associative_Side then\n\n if A_Instance.all'Tag = Multiple_Side then\n\n Do_Link (\n Multiple_Instance => A_Instance,\n Single_Instance => B_Instance,\n Associative_Instance => Using);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships + 1;\n\n elsif A_Instance.all'Tag = Single_Side then\n\n Do_Link (\n Multiple_Instance => B_Instance,\n Single_Instance => A_Instance,\n Associative_Instance => Using);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships + 1;\n\n end if;\n end if; -- Using.all'tag /= Associative_Side\n\n end Link;\n\n -----------------------------------------------------------------------\n\n procedure Unassociate (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access;\n From : in Root_Object.Object_Access) is\n begin\n null;\n end Unassociate;\n\n -----------------------------------------------------------------------\n\n procedure Unlink (\n A_Instance : in Root_Object.Object_Access;\n B_Instance : in Root_Object.Object_Access) is\n\n begin\n\n if A_Instance.all'Tag = Multiple_Side then\n\n Do_Unlink (\n Left_Instance => B_Instance,\n Right_Instance => A_Instance);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships - 1;\n\n elsif A_Instance.all'Tag = Single_Side then\n --\n Do_Unlink (\n Left_Instance => A_Instance,\n Right_Instance => B_Instance);\n --\n -- PILOT_0000_0423 Include diagnostic references.\n --\n Application_Types.Count_Of_Relationships := Application_Types.Count_Of_Relationships - 1;\n\n end if;\n\n end Unlink;\n\n -----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_List.List_Header_Access_Type;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n Source_Instance: Root_Object.Object_Access;\n Temp_Node: Root_Object.Object_List.Node_Access_Type;\n Temp_Instance: Root_Object.Object_Access;\n --Temp_Single: Root_Object.Object_Access;\n --Temp_Associative: Root_Object.Object_Access;\n --Temp_Multiple: Root_Object.Object_Access;\n\n begin\n\n Temp_Node := Root_Object.Object_List.First_Entry_Of (From);\n\n while Temp_Node /= null loop\n\n Source_Instance := Temp_Node.Item;\n\n if Source_Instance.all'Tag = Multiple_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => Temp_Instance);\n\n if Temp_Instance /= null then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Instance,\n On_To => To );\n\n end if;\n --\n elsif Source_Instance.all'Tag = Single_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => To);\n --\n\n elsif Source_Instance.all'Tag = Associative_Side then\n\n Navigate (\n From => Source_Instance,\n Class => Class,\n To => Temp_Instance);\n\n if Temp_Instance /= null then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Instance,\n On_To => To );\n\n end if;\n --\n\n end if;\n\n Temp_Node := Root_Object.Object_List.Next_Entry_Of (From);\n\n end loop;\n\n end Navigate;\n\n -----------------------------------------------------------------------\n\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n --\n -- navigate from a single to a single\n -- valid for:\n -- A -> M\n -- A -> S\n -- M -> S\n -- M -> A\n --\n Temp_Single: Root_Object.Object_Access;\n Temp_Associative: Root_Object.Object_Access;\n Temp_Multiple: Root_Object.Object_Access;\n Found: Boolean;\n\n begin\n\n -- PILOT_0000_1422\n -- Defaulting the return parameter ensures that if an attempt\n -- is made to navigate this type of one to many associative\n -- without having linked it, the correct null parameter is\n -- returned. This relationship mechanism relies on the link\n -- operation to sort out all the tags. We can't rely on that\n -- happening in all cases.\n To := null;\n\n if From.all'Tag = Multiple_Side then\n --\n\n Check_List_For_Multiple (\n Multiple_Instance => From,\n Associative_Instance => Temp_Associative,\n Single_Instance => Temp_Single,\n Multiple_Instance_Found => Found);\n\n if Found then\n --\n if Class = Single_Side then\n\n To := Temp_Single;\n\n\n elsif Class = Associative_Side then\n\n To := Temp_Associative;\n\n end if;\n --\n\n end if;\n --\n\n elsif From.all'Tag = Associative_Side then\n\n\n Check_List_For_Associative (\n Associative_Instance => From,\n Multiple_Instance => Temp_Multiple,\n Single_Instance => Temp_Single,\n Associative_Instance_Found => Found);\n\n if Found then\n --\n if Class = Single_Side then\n\n To := Temp_Single;\n\n elsif Class = Multiple_Side then\n\n To := Temp_Multiple;\n\n end if;\n\n end if;\n\n end if;\n\n end Navigate;\n\n ---------------------------------------------------------------------\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : in Root_Object.Object_List.List_Header_Access_Type) is\n\n --\n -- navigate from a single to a set\n -- valid for:\n -- S -> M\n -- S -> A\n --\n\n Temp_Minor_Pointer: Relationship_Pair_Access_Type;\n Temp_Major_Pointer: Relationship_Entry_Access_Type;\n\n begin\n\n if From.all'Tag = Single_Side then\n\n Temp_Major_Pointer := The_Relationship_List;\n\n Major_Loop:\n\n while Temp_Major_Pointer /= null loop\n\n if Temp_Major_Pointer.Single = From then\n\n Temp_Minor_Pointer := Temp_Major_Pointer.Completion_List;\n\n Minor_Loop:\n\n while Temp_Minor_Pointer /= null loop\n\n if Class = Multiple_Side then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Minor_Pointer.Multiple,\n On_To => To);\n\n elsif Class = Associative_Side then\n\n Root_Object.Object_List.Insert (\n New_Item => Temp_Minor_Pointer.Associative,\n On_To => To);\n\n end if;\n\n Temp_Minor_Pointer := Temp_Minor_Pointer.Next;\n\n end loop Minor_Loop;\n\n exit Major_Loop;\n\n end if;\n\n Temp_Major_Pointer := Temp_Major_Pointer.Next;\n\n end loop Major_Loop;\n --\n end if;\n\n end Navigate;\n\n\n------------------------------------------------------------------------\n\n\n -- associative correlated navigation\n procedure Navigate (\n From : in Root_Object.Object_Access;\n Also : in Root_Object.Object_Access;\n Class : in Ada.Tags.Tag;\n To : out Root_Object.Object_Access) is\n\n\n -- navigate from two singles to a single\n -- valid for:\n -- M and S -> A\n -- S and M -> A\n\n Temp_Single,\n Single_Side_Source ,\n Multiple_Side_Source,\n Temp_Associative_Multiple,\n Temp_Associative_Single : Root_Object.Object_Access := null;\n\n Assoc_Set : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;\n\n Found,\n Tags_Correct : Boolean := FALSE;\n\n begin\n\n -- Reset the output pointer to null so that if we don't find anything\n -- useful, the caller can check for it.\n To := null;\n\n Tags_Correct := ((( From.all'Tag = Multiple_Side) and then\n ( Also.all'Tag = Single_Side))\n or else ((( From.all'Tag = Single_Side) and then\n ( Also.all'Tag = Multiple_Side)))) ;\n\n if Tags_Correct then\n\n if From.all'Tag = Multiple_Side then\n\n Multiple_Side_Source := From;\n Single_Side_Source := Also;\n else\n Multiple_Side_Source := Also;\n Single_Side_Source := From;\n end if;\n\n -- Do the navigations now, all is correct.\n\n -- Navigate from multiple side to associative side.\n Check_List_For_Multiple (\n Multiple_Instance => Multiple_Side_Source,\n Associative_Instance => Temp_Associative_Multiple,\n Single_Instance => Temp_Single,\n Multiple_Instance_Found => Found);\n\n\n -- Navigate from single side to associative side.\n if Found then\n\n -- do the navigation\n\n declare\n Input_List : Root_Object.Object_List.List_Header_Access_Type;\n begin\n Input_List := Root_Object.Object_List.Initialise;\n\n Root_Object.Object_List.Clear(Assoc_Set);\n\n Root_Object.Object_List.Insert (\n New_Item => Single_Side_Source,\n On_To => Input_List);\n\n Navigate(\n From => Input_List,\n Class => Class,\n To => Assoc_Set);\n\n Root_Object.Object_List.Destroy_List(Input_List);" + }, + { + "function_def": "function distance(p : in Position) return Natural is", + "function_body": "begin\n return abs(p.x) + abs(p.y);\n end distance;\n\n function hash(p : in Position) return Ada.Containers.Hash_Type is\n begin\n return Ada.Strings.Hash(p.x'IMAGE & \",\" & p.y'IMAGE);\n end hash;\n\n function equivalent_positions(left, right: Position) return Boolean is\n begin\n return (left.x = right.x) and then (left.y = right.y);\n end equivalent_positions;\n\n -- function \"=\" (left : in Position; right : in Position) return Boolean is\n -- begin\n -- return (left.x = right.x) and (left.y = right.y);\n -- end \"=\";\n\n function to_string(wp : in Wire_Points.Set) return String is\n package Unbounded renames Ada.Strings.Unbounded;\n s : Unbounded.Unbounded_String;\n begin\n for elt of wp loop\n Unbounded.append(s, to_string(elt) & \", \");\n end loop;\n return Unbounded.to_string(s);\n end to_string;\n\n function to_string(ws : in Wire_Segment) return String is\n begin\n return to_string(ws.dir) & Integer'Image(ws.distance);\n end to_string;\n\n function to_string(w : in Wire.Vector) return String is\n package Unbounded renames Ada.Strings.Unbounded;\n s : Unbounded.Unbounded_String;\n begin\n for elt of w loop\n Unbounded.append(s, to_string(elt) & \", \");\n end loop;\n return Unbounded.to_string(s);\n end to_string;\n\n procedure parse_wire(w_str : in String; w : in out Wire.Vector) is\n start : Natural := w_str'First;\n finish : Natural;\n delimiters : constant Ada.Strings.Maps.Character_Set := Ada.Strings.Maps.to_set(Sequence => \",\");\n begin\n w.clear;\n while start <= w_str'Last loop\n Ada.Strings.Fixed.find_token(Source => w_str(start .. w_str'Last),\n Set => delimiters,\n Test => Ada.Strings.outside,\n First => start, Last => finish);\n if not(finish = 0 and then start = w_str'First) then\n w.append((dir => to_dir(w_str(start)), distance => Integer'Value(w_str(start+1 .. finish))));\n end if;\n start := finish + 1;\n end loop;\n end parse_wire;\n\n procedure step(pos : in out Position; dir : in Direction) is\n begin\n case dir is\n when Up => pos := (x => pos.x, y => pos.y - 1, dist => pos.dist + 1);\n when Down => pos := (x => pos.x, y => pos.y + 1, dist => pos.dist + 1);\n when Left => pos := (x => pos.x - 1, y => pos.y, dist => pos.dist + 1);\n when Right => pos := (x => pos.x + 1, y => pos.y, dist => pos.dist + 1);\n end case;\n end step;\n\n procedure expand(pos : in out Position; segment : in Wire_Segment; points : in out Wire_Points.Set) is\n begin\n for i in 1 .. segment.distance loop\n step(pos => pos, dir => segment.dir);\n points.include(pos);\n end loop;\n end expand;\n\n procedure expand_segments(w : in Wire.Vector; points : in out Wire_Points.Set) is\n start_pos : constant Position := (x => 0, y => 0, dist => 0);\n curr_pos : Position := start_pos;\n begin\n points.clear;\n for segment of w loop\n expand(pos => curr_pos, segment => segment, points => points);\n end loop;\n end expand_segments;\n\n procedure load(w1 : in String; w2 : in String) is\n begin\n parse_wire(w1, wire_1);\n expand_segments(wire_1, wire_points_1);\n parse_wire(w2, wire_2);\n expand_segments(wire_2, wire_points_2);\n end load;\n\n procedure load_file(path : String) is\n file : TIO.File_Type;\n begin\n TIO.open(File => file, Mode => TIO.In_File, Name => path);\n declare\n str1 : constant String := TIO.get_line(file);\n str2 : constant String := TIO.get_line(file);\n begin\n load(w1 => str1, w2 => str2);" + }, + { + "function_def": "procedure Ping is", + "function_body": "use type Interfaces.Unsigned_32;\n use type Net.Ip_Addr;\n use type Net.DHCP.State_Type;\n use type Ada.Real_Time.Time;\n use type Ada.Real_Time.Time_Span;\n\n procedure Refresh;\n procedure Header;\n\n procedure Refresh is\n Y : Natural := 90;\n Hosts : constant Pinger.Ping_Info_Array := Pinger.Get_Hosts;\n begin\n for I in Hosts'Range loop\n Demos.Put (0, Y, Net.Utils.To_String (Hosts (I).Ip));\n Demos.Put (250, Y, Net.Uint64 (Hosts (I).Seq));\n Demos.Put (350, Y, Net.Uint64 (Hosts (I).Received));\n Y := Y + 16;\n end loop;\n Demos.Refresh_Ifnet_Stats;\n STM32.Board.Display.Update_Layer (1);\n end Refresh;\n\n procedure Header is\n begin\n Demos.Put (0, 70, \"Host\");\n Demos.Put (326, 70, \"Send\");\n Demos.Put (402, 70, \"Receive\");\n end Header;\n\n procedure Initialize is new Demos.Initialize (Header);\n\n -- The ping period.\n PING_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (1000);\n\n -- Send ping echo request deadline\n Ping_Deadline : Ada.Real_Time.Time;\n\n Icmp_Handler : Net.Protos.Receive_Handler;\nbegin\n Initialize (\"STM32 Ping\");\n\n Pinger.Add_Host ((192, 168, 1, 1));\n Pinger.Add_Host ((8, 8, 8, 8));\n Net.Protos.Dispatchers.Set_Handler (Proto => Net.Protos.IPv4.P_ICMP,\n Handler => Pinger.Receive'Access,\n Previous => Icmp_Handler);\n\n -- Change font to 8x8.\n Demos.Current_Font := BMP_Fonts.Font8x8;\n Ping_Deadline := Ada.Real_Time.Clock;\n loop\n declare\n Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;\n Dhcp_Deadline : Ada.Real_Time.Time;\n begin\n Net.Protos.Arp.Timeout (Demos.Ifnet);\n Demos.Dhcp.Process (Dhcp_Deadline);\n if Demos.Dhcp.Get_State = Net.DHCP.STATE_BOUND then\n Pinger.Add_Host (Demos.Dhcp.Get_Config.Router);\n Pinger.Add_Host (Demos.Dhcp.Get_Config.Dns1);\n Pinger.Add_Host (Demos.Dhcp.Get_Config.Dns2);\n Pinger.Add_Host (Demos.Dhcp.Get_Config.Ntp);\n Pinger.Add_Host (Demos.Dhcp.Get_Config.Www);\n end if;\n if Ping_Deadline < Now then\n Pinger.Do_Ping;\n Refresh;\n Ping_Deadline := Ping_Deadline + PING_PERIOD;\n end if;\n if Ping_Deadline < Dhcp_Deadline then\n delay until Ping_Deadline;\n else\n delay until Dhcp_Deadline;\n end if;" + }, + { + "function_def": "function Check_Monster_Collision return Boolean;", + "function_body": "--------------\n -- Collides --\n --------------\n\n function Collides (Points : Collision_Points) return Boolean is\n X : constant Integer := Integer (P.Position.X);\n Y : constant Integer := Integer (P.Position.Y);\n begin\n for Pt of Points loop\n\n if Show_Collision_Points then\n declare\n Data : aliased HAL.UInt16_Array := (0 => 0);\n begin\n PyGamer.Screen.Set_Address (UInt16 (X + Pt.X),\n UInt16 (X + Pt.X),\n UInt16 (Y + Pt.Y),\n UInt16 (Y + Pt.Y));\n PyGamer.Screen.Start_Pixel_TX;\n PyGamer.Screen.Push_Pixels (Data'Address, Data'Length);\n PyGamer.Screen.End_Pixel_TX;" + }, + { + "function_def": "function Check_Monster_Collision return Boolean is", + "function_body": "X : constant Integer := Integer (P.Position.X);\n Y : constant Integer := Integer (P.Position.Y);\n begin\n for Pt of Bounding_Box loop\n if Monsters.Check_Hit ((X + Pt.X,\n Y + Pt.Y),\n Lethal => False)\n then\n return True;\n end if;\n end loop;\n return False;\n end Check_Monster_Collision;\n\n -----------\n -- Spawn --\n -----------\n\n procedure Spawn is\n begin\n P.Alive := True;\n P.Set_Mass (Value (90.0));\n P.Sprite.Flip_Vertical (False);\n P.Set_Speed ((0.0, 0.0));\n GESTE.Add (P.Sprite'Access, 3);\n P.Sprite.Flip_Horizontal (True);\n\n for Prj of Projs loop\n Prj.Init;\n end loop;\n end Spawn;\n\n ----------\n -- Move --\n ----------\n\n procedure Move (Pt : GESTE.Pix_Point) is\n begin\n P.Set_Position (GESTE.Maths_Types.Point'(Value (Pt.X), Value (Pt.Y)));\n P.Sprite.Move ((Integer (P.Position.X) - 4,\n Integer (P.Position.Y) - 4));\n end Move;\n\n --------------\n -- Position --\n --------------\n\n function Position return GESTE.Pix_Point\n is ((Integer (P.Position.X), Integer (P.Position.Y)));\n\n --------------\n -- Is_Alive --\n --------------\n\n function Is_Alive return Boolean\n is (P.Alive);\n\n ------------\n -- Update --\n ------------\n\n procedure Update is\n Old : constant Point := P.Position;\n Elapsed : constant Value := Value (1.0 / 60.0);\n\n Collision_To_Fix : Boolean;\n begin\n -- Check collision with monsters\n if Check_Monster_Collision then\n P.Sprite.Flip_Vertical (True);\n P.Alive := False;\n end if;\n\n if Going_Right then\n Facing_Left := False;\n P.Sprite.Flip_Horizontal (True);\n elsif Going_Left then\n Facing_Left := True;\n P.Sprite.Flip_Horizontal (False);\n end if;\n\n -- Lateral movements\n if Grounded then\n if Going_Right then\n P.Apply_Force ((14_000.0, 0.0));\n elsif Going_Left then\n P.Apply_Force ((-14_000.0, 0.0));\n else\n -- Friction on the floor\n P.Apply_Force (\n (Value (Value (-2000.0) * P.Speed.X),\n 0.0));\n end if;\n else\n if Going_Right then\n P.Apply_Force ((7_000.0, 0.0));\n\n elsif Going_Left then\n P.Apply_Force ((-7_000.0, 0.0));\n\n end if;\n end if;\n\n -- Gavity\n if not Grounded then\n P.Apply_Gravity (Value (-500.0));\n end if;\n\n -- Wall grab\n if not Grounded\n\n and then\n P.Speed.Y > 0.0 -- Going down\n\n and then\n -- Pushing against a wall\n ((Collides (Right_Wall))\n or else\n (Collides (Left_Wall)))\n then\n\n -- Friction against the wall\n P.Apply_Force ((0.0, -4_0000.0));\n\n Grabing_Wall := True;\n else\n Grabing_Wall := False;\n end if;\n\n -- Jump\n if Do_Jump then\n declare\n Jmp_X : Value := 0.0;\n begin\n if Grabing_Wall then\n -- Wall jump\n Jmp_X := 215_000.0;\n if Collides (Right_Wall) then\n Jmp_X := -Jmp_X;\n end if;\n end if;\n\n P.Apply_Force ((Jmp_X, -900_000.0));\n Grounded := False;\n Jumping := True;\n Sound.Play_Jump;" + }, + { + "function_def": "procedure Main_Ada_2048 is", + "function_body": "WIDTH : constant := 800;\n HEIGHT : constant := 600;\n\n SDL_WINDOWPOS_UNDEFINED : constant := 16#1FFF_0000#;\n\n\n package RC_Window is new My_RC(T => Windows,\n T_Access => Windows_Pointer,\n Free_T => SDL_DestroyWindow);\n\n package RC_Render is new My_RC(T => Renderers,\n T_Access => Renderer_Pointer,\n Free_T => SDL_DestroyRenderer);\n\n Window : RC_Window.Object;\n Render : RC_Render.Object;\n Title : RC_CString.RC_CString;\n\n Font_Path : RC_CString.RC_CString;\n\n discard : Boolean;\nbegin\n Title.make(\"Ada 2048\");\n Font_Path.make(\"/usr/share/fonts/TTF/NotoSansCJK.ttc\");\n\n if SDL_Init = true then\n discard := TTF_Init;\n Open_Font(TTF_OpenFont(Font_Path.To_C, 24));\n\n RC_Window.Set(window, SDL_CreateWindow(Title.To_C,\n SDL_WINDOWPOS_UNDEFINED,\n SDL_WINDOWPOS_UNDEFINED,\n WIDTH, HEIGHT, Shown or Resizable));\n\n RC_Render.Set(render, SDL_CreateRenderer(window.Get,\n Interfaces.C.int(-1),\n SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC));\n\n\n declare\n r : Renderer_Pointer := render.Get;\n\n running : Boolean := true;\n event : World_Machine.Events.Events;\n begin\n World_Machine.View.Clean_Screen(r);\n World_Machine.View.Start_Screen(r);\n\n while running loop\n event := Press_Event;\n running := Mode.Dispatch(r, event);\n end loop;" + }, + { + "function_def": "procedure Main_Operations is", + "function_body": "Time_Interval : constant Time_Span := Measure_Interval; -- Time since last call\n FrameRate : constant Natural := Natural (Average_Framerate (Time_Interval));\n Time_Interval_Real : constant Real := Real (To_Duration (Time_Interval));\n\n Commands : Commands_Array := Command_Set_Reset;\n\n begin\n Framerate_Limiter (Intented_Framerate);\n\n Get_Keys (Commands);\n\n case Camera_Mode is\n when Scene =>\n Execute_Commands.Act_On_Input (Cam.Scene_Offset, Cam.Rotation, Time_Interval_Real, Commands);\n case Camera_Mode is\n when Scene =>\n Cam.Position := Swarm_Monitor.Centre_Of_Gravity;\n when Chase =>\n Cam := Initial_Cams (Camera_Mode);\n end case;\n\n when Chase =>\n Execute_Commands.Act_On_Input (Cam.Object_Offset, Cam.Rotation, Time_Interval_Real, Commands);\n case Camera_Mode is\n when Scene => Cam := Initial_Cams (Camera_Mode);\n when Chase =>\n Cam.Position := Element (Swarm_State, 1).Position.all.Read;\n declare\n -- Element_Roll : constant Angle := Roll (Element (Swarm_State, 1).Rotation);\n Element_Pitch : constant Radiants := Pitch (Element (Swarm_State, 1).Rotation.all.Read);\n Element_Yaw : constant Radiants := Yaw (Element (Swarm_State, 1).Rotation.all.Read);\n begin\n Cam.Rotation := To_Rotation (0.0, 0.0, -Element_Yaw);\n Cam.Rotation := Rotate (Cam.Rotation, To_Rotation (0.0, -Element_Pitch, 0.0));\n -- Cam.Rotation := Rotate (Cam.Rotation, To_Rotation (-Element_Roll, 0.0, 0.0));" + }, + { + "function_def": "procedure Initialize is", + "function_body": "begin\n for Model in Model_Name loop\n case Model is\n-- when Arrow => Arrow_P.Create (object => Model_Set (Model), scale => 0.003, centre => (0.0, 0.0, 0.0));\n-- when Cube => Cube_P.Create (object => Model_Set (Model), scale => 0.015, centre => (0.0, 0.0, 0.0));\n-- when Duck => Duck_P.Create (object => Model_Set (Model), scale => 0.003, centre => (0.0, 0.0, 0.0));\n-- when Plane => Plane_P.Create (object => Model_Set (Model), scale => 0.003, centre => (0.0, 0.0, 0.0));\n when Spaceship => Spaceship_P.Create (Object => Model_Set (Model), Object_Scale => 0.003, Centre => (0.0, 0.0, 0.0)); Assign_Material (Model_Set (Model), Pearl);\n-- when Spaceship_Ruby => Spaceship_P.Create (object => Model_Set (Model), scale => 0.003, centre => (0.0, 0.0, 0.0)); Assign_Material (Model_Set (Model), Ruby);\n when Sphere => Sphere_P.Create (object => Model_Set (Model), Object_Scale => 0.015, centre => (0.0, 0.0, 0.0)); Assign_Material (Model_Set (Model), Ruby);\n end case;\n end loop;\n\n for M in Spaceship_Gradient'Range (1) loop\n for i in Spaceship_Gradient'Range (2) loop\n Spaceship_P.Create (Object => Spaceship_Gradient (M, i), Object_Scale => 0.003, Centre => (0.0, 0.0, 0.0));\n declare\n Ratio : constant Ratio_T :=\n ((Real (i) - Real (Spaceship_Gradient'First (2)))\n / Real (Spaceship_Gradient'Last (2) - Spaceship_Gradient'First (2)))\n + Ratio_T'First;\n begin\n case M is\n when G_Ruby => Assign_Material (Spaceship_Gradient (M, i), Blend_Material (Ruby, Pearl, Ratio));\n when G_Turquoise => Assign_Material (Spaceship_Gradient (M, i), Blend_Material (Turquoise, Pearl, Ratio));\n end case;" + }, + { + "function_def": "function Mean_Closest_Distance return Real is", + "function_body": "Acc_Distance : Real := 0.0;\n\n begin\n for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n declare\n This_Element : constant Swarm_Element_State := Element (Swarm_State, Element_Index);\n Neighbours : constant Distance_Vectors.Vector := This_Element.Neighbours.all;\n begin\n if Distance_Vectors.Length (Neighbours) > 0 then\n declare\n Closest_Distance : constant Real :=\n Distance_Vectors.Element (Neighbours, Distance_Vectors.First_Index (Neighbours)).Distance;\n begin\n Acc_Distance := Acc_Distance + Closest_Distance;" + }, + { + "function_def": "procedure Sorted_Close_Distances (Close_Dist : in out Distance_Vectors.Vector;", + "function_body": "Element_Index : Swarm_Element_Index;\n Max_Distance : Distances) is\n\n This_Element : constant Swarm_Element_State := Element (Swarm_State, Element_Index);\n This_Position : constant Positions := This_Element.Position.all.Read;\n\n begin\n Distance_Vectors.Clear (Close_Dist);\n Distance_Vectors.Reserve_Capacity (Close_Dist, Length (Swarm_State) - 1);\n for Scan_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n if Element_Index /= Scan_Index then\n declare\n Test_Element : constant Swarm_Element_State := Element (Swarm_State, Scan_Index);\n Test_Position : constant Positions := Test_Element.Position.all.Read;\n Test_Direction : constant Vector_3D := This_Position - Test_Position;\n Test_Distance : constant Distances := abs (Test_Direction);\n begin\n if Test_Distance <= Max_Distance then\n Distance_Vectors.Append (Close_Dist, (Index => Scan_Index,\n Distance => Test_Distance,\n Position_Diff => Test_Direction,\n Velocity_Diff => This_Element.Velocity.all.Read - Test_Element.Velocity.all.Read));\n end if;" + }, + { + "function_def": "procedure Set_All_Accelerations is", + "function_body": "begin\n for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n Set_Acceleration (Element_Index);\n end loop;\n end Set_All_Accelerations;\n\n --\n --\n --\n\n procedure Forward_Messages (Element_Index : Swarm_Element_Index) is\n\n This_Element : constant Swarm_Element_State := Element (Swarm_State, Element_Index);\n Message_To_Be_Distributed : Inter_Vehicle_Messages;\n\n begin\n while This_Element.Comms.all.Has_Outgoing_Messages loop\n This_Element.Comms.all.Fetch_Message (Message_To_Be_Distributed);\n Check_Neighbours : for Distance_Index in Distance_Vectors.First_Index (This_Element.Neighbours.all) .. Distance_Vectors.Last_Index (This_Element.Neighbours.all) loop\n declare\n Distance_Entry : constant Distance_Entries := Distance_Vectors.Element (This_Element.Neighbours.all, Distance_Index);\n begin\n if Distance_Entry.Distance <= Comms_Range then\n Element (Swarm_State, Distance_Entry.Index).Comms.all.Push_Message (Message_To_Be_Distributed);\n else\n exit Check_Neighbours;\n end if;" + }, + { + "function_def": "procedure Forward_All_Messages is", + "function_body": "begin\n for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n Forward_Messages (Element_Index);\n end loop;\n end Forward_All_Messages;\n\n --\n --\n --\n\n procedure Move_Element (Element_Index : Swarm_Element_Index) is\n\n This_Element : Swarm_Element_State := Element (Swarm_State, Element_Index);\n Interval : constant Real := Real'Min (Real (To_Duration (Clock - This_Element.Last_Update)), Max_Update_Interval);\n\n begin\n This_Element.Velocity.all.Write (This_Element.Velocity.all.Read + (Interval * This_Element.Acceleration.all.Read));\n\n declare\n Move_Start : constant Positions := This_Element.Position.all.Read;\n Move_End : constant Positions := Move_Start + (Interval * This_Element.Velocity.all.Read);\n begin\n This_Element.Position.all.Write (Move_End);\n\n This_Element.Charge.Level := Vehicle_Charges\n (Real'Max (Real (Empty_Charge),\n Real'Min (Real (Full_Charge),\n Real (This_Element.Charge.Level)\n - (Interval\n * (Charging_Setup.Constant_Discharge_Rate_Per_Sec\n + Charging_Setup.Propulsion_Discharge_Rate_Per_Sec * abs (This_Element.Acceleration.all.Read))))));\n\n for Globe_Ix in Globes'Range loop\n\n declare\n Globe_Pos : constant Positions := Globes (Globe_Ix).Position.all.Read;\n Interratio : constant Real := (Globe_Pos - Move_Start) * ((Move_End - Move_Start) / (abs (Move_End - Move_Start)));\n Intersection : constant Positions := Move_Start + Interratio * (Move_End - Move_Start);\n Touching : constant Boolean := abs (Intersection - Globe_Pos) <= Energy_Globe_Detection and then Interratio >= 0.0 and then Interratio <= 1.0;\n Slot_Passed : constant Boolean := Clock - This_Element.Charge.Charge_Time.all.Read > Charging_Setup.Max_Globe_Interval;\n begin\n if (not This_Element.Charge.Globes_Touched (Globe_Ix) or else Slot_Passed) and then Touching then\n\n if Slot_Passed then\n This_Element.Charge.Globes_Touched := No_Globes_Touched;\n This_Element.Charge.Charge_No := 0;\n end if;\n\n This_Element.Charge.Charge_No := This_Element.Charge.Charge_No + 1;\n This_Element.Charge.Globes_Touched (Globe_Ix) := True;\n This_Element.Charge.Charge_Time.all.Write (Clock);\n\n if This_Element.Charge.Charge_No = Charging_Setup.Globes_Required then\n This_Element.Charge.Level := Full_Charge;\n This_Element.Charge.Charge_No := 0;\n This_Element.Charge.Globes_Touched := No_Globes_Touched;\n end if;\n\n end if;" + }, + { + "function_def": "procedure Move_All_Elements is", + "function_body": "begin\n for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n Move_Element (Element_Index);\n end loop;\n end Move_All_Elements;\n\n --\n --\n --\n\n procedure Update_Rotation (Element_Index : Swarm_Element_Index) is\n\n function Vector_Yaw (In_Vector : Vector_3D) return Real is\n (if In_Vector (x) = 0.0 and then In_Vector (z) = 0.0\n then 0.0\n else Arctan (In_Vector (x), In_Vector (z)));\n\n function Vector_Pitch (In_Vector : Vector_3D) return Real is\n ((Pi / 2.0) - Angle_Between (In_Vector, (0.0, 1.0, 0.0)));\n\n This_Element : constant Swarm_Element_State := Element (Swarm_State, Element_Index);\n\n Velocity : constant Vector_3D := This_Element.Velocity.all.Read;\n Element_Yaw : constant Real := Vector_Yaw (Velocity);\n Element_Pitch : constant Real := Vector_Pitch (Velocity);\n\n Rotation : constant Quaternion_Rotation := To_Rotation (0.0, -Element_Pitch, Element_Yaw + Pi);\n Norm_Acc : constant Vector_3D := Rotate (This_Element.Acceleration.all.Read, Rotation);\n Lateral_Acc : constant Real := Norm_Acc (x) * abs (Velocity);\n Element_Roll : constant Real :=\n Real'Max (-Pi / 2.0,\n Real'Min (Pi / 2.0,\n Lateral_Acc * (Pi / 2.0) / Max_Assumed_Acceleration));\n\n begin\n This_Element.Rotation.all.Write (To_Rotation (Element_Roll, -Element_Pitch, -Element_Yaw + Pi));\n Replace_Element (Swarm_State, Element_Index, This_Element);\n end Update_Rotation;\n\n ---\n ---\n ---\n\n procedure Update_All_Rotations is\n\n begin\n for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop\n Update_Rotation (Element_Index);\n end loop;\n end Update_All_Rotations;\n\n --\n --\n --\n\n procedure Remove_Empties is\n\n begin\n if Length (Swarm_State) > 1 then\n declare\n Element_Index : Swarm_Element_Index := First_Index (Swarm_State);\n begin\n while Element_Index <= Last_Index (Swarm_State) and then Length (Swarm_State) > 1 loop\n if Element (Swarm_State, Element_Index).Charge.Level = Empty_Charge then\n Remove_Vehicle_in_Stages (Element_Index);\n else\n Element_Index := Element_Index + 1;\n end if;\n end loop;" + }, + { + "function_def": "procedure Distribute_Jobs (Job : Job_Type) is", + "function_body": "use Swarm_Vectors;\n\n First_Element_Ix : constant Swarm_Element_Index := First_Index (Swarm_State);\n Last_Element_Ix : constant Swarm_Element_Index := Last_Index (Swarm_State);\n No_Of_Elements : constant Swarm_Element_Index := Swarm_Element_Index (Length (Swarm_State));\n Elements_Per_Task : constant Swarm_Element_Index := Natural'Max (1, No_Of_Elements / No_Of_CPU_Cores);\n\n begin\n for Task_Index in Workers'First .. Workers'Last - 1 loop\n declare\n From_Ix : constant Integer := Swarm_Element_Index ((Integer (Task_Index) - Workers'First) * Elements_Per_Task + First_Element_Ix);\n To_Ix : constant Integer := Swarm_Element_Index ((Integer (Task_Index) - Workers'First + 1) * Elements_Per_Task + First_Element_Ix - 1);\n begin\n if From_Ix >= First_Element_Ix and then To_Ix <= Last_Element_Ix then\n Workers (Task_Index).Set_Job (Job, From_Ix, To_Ix);\n else\n Workers (Task_Index).Set_Job (No_Job, From_Ix, To_Ix);\n end if;" + }, + { + "function_def": "function Current_Discharge_Per_Sec return Real is", + "function_body": "(Charging_Setup.Constant_Discharge_Rate_Per_Sec + Charging_Setup.Propulsion_Discharge_Rate_Per_Sec * abs (Acceleration));\n\n function Energy_Globes_Around return Energy_Globes is\n\n Globes_Found : Natural := 0;\n Globes_Detected : array (Globes'Range) of Boolean := (others => False);\n This_Element_Position : constant Positions := Position;\n\n begin\n for Globe_Ix in Globes'Range loop\n if abs (This_Element_Position - Globes (Globe_Ix).Position.all.Read) <= Energy_Globe_Detection then\n Globes_Detected (Globe_Ix) := True;\n Globes_Found := Globes_Found + 1;\n end if;\n end loop;\n\n declare\n Found_Globes : Energy_Globes (1 .. Globes_Found);\n Found_Globes_Ix : Natural := Globes'First;\n begin\n for Globe_Ix in Globes'Range loop\n if Globes_Detected (Globe_Ix) then\n Found_Globes (Found_Globes_Ix) := (Position => Globes (Globe_Ix).Position.all.Read,\n Velocity => Globes (Globe_Ix).Velocity.all.Read);\n Found_Globes_Ix := Found_Globes_Ix + 1;\n end if;\n end loop;\n return Found_Globes;" + }, + { + "function_def": "function Cvt is new Ada.Unchecked_Conversion (I16, U16);", + "function_body": "function Cvt is new Ada.Unchecked_Conversion (I32, U32);\n function Cvt is new Ada.Unchecked_Conversion (U16, I16);\n function Cvt is new Ada.Unchecked_Conversion (U32, I32);\n\n generic\n type Number is mod <>;\n procedure Read_Intel_x86_number (sb : in out GL.IO.Input_buffer; n : out Number);\n\n procedure Read_Intel_x86_number (sb : in out GL.IO.Input_buffer; n : out Number) is\n b : U8;\n m : Number := 1;\n bytes : constant Integer := Number'Size / 8;\n begin\n n := 0;\n for i in 1 .. bytes loop\n GL.IO.Get_Byte (sb, b);\n n := n + m * Number (b);\n m := m * 256;\n end loop;\n end Read_Intel_x86_number;\n\n procedure Read_Double (\n sb : in out GL.IO.Input_buffer;\n n : out GL.Double\n) is\n procedure Read_Intel is new Read_Intel_x86_number (U16);\n procedure Read_Intel is new Read_Intel_x86_number (U32);\n m1, m2 : U32; e : U16;\n begin\n Read_Intel (sb, m1);\n Read_Intel (sb, m2);\n Read_Intel (sb, e);\n Merge (Cvt (m1), Cvt (m2), Cvt (e), n);\n -- Double is stored in two parts due to the absence of\n -- 64 - bit integers on certain compilers (e.g. OA 8.2)\n end Read_Double;\n\n generic\n s : Ada.Streams.Stream_IO.Stream_Access;\n type Number is mod <>;\n procedure Write_Intel_x86_number (n : in Number);\n\n procedure Write_Intel_x86_number (n : in Number) is\n m : Number := n;\n bytes : constant Integer := Number'Size/8;\n begin\n for i in 1 .. bytes loop\n U8'Write (s, U8 (m mod 256));\n m := m / 256;\n end loop;\n end Write_Intel_x86_number;\n\n procedure Write_Double (\n s : Ada.Streams.Stream_IO.Stream_Access;\n n : in GL.Double)\n is\n procedure Write_Intel is new Write_Intel_x86_number (s, U16);\n procedure Write_Intel is new Write_Intel_x86_number (s, U32);\n m1, m2 : I32; e : I16;\n begin\n Split (n, m1, m2, e);\n -- Double is stored in two parts due to the absence of\n -- 64 - bit integers on certain compilers (e.g. OA 8.2)\n Write_Intel (Cvt (m1));\n Write_Intel (Cvt (m2));\n Write_Intel (Cvt (e));\n end Write_Double;\n\n procedure Write_String (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n str : in String\n)\n is\n tstr : constant String := Trim (str, Right);\n begin\n U8'Write (s, tstr'Length);\n String'Write (s, tstr);\n end Write_String;\n\n procedure Read_String (\n sb : in out GL.IO.Input_buffer;\n str : out String\n)\n is\n l8 : U8;\n l : Natural;\n begin\n GL.IO.Get_Byte (sb, l8);\n l := Natural (l8);\n if l > str'Length then\n raise Constraint_Error;\n end if;\n for i in str'First .. str'First + l - 1 loop\n GL.IO.Get_Byte (sb, l8);\n str (i) := Character'Val (l8);\n end loop;\n str (str'First + l .. str'Last) := (others => ' ');\n end Read_String;\n\n -------------------\n -- Object_3D I/O --\n -------------------\n\n procedure Read (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n o : out p_Object_3D\n)\n is\n\n buf : GL.IO.Input_buffer;\n\n procedure Read_Intel is new Read_Intel_x86_number (U16);\n procedure Read_Intel is new Read_Intel_x86_number (U32);\n\n procedure Read_Float (n : out GL.C_Float) is\n m : U32; e : U16;\n begin\n Read_Intel (buf, m);\n Read_Intel (buf, e);\n Merge (Cvt (m), Cvt (e), n);\n end Read_Float;\n\n procedure Read_Material_Float_vector (mfv : out GL.Material_Float_vector) is\n begin\n for i in mfv'Range loop\n Read_Float (mfv (i));\n end loop;\n end Read_Material_Float_vector;\n\n procedure Read_Point_3D (p : out Point_3D) is\n begin\n for i in p'Range loop\n Read_Double (buf, p (i));\n end loop;\n end Read_Point_3D;\n\n procedure Read_Map_idx_pair_array (m : out Map_idx_pair_array) is\n begin\n for i in m'Range loop\n Read_Double (buf, m (i).U);\n Read_Double (buf, m (i).V);\n end loop;\n end Read_Map_idx_pair_array;\n\n v8 : U8;\n v32, mp32, mf32 : U32;\n\n procedure Read_face (face : out Face_type; face_invar : in out Face_invariant_type) is\n begin\n -- 1/ Points\n for i in face.p'Range loop\n Read_Intel (buf, v32);\n face.p (i) := Integer (v32);\n end loop;\n -- 2/ Portal connection : object name is stored;\n -- access must be found later\n Read_String (buf, face_invar.connect_name);\n -- 3/ Skin\n GL.IO.Get_Byte (buf, v8);\n face.skin := Skin_Type'Val (v8);\n -- 4/ Mirror\n GL.IO.Get_Byte (buf, v8);\n face.mirror := Boolean'Val (v8);\n -- 5/ Alpha\n Read_Double (buf, face.alpha);\n -- 6/ Colour\n case face.skin is\n when colour_only | coloured_texture =>\n Read_Double (buf, face.colour.red);\n Read_Double (buf, face.colour.green);\n Read_Double (buf, face.colour.blue);\n when others =>\n null;\n end case;\n -- 7/ Material\n case face.skin is\n when material_only | material_texture =>\n Read_Material_Float_vector (face.material.ambient);\n Read_Material_Float_vector (face.material.diffuse);\n Read_Material_Float_vector (face.material.specular);\n Read_Material_Float_vector (face.material.emission);\n Read_Float (face.material.shininess);\n when others =>\n null;\n end case;\n -- 8/ Texture : texture name is stored;\n -- id must be found later\n Read_String (buf, face_invar.texture_name);\n GL.IO.Get_Byte (buf, v8);\n face.whole_texture := Boolean'Val (v8);\n GL.IO.Get_Byte (buf, v8);\n face.repeat_U := Positive'Val (v8);\n GL.IO.Get_Byte (buf, v8);\n face.repeat_V := Positive'Val (v8);\n if not face.whole_texture then\n Read_Map_idx_pair_array (face.texture_edge_map);\n end if;\n end Read_face;\n test_signature : String (signature_obj'Range);\n ID : Ident;\n begin\n String'Read (s, test_signature);\n if test_signature /= signature_obj then\n raise Bad_data_format;\n end if;\n GL.IO.Attach_Stream (b => buf, stm => s);\n Read_String (buf, ID);\n -- Read the object's dimensions, create object, read its contents\n Read_Intel (buf, mp32);\n Read_Intel (buf, mf32);\n o := new Object_3D (Integer (mp32), Integer (mf32));\n o.ID := ID;\n for p in o.Point'Range loop\n Read_Point_3D (o.Point (p));\n end loop;\n for f in o.face'Range loop\n Read_face (o.face (f), o.face_invariant (f));\n end loop;\n Read_Point_3D (o.Centre);\n for i in Matrix_33'Range (1) loop\n for j in Matrix_33'Range (2) loop\n Read_Double (buf, o.rotation (i, j));\n end loop;\n end loop;\n -- !! sub - objects : skipped !!\n -- Main operation done!\n end Read;\n\n procedure Write (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n o : in Object_3D\n)\n is\n\n procedure Write_Intel is new Write_Intel_x86_number (s, U16);\n procedure Write_Intel is new Write_Intel_x86_number (s, U32);\n\n procedure Write_Float (n : in GL.C_Float) is\n m : I32; e : I16;\n begin\n Split (n, m, e);\n Write_Intel (Cvt (m));\n Write_Intel (Cvt (e));\n end Write_Float;\n\n procedure Write_Material_Float_vector (mfv : in GL.Material_Float_vector) is\n begin\n for i in mfv'Range loop\n Write_Float (mfv (i));\n end loop;\n end Write_Material_Float_vector;\n\n procedure Write_Point_3D (p : in Point_3D) is\n begin\n for i in p'Range loop\n Write_Double (s, p (i));\n end loop;\n end Write_Point_3D;\n\n procedure Write_Map_idx_pair_array (m : in Map_idx_pair_array) is\n begin\n for i in m'Range loop\n Write_Double (s, m (i).U);\n Write_Double (s, m (i).V);\n end loop;\n end Write_Map_idx_pair_array;\n\n procedure Write_face (face : Face_type; face_invar : Face_invariant_type) is\n begin\n -- 1/ Points\n for i in face.p'Range loop\n Write_Intel (U32 (face.p (i)));\n end loop;\n -- 2/ Portal connection : object name is stored\n if face.connecting = null then\n Write_String (s, empty);\n else\n Write_String (s, face.connecting.ID);\n end if;\n -- 3/ Skin\n U8'Write (s, Skin_Type'Pos (face.skin));\n -- 4/ Mirror\n U8'Write (s, Boolean'Pos (face.mirror));\n -- 5/ Alpha\n Write_Double (s, face.alpha);\n -- 6/ Colour\n case face.skin is\n when colour_only | coloured_texture =>\n Write_Double (s, face.colour.red);\n Write_Double (s, face.colour.green);\n Write_Double (s, face.colour.blue);\n when others =>\n null;\n end case;\n -- 7/ Material\n case face.skin is\n when material_only | material_texture =>\n Write_Material_Float_vector (face.material.ambient);\n Write_Material_Float_vector (face.material.diffuse);\n Write_Material_Float_vector (face.material.specular);\n Write_Material_Float_vector (face.material.emission);\n Write_Float (face.material.shininess);\n when others =>\n null;\n end case;\n -- 8/ Texture : texture name is stored\n if face.texture = null_image then\n -- Maybe a texture name has been given with Texture_name_hint,\n -- but was not yet attached to a GL ID number through Rebuild_Links\n Write_String (s, face_invar.texture_name);\n else\n -- Usual way : We can get the texture name associated to the\n -- GL ID number; name is stored by GLOBE_3D.Textures.\n Write_String (s, Textures.Texture_name (face.texture, False));\n end if;\n U8'Write (s, Boolean'Pos (face.whole_texture));\n U8'Write (s, Positive'Pos (face.repeat_U));\n U8'Write (s, Positive'Pos (face.repeat_V));\n if not face.whole_texture then\n Write_Map_idx_pair_array (face.texture_edge_map);\n end if;\n end Write_face;\n\n begin\n String'Write (s, signature_obj);\n Write_String (s, o.ID);\n Write_Intel (U32 (o.Max_points));\n Write_Intel (U32 (o.Max_faces));\n for p in o.Point'Range loop\n Write_Point_3D (o.Point (p));\n end loop;\n for f in o.face'Range loop\n Write_face (o.face (f), o.face_invariant (f));\n end loop;\n Write_Point_3D (o.Centre);\n for i in Matrix_33'Range (1) loop\n for j in Matrix_33'Range (2) loop\n Write_Double (s, o.rotation (i, j));\n end loop;\n end loop;\n -- !! sub - objects : skipped !!\n -- Main operation done!\n end Write;\n\n generic\n type Anything is private;\n extension : String;\n animal : String;\n with procedure Read (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n a : out Anything\n);\n procedure Load_generic (name_in_resource : String; a : out Anything);\n\n procedure Load_generic (name_in_resource : String; a : out Anything) is\n name_ext : constant String := name_in_resource & extension;\n\n procedure Try (zif : in out Zip.Zip_info; name : String) is\n use UnZip.Streams;\n fobj : Zipped_File_Type;\n begin -- Try\n Load_if_needed (zif, name);\n Open (fobj, zif, name_ext);\n Read (Stream (fobj), a);\n Close (fobj);\n exception\n when Zip.File_name_not_found =>\n raise;\n when e:others =>\n Raise_Exception (\n Exception_Identity (e),\n Exception_Message (e) & \" on \" & animal & \" : \" & name_ext\n);\n end Try;\n begin\n begin\n Try (zif_level, To_String (level_data_name));\n exception\n when Zip.File_name_not_found |\n Zip.Zip_file_open_Error =>\n -- Not found in level - specific pack\n Try (zif_global, To_String (global_data_name));" + }, + { + "function_def": "procedure Load_Internal is", + "function_body": "new Load_generic (\n Anything => p_Object_3D,\n extension => object_extension,\n animal => \"object\",\n Read => Read\n);\n\n procedure Load (name_in_resource : String; o : out p_Object_3D)\n renames Load_Internal;\n\n procedure Load_file (file_name : String; o : out p_Object_3D) is\n use Ada.Streams.Stream_IO;\n f : File_Type;\n begin\n Open (f, in_file, file_name);\n Read (Stream (f), o);\n Close (f);\n end Load_file;\n\n procedure Save_file (file_name : String; o : in Object_3D'Class) is\n use Ada.Streams.Stream_IO;\n f : File_Type;\n begin\n Create (f, out_file, file_name);\n Write (Stream (f), Object_3D (o));\n -- ^ endian - proof and floating - point hardware neutral;\n -- using stream attribute would be machine - specific.\n Close (f);\n end Save_file;\n\n procedure Save_file (o : in Object_3D'Class) is\n begin\n Save_file (Trim (o.ID, Right) & object_extension, o);\n end Save_file;\n\n -------------\n -- BSP I/O --\n -------------\n\n -- Write a BSP tree to a stream\n\n procedure Write (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n tree : in BSP.p_BSP_node\n)\n is\n procedure Write_Intel is new Write_Intel_x86_number (s, U32);\n use BSP;\n\n n : Natural := 0;\n\n procedure Numbering (node : p_BSP_node) is\n begin\n if node /= null then\n n := n + 1;\n node.node_id := n;\n Numbering (node.front_child);\n Numbering (node.back_child);\n end if;\n end Numbering;\n\n procedure Save_node (node : p_BSP_node) is\n begin\n if node /= null then\n Write_Intel (U32 (node.node_id));\n if node.front_child = null then\n Write_Intel (U32' (0));\n if node.front_leaf = null then\n Write_String (s, empty);\n else\n Write_String (s, node.front_leaf.ID);\n end if;\n else\n Write_Intel (U32 (node.front_child.node_id));\n end if;\n if node.back_child = null then\n Write_Intel (U32' (0));\n if node.back_leaf = null then\n Write_String (s, empty);\n else\n Write_String (s, node.back_leaf.ID);\n end if;\n else\n Write_Intel (U32 (node.back_child.node_id));\n end if;\n for i in node.normal'Range loop\n Write_Double (s, node.normal (i));\n end loop;\n Write_Double (s, node.distance);\n --\n Save_node (node.front_child);\n Save_node (node.back_child);\n end if;\n end Save_node;\n\n begin\n Numbering (tree); -- fill the node_id's\n String'Write (s, signature_bsp); -- header\n Write_Intel (U32 (n)); -- give the number of nodes first\n Save_node (tree);\n end Write;\n\n -- Write a BSP tree to a file\n\n procedure Save_file (file_name : String; tree : in BSP.p_BSP_node) is\n use Ada.Streams.Stream_IO;\n f : File_Type;\n begin\n if Index (file_name, \".\")=0 then\n Create (f, out_file, file_name & BSP_extension);\n else\n Create (f, out_file, file_name);\n end if;\n Write (Stream (f), tree);\n Close (f);\n end Save_file;\n\n procedure Load (\n name_in_resource : in String;\n referred : in Map_of_Visuals;\n tree : out BSP.p_BSP_node\n)\n is\n\n function Find_object (ID : Ident; tolerant : Boolean) return p_Object_3D is\n begin\n if ID = empty then\n return null;\n else\n return p_Object_3D (\n Visuals_Mapping.Element (\n Container => Visuals_Mapping.Map (referred),\n Key => Ada.Strings.Unbounded.To_Unbounded_String (ID)\n)\n);\n end if;\n exception\n when Constraint_Error =>\n -- GNAT gives also the message:\n -- no element available because key not in map\n if tolerant then\n return null;\n else\n Raise_Exception (\n Missing_object_in_BSP'Identity,\n \"Object not found : [\" & Trim (ID, Right) & ']'\n);\n end if;\n end Find_object;\n\n procedure Read (\n s : in Ada.Streams.Stream_IO.Stream_Access;\n tree : out BSP.p_BSP_node\n)\n is\n use BSP;\n buf : GL.IO.Input_buffer;\n procedure Read_Intel is new Read_Intel_x86_number (U32);\n\n test_signature : String (signature_bsp'Range);\n n, j, k : U32;\n ID : Ident;\n tol : constant Boolean := False;\n begin\n String'Read (s, test_signature);\n if test_signature /= signature_bsp then\n raise Bad_data_format;\n end if;\n GL.IO.Attach_Stream (b => buf, stm => s);\n Read_Intel (buf, n);\n if n < 1 then\n tree := null;\n return;\n end if;\n declare\n -- We put all the new - born nodes into a farm with numbered boxes,\n -- because only the numbers are stored in the BSP file.\n -- Once the nodes are linked together through accesses (pointers),\n -- we can forget the farm and let the tree float .. .\n farm : array (0 .. n) of p_BSP_Node;\n begin\n farm (0) := null;\n for i in 1 .. n loop\n farm (i) := new BSP_Node;\n end loop;\n for i in 1 .. n loop\n Read_Intel (buf, j); -- node_id\n farm (j).node_id := Integer (j);\n Read_Intel (buf, k);\n farm (j).front_child := farm (k);\n if k = 0 then -- it is a front leaf - > associate object\n Read_String (buf, ID);\n farm (j).front_leaf := Find_object (ID, tol);\n end if;\n Read_Intel (buf, k);\n farm (j).back_child := farm (k);\n if k = 0 then -- it is a back leaf - > associate object\n Read_String (buf, ID);\n farm (j).back_leaf := Find_object (ID, tol);\n end if;\n -- The node's geometric information (a plane):\n for ii in farm (j).normal'Range loop\n Read_Double (buf, farm (j).normal (ii));\n end loop;\n Read_Double (buf, farm (j).distance);\n end loop;\n tree := farm (1);" + }, + { + "function_def": "procedure Deallocate is new Ada.Unchecked_Deallocation (Visual'Class, p_Visual);", + "function_body": "begin\n Destroy (o.all);\n Deallocate (o);\n end Free;\n\n function skinned_Geometrys (o : Visual) return GL.Skinned_Geometry.skinned_Geometrys is\n (GL.Skinned_Geometry.null_skinned_Geometrys);\n\n function Width (o : Visual'class) return Real is\n (Bounds (o).Box.X_Extent.Max - Bounds (o).Box.X_Extent.Min);\n\n function Height (o : Visual'class) return Real is\n (Bounds (o).Box.Y_Extent.Max - Bounds (o).Box.Y_Extent.Min);\n\n function Depth (o : Visual'class) return Real is\n (Bounds (o).Box.Z_Extent.Max - Bounds (o).Box.Z_Extent.Min);\n\n -- 'Object_3D'\n --\n\n -- object validation\n --\n\n procedure Check_object (o : Object_3D) is\n\n use G3DM;\n\n procedure Check_faces is\n\n procedure Check (f, v : Integer) is\n pragma Inline (Check);\n begin\n if v < 0 or else v > o.Max_points then\n Raise_Exception (bad_vertex_number'Identity,\n o.ID & \" face =\" & Integer'Image (f) &\n \" vertex =\" & Integer'Image (v));\n end if;\n end Check;\n\n procedure Check_duplicate (f, Pn1, Pn2 : Integer) is\n pragma Inline (Check_duplicate);\n begin\n -- Skip \"dead\" edge (triangle), 30 - Dec - 2001\n if Pn1 = 0 or else Pn2 = 0 then\n return;\n end if;\n -- Detect same point number\n if Pn1 = Pn2 then\n Raise_Exception (duplicated_vertex'Identity,\n o.ID & \" in face \" & Integer'Image (f));\n end if;\n -- Detect same point coordinates (tolerated in an object,\n -- although inefficient, but harms as vertex of the same face!)\n\n if Almost_zero (Norm2 (o.Point (Pn1) - o.Point (Pn2))) then\n Raise_Exception (duplicated_vertex_location'Identity,\n o.ID & \" in face \" & Integer'Image (f));\n end if;\n end Check_duplicate;\n\n begin\n for fa in o.face'Range loop\n for edge_num in 1 .. 4 loop\n Check (fa, o.face (fa).P (edge_num));\n for other_edge in edge_num + 1 .. 4 loop\n Check_duplicate (fa, o.face (fa).P (edge_num),\n o.face (fa).P (other_edge));\n end loop;\n end loop;\n end loop; -- fa\n end Check_faces;\n\n begin\n Check_faces;\n end Check_object;\n\n --------------------------------------------\n -- Object initialization (1x in its life) --\n --------------------------------------------\n\n overriding procedure Pre_calculate (o : in out Object_3D) is\n\n use G3DM;\n\n N : Vector_3D;\n length_N : Real;\n\n procedure Calculate_face_invariants (\n fa : Face_type;\n fi : out Face_invariant_type\n ) is\n l : Natural := 0;\n quadri_edge : array (fa.P'Range) of Natural;\n ex_U, ex_V : Real;\n begin\n l := 0;\n for qe in fa.P'Range loop\n if fa.P (qe) /= 0 then\n l := l + 1;\n quadri_edge (l) := qe; -- if triangle, \"map\" edge on a quadri\n fi.P_compact (l) := fa.P (qe);\n end if;\n end loop;\n if l in Edge_count then\n fi.last_edge := l;\n else\n Raise_Exception (bad_edge_number'Identity, o.ID);\n end if;\n -- * Face invariant : Textured face : extremities\n for e in 1 .. l loop\n if fa.whole_texture then\n ex_U := Real (fa.repeat_U);\n ex_V := Real (fa.repeat_V);\n case quadri_edge (e) is\n when 1 => fi.UV_extrema (e) := (0.0, 0.0); -- bottom, left 4 --< --3\n when 2 => fi.UV_extrema (e) := (ex_U, 0.0); -- bottom, right | |\n when 3 => fi.UV_extrema (e) := (ex_U, ex_V); -- top, right 1 --> --2\n when 4 => fi.UV_extrema (e) := (0.0, ex_V); -- top, left\n when others => null;\n end case;\n else\n -- Just copy the mapping, but in compact form for triangles :\n fi.UV_extrema (e) := fa.texture_edge_map (quadri_edge (e));\n end if;\n end loop;\n -- * Face invariant : Normal of unrotated face\n N := (0.0, 0.0, 0.0);\n case fi.last_edge is\n when 3 =>\n Add_Normal_of_3p (o,\n fi.P_compact (1),\n fi.P_compact (2),\n fi.P_compact (3),\n N\n );\n when 4 =>\n Add_Normal_of_3p (o, fa.P (1), fa.P (2), fa.P (4), N);\n -- We sum other normals for not perfectly flat faces,\n -- in order to have a convenient average .. .\n Add_Normal_of_3p (o, fa.P (2), fa.P (3), fa.P (1), N);\n Add_Normal_of_3p (o, fa.P (3), fa.P (4), fa.P (2), N);\n Add_Normal_of_3p (o, fa.P (4), fa.P (1), fa.P (3), N);\n end case;\n length_N := Norm (N);\n if Almost_zero (length_N) then\n if strict_geometry then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n raise zero_summed_normal;\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n else\n fi.normal := N; -- 0 vector !\n end if;\n else\n fi.normal := (1.0 / length_N) * N;\n end if;\n end Calculate_face_invariants;\n\n adjacent_faces : array (o.Point'Range) of Natural := (others => 0);\n pf : Natural;\n length : Real;\n\n begin -- Pre_calculate\n if full_check_objects then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Check_object (o);\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n for i in o.face'Range loop\n begin\n -- Geometry\n Calculate_face_invariants (o.face (i), o.Face_Invariant (i));\n -- Disable blending when alphas are = 1\n case o.face (i).skin is\n when material_only | material_texture =>\n o.Face_Invariant (i).blending := Is_to_blend (o.face (i).material);\n when colour_only | coloured_texture | texture_only =>\n o.Face_Invariant (i).blending := Is_to_blend (o.face (i).alpha);\n when invisible =>\n o.Face_Invariant (i).blending := False;\n end case;\n o.transparent := o.transparent or else o.Face_Invariant (i).blending;\n exception\n when zero_summed_normal =>\n Raise_Exception (zero_summed_normal'Identity,\n o.ID & \" face =\" & Integer'Image (i));" + }, + { + "function_def": "procedure Display_one (o : in out Object_3D) is", + "function_body": "-- Display only this object and not connected objects\n -- out : object will be initialized if not yet\n\n --\n\n --\n -- Display face routine which is optimized to produce a shorter list\n -- of GL commands. Runs slower then the original Display face routine\n -- yet needs to be executed only once.\n --\n -- Uwe R. Zimmer, July 2011\n --\n package Display_face_optimized is\n procedure Display_face (First_Face : Boolean; fa : Face_type; fi : in out Face_invariant_type);\n private\n Previous_face : Face_type;\n Previous_face_Invariant : Face_invariant_type;\n end Display_face_optimized;\n\n package body Display_face_optimized is\n\n use GL.Materials;\n\n procedure Display_face (First_Face : Boolean; fa : Face_type; fi : in out Face_invariant_type) is\n\n blending_hint : Boolean;\n\n begin -- Display_face\n\n if fa.skin = invisible then\n Previous_face := fa;\n Previous_face_Invariant := fi;\n return;\n end if;\n\n --------------\n -- Material --\n --------------\n\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then fa.material /= Previous_face.material)\n then\n case fa.skin is\n when material_only | material_texture =>\n Disable (COLOR_MATERIAL);\n Set_Material (fa.material);\n when others =>\n Set_Material (GL.Materials.neutral_material);\n end case;\n end if;\n\n ------------\n -- Colour --\n ------------\n\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then (fa.colour /= Previous_face.colour\n or else fa.alpha /= Previous_face.alpha))\n then\n case fa.skin is\n when material_only | material_texture =>\n null; -- done above\n when colour_only | coloured_texture =>\n Enable (COLOR_MATERIAL);\n ColorMaterial (FRONT_AND_BACK, AMBIENT_AND_DIFFUSE);\n Color (\n red => fa.colour.Red,\n green => fa.colour.Green,\n blue => fa.colour.Blue,\n alpha => fa.alpha\n );\n when texture_only =>\n Disable (COLOR_MATERIAL);\n when invisible =>\n null;\n end case;\n end if;\n\n -------------\n -- Texture --\n -------------\n\n if is_textured (fa.skin) then\n G3DT.Check_2D_texture (fa.texture, blending_hint);\n if blending_hint then\n fi.blending := True;\n -- 13 - Oct - 2006 : override the decision made at Pre_calculate.\n -- If texture data contains an alpha layer, we switch\n -- on transparency.\n end if;\n end if;\n\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then fa.texture /= Previous_face.texture)\n then\n case fa.skin is\n when texture_only | coloured_texture | material_texture =>\n Enable (TEXTURE_2D);\n GL.BindTexture (GL.TEXTURE_2D, GL.Uint (Image_ID'Pos (fa.texture) + 1));\n -- ^ superfluous ?!!\n when colour_only | material_only =>\n Disable (TEXTURE_2D);\n when invisible =>\n null;\n end case;\n end if;\n\n -----------------------------\n -- Blending / transparency --\n -----------------------------\n\n if First_Face\n or else Previous_face.skin = invisible\n or else fi.blending /= Previous_face_Invariant.blending\n then\n if fi.blending then\n Enable (BLEND); -- See 4.1.7 Blending\n BlendFunc (sfactor => SRC_ALPHA,\n dfactor => ONE_MINUS_SRC_ALPHA);\n -- Disable (DEPTH_TEST);\n -- Disable (CULL_FACE);\n else\n Disable (BLEND);\n -- Enable (DEPTH_TEST);\n -- Enable (CULL_FACE);\n -- CullFace (BACK);\n end if;\n end if;\n\n -------------\n -- Drawing --\n -------------\n\n case fi.last_edge is\n when 3 => GL_Begin (TRIANGLES);\n when 4 => GL_Begin (QUADS);\n end case;\n\n for i in 1 .. fi.last_edge loop\n if is_textured (fa.skin) then\n TexCoord (fi.UV_extrema (i).U, fi.UV_extrema (i).V);\n end if;\n Normal (o.edge_vector (fi.P_compact (i)));\n Vertex (o.Point (fi.P_compact (i)));\n end loop;\n\n GL_End;\n\n Previous_face := fa;\n Previous_face_Invariant := fi;\n end Display_face;\n\n end Display_face_optimized;\n\n procedure Display_normals is\n\n use G3DM;\n\n C : Vector_3D;\n\n begin\n GL.Color (0.5, 0.5, 1.0, 1.0);\n -- show pseudo (average) normals at edges :\n for e in o.Point'Range loop\n Arrow (o.Point (e), arrow_inflator * o.edge_vector (e));\n end loop;\n GL.Color (1.0, 1.0, 0.5, 1.0);\n -- show normals of faces :\n for f in o.face'Range loop\n C := (0.0, 0.0, 0.0);\n for i in 1 .. o.Face_Invariant (f).last_edge loop\n C := C + o.Point (o.Face_Invariant (f).P_compact (i));\n end loop;\n C := (1.0 / Real (o.Face_Invariant (f).last_edge)) * C;\n Arrow (C, arrow_inflator * o.Face_Invariant (f).normal);\n end loop;\n end Display_normals;\n\n use G3DM;\n\n begin -- Display_one\n\n if not o.pre_calculated then\n Pre_calculate (o);\n end if;\n\n GL.BindBuffer (GL.ARRAY_BUFFER, 0); -- disable 'vertex buffer objects'\n GL.BindBuffer (GL.ELEMENT_ARRAY_BUFFER, 0); -- disable 'vertex buffer objects' indices\n\n -- gl.disableClientState (gl.TEXTURE_COORD_ARRAY);\n -- gl.disable (ALPHA_TEST);\n GL.Enable (LIGHTING);\n\n GL.PushMatrix; -- 26 - May - 2006 : instead of rotating/translating back\n GL.Translate (o.Centre);\n Multiply_GL_Matrix (o.rotation);\n\n -- List preparation phase\n case o.List_Status is\n when No_List | Is_List =>\n null;\n\n when Generate_List =>\n o.List_Id := Integer (GL.GenLists (1));\n GL.NewList (GL.Uint (o.List_Id), COMPILE_AND_EXECUTE);\n end case;\n\n -- Execution phase\n case o.List_Status is\n when No_List =>\n for f in o.face'Range loop\n Display_face_optimized.Display_face (True, o.face (f), o.Face_Invariant (f));\n -- We mimic the old Display_face with redundant color, material, etc.\n -- instructions by passing True for First_Face.\n end loop;\n when Generate_List =>\n for f in o.face'Range loop\n Display_face_optimized.Display_face (f = o.face'First, o.face (f), o.Face_Invariant (f));\n end loop;\n\n when Is_List => GL.CallList (GL.Uint (o.List_Id));\n end case;\n\n -- Close list\n case o.List_Status is\n when No_List | Is_List => null;\n\n when Generate_List =>\n GL.EndList;\n if GL.Get_Error = OUT_OF_MEMORY then\n o.List_Status := No_List;\n else\n o.List_Status := Is_List;\n end if;\n end case;\n\n if show_normals then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n GL.Disable (GL.LIGHTING);\n GL.Disable (GL.TEXTURE_2D);\n Display_normals;\n GL.Enable (GL.LIGHTING); -- mmmh .. .\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n GL.PopMatrix; -- 26 - May - 2006 : instead of rotating/translating back\n -- GL.Rotate (o.auto_rotation (2), 0.0, 0.0, - 1.0);\n -- GL.Rotate (o.auto_rotation (1), 0.0, - 1.0, 0.0);\n -- GL.Rotate (o.auto_rotation (0), - 1.0, 0.0, 0.0);\n\n -- GL.Translate ( - o.centre);\n end Display_one;\n\n overriding procedure Display (o : in out Object_3D;\n clip : Clipping_data) is\n\n use GLOBE_3D.Portals;\n\n procedure Display_clipped (o : in out Object_3D'Class;\n clip_area : Clipping_area;\n portal_depth : Natural) is\n\n procedure Try_portal (f : Positive) is\n\n use G3DM;\n\n dp : Real;\n plane_to_eye : Vector_3D; -- vector from any point in plane to the eye\n bounding_of_face, intersection_clip_and_face : Clipping_area;\n success, non_empty_intersection : Boolean;\n\n begin\n -- Culling #1 : check if portal is in vield of view's \"dead angle\"\n dp := o.Face_Invariant (f).normal * clip.view_direction;\n if dp < clip.max_dot_product then\n -- Culling #2 : check if we are on the right side of the portal\n -- NB : ignores o.auto_rotation !\n plane_to_eye :=\n clip.Eye_Position -\n (o.Point (o.Face_Invariant (f).P_compact (1)) + o.Centre)\n ;\n dp := plane_to_eye * o.Face_Invariant (f).normal;\n -- dp = signed distance to the plane\n if dp > 0.0 then\n -- Culling #3 : clipping rectangle\n Find_bounding_box (o, f, bounding_of_face, success);\n if success then\n Intersect (clip_area, bounding_of_face,\n intersection_clip_and_face, non_empty_intersection);\n else\n -- in doubt, draw with the present clipping\n intersection_clip_and_face := clip_area;\n non_empty_intersection := True;\n end if;\n if non_empty_intersection then\n -- Recursion here :\n Display_clipped (\n o => o.face (f).connecting.all,\n clip_area => intersection_clip_and_face,\n portal_depth => portal_depth + 1\n );\n end if;\n end if;\n end if;\n end Try_portal;\n\n begin -- Display_clipped\n if not o.pre_calculated then\n Pre_calculate (o);\n end if;\n --\n -- a/ Display connected objects which are visible through o's faces\n -- This is where recursion happens\n if (not filter_portal_depth) or else -- filter_portal_depth : test/debug\n portal_depth <= 6\n then\n for f in o.face'Range loop\n if o.face (f).connecting /= null and then\n not o.Face_Invariant (f).portal_seen\n -- ^ prevents infinite recursion on rare cases where\n -- object A or B is not convex, and A and B see each other\n -- and the culling by clipping cannot stop the recursion\n -- (e.g. origin2.proc, tomb.proc)\n --\n -- NB : drawing [different parts of] the same object several times\n -- is right, since portions can be seen through different portals,\n -- but going more than once through the same portal is wrong\n then\n o.Face_Invariant (f).portal_seen := True;\n Try_portal (f);\n -- ^ recursively calls Display_clipped for\n -- objects visible through face f.\n end if;\n end loop;\n end if;\n -- b/ Display the object itself\n if (not filter_portal_depth) or else -- filter_portal_depth : test/debug\n (portal_depth = 1 or else portal_depth = 5)\n then\n -- The graphical clipping (Scissor) gives various effects\n -- - almost no speedup on the ATI Radeon 9600 Pro (hardware)\n -- - factor : ~ Sqrt (clipped surface ratio) with software GL\n if portal_depth > 0 then\n GL.Enable (GL.SCISSOR_TEST);\n GL.Scissor (x => GL.Int (clip_area.X1),\n y => GL.Int (clip_area.Y1),\n width => GL.Sizei (clip_area.X2 - clip_area.X1 + 1),\n height => GL.Sizei (clip_area.Y2 - clip_area.Y1 + 1));\n else\n GL.Disable (GL.SCISSOR_TEST);\n end if;\n info_b_ntl2 := info_b_ntl2 + 1;\n info_b_ntl3 := Natural'Max (portal_depth, info_b_ntl3);\n Display_one (o);\n end if;\n if show_portals and then portal_depth > 0 then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Draw_boundary (clip.main_clipping, clip_area);\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end Display_clipped;\n\n procedure Reset_portal_seen (o : in out Object_3D'Class) is\n begin\n for f in o.face'Range loop\n if o.Face_Invariant (f).portal_seen then\n o.Face_Invariant (f).portal_seen := False;\n Reset_portal_seen (o.face (f).connecting.all);\n end if;\n end loop;\n end Reset_portal_seen;\n\n begin\n info_b_ntl2 := 0; -- count amount of objects displayed, not distinct\n info_b_ntl3 := 0; -- records max depth\n Display_clipped (o, clip_area => clip.main_clipping, portal_depth => 0);\n Reset_portal_seen (o);\n end Display;\n\n overriding procedure Destroy (o : in out Object_3D) is\n\n ol : p_Object_3D_list := o.sub_objects;\n\n begin\n while ol /= null loop\n Free (p_Visual (ol.all.objc));\n ol := ol.all.next;\n end loop;\n end Destroy;\n\n overriding procedure set_Alpha (o : in out Object_3D; Alpha : GL.Double) is\n\n begin\n for f in o.face'Range loop\n o.face (f).alpha := Alpha;\n end loop;\n end set_Alpha;\n\n overriding function is_Transparent (o : Object_3D) return Boolean is\n\n begin\n return o.transparent;\n end is_Transparent;\n\n overriding function face_Count (o : Object_3D) return Natural is\n\n begin\n return o.Max_faces;\n end face_Count;\n\n overriding function Bounds (o : Object_3D) return GL.Geometry.Bounds_record is\n\n begin\n return o.Bounds;\n end Bounds;\n\n -- Lighting support.\n --\n\n -- lights : array (Light_ident) of Light_definition;\n light_defined : array (Light_ident) of Boolean := (others => False);\n\n procedure Define (which : Light_ident; as : Light_definition) is\n\n id : constant GL.LightIDEnm := GL.LightIDEnm'Val (which - 1);\n\n begin\n -- lights (which) := as;\n Light (id, POSITION, as.position);\n Light (id, AMBIENT, as.ambient);\n Light (id, DIFFUSE, as.diffuse);\n Light (id, SPECULAR, as.specular);\n light_defined (which) := True;\n end Define;\n\n procedure Switch_lights (on : Boolean) is\n\n begin\n for l in Light_ident loop\n Switch_light (l, on);\n end loop;\n end Switch_lights;\n\n function Server_id (which : Light_ident) return GL.ServerCapabilityEnm is\n\n begin\n return GL.ServerCapabilityEnm'Val (GL.ServerCapabilityEnm'Pos (GL.LIGHT0) + which - 1);\n end Server_id;\n\n procedure Switch_light (which : Light_ident; on : Boolean) is\n\n begin\n if light_defined (which) then\n if on then\n GL.Enable (Server_id (which));\n else\n GL.Disable (Server_id (which));\n end if;\n end if;\n end Switch_light;\n\n function Is_light_switched (which : Light_ident) return Boolean is\n\n begin\n return Boolean'Val (GL.IsEnabled (Server_id (which)));\n end Is_light_switched;\n\n procedure Reverse_light_switch (which : Light_ident) is\n\n begin\n Switch_light (which, not Is_light_switched (which));\n end Reverse_light_switch;\n\n prec_a360 : constant := 10000;\n r_prec_a360 : constant := 10000.0;\n i_r_prec_a360 : constant := 1.0 / r_prec_a360;\n\n procedure Angles_modulo_360 (v : in out Vector_3D) is\n\n begin\n for i in v'Range loop\n v (i) :=\n GL.Double (Integer (r_prec_a360 * v (i)) mod (360 * prec_a360))\n * i_r_prec_a360;\n end loop;\n end Angles_modulo_360;\n\n ------------------\n -- Resource I/O --\n ------------------\n\n procedure Load_if_needed (zif : in out Zip.Zip_info; name : String) is\n\n begin\n if not Zip.Is_loaded (zif) then\n begin\n Zip.Load (zif, name);\n exception\n when Zip.Zip_file_open_Error => -- Try with lower case :\n Zip.Load (zif, To_Lower (name));" + }, + { + "function_def": "procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,", + "function_body": "Visual_Geometry,\n Visual_Geometries);\n use GL.Skins, GL.Geometry, GL.Skinned_Geometry;\n\n current_Visual : p_Visual;\n\n begin\n if geometry_Count > 1 then\n sort (All_Geometries (1 .. geometry_Count));\n end if;\n\n GL.PushMatrix;\n\n for Each in 1 .. geometry_Count loop\n\n if All_Geometries (Each).Geometry.Skin /= current_Skin then\n current_Skin := All_Geometries (Each).Geometry.Skin;\n Enable (current_Skin.all);\n GL.Errors.log;\n end if;\n\n if All_Geometries (Each).Geometry.Veneer /= null then\n Enable (All_Geometries (Each).Geometry.Veneer.all);\n GL.Errors.log;\n end if;\n\n if All_Geometries (Each).Visual = current_Visual then\n Draw (All_Geometries (Each).Geometry.Geometry.all);\n GL.Errors.log;\n else\n GL.PopMatrix;\n GL.PushMatrix;\n GL.Translate (All_Geometries (Each).Visual.all.Centre);\n Multiply_GL_Matrix (All_Geometries (Each).Visual.all.rotation);\n\n Draw (All_Geometries (Each).Geometry.Geometry.all);\n GL.Errors.log;\n\n current_Visual := All_Geometries (Each).Visual;\n end if;\n\n end loop;\n\n GL.PopMatrix;" + }, + { + "function_def": "-- procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,", + "function_body": "procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,\n GLOBE_3D.p_Visual,\n GLOBE_3D.Visual_array);\n begin\n for Each in 1 .. transparent_Count loop -- pre - calculate each visuals Centre in camera space.\n all_Transparents (Each).all.Centre_Camera_Space := the_Camera.World_Rotation\n * (all_Transparents (Each).all.Centre - the_Camera.Clipper.Eye_Position);\n end loop;\n\n if transparent_Count > 1 then\n sort (all_Transparents (1 .. transparent_Count));\n end if;\n\n GL.Depth_Mask (GL_False); -- make depth buffer read - only, for correct transparency\n\n Enable (LIGHTING); -- ensure lighting is enabled for G3D.Display of transparents (obsolete).\n Enable (BLEND);\n BlendFunc (sfactor => ONE,\n dfactor => ONE_MINUS_SRC_ALPHA);\n\n for Each_Transparency in 1 .. transparent_Count loop\n declare\n the_Visual : Visual'Class renames all_Transparents (Each_Transparency).all;\n visual_Geometrys : constant GL.Skinned_Geometry.skinned_Geometrys := skinned_Geometrys (the_Visual); -- tbd : apply ogl state sorting here ?\n begin\n Display (the_Visual, the_Camera.Clipper);\n GL.Errors.log;\n\n for Each_Geometry in visual_Geometrys'Range loop\n declare\n use GL.Skins, GL.Geometry;\n the_Geometry : GL.Skinned_Geometry.Skinned_Geometry_t renames visual_Geometrys (Each_Geometry);\n begin\n\n if the_Geometry.Skin /= current_Skin then\n current_Skin := the_Geometry.Skin;\n Enable (current_Skin.all);\n GL.Errors.log;\n end if;\n\n if the_Geometry.Veneer /= null then\n Enable (the_Geometry.Veneer.all);\n GL.Errors.log;\n end if;\n\n GL.PushMatrix;\n\n GL.Translate (the_Visual.Centre);\n Multiply_GL_Matrix (the_Visual.rotation);\n\n Draw (the_Geometry.Geometry.all);\n GL.Errors.log;\n\n GL.PopMatrix;" + }, + { + "function_def": "function to_Window is new Ada.Unchecked_Conversion (System.Address, GLOBE_3D.p_Window);", + "function_body": "begin\n return GLUT.Windows.Window_view (to_Window (GetWindowData));\n end current_Window;\n\n procedure Name_is (Self : in out Window; Now : String) is\n\n begin\n Self.Name := To_Unbounded_String (Now);\n end Name_is;\n\n function Name (Self : Window) return String is (To_String (Self.Name));\n\n function is_Closed (Self : Window) return Boolean is (Self.is_Closed);\n\n procedure Prepare_default_lighting (Self : in out Window;\n fact : GL.C_Float) is\n\n proto_light : G3D.Light_definition := (position => (0.0, 500.0, 0.0, 1.0),\n ambient => (0.3, 0.3, 0.3, fact),\n diffuse => (0.9, 0.9, 0.9, fact),\n specular => (0.05, 0.05, 0.01, fact));\n begin\n GL.Enable (GL.LIGHTING);\n\n G3D.Define (1, proto_light);\n Self.frontal_light := proto_light;\n\n proto_light.diffuse := (0.5, 0.9, 0.5, fact);\n G3D.Define (2, proto_light);\n\n proto_light.diffuse := (0.2, 0.0, 0.9, fact);\n proto_light.specular := (1.0, 1.0, 1.0, fact);\n G3D.Define (3, proto_light);\n\n proto_light.position := (-3.0, 4.0, 10.0, 1.0);\n G3D.Define (4, proto_light);\n\n proto_light.position := (3.0, -4.0, 10.0, 1.0);\n proto_light.ambient := (0.6, 0.6, 0.6, 0.1);\n G3D.Define (5, proto_light);\n\n proto_light.ambient := (0.6, 0.0, 0.0, 0.1);\n G3D.Define (6, proto_light);\n\n proto_light.ambient := (0.0, 0.6, 0.0, 0.1);\n G3D.Define (7, proto_light);\n\n proto_light.ambient := (0.0, 0.0, 0.6, 0.1);\n G3D.Define (8, proto_light);\n\n G3D.Switch_lights (True);\n\n G3D.Switch_light (2, False);\n G3D.Switch_light (3, False);\n G3D.Switch_light (4, False);\n G3D.Switch_light (5, False);\n G3D.Switch_light (6, False);\n G3D.Switch_light (7, False);\n G3D.Switch_light (8, False);\n\n end Prepare_default_lighting;\n\n procedure Clear_modes is\n\n begin\n Disable (BLEND);\n Disable (LIGHTING);\n Disable (AUTO_NORMAL);\n Disable (NORMALIZE);\n Disable (DEPTH_TEST);\n end Clear_modes;\n\n procedure Reset_for_3D (Self : in out Window'Class) is\n\n begin\n pragma Unreferenced (Self);\n MatrixMode (MODELVIEW); -- (tbd : still needed ?) . .. The matrix generated by GLU.Perspective is multipled by the current matrix\n ShadeModel (SMOOTH); -- GL's default is SMOOTH, vs FLAT\n -- ShadeModel (FLAT); -- GL's default is SMOOTH, vs FLAT\n\n ClearColor (0.0, 0.0, 0.0, 0.0); -- Specifies clear values for color buffer (s)\n ClearAccum (0.0, 0.0, 0.0, 0.0); -- Specifies clear values for the accumulation buffer\n end Reset_for_3D;\n\n procedure enable_Viewport_and_Perspective (Self : in out Window'Class) is -- tbd : move projection matrix to 'window resize'.\n\n begin\n Viewport (0, 0, Self.main_size_x, Self.main_size_y);\n\n MatrixMode (PROJECTION);\n LoadIdentity;\n\n GLU.Perspective (fovy => Self.Camera.FOVy, -- field of view angle (deg) in the y direction\n aspect => Self.Camera.Aspect, -- x/y aspect ratio\n zNear => Self.Camera.near_plane_Distance, -- distance from the viewer to the near clipping plane\n zFar => Self.Camera.far_plane_Distance); -- distance from the viewer to the far clipping plane\n\n Get (GL.PROJECTION_MATRIX, Self.Camera.Projection_Matrix (1, 1)'Unchecked_Access); -- Get the current PROJECTION matrix from OpenGL\n\n Self.Camera.Projection_Matrix := Transpose (Self.Camera.Projection_Matrix);\n\n MatrixMode (MODELVIEW); -- The matrix generated by GLU.Perspective is multipled by the current matrix\n end enable_Viewport_and_Perspective;\n\n procedure set_Size (Self : in out Window'Class; width, height : Integer) is\n\n use G3D;\n use REF;\n\n half_fov_max_rads : Real;\n Tan_of_half_fov_max_rads : Real;\n\n begin\n Self.main_size_x := GL.Sizei (width);\n Self.main_size_y := GL.Sizei (height);\n\n Self.Camera.Clipper.main_clipping.X1 := 0;\n Self.Camera.Clipper.main_clipping.Y1 := 0;\n Self.Camera.Clipper.main_clipping.X2 := width - 1;\n Self.Camera.Clipper.main_clipping.Y2 := height - 1;\n\n Self.Camera.Aspect := GL.Double (Self.main_size_x) / GL.Double (Self.main_size_y);\n half_fov_max_rads := 0.5 * Self.Camera.FOVy * deg2rad;\n\n Tan_of_half_fov_max_rads := Tan (half_fov_max_rads);\n\n Self.Camera.near_plane_Height := Self.Camera.near_plane_Distance * Tan_of_half_fov_max_rads;\n Self.Camera.near_plane_Width := Self.Camera.near_plane_Height * Self.Camera.Aspect;\n\n Self.Camera.far_plane_Height := Self.Camera.far_plane_Distance * Tan_of_half_fov_max_rads;\n Self.Camera.far_plane_Width := Self.Camera.far_plane_Height * Self.Camera.Aspect;\n\n if Self.Camera.Aspect > 1.0 then -- x side angle broader than y side angle\n half_fov_max_rads := Arctan (Self.Camera.Aspect * Tan_of_half_fov_max_rads);\n end if;\n\n Self.Camera.Clipper.max_dot_product := Sin (half_fov_max_rads);\n\n end set_Size;\n\n -- Procedures passed to GLUT:\n -- Window_Resize, Keyboard, Motion, Menu, Mouse, Display\n\n procedure Window_Resize (width, height : Integer) is\n\n the_Window : constant GLUT.Windows.Window_view := current_Window;\n\n begin\n the_Window.all.forget_mouse := 5;\n set_Size (the_Window.all, width, height);\n Reset_for_3D (the_Window.all);\n end Window_Resize;\n\n procedure Menu (value : Integer) is\n\n begin\n case value is\n when 1 => -- GLUT.GameModeString (Full_Screen_Mode);\n GLUT.FullScreen;\n -- res := GLUT.EnterGameMode;\n GLUT.SetCursor (GLUT.CURSOR_NONE);\n current_Window.all.forget_mouse := 10;\n current_Window.all.full_screen := True;\n when 2 => null; -- GLUT_exit;\n when others => null;\n end case;\n end Menu;\n pragma Unreferenced (Menu);\n\n procedure Display_status (Self : in out Window;\n sec : GLOBE_3D.Real) is\n\n use G3D, G3D.REF;\n\n light_info : String (1 .. 8);\n\n begin\n PushMatrix;\n\n Disable (LIGHTING);\n Disable (TEXTURE_2D);\n\n Color (red => 0.7,\n green => 0.7,\n blue => 0.6);\n\n GLUT_2D.Text_output ((1.0, 0.0, 0.0), \" (x)\", GLUT_2D.Times_Roman_24);\n GLUT_2D.Text_output ((0.0, 1.0, 0.0), \" (y)\", GLUT_2D.Times_Roman_24);\n GLUT_2D.Text_output ((0.0, 0.0, 1.0), \" (z)\", GLUT_2D.Times_Roman_24);\n\n GLUT_2D.Text_output (0, 50, Self.main_size_x, Self.main_size_y,\n \"Eye : \" & Coords (Self.Camera.Clipper.Eye_Position),\n GLUT_2D.Helvetica_10);\n\n GLUT_2D.Text_output (0, 60, Self.main_size_x, Self.main_size_y,\n \"View direction : \" & Coords (Self.Camera.Clipper.view_direction),\n GLUT_2D.Helvetica_10);\n\n for i in light_info'Range loop\n\n if Is_light_switched (i) then\n light_info (i) := Character'Val (Character'Pos ('0') + i);\n else\n light_info (i) := 'x';\n end if;\n end loop;\n\n GLUT_2D.Text_output (0, 70, Self.main_size_x, Self.main_size_y, \"Lights : (\" & light_info & ')', GLUT_2D.Helvetica_10);\n\n if sec > 0.0 then\n GLUT_2D.Text_output (0, 130, Self.main_size_x, Self.main_size_y, \"FPS : \" & Integer'Image (Integer (1.0 / sec)), GLUT_2D.Helvetica_10);\n end if;\n\n if Self.is_capturing_Video then\n GLUT_2D.Text_output (0, 150, Self.main_size_x, Self.main_size_y, \"*recording*\", GLUT_2D.Helvetica_10);\n end if;\n\n PopMatrix;\n\n end Display_status;\n\n function Frames_per_second (Self : Window) return Float is (Float (1.0 / (Self.Average * 0.001)));\n\n procedure Graphic_display (Self : in out Window'Class;\n Extras : GLOBE_3D.Visual_array := GLOBE_3D.null_Visuals) is\n\n use G3D;\n\n begin\n G3D.render (Self.Objects (1 .. Self.object_Count) & Extras, Self.Camera);\n\n if Self.Show_Status then\n Display_status (Self, Self.Average * 0.001);\n end if;\n end Graphic_display;\n\n procedure Fill_screen (Self : in out Window'Class;\n Extras : GLOBE_3D.Visual_array := GLOBE_3D.null_Visuals) is\n\n procedure Display is\n\n begin\n Graphic_display (Self, Extras);\n end Display;\n\n package SAA is new GLOBE_3D.Software_Anti_Aliasing (Display);\n begin\n\n case Self.Smoothing is\n\n when Software =>\n SAA.Set_Quality (SAA.Q3);\n for SAA_Phase in 1 .. SAA.Anti_Alias_phases loop\n SAA.Display_with_Anti_Aliasing (SAA_Phase);\n end loop;\n\n when Hardware =>\n Enable (MULTISAMPLE_ARB); -- (if not done yet)\n\n -- ClearColor (0.0, 0.0, 0.0, 1.0); -- Specifies clear values for color buffer (s)\n -- ClearColor (0.15, 0.4, 0.15, 1.0); -- Specifies clear values for color buffer (s) -- tbd : make clear color user - settable\n ClearColor (0.0, 0.0, 0.0, 1.0); -- Specifies clear values for color buffer (s) -- tbd : make clear color user - settable\n ClearAccum (0.0, 0.0, 0.0, 0.0); -- Specifies clear values for the accumulation buffer\n\n Graphic_display (Self, Extras);\n Flush;\n\n when None =>\n Graphic_display (Self, Extras);\n Flush;\n end case;\n\n GLUT.SwapBuffers;\n end Fill_screen;\n\n procedure Reset_eye (Self : in out Window'Class) is\n\n begin\n Self.Camera.Clipper.Eye_Position := (0.0, 5.0, 4.0);\n Self.Camera.World_Rotation := GLOBE_3D.Id_33;\n end Reset_eye;\n\n function Image (Date : Ada.Calendar.Time) return String;\n -- Proxy for Ada 2005 Ada.Calendar.Formatting.Image\n\n procedure Main_Operations (Self : access Window;\n time_Step : G3D.Real;\n Extras : GLOBE_3D.Visual_array := GLOBE_3D.null_Visuals) is\n\n use G3D, G3D.REF, Game_Control;\n\n elaps, time_now : Integer;\n gx, gy : GL.Double; -- mouse movement since last call\n seconds : GL.Double; -- seconds since last image\n alpha_correct : Boolean;\n attenu_t, attenu_r : Real;\n\n begin\n if not Self.all.is_Visible or else Self.all.is_Closed then\n return;\n end if;\n\n enable_Viewport_and_Perspective (Self.all); -- nb : must be done prior to setting frustum planes (when using GL.frustums.current_Planes)\n\n -- Control of lighting\n --\n -- self.frontal_light.position := (GL.Float (self.Camera.Clipper.eye_Position (0)),\n -- GL.Float (self.Camera.Clipper.eye_Position (1)),\n -- GL.Float (self.Camera.Clipper.eye_Position (2)),\n -- 1.0);\n -- G3D.Define (1, self.frontal_light);\n\n for c in n1 .. n8 loop\n if Self.all.game_command (c) then\n Reverse_light_switch (1 + Command'Pos (c) - Command'Pos (n1));\n end if;\n end loop;\n\n -- Display screen\n --\n Fill_screen (Self.all, Extras);\n\n -- Timer management\n --\n time_now := GLUT.Get (GLUT.ELAPSED_TIME); -- Number of milliseconds since GLUT.Init\n\n if Self.all.new_scene then\n Self.all.new_scene := False;\n elaps := 0;\n else\n elaps := time_now - Self.all.last_time;\n end if;\n\n Self.all.last_time := time_now;\n Self.all.Average := 0.0;\n\n for i in reverse Self.all.sample'First + 1 .. Self.all.sample'Last loop\n Self.all.sample (i) := Self.all.sample (i - 1);\n Self.all.Average := Self.all.Average + Real (Self.all.sample (i));\n end loop;\n\n Self.all.sample (Self.all.sample'First) := elaps;\n\n Self.all.Average := Self.all.Average + Real (elaps);\n Self.all.Average := Self.all.Average / Real (Self.all.sample'Length);\n\n seconds := Real (elaps) * 0.001;\n attenu_t := Real'Min (0.96, Real'Max (0.04, 1.0 - seconds * 4.0));\n attenu_r := attenu_t ** 0.5;\n\n -- Game control management\n --\n Self.all.game_command := no_command;\n\n Game_Control.Append_Commands (size_x => Integer (Self.all.main_size_x),\n size_y => Integer (Self.all.main_size_y),\n warp_mouse => Self.all.full_screen,\n c => Self.all.game_command,\n gx => gx,\n gy => gy,\n Keyboard => Self.all.Keyboard'Access,\n Mouse => Self.all.Mouse'Access);\n\n if Self.all.forget_mouse > 0 then -- mouse coords disturbed by resize\n gx := 0.0;\n gy := 0.0;\n Self.all.forget_mouse := Self.all.forget_mouse - 1;\n end if;\n\n if Self.all.game_command (interrupt_game) then\n null; -- GLUT_exit; -- tbd : how to handle this best ?\n end if;\n\n alpha_correct := False;\n\n if Self.all.game_command (special_plus) then\n Self.all.Alpha := Self.all.Alpha + seconds; alpha_correct := True;\n end if;\n if Self.all.game_command (special_minus) then\n Self.all.Alpha := Self.all.Alpha - seconds; alpha_correct := True;\n end if;\n\n if alpha_correct then\n if Self.all.Alpha < 0.0 then\n Self.all.Alpha := 0.0;\n elsif Self.all.Alpha > 1.0 then\n Self.all.Alpha := 1.0;\n end if;\n\n for Each in 1 .. Self.all.object_Count loop\n set_Alpha (Self.all.Objects (Each).all, Self.all.Alpha);\n end loop;\n end if;\n\n -- Camera/Eye - nb : camera movement is done after rendering, so camera is in a state ready for the next frame.\n -- - (important for Impostors)\n\n -- Rotating the eye\n\n Actors.Rotation (Self.all.Camera,\n gc => Self.all.game_command,\n gx => gx,\n gy => gy,\n unitary_change => seconds,\n deceleration => attenu_r,\n time_step => time_Step);\n\n -- Moving the eye\n\n Actors.Translation (Self.all.Camera,\n gc => Self.all.game_command,\n gx => gx,\n gy => gy,\n unitary_change => seconds,\n deceleration => attenu_t,\n time_step => time_Step);\n\n if Self.all.game_command (n0) then\n Reset_eye (Self.all);\n end if;\n\n Self.all.Camera.Clipper.view_direction := Transpose (Self.all.Camera.World_Rotation) * (0.0, 0.0, -1.0);\n\n -- update camera frustum\n --\n MatrixMode (MODELVIEW);\n Set_GL_Matrix (Self.all.Camera.World_Rotation);\n Translate (-Self.all.Camera.Clipper.Eye_Position (0), -Self.all.Camera.Clipper.Eye_Position (1), -Self.all.Camera.Clipper.Eye_Position (2));\n\n Self.all.Camera.frustum_Planes := GL.Frustums.Current_Planes; -- tbd : getting frustum planes from camera, might be quicker,\n -- set_frustum_Planes (Self.Camera); -- but 'set_frustum_Planes' seems buggy :/.\n\n -- video management\n --\n if Self.all.game_command (video) then\n if Self.all.is_capturing_Video then\n GL.IO.Stop_Capture;\n Self.all.is_capturing_Video := False;\n else\n GL.IO.Start_Capture (AVI_Name => To_String (Self.all.Name) & \".\" & Image (Ada.Calendar.Clock) & \".avi\",\n frame_rate => 8); -- Integer (self.Frames_per_second));\n Self.all.is_capturing_Video := True;\n end if;\n end if;\n\n if Self.all.is_capturing_Video then\n GL.IO.Capture_Frame;\n end if;\n\n -- photo management\n --\n if Self.all.game_command (photo) then\n GL.IO.Screenshot (Name => To_String (Self.all.Name) & \".\" & Image (Ada.Calendar.Clock) & \".bmp\");\n end if;\n\n end Main_Operations;\n\n procedure Close_Window is\n\n begin\n current_Window.all.is_Closed := True;\n end Close_Window;\n\n procedure Update_Visibility (State : Integer) is\n\n begin\n -- ada.text_io.put_line (\"in update_Visibility callback state : \" & integer'image (State));\n --\n -- tbd : this callback is not being called when a window is iconicised !!\n\n current_Window.all.is_Visible := not (State = GLUT.HIDDEN or else State = GLUT.FULLY_COVERED);\n end Update_Visibility;\n\n procedure Start_GLUTs (Self : in out Window) is\n\n use GLUT;\n\n function to_Address is new Ada.Unchecked_Conversion (GLOBE_3D.p_Window, System.Address);\n\n GLUT_options : GLUT.Unsigned := GLUT.DOUBLE or GLUT.RGBA or GLUT.ALPHA or GLUT.DEPTH;\n\n begin\n if Self.Smoothing = Hardware then\n GLUT_options := GLUT_options or GLUT.MULTISAMPLE;\n end if;\n\n InitDisplayMode (GLUT_options);\n\n set_Size (Self, 500, 400);\n\n InitWindowSize (Integer (Self.main_size_x), Integer (Self.main_size_y));\n InitWindowPosition (120, 120);\n\n Self.glut_Window := CreateWindow (\"GLOBE_3D/GLUT Window\");\n\n if Self.glut_Window = 0 then\n raise GLUT_Problem;\n end if;\n\n GLUT.CloseFunc (Close_Window'Access);\n GLUT.ReshapeFunc (Window_Resize'Access);\n GLUT.WindowStatusFunc (Update_Visibility'Access);\n GLUT.SetWindowData (to_Address (GLOBE_3D.Window'Class (Self)'Unchecked_Access));\n\n GLUT.Devices.Initialize;\n\n -- if CreateMenu (Menu'Access) = 0 then -- tdb : deferred\n -- raise GLUT_Problem;\n -- end if;\n\n -- AttachMenu (MIDDLE_BUTTON);\n\n -- AddMenuEntry (\" * Full Screen\", 1);\n -- AddMenuEntry (\"--> Exit (Esc)\", 2);\n\n end Start_GLUTs;\n\n procedure Start_GLs (Self : in out Window) is\n\n fog_colour : GL.Light_Float_vector := (0.2, 0.2, 0.2, 0.1);\n\n begin\n\n Clear_modes;\n Prepare_default_lighting (Self, 0.9);\n\n if Self.foggy then\n Enable (FOG);\n Fogfv (FOG_COLOR, fog_colour (0)'Unchecked_Access);\n Fogf (FOG_DENSITY, 0.02);\n end if;\n\n Reset_for_3D (Self);\n\n if Self.Smoothing = Hardware then\n Enable (MULTISAMPLE_ARB);\n Enable (SAMPLE_COVERAGE_ARB); -- Hope it helps switching on the AA .. .\n end if;\n\n end Start_GLs;\n\n procedure Initialize is\n\n begin\n GLUT.Init;\n GLUT.SetOption (GLUT.GLUT_RENDERING_CONTEXT, GLUT.GLUT_USE_CURRENT_CONTEXT);\n GLUT.SetOption (GLUT.ACTION_ON_WINDOW_CLOSE, ACTION_CONTINUE_EXECUTION);\n end Initialize;\n\n procedure Define (Self : in out Window) is\n\n begin\n Start_GLUTs (Self); -- Initialize the GLUT things\n Start_GLs (Self); -- Initialize the (Open)GL things\n Reset_eye (Self);\n\n Freshen (Self, 0.02); -- do an initial freshen, to initialise Camera, etc.\n end Define;\n\n procedure Destroy (Self : in out Window) is\n\n begin\n DestroyWindow (Self.glut_Window);\n end Destroy;\n\n overriding procedure Enable (Self : in out Window) is\n\n begin\n GLUT.SetWindow (Self.glut_Window);\n -- opengl.glx.glXMakeCurrent;\n end Enable;\n\n overriding procedure Freshen (Self : in out Window;\n time_Step : G3D.Real;\n Extras : GLOBE_3D.Visual_array := GLOBE_3D.null_Visuals) is\n\n begin\n Enable (Self); -- for multi - window operation.\n Main_Operations (Self'Access, time_Step, Extras);\n end Freshen;\n\n -- traits\n --\n\n function Smoothing (Self : Window) return Smoothing_method is (Self.Smoothing);\n\n procedure Smoothing_is (Self : in out Window;\n Now : Smoothing_method) is\n\n begin\n Self.Smoothing := Now;\n end Smoothing_is;\n\n procedure Add (Self : in out Window; the_Object : GLOBE_3D.p_Visual) is\n\n begin\n Self.object_Count := Self.object_Count + 1;\n Self.Objects (Self.object_Count) := the_Object.all'Access;\n end Add;\n\n procedure Rid (Self : in out Window; the_Object : GLOBE_3D.p_Visual) is\n\n use G3D;\n\n begin\n for Each in 1 .. Self.object_Count loop\n\n if Self.Objects (Each) = the_Object then\n\n if Each /= Self.object_Count then\n Self.Objects (Each .. Self.object_Count - 1) := Self.Objects (Each + 1 .. Self.object_Count);\n end if;\n\n Self.object_Count := Self.object_Count - 1;\n return;\n end if;\n\n end loop;\n\n raise no_such_Object;\n end Rid;\n\n function Object_Count (Self : Window) return Natural is (Self.object_Count);\n\n -- status display\n --\n\n function Show_Status (Self : Window) return Boolean is (Self.Show_Status);\n\n procedure Show_Status (Self : in out Window;\n Show : Boolean := True) is\n\n begin\n Self.Show_Status := Show;\n end Show_Status;\n\n -- Devices\n --\n\n function Keyboard (Self : access Window'Class) return Devices.p_Keyboard is (Self.all.Keyboard'Access);\n\n function Mouse (Self : access Window'Class) return Devices.p_Mouse is (Self.all.Mouse'Access);\n\n -- Proxy for Ada 2005 Ada.Calendar.Formatting.Image\n function Image (Date : Ada.Calendar.Time) return String is\n\n use Ada.Calendar;\n\n subtype Sec_int is Long_Integer; -- must contain 86_400\n\n m, s : Sec_int;\n\n begin\n s := Sec_int (Seconds (Date));\n m := s / 60;\n\n declare\n -- + 100 : trick for obtaining 0x\n sY : constant String := Integer'Image (Year (Date));\n sM : constant String := Integer'Image (Month (Date) + 100);\n sD : constant String := Integer'Image (Day (Date) + 100);\n shr : constant String := Sec_int'Image (m / 60 + 100);\n smn : constant String := Sec_int'Image (m mod 60 + 100);\n ssc : constant String := Sec_int'Image (s mod 60 + 100);\n\n begin\n return\n sY (sY'Last - 3 .. sY'Last) & '-' & -- not Year 10'000 compliant.\n sM (sM'Last - 1 .. sM'Last) & '-' &\n sD (sD'Last - 1 .. sD'Last) &\n \" \" &\n shr (shr'Last - 1 .. shr'Last) & '.' &\n smn (smn'Last - 1 .. smn'Last) & '.' &\n ssc (ssc'Last - 1 .. ssc'Last);" + }, + { + "function_def": "function New_List_Id return List_Ids;", + "function_body": "private\n Available_List_Id : List_Ids := List_Ids'First;\n end List_Id_Generator;\n package body List_Id_Generator is\n function New_List_Id return List_Ids is\n begin\n Available_List_Id := Available_List_Id + 1;\n return Available_List_Id - 1;\n end New_List_Id;\n end List_Id_Generator;\n --\n function Image (r : Real) return String is\n s : String (1 .. 10);\n begin\n RIO.Put (s, r, 4, 0);\n return s;\n exception\n when Ada.Text_IO.Layout_Error =>\n return Real'Image (r);\n end Image;\n function Coords (p : Point_3D) return String is\n begin\n return ' (' & Image (p (0)) &\n ', ' & Image (p (1)) &\n ', ' & Image (p (2)) &\n ')';\n end Coords;\n\n -- normal support\n --\n procedure Add_Normal_of_3p (o : in Object_3d'Class;\n Pn0, Pn1, Pn2 : in Integer;\n N : in out Vector_3D) is\n use GL, G3dm;\n function Params return String is\n begin\n return\n \" Object : \" & Trim (o.id, right) &\n \" Pn0=\" & Integer'Image (Pn0) &\n \" Pn1=\" & Integer'Image (Pn1) &\n \" Pn2=\" & Integer'Image (Pn2);\n end Params;\n N_contrib : Vector_3D;\n begin\n if Pn0=0 or Pn1=0 or Pn2=0 then return; end if;\n N_contrib := (o.point (Pn1) - o.point (Pn0))* (o.point (Pn2) - o.point (Pn0)) ;\n if strict_geometry and then Almost_zero (Norm2 (N_contrib)) then\n raise_exception (zero_normal'Identity,\n Params &\n \" P0=\" & Coords (o.point (Pn0)) &\n \" P1=\" & Coords (o.point (Pn1)) &\n \" P2=\" & Coords (o.point (Pn2)) &\n \" Nc=\" & Coords (N_contrib)\n);\n end if;\n N := N + N_contrib;\n exception\n when e : others =>\n raise_exception (\n Exception_Identity (e),\n Exception_Message (e) & Params\n);\n end Add_Normal_of_3p;\n\n -- blending support\n --\n function Is_to_blend (m : GL.Double) return Boolean is\n use GL, G3DM;\n begin\n return not Almost_zero (m - 1.0);\n end Is_to_blend;\n function Is_to_blend (m : GL.Float) return Boolean is\n use GL, G3DM;\n begin\n return not Almost_zero (m - 1.0);\n end Is_to_blend;\n function Is_to_blend (m : GL.Material_Float_vector) return Boolean is\n begin\n return Is_to_blend (m (3));\n end Is_to_blend;\n function Is_to_blend (m : GL.Materials.Material_type) return Boolean is\n begin\n return\n Is_to_blend (m.ambient) or\n Is_to_blend (m.diffuse) or\n Is_to_blend (m.specular);\n -- m.emission, m.shininess not relevant\n end Is_to_blend;\n -- material support\n --\n procedure Set_Material (m : GL.Materials.Material_type) is\n use GL;\n begin\n Material (FRONT_AND_BACK, AMBIENT, m.ambient);\n Material (FRONT_AND_BACK, DIFFUSE, m.diffuse);\n Material (FRONT_AND_BACK, SPECULAR, m.specular);\n Material (FRONT_AND_BACK, EMISSION, m.emission);\n Material (FRONT_AND_BACK, SHININESS, m.shininess);\n end Set_Material;\n -- 'Visual'\n --\n procedure free (o : in out p_Visual)\n is\n procedure deallocate is new ada.unchecked_deallocation (Visual'Class, p_Visual);\n begin\n destroy (o.all);\n deallocate (o);\n end free;\n function skinned_Geometrys (o : in Visual) return GL.skinned_geometry.skinned_Geometrys\n is\n begin\n return GL.skinned_geometry.null_skinned_Geometrys;\n end skinned_Geometrys;\n function Width (o : in Visual'class) return Real\n is\n begin\n return bounds (o).box.X_Extent.Max - bounds (o).box.X_Extent.Min;\n end Width;\n function Height (o : in Visual'class) return Real\n is\n begin\n return bounds (o).box.Y_Extent.Max - bounds (o).box.Y_Extent.Min;\n end Height;\n function Depth (o : in Visual'class) return Real\n is\n begin\n return bounds (o).box.Z_Extent.Max - bounds (o).box.Z_Extent.Min;\n end Depth;\n -- 'Object_3D'\n --\n -- object validation\n --\n procedure Check_object (o : Object_3D) is\n use G3DM;\n procedure Check_faces is\n procedure Check (f, v : Integer) is\n pragma Inline (Check);\n begin\n if v < 0 or else v > o.max_points then\n raise_exception (bad_vertex_number'Identity,\n o.id & \" face=\" & Integer'Image (f) &\n \" vertex=\" & Integer'Image (v));\n end if;\n end Check;\n procedure Check_duplicate (f, Pn1, Pn2 : Integer) is\n pragma Inline (Check_duplicate);\n begin\n -- Skip \"dead\" edge (triangle), 30 - Dec - 2001\n if Pn1=0 or else Pn2=0 then return; end if;\n -- Detect same point number\n if Pn1=Pn2 then\n raise_exception (duplicated_vertex'Identity,\n o.id & \" in face \" & Integer'Image (f));\n end if;\n -- Detect same point coordinates (tolerated in an object,\n -- although inefficient, but harms as vertex of the same face!)\n if Almost_zero (Norm2 (o.point (Pn1) - o.point (Pn2))) then\n raise_exception (duplicated_vertex_location'Identity,\n o.id & \" in face \" & Integer'Image (f));\n end if;\n end Check_duplicate;\n begin\n for fa in o.face'Range loop\n for edge_num in 1 .. 4 loop\n Check (fa, o.face (fa).P (edge_num));\n for other_edge in edge_num + 1 .. 4 loop\n Check_duplicate (fa, o.face (fa).P (edge_num),\n o.face (fa).P (other_edge));\n end loop;\n end loop;\n end loop; -- fa\n end Check_faces;\n begin\n Check_faces;\n end Check_object;\n --------------------------------------------\n -- Object initialization (1x in its life) --\n --------------------------------------------\n procedure Pre_calculate (o : in out Object_3D) is\n use GL, G3DM;\n N : Vector_3D;\n length_N : Real;\n procedure Calculate_face_invariants (\n fa : in Face_type;\n fi : out Face_invariant_type\n) is\n l : Natural := 0;\n quadri_edge : array (fa.P'Range) of Natural;\n ex_U, ex_V : Real;\n begin\n l := 0;\n for qe in fa.P'Range loop\n if fa.P (qe) /= 0 then\n l := l + 1;\n quadri_edge (l) := qe; -- if triangle, \"map\" edge on a quadri\n fi.P_compact (l) := fa.P (qe);\n end if;\n end loop;\n if l in Edge_count then\n fi.last_edge := l;\n else\n raise_exception (bad_edge_number'Identity, o.id);\n end if;\n -- * Face invariant : Textured face : extremities\n for e in 1 .. l loop\n if fa.whole_texture then\n ex_U := Real (fa.repeat_U);\n ex_V := Real (fa.repeat_V);\n case quadri_edge (e) is\n when 1 => fi.UV_extrema (e) := (0.0, 0.0); -- bottom, left 4 --< --3\n when 2 => fi.UV_extrema (e) := (ex_U, 0.0); -- bottom, right | |\n when 3 => fi.UV_extrema (e) := (ex_U, ex_V); -- top, right 1 --> --2\n when 4 => fi.UV_extrema (e) := (0.0, ex_V); -- top, left\n when others => null;\n end case;\n else\n -- Just copy the mapping, but in compact form for triangles:\n fi.UV_extrema (e) := fa.texture_edge_map (quadri_edge (e));\n end if;\n end loop;\n -- * Face invariant : Normal of unrotated face\n N := (0.0, 0.0, 0.0);\n case fi.last_edge is\n when 3 =>\n Add_Normal_of_3p (o,\n fi.P_compact (1),\n fi.P_compact (2),\n fi.P_compact (3),\n N\n);\n when 4 =>\n Add_Normal_of_3p (o, fa.P (1), fa.P (2), fa.P (4), N);\n -- We sum other normals for not perfectly flat faces,\n -- in order to have a convenient average .. .\n Add_Normal_of_3p (o, fa.P (2), fa.P (3), fa.P (1), N);\n Add_Normal_of_3p (o, fa.P (3), fa.P (4), fa.P (2), N);\n Add_Normal_of_3p (o, fa.P (4), fa.P (1), fa.P (3), N);\n end case;\n length_N := Norm (N);\n if Almost_zero (length_N) then\n if strict_geometry then\n raise zero_summed_normal;\n else\n fi.normal := N; -- 0 vector !\n end if;\n else\n fi.normal := (1.0 / length_N) * N;\n end if;\n end Calculate_face_invariants;\n adjacent_faces : array (o.point'Range) of Natural := (others => 0);\n pf : Natural;\n length : Real;\n begin --Pre_calculate\n if full_check_objects then Check_object (o); end if;\n for i in o.face'Range loop\n begin\n -- Geometry\n Calculate_face_invariants (o.face (i), o.face_invariant (i));\n -- Disable blending when alphas are = 1\n case o.face (i).skin is\n when material_only | material_texture =>\n o.face_invariant (i).blending := Is_to_blend (o.face (i).material);\n when colour_only | coloured_texture | texture_only =>\n o.face_invariant (i).blending := Is_to_blend (o.face (i).alpha);\n when invisible =>\n o.face_invariant (i).blending := False;\n end case;\n o.transparent := o.transparent or o.face_invariant (i).blending;\n exception\n when zero_summed_normal =>\n raise_exception (zero_summed_normal'Identity,\n o.id & \" face=\" & Integer'Image (i));" + }, + { + "function_def": "procedure Display_one (o : in out Object_3D) is", + "function_body": "-- Display only this object and not connected objects\n -- out : object will be initialized if not yet\n --\n --\n -- Display face routine which is optimized to produce a shorter list\n -- of GL commands. Runs slower then the original Display face routine\n -- yet needs to be executed only once.\n --\n -- Uwe R. Zimmer, July 2011\n --\n package Display_face_optimized is\n procedure Display_face (First_Face : Boolean; fa : Face_type; fi : in out Face_invariant_type);\n private\n Previous_face : Face_type;\n Previous_face_Invariant : Face_invariant_type;\n end Display_face_optimized;\n package body Display_face_optimized is\n use GL.Materials;\n procedure Display_face (First_Face : Boolean; fa : Face_type; fi : in out Face_invariant_type) is\n use GL;\n blending_hint : Boolean;\n begin -- Display_face\n if fa.skin = invisible then\n Previous_face := fa;\n Previous_face_Invariant := fi;\n return;\n end if;\n --------------\n -- Material --\n --------------\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then fa.material /= Previous_face.material) then\n case fa.skin is\n when material_only | material_texture =>\n Disable (COLOR_MATERIAL);\n Set_Material (fa.material);\n when others =>\n Set_Material (GL.Materials.neutral_material);\n end case;\n end if;\n ------------\n -- Colour --\n ------------\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then (fa.colour /= Previous_face.colour\n or else fa.alpha /= Previous_face.alpha)) then\n case fa.skin is\n when material_only | material_texture =>\n null; -- done above\n when colour_only | coloured_texture =>\n Enable (COLOR_MATERIAL);\n ColorMaterial (FRONT_AND_BACK, AMBIENT_AND_DIFFUSE);\n Color (red => fa.colour.red,\n green => fa.colour.green,\n blue => fa.colour.blue,\n alpha => fa.alpha);\n when texture_only =>\n Disable (COLOR_MATERIAL);\n when invisible =>\n null;\n end case;\n end if;\n -------------\n -- Texture --\n -------------\n if First_Face\n or else Previous_face.skin = invisible\n or else fa.skin /= Previous_face.skin\n or else (fa.skin = Previous_face.skin\n and then fa.texture /= Previous_face.texture) then\n case fa.skin is\n when texture_only | coloured_texture | material_texture =>\n Enable (TEXTURE_2D);\n G3DT.Check_2D_texture (fa.texture, blending_hint);\n GL.BindTexture (GL.TEXTURE_2D, GL.Uint (Image_id'Pos (fa.texture) + 1));\n -- ^ superfluous ?!!\n if blending_hint then\n fi.blending := True;\n -- 13 - Oct - 2006 : override decision made at Pre_calculate\n -- if texture data contains an alpha layer\n end if;\n when colour_only | material_only =>\n Disable (TEXTURE_2D);\n when invisible =>\n null;\n end case;\n end if;\n -----------------------------\n -- Blending / transparency --\n -----------------------------\n if First_Face\n or else Previous_face.skin = invisible\n or else fi.blending /= Previous_face_Invariant.blending then\n if fi.blending then\n Enable (BLEND); -- See 4.1.7 Blending\n BlendFunc (sfactor => SRC_ALPHA,\n dfactor => ONE_MINUS_SRC_ALPHA);\n -- Disable (DEPTH_TEST);\n -- Disable (CULL_FACE);\n else\n Disable (BLEND);\n -- Enable (DEPTH_TEST);\n -- Enable (CULL_FACE);\n -- CullFace (BACK);\n end if;\n end if;\n -------------\n -- Drawing --\n -------------\n case fi.last_edge is\n when 3 => GL_Begin (TRIANGLES);\n when 4 => GL_Begin (QUADS);\n end case;\n for i in 1 .. fi.last_edge loop\n if is_textured (fa.skin) then\n TexCoord (fi.UV_extrema (i).U, fi.UV_extrema (i).V);\n end if;\n Normal (o.edge_vector (fi.P_compact (i)));\n Vertex (o.point (fi.P_compact (i)));\n end loop;\n GL_End;\n Previous_face := fa;\n Previous_face_Invariant := fi;\n end Display_face;\n end Display_face_optimized;\n --\n procedure Display_face (fa : Face_type; fi : in out Face_invariant_type) is\n use GL;\n blending_hint : Boolean;\n begin -- Display_face\n if fa.skin = invisible then\n return;\n end if;\n --------------\n -- Material --\n --------------\n case fa.skin is\n when material_only | material_texture =>\n Disable (COLOR_MATERIAL);\n Set_Material (fa.material);\n neutral_material_already_set := False;\n when others =>\n -- Avoid setting again and again the neutral material\n if not neutral_material_already_set then\n Set_Material (GL.Materials.neutral_material);\n neutral_material_already_set := True;\n end if;\n end case;\n ------------\n -- Colour --\n ------------\n case fa.skin is\n when material_only | material_texture =>\n null; -- done above\n when colour_only | coloured_texture =>\n Enable (COLOR_MATERIAL);\n ColorMaterial (FRONT_AND_BACK, AMBIENT_AND_DIFFUSE);\n Color (\n red => fa.colour.red,\n green => fa.colour.green,\n blue => fa.colour.blue,\n alpha => fa.alpha\n);\n when texture_only =>\n Disable (COLOR_MATERIAL);\n when invisible =>\n null;\n end case;\n -------------\n -- Texture --\n -------------\n case fa.skin is\n when texture_only | coloured_texture | material_texture =>\n Enable (TEXTURE_2D);\n G3DT.Check_2D_texture (fa.texture, blending_hint);\n GL.BindTexture (GL.TEXTURE_2D, GL.Uint (Image_id'Pos (fa.texture) + 1));\n -- ^ superfluous ?!!\n if blending_hint then\n fi.blending := True;\n -- 13 - Oct - 2006 : override decision made at Pre_calculate\n -- if texture data contains an alpha layer\n end if;\n when colour_only | material_only =>\n Disable (TEXTURE_2D);\n when invisible =>\n null;\n end case;\n -----------------------------\n -- Blending / transparency --\n -----------------------------\n if fi.blending then\n Enable (BLEND); -- See 4.1.7 Blending\n BlendFunc (sfactor => SRC_ALPHA,\n dfactor => ONE_MINUS_SRC_ALPHA);\n -- Disable (DEPTH_TEST);\n -- Disable (CULL_FACE);\n else\n Disable (BLEND);\n -- Enable (DEPTH_TEST);\n -- Enable (CULL_FACE);\n -- CullFace (BACK);\n end if;\n -------------\n -- Drawing --\n -------------\n case fi.last_edge is\n when 3 => GL_Begin (TRIANGLES);\n when 4 => GL_Begin (QUADS);\n end case;\n for i in 1 .. fi.last_edge loop\n if is_textured (fa.skin) then\n TexCoord (fi.UV_extrema (i).U, fi.UV_extrema (i).V);\n end if;\n Normal (o.edge_vector (fi.P_compact (i)));\n Vertex (o.point (fi.P_compact (i)));\n end loop;\n GL_End;\n end Display_face;\n procedure Display_normals is\n use GL, G3DM;\n C : Vector_3D;\n begin\n GL.Color (0.5, 0.5, 1.0, 1.0);\n -- show pseudo (average) normals at edges:\n for e in o.point'Range loop\n Arrow (o.point (e), arrow_inflator * o.edge_vector (e));\n end loop;\n GL.Color (1.0, 1.0, 0.5, 1.0);\n -- show normals of faces:\n for f in o.face'Range loop\n C := (0.0, 0.0, 0.0);\n for i in 1 .. o.face_invariant (f).last_edge loop\n C := C + o.point (o.face_invariant (f).P_compact (i));\n end loop;\n C := (1.0/Real (o.face_invariant (f).last_edge)) * C;\n Arrow (C, arrow_inflator * o.face_invariant (f).normal);\n end loop;\n end Display_normals;\n use GL, G3DM;\n begin -- Display_one\n if not o.pre_calculated then\n Pre_calculate (o);\n end if;\n GL.bindBuffer (gl.ARRAY_BUFFER, 0); -- disable 'vertex buffer objects'\n GL.bindBuffer (gl.ELEMENT_ARRAY_BUFFER, 0); -- disable 'vertex buffer objects' indices\n -- GL.disableClientState (gl.TEXTURE_COORD_ARRAY);\n -- GL.disable (ALPHA_TEST);\n GL.enable (Lighting);\n GL.PushMatrix; -- 26 - May - 2006 : instead of rotating/translating back\n GL.Translate (o.centre);\n Multiply_GL_Matrix (o.rotation);\n -- List preparation phase\n case o.List_Status is\n when No_list | Is_List => null;\n when Generate_List =>\n o.List_Id := List_Id_Generator.New_List_Id;\n GL.NewList (GL.uint (o.List_Id), COMPILE_AND_EXECUTE);\n end case;\n -- Execution phase\n case o.List_Status is\n when No_list =>\n for f in o.face'Range loop\n Display_face (o.face (f), o.face_invariant (f));\n end loop;\n when Generate_List =>\n for f in o.face'Range loop\n Display_face_optimized.Display_face (f = o.face'First, o.face (f), o.face_invariant (f));\n end loop;\n when Is_List => GL.CallList (GL.uint (o.List_Id));\n end case;\n -- Close list\n case o.List_Status is\n when No_list | Is_List => null;\n when Generate_List =>\n GL.EndList;\n if GL.GetError = OUT_OF_MEMORY then\n o.List_Status := No_List;\n else\n o.List_Status := Is_List;\n end if;\n end case;\n if show_normals then\n GL.Disable (GL.LIGHTING);\n GL.Disable (GL.TEXTURE_2D);\n Display_normals;\n GL.Enable (GL.LIGHTING); -- mmmh .. .\n end if;\n GL.PopMatrix; -- 26 - May - 2006 : instead of rotating/translating back\n -- GL.Rotate (o.auto_rotation (2), 0.0, 0.0, - 1.0);\n -- GL.Rotate (o.auto_rotation (1), 0.0, - 1.0, 0.0);\n -- GL.Rotate (o.auto_rotation (0), - 1.0, 0.0, 0.0);\n -- GL.Translate ( - o.centre);\n end Display_one;\n procedure Display (\n o : in out Object_3D;\n clip : in Clipping_data\n)\n is\n use GLOBE_3D.Portals;\n procedure Display_clipped (\n o : in out Object_3D'Class;\n clip_area : in Clipping_area;\n portal_depth : in Natural\n)\n is\n procedure Try_portal (f : Positive) is\n use G3DM, GL;\n dp : Real;\n plane_to_eye : Vector_3D; -- vector from any point in plane to the eye\n bounding_of_face, intersection_clip_and_face : Clipping_area;\n success, non_empty_intersection : Boolean;\n begin\n -- Culling #1 : check if portal is in vield of view's \"dead angle\"\n dp := o.face_invariant (f).normal * clip.view_direction;\n if dp < clip.max_dot_product then\n -- Culling #2 : check if we are on the right side of the portal\n -- NB : ignores o.auto_rotation !\n plane_to_eye :=\n clip.eye_position -\n (o.point (o.face_invariant (f).P_compact (1)) + o.centre)\n ;\n dp := plane_to_eye * o.face_invariant (f).normal;\n -- dp = signed distance to the plane\n if dp > 0.0 then\n -- Culling #3 : clipping rectangle\n Find_bounding_box (o, f, bounding_of_face, success);\n if success then\n Intersect (clip_area, bounding_of_face,\n intersection_clip_and_face, non_empty_intersection);\n else\n -- in doubt, draw with the present clipping\n intersection_clip_and_face := clip_area;\n non_empty_intersection := True;\n end if;\n if non_empty_intersection then\n -- Recursion here:\n Display_clipped (\n o => o.face (f).connecting.all,\n clip_area => intersection_clip_and_face,\n portal_depth => portal_depth + 1\n);\n end if;\n end if;\n end if;\n end Try_portal;\n begin -- Display_clipped\n if not o.pre_calculated then\n Pre_calculate (o);\n end if;\n --\n -- a/ Display connected objects which are visible through o's faces\n -- This is where recursion happens\n if (not filter_portal_depth) or else -- filter_portal_depth : test/debug\n portal_depth <= 6\n then\n for f in o.face'Range loop\n if o.face (f).connecting /= null and then\n not o.face_invariant (f).portal_seen\n -- ^ prevents infinite recursion on rare cases where\n -- object A or B is not convex, and A and B see each other\n -- and the culling by clipping cannot stop the recursion\n -- (e.g. origin2.proc, tomb.proc)\n --\n -- NB : drawing [different parts of] the same object several times\n -- is right, since portions can be seen through different portals,\n -- but going more than once through the same portal is wrong\n then\n o.face_invariant (f).portal_seen := True;\n Try_portal (f);\n -- ^ recursively calls Display_clipped for\n -- objects visible through face f.\n end if;\n end loop;\n end if;\n -- b/ Display the object itself\n if (not filter_portal_depth) or else -- filter_portal_depth : test/debug\n (portal_depth = 1 or portal_depth = 5)\n then\n -- The graphical clipping (Scissor) gives various effects\n -- - almost no speedup on the ATI Radeon 9600 Pro (hardware)\n -- - factor : ~ Sqrt (clipped surface ratio) with software GL\n if portal_depth > 0 then\n GL.Enable (GL.SCISSOR_TEST);\n GL.Scissor (\n x => GL.Int (clip_area.x1),\n y => GL.Int (clip_area.y1),\n width => GL.SizeI (clip_area.x2 - clip_area.x1 + 1),\n height => GL.SizeI (clip_area.y2 - clip_area.y1 + 1)\n);\n else\n GL.Disable (GL.SCISSOR_TEST);\n end if;\n info_b_ntl2 := info_b_ntl2 + 1;\n info_b_ntl3 := Natural'Max (portal_depth, info_b_ntl3);\n Display_one (o);\n end if;\n if show_portals and then portal_depth > 0 then\n Draw_boundary (clip.main_clipping, clip_area);\n end if;\n end Display_clipped;\n procedure Reset_portal_seen (o : in out Object_3D'Class) is\n begin\n for f in o.face'Range loop\n if o.face_invariant (f).portal_seen then\n o.face_invariant (f).portal_seen := False;\n Reset_portal_seen (o.face (f).connecting.all);\n end if;\n end loop;\n end Reset_portal_seen;\n begin\n info_b_ntl2 := 0; -- count amount of objects displayed, not distinct\n info_b_ntl3 := 0; -- records max depth\n Display_clipped (o, clip_area => clip.main_clipping, portal_depth => 0);\n Reset_portal_seen (o);\n end Display;\n procedure Destroy (o : in out Object_3D) is\n ol : p_Object_3D_list := o.sub_objects;\n begin\n while ol /= null loop\n Free (p_Visual (ol.objc));\n ol := ol.next;\n end loop;\n end Destroy;\n procedure set_Alpha (o : in out Object_3D; Alpha : in GL.Double) is\n begin\n for f in o.face'Range loop\n o.face (f).alpha := Alpha;\n end loop;\n end set_Alpha;\n function is_Transparent (o : in Object_3D) return Boolean is\n begin\n return o.transparent;\n end is_Transparent;\n function face_Count (o : in Object_3D) return Natural is\n begin\n return o.Max_faces;\n end face_Count;\n function Bounds (o : in Object_3D) return GL.geometry.Bounds_record is\n begin\n return o.Bounds;\n end Bounds;\n -- Lighting support.\n --\n -- lights : array (Light_ident) of Light_definition;\n light_defined : array (Light_ident) of Boolean := (others => False);\n procedure Define (which : Light_ident; as : Light_definition) is\n id : constant GL.LightIDEnm := GL.LightIDEnm'Val (which - 1);\n use GL;\n begin\n -- lights (which) := as;\n Light (id, POSITION, as.position);\n Light (id, AMBIENT, as.ambient);\n Light (id, DIFFUSE, as.diffuse);\n Light (id, SPECULAR, as.specular);\n light_defined (which) := True;\n end Define;\n procedure Switch_lights (on : Boolean) is\n begin\n for l in Light_ident loop\n Switch_light (l, on);\n end loop;\n end Switch_lights;\n function Server_id (which : Light_ident) return GL.ServerCapabilityEnm is\n begin\n return GL.ServerCapabilityEnm'Val (GL.ServerCapabilityEnm'Pos (GL.LIGHT0) + which - 1);\n end Server_id;\n procedure Switch_light (which : Light_ident; on : Boolean) is\n begin\n if light_defined (which) then\n if on then\n GL.Enable (Server_id (which));\n else\n GL.Disable (Server_id (which));\n end if;\n end if;\n end Switch_light;\n function Is_light_switched (which : Light_ident) return Boolean is\n begin\n return Boolean'Val (GL.IsEnabled (Server_id (which)));\n end Is_light_switched;\n procedure Reverse_light_switch (which : Light_ident) is\n begin\n Switch_light (which, not Is_light_switched (which));\n end Reverse_light_switch;\n prec_a360 : constant := 10000;\n r_prec_a360 : constant := 10000.0;\n i_r_prec_a360 : constant := 1.0 / r_prec_a360;\n procedure Angles_modulo_360 (v : in out Vector_3D)is\n use GL;\n begin\n for i in v'Range loop\n v (i) :=\n GL.Double (Integer (r_prec_a360 * v (i)) mod (360*prec_a360))\n * i_r_prec_a360;\n end loop;\n end Angles_modulo_360;\n ------------------\n -- Resource I/O --\n ------------------\n procedure Load_if_needed (zif : in out Zip.Zip_info; name : String) is\n begin\n if not Zip.Is_loaded (zif) then\n begin\n Zip.Load (zif, name);\n exception\n when Zip.Zip_file_open_error => -- Try with lower case:\n Zip.Load (zif, To_Lower (name));" + }, + { + "function_def": "procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,", + "function_body": "visual_geometry,\n visual_geometrys);\n use GL.Skins, GL.Geometry, GL.Skinned_Geometry;\n current_Visual : p_Visual;\n begin\n if geometry_Count > 1 then\n sort (all_Geometrys (1 .. geometry_Count));\n end if;\n GL.PushMatrix;\n for Each in 1 .. geometry_Count loop\n if all_Geometrys (Each).Geometry.Skin /= current_Skin then\n current_Skin := all_Geometrys (Each).Geometry.Skin;\n enable (current_Skin.all);\n GL.Errors.log;\n end if;\n if all_Geometrys (Each).Geometry.Veneer /= null then\n enable (all_Geometrys (Each).Geometry.Veneer.all);\n GL.Errors.log;\n end if;\n if all_Geometrys (Each).Visual = current_Visual then\n draw (all_Geometrys (Each).Geometry.Geometry.all);\n GL.Errors.log;\n else\n GL.PopMatrix;\n GL.PushMatrix;\n GL.Translate (all_Geometrys (Each).Visual.centre);\n Multiply_GL_Matrix (all_Geometrys (Each).Visual.rotation);\n draw (all_Geometrys (Each).Geometry.Geometry.all);\n GL.Errors.log;\n current_Visual := all_Geometrys (Each).Visual;\n end if;\n end loop;\n GL.PopMatrix;" + }, + { + "function_def": "--procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,", + "function_body": "procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,\n globe_3d.p_Visual,\n globe_3d.Visual_array);\n begin\n for Each in 1 .. transparent_Count loop -- pre - calculate each visuals Centre in camera space.\n all_Transparents (Each).Centre_camera_space := the_Camera.world_Rotation\n * (all_Transparents (Each).Centre - the_Camera.Clipper.eye_Position);\n end loop;\n if transparent_Count > 1 then\n sort (all_Transparents (1 .. transparent_Count));\n end if;\n GL.depthMask (gl_False); -- make depth buffer read - only, for correct transparency\n Enable (LIGHTING); -- ensure lighting is enabled for G3D.Display of transparents (obsolete).\n Enable (BLEND);\n BlendFunc (sfactor => ONE,\n dfactor => ONE_MINUS_SRC_ALPHA);\n for Each in 1 .. transparent_Count loop\n declare\n the_Visual : Visual'Class renames all_Transparents (Each).all;\n visual_Geometrys : constant GL.skinned_geometry.skinned_Geometrys := skinned_Geometrys (the_visual); -- tbd : apply ogl state sorting here ?\n begin\n display (the_Visual, the_Camera.clipper);\n GL.Errors.log;\n for Each in visual_Geometrys'Range loop\n declare\n use GL.Skins, GL.Geometry;\n the_Geometry : GL.skinned_geometry.skinned_Geometry renames visual_Geometrys (Each);\n begin\n if the_Geometry.Skin /= current_Skin then\n current_Skin := the_Geometry.Skin;\n enable (current_Skin.all);\n GL.Errors.log;\n end if;\n if the_Geometry.Veneer /= null then\n enable (the_Geometry.Veneer.all);\n GL.Errors.log;\n end if;\n GL.PushMatrix;\n GL.Translate (the_Visual.centre);\n Multiply_GL_Matrix (the_Visual.rotation);\n draw (the_Geometry.Geometry.all);\n GL.Errors.log;\n GL.PopMatrix;" + }, + { + "function_def": "procedure Dispose is new Ada.Unchecked_Deallocation (Texture_info_array, p_Texture_info_array);", + "function_body": "-----------------------------------\n -- 2) Fast access through a name --\n -----------------------------------\n\n package Texture_Name_Mapping is new Ada.Containers.Hashed_Maps\n (Key_Type => Ada.Strings.Unbounded.Unbounded_String,\n Element_Type => Image_ID,\n Hash => Ada.Strings.Unbounded.Hash,\n Equivalent_Keys => Ada.Strings.Unbounded.\"=\");\n\n type Texture_2d_infos_type is record\n tex : p_Texture_info_array;\n map : Texture_Name_Mapping.Map;\n last_entry_in_use : Image_ID;\n end record;\n\n empty_texture_2d_infos : constant Texture_2d_infos_type :=\n (null,\n Texture_Name_Mapping.Empty_Map,\n null_image\n);\n\n Texture_2d_Infos : Texture_2d_infos_type := empty_texture_2d_infos;\n\n -----------------------------\n -- Load_texture (internal) --\n -----------------------------\n\n procedure Load_texture_2D (id : Image_ID; blending_hint : out Boolean) is\n tex_name : constant String := Trim (Texture_2d_Infos.tex.all (id).name, Right);\n\n procedure Try (zif : in out Zip.Zip_info; name : String) is\n use UnZip.Streams;\n ftex : Zipped_File_Type;\n procedure Try_a_type (tex_name_ext : String; format : GL.IO.Supported_format) is\n begin\n Open (ftex, zif, tex_name_ext);\n GL.IO.Load (Stream (ftex), format, Image_ID'Pos (id) + 1, blending_hint);\n Close (ftex);\n exception\n when Zip.File_name_not_found =>\n raise;\n when e : others =>\n Raise_Exception (\n Exception_Identity (e),\n Exception_Message (e) & \" on texture : \" & tex_name_ext);\n end Try_a_type;\n begin -- Try\n Load_if_needed (zif, name);\n Try_a_type (tex_name & \".TGA\", GL.IO.TGA);\n exception\n when Zip.File_name_not_found =>\n Try_a_type (tex_name & \".BMP\", GL.IO.BMP);\n end Try;\n begin\n begin\n Try (zif_level, To_String (level_data_name));\n exception\n when Zip.File_name_not_found |\n Zip.Zip_file_open_Error =>\n -- Not found in level - specific pack\n Try (zif_global, To_String (global_data_name));" + }, + { + "function_def": "procedure deallocate is new ada.unchecked_Deallocation (Impostor'Class, p_Impostor);", + "function_body": "begin\n destroy (o.all);\n deallocate (o);" + }, + { + "function_def": "procedure Display (o : in out tri_Mesh;", + "function_body": "clip : in Clipping_data)\n is\n begin\n null;\n end Display;\n\n procedure set_Vertices (Self : in out tri_Mesh; To : access GL.geometry.GL_vertex_Array)\n is\n use GL.Buffer.vertex, GL.Geometry, GL.Geometry.vbo;\n\n the_Geometry : GL.geometry.vbo.vbo_Geometry renames GL.geometry.vbo.vbo_Geometry (self.skinned_geometry.Geometry.all);\n begin\n the_Geometry.Vertices := to_Buffer (To, usage => GL.static_draw); -- tbd : check usage\n the_Geometry.vertex_Count := GL.SizeI (To'Length);\n\n the_Geometry.Bounds := Bounds (To.all);" + }, + { + "function_def": "procedure Skin_is (o : in out tri_Mesh; Now : in GL.skins.p_Skin)", + "function_body": "is\n begin\n o.skinned_Geometry.Skin := Now;\n o.skinned_Geometry.Veneer := Now.all.new_Veneer (for_geometry => o.skinned_Geometry.Geometry.all);" + }, + { + "function_def": "procedure dummy is begin null; end;", + "function_body": "-- 'vertex_cache_optimise' is based on algorithm descibed here . .. http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html\n --\n procedure vertex_cache_optimise (Vertices : in out GL.geometry.GL_Vertex_array; Indices : in out GL.geometry.vertex_Id_array)\n is\n use GL, GL.Geometry;\n\n --subtype vertex_Id is Positive;\n subtype triangle_Id is positive_uInt;\n\n type triangle_Indices is array (Positive range <>) of triangle_Id;\n\n function Indices_Index (the_Face : in positive_uInt; the_Vertex : in positive_uInt) return positive_uInt\n is\n begin\n return 3 * (the_Face - 1) + the_Vertex;" + }, + { + "function_def": "procedure free is new ada.unchecked_deallocation (vco_vertex_Array, access_vco_vertex_Array);", + "function_body": "num_Faces : constant positive_uInt := indices'Length / 3;\n vco_Vertices : access_vco_vertex_Array := new vco_vertex_Array; -- can be very large, so create in the heap\n vco_Triangles : array (1 .. num_Faces) of vco_Triangle;\n\n type LRU_Cache is array (Natural range <>) of GL.geometry.vertex_Id;\n\n the_LRU_Cache : LRU_Cache (0 .. MaxSizeVertexCache - 1);\n LRU_Cache_last : Integer := - 1;\n\n procedure add_recent_Vertices_to_LRU_Cache (v1, v2, v3 : in GL.geometry.vertex_Id)\n is\n prior_Cache : LRU_Cache := the_LRU_Cache (0 .. LRU_Cache_last);\n begin\n the_LRU_Cache (0) := v1;\n the_LRU_Cache (1) := v2;\n the_LRU_Cache (2) := v3;\n\n LRU_Cache_last := 2;\n\n for Each in prior_Cache'Range loop\n\n if not (prior_Cache (Each) = v1\n or else prior_Cache (Each) = v2\n or else prior_Cache (Each) = v3)\n then\n LRU_Cache_last := LRU_Cache_last + 1;\n the_LRU_Cache (LRU_Cache_last) := prior_Cache (Each);\n end if;\n\n end loop;\n\n end add_recent_Vertices_to_LRU_Cache;\n\n function tri_Score_of (triangle_Id : in positive_uInt) return GL.Double\n is\n use GL;\n the_Triangle : vco_Triangle renames vco_Triangles (triangle_Id);\n\n Base : positive_uInt := positive_uInt (triangle_Id - 1) * 3;\n v1_Id : GL.geometry.vertex_Id renames Indices (base + 1);\n v2_Id : GL.geometry.vertex_Id renames Indices (base + 2);\n v3_Id : GL.geometry.vertex_Id renames Indices (base + 3);\n\n Score : GL.Double;\n begin\n Score := vco_Vertices (v1_Id).Score;\n Score := Score + vco_Vertices (v2_Id).Score;\n Score := Score + vco_Vertices (v3_Id).Score;\n\n return Score;\n end tri_Score_of;\n\n best_Triangle : triangle_Id;\n best_Triangle_score : GL.Double := GL.Double'First;\n\n new_face_Indices : GL.geometry.vertex_Id_array (Indices'Range); -- the resulting optimised triangle indices.\n -- new_face_Indices : triangle_vertex_Indices (o.Face_Indices'Range); -- the resulting optimised triangle indices.\n -- -- new_face_Indices_last : Natural := new_face_Indices'first - 1;\n begin\n --put_Line (\"start optimise !\");\n\n -- combined pass's : - increments the counter of the number of triangles that use each vertex\n -- - adds the triangle to the vertex's triangle list, for each vertex.\n --\n for Each in 1 .. num_Faces loop\n declare\n procedure add_face_Vertex (which_vertex : positive_uInt)\n is\n the_Vertex : vco_Vertex renames vco_Vertices (Indices ((Each - 1) * 3 + which_vertex));\n begin\n the_Vertex.tri_Count := the_Vertex.tri_Count + 1;\n the_Vertex.Triangles (the_Vertex.tri_Count) := triangle_Id (Each);\n\n the_Vertex.tri_Count_unadded := the_Vertex.tri_Count;\n exception\n when constraint_Error =>\n put_Line (\"vco_Triangles max exceeded . .. increase Max_triangles_per_vertex !!\");\n raise;" + }, + { + "function_def": "procedure deallocate is new ada.unchecked_Deallocation (Impostor'Class, p_Impostor);", + "function_body": "begin\n if o /= null then\n destroy (o.all);\n end if;\n\n deallocate (o);" + }, + { + "function_def": "procedure deallocate is new ada.unchecked_Deallocation (Impostor'Class, p_Impostor);", + "function_body": "begin\n if o /= null then\n destroy (o.all);\n end if;\n\n deallocate (o);" + }, + { + "function_def": "function target_camera_Distance (o : in Impostor'Class) return Real", + "function_body": "is\n begin\n return o.target_camera_Distance;" + }, + { + "function_def": "procedure Display (o : in out Impostor; clip : in Clipping_data)", + "function_body": "is\n begin\n null; -- actual display is done by the renderer (ie glut.Windows), which requests all skinned Geometry's\n -- and then applies 'gl state' sorting for performance, before drawing.\n end Display;\n\n procedure set_Alpha (o : in out Impostor; Alpha : in GL.Double)\n is\n begin\n null; -- tbd" + }, + { + "function_def": "procedure Display (o : in out Sprite;", + "function_body": "clip : in Clipping_data)\n is\n begin\n null; -- actual display is done by the renderer (ie glut.Windows), which requests all skinned Geometry's\n -- and then applies 'gl state' sorting for performance, before drawing.\n end Display;\n\n procedure set_Alpha (o : in out Sprite; Alpha : in GL.Double)\n is\n begin\n null; -- tbd" + }, + { + "function_def": "procedure Display (o : in out tri_Mesh;", + "function_body": "clip : in Clipping_data)\n is\n begin\n null;\n end Display;\n\n procedure set_Vertices (Self : in out tri_Mesh; To : access GL.geometry.GL_vertex_Array)\n is\n use GL.Geometry, GL.Geometry.primal;\n\n the_Geometry : GL.geometry.primal.primal_Geometry\n renames GL.geometry.primal.primal_Geometry (self.skinned_geometry.Geometry.all);\n begin\n the_Geometry.set_Vertices (to => To);" + }, + { + "function_def": "procedure Skin_is (o : in out tri_Mesh; Now : in GL.skins.p_Skin)", + "function_body": "is\n begin\n o.skinned_Geometry.Skin := Now;\n o.skinned_Geometry.Veneer := Now.all.new_Veneer (for_geometry => o.skinned_Geometry.Geometry.all);" + }, + { + "function_def": "function Intel_nb is new Intel_x86_number (Unsigned_16);", + "function_body": "function Intel_nb is new Intel_x86_number (Unsigned_32);\n\n -- Put numbers with correct endianess as bytes\n\n generic\n type Number is mod <>; -- range <> in Ada83 version (fake Interfaces)\n size : Positive;\n function Intel_x86_buffer (n : Number) return Byte_Buffer;\n\n function Intel_x86_buffer (n : Number) return Byte_Buffer is\n\n b : Byte_Buffer (1 .. size);\n m : Number := n;\n\n begin\n for i in b'Range loop\n b (i) := Unsigned_8 (m and 255);\n m := m / 256;\n end loop;\n return b;\n end Intel_x86_buffer;\n\n function Intel_bf is new Intel_x86_buffer (Unsigned_16, 2);\n function Intel_bf is new Intel_x86_buffer (Unsigned_32, 4);\n\n -------------------\n -- PK signatures --\n -------------------\n\n function PK_signature (buf : Byte_Buffer; code : Unsigned_8) return Boolean is\n (buf (1 .. 4) = (16#50#, 16#4B#, code, code + 1)); -- PK12, PK34, . ..\n\n procedure PK_signature (buf : in out Byte_Buffer; code : Unsigned_8) is\n\n begin\n buf (1 .. 4) := (16#50#, 16#4B#, code, code + 1); -- PK12, PK34, . ..\n end PK_signature;\n\n -------------------------------------------------------\n -- PKZIP file header, as in central directory - PK12 --\n -------------------------------------------------------\n\n procedure Read_and_check (stream : Zipstream_Class;\n header : out Central_File_Header) is\n\n chb : Byte_Buffer (1 .. 46);\n\n begin\n BlockRead (stream, chb);\n\n if not PK_signature (chb, 1) then\n raise bad_central_header;\n end if;\n\n header := (made_by_version => Intel_nb (chb (5 .. 6)),\n short_info =>\n (needed_extract_version => Intel_nb (chb (7 .. 8)),\n bit_flag => Intel_nb (chb (9 .. 10)),\n zip_type => Intel_nb (chb (11 .. 12)),\n file_timedate => Zip_Streams.Calendar.Convert (Unsigned_32'(Intel_nb (chb (13 .. 16)))),\n dd =>\n (crc_32 => Intel_nb (chb (17 .. 20)),\n compressed_size => Intel_nb (chb (21 .. 24)),\n uncompressed_size => Intel_nb (chb (25 .. 28))),\n filename_length => Intel_nb (chb (29 .. 30)),\n extra_field_length => Intel_nb (chb (31 .. 32))),\n comment_length => Intel_nb (chb (33 .. 34)),\n disk_number_start => Intel_nb (chb (35 .. 36)),\n internal_attributes => Intel_nb (chb (37 .. 38)),\n external_attributes => Intel_nb (chb (39 .. 42)),\n local_header_offset => Intel_nb (chb (43 .. 46)));\n\n end Read_and_check;\n\n procedure Write (stream : Zipstream_Class;\n header : Central_File_Header) is\n\n chb : Byte_Buffer (1 .. 46);\n\n begin\n PK_signature (chb, 1);\n\n chb (5 .. 6) := Intel_bf (header.made_by_version);\n chb (7 .. 8) := Intel_bf (header.short_info.needed_extract_version);\n chb (9 .. 10) := Intel_bf (header.short_info.bit_flag);\n chb (11 .. 12) := Intel_bf (header.short_info.zip_type);\n chb (13 .. 16) := Intel_bf (Zip_Streams.Calendar.Convert (header.short_info.file_timedate));\n chb (17 .. 20) := Intel_bf (header.short_info.dd.crc_32);\n chb (21 .. 24) := Intel_bf (header.short_info.dd.compressed_size);\n chb (25 .. 28) := Intel_bf (header.short_info.dd.uncompressed_size);\n chb (29 .. 30) := Intel_bf (header.short_info.filename_length);\n chb (31 .. 32) := Intel_bf (header.short_info.extra_field_length);\n chb (33 .. 34) := Intel_bf (header.comment_length);\n chb (35 .. 36) := Intel_bf (header.disk_number_start);\n chb (37 .. 38) := Intel_bf (header.internal_attributes);\n chb (39 .. 42) := Intel_bf (header.external_attributes);\n chb (43 .. 46) := Intel_bf (header.local_header_offset);\n\n BlockWrite (stream.all, chb);\n end Write;\n\n -----------------------------------------------------------------------\n -- PKZIP local file header, in front of every file in archive - PK34 --\n -----------------------------------------------------------------------\n\n procedure Read_and_check (stream : Zipstream_Class;\n header : out Local_File_Header) is\n\n lhb : Byte_Buffer (1 .. 30);\n\n begin\n BlockRead (stream, lhb);\n\n if not PK_signature (lhb, 3) then\n raise bad_local_header;\n end if;\n\n header :=\n (needed_extract_version => Intel_nb (lhb (5 .. 6)),\n bit_flag => Intel_nb (lhb (7 .. 8)),\n zip_type => Intel_nb (lhb (9 .. 10)),\n file_timedate => Zip_Streams.Calendar.Convert (Unsigned_32'(Intel_nb (lhb (11 .. 14)))),\n dd =>\n (crc_32 => Intel_nb (lhb (15 .. 18)),\n compressed_size => Intel_nb (lhb (19 .. 22)),\n uncompressed_size => Intel_nb (lhb (23 .. 26))),\n filename_length => Intel_nb (lhb (27 .. 28)),\n extra_field_length => Intel_nb (lhb (29 .. 30)));\n\n end Read_and_check;\n\n procedure Write (stream : Zipstream_Class;\n header : Local_File_Header) is\n\n lhb : Byte_Buffer (1 .. 30);\n\n begin\n PK_signature (lhb, 3);\n\n lhb (5 .. 6) := Intel_bf (header.needed_extract_version);\n lhb (7 .. 8) := Intel_bf (header.bit_flag);\n lhb (9 .. 10) := Intel_bf (header.zip_type);\n lhb (11 .. 14) := Intel_bf (Zip_Streams.Calendar.Convert (header.file_timedate));\n lhb (15 .. 18) := Intel_bf (header.dd.crc_32);\n lhb (19 .. 22) := Intel_bf (header.dd.compressed_size);\n lhb (23 .. 26) := Intel_bf (header.dd.uncompressed_size);\n lhb (27 .. 28) := Intel_bf (header.filename_length);\n lhb (29 .. 30) := Intel_bf (header.extra_field_length);\n\n BlockWrite (stream.all, lhb);\n end Write;\n\n -------------------------------------------\n -- PKZIP end - of - central - directory - PK56 --\n -------------------------------------------\n\n procedure Copy_and_check (buffer : Byte_Buffer;\n the_end : out End_of_Central_Dir) is\n\n begin\n if not PK_signature (buffer, 5) then\n raise bad_end;\n end if;\n\n the_end :=\n (disknum => Intel_nb (buffer (5 .. 6)),\n disknum_with_start => Intel_nb (buffer (7 .. 8)),\n disk_total_entries => Intel_nb (buffer (9 .. 10)),\n total_entries => Intel_nb (buffer (11 .. 12)),\n central_dir_size => Intel_nb (buffer (13 .. 16)),\n central_dir_offset => Intel_nb (buffer (17 .. 20)),\n main_comment_length => Intel_nb (buffer (21 .. 22)),\n offset_shifting => 0); -- Assuming single zip archive here\n\n end Copy_and_check;\n\n procedure Read_and_check (stream : Zipstream_Class;\n the_end : out End_of_Central_Dir) is\n\n eb : Byte_Buffer (1 .. 22);\n\n begin\n BlockRead (stream, eb);\n Copy_and_check (eb, the_end);\n end Read_and_check;\n\n -- Some explanations - GdM 2001\n\n -- The idea is that the .ZIP can be appended to an .EXE, for\n -- self - extracting purposes. So, the most general infos are\n -- at the end, and we crawl back for more precise infos:\n -- 1) end - of - central directory\n -- 2) central directory\n -- 3) zipped files\n\n procedure Load (stream : Zipstream_Class;\n the_end : out End_of_Central_Dir) is\n\n end_buffer : Byte_Buffer (1 .. 22);\n min_end_start : Ada.Streams.Stream_IO.Count;\n\n use Ada.Streams.Stream_IO;\n\n max_comment : constant := 65_535;\n\n begin\n -- 20 - Jun - 2001 : abandon search below min_end_start\n -- - read about max comment length in appnote\n\n if Size (stream) <= max_comment then\n min_end_start := 1;\n else\n min_end_start := Ada.Streams.Stream_IO.Count (Size (stream)) - max_comment;\n end if;\n\n -- Yes, we must _search_ for it .. .\n -- because PKWARE put a variable - size comment _after_ it 8 - (\n\n for i in reverse min_end_start .. Ada.Streams.Stream_IO.Count (Size (stream)) - 21 loop\n Zip_Streams.Set_Index (stream, Positive (i));\n begin\n for j in end_buffer'Range loop\n Byte'Read (stream, end_buffer (j));\n -- 20 - Jun - 2001 : useless to read more if 1st character is not 'P'\n if j = end_buffer'First and then\n end_buffer (j) /= Character'Pos ('P')\n then\n raise bad_end;\n end if;\n end loop;\n Copy_and_check (end_buffer, the_end);\n -- at this point, the buffer was successfully read\n -- (no exception raised).\n the_end.offset_shifting :=\n -- This is the real position of the end - of - central - directory block.\n Unsigned_32 (Zip_Streams.Index (stream) - 22)\n -\n -- This is the theoretical position of the end - of - central - directory,\n -- block. Should coincide with the real position if the zip file\n -- is not appended.\n (\n 1 +\n the_end.central_dir_offset +\n the_end.central_dir_size\n );\n return; -- the_end found and filled - > exit\n exception\n when bad_end =>\n if i > min_end_start then\n null; -- we will try 1 index before .. .\n else\n raise; -- definitely no \"end - of - central - directory\" here\n end if;" + }, + { + "function_def": "procedure Init_Buffers;", + "function_body": "package Decryption is\n procedure Set_mode (crypted : Boolean);\n function Get_mode return Boolean;\n procedure Init (passwrd : String; crc_check : Unsigned_32);\n procedure Decode (b : in out Unsigned_8);\n pragma Inline (Decode);\n end Decryption;\n\n procedure Read_raw_byte (bt : out Unsigned_8);\n pragma Inline (Read_raw_byte);\n\n package Bit_buffer is\n procedure Init;\n -- Read at least n bits into the bit buffer, returns the n first bits\n function Read (n : Natural) return Integer;\n pragma Inline (Read);\n function Read_U32 (n : Natural) return Unsigned_32;\n pragma Inline (Read_U32);\n -- Inverts (NOT operator) the result before masking by n bits\n function Read_inverted (n : Natural) return Integer;\n pragma Inline (Read_inverted);\n -- Dump n bits no longer needed from the bit buffer\n procedure Dump (n : Natural);\n pragma Inline (Dump);\n procedure Dump_to_byte_boundary;\n function Read_and_dump (n : Natural) return Integer;\n pragma Inline (Read_and_dump);\n function Read_and_dump_U32 (n : Natural) return Unsigned_32;\n pragma Inline (Read_and_dump_U32);\n end Bit_buffer;\n\n procedure Flush (x : Natural); -- directly from slide to output stream\n\n procedure Flush_if_full (W : in out Integer; unflushed : in out Boolean);\n pragma Inline (Flush_if_full);\n\n procedure Flush_if_full (W : in out Integer);\n pragma Inline (Flush_if_full);\n\n procedure Copy (distance, copy_length : Natural;\n index : in out Natural);\n pragma Inline (Copy);\n\n procedure Copy_or_zero (distance, copy_length : Natural;\n index : in out Natural;\n unflushed : in out Boolean);\n pragma Inline (Copy_or_zero);\n\n procedure Delete_output; -- an error has occured (bad compressed data)\n\n end UnZ_IO;\n\n package UnZ_Meth is\n procedure Copy_stored;\n procedure Unshrink;\n subtype Reduction_factor is Integer range 1 .. 4;\n procedure Unreduce (factor : Reduction_factor);\n procedure Explode (literal_tree, slide_8_KB : Boolean);\n deflate_e_mode : Boolean := False;\n procedure Inflate;\n procedure Bunzip2; -- Nov - 2009\n end UnZ_Meth;\n\n ------------------------------\n -- Bodies of UnZ_* packages --\n ------------------------------\n package body UnZ_IO is\n\n -- Centralize buffer initialisations - 29 - Jun - 2001\n\n procedure Init_Buffers is\n begin\n UnZ_Glob.inpos := 0; -- Input buffer position\n UnZ_Glob.readpos := -1; -- Nothing read\n UnZ_Glob.slide_index := 0;\n UnZ_Glob.reachedsize := 0;\n UnZ_Glob.effective_writes := 0;\n UnZ_Glob.Zip_EOF := False;\n Zip.CRC.Init (UnZ_Glob.crc32val);\n Bit_buffer.Init;\n end Init_Buffers;\n\n procedure Read_buffer is\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[Read_buffer .. .\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n if UnZ_Glob.reachedsize > UnZ_Glob.compsize + 2 then\n -- + 2 : last code is smaller than requested!\n UnZ_Glob.readpos := UnZ_Glob.inbuf'Length;\n -- Simulates reading - > no blocking\n UnZ_Glob.Zip_EOF := True;\n else\n begin\n Zip.BlockRead (\n stream => zip_file,\n buffer => UnZ_Glob.inbuf,\n actually_read => UnZ_Glob.readpos\n );\n exception\n when others => -- I/O error\n UnZ_Glob.readpos := UnZ_Glob.inbuf'Length;\n -- Simulates reading - > CRC error\n UnZ_Glob.Zip_EOF := True;" + }, + { + "function_def": "procedure Init is", + "function_body": "begin\n B := 0;\n K := 0;\n end Init;\n\n procedure Need (n : Natural) is\n pragma Inline (Need);\n bt : Zip.Byte;\n begin\n while K < n loop\n Read_raw_byte (bt);\n B := B or Shift_Left (Unsigned_32 (bt), K);\n K := K + 8;\n end loop;\n end Need;\n\n procedure Dump (n : Natural) is\n begin\n B := Shift_Right (B, n);\n K := K - n;\n end Dump;\n\n procedure Dump_to_byte_boundary is\n begin\n Dump (K mod 8);\n end Dump_to_byte_boundary;\n\n function Read_U32 (n : Natural) return Unsigned_32 is\n begin\n Need (n);\n return B and (Shift_Left (1, n) - 1);\n end Read_U32;\n\n function Read_inverted (n : Natural) return Integer is\n begin\n Need (n);\n return Integer ((not B) and (Shift_Left (1, n) - 1));\n end Read_inverted;\n\n function Read (n : Natural) return Integer is\n begin\n return Integer (Read_U32 (n));\n end Read;\n\n function Read_and_dump (n : Natural) return Integer is\n res : Integer;\n begin\n res := Read (n);\n Dump (n);\n return res;\n end Read_and_dump;\n\n function Read_and_dump_U32 (n : Natural) return Unsigned_32 is\n res : Unsigned_32;\n begin\n res := Read_U32 (n);\n Dump (n);\n return res;\n end Read_and_dump_U32;\n\n end Bit_buffer;\n\n procedure Flush (x : Natural) is\n use Zip, UnZip, Ada.Streams;\n user_aborting : Boolean;\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[Flush .. .\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n begin\n case mode is\n when write_to_binary_file =>\n BlockWrite (Ada.Streams.Stream_IO.Stream (out_bin_file).all, UnZ_Glob.slide (0 .. x - 1));\n when write_to_text_file =>\n Zip.Write_as_text (\n UnZ_IO.out_txt_file, UnZ_Glob.slide (0 .. x - 1), UnZ_IO.last_char\n );\n when write_to_memory =>\n for i in 0 .. x - 1 loop\n output_memory_access.all (UnZ_Glob.uncompressed_index) :=\n Ada.Streams.Stream_Element (UnZ_Glob.slide (i));\n UnZ_Glob.uncompressed_index := UnZ_Glob.uncompressed_index + 1;\n end loop;\n when just_test =>\n null;\n end case;\n exception\n when others =>\n raise UnZip.Write_Error;" + }, + { + "function_def": "procedure Delete_output is -- an error has occured (bad compressed data)", + "function_body": "begin\n if no_trace then -- if there is a trace, we are debugging\n case mode is -- and want to keep the malformed file\n when write_to_binary_file =>\n Ada.Streams.Stream_IO.Delete (UnZ_IO.out_bin_file);\n when write_to_text_file =>\n Ada.Text_IO.Delete (UnZ_IO.out_txt_file);\n when others =>\n null;\n end case;\n end if;\n end Delete_output;\n\n end UnZ_IO;\n\n package body UnZ_Meth is\n\n --------[ Method : Unshrink ] --------\n\n -- Original in Pascal written by Christian Ghisler.\n\n Max_Code : constant := 8192;\n Max_Stack : constant := 8192;\n Initial_Code_Size : constant := 9;\n Maximum_Code_Size : constant := 13;\n First_Entry : constant := 257;\n\n -- Rest of slide=write buffer =766 bytes\n\n Write_Max : constant := wsize - 3 * (Max_Code - 256) - Max_Stack - 2;\n\n Previous_Code : array (First_Entry .. Max_Code) of Integer;\n Actual_Code : array (First_Entry .. Max_Code) of Zip.Byte;\n\n Next_Free : Integer; -- Next free code in trie\n Write_Ptr : Integer; -- Pointer to output buffer\n\n Writebuf : Zip.Byte_Buffer (0 .. Write_Max); -- Write buffer\n\n procedure Unshrink_Flush is\n use Zip, UnZip, Ada.Streams, Ada.Streams.Stream_IO;\n user_aborting : Boolean;\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[Unshrink_Flush]\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n begin\n case mode is\n when write_to_binary_file =>\n BlockWrite (Stream (UnZ_IO.out_bin_file).all, Writebuf (0 .. Write_Ptr - 1));\n when write_to_text_file =>\n Zip.Write_as_text (UnZ_IO.out_txt_file, Writebuf (0 .. Write_Ptr - 1), UnZ_IO.last_char);\n when write_to_memory =>\n for I in 0 .. Write_Ptr - 1 loop\n output_memory_access.all (UnZ_Glob.uncompressed_index) :=\n Stream_Element (Writebuf (I));\n UnZ_Glob.uncompressed_index := UnZ_Glob.uncompressed_index + 1;\n end loop;\n when just_test =>\n null;\n end case;\n exception\n when others =>\n raise UnZip.Write_Error;" + }, + { + "function_def": "procedure Clear_Leaf_Nodes is", + "function_body": "Pc : Integer; -- previous code\n Act_Max_Code : Integer; -- max code to be searched for leaf nodes\n\n begin\n Act_Max_Code := Next_Free - 1;\n for I in First_Entry .. Act_Max_Code loop\n Previous_Code (I) :=\n Integer (Unsigned_32 (Previous_Code (I)) or 16#8000#);\n end loop;\n\n for I in First_Entry .. Act_Max_Code loop\n Pc := Previous_Code (I) mod 16#8000#;\n if Pc > 256 then\n Previous_Code (Pc) := Previous_Code (Pc) mod 16#8000#;\n end if;\n end loop;\n\n -- Build new free list\n Pc := -1;\n Next_Free := -1;\n for I in First_Entry .. Act_Max_Code loop\n -- Either free before or marked now\n if (Unsigned_32 (Previous_Code (I)) and 16#C000#) /= 0 then\n -- Link last item to this item\n if Pc = -1 then\n Next_Free := I;\n else\n Previous_Code (Pc) := -I;\n end if;\n Pc := I;\n end if;\n end loop;\n\n if Pc /= -1 then\n Previous_Code (Pc) := -Act_Max_Code - 1;\n end if;\n\n end Clear_Leaf_Nodes;\n\n procedure Unshrink is\n Incode : Integer; -- Code read in\n Last_Incode : Integer;\n Last_Outcode : Zip.Byte;\n Code_Size : Integer := Initial_Code_Size; -- Actual code size (9 .. 13)\n Stack : Zip.Byte_Buffer (0 .. Max_Stack); -- Stack for output\n Stack_Ptr : Integer := Max_Stack;\n New_Code : Integer; -- Save new normal code read\n\n Code_for_Special : constant := 256;\n Code_Increase_size : constant := 1;\n Code_Clear_table : constant := 2;\n\n S : UnZip.File_size_type := UnZ_Glob.uncompsize;\n -- Fix Jan - 2009 : replaces a remaining bits counter as Unsigned_*32* .. .\n\n procedure Read_Code is\n pragma Inline (Read_Code);\n begin\n Incode := UnZ_IO.Bit_buffer.Read_and_dump (Code_Size);\n end Read_Code;\n\n begin\n Previous_Code := (others => 0);\n Actual_Code := (others => 0);\n Stack := (others => 0);\n Writebuf := (others => 0);\n\n if UnZ_Glob.compsize = Unsigned_32'Last then\n -- Compressed Size was not in header!\n raise UnZip.Not_supported;\n elsif UnZ_Glob.uncompsize = 0 then\n return; -- compression of a 0 - file with Shrink.pas\n end if;\n\n -- initialize free codes list\n\n for I in Previous_Code'Range loop\n Previous_Code (I) := -(I + 1);\n end loop;\n\n Next_Free := First_Entry;\n Write_Ptr := 0;\n\n Read_Code;\n Last_Incode := Incode;\n Last_Outcode := Zip.Byte (Incode);\n Write_Byte (Last_Outcode);\n S := S - 1;\n\n while S > 0 and then not UnZ_Glob.Zip_EOF loop\n Read_Code;\n if Incode = Code_for_Special then\n Read_Code;\n case Incode is\n when Code_Increase_size =>\n Code_Size := Code_Size + 1;\n if some_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\n \"[LZW code size - >\" & Integer'Image (Code_Size) & ']'\n );\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n if Code_Size > Maximum_Code_Size then\n raise Zip.Zip_file_Error;\n end if;\n when Code_Clear_table =>\n Clear_Leaf_Nodes;\n when others =>\n raise Zip.Zip_file_Error;\n end case;\n\n else -- Normal code\n New_Code := Incode;\n if Incode < 256 then -- Simple char\n Last_Outcode := Zip.Byte (Incode);\n Write_Byte (Last_Outcode);\n S := S - 1;\n else\n if Previous_Code (Incode) < 0 then\n Stack (Stack_Ptr) := Last_Outcode;\n Stack_Ptr := Stack_Ptr - 1;\n Incode := Last_Incode;\n end if;\n while Incode > 256 loop\n -- Test added 11 - Dec - 2007 for situations\n -- happening on corrupt files:\n if Stack_Ptr < Stack'First or else\n Incode > Actual_Code'Last\n then\n raise Zip.Zip_file_Error;\n end if;\n Stack (Stack_Ptr) := Actual_Code (Incode);\n Stack_Ptr := Stack_Ptr - 1;\n Incode := Previous_Code (Incode);\n end loop;\n\n Last_Outcode := Zip.Byte (Incode mod 256);\n Write_Byte (Last_Outcode);\n\n for I in Stack_Ptr + 1 .. Max_Stack loop\n Write_Byte (Stack (I));\n end loop;\n S := S - UnZip.File_size_type (Max_Stack - Stack_Ptr + 1);\n\n Stack_Ptr := Max_Stack;\n end if;\n Incode := Next_Free;\n if Incode <= Max_Code then\n Next_Free := -Previous_Code (Incode);\n -- Next node in free list\n Previous_Code (Incode) := Last_Incode;\n Actual_Code (Incode) := Last_Outcode;\n end if;\n Last_Incode := New_Code;\n end if;\n end loop;\n if some_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[ Unshrink main loop finished ]\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n Unshrink_Flush;\n end Unshrink;\n\n --------[ Method : Unreduce ] --------\n\n procedure Unreduce (factor : Reduction_factor) is\n\n -- Original slide limit : 16#4000#\n DLE_code : constant := 144;\n subtype Symbol_range is Integer range 0 .. 255;\n subtype Follower_range is Integer range 0 .. 63; -- Appnote : <= 32 !\n Followers : array (Symbol_range, Follower_range) of Symbol_range :=\n (others => (others => 0));\n Slen : array (Symbol_range) of Follower_range;\n\n -- Bits taken by (x - 1) mod 256:\n B_Table : constant array (Symbol_range) of Integer :=\n (0 => 8,\n 1 .. 2 => 1,\n 3 .. 4 => 2,\n 5 .. 8 => 3,\n 9 .. 16 => 4,\n 17 .. 32 => 5,\n 33 .. 64 => 6,\n 65 .. 128 => 7,\n 129 .. 255 => 8);\n\n procedure LoadFollowers is\n list_followers : constant Boolean := some_trace;\n procedure Show_symbol (S : Symbol_range) is\n begin\n if S in 32 .. 254 then\n Ada.Text_IO.Put (Character'Val (S));\n else\n Ada.Text_IO.Put ('{' & Symbol_range'Image (S) & '}');\n end if;\n end Show_symbol;\n begin\n for X in reverse Symbol_range loop\n Slen (X) := UnZ_IO.Bit_buffer.Read_and_dump (6);\n if list_followers then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Show_symbol (X);\n Ada.Text_IO.Put (\" - > (\" & Integer'Image (Slen (X)) & \") \");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n for I in 0 .. Slen (X) - 1 loop\n Followers (X, I) := UnZ_IO.Bit_buffer.Read_and_dump (8);\n if list_followers then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Show_symbol (Followers (X, I));\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end loop;\n if list_followers then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.New_Line;\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end loop;\n end LoadFollowers;\n\n unreduce_length,\n char_read,\n last_char : Integer := 0;\n -- ^ some := 0 are useless, just to calm down ObjectAda 7.2.2\n S : UnZip.File_size_type := UnZ_Glob.uncompsize;\n -- number of bytes left to decompress\n unflushed : Boolean := True;\n maximum_AND_mask : constant Unsigned_32 := Shift_Left (1, 8 - factor) - 1;\n\n procedure Out_byte (b : Zip.Byte) is\n begin\n S := S - 1;\n UnZ_Glob.slide (UnZ_Glob.slide_index) := b;\n UnZ_Glob.slide_index := UnZ_Glob.slide_index + 1;\n UnZ_IO.Flush_if_full (UnZ_Glob.slide_index, unflushed);\n end Out_byte;\n\n V : Unsigned_32 := 0;\n type State_type is (normal, length_a, length_b, distance);\n state : State_type := normal;\n\n begin\n LoadFollowers;\n\n while S > 0 and then not UnZ_Glob.Zip_EOF loop\n\n -- 1/ Probabilistic expansion\n if Slen (last_char) = 0 then\n -- follower set is empty for this character\n char_read := UnZ_IO.Bit_buffer.Read_and_dump (8);\n elsif UnZ_IO.Bit_buffer.Read_and_dump (1) = 0 then\n char_read := Followers (\n last_char,\n UnZ_IO.Bit_buffer.Read_and_dump (B_Table (Slen (last_char)))\n );\n else\n char_read := UnZ_IO.Bit_buffer.Read_and_dump (8);\n end if;\n\n -- 2/ Expand the resulting Zip.Byte into repeated sequences\n case state is\n\n when normal =>\n if char_read = DLE_code then\n -- >> Next will be a DLE\n state := length_a;\n else\n -- >> A single char\n Out_byte (Zip.Byte (char_read));\n end if;\n\n when length_a =>\n if char_read = 0 then\n -- >> DLE_code & 0 - > was just the Zip.Byte coded DLE_code\n Out_byte (DLE_code);\n state := normal;\n else\n V := Unsigned_32 (char_read);\n unreduce_length := Integer (V and maximum_AND_mask);\n -- The remaining bits of V will be used for the distance\n if unreduce_length = Integer (maximum_AND_mask) then\n state := length_b;\n -- >> length must be completed before reading distance\n else\n state := distance;\n end if;\n end if;\n\n when length_b =>\n unreduce_length := unreduce_length + char_read;\n state := distance;\n\n when distance =>\n unreduce_length := unreduce_length + 3;\n S := S - UnZip.File_size_type (unreduce_length);\n\n UnZ_IO.Copy_or_zero (\n distance => char_read + 1 + Integer (Shift_Right (V, 8 - factor) * 2**8),\n copy_length => unreduce_length,\n index => UnZ_Glob.slide_index,\n unflushed => unflushed\n );\n state := normal;\n\n end case;\n\n last_char := char_read; -- store character for next iteration\n end loop;\n\n UnZ_IO.Flush (UnZ_Glob.slide_index);\n end Unreduce;\n\n --------[ Method : Explode ] --------\n\n -- C code by info - zip group, translated to Pascal by Christian Ghisler\n -- based on unz51g.zip\n\n use UnZip.Decompress.Huffman;\n\n procedure Get_Tree (L : out Length_array) is\n I, K, J, B : Unsigned_32;\n N : constant Unsigned_32 := L'Length;\n L_Idx : Integer := L'First;\n Bytebuf : Zip.Byte;\n\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin UnZ_Expl.Get_tree\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n UnZ_IO.Read_raw_byte (Bytebuf);\n I := Unsigned_32 (Bytebuf) + 1;\n K := 0;\n\n loop\n UnZ_IO.Read_raw_byte (Bytebuf);\n J := Unsigned_32 (Bytebuf);\n B := (J and 16#0F#) + 1;\n J := (J and 16#F0#) / 16 + 1;\n if K + J > N then\n raise Zip.Zip_file_Error;\n end if;\n\n loop\n L (L_Idx) := Natural (B);\n L_Idx := L_Idx + 1;\n K := K + 1;\n J := J - 1;\n exit when J = 0;\n end loop;\n\n I := I - 1;\n exit when I = 0;\n end loop;\n\n if K /= N then\n raise Zip.Zip_file_Error;\n end if;\n\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"End UnZ_Expl.Get_tree\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end Get_Tree;\n\n procedure Explode_Lit ( -- method with 3 trees\n Needed : Integer;\n Tb, Tl, Td : p_Table_list;\n Bb, Bl, Bd : Integer\n )\n is\n S : Unsigned_32;\n E, N, D : Integer;\n\n W : Integer := 0;\n Ct : p_HufT_table; -- current table\n Ci : Natural; -- current index\n unflushed : Boolean := True; -- true while slide not yet unflushed\n\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin Explode_lit\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n UnZ_IO.Bit_buffer.Init;\n\n S := UnZ_Glob.uncompsize;\n while S > 0 and then not UnZ_Glob.Zip_EOF loop\n if UnZ_IO.Bit_buffer.Read_and_dump (1) /= 0 then -- 1 : Litteral\n S := S - 1;\n Ct := Tb.all.table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (Bb);\n\n loop\n E := Ct.all (Ci).extra_bits;\n exit when E <= 16;\n\n if E = invalid then\n raise Zip.Zip_file_Error;\n end if;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n E := E - 16;\n Ct := Ct.all (Ci).next_table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (E);\n end loop;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n UnZ_Glob.slide (W) := Zip.Byte (Ct.all (Ci).n);\n W := W + 1;\n UnZ_IO.Flush_if_full (W, unflushed);\n\n else -- 0 : Copy\n D := UnZ_IO.Bit_buffer.Read_and_dump (Needed);\n Ct := Td.all.table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (Bd);\n\n loop\n E := Ct.all (Ci).extra_bits;\n exit when E <= 16;\n\n if E = invalid then\n raise Zip.Zip_file_Error;\n end if;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n E := E - 16;\n Ct := Ct.all (Ci).next_table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (E);\n end loop;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n D := D + Ct.all (Ci).n;\n\n Ct := Tl.all.table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (Bl);\n\n loop\n E := Ct.all (Ci).extra_bits;\n exit when E <= 16;\n\n if E = invalid then\n raise Zip.Zip_file_Error;\n end if;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n E := E - 16;\n Ct := Ct.all (Ci).next_table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (E);\n end loop;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n\n N := Ct.all (Ci).n;\n if E /= 0 then\n N := N + UnZ_IO.Bit_buffer.Read_and_dump (8);\n end if;\n S := S - Unsigned_32 (N);\n\n UnZ_IO.Copy_or_zero (\n distance => D,\n copy_length => N,\n index => W,\n unflushed => unflushed\n );\n\n end if;\n end loop;\n\n UnZ_IO.Flush (W);\n if UnZ_Glob.Zip_EOF then\n raise UnZip.Read_Error;\n end if;\n\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"End Explode_lit\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end Explode_Lit;\n\n procedure Explode_Nolit ( -- method with 2 trees\n Needed : Integer;\n Tl, Td : p_Table_list;\n Bl, Bd : Integer\n )\n is\n S : Unsigned_32;\n E, N, D : Integer;\n W : Integer := 0;\n Ct : p_HufT_table; -- current table\n Ci : Natural; -- current index\n unflushed : Boolean := True; -- true while slide not yet unflushed\n\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin Explode_nolit\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n UnZ_IO.Bit_buffer.Init;\n S := UnZ_Glob.uncompsize;\n while S > 0 and then not UnZ_Glob.Zip_EOF loop\n if UnZ_IO.Bit_buffer.Read_and_dump (1) /= 0 then -- 1 : Litteral\n S := S - 1;\n UnZ_Glob.slide (W) :=\n Zip.Byte (UnZ_IO.Bit_buffer.Read_and_dump (8));\n W := W + 1;\n UnZ_IO.Flush_if_full (W, unflushed);\n else -- 0 : Copy\n D := UnZ_IO.Bit_buffer.Read_and_dump (Needed);\n Ct := Td.all.table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (Bd);\n\n loop\n E := Ct.all (Ci).extra_bits;\n exit when E <= 16;\n\n if E = invalid then\n raise Zip.Zip_file_Error;\n end if;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n E := E - 16;\n Ct := Ct.all (Ci).next_table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (E);\n end loop;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n\n D := D + Ct.all (Ci).n;\n Ct := Tl.all.table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (Bl);\n\n loop\n E := Ct.all (Ci).extra_bits;\n exit when E <= 16;\n\n if E = invalid then\n raise Zip.Zip_file_Error;\n end if;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n E := E - 16;\n Ct := Ct.all (Ci).next_table;\n Ci := UnZ_IO.Bit_buffer.Read_inverted (E);\n end loop;\n\n UnZ_IO.Bit_buffer.Dump (Ct.all (Ci).bits);\n\n N := Ct.all (Ci).n;\n if E /= 0 then\n N := N + UnZ_IO.Bit_buffer.Read_and_dump (8);\n end if;\n S := S - Unsigned_32 (N);\n\n UnZ_IO.Copy_or_zero (\n distance => D,\n copy_length => N,\n index => W,\n unflushed => unflushed\n );\n\n end if;\n end loop;\n\n UnZ_IO.Flush (W);\n if UnZ_Glob.Zip_EOF then\n raise UnZip.Read_Error;\n end if;\n\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"End Explode_nolit\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n end Explode_Nolit;\n\n procedure Explode (literal_tree, slide_8_KB : Boolean) is\n\n Tb, Tl, Td : p_Table_list;\n Bb, Bl, Bd : Integer;\n L : Length_array (0 .. 255);\n huft_incomplete : Boolean;\n\n cp_length_2_trees :\n constant Length_array (0 .. 63) :=\n (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,\n 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65);\n\n cp_length_3_trees :\n constant Length_array (0 .. 63) :=\n (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,\n 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,\n 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66);\n\n cp_dist_4KB :\n constant Length_array (0 .. 63) :=\n (1, 65, 129, 193, 257, 321, 385, 449, 513, 577, 641, 705,\n 769, 833, 897, 961, 1025, 1089, 1153, 1217, 1281, 1345, 1409, 1473,\n 1537, 1601, 1665, 1729, 1793, 1857, 1921, 1985, 2049, 2113, 2177,\n 2241, 2305, 2369, 2433, 2497, 2561, 2625, 2689, 2753, 2817, 2881,\n 2945, 3009, 3073, 3137, 3201, 3265, 3329, 3393, 3457, 3521, 3585,\n 3649, 3713, 3777, 3841, 3905, 3969, 4033);\n\n cp_dist_8KB :\n constant Length_array (0 .. 63) :=\n (1, 129, 257, 385, 513, 641, 769, 897, 1025, 1153, 1281,\n 1409, 1537, 1665, 1793, 1921, 2049, 2177, 2305, 2433, 2561, 2689,\n 2817, 2945, 3073, 3201, 3329, 3457, 3585, 3713, 3841, 3969, 4097,\n 4225, 4353, 4481, 4609, 4737, 4865, 4993, 5121, 5249, 5377, 5505,\n 5633, 5761, 5889, 6017, 6145, 6273, 6401, 6529, 6657, 6785, 6913,\n 7041, 7169, 7297, 7425, 7553, 7681, 7809, 7937, 8065);\n\n extra :\n constant Length_array (0 .. 63) := (0 .. 62 => 0, 63 => 8);\n\n begin\n Bl := 7;\n if UnZ_Glob.compsize > 200000 then\n Bd := 8;\n else\n Bd := 7;\n end if;\n\n if literal_tree then\n Bb := 9;\n Get_Tree (L);\n begin\n HufT_build (L, 256, empty, empty, Tb, Bb, huft_incomplete);\n if huft_incomplete then\n HufT_free (Tb);\n raise Zip.Zip_file_Error;\n end if;\n exception\n when others =>\n raise Zip.Zip_file_Error;" + }, + { + "function_def": "procedure Copy_stored is", + "function_body": "size : constant UnZip.File_size_type := UnZ_Glob.compsize;\n read_in, absorbed : UnZip.File_size_type;\n begin\n absorbed := 0;\n if UnZ_IO.Decryption.Get_mode then\n absorbed := 12;\n end if;\n while absorbed < size loop\n read_in := size - absorbed;\n if read_in > wsize then\n read_in := wsize;\n end if;\n begin\n for I in 0 .. read_in - 1 loop\n UnZ_IO.Read_raw_byte (UnZ_Glob.slide (Natural (I)));\n end loop;\n exception\n when others =>\n raise UnZip.Read_Error;" + }, + { + "function_def": "procedure Inflate_stored_block is -- Actually, nothing to inflate", + "function_body": "N : Integer;\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin Inflate_stored_block\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n UnZ_IO.Bit_buffer.Dump_to_byte_boundary;\n\n -- Get the block length and its complement\n N := UnZ_IO.Bit_buffer.Read_and_dump (16);\n if N /= Integer (\n (not UnZ_IO.Bit_buffer.Read_and_dump_U32 (16))\n and 16#ffff#)\n then\n raise Zip.Zip_file_Error;\n end if;\n while N > 0 and then not UnZ_Glob.Zip_EOF loop\n -- Read and output the non - compressed data\n N := N - 1;\n UnZ_Glob.slide (UnZ_Glob.slide_index) :=\n Zip.Byte (UnZ_IO.Bit_buffer.Read_and_dump (8));\n UnZ_Glob.slide_index := UnZ_Glob.slide_index + 1;\n UnZ_IO.Flush_if_full (UnZ_Glob.slide_index);\n end loop;\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"End Inflate_stored_block\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end Inflate_stored_block;\n\n -- Copy lengths for literal codes 257 .. 285\n\n copy_lengths_literal : Length_array (0 .. 30) :=\n (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,\n 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);\n\n -- Extra bits for literal codes 257 .. 285\n\n extra_bits_literal : Length_array (0 .. 30) :=\n (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\n 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid, invalid);\n\n -- Copy offsets for distance codes 0 .. 29 (30 .. 31 : deflate_e)\n\n copy_offset_distance : constant Length_array (0 .. 31) :=\n (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\n 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\n 8193, 12289, 16385, 24577, 32769, 49153);\n\n -- Extra bits for distance codes\n\n extra_bits_distance : constant Length_array (0 .. 31) :=\n (0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,\n 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14);\n\n max_dist : Integer := 29; -- changed to 31 for deflate_e\n\n procedure Inflate_fixed_block is\n Tl, -- literal/length code table\n Td : p_Table_list; -- distance code table\n Bl, Bd : Integer; -- lookup bits for tl/bd\n huft_incomplete : Boolean;\n\n -- length list for HufT_build (literal table)\n L : constant Length_array (0 .. 287) :=\n (0 .. 143 => 8, 144 .. 255 => 9, 256 .. 279 => 7, 280 .. 287 => 8);\n\n begin\n if some_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin Inflate_fixed_block\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n -- make a complete, but wrong code set\n Bl := 7;\n HufT_build (\n L, 257, copy_lengths_literal, extra_bits_literal,\n Tl, Bl, huft_incomplete\n );\n\n -- Make an incomplete code set\n Bd := 5;\n begin\n HufT_build (\n (0 .. max_dist => 5), 0,\n copy_offset_distance, extra_bits_distance,\n Td, Bd, huft_incomplete\n );\n if huft_incomplete then\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\n \"td is incomplete, pointer=null : \" &\n Boolean'Image (Td = null)\n );\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end if;\n exception\n when huft_out_of_memory | huft_error =>\n HufT_free (Tl);\n raise Zip.Zip_file_Error;" + }, + { + "function_def": "procedure Inflate_dynamic_block is", + "function_body": "bit_order : constant array (0 .. 18) of Natural :=\n (16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);\n\n Lbits : constant := 9;\n Dbits : constant := 6;\n\n current_length : Natural;\n defined, number_of_lengths : Natural;\n\n Tl, -- literal/length code tables\n Td : p_Table_list; -- distance code tables\n\n CTE : p_HufT; -- current table element\n\n Bl, Bd : Integer; -- lookup bits for tl/bd\n Nb : Natural; -- number of bit length codes\n Nl : Natural; -- number of literal length codes\n Nd : Natural; -- number of distance codes\n\n -- literal/length and distance code lengths\n Ll : Length_array (0 .. 288 + 32 - 1) := (others => 0);\n\n huft_incomplete : Boolean;\n\n procedure Repeat_length_code (amount : Natural) is\n begin\n if defined + amount > number_of_lengths then\n raise Zip.Zip_file_Error;\n end if;\n for c in reverse 1 .. amount loop\n Ll (defined) := current_length;\n defined := defined + 1;\n end loop;\n end Repeat_length_code;\n\n begin\n if some_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (\"Begin Inflate_dynamic_block\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n\n -- Read in table lengths\n Nl := 257 + UnZ_IO.Bit_buffer.Read_and_dump (5);\n Nd := 1 + UnZ_IO.Bit_buffer.Read_and_dump (5);\n Nb := 4 + UnZ_IO.Bit_buffer.Read_and_dump (4);\n\n if Nl > 288 or else Nd > 32 then\n raise Zip.Zip_file_Error;\n end if;\n\n -- Read in bit - length - code lengths.\n -- The rest, Ll (Bit_Order (Nb .. 18)), is already = 0\n for J in 0 .. Nb - 1 loop\n Ll (bit_order (J)) := UnZ_IO.Bit_buffer.Read_and_dump (3);\n end loop;\n\n -- Build decoding table for trees --single level, 7 bit lookup\n Bl := 7;\n begin\n HufT_build (\n Ll (0 .. 18), 19, empty, empty, Tl, Bl, huft_incomplete\n );\n if huft_incomplete then\n HufT_free (Tl);\n raise Zip.Zip_file_Error;\n end if;\n exception\n when others =>\n raise Zip.Zip_file_Error;" + }, + { + "function_def": "procedure Inflate is", + "function_body": "is_last_block : Boolean;\n blocks : Positive := 1;\n begin\n if deflate_e_mode then\n copy_lengths_literal (28) := 3; -- instead of 258\n extra_bits_literal (28) := 16; -- instead of 0\n max_dist := 31;\n end if;\n loop\n Inflate_Block (is_last_block);\n exit when is_last_block;\n blocks := blocks + 1;\n end loop;\n UnZ_IO.Flush (UnZ_Glob.slide_index);\n UnZ_Glob.slide_index := 0;\n if some_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"# blocks:\" & Integer'Image (blocks));\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end Inflate;\n\n --------[ Method : BZip2 ] --------\n\n procedure Bunzip2 is\n type BZ_Buffer is array (Natural range <>) of Interfaces.Unsigned_8;\n procedure Read (b : out BZ_Buffer) is\n begin\n for i in b'Range loop\n exit when UnZ_Glob.Zip_EOF;\n UnZ_IO.Read_raw_byte (b (i));\n end loop;\n end Read;\n procedure Write (b : BZ_Buffer) is\n begin\n for i in b'Range loop\n UnZ_Glob.slide (UnZ_Glob.slide_index) := b (i);\n UnZ_Glob.slide_index := UnZ_Glob.slide_index + 1;\n UnZ_IO.Flush_if_full (UnZ_Glob.slide_index);\n end loop;\n end Write;\n package My_BZip2 is new BZip2\n (Buffer => BZ_Buffer,\n check_CRC => False, -- Already done by UnZ_IO\n Read => Read,\n Write => Write\n );\n begin\n My_BZip2.Decompress;\n UnZ_IO.Flush (UnZ_Glob.slide_index);\n end Bunzip2;\n\n end UnZ_Meth;\n\n procedure Process (descriptor : out Zip.Headers.Data_descriptor)\n is\n start : Integer;\n b : Unsigned_8;\n dd_buffer : Zip.Byte_Buffer (1 .. 30);\n begin\n UnZ_IO.Bit_buffer.Dump_to_byte_boundary;\n UnZ_IO.Read_raw_byte (b);\n if b = 75 then -- 'K' ('P' is before, Java/JAR bug!)\n dd_buffer (1) := 80;\n dd_buffer (2) := 75;\n start := 3;\n else\n dd_buffer (1) := b; -- hopefully = 80\n start := 2;\n end if;\n for i in start .. 16 loop\n UnZ_IO.Read_raw_byte (dd_buffer (i));\n end loop;\n Zip.Headers.Copy_and_check (dd_buffer, descriptor);\n end Process;\n\n tolerance_wrong_password : constant := 4; -- after that, error !\n work_index : Ada.Streams.Stream_IO.Positive_Count;\n use Zip, UnZ_Meth;\n\n begin -- Decompress_Data\n output_memory_access := null;\n -- ^ this is an 'out' parameter, we have to set it anyway\n case mode is\n when write_to_binary_file =>\n Ada.Streams.Stream_IO.Create (UnZ_IO.out_bin_file, Ada.Streams.Stream_IO.Out_File, output_file_name,\n Form => To_String (Zip.Form_For_IO_Open_N_Create));\n when write_to_text_file =>\n Ada.Text_IO.Create (UnZ_IO.out_txt_file, Ada.Text_IO.Out_File, output_file_name,\n Form => To_String (Zip.Form_For_IO_Open_N_Create));\n when write_to_memory =>\n output_memory_access := new\n Ada.Streams.Stream_Element_Array (\n 1 .. Ada.Streams.Stream_Element_Offset (hint.uncompressed_size)\n );\n UnZ_Glob.uncompressed_index := output_memory_access'First;\n when just_test =>\n null;\n end case;\n\n UnZ_Glob.compsize := hint.compressed_size;\n -- 2008 : from TT's version:\n -- Avoid wraparound in read_buffer, when File_size_type'Last is given\n -- as hint.compressed_size (unknown size)\n if UnZ_Glob.compsize > File_size_type'Last - 2 then\n UnZ_Glob.compsize := File_size_type'Last - 2;\n end if;\n UnZ_Glob.uncompsize := hint.uncompressed_size;\n UnZ_IO.Init_Buffers;\n UnZ_IO.Decryption.Set_mode (encrypted);\n if encrypted then\n work_index := Ada.Streams.Stream_IO.Positive_Count (Zip_Streams.Index (zip_file));\n password_passes : for p in 1 .. tolerance_wrong_password loop\n begin\n UnZ_IO.Decryption.Init (To_String (password), hint.crc_32);\n exit password_passes; -- the current password fits, then go on!\n exception\n when Wrong_password =>\n if p = tolerance_wrong_password then\n raise;\n end if; -- alarm!\n if get_new_password /= null then\n get_new_password (password); -- ask for a new one\n end if;" + }, + { + "function_def": "procedure Decompress is", + "function_body": "max_groups : constant := 6;\n max_alpha_size : constant := 258;\n max_code_len : constant := 23;\n group_size : constant := 50;\n max_selectors : constant := 2 + (900_000 / group_size);\n\n sub_block_size : constant := 100_000;\n\n type Length_array is array (Integer range <>) of Natural;\n\n block_randomized : Boolean := False;\n block_size : Natural;\n\n use Interfaces;\n\n type Tcardinal_array is array (Integer range <>) of Unsigned_32;\n type Pcardinal_array is access Tcardinal_array;\n procedure Dispose is new Ada.Unchecked_Deallocation (Tcardinal_array, Pcardinal_array);\n tt : Pcardinal_array;\n tt_count : Natural;\n\n rle_run_left : Natural := 0;\n rle_run_data : Unsigned_8 := 0;\n decode_available : Natural := Natural'Last;\n block_origin : Natural := 0;\n read_data : Unsigned_8 := 0;\n bits_available : Natural := 0;\n inuse_count : Natural;\n seq_to_unseq : array (0 .. 255) of Natural;\n global_alpha_size : Natural;\n group_count : Natural;\n --\n selector_count : Natural;\n selector, selector_mtf : array (0 .. max_selectors) of Unsigned_8;\n --\n type Alpha_U32_array is array (0 .. max_alpha_size) of Unsigned_32;\n type Alpha_Nat_array is array (0 .. max_alpha_size) of Natural;\n\n len : array (0 .. max_groups) of Alpha_Nat_array;\n global_limit,\n global_base,\n global_perm : array (0 .. max_groups) of Alpha_U32_array;\n --\n minlens : Length_array (0 .. max_groups);\n cftab : array (0 .. 257) of Natural;\n --\n end_reached : Boolean := False;\n\n in_buf : Buffer (1 .. input_buffer_size);\n in_idx : Natural := in_buf'Last + 1;\n\n function Read_byte return Unsigned_8 is\n res : Unsigned_8;\n begin\n if in_idx > in_buf'Last then\n Read (in_buf);\n in_idx := in_buf'First;\n end if;\n res := in_buf (in_idx);\n in_idx := in_idx + 1;\n return res;\n end Read_byte;\n\n procedure hb_create_decode_tables (limit, base, perm : in out Alpha_U32_array;\n length : Alpha_Nat_array;\n min_len, max_len : Natural;\n alpha_size : Integer) is\n\n pp, idx : Integer;\n vec : Unsigned_32;\n\n begin\n pp := 0;\n for i in min_len .. max_len loop\n for j in 0 .. alpha_size - 1 loop\n if length (j) = i then\n perm (pp) := Unsigned_32 (j);\n pp := pp + 1;\n end if;\n end loop;\n end loop;\n for i in 0 .. max_code_len - 1 loop\n base (i) := 0;\n limit (i) := 0;\n end loop;\n for i in 0 .. alpha_size - 1 loop\n idx := length (i) + 1;\n base (idx) := base (idx) + 1;\n end loop;\n for i in 1 .. max_code_len - 1 loop\n base (i) := base (i) + base (i - 1);\n end loop;\n vec := 0;\n for i in min_len .. max_len loop\n vec := vec + base (i + 1) - base (i);\n limit (i) := vec - 1;\n vec := vec * 2;\n end loop;\n for i in min_len + 1 .. max_len loop\n base (i) := (limit (i - 1) + 1) * 2 - base (i);\n end loop;\n end hb_create_decode_tables;\n\n procedure Init is\n magic : String (1 .. 3);\n b : Unsigned_8;\n begin\n -- Read the magic.\n for i in magic'Range loop\n b := Read_byte;\n magic (i) := Character'Val (b);\n end loop;\n if magic /= \"BZh\" then\n raise bad_header_magic;\n end if;\n -- Read the block size and allocate the working array.\n b := Read_byte;\n block_size := Natural (b) - Character'Pos ('0');\n tt := new Tcardinal_array (0 .. block_size * sub_block_size);\n end Init;\n\n function get_bits (n : Natural) return Unsigned_8 is\n Result_get_bits : Unsigned_8;\n data : Unsigned_8;\n begin\n if n > bits_available then\n data := Read_byte;\n Result_get_bits := Shift_Right (read_data, 8 - n) or Shift_Right (data, 8 - (n - bits_available));\n read_data := Shift_Left (data, n - bits_available);\n bits_available := bits_available + 8;\n else\n Result_get_bits := Shift_Right (read_data, 8 - n);\n read_data := Shift_Left (read_data, n);\n end if;\n bits_available := bits_available - n;\n return Result_get_bits;\n end get_bits;\n\n function get_bits_32 (n : Natural) return Unsigned_32 is\n begin\n return Unsigned_32 (get_bits (n));\n end get_bits_32;\n\n function get_boolean return Boolean is\n begin\n return Boolean'Val (get_bits (1));\n end get_boolean;\n\n function get_byte return Unsigned_8 is\n begin\n return get_bits (8);\n end get_byte;\n\n function get_cardinal24 return Unsigned_32 is\n begin\n return Shift_Left (get_bits_32 (8), 16) or Shift_Left (get_bits_32 (8), 8) or get_bits_32 (8);\n end get_cardinal24;\n\n function get_cardinal return Unsigned_32 is\n begin\n return Shift_Left (get_bits_32 (8), 24) or\n Shift_Left (get_bits_32 (8), 16) or\n Shift_Left (get_bits_32 (8), 8) or\n get_bits_32 (8);\n end get_cardinal;\n\n -- Receive the mapping table. To save space, the inuse set is stored in pieces\n -- of 16 bits. First 16 bits are stored which pieces of 16 bits are used, then\n -- the pieces follow.\n procedure receive_mapping_table is\n inuse16 : array (0 .. 15) of Boolean;\n --* inuse : array (0 .. 255) of Boolean; -- for dump purposes\n begin\n inuse16 := (others => False);\n -- Receive the first 16 bits which tell which pieces are stored.\n for i in 0 .. 15 loop\n inuse16 (i) := get_boolean;\n end loop;\n -- Receive the used pieces.\n --* inuse := (others => False);\n inuse_count := 0;\n for i in 0 .. 15 loop\n if inuse16 (i) then\n for j in 0 .. 15 loop\n if get_boolean then\n --* inuse (16*i + j) := True;\n seq_to_unseq (inuse_count) := 16 * i + j;\n inuse_count := inuse_count + 1;\n end if;\n end loop;\n end if;\n end loop;\n end receive_mapping_table;\n\n -- Receives the selectors.\n procedure receive_selectors is\n j : Unsigned_8;\n begin\n group_count := Natural (get_bits (3));\n selector_count := Natural (Shift_Left (get_bits_32 (8), 7) or get_bits_32 (7));\n for i in 0 .. selector_count - 1 loop\n j := 0;\n while get_boolean loop\n j := j + 1;\n if j > 5 then\n raise data_error;\n end if;\n end loop;\n selector_mtf (i) := j;\n end loop;\n end receive_selectors;\n\n -- Undo the MTF values for the selectors.\n procedure undo_mtf_values is\n pos : array (0 .. max_groups) of Natural;\n v, tmp : Natural;\n begin\n for w in 0 .. group_count - 1 loop\n pos (w) := w;\n end loop;\n for i in 0 .. selector_count - 1 loop\n v := Natural (selector_mtf (i));\n tmp := pos (v);\n while v /= 0 loop\n pos (v) := pos (v - 1);\n v := v - 1;\n end loop;\n pos (0) := tmp;\n selector (i) := Unsigned_8 (tmp);\n end loop;\n end undo_mtf_values;\n\n procedure receive_coding_tables is\n curr : Natural;\n begin\n for t in 0 .. group_count - 1 loop\n curr := Natural (get_bits (5));\n for i in 0 .. global_alpha_size - 1 loop\n loop\n if curr not in 1 .. 20 then\n raise data_error;\n end if;\n exit when not get_boolean;\n if get_boolean then\n curr := curr - 1;\n else\n curr := curr + 1;\n end if;\n end loop;\n len (t) (i) := curr;\n end loop;\n end loop;\n end receive_coding_tables;\n\n -- Builds the Huffman tables.\n procedure make_hufftab is\n minlen, maxlen : Natural;\n begin\n for t in 0 .. group_count - 1 loop\n minlen := 32;\n maxlen := 0;\n for i in 0 .. global_alpha_size - 1 loop\n if len (t) (i) > maxlen then\n maxlen := len (t) (i);\n end if;\n if len (t) (i) < minlen then\n minlen := len (t) (i);\n end if;\n end loop;\n hb_create_decode_tables (global_limit (t), global_base (t), global_perm (t), len (t),\n minlen, maxlen, global_alpha_size);\n minlens (t) := minlen;\n end loop;\n end make_hufftab;\n\n -------------------------\n -- MTF - Move To Front --\n -------------------------\n\n procedure receive_mtf_values is\n --\n mtfa_size : constant := 4096;\n mtfl_size : constant := 16;\n mtfbase : array (0 .. 256 / mtfl_size - 1) of Natural;\n mtfa : array (0 .. mtfa_size - 1) of Natural;\n --\n procedure init_mtf is\n k : Natural := mtfa_size - 1;\n begin\n for i in reverse 0 .. 256 / mtfl_size - 1 loop\n for j in reverse 0 .. mtfl_size - 1 loop\n mtfa (k) := i * mtfl_size + j;\n k := k - 1;\n end loop;\n mtfbase (i) := k + 1;\n end loop;\n end init_mtf;\n --\n group_pos, group_no : Integer;\n gminlen, gsel : Natural;\n --\n function get_mtf_value return Unsigned_32 is\n zn : Natural;\n zvec : Unsigned_32;\n begin\n if group_pos = 0 then\n group_no := group_no + 1;\n group_pos := group_size;\n gsel := Natural (selector (group_no));\n gminlen := minlens (gsel);\n end if;\n group_pos := group_pos - 1;\n zn := gminlen;\n zvec := get_bits_32 (zn);\n while zvec > global_limit (gsel) (zn) loop\n zn := zn + 1;\n zvec := Shift_Left (zvec, 1) or get_bits_32 (1);\n end loop;\n return global_perm (gsel) (Natural (zvec - global_base (gsel) (zn)));\n end get_mtf_value;\n --\n procedure move_mtf_block is\n j, k : Natural;\n begin\n k := mtfa_size;\n for i in reverse 0 .. 256 / mtfl_size - 1 loop\n j := mtfbase (i);\n mtfa (k - 16 .. k - 1) := mtfa (j .. j + 15);\n k := k - 16;\n mtfbase (i) := k;\n end loop;\n end move_mtf_block;\n --\n run_b : constant := 1;\n t : Natural;\n next_sym : Unsigned_32;\n es : Natural;\n n, nn : Natural;\n p, q : Natural; -- indexes mtfa\n u, v : Natural; -- indexes mtfbase\n lno, off : Natural;\n begin -- receive_mtf_values\n group_no := -1;\n group_pos := 0;\n t := 0;\n cftab := (others => 0);\n init_mtf;\n next_sym := get_mtf_value;\n --\n while Natural (next_sym) /= inuse_count + 1 loop\n if next_sym <= run_b then\n es := 0;\n n := 0;\n loop\n es := es + Natural (Shift_Left (next_sym + 1, n));\n n := n + 1;\n next_sym := get_mtf_value;\n exit when next_sym > run_b;\n end loop;\n n := seq_to_unseq (mtfa (mtfbase (0)));\n cftab (n) := cftab (n) + es;\n if t + es > sub_block_size * block_size then\n raise data_error;\n end if;\n while es > 0 loop\n tt.all (t) := Unsigned_32 (n);\n es := es - 1;\n t := t + 1;\n end loop;\n else\n nn := Natural (next_sym - 1);\n if nn < mtfl_size then\n -- Avoid the costs of the general case.\n p := mtfbase (0);\n q := p + nn;\n n := mtfa (q);\n loop\n mtfa (q) := mtfa (q - 1);\n q := q - 1;\n exit when q = p;\n end loop;\n mtfa (q) := n;\n else\n -- General case.\n lno := nn / mtfl_size;\n off := nn mod mtfl_size;\n p := mtfbase (lno);\n q := p + off;\n n := mtfa (q);\n while q /= p loop\n mtfa (q) := mtfa (q - 1);\n q := q - 1;\n end loop;\n u := mtfbase'First;\n v := u + lno;\n loop\n mtfa (mtfbase (v)) := mtfa (mtfbase (v - 1) + mtfl_size - 1);\n v := v - 1;\n mtfbase (v) := mtfbase (v) - 1;\n exit when v = u;\n end loop;\n mtfa (mtfbase (v)) := n;\n if mtfbase (v) = 0 then\n move_mtf_block;\n end if;\n end if;\n cftab (seq_to_unseq (n)) := cftab (seq_to_unseq (n)) + 1;\n tt.all (t) := Unsigned_32 (seq_to_unseq (n));\n t := t + 1;\n if t > sub_block_size * block_size then\n raise data_error;\n end if;\n next_sym := get_mtf_value;\n end if;\n end loop;\n tt_count := t;\n -- Setup cftab to facilitate generation of T^ ( - 1).\n t := 0;\n for i in 0 .. 256 loop\n nn := cftab (i);\n cftab (i) := t;\n t := t + nn;\n end loop;\n end receive_mtf_values;\n\n procedure detransform is\n a : Unsigned_32;\n p, q, r, i255 : Natural;\n begin\n a := 0;\n p := tt'First;\n q := p + tt_count;\n while p /= q loop\n i255 := Natural (tt.all (p) and 16#ff#);\n r := cftab (i255);\n cftab (i255) := cftab (i255) + 1;\n tt.all (r) := tt.all (r) or a;\n a := a + 256;\n p := p + 1;\n end loop;\n end detransform;\n\n -- Cyclic redundancy check to verify uncompressed block data integrity\n\n package CRC is\n\n procedure Init (CRC_Value : out Unsigned_32);\n function Final (CRC_Value : Unsigned_32) return Unsigned_32;\n procedure Update (CRC_Value : in out Unsigned_32; val : Unsigned_8);\n pragma Inline (Update);\n\n end CRC;\n\n package body CRC is\n\n CRC32_Table :\n constant array (Unsigned_32'(0) .. 255) of Unsigned_32 := (\n 16#00000000#, 16#04c11db7#, 16#09823b6e#, 16#0d4326d9#,\n 16#130476dc#, 16#17c56b6b#, 16#1a864db2#, 16#1e475005#,\n 16#2608edb8#, 16#22c9f00f#, 16#2f8ad6d6#, 16#2b4bcb61#,\n 16#350c9b64#, 16#31cd86d3#, 16#3c8ea00a#, 16#384fbdbd#,\n 16#4c11db70#, 16#48d0c6c7#, 16#4593e01e#, 16#4152fda9#,\n 16#5f15adac#, 16#5bd4b01b#, 16#569796c2#, 16#52568b75#,\n 16#6a1936c8#, 16#6ed82b7f#, 16#639b0da6#, 16#675a1011#,\n 16#791d4014#, 16#7ddc5da3#, 16#709f7b7a#, 16#745e66cd#,\n 16#9823b6e0#, 16#9ce2ab57#, 16#91a18d8e#, 16#95609039#,\n 16#8b27c03c#, 16#8fe6dd8b#, 16#82a5fb52#, 16#8664e6e5#,\n 16#be2b5b58#, 16#baea46ef#, 16#b7a96036#, 16#b3687d81#,\n 16#ad2f2d84#, 16#a9ee3033#, 16#a4ad16ea#, 16#a06c0b5d#,\n 16#d4326d90#, 16#d0f37027#, 16#ddb056fe#, 16#d9714b49#,\n 16#c7361b4c#, 16#c3f706fb#, 16#ceb42022#, 16#ca753d95#,\n 16#f23a8028#, 16#f6fb9d9f#, 16#fbb8bb46#, 16#ff79a6f1#,\n 16#e13ef6f4#, 16#e5ffeb43#, 16#e8bccd9a#, 16#ec7dd02d#,\n 16#34867077#, 16#30476dc0#, 16#3d044b19#, 16#39c556ae#,\n 16#278206ab#, 16#23431b1c#, 16#2e003dc5#, 16#2ac12072#,\n 16#128e9dcf#, 16#164f8078#, 16#1b0ca6a1#, 16#1fcdbb16#,\n 16#018aeb13#, 16#054bf6a4#, 16#0808d07d#, 16#0cc9cdca#,\n 16#7897ab07#, 16#7c56b6b0#, 16#71159069#, 16#75d48dde#,\n 16#6b93dddb#, 16#6f52c06c#, 16#6211e6b5#, 16#66d0fb02#,\n 16#5e9f46bf#, 16#5a5e5b08#, 16#571d7dd1#, 16#53dc6066#,\n 16#4d9b3063#, 16#495a2dd4#, 16#44190b0d#, 16#40d816ba#,\n 16#aca5c697#, 16#a864db20#, 16#a527fdf9#, 16#a1e6e04e#,\n 16#bfa1b04b#, 16#bb60adfc#, 16#b6238b25#, 16#b2e29692#,\n 16#8aad2b2f#, 16#8e6c3698#, 16#832f1041#, 16#87ee0df6#,\n 16#99a95df3#, 16#9d684044#, 16#902b669d#, 16#94ea7b2a#,\n 16#e0b41de7#, 16#e4750050#, 16#e9362689#, 16#edf73b3e#,\n 16#f3b06b3b#, 16#f771768c#, 16#fa325055#, 16#fef34de2#,\n 16#c6bcf05f#, 16#c27dede8#, 16#cf3ecb31#, 16#cbffd686#,\n 16#d5b88683#, 16#d1799b34#, 16#dc3abded#, 16#d8fba05a#,\n 16#690ce0ee#, 16#6dcdfd59#, 16#608edb80#, 16#644fc637#,\n 16#7a089632#, 16#7ec98b85#, 16#738aad5c#, 16#774bb0eb#,\n 16#4f040d56#, 16#4bc510e1#, 16#46863638#, 16#42472b8f#,\n 16#5c007b8a#, 16#58c1663d#, 16#558240e4#, 16#51435d53#,\n 16#251d3b9e#, 16#21dc2629#, 16#2c9f00f0#, 16#285e1d47#,\n 16#36194d42#, 16#32d850f5#, 16#3f9b762c#, 16#3b5a6b9b#,\n 16#0315d626#, 16#07d4cb91#, 16#0a97ed48#, 16#0e56f0ff#,\n 16#1011a0fa#, 16#14d0bd4d#, 16#19939b94#, 16#1d528623#,\n 16#f12f560e#, 16#f5ee4bb9#, 16#f8ad6d60#, 16#fc6c70d7#,\n 16#e22b20d2#, 16#e6ea3d65#, 16#eba91bbc#, 16#ef68060b#,\n 16#d727bbb6#, 16#d3e6a601#, 16#dea580d8#, 16#da649d6f#,\n 16#c423cd6a#, 16#c0e2d0dd#, 16#cda1f604#, 16#c960ebb3#,\n 16#bd3e8d7e#, 16#b9ff90c9#, 16#b4bcb610#, 16#b07daba7#,\n 16#ae3afba2#, 16#aafbe615#, 16#a7b8c0cc#, 16#a379dd7b#,\n 16#9b3660c6#, 16#9ff77d71#, 16#92b45ba8#, 16#9675461f#,\n 16#8832161a#, 16#8cf30bad#, 16#81b02d74#, 16#857130c3#,\n 16#5d8a9099#, 16#594b8d2e#, 16#5408abf7#, 16#50c9b640#,\n 16#4e8ee645#, 16#4a4ffbf2#, 16#470cdd2b#, 16#43cdc09c#,\n 16#7b827d21#, 16#7f436096#, 16#7200464f#, 16#76c15bf8#,\n 16#68860bfd#, 16#6c47164a#, 16#61043093#, 16#65c52d24#,\n 16#119b4be9#, 16#155a565e#, 16#18197087#, 16#1cd86d30#,\n 16#029f3d35#, 16#065e2082#, 16#0b1d065b#, 16#0fdc1bec#,\n 16#3793a651#, 16#3352bbe6#, 16#3e119d3f#, 16#3ad08088#,\n 16#2497d08d#, 16#2056cd3a#, 16#2d15ebe3#, 16#29d4f654#,\n 16#c5a92679#, 16#c1683bce#, 16#cc2b1d17#, 16#c8ea00a0#,\n 16#d6ad50a5#, 16#d26c4d12#, 16#df2f6bcb#, 16#dbee767c#,\n 16#e3a1cbc1#, 16#e760d676#, 16#ea23f0af#, 16#eee2ed18#,\n 16#f0a5bd1d#, 16#f464a0aa#, 16#f9278673#, 16#fde69bc4#,\n 16#89b8fd09#, 16#8d79e0be#, 16#803ac667#, 16#84fbdbd0#,\n 16#9abc8bd5#, 16#9e7d9662#, 16#933eb0bb#, 16#97ffad0c#,\n 16#afb010b1#, 16#ab710d06#, 16#a6322bdf#, 16#a2f33668#,\n 16#bcb4666d#, 16#b8757bda#, 16#b5365d03#, 16#b1f740b4#\n );\n\n procedure Update (CRC_Value : in out Unsigned_32; val : Unsigned_8) is\n begin\n CRC_Value :=\n CRC32_Table (16#FF# and (Shift_Right (CRC_Value, 24) xor Unsigned_32 (val)))\n xor\n Shift_Left (CRC_Value, 8);\n end Update;\n\n procedure Init (CRC_Value : out Unsigned_32) is\n begin\n CRC_Value := 16#FFFF_FFFF#;\n end Init;\n\n function Final (CRC_Value : Unsigned_32) return Unsigned_32 is\n begin\n return not CRC_Value;\n end Final;\n\n end CRC;\n\n compare_final_CRC : Boolean := False;\n stored_blockcrc, mem_stored_blockcrc, computed_crc : Unsigned_32;\n\n -- Decode a new compressed block.\n function decode_block return Boolean is\n magic : String (1 .. 6);\n begin\n for i in 1 .. 6 loop\n magic (i) := Character'Val (get_byte);\n end loop;\n if magic = \"1AY&SY\" then\n if check_CRC then\n if compare_final_CRC then\n null; -- initialisation is delayed until the rle buffer is empty\n else\n CRC.Init (computed_crc); -- Initialize for next block.\n end if;\n end if;\n stored_blockcrc := get_cardinal;\n block_randomized := get_boolean;\n block_origin := Natural (get_cardinal24);\n -- Receive the mapping table.\n receive_mapping_table;\n global_alpha_size := inuse_count + 2;\n -- Receive the selectors.\n receive_selectors;\n -- Undo the MTF values for the selectors.\n undo_mtf_values;\n -- Receive the coding tables.\n receive_coding_tables;\n -- Build the Huffman tables.\n make_hufftab;\n -- Receive the MTF values.\n receive_mtf_values;\n -- Undo the Burrows Wheeler transformation.\n detransform;\n decode_available := tt_count;\n return True;\n elsif magic = Character'Val (16#17#) & \"rE8P\" & Character'Val (16#90#) then\n return False;\n else\n raise bad_block_magic;\n end if;\n end decode_block;\n\n next_rle_idx : Integer := -2;\n buf : Buffer (1 .. output_buffer_size);\n last : Natural;\n\n procedure Read is\n shorten : Natural := 0;\n\n procedure rle_read is\n rle_len : Natural;\n data : Unsigned_8;\n idx : Integer := buf'First;\n count : Integer := buf'Length;\n --\n procedure rle_write is\n pragma Inline (rle_write);\n begin\n loop\n buf (idx) := data;\n idx := idx + 1;\n count := count - 1;\n rle_len := rle_len - 1;\n if check_CRC then\n CRC.Update (computed_crc, data);\n if rle_len = 0 and then compare_final_CRC then\n if CRC.Final (computed_crc) /= mem_stored_blockcrc then\n raise block_crc_check_failed;\n end if;\n compare_final_CRC := False;\n CRC.Init (computed_crc); -- Initialize for next block.\n end if;\n end if;\n exit when rle_len = 0 or else count = 0;\n end loop;\n end rle_write;\n --\n -- handle extreme cases of data of length 1, 2\n input_dried : exception;\n --\n -- Make next_rle_idx index to the next decoded byte.\n -- If next_rle_idx did index to the last\n -- byte in the current block, decode the next block.\n --\n procedure consume_rle is\n pragma Inline (consume_rle);\n begin\n next_rle_idx := Integer (Shift_Right (tt.all (next_rle_idx), 8));\n decode_available := decode_available - 1;\n if decode_available = 0 then\n compare_final_CRC := True;\n mem_stored_blockcrc := stored_blockcrc;\n -- ^ There might be a new block when last block's\n -- rle is finally emptied.\n --\n -- ** New block\n if decode_block then\n next_rle_idx := Natural (Shift_Right (tt.all (block_origin), 8));\n else\n next_rle_idx := -1;\n end_reached := True;\n end if;\n -- **\n if end_reached then\n raise input_dried;\n end if;\n end if;\n end consume_rle;\n --\n function rle_byte return Unsigned_8 is\n pragma Inline (rle_byte);\n begin\n return Unsigned_8 (tt.all (next_rle_idx) and 16#FF#);\n end rle_byte;\n --\n function rle_possible return Boolean is\n pragma Inline (rle_possible);\n begin\n return decode_available > 0 and then data = rle_byte;\n end rle_possible;\n --\n begin -- rle_read\n rle_len := rle_run_left;\n data := rle_run_data;\n if block_randomized then\n raise randomized_not_yet_implemented;\n end if;\n if rle_len /= 0 then\n rle_write;\n if count = 0 then\n shorten := 0;\n rle_run_data := data;\n rle_run_left := rle_len;\n return;\n end if;\n end if;\n begin\n -- The big loop\n loop\n if decode_available = 0 or else end_reached then\n exit;\n end if;\n rle_len := 1;\n data := rle_byte;\n consume_rle;\n if rle_possible then\n rle_len := rle_len + 1;\n consume_rle;\n if rle_possible then\n rle_len := rle_len + 1;\n consume_rle;\n if rle_possible then\n consume_rle;\n rle_len := rle_len + Natural (rle_byte) + 1;\n consume_rle;\n end if;\n end if;\n end if;\n rle_write;\n exit when count = 0;\n end loop;\n exception\n when input_dried => rle_write;" + }, + { + "function_def": "procedure Dispose is new", + "function_body": "Ada.Unchecked_Deallocation (String, p_String);\n\n procedure Dispose is new\n Ada.Unchecked_Deallocation (Ada.Streams.Stream_Element_Array,\n p_Stream_Element_Array);\n\n procedure Dispose is new\n Ada.Unchecked_Deallocation (UnZip_Stream_Type,\n Zipped_File_Type);\n\n --------------------------------------------------\n -- *The* internal 1 - file unzipping procedure. --\n -- Input must be _open_ and won't be _closed_ ! --\n --------------------------------------------------\n\n procedure UnZipFile (zip_file : Zip_Streams.Zipstream_Class;\n header_index : in out Ada.Streams.Stream_IO.Positive_Count;\n mem_ptr : out p_Stream_Element_Array;\n password : in out Ada.Strings.Unbounded.Unbounded_String;\n hint_comp_size : File_size_type; -- Added 2007 for .ODS files\n cat_uncomp_size : File_size_type) is\n\n work_index : Ada.Streams.Stream_IO.Positive_Count := header_index;\n local_header : Zip.Headers.Local_File_Header;\n data_descriptor_present : Boolean;\n encrypted : Boolean;\n method : PKZip_method;\n use Ada.Streams.Stream_IO, Zip, Zip_Streams;\n begin\n begin\n Zip_Streams.Set_Index (zip_file, Positive (header_index));\n declare\n TempStream : constant Zipstream_Class := zip_file;\n begin\n Zip.Headers.Read_and_check (TempStream, local_header);" + }, + { + "function_def": "procedure Dispose is new Ada.Unchecked_Deallocation (Dir_node, p_Dir_node);", + "function_body": "procedure Dispose is new Ada.Unchecked_Deallocation (String, p_String);\n\n package Binary_tree_rebalancing is\n procedure Rebalance (root : in out p_Dir_node);\n end Binary_tree_rebalancing;\n\n package body Binary_tree_rebalancing is\n\n -------------------------------------------------------------------\n -- Tree Rebalancing in Optimal Time and Space --\n -- QUENTIN F. STOUT and BETTE L. WARREN --\n -- Communications of the ACM September 1986 Volume 29 Number 9 --\n -------------------------------------------------------------------\n -- http://www.eecs.umich.edu/~qstout/pap/CACM86.pdf\n --\n -- Translated by (New) P2Ada v. 15 - Nov - 2006\n\n procedure Tree_to_vine (root : p_Dir_node; size : out Integer) is\n -- transform the tree with pseudo - root\n -- \"root^\" into a vine with pseudo - root\n -- node \"root^\", and store the number of\n -- nodes in \"size\"\n\n vine_tail, remainder, temp : p_Dir_node;\n\n begin\n vine_tail := root;\n remainder := vine_tail.all.right;\n size := 0;\n while remainder /= null loop\n if remainder.all.left = null then\n -- move vine - tail down one:\n vine_tail := remainder;\n remainder := remainder.all.right;\n size := size + 1;\n else\n -- rotate:\n temp := remainder.all.left;\n remainder.all.left := temp.all.right;\n temp.all.right := remainder;\n remainder := temp;\n vine_tail.all.right := temp;\n end if;\n end loop;\n end Tree_to_vine;\n\n procedure Vine_to_tree (root : p_Dir_node; size_given : Integer) is\n -- convert the vine with \"size\" nodes and pseudo - root\n -- node \"root^\" into a balanced tree\n leaf_count : Integer;\n size : Integer := size_given;\n\n procedure Compression (Dir_Root : p_Dir_node; count : Integer) is\n -- compress \"count\" spine nodes in the tree with pseudo - root \"root^\"\n scanner, child : p_Dir_node;\n begin\n scanner := Dir_Root;\n for i in 1 .. count loop\n child := scanner.all.right;\n scanner.all.right := child.all.right;\n scanner := scanner.all.right;\n child.all.right := scanner.all.left;\n scanner.all.left := child;\n end loop;\n end Compression;\n\n -- Returns n - 2 ** Integer (Float'Floor (log (Float (n)) / log (2.0)))\n -- without Float - Point calculation and rounding errors with too short floats\n function Remove_leading_binary_1 (n : Integer) return Integer is\n x : Integer := 2**16; -- supposed maximum\n begin\n if n < 1 then\n return n;\n end if;\n while n mod x = n loop\n x := x / 2;\n end loop;\n return n mod x;\n end Remove_leading_binary_1;\n\n begin -- Vine_to_tree\n leaf_count := Remove_leading_binary_1 (size + 1);\n Compression (root, leaf_count); -- create deepest leaves\n -- use Perfect_leaves instead for a perfectly balanced tree\n size := size - leaf_count;\n while size > 1 loop\n Compression (root, size / 2);\n size := size / 2;\n end loop;\n end Vine_to_tree;\n\n procedure Rebalance (root : in out p_Dir_node) is\n -- Rebalance the binary search tree with root \"root.all\",\n -- with the result also rooted at \"root.all\".\n -- Uses the Tree_to_vine and Vine_to_tree procedures.\n pseudo_root : p_Dir_node;\n size : Integer;\n begin\n pseudo_root := new Dir_node (name_len => 0);\n pseudo_root.all.right := root;\n Tree_to_vine (pseudo_root, size);\n Vine_to_tree (pseudo_root, size);\n root := pseudo_root.all.right;\n Dispose (pseudo_root);\n end Rebalance;\n\n end Binary_tree_rebalancing;\n\n -- 19 - Jun - 2001 : Enhanced file name identification\n -- a) when case insensitive - > all UPPER (current)\n -- b) '\\' and '/' identified - > all '/' (new)\n\n function Normalize (s : String; case_sensitive : Boolean) return String is\n sn : String (s'Range);\n begin\n if case_sensitive then\n sn := s;\n else\n sn := Ada.Characters.Handling.To_Upper (s);\n end if;\n for i in sn'Range loop\n if sn (i) = '\\' then\n sn (i) := '/';\n end if;\n end loop;\n return sn;\n end Normalize;\n\n -------------------------------------------------------------\n -- Load Zip_info from a stream containing the .zip archive --\n -------------------------------------------------------------\n\n procedure Load (info : out Zip_info;\n from : Zip_Streams.Zipstream_Class;\n case_sensitive : Boolean := False) is\n\n procedure Insert (dico_name : String; -- UPPER if case - insensitive search\n file_name : String;\n file_index : Ada.Streams.Stream_IO.Positive_Count;\n comp_size,\n uncomp_size : File_size_type;\n crc_32 : Unsigned_32;\n date_time : Time;\n method : PKZip_method;\n unicode_file_name : Boolean;\n node : in out p_Dir_node) is\n\n begin\n if node = null then\n node := new Dir_node'\n ((name_len => file_name'Length,\n left => null,\n right => null,\n dico_name => dico_name,\n file_name => file_name,\n file_index => file_index,\n comp_size => comp_size,\n uncomp_size => uncomp_size,\n crc_32 => crc_32,\n date_time => date_time,\n method => method,\n unicode_file_name => unicode_file_name\n )\n );\n elsif dico_name > node.all.dico_name then\n Insert (dico_name, file_name, file_index, comp_size, uncomp_size, crc_32, date_time, method, unicode_file_name, node.all.right);\n elsif dico_name < node.all.dico_name then\n Insert (dico_name, file_name, file_index, comp_size, uncomp_size, crc_32, date_time, method, unicode_file_name, node.all.left);\n else\n raise Duplicate_name;\n end if;\n end Insert;\n\n the_end : Zip.Headers.End_of_Central_Dir;\n header : Zip.Headers.Central_File_Header;\n p : p_Dir_node := null;\n zip_info_already_loaded : exception;\n main_comment : p_String;\n use Ada.Streams, Ada.Streams.Stream_IO;\n begin -- Load Zip_info\n if info.loaded then\n raise zip_info_already_loaded;\n end if; -- 15 - Apr - 2002\n Zip.Headers.Load (from, the_end);\n -- We take the opportunity to read the main comment, which is right\n -- after the end - of - central - directory block.\n main_comment := new String (1 .. Integer (the_end.main_comment_length));\n String'Read (from, main_comment.all);\n -- Process central directory:\n Zip_Streams.Set_Index (\n from,\n Positive (\n 1 +\n the_end.offset_shifting + the_end.central_dir_offset\n )\n );\n\n for i in 1 .. the_end.total_entries loop\n Zip.Headers.Read_and_check (from, header);\n declare\n this_name : String (1 .. Natural (header.short_info.filename_length));\n begin\n String'Read (from, this_name);\n -- Skip extra field and entry comment.\n Zip_Streams.Set_Index (\n from, Positive (\n Ada.Streams.Stream_IO.Count (Zip_Streams.Index (from)) +\n Ada.Streams.Stream_IO.Count (\n header.short_info.extra_field_length +\n header.comment_length\n ))\n );\n -- Now the whole i_th central directory entry is behind\n Insert (dico_name => Normalize (this_name, case_sensitive),\n file_name => Normalize (this_name, True),\n file_index => Ada.Streams.Stream_IO.Count\n (1 + header.local_header_offset + the_end.offset_shifting),\n comp_size => header.short_info.dd.compressed_size,\n uncomp_size => header.short_info.dd.uncompressed_size,\n crc_32 => header.short_info.dd.crc_32,\n date_time => header.short_info.file_timedate,\n method => Method_from_code (header.short_info.zip_type),\n unicode_file_name =>\n (header.short_info.bit_flag and\n Zip.Headers.Language_Encoding_Flag_Bit) /= 0,\n node => p);\n -- Since the files are usually well ordered, the tree as inserted\n -- is very unbalanced; we need to rebalance it from time to time\n -- during loading, otherwise the insertion slows down dramatically\n -- for zip files with plenty of files - converges to\n -- O (total_entries ** 2) .. .\n if i mod 256 = 0 then\n Binary_tree_rebalancing.Rebalance (p);\n end if;" + }, + { + "function_def": "procedure Dispose is new", + "function_body": "Ada.Unchecked_Deallocation (HufT_table, p_HufT_table);\n procedure Dispose is new\n Ada.Unchecked_Deallocation (Table_list, p_Table_list);\n\n current : p_Table_list;\n tcount : Natural; -- just a stat. Idea : replace table_list with an array\n\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[HufT_Free .. . \");\n tcount := 0;\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n while tl /= null loop\n Dispose (tl.all.table); -- destroy the Huffman table\n current := tl;\n tl := tl.all.next;\n Dispose (current); -- destroy the current node\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n tcount := tcount + 1;\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end loop;\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put_Line (Integer'Image (tcount) & \" tables]\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n end HufT_free;\n\n -- Build huffman table from code lengths given by array b\n\n procedure HufT_build (b : Length_array;\n s : Integer;\n d, e : Length_array;\n tl : out p_Table_list;\n m : in out Integer;\n huft_incomplete : out Boolean)\n is\n use Interfaces;\n\n b_max : constant := 16;\n b_maxp1 : constant := b_max + 1;\n\n -- bit length count table\n count : array (0 .. b_maxp1) of Integer := (others => 0);\n\n f : Integer; -- i repeats in table every f entries\n g : Integer; -- max. code length\n i, -- counter, current code\n j : Integer; -- counter\n kcc : Integer; -- number of bits in current code\n\n c_idx, v_idx : Natural; -- array indices\n\n current_table_ptr : p_HufT_table := null;\n current_node_ptr : p_Table_list := null; -- curr. node for the curr. table\n new_node_ptr : p_Table_list; -- new node for the new table\n\n new_entry : HufT; -- table entry for structure assignment\n\n u : array (0 .. b_max) of p_HufT_table; -- table stack\n\n n_max : constant := 288;\n -- values in order of bit length\n v : array (0 .. n_max) of Integer := (others => 0);\n el_v, el_v_m_s : Integer;\n\n w : Natural := 0; -- bits before this table\n\n offset, code_stack : array (0 .. b_maxp1) of Integer;\n\n table_level : Integer := -1;\n bits : array (Integer'(-1) .. b_maxp1) of Integer;\n -- ^bits (table_level) = # bits in table of level table_level\n\n y : Integer; -- number of dummy codes added\n z : Natural := 0; -- number of entries in current table\n el : Integer; -- length of eob code=code 256\n\n no_copy_length_array : constant Boolean := d'Length = 0 or else e'Length = 0;\n\n begin\n if full_trace then\n pragma Warnings (Off, \"this code can never be executed and has been deleted\");\n Ada.Text_IO.Put (\"[HufT_Build .. .\");\n pragma Warnings (On, \"this code can never be executed and has been deleted\");\n end if;\n tl := null;\n\n if b'Length > 256 then -- set length of EOB code, if any\n el := b (256);\n else\n el := b_max;\n end if;\n\n -- Generate counts for each bit length\n\n for k in b'Range loop\n if b (k) > b_max then\n -- m := 0; -- GNAT 2005 doesn't like it (warning).\n raise huft_error;\n end if;\n count (b (k)) := count (b (k)) + 1;\n end loop;\n\n if count (0) = b'Length then\n m := 0;\n huft_incomplete := False; -- spotted by Tucker Taft, 19 - Aug - 2004\n return; -- complete\n end if;\n\n -- Find minimum and maximum length, bound m by those\n\n j := 1;\n while j <= b_max and then count (j) = 0 loop\n j := j + 1;\n end loop;\n kcc := j;\n if m < j then\n m := j;\n end if;\n i := b_max;\n while i > 0 and then count (i) = 0 loop\n i := i - 1;\n end loop;\n g := i;\n if m > i then\n m := i;\n end if;\n\n -- Adjust last length count to fill out codes, if needed\n\n y := Integer (Shift_Left (Unsigned_32'(1), j)); -- y := 2 ** j;\n while j < i loop\n y := y - count (j);\n if y < 0 then\n raise huft_error;\n end if;\n y := y * 2;\n j := j + 1;\n end loop;\n\n y := y - count (i);\n if y < 0 then\n raise huft_error;\n end if;\n count (i) := count (i) + y;\n\n -- Generate starting offsets into the value table for each length\n\n offset (1) := 0;\n j := 0;\n for idx in 2 .. i loop\n j := j + count (idx - 1);\n offset (idx) := j;\n end loop;\n\n -- Make table of values in order of bit length\n\n for idx in b'Range loop\n j := b (idx);\n if j /= 0 then\n v (offset (j)) := idx - b'First;\n offset (j) := offset (j) + 1;\n end if;\n end loop;\n\n -- Generate huffman codes and for each, make the table entries\n\n code_stack (0) := 0;\n i := 0;\n v_idx := v'First;\n bits (-1) := 0;\n\n -- go through the bit lengths (kcc already is bits in shortest code)\n for k in kcc .. g loop\n\n for am1 in reverse 0 .. count (k) - 1 loop -- a counts codes of length k\n\n -- here i is the huffman code of length k bits for value v (v_idx)\n while k > w + bits (table_level) loop\n\n w := w + bits (table_level); -- Length of tables to this position\n table_level := table_level + 1;\n z := g - w; -- Compute min size table <= m bits\n if z > m then\n z := m;\n end if;\n j := k - w;\n f := Integer (Shift_Left (Unsigned_32'(1), j)); -- f := 2 ** j;\n if f > am1 + 2 then -- Try a k - w bit table\n f := f - (am1 + 2);\n c_idx := k;\n loop -- Try smaller tables up to z bits\n j := j + 1;\n exit when j >= z;\n f := f * 2;\n c_idx := c_idx + 1;\n exit when f - count (c_idx) <= 0;\n f := f - count (c_idx);\n end loop;\n end if;\n\n if w + j > el and then w < el then\n j := el - w; -- Make EOB code end at table\n end if;\n if w = 0 then\n j := m; -- Fix : main table always m bits!\n end if;\n z := Integer (Shift_Left (Unsigned_32'(1), j)); -- z := 2 ** j;\n bits (table_level) := j;\n\n -- Allocate and link new table\n\n begin\n current_table_ptr := new HufT_table (0 .. z);\n new_node_ptr := new Table_list'(current_table_ptr, null);\n exception\n when Storage_Error =>\n raise huft_out_of_memory;" + }, + { + "function_def": "procedure Translation_inst is new Limited_Translation (No_Limitation);", + "function_body": "procedure Translation (actor : in out GLOBE_3D.Camera;\n gc : Game_Control.Command_set;\n gx, gy : GLOBE_3D.Real;\n unitary_change : GLOBE_3D.Real;\n deceleration : GLOBE_3D.Real;\n time_step : GLOBE_3D.Real) renames Translation_inst;\n\n procedure Rotation (actor : in out GLOBE_3D.Camera;\n gc : Game_Control.Command_set;\n gx, gy : GLOBE_3D.Real;\n unitary_change : GLOBE_3D.Real;\n deceleration : GLOBE_3D.Real;\n time_step : GLOBE_3D.Real) is\n\n incremental_rotation : Vector_3D := (0.0, 0.0, 0.0);\n\n begin\n Abstract_rotation (gc, gx, gy,\n unitary_change, deceleration, incremental_rotation, time_step,\n actor.rotation_Speed);\n actor.rotation := actor.rotation + incremental_rotation;\n if actor.compose_rotations then\n actor.World_Rotation :=\n XYZ_rotation (incremental_rotation) * actor.World_Rotation;\n Re_Orthonormalize (actor.World_Rotation);\n else\n declare\n r : Vector_3D renames actor.rotation;\n -- We need to turn around the axes in this order : Y, X, Z\n begin\n actor.World_Rotation :=\n XYZ_rotation (0.0, 0.0, r (2)) * -- 3) turn around the nose\n XYZ_rotation (r (0), 0.0, 0.0) * -- 2) lift or lower the head\n XYZ_rotation (0.0, r (1), 0.0); -- 1) pivotate around the feet" + }, + { + "function_def": "procedure Texture_is (Self : in sprite.p_Sprite; Now : in GL.textures.Object;", + "function_body": "texture_Transform_s : in GL.textures.texture_Transform;\n texture_Transform_t : in GL.textures.texture_Transform)\n is\n use GL.Textures, GL.Skins, GL.Geometry.vbo;\n\n the_skinned_Geometry : GL.skinned_Geometry.skinned_Geometry_t renames self.skinned_geometrys (1);\n\n the_Skin : p_Skin_unlit_textured_vbo := new Skin_unlit_textured_vbo' (texture => Now);\n the_Vertices : GL.geometry.GL_vertex_Array renames vbo_Geometry (the_skinned_Geometry.Geometry.all).Vertices.get;\n texture_Coords : GL.textures.p_Coordinate_2D_array := to_texture_Coordinates_xz (the_Vertices, texture_Transform_s,\n texture_Transform_t);\n begin\n the_skinned_Geometry.Skin := the_Skin.all'Access;\n the_skinned_Geometry.Veneer := the_Skin.all.new_Veneer (for_geometry => the_skinned_Geometry.Geometry.all);\n\n declare\n use GL.Buffer.texture_coords;\n the_Veneer : GL.skins.Veneer_unlit_textured_vbo'Class renames GL.skins.Veneer_unlit_textured_vbo'Class (the_skinned_Geometry.Veneer.all);\n begin\n the_Veneer.texture_Coordinates := to_Buffer (texture_Coords, usage => GL.STATIC_DRAW);" + }, + { + "function_def": "procedure initialise", + "function_body": "is\n begin\n the_vertex_Buffer := GL.Buffer.vertex.to_Buffer (object_points'Access, usage => GL.STATIC_DRAW);\n\n declare\n piece_Id : Piece;\n begin\n for i in reverse 1 .. nb_faces loop\n case i is\n when 178 .. 237 => piece_Id := silver_Metal;\n when 260 .. 315 => piece_Id := black_Cockpit;\n when 740 .. 779 => piece_Id := Black;\n when 860 .. 865 |\n 936 .. 941 => piece_Id := black_front_Air;\n when 316 .. 391 => piece_Id := Copper;\n when 780 .. 803 => piece_Id := fire_Engine;\n when 392 => piece_Id := nose_Cone;\n when others => piece_Id := Remains;\n end case;\n\n indices_Count (piece_Id) := indices_Count (piece_Id) + 1;\n the_Indices (piece_Id) (positive_uInt (indices_Count (piece_Id))) := vertex_Id (object_faces (i, 1));\n\n indices_Count (piece_Id) := indices_Count (piece_Id) + 1;\n the_Indices (piece_Id) (positive_uInt (indices_Count (piece_Id))) := vertex_Id (object_faces (i, 2));\n\n indices_Count (piece_Id) := indices_Count (piece_Id) + 1;\n the_Indices (piece_Id) (positive_uInt (indices_Count (piece_Id))) := vertex_Id (object_faces (i, 3));\n end loop;" + }, + { + "function_def": "procedure deallocate is new ada.unchecked_Deallocation (Primitive'Class, p_Primitive);", + "function_body": "begin\n destroy (Self.all);\n deallocate (Self);" + }, + { + "function_def": "procedure Get_pixel is", + "function_body": "begin\n case iBits is\n when 32 => -- BGRA\n Get_Byte (stream_buf, pix (pix'First + 2));\n Get_Byte (stream_buf, pix (pix'First + 1));\n Get_Byte (stream_buf, pix (pix'First));\n Get_Byte (stream_buf, pix (pix'First + 3));\n when 24 => -- BGR\n Get_Byte (stream_buf, pix (pix'First + 2));\n Get_Byte (stream_buf, pix (pix'First + 1));\n Get_Byte (stream_buf, pix (pix'First));\n when 8 => -- Grey\n Get_Byte (stream_buf, pix (pix'First));\n when others =>\n null;\n end case;\n end Get_pixel;\n\n tmp : GL.Ubyte;\n\n begin -- RLE_Pixel\n if RLE_pixels_remaining = 0 then -- load RLE code\n Get_Byte (stream_buf, tmp);\n Get_pixel;\n RLE_pixels_remaining := GL.Ubyte'Pos (tmp and 16#7F#);\n is_run_packet := (tmp and 16#80#) /= 0;\n if is_run_packet then\n case iBits is\n when 32 =>\n pix_mem (1 .. 4) := pix;\n when 24 =>\n pix_mem (1 .. 3) := pix;\n when 8 =>\n pix_mem (1 .. 1) := pix;\n when others =>\n null;\n end case;\n end if;\n else\n if is_run_packet then\n case iBits is\n when 32 =>\n pix := pix_mem (1 .. 4);\n when 24 =>\n pix := pix_mem (1 .. 3);\n when 8 =>\n pix := pix_mem (1 .. 1);\n when others =>\n null;\n end case;\n else\n Get_pixel;\n end if;\n RLE_pixels_remaining := RLE_pixels_remaining - 1;\n end if;\n end RLE_Pixel;\n\n -- =============\n -- getRGBA\n\n -- Reads in RGBA data for a 32bit image.\n -- =============\n\n procedure getRGBA (buffer : out Byte_Array) is\n i : Integer := buffer'First;\n begin\n if RLE then\n while i <= buffer'Last - 3 loop\n RLE_Pixel (32, buffer (i .. i + 3));\n i := i + 4;\n end loop;\n else\n while i <= buffer'Last - 3 loop\n -- TGA is stored in BGRA, make it RGBA\n Get_Byte (stream_buf, buffer (i + 2));\n Get_Byte (stream_buf, buffer (i + 1));\n Get_Byte (stream_buf, buffer (i));\n Get_Byte (stream_buf, buffer (i + 3));\n i := i + 4;\n end loop;\n end if;\n the_Image.tex_Format := GL.RGBA;\n the_Image.tex_pixel_Format := GL.RGBA;\n end getRGBA;\n\n -- =============\n -- getRGB\n\n -- Reads in RGB data for a 24bit image.\n -- =============\n\n procedure getRGB (buffer : out Byte_Array) is\n i : Integer := buffer'First;\n begin\n if RLE then\n while i <= buffer'Last - 2 loop\n RLE_Pixel (24, buffer (i .. i + 2));\n i := i + 3;\n end loop;\n else\n while i <= buffer'Last - 2 loop\n -- TGA is stored in BGR, make it RGB\n Get_Byte (stream_buf, buffer (i + 2));\n Get_Byte (stream_buf, buffer (i + 1));\n Get_Byte (stream_buf, buffer (i));\n i := i + 3;\n end loop;\n end if;\n the_Image.tex_Format := GL.RGB;\n the_Image.tex_pixel_Format := GL.RGB;\n end getRGB;\n\n -- =============\n -- getGray\n\n -- Gets the grayscale image data. Used as an alpha channel.\n -- =============\n\n procedure getGray (buffer : out Byte_Array) is\n begin\n if RLE then\n for b in buffer'Range loop\n RLE_Pixel (8, buffer (b .. b));\n end loop;\n else\n for b in buffer'Range loop\n Get_Byte (stream_buf, buffer (b));\n end loop;\n end if;\n the_Image.tex_Format := GL.LUMINANCE; -- ALPHA\n the_Image.tex_pixel_Format := GL.LUMINANCE;\n end getGray;\n\n -- =============\n -- getData\n\n -- Gets the image data for the specified bit depth.\n -- =============\n\n procedure getData (iBits : Integer; buffer : out Byte_Array) is\n begin\n Attach_Stream (stream_buf, S);\n case iBits is\n when 32 =>\n getRGBA (buffer);\n the_Image.blending_hint := True;\n when 24 =>\n getRGB (buffer);\n the_Image.blending_hint := False;\n when 8 =>\n getGray (buffer);\n the_Image.blending_hint := True;\n when others => null;\n end case;\n end getData;\n\n TGA_type : Byte_Array (0 .. 3);\n info : Byte_Array (0 .. 5);\n dummy : Byte_Array (1 .. 8);\n\n Image_Bits : Integer;\n Image_Type : Integer;\n\n begin -- to_TGA_Image\n Byte_Array'Read (S, TGA_type); -- read in colormap info and image type\n Byte_Array'Read (S, dummy); -- seek past the header and useless info\n Byte_Array'Read (S, info);\n\n if TGA_type (1) /= GL.Ubyte'Val (0) then\n Raise_Exception (\n TGA_Unsupported_Image_Type'Identity,\n \"TGA : palette not supported, please use BMP\"\n );\n end if;\n\n -- Image type:\n -- 1=8 - bit palette style\n -- 2=Direct [A]RGB image\n -- 3=grayscale\n -- 9=RLE version of Type 1\n -- 10=RLE version of Type 2\n -- 11=RLE version of Type 3\n\n Image_Type := GL.Ubyte'Pos (TGA_type (2));\n RLE := Image_Type >= 9;\n if RLE then\n Image_Type := Image_Type - 8;\n RLE_pixels_remaining := 0;\n end if;\n if Image_Type /= 2 and then Image_Type /= 3 then\n Raise_Exception (\n TGA_Unsupported_Image_Type'Identity,\n \"TGA type =\" & Integer'Image (Image_Type)\n );\n end if;\n\n the_Image.Width := GL.Ubyte'Pos (info (0)) + GL.Ubyte'Pos (info (1)) * 256;\n the_Image.Height := GL.Ubyte'Pos (info (2)) + GL.Ubyte'Pos (info (3)) * 256;\n Image_Bits := GL.Ubyte'Pos (info (4));\n\n the_Image.size := the_Image.Width * the_Image.Height;\n\n -- 30 - Apr - 2006 : dimensions not power of two allowed, but discouraged in the docs.\n --\n -- -- make sure dimension is a power of 2\n -- if not (checkSize (imageWidth) and checkSize (imageHeight)) then\n -- raise TGA_BAD_DIMENSION;\n -- end if;\n\n -- make sure we are loading a supported TGA_type\n if Image_Bits /= 32 and then Image_Bits /= 24 and then Image_Bits /= 8 then\n raise TGA_Unsupported_Bits_per_pixel;\n end if;\n\n -- Allocation\n the_Image.Data := new Byte_Array (0 .. (Image_Bits / 8) * the_Image.size - 1);\n getData (Image_Bits, the_Image.Data.all);\n\n return the_Image;\n end To_TGA_Image;\n\n function To_TGA_Image (Filename : String) return Image is\n\n f : File_Type;\n the_Image : Image;\n\n begin\n begin\n Open (f, In_File, Filename);\n exception\n when Name_Error => Raise_Exception (File_Not_Found'Identity, \" file name:\" & Filename);" + }, + { + "function_def": "procedure i_Load_TGA is new Load_XXX (Stream_Loader => Load_TGA);", + "function_body": "procedure Load_TGA (Name : String; Id : Integer; blending_hint : out Boolean) renames i_Load_TGA;\n\n -- BMP\n\n procedure Load_BMP (S : Ada.Streams.Stream_IO.Stream_Access; -- Input data stream\n Id : Integer; -- Id is the texture identifier to bind to\n blending_hint : out Boolean) is -- has the image blending / transparency /alpha ?\n\n imageData : Byte_Array_Ptr := null;\n stream_buf : Input_buffer;\n\n subtype Y_Loc is Natural range 0 .. 4095;\n subtype X_Loc is Natural range 0 .. 4095;\n\n -- 256 - col types\n\n subtype Color_Type is GL.Ubyte;\n\n type RGB_Color_Bytes is\n record\n Red : Color_Type;\n Green : Color_Type;\n Blue : Color_Type;\n end record;\n\n type Color_Palette is array (Color_Type) of RGB_Color_Bytes;\n\n Palette : Color_Palette;\n\n ----------------------------------------------------\n -- BMP format I/O --\n -- --\n -- Rev 1.5 10 - May - 2006 GdM : added 4 - bit support --\n -- Rev 1.4 11/02/99 RBS --\n -- --\n ----------------------------------------------------\n -- Coded by G. de Montmollin\n\n -- Code additions, changes, and corrections by Bob Sutton\n --\n -- Remarks expanded and altered\n -- Provided for scanline padding in data stream\n -- Corrected stream reading for images exceeding screen size.\n -- Provided selectable trim modes for oversize images\n -- Procedures originally Read_BMP_dimensions now Read_BMP_Header\n -- Some exceptions added\n --\n -- Rev 1.2 RBS. Added variable XY screen location for BMP\n -- Rev 1.3 RBS. Added image inversion & reversal capability\n -- Rev 1.4 RBS. Activated LOCATE centering / clipping options\n --\n -- This version presumes that the infile is a new style, 256 color bitmap.\n -- The Bitmap Information Header structure (40 bytes) is presumed\n -- instead of the pre - Windows 3.0 Bitmap Core Header Structure (12 Bytes)\n -- Pos 15 (0EH), if 28H, is valid BIH structure. If 0CH, is BCH structure.\n\n procedure Read_BMP_Header (S : Stream_Access;\n width : out X_Loc;\n height : out Y_Loc;\n image_bits : out Integer;\n offset : out U32) is\n\n fsz : U32;\n ih : U32;\n w, dummy16 : U16;\n n : U32;\n Str2 : String (1 .. 2);\n Str4 : String (1 .. 4);\n Str20 : String (1 .. 20);\n\n -- Get numbers with correct trucmuche endian, to ensure\n -- correct header loading on some non - Intel machines\n\n generic\n type Number is mod <>; -- range <> in Ada83 version (fake Interfaces)\n procedure Read_Intel_x86_number (n : out Number);\n\n procedure Read_Intel_x86_number (n : out Number) is\n b : GL.Ubyte;\n m : Number := 1;\n begin\n n := 0;\n for i in 1 .. Number'Size / 8 loop\n GL.Ubyte'Read (S, b);\n n := n + m * Number (b);\n m := m * 256;\n end loop;\n end Read_Intel_x86_number;\n\n procedure Read_Intel is new Read_Intel_x86_number (U16);\n procedure Read_Intel is new Read_Intel_x86_number (U32);\n\n begin\n -- First 14 bytes is file header structure.\n -- Pos= 1, read 2 bytes, file signature word\n String'Read (S, Str2);\n if Str2 /= \"BM\" then\n raise Not_BMP_format;\n end if;\n -- Pos= 3, read the file size\n Read_Intel (fsz);\n -- Pos= 7, read four bytes, unknown\n String'Read (S, Str4);\n -- Pos= 11, read four bytes offset, file top to bitmap data.\n -- For 256 colors, this is usually 36 04 00 00\n Read_Intel (offset);\n -- Pos= 15. The beginning of Bitmap information header.\n -- Data expected : 28H, denoting 40 byte header\n Read_Intel (ih);\n -- Pos= 19. Bitmap width, in pixels. Four bytes\n Read_Intel (n);\n width := X_Loc (n);\n -- Pos= 23. Bitmap height, in pixels. Four bytes\n Read_Intel (n);\n height := Y_Loc (n);\n -- Pos= 27, skip two bytes. Data is number of Bitmap planes.\n Read_Intel (dummy16); -- perform the skip\n -- Pos= 29, Number of bits per pixel\n -- Value 8, denoting 256 color, is expected\n Read_Intel (w);\n if w /= 8 and then w /= 4 and then w /= 1 then\n raise BMP_Unsupported_Bits_per_Pixel;\n end if;\n image_bits := Integer (w);\n -- Pos= 31, read four bytees\n Read_Intel (n); -- Type of compression used\n if n /= 0 then\n raise Unsupported_compression;\n end if;\n\n -- Pos= 35 (23H), skip twenty bytes\n String'Read (S, Str20); -- perform the skip\n\n -- Pos= 55 (36H), - start of palette\n end Read_BMP_Header;\n\n procedure Load_BMP_Palette (S : Stream_Access;\n Image_Bits : Integer;\n BMP_Palette : out Color_Palette) is\n\n dummy : GL.Ubyte;\n mc : constant Color_Type := (2**Image_Bits) - 1;\n\n begin\n for DAC in 0 .. mc loop\n GL.Ubyte'Read (S, BMP_Palette (DAC).Blue);\n GL.Ubyte'Read (S, BMP_Palette (DAC).Green);\n GL.Ubyte'Read (S, BMP_Palette (DAC).Red);\n GL.Ubyte'Read (S, dummy);\n end loop;\n end Load_BMP_Palette;\n\n -- Load image only from stream (after having read header and palette!)\n\n procedure Load_BMP_Image (S : Stream_Access;\n width : X_Loc;\n height : Y_Loc;\n Buffer : in out Byte_Array;\n BMP_bits : Integer;\n BMP_Palette : Color_Palette) is\n\n idx : Natural;\n b01, b : GL.Ubyte := 0;\n pair : Boolean := True;\n bit : Natural range 0 .. 7 := 0;\n --\n x3 : Natural; -- idx + x*3 (each pixel takes 3 bytes)\n x3_max : Natural;\n --\n procedure Fill_palettized is\n pragma Inline (Fill_palettized);\n begin\n Buffer (x3) := Ubyte (BMP_Palette (b).Red);\n Buffer (x3 + 1) := Ubyte (BMP_Palette (b).Green);\n Buffer (x3 + 2) := Ubyte (BMP_Palette (b).Blue);\n end Fill_palettized;\n --\n begin\n Attach_Stream (stream_buf, S);\n for y in 0 .. height - 1 loop\n idx := y * width * 3; -- GL destination picture is 24 bit\n x3 := idx;\n x3_max := idx + (width - 1) * 3;\n case BMP_bits is\n when 1 => -- B/W\n while x3 <= x3_max loop\n if bit = 0 then\n Get_Byte (stream_buf, b01);\n end if;\n b := (b01 and 16#80#) / 16#80#;\n Fill_palettized;\n b01 := b01 * 2; -- cannot overflow.\n if bit = 7 then\n bit := 0;\n else\n bit := bit + 1;\n end if;\n x3 := x3 + 3;\n end loop;\n when 4 => -- 16 colour image\n while x3 <= x3_max loop\n if pair then\n Get_Byte (stream_buf, b01);\n b := (b01 and 16#F0#) / 16#10#;\n else\n b := (b01 and 16#0F#);\n end if;\n pair := not pair;\n Fill_palettized;\n x3 := x3 + 3;\n end loop;\n when 8 => -- 256 colour image\n while x3 <= x3_max loop\n Get_Byte (stream_buf, b);\n Fill_palettized;\n x3 := x3 + 3;\n end loop;\n when others =>\n null;\n end case;\n end loop;\n end Load_BMP_Image;\n\n Width : X_Loc;\n Height : Y_Loc;\n offset : U32;\n BMP_bits, imagebits : Integer;\n BMP_Size : Integer;\n BMP_tex_format : GL.TexFormatEnm;\n BMP_tex_pixel_format : GL.TexPixelFormatEnm;\n\n begin\n Read_BMP_Header (S, Width, Height, BMP_bits, offset);\n imagebits := 24;\n blending_hint := False; -- no blending with BMP's\n BMP_tex_format := GL.RGB;\n BMP_tex_pixel_format := GL.RGB;\n Load_BMP_Palette (S, BMP_bits, Palette);\n\n BMP_Size := Width * Height;\n\n -- Allocation\n imageData := new Byte_Array (0 .. (imagebits / 8) * BMP_Size - 1);\n\n Load_BMP_Image\n (S, Width, Height, imageData.all,\n BMP_bits, Palette);\n\n Insert_into_GL (id => Id,\n Insert_Size => BMP_Size,\n width => Width,\n height => Height,\n texFormat => BMP_tex_format,\n texPixelFormat => BMP_tex_pixel_format,\n image_p => imageData\n );\n\n -- release our data, its been uploaded to the GL system\n Free (imageData);\n\n end Load_BMP;\n\n procedure i_Load_BMP is new Load_XXX (Stream_Loader => Load_BMP);\n\n procedure Load_BMP (Name : String; Id : Integer; blending_hint : out Boolean) renames i_Load_BMP;\n\n procedure Load (name : String; -- file name\n format : Supported_format; -- expected file format\n ID : Integer; -- ID is the texture identifier to bind to\n blending_hint : out Boolean) is -- has blending / transparency /alpha ?\n\n begin\n case format is\n when BMP => Load_BMP (name, ID, blending_hint);\n when TGA => Load_TGA (name, ID, blending_hint);\n end case;\n end Load;\n\n procedure Load (s : Ada.Streams.Stream_IO.Stream_Access; -- input data stream (e.g. Unzip.Streams)\n format : Supported_format; -- expected file format\n ID : Integer; -- ID is the texture identifier to bind to\n blending_hint : out Boolean) is -- has blending / transparency /alpha ?\n\n begin\n case format is\n when BMP => Load_BMP (s, ID, blending_hint);\n when TGA => Load_TGA (s, ID, blending_hint);\n end case;\n end Load;\n\n -------------\n -- Outputs --\n -------------\n\n generic\n type Number is mod <>;\n s : Stream_Access;\n procedure Write_Intel_x86_number (n : Number);\n\n procedure Write_Intel_x86_number (n : Number) is\n m : Number := n;\n bytes : constant Integer := Number'Size / 8;\n begin\n for i in 1 .. bytes loop\n U8'Write (s, U8 (m mod 256));\n m := m / 256;\n end loop;\n end Write_Intel_x86_number;\n\n procedure Write_raw_BGR_frame (s : Stream_Access; width, height : Natural) is\n -- 4 - byte padding for .bmp/.avi formats is the same as GL's default\n -- padding : see glPixelStore, GL_[UN]PACK_ALIGNMENT = 4 as initial value.\n -- http://www.opengl.org/sdk/docs/man/xhtml/glPixelStore.xml\n --\n padded_row_size : constant Positive :=\n 4 * Integer (C_Float'Ceiling (C_Float (width) * 3.0 / 4.0));\n -- (in bytes)\n --\n type Temp_bitmap_type is array (Natural range <>) of aliased GL.Ubyte;\n PicData : Temp_bitmap_type (0 .. (padded_row_size + 4) * (height + 4) - 1);\n -- No dynamic allocation needed!\n -- The \"+ 4\" are there to avoid parity address problems when GL writes\n -- to the buffer.\n type loc_pointer is new GL.pointer;\n function Cvt is new Ada.Unchecked_Conversion (System.Address, loc_pointer);\n -- This method is functionally identical as GNAT's Unrestricted_Access\n -- but has no type safety (cf GNAT Docs)\n pragma No_Strict_Aliasing (loc_pointer); -- recommended by GNAT 2005 +\n pPicData : loc_pointer;\n data_max : constant Integer := padded_row_size * height - 1;\n begin\n pPicData := Cvt (PicData (0)'Address);\n GL.ReadPixels (\n 0, 0,\n GL.Sizei (width), GL.Sizei (height),\n GL.BGR,\n GL.GL_UNSIGNED_BYTE,\n GL.pointer (pPicData)\n );\n if workaround_possible then\n declare\n use Ada.Streams;\n SE_Buffer : Stream_Element_Array (0 .. Stream_Element_Offset (PicData'Last));\n for SE_Buffer'Address use PicData'Address;\n pragma Import (Ada, SE_Buffer);\n begin\n Ada.Streams.Write (s.all, SE_Buffer (0 .. Stream_Element_Offset (data_max)));" + }, + { + "function_def": "function Cvt is new Ada.Unchecked_Conversion (System.Address, GL_IntPointer);", + "function_body": "-- This method is functionally identical as GNAT's Unrestricted_Access\n -- but has no type safety (cf GNAT Docs)\n pragma No_Strict_Aliasing (GL_IntPointer); -- recommended by GNAT 2005+\n\n begin\n -- Gr\u00f6\u00dfe des Viewports abfragen --> Sp\u00e4tere Bildgr\u00f6\u00dfenangaben\n GL.GetIntegerv (GL.VIEWPORT, GL.intPointer (Cvt (Screenshot_Viewport (0)'Address)));\n\n -- Initialisieren der Daten des Headers\n FileHeader.bfType := 16#4D42#; -- 'BM'\n FileHeader.bfOffBits := Bitmap_Info_Header'Size / 8 + Bitmap_File_Header'Size / 8;\n\n -- Schreiben der Bitmap - Informationen\n FileInfo.biSize := Bitmap_Info_Header'Size / 8;\n FileInfo.biWidth := I32 (Screenshot_Viewport (2));\n FileInfo.biHeight := I32 (Screenshot_Viewport (3));\n FileInfo.biPlanes := 1;\n FileInfo.biBitCount := 24;\n FileInfo.biCompression := 0;\n FileInfo.biSizeImage :=\n U32 (\n -- 4 - byte padding for .bmp/.avi formats\n 4 * Integer (C_Float'Ceiling (C_Float (FileInfo.biWidth) * 3.0 / 4.0)) *\n Integer (FileInfo.biHeight)\n );\n\n -- Gr\u00f6\u00dfenangabe auch in den Header \u00fcbernehmen\n FileHeader.bfSize := FileHeader.bfOffBits + FileInfo.biSizeImage;\n\n -- Und den ganzen M\u00fcll in die Datei schieben ; - )\n -- Moderne Leute nehmen daf\u00fcr auch Streams . ..\n Create (f, Out_File, Name);\n declare\n procedure Write_Intel is new Write_Intel_x86_number (U16, Stream (f));\n procedure Write_Intel is new Write_Intel_x86_number (U32, Stream (f));\n function Cvt is new Ada.Unchecked_Conversion (I32, U32);\n\n begin\n -- ** Only for Intel endianess : ** --\n -- BITMAPFILEHEADER'Write (Stream (F), FileHeader);\n -- BITMAPINFOHEADER'Write (Stream (F), FileInfo);\n --\n -- ** Endian - safe : ** --\n Write_Intel (FileHeader.bfType);\n Write_Intel (FileHeader.bfSize);\n Write_Intel (FileHeader.bfReserved1);\n Write_Intel (FileHeader.bfReserved2);\n Write_Intel (FileHeader.bfOffBits);\n --\n Write_Intel (FileInfo.biSize);\n Write_Intel (Cvt (FileInfo.biWidth));\n Write_Intel (Cvt (FileInfo.biHeight));\n Write_Intel (FileInfo.biPlanes);\n Write_Intel (FileInfo.biBitCount);\n Write_Intel (FileInfo.biCompression);\n Write_Intel (FileInfo.biSizeImage);\n Write_Intel (Cvt (FileInfo.biXPelsPerMeter));\n Write_Intel (Cvt (FileInfo.biYPelsPerMeter));\n Write_Intel (FileInfo.biClrUsed);\n Write_Intel (FileInfo.biClrImportant);\n --\n Write_raw_BGR_frame (Stream (f), Integer (Screenshot_Viewport (2)), Integer (Screenshot_Viewport (3)));\n Close (f);\n exception\n when others =>\n Close (f);\n raise;" + }, + { + "function_def": "procedure Normalise (the_Plane : in out Plane) is", + "function_body": "use GL_Double_EF;\n inv_Magnitude : constant GL.Double := 1.0 / Sqrt (the_Plane (0) * the_Plane (0)\n + the_Plane (1) * the_Plane (1)\n + the_Plane (2) * the_Plane (2));\n begin\n the_Plane := (0 => the_Plane (0) * inv_Magnitude,\n 1 => the_Plane (1) * inv_Magnitude,\n 2 => the_Plane (2) * inv_Magnitude,\n 3 => the_Plane (3) * inv_Magnitude);\n end Normalise;\n\n -- Bounds\n --\n\n function Max (L, R : Extent) return Extent is\n (Min => GL.Double'Max (L.Min, R.Min),\n Max => GL.Double'Max (L.Max, R.Max));\n\n function Max (L, R : Axis_Aligned_Bounding_Box) return Axis_Aligned_Bounding_Box is\n (X_Extent => Max (L.X_Extent, R.X_Extent),\n Y_Extent => Max (L.Y_Extent, R.Y_Extent),\n Z_Extent => Max (L.Z_Extent, R.Z_Extent));\n\n function Max (L, R : Bounds_record) return Bounds_record is\n (Sphere_Radius => GL.Double'Max (L.Sphere_Radius, R.Sphere_Radius),\n Box => Max (L.Box, R.Box));\n\n -- vertex_Id's\n --\n\n procedure Increment (Self : in out vertex_Id_array) is\n\n begin\n for Each in Self'Range loop\n Self (Each) := Self (Each) + 1;\n end loop;\n end Increment;\n\n procedure Decrement (Self : in out vertex_Id_array) is\n\n begin\n for Each in Self'Range loop\n Self (Each) := Self (Each) - 1;\n end loop;\n end Decrement;\n\n -- vertices\n --\n\n function Image (Self : GL_Vertex) return String is\n (\" (\" & Double'Image (Self (0)) & Double'Image (Self (1)) & Double'Image (Self (2)) & \")\");\n\n function Bounds (Self : GL_Vertex_array) return GL.Geometry.Bounds_record is\n\n use GL_Double_EF;\n the_Bounds : Bounds_record := null_Bounds;\n max_Distance_2 : GL.Double := 0.0; -- current maximum distance squared.\n\n begin\n for p in Self'Range loop\n max_Distance_2 := GL.Double'Max (Self (p) (0) * Self (p) (0)\n + Self (p) (1) * Self (p) (1)\n + Self (p) (2) * Self (p) (2),\n max_Distance_2);\n\n the_Bounds.Box := (X_Extent => (Min => GL.Double'Min (the_Bounds.Box.X_Extent.Min, Self (p) (0)),\n Max => GL.Double'Max (the_Bounds.Box.X_Extent.Max, Self (p) (0))),\n Y_Extent => (Min => GL.Double'Min (the_Bounds.Box.Y_Extent.Min, Self (p) (1)),\n Max => GL.Double'Max (the_Bounds.Box.Y_Extent.Max, Self (p) (1))),\n Z_Extent => (Min => GL.Double'Min (the_Bounds.Box.Z_Extent.Min, Self (p) (2)),\n Max => GL.Double'Max (the_Bounds.Box.Z_Extent.Max, Self (p) (2))));\n end loop;\n\n the_Bounds.Sphere_Radius := Sqrt (max_Distance_2);\n\n return the_Bounds;\n end Bounds;\n\n function Bounds (Given_Vertices : GL_Vertex_array; Given_Indices : vertex_Id_array) return GL.Geometry.Bounds_record is\n\n use GL_Double_EF;\n the_Bounds : Bounds_record := null_Bounds;\n max_Distance_2 : GL.Double := 0.0; -- current maximum distance squared.\n\n begin\n for Each in Given_Indices'Range loop\n declare\n the_Point : GL_Vertex renames Given_Vertices (Given_Indices (Each));\n begin\n max_Distance_2 := GL.Double'Max (the_Point (0) * the_Point (0)\n + the_Point (1) * the_Point (1)\n + the_Point (2) * the_Point (2),\n max_Distance_2);\n\n the_Bounds.Box := (X_Extent => (Min => GL.Double'Min (the_Bounds.Box.X_Extent.Min, the_Point (0)),\n Max => GL.Double'Max (the_Bounds.Box.X_Extent.Max, the_Point (0))),\n Y_Extent => (Min => GL.Double'Min (the_Bounds.Box.Y_Extent.Min, the_Point (1)),\n Max => GL.Double'Max (the_Bounds.Box.Y_Extent.Max, the_Point (1))),\n Z_Extent => (Min => GL.Double'Min (the_Bounds.Box.Z_Extent.Min, the_Point (2)),\n Max => GL.Double'Max (the_Bounds.Box.Z_Extent.Max, the_Point (2))));" + }, + { + "function_def": "procedure deallocate is new Ada.Unchecked_Deallocation (Geometry_t'Class, p_Geometry);", + "function_body": "begin\n destroy (Self.all);\n deallocate (Self);\n end Free;\n\n function Vertex_Normals (Self : Geometry_t'Class) return GL_Normals_Vertex_Id is\n\n begin\n case primitive_Id (Self) is\n when TRIANGLES =>\n declare\n the_Vertices : GL_Vertex_array renames Vertices (Self);\n the_Indices : vertex_Id_array renames Indices (Self);\n the_Normals : GL_Normals_Vertex_Id (the_Vertices'Range);\n\n Triangle_Face_Count : constant Positive := the_Indices'Length / 3;\n face_Normals : GL_Normals (1 .. Triangle_Face_Count);\n\n N : GL.Double_Vector_3D;\n length_N : GL.Double;\n\n function vertex_Id_for (Face : Positive; point_Id : Positive) return vertex_Id is\n (the_Indices (positive_uInt (3 * (Face - 1) + point_Id)));\n\n begin\n -- Geometry (Normal of unrotated face)\n --\n for each_Face in 1 .. Triangle_Face_Count loop\n N := (the_Vertices (vertex_Id_for (each_Face, 2)) - the_Vertices (vertex_Id_for (each_Face, 1)))\n * (the_Vertices (vertex_Id_for (each_Face, 3)) - the_Vertices (vertex_Id_for (each_Face, 1)));\n length_N := Norm (N);\n\n case Almost_zero (length_N) is\n when True => face_Normals (each_Face) := N; -- 0 vector !\n when False => face_Normals (each_Face) := (1.0 / length_N) * N;\n end case;\n end loop;\n\n -- Calculate normal at each vertex.\n --\n declare\n vertex_adjacent_faces_Count : array (the_Vertices'Range) of Natural := (others => 0);\n the_Vertex : vertex_Id;\n Vertex_Length : Double;\n begin\n\n for p in the_Vertices'Range loop\n the_Normals (p) := (0.0, 0.0, 0.0);\n end loop;\n\n for f in 1 .. Triangle_Face_Count loop\n for p in 1 .. 3 loop\n the_Vertex := vertex_Id_for (f, p);\n\n vertex_adjacent_faces_Count (the_Vertex) := vertex_adjacent_faces_Count (the_Vertex) + 1;\n the_Normals (the_Vertex) := the_Normals (the_Vertex) + face_Normals (f);\n end loop;\n end loop;\n\n for p in the_Vertices'Range loop\n\n Vertex_Length := Norm (the_Normals (p));\n\n if not Almost_zero (Vertex_Length) then\n the_Normals (p) := (1.0 / Vertex_Length) * the_Normals (p);\n else\n null; -- raise Constraint_Error; -- tbd : proper exception as usual.\n end if;\n end loop;" + }, + { + "function_def": "function vanish_point_size_Min (Self : in Culler'Class) return Real", + "function_body": "is\n begin\n return self.vanish_point_size_Min;" + }, + { + "function_def": "procedure vanish_point_size_Min_is (Self : in out Culler'Class; Now : in Real)", + "function_body": "is\n begin\n self.vanish_point_size_Min := Now;" + }, + { + "function_def": "procedure impostor_size_Min_is (Self : in out Culler'Class; Now : in Real)", + "function_body": "is\n begin\n self.impostor_size_Min := Now;" + }, + { + "function_def": "procedure frustum_culling_Enabled_is (Self : in out Culler'Class; Now : in Boolean)", + "function_body": "is\n begin\n self.frustum_culling_Enabled := Now;" + }, + { + "function_def": "function is_visible_for_plane (Which : in GL.frustums.plane_Id) return Boolean", + "function_body": "is\n the_Site : Vector_3D renames the_Object.Centre;\n plane_Distance : Real := Frustum (Which) (0) * the_Site (0)\n + Frustum (Which) (1) * the_Site (1)\n + Frustum (Which) (2) * the_Site (2)\n + Frustum (Which) (3);\n begin\n return plane_Distance + the_Size > 0.0;" + }, + { + "function_def": "--procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,", + "function_body": "procedure sort is new Ada.Containers.Generic_Array_Sort (Positive,\n impostor.p_Impostor,\n impostor.p_Impostor_array);\n begin\n sort (the_Slot.Impostors (1 .. the_Slot.impostors_Count));\n\n for Each in 1 .. num_Updates loop\n the_slot.Impostors (Each).update (self.viewer.Camera'Access, self.texture_Pool'Unchecked_Access);\n -- tbd : would 'flush' improve performance here ?\n end loop;" + }, + { + "function_def": "procedure deallocate is new ada.unchecked_Deallocation (sprite_Set, sprite_Set_view);", + "function_body": "Pad : sprite_Set_view := Self;\n begin\n destroy (Self.all);\n deallocate (Pad);" + }, + { + "function_def": "procedure Viewer_is (Self : in out Culler'Class; Now : p_Window)", + "function_body": "is\n begin\n self.Viewer := Now.all'Access;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E385 := E385 - 1;\n E389 := E389 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"vehicle_interface__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"swarm_control__finalize_spec\");\n begin\n F2;" + }, + { + "function_def": "procedure F3;", + "function_body": "pragma Import (Ada, F3, \"swarm_data__finalize_spec\");\n begin\n E376 := E376 - 1;\n F3;" + }, + { + "function_def": "procedure F4;", + "function_body": "pragma Import (Ada, F4, \"swarm_structures__finalize_spec\");\n begin\n F4;" + }, + { + "function_def": "procedure F5;", + "function_body": "pragma Import (Ada, F5, \"vehicle_task_type__finalize_spec\");\n begin\n F5;" + }, + { + "function_def": "procedure F6;", + "function_body": "pragma Import (Ada, F6, \"swarm_structures_base__finalize_spec\");\n begin\n E365 := E365 - 1;\n F6;" + }, + { + "function_def": "procedure F7;", + "function_body": "pragma Import (Ada, F7, \"graphics_structures__finalize_spec\");\n begin\n E305 := E305 - 1;\n F7;" + }, + { + "function_def": "procedure F8;", + "function_body": "pragma Import (Ada, F8, \"glut__windows__finalize_spec\");\n begin\n F8;" + }, + { + "function_def": "procedure F9;", + "function_body": "pragma Import (Ada, F9, \"globe_3d__textures__finalize_body\");\n begin\n E256 := E256 - 1;\n F9;" + }, + { + "function_def": "procedure F10;", + "function_body": "pragma Import (Ada, F10, \"globe_3d__finalize_spec\");\n begin\n F10;" + }, + { + "function_def": "procedure F11;", + "function_body": "pragma Import (Ada, F11, \"unzip__streams__finalize_spec\");\n begin\n F11;" + }, + { + "function_def": "procedure F12;", + "function_body": "pragma Import (Ada, F12, \"zip_streams__finalize_spec\");\n begin\n F12;" + }, + { + "function_def": "procedure F13;", + "function_body": "pragma Import (Ada, F13, \"glut__finalize_body\");\n begin\n E297 := E297 - 1;\n F13;" + }, + { + "function_def": "procedure F14;", + "function_body": "pragma Import (Ada, F14, \"gl__skins__finalize_spec\");\n begin\n F14;" + }, + { + "function_def": "procedure F15;", + "function_body": "pragma Import (Ada, F15, \"gl__textures__finalize_spec\");\n begin\n F15;" + }, + { + "function_def": "procedure F16;", + "function_body": "pragma Import (Ada, F16, \"gl__geometry__finalize_spec\");\n begin\n F16;" + }, + { + "function_def": "procedure F17;", + "function_body": "pragma Import (Ada, F17, \"gl__buffer__finalize_spec\");\n begin\n F17;" + }, + { + "function_def": "procedure F18;", + "function_body": "pragma Import (Ada, F18, \"barrier_type__finalize_spec\");\n begin\n F18;" + }, + { + "function_def": "procedure F19;", + "function_body": "pragma Import (Ada, F19, \"system__tasking__protected_objects__entries__finalize_spec\");\n begin\n F19;" + }, + { + "function_def": "procedure F20;", + "function_body": "pragma Import (Ada, F20, \"system__pool_global__finalize_spec\");\n begin\n F20;" + }, + { + "function_def": "procedure F21;", + "function_body": "pragma Import (Ada, F21, \"ada__strings__unbounded__finalize_spec\");\n begin\n F21;" + }, + { + "function_def": "procedure F22;", + "function_body": "pragma Import (Ada, F22, \"ada__text_io__finalize_spec\");\n begin\n F22;" + }, + { + "function_def": "procedure F23;", + "function_body": "pragma Import (Ada, F23, \"system__storage_pools__subpools__finalize_spec\");\n begin\n F23;" + }, + { + "function_def": "procedure F24;", + "function_body": "pragma Import (Ada, F24, \"system__finalization_masters__finalize_spec\");\n begin\n F24;" + }, + { + "function_def": "procedure F25;", + "function_body": "pragma Import (Ada, F25, \"ada__streams__stream_io__finalize_spec\");\n begin\n F25;" + }, + { + "function_def": "procedure F26;", + "function_body": "pragma Import (Ada, F26, \"system__file_io__finalize_body\");\n begin\n E135 := E135 - 1;\n F26;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (C, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Exception_Tracebacks : Integer;\n pragma Import (C, Exception_Tracebacks, \"__gl_exception_tracebacks\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Leap_Seconds_Support : Integer;\n pragma Import (C, Leap_Seconds_Support, \"__gl_leap_seconds_support\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n System.Restrictions.Run_Time_Restrictions :=\n (Set =>\n (False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False, False, True, False, False, \n False, False, False, False, False, False, False, False, \n False, False, False, False),\n Value => (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n Violated =>\n (True, True, False, False, True, True, False, False, \n True, False, False, True, True, True, True, False, \n False, False, True, False, True, True, False, True, \n True, False, True, True, True, True, False, True, \n True, False, False, True, False, True, True, False, \n True, True, True, True, False, True, True, True, \n True, False, False, True, False, True, True, False, \n True, False, False, True, True, True, True, True, \n False, False, True, False, True, True, True, False, \n True, True, False, True, True, True, True, False, \n True, True, False, False, False, True, True, True, \n True, True, True, False),\n Count => (0, 0, 0, 1, 2, 1, 3, 2, 7, 0),\n Unknown => (False, False, False, False, False, False, True, True, True, False));\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Exception_Tracebacks := 1;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n Leap_Seconds_Support := 0;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E023 := E023 + 1;\n System.Exceptions'Elab_Spec;\n E025 := E025 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E019 := E019 + 1;\n E011 := E011 + 1;\n Ada.Containers'Elab_Spec;\n E172 := E172 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E127 := E127 + 1;\n Ada.Numerics'Elab_Spec;\n E144 := E144 + 1;\n Ada.Strings'Elab_Spec;\n E166 := E166 + 1;\n Interfaces.C'Elab_Spec;\n E061 := E061 + 1;\n Interfaces.C.Strings'Elab_Spec;\n E159 := E159 + 1;\n System.Os_Lib'Elab_Body;\n E137 := E137 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E091 := E091 + 1;\n Ada.Streams'Elab_Spec;\n E126 := E126 + 1;\n System.File_Control_Block'Elab_Spec;\n E140 := E140 + 1;\n System.Finalization_Root'Elab_Spec;\n E129 := E129 + 1;\n Ada.Finalization'Elab_Spec;\n E124 := E124 + 1;\n System.File_Io'Elab_Body;\n E135 := E135 + 1;\n Ada.Streams.Stream_Io'Elab_Spec;\n E244 := E244 + 1;\n System.Storage_Pools'Elab_Spec;\n E191 := E191 + 1;\n System.Finalization_Masters'Elab_Spec;\n System.Finalization_Masters'Elab_Body;\n E195 := E195 + 1;\n System.Storage_Pools.Subpools'Elab_Spec;\n E193 := E193 + 1;\n Ada.Calendar'Elab_Spec;\n Ada.Calendar'Elab_Body;\n E279 := E279 + 1;\n Ada.Calendar.Delays'Elab_Body;\n E304 := E304 + 1;\n Ada.Real_Time'Elab_Spec;\n Ada.Real_Time'Elab_Body;\n E054 := E054 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E131 := E131 + 1;\n System.Assertions'Elab_Spec;\n E150 := E150 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E168 := E168 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E171 := E171 + 1;\n Ada.Strings.Unbounded'Elab_Spec;\n E211 := E211 + 1;\n System.Interrupt_Management.Operations'Elab_Body;\n E393 := E393 + 1;\n System.Pool_Global'Elab_Spec;\n E187 := E187 + 1;\n System.Random_Seed'Elab_Body;\n E338 := E338 + 1;\n System.Tasking.Initialization'Elab_Body;\n E109 := E109 + 1;\n System.Tasking.Protected_Objects'Elab_Body;\n E119 := E119 + 1;\n System.Tasking.Protected_Objects.Entries'Elab_Spec;\n E121 := E121 + 1;\n System.Tasking.Queuing'Elab_Body;\n E117 := E117 + 1;\n System.Tasking.Stages'Elab_Body;\n E387 := E387 + 1;\n System.Tasking.Async_Delays'Elab_Body;\n E391 := E391 + 1;\n Barrier_Type'Elab_Spec;\n E380 := E380 + 1;\n E269 := E269 + 1;\n E103 := E103 + 1;\n E367 := E367 + 1;\n E156 := E156 + 1;\n GL.BUFFER'ELAB_SPEC;\n E201 := E201 + 1;\n GL.IO'ELAB_SPEC;\n GL.IO'ELAB_BODY;\n E240 := E240 + 1;\n E248 := E248 + 1;\n GL.MATH'ELAB_BODY;\n E219 := E219 + 1;\n GL.GEOMETRY'ELAB_SPEC;\n E209 := E209 + 1;\n E291 := E291 + 1;\n E180 := E180 + 1;\n GL.ERRORS'ELAB_SPEC;\n E178 := E178 + 1;\n GL.TEXTURES'ELAB_SPEC;\n GL.TEXTURES'ELAB_BODY;\n E238 := E238 + 1;\n GL.BUFFER.TEXTURE_COORDS'ELAB_SPEC;\n GL.BUFFER.TEXTURE_COORDS'ELAB_BODY;\n E205 := E205 + 1;\n GL.SKINS'ELAB_SPEC;\n GL.SKINS'ELAB_BODY;\n E184 := E184 + 1;\n E293 := E293 + 1;\n GLUT'ELAB_BODY;\n E297 := E297 + 1;\n E295 := E295 + 1;\n E142 := E142 + 1;\n Graphics_Framerates'Elab_Body;\n E302 := E302 + 1;\n E309 := E309 + 1;\n Quaternions'Elab_Body;\n E311 := E311 + 1;\n E360 := E360 + 1;\n Vectors_2d'Elab_Spec;\n E398 := E398 + 1;\n Vectors_3d'Elab_Spec;\n E313 := E313 + 1;\n Rotations'Elab_Body;\n E307 := E307 + 1;\n Vectors_3d_Lf'Elab_Spec;\n E395 := E395 + 1;\n Vectors_4d'Elab_Spec;\n E330 := E330 + 1;\n Vectors_2d_I'Elab_Spec;\n E399 := E399 + 1;\n Vectors_2d_N'Elab_Spec;\n E320 := E320 + 1;\n Vectors_2d_P'Elab_Spec;\n E400 := E400 + 1;\n E397 := E397 + 1;\n Zip_Streams'Elab_Spec;\n Zip'Elab_Spec;\n Zip_Streams'Elab_Body;\n E277 := E277 + 1;\n Zip.Headers'Elab_Spec;\n E275 := E275 + 1;\n Zip'Elab_Body;\n E273 := E273 + 1;\n E281 := E281 + 1;\n Unzip'Elab_Spec;\n Unzip.Decompress.Huffman'Elab_Spec;\n E271 := E271 + 1;\n Unzip'Elab_Body;\n E265 := E265 + 1;\n E267 := E267 + 1;\n Unzip.Streams'Elab_Spec;\n Unzip.Streams'Elab_Body;\n E283 := E283 + 1;\n GLOBE_3D'ELAB_SPEC;\n GLOBE_3D.TEXTURES'ELAB_SPEC;\n E252 := E252 + 1;\n GLOBE_3D.MATH'ELAB_BODY;\n E250 := E250 + 1;\n GLOBE_3D.TEXTURES'ELAB_BODY;\n E256 := E256 + 1;\n GLOBE_3D'ELAB_BODY;\n E161 := E161 + 1;\n E254 := E254 + 1;\n E356 := E356 + 1;\n GLUT.DEVICES'ELAB_SPEC;\n Game_Control'Elab_Spec;\n E354 := E354 + 1;\n Actors'Elab_Body;\n E352 := E352 + 1;\n GLUT.WINDOWS'ELAB_SPEC;\n GLUT.WINDOWS'ELAB_BODY;\n E350 := E350 + 1;\n E348 := E348 + 1;\n Graphics_Structures'Elab_Spec;\n E305 := E305 + 1;\n Graphics_Configuration'Elab_Spec;\n E154 := E154 + 1;\n E358 := E358 + 1;\n E327 := E327 + 1;\n E329 := E329 + 1;\n Models'Elab_Spec;\n Models'Elab_Body;\n E325 := E325 + 1;\n Graphics_Data'Elab_Spec;\n E323 := E323 + 1;\n E344 := E344 + 1;\n Graphics_Opengl'Elab_Body;\n E332 := E332 + 1;\n Swarm_Structures_Base'Elab_Spec;\n E365 := E365 + 1;\n Swarm_Configurations'Elab_Spec;\n E364 := E364 + 1;\n Swarm_Configuration'Elab_Spec;\n E362 := E362 + 1;\n Vehicle_Task_Type'Elab_Spec;\n Swarm_Structures'Elab_Spec;\n E378 := E378 + 1;\n Swarm_Data'Elab_Spec;\n E376 := E376 + 1;\n Swarm_Control'Elab_Spec;\n E375 := E375 + 1;\n Vehicle_Interface'Elab_Spec;\n E389 := E389 + 1;\n Vehicle_Task_Type'Elab_Body;\n E385 := E385 + 1;\n E402 := E402 + 1;\n Callback_Procedures'Elab_Body;\n E052 := E052 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_swarm\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n gnat_argc := argc;\n gnat_argv := argv;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure Global_Registry_Handler", + "function_body": "(Registry : in out WP.Client.Registry'Class;\n Id : Unsigned_32;\n Name : String;\n Version : Unsigned_32) is\n begin\n Interfaces.Append ((Name => +Name, Id => Id, Version => Version));\n\n if Name = WP.Client.Compositor_Interface.Name then\n Compositor.Bind (Registry, Id, Unsigned_32'Min (Version, 4));\n elsif Name = WP.Client.Shm_Interface.Name then\n Shm.Bind (Registry, Id, Unsigned_32'Min (Version, 1));\n\n if not Shm.Has_Proxy then\n raise Wayland_Error with \"No shm\";\n end if;\n\n Shm_Events.Subscribe (Shm);\n elsif Name = WP.Client.Seat_Interface.Name then\n declare\n Seat : WP.Client.Seat renames Seats (Seat_Last_Index + 1).Seat;\n begin\n Seat.Bind (Registry, Id, Unsigned_32'Min (Version, 6));\n\n if not Seat.Has_Proxy then\n raise Wayland_Error with \"No seat\";\n end if;\n\n Seat_Events.Subscribe (Seat);\n\n Seat_Last_Index := Seat_Last_Index + 1;" + }, + { + "function_def": "procedure Wayland_Ada_Scanner is", + "function_body": "use type Ada.Containers.Count_Type;\n use type Wayland_XML.Event_Child;\n use type Wayland_XML.Request_Child;\n\n use all type Wayland_XML.Arg_Tag;\n use all type Wayland_XML.Copyright_Tag;\n use all type Wayland_XML.Description_Tag;\n use all type Wayland_XML.Entry_Tag;\n use all type Wayland_XML.Enum_Tag;\n use all type Wayland_XML.Event_Tag;\n use all type Wayland_XML.Request_Tag;\n use all type Wayland_XML.Interface_Tag;\n use all type Wayland_XML.Protocol_Tag;\n\n use all type Aida.Deepend.XML_DOM_Parser.Node_Kind_Id;\n use all type Aida.Deepend.XML_DOM_Parser.Attribute;\n use all type Aida.Deepend.XML_DOM_Parser.XML_Tag;\n use all type Wayland_XML.Protocol_Child_Kind_Id;\n use all type Wayland_XML.Interface_Child_Kind_Id;\n use all type Wayland_XML.Event_Child_Kind_Id;\n use all type Wayland_XML.Arg_Type_Attribute;\n use all type Wayland_XML.Request_Child_Kind_Id;\n use all type Wayland_XML.Enum_Child;\n\n package SF renames Ada.Strings.Fixed;\n package SU renames Ada.Strings.Unbounded;\n\n package Unbounded_String_Vectors is new Ada.Containers.Vectors\n (Index_Type => Positive,\n Element_Type => SU.Unbounded_String,\n \"=\" => SU.\"=\");\n\n function Trim (Value : String) return String is (SF.Trim (Value, Ada.Strings.Both));\n\n function Is_Reserved_Keyword (Name : String) return Boolean is\n (Name in \"Begin\" | \"End\");\n\n procedure Put\n (File : Ada.Text_IO.File_Type;\n Item : String) renames Ada.Text_IO.Put;\n\n procedure Put_Line\n (File : Ada.Text_IO.File_Type;\n Item : String) renames Ada.Text_IO.Put_Line;\n\n procedure Put_Line\n (Item : String) renames Ada.Text_IO.Put_Line;\n\n procedure New_Line\n (File : Ada.Text_IO.File_Type;\n Spacing : Ada.Text_IO.Positive_Count := 1) renames Ada.Text_IO.New_Line;\n\n function \"+\" (Value : String) return SU.Unbounded_String renames SU.To_Unbounded_String;\n function \"+\" (Value : SU.Unbounded_String) return String renames SU.To_String;\n\n XML_Exception : exception;\n\n procedure Create_Wayland_Spec_File (Enable_Comments : Boolean);\n procedure Create_Wayland_Body_File;\n\n Protocol_Tag : Wayland_XML.Protocol_Tag_Ptr;\n\n function Is_Deprecated (Interface_Tag : Wayland_XML.Interface_Tag) return Boolean is\n (Name (Interface_Tag) in \"wl_shell\" | \"wl_shell_surface\");\n -- wl_shell[_surface] are deprecated and replaced by the xdg-shell protocol\n\n function Get_Protocol_Name (Name : String) return String is\n (if Name = \"wayland\" then \"client\" else Name);\n\n package String_Maps is new Ada.Containers.Indefinite_Hashed_Maps\n (Key_Type => String,\n Element_Type => String,\n Hash => Ada.Strings.Hash,\n Equivalent_Keys => \"=\");\n\n procedure Generate_Code_For_Arg\n (File : Ada.Text_IO.File_Type;\n Interface_Tag : Wayland_XML.Interface_Tag;\n Arg_Tag : Wayland_XML.Arg_Tag;\n Max_Length : Natural;\n Is_Last : Boolean;\n Enum_Types : in out String_Maps.Map)\n is\n function Get_Enum_Type_Name return String is\n Result : String := Enum (Arg_Tag);\n begin\n case SF.Count (Result, \".\") is\n when 0 =>\n return Name (Interface_Tag) & \"_\" & Result;\n when 1 =>\n Result (SF.Index (Result, \".\")) := '_';\n return Result;\n when others =>\n raise XML_Exception;\n end case;\n end Get_Enum_Type_Name;\n\n Arg_Name : constant String\n := Xml_Parser_Utils.Adaify_Variable_Name (Name (Arg_Tag));\n Arg_Type : constant String :=\n Xml_Parser_Utils.Arg_Type_As_String (Arg_Tag);\n\n Arg_Type_Name : constant String :=\n (if Exists_Enum (Arg_Tag) then\n Xml_Parser_Utils.Adaify_Name (Get_Enum_Type_Name)\n else\n Arg_Type);\n\n Arg_Name_Aligned : constant String := SF.Head (Arg_Name, Max_Length, ' ');\n begin\n if Arg_Type_Name /= Arg_Type then\n Enum_Types.Include (Arg_Type_Name, Arg_Type);\n end if;\n\n if Is_Last then\n Put (File, \" \" & Arg_Name_Aligned & \" : \" & Arg_Type_Name & \")\");\n else\n Put_Line (File, \" \" & Arg_Name_Aligned & \" : \" & Arg_Type_Name & \";\");\n end if;\n end Generate_Code_For_Arg;\n\n type Parameter is record\n Name, Ada_Type : SU.Unbounded_String;\n end record;\n\n type Parameter_Array is array (Positive range <>) of Parameter;\n\n type Subprogram_Kind is (Declaration, Implementation);\n\n Max_Line_Length : constant := 99;\n Generate_Interfaces_For_Client : constant Boolean := True;\n Unused_Padding_Name : constant String := \"Unused\";\n\n procedure Generate_Pretty_Code_For_Subprogram\n (File : Ada.Text_IO.File_Type;\n Kind : Subprogram_Kind;\n Interface_Tag : aliased Wayland_XML.Interface_Tag;\n Procedure_Name : String;\n Return_Type : String;\n Parameters : Parameter_Array := (1 .. 0 => <>))\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag));\n Ptr_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Ptr\");\n\n Subprogram_Kind : constant String := (if Return_Type'Length > 0 then \"function\" else \"procedure\");\n Return_String : constant String := (if Return_Type'Length > 0 then \" return \" & Return_Type else \"\");\n\n Max_Name_Length : Natural := Name'Length;\n\n function Align (Value : String) return String is (SF.Head (Value, Max_Name_Length, ' '));\n\n Last_Char : constant String := (if Kind = Declaration then \";\" else \" is\");\n One_Line : Boolean;\n begin\n for Parameter of Parameters loop\n Max_Name_Length := Natural'Max (Max_Name_Length, SU.Length (Parameter.Name));\n end loop;\n\n declare\n Line_Length : Natural := Subprogram_Kind'Length + 8 + 2 * Name'Length + Procedure_Name'Length + Ptr_Name'Length + Return_String'Length + Last_Char'Length + 2 * Parameters'Length;\n begin\n for Parameter of Parameters loop\n Line_Length := Line_Length + SU.Length (Parameter.Name) + SU.Length (Parameter.Ada_Type) + 3;\n end loop;\n\n One_Line := Parameters'Length = 0 and Line_Length <= Max_Line_Length;" + }, + { + "function_def": "procedure Identify_Protocol_Tag;", + "function_body": "procedure Identify_Protocol_Children;\n\n procedure Allocate_Space_For_Wayland_XML_Contents\n (File_Name : String;\n File_Contents : out Aida.Deepend.String_Ptr)\n is\n package IO renames Ada.Streams.Stream_IO;\n\n Size : constant Natural := Natural (Ada.Directories.Size (File_Name));\n File : IO.File_Type;\n\n subtype File_String is String (1 .. Size);\n begin\n IO.Open (File, IO.In_File, File_Name);\n\n File_Contents := new File_String;\n File_String'Read (IO.Stream (File), File_Contents.all);\n\n IO.Close (File);\n end Allocate_Space_For_Wayland_XML_Contents;\n\n Root_Node : Aida.Deepend.XML_DOM_Parser.Node_Ptr;\n\n procedure Parse_Contents (File_Contents : Aida.Deepend.String_Ptr) is\n Call_Result : Aida.Call_Result;\n begin\n Aida.Deepend.XML_DOM_Parser.Parse\n (File_Contents.all, Call_Result, Root_Node);\n\n if Call_Result.Has_Failed then\n raise XML_Exception with Call_Result.Message;\n else\n Identify_Protocol_Tag;\n Identify_Protocol_Children;\n end if;\n end Parse_Contents;\n\n procedure Identify_Protocol_Tag is\n begin\n if Root_Node.Id /= Node_Kind_Tag or else Name (Root_Node.Tag) /= \"protocol\" then\n raise XML_Exception with \"Root node is not \";\n end if;\n\n if\n Attributes (Root_Node.Tag).Length /= 1 or else\n Name (Attributes (Root_Node.Tag) (1).all) /= \"name\"\n then\n raise XML_Exception with \" node has no name attribute\";\n end if;\n\n Protocol_Tag := new Wayland_XML.Protocol_Tag;\n Set_Name (Protocol_Tag.all, Value (Attributes (Root_Node.Tag) (1).all));\n end Identify_Protocol_Tag;\n\n procedure Identify_Protocol_Children is\n function Identify_Copyright\n (Node : not null Aida.Deepend.XML_DOM_Parser.Node_Ptr)\n return not null Wayland_XML.Copyright_Ptr\n is\n Copyright_Tag : constant not null Wayland_XML.Copyright_Ptr\n := new Wayland_XML.Copyright_Tag;\n begin\n if Child_Nodes (Node.Tag).Length = 1 then\n if Child_Nodes (Node.Tag) (1).Id = Node_Kind_Text then\n Set_Text\n (Copyright_Tag.all,\n Trim (Child_Nodes (Node.Tag) (1).Text.all));\n else\n raise XML_Exception;\n end if;\n else\n raise XML_Exception;\n end if;\n return Copyright_Tag;\n end Identify_Copyright;\n\n function Identify_Description\n (Node : not null Aida.Deepend.XML_DOM_Parser.Node_Ptr)\n return not null Wayland_XML.Description_Tag_Ptr\n is\n Description_Tag : constant not null Wayland_XML.Description_Tag_Ptr\n := new Wayland_XML.Description_Tag;\n\n Text : SU.Unbounded_String;\n begin\n if Attributes (Node.Tag).Length = 1 and then\n Name (Attributes (Node.Tag) (1).all) = \"summary\"\n then\n Set_Summary (Description_Tag.all, Value (Attributes (Node.Tag) (1).all));\n else\n raise XML_Exception with \"Expected tag 'description' to have 1 attribute 'summary'\";\n end if;\n\n for Child of Child_Nodes (Node.Tag) loop\n if Child.Id = Node_Kind_Text then\n SU.Append (Text, Trim (Child.Text.all));\n elsif Child.Id /= Node_Kind_Comment then\n raise XML_Exception with\n \"Tag 'description' has unexpected child \" & Child.Id'Image;\n end if;\n end loop;\n Set_Text (Description_Tag.all, +Text);\n\n return Description_Tag;\n end Identify_Description;\n\n function Identify_Arg\n (Node : not null Aida.Deepend.XML_DOM_Parser.Node_Ptr)\n return not null Wayland_XML.Arg_Tag_Ptr\n is\n Arg_Tag : constant not null Wayland_XML.Arg_Tag_Ptr\n := new Wayland_XML.Arg_Tag;\n\n procedure Iterate\n (Tag : aliased Aida.Deepend.XML_DOM_Parser.XML_Tag) is\n begin\n for A of Attributes (Tag) loop\n if Name (A.all) = \"name\" then\n Set_Name (Arg_Tag.all, Value (A.all));\n elsif Name (A.all) = \"type\" then\n Set_Type_Attribute (Arg_Tag.all, Value (A.all));\n elsif Name (A.all) = \"summary\" then\n Set_Summary (Arg_Tag.all, Value (A.all));\n elsif Name (A.all) = \"interface\" then\n Set_Interface_Attribute (Arg_Tag.all, Value (A.all));\n elsif Name (A.all) = \"allow-null\" then\n if Value (A.all) = \"true\" then\n Set_Allow_Null (Arg_Tag.all, True);\n elsif Value (A.all) = \"false\" then\n Set_Allow_Null (Arg_Tag.all, False);\n else\n raise XML_Exception with\n \"Attribute 'allow-null' must be 'true' or 'false'\";\n end if;\n elsif Name (A.all) = \"enum\" then\n Set_Enum (Arg_Tag.all, Value (A.all));\n else\n raise XML_Exception;\n end if;\n end loop;\n end Iterate;\n begin\n Iterate (Node.Tag);\n\n return Arg_Tag;\n end Identify_Arg;\n\n function Identify_Request\n (Node : not null Aida.Deepend.XML_DOM_Parser.Node_Ptr)\n return not null Wayland_XML.Request_Tag_Ptr\n is\n Request_Tag : constant not null Wayland_XML.Request_Tag_Ptr\n := new Wayland_XML.Request_Tag;\n\n procedure Iterate\n (Tag : aliased Aida.Deepend.XML_DOM_Parser.XML_Tag) is\n begin\n for A of Attributes (Tag) loop\n if Name (A.all) = \"name\" then\n Set_Name (Request_Tag.all, Value (A.all));\n elsif Name (A.all) = \"type\" then\n Set_Type_Attribute (Request_Tag.all, Value (A.all));\n elsif Name (A.all) = \"since\" then\n declare\n V : Integer;\n Has_Failed : Boolean;\n begin\n Aida.To_Integer (Value (A.all), V, Has_Failed);\n\n if Has_Failed then\n raise XML_Exception;\n else\n Set_Since\n (Request_Tag.all,\n Wayland_XML.Version_Number (V));\n end if;" + }, + { + "function_def": "procedure Generate_Code_For_Opcodes is", + "function_body": "I : Integer := 0;\n\n procedure Generate_Code\n (Request_Tag : aliased Wayland_XML.Request_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_\" &\n Wayland_XML.Name (Request_Tag));\n begin\n if I = 0 then\n New_Line (File);\n end if;\n Put_Line (File, \" \" & Name & \" : constant := \" & Aida.To_String (I) & \";\");\n\n I := I + 1;\n end Generate_Code;\n begin\n Iterate_Over_Requests (Interface_Tag, Generate_Code'Access);\n end Generate_Code_For_Opcodes;\n\n begin\n Generate_Code_For_Opcodes;\n -- Note: See git history for *_Since_Version constants\n end Handle_Interface;\n begin\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Code_For_Numeric_Constants;\n\n All_Types : Unbounded_String_Vectors.Vector;\n\n procedure Create_Wayland_Spec_File (Enable_Comments : Boolean) is\n File : Ada.Text_IO.File_Type;\n\n procedure Create_Wl_Thin_Spec_File (Protocol_Name : String);\n\n procedure Generate_Code_For_Type_Declarations;\n procedure Generate_Code_For_External_Proxies (Protocol_Name : String);\n procedure Generate_Code_For_The_Interface_Constants;\n procedure Generate_Code_For_Enum_Constants;\n procedure Generate_Private_Code_For_Enum_Constants;\n procedure Generate_Manually_Edited_Partial_Type_Declarations (Protocol_Name : String);\n procedure Generate_Use_Type_Declarions (Package_Name : String);\n procedure Generate_Manually_Edited_Code_For_Type_Definitions;\n procedure Generate_Private_Code_For_The_Interface_Constants;\n\n procedure Create_File is\n Protocol_Name : constant String := Get_Protocol_Name (Name (Protocol_Tag.all));\n Package_Name : constant String := Xml_Parser_Utils.Adaify_Name (Protocol_Name);\n\n Has_Enums : constant Boolean :=\n Protocol_Name in\n \"client\" |\n \"pointer_constraints_unstable_v1\" |\n \"presentation_time\" |\n \"xdg_decoration_unstable_v1\" |\n \"xdg_shell\";\n begin\n Ada.Text_IO.Create\n (File, Ada.Text_IO.Out_File,\n \"wayland-protocols-\" & Protocol_Name & \".ads\");\n\n Put_Line (File, \"private with Wayland.Protocols.Thin_\" & Package_Name & \";\");\n if Has_Enums then\n New_Line (File);\n Put_Line (File, \"with Wayland.Enums.\" & Package_Name & \";\");\n end if;\n\n if Protocol_Name = \"client\" then\n null;\n elsif Protocol_Name = \"xdg_decoration_unstable_v1\" then\n New_Line (File);\n Put_Line (File, \"with Wayland.Protocols.Client;\");\n Put_Line (File, \"with Wayland.Protocols.Xdg_Shell;\");\n else\n New_Line (File);\n Put_Line (File, \"with Wayland.Protocols.Client;\");\n end if;\n\n New_Line (File);\n Put_Line (File, \"package Wayland.Protocols.\" & Package_Name & \" is\");\n Put_Line (File, \" pragma Preelaborate;\");\n\n if Has_Enums then\n New_Line (File);\n Put_Line (File, \" use Wayland.Enums.\" & Package_Name & \";\");\n end if;\n\n if Protocol_Name = \"xdg_shell\" then\n New_Line (File);\n Put_Line (File, \" type State_Array is array (Positive range <>) of Xdg_Toplevel_State;\");\n Put_Line (File, \" type Capability_Array is array (Positive range <>) of Xdg_Toplevel_Wm_Capabilities;\");\n end if;\n\n Generate_Code_For_Type_Declarations;\n Generate_Code_For_External_Proxies (Protocol_Name);\n Generate_Code_For_The_Interface_Constants;\n\n if Generate_Interfaces_For_Client or Protocol_Name /= \"client\" then\n New_Line (File);\n Put_Line (File, \" procedure Initialize;\");\n end if;\n\n if Protocol_Name = \"client\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Bind\");\n Put_Line (File, \" (Object : Registry;\");\n Put_Line (File, \" Iface : Interface_Type;\");\n Put_Line (File, \" Id : Unsigned_32;\");\n Put_Line (File, \" Version : Unsigned_32) return Secret_Proxy;\");\n end if;\n\n Generate_Manually_Edited_Partial_Type_Declarations (Protocol_Name);\n\n New_Line (File);\n Put_Line (File, \"private\");\n New_Line (File);\n\n Generate_Use_Type_Declarions (Package_Name);\n Generate_Manually_Edited_Code_For_Type_Definitions;\n\n if Protocol_Name = \"client\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Get_Proxy (Object : Surface) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n Put_Line (File, \" function Get_Proxy (Object : Seat) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n Put_Line (File, \" function Get_Proxy (Object : Shm) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n Put_Line (File, \" function Get_Proxy (Object : Output) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n Put_Line (File, \" function Get_Proxy (Object : Pointer) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n Put_Line (File, \" function Get_Proxy (Object : Region) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n elsif Protocol_Name = \"xdg_shell\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Get_Proxy (Object : Xdg_Toplevel) return Secret_Proxy is (Secret_Proxy (Object.Proxy));\");\n end if;\n\n Generate_Private_Code_For_The_Interface_Constants;\n\n Put_Line (File, \"\");\n Put_Line (File, \"end Wayland.Protocols.\" & Package_Name & \";\");\n\n Ada.Text_IO.Close (File);\n\n -----------------------------------------------------------------------\n\n -- TODO Do not generate file if there are no enum constants\n Ada.Text_IO.Create\n (File, Ada.Text_IO.Out_File,\n \"wayland-enums-\" & Protocol_Name & \".ads\");\n\n Put_Line (File, \"package Wayland.Enums.\" & Package_Name & \" is\");\n Put_Line (File, \" pragma Preelaborate;\");\n\n Generate_Code_For_Enum_Constants;\n\n New_Line (File);\n Put_Line (File, \"private\");\n New_Line (File);\n\n Generate_Private_Code_For_Enum_Constants;\n\n Put_Line (File, \"end Wayland.Enums.\" & Package_Name & \";\");\n\n Ada.Text_IO.Close (File);\n\n Ada.Text_IO.Create\n (File, Ada.Text_IO.Out_File,\n \"wayland-protocols-thin_\" & Protocol_Name & \".ads\");\n\n Put_Line (File, \"with Interfaces.C.Strings;\");\n Put_Line (File, \"\");\n Put_Line (File, \"with Wayland.API;\");\n if Has_Enums then\n Put_Line (File, \"with Wayland.Enums.\" & Package_Name & \";\");\n end if;\n\n if Protocol_Name = \"client\" then\n null;\n elsif Protocol_Name = \"xdg_decoration_unstable_v1\" then\n Put_Line (File, \"with Wayland.Protocols.Thin_Xdg_Shell;\");\n else\n Put_Line (File, \"with Wayland.Protocols.Thin_Client;\");\n end if;\n Put_Line (File, \"\");\n Put_Line (File, \"private package Wayland.Protocols.Thin_\" & Package_Name & \" is\");\n Put_Line (File, \" pragma Preelaborate;\");\n\n if Has_Enums then\n Put_Line (File, \"\");\n Put_Line (File, \" use Wayland.Enums.\" & Package_Name & \";\");\n end if;\n\n Put_Line (File, \"\");\n Put_Line (File, \" subtype chars_ptr is Interfaces.C.Strings.chars_ptr;\");\n Put_Line (File, \"\");\n\n Put_Line (File, \" subtype Interface_T is Wayland.API.Interface_T;\");\n Put_Line (File, \"\");\n Put_Line (File, \" subtype Proxy_Ptr is Wayland.API.Proxy_Ptr;\");\n Put_Line (File, \" subtype Interface_Ptr is Wayland.API.Interface_Ptr;\");\n Put_Line (File, \"\");\n\n Create_Wl_Thin_Spec_File (Protocol_Name);\n\n Put_Line (File, \"end Wayland.Protocols.Thin_\" & Package_Name & \";\");\n\n Ada.Text_IO.Close (File);\n end Create_File;\n\n procedure Generate_Code_For_Type_Declarations is\n procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n Put_Line (File, \" type \" & Name & \" is tagged limited private;\");\n end Handle_Interface;\n begin\n New_Line (File);\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Code_For_Type_Declarations;\n\n procedure Generate_Code_For_External_Proxies (Protocol_Name : String) is\n begin\n if Protocol_Name = \"client\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Get_Proxy (Object : Surface) return Secret_Proxy;\");\n Put_Line (File, \" function Get_Proxy (Object : Seat) return Secret_Proxy;\");\n Put_Line (File, \" function Get_Proxy (Object : Shm) return Secret_Proxy;\");\n Put_Line (File, \" function Get_Proxy (Object : Output) return Secret_Proxy;\");\n Put_Line (File, \" function Get_Proxy (Object : Pointer) return Secret_Proxy;\");\n Put_Line (File, \" function Get_Proxy (Object : Region) return Secret_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" package Constructors is\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Buffer;\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Output;\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Surface;\");\n Put_Line (File, \" end Constructors;\");\n elsif Protocol_Name = \"xdg_shell\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Get_Proxy (Object : Xdg_Toplevel) return Secret_Proxy;\");\n end if;\n end Generate_Code_For_External_Proxies;\n\n procedure Generate_Code_For_The_Interface_Constants is\n procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Interface\");\n begin\n Put_Line (File, \" \" & Name & \" : constant Interface_Type;\");\n end Handle_Interface;\n begin\n New_Line (File);\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Code_For_The_Interface_Constants;\n\n function Get_Name (Entry_Tag : Wayland_XML.Entry_Tag) return String is\n -- Just because some entries in wl_output.transform start with a digit :/\n Entry_Name : constant String := Name (Entry_Tag);\n begin\n return\n (if Entry_Name in \"90\" | \"180\" | \"270\" then\n \"Rotate_\" & Entry_Name\n else\n Xml_Parser_Utils.Adaify_Name (Entry_Name));\n end Get_Name;\n\n function Get_Max_Child_Length (Enum_Tag : aliased Wayland_XML.Enum_Tag) return Natural is\n Result : Natural := 0;\n begin\n for Child of Wayland_XML.Entries (Enum_Tag) loop\n Result := Natural'Max (Result, Get_Name (Child.Entry_Tag.all)'Length);\n end loop;\n\n return Result;\n end Get_Max_Child_Length;\n\n procedure Generate_Code_For_Enum_Constants is\n procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n procedure Generate_Code (Enum_Tag : aliased Wayland_XML.Enum_Tag) is\n Enum_Type_Name : constant String := Xml_Parser_Utils.Adaify_Name\n (Name (Interface_Tag) & \"_\" & Name (Enum_Tag));\n\n Is_Bitfield : constant Boolean :=\n Exists_Bitfield (Enum_Tag) and then Bitfield (Enum_Tag);\n\n Max_Length : constant Natural :=\n Natural'Max (Get_Max_Child_Length (Enum_Tag), Unused_Padding_Name'Length);\n\n procedure Generate_Summary_For_Entry\n (Entry_Tag : Wayland_XML.Entry_Tag)\n is\n Summary_String : constant String :=\n (if Enable_Comments and Exists_Summary (Entry_Tag) then\n Summary (Entry_Tag)\n else \"\");\n begin\n if Summary_String'Length > 0 then\n Put_Line (File, \" -- \" & Summary_String);\n end if;\n end Generate_Summary_For_Entry;\n\n Count_components : Natural := 0;\n\n procedure Generate_Code_For_Entry_Component\n (Entry_Tag : Wayland_XML.Entry_Tag)\n is\n Aligned_Name : constant String :=\n SF.Head (Get_Name (Entry_Tag), Max_Length, ' ');\n\n Value : constant Natural := Natural'Value (Value_As_String (Entry_Tag));\n begin\n -- Ignore entry with value 0 because then all components of\n -- the record are False\n if Value = 0 then\n return;\n end if;\n\n Count_components := Count_components + 1;\n\n Put_Line (File, \" \" & Aligned_Name & \" : Boolean := False;\");\n Generate_Summary_For_Entry (Entry_Tag);\n end Generate_Code_For_Entry_Component;\n\n procedure Generate_Code_For_Entry\n (Entry_Tag : Wayland_XML.Entry_Tag;\n Is_First : Boolean;\n Is_Last : Boolean)\n is\n Aligned_Name : constant String := Get_Name (Entry_Tag);\n\n Prefix : constant String := (if Is_First then \"\" else \" \");\n Suffix : constant String := (if Is_Last then \");\" else \",\");\n begin\n Put_Line (File, Prefix & Aligned_Name & Suffix);\n Generate_Summary_For_Entry (Entry_Tag);\n end Generate_Code_For_Entry;\n begin\n New_Line (File);\n if Is_Bitfield then\n Put_Line (File, \" type \" & Enum_Type_Name & \" is record\");\n for Child of Wayland_XML.Entries (Enum_Tag) loop\n Generate_Code_For_Entry_Component (Child.Entry_Tag.all);\n end loop;\n if Count_components < 32 then\n declare\n Aligned_Name : constant String :=\n SF.Head (Unused_Padding_Name, Max_Length, ' ');\n begin\n Put_Line (File, \" \" & Aligned_Name & \" : Unused_Type;\");" + }, + { + "function_def": "procedure Generate_Private_Code_For_Enum_Constants is", + "function_body": "procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n procedure Generate_Code (Enum_Tag : aliased Wayland_XML.Enum_Tag) is\n Enum_Type_Name : constant String := Xml_Parser_Utils.Adaify_Name\n (Name (Interface_Tag) & \"_\" & Name (Enum_Tag));\n\n Is_Bitfield : constant Boolean :=\n Exists_Bitfield (Enum_Tag) and then Bitfield (Enum_Tag);\n\n Max_Length : constant Natural :=\n Natural'Max (Get_Max_Child_Length (Enum_Tag), Unused_Padding_Name'Length);\n\n Count_Components : Natural := 0;\n\n procedure Generate_Code_For_Entry_Component\n (Entry_Tag : Wayland_XML.Entry_Tag)\n is\n Aligned_Name : constant String :=\n SF.Head (Get_Name (Entry_Tag), Max_Length, ' ');\n\n type U32 is mod 2 ** 32\n with Size => 32;\n\n Value : constant U32 := U32'Value (Value_As_String (Entry_Tag));\n begin\n -- Ignore entry with value 0 because then all components of\n -- the record are False\n if Value = 0 then\n return;\n end if;\n\n if (Value and (Value - 1)) /= 0 then\n raise Constraint_Error with Value'Image & \" is not a power of two\";\n end if;\n\n Count_Components := Count_Components + 1;\n\n declare\n Bit : Natural := 0;\n begin\n while Value > 2 ** Bit loop\n Bit := Bit + 1;\n end loop;\n\n Put_Line (File, \" \" & Aligned_Name &\n \" at 0 range \" & Trim (Bit'Image) & \" .. \" & Trim (Bit'Image) & \";\");" + }, + { + "function_def": "procedure Generate_Prefix_Spec_Events is", + "function_body": "begin\n Put_Line (File, \"\");\n Put_Line (File, \" generic\");\n end Generate_Prefix_Spec_Events;\n\n procedure Generate_Suffix_Spec_Events (Name : String) is\n begin\n Put_Line (File, \" package \" & Name & \"_Events is\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Subscribe\");\n Put_Line (File, \" (Object : aliased in out \" & Name & \"'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" end \" & Name & \"_Events;\");\n end Generate_Suffix_Spec_Events;\n\n procedure Handle_Interface_Subprograms_Client\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Compositor\" | \"Seat\" | \"Shm\" | \"Output\" | \"Data_Device_Manager\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Display\" then\n Put_Line (File, \"\");\n Put_Line (File, \" function Is_Connected (Object : Display) return Boolean renames Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Connect (Object : in out Display)\");\n Put_Line (File, \" with Pre => not Object.Is_Connected;\");\n Put_Line (File, \" -- Attempts connecting with the Wayland server\");\n Put_Line (File, \"\");\n Put_Line (File, \" type Events_Status is (Has_Events, No_Events, Error);\");\n Put_Line (File, \"\");\n Put_Line (File, \" type Events_Status_Array is array (Positive range <>) of Events_Status;\");\n Put_Line (File, \"\");\n Put_Line (File, \" type File_Descriptor_Array is array (Positive range <>) of File_Descriptor;\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Check_For_Events\");\n Put_Line (File, \" (Object : Display;\");\n Put_Line (File, \" Timeout : Duration;\");\n Put_Line (File, \" Descriptors : File_Descriptor_Array := (1 .. 0 => 0)) return Events_Status_Array\");\n Put_Line (File, \" with Post => Check_For_Events'Result'Length = Descriptors'Length + 1;\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Flush (Object : Display) return Optional_Result\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Send all buffered requests to the Wayland compositor\");\n Put_Line (File, \" --\");\n Put_Line (File, \" -- Returns the number of bytes sent if successful.\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Flush (Object : Display)\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Send all buffered requests to the Wayland compositor\");\n Put_Line (File, \" --\");\n Put_Line (File, \" -- Raises Program_Error if flushing failed.\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Dispatch (Object : Display) return Optional_Result\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Process incoming events\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Dispatch (Object : Display)\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Process incoming events\");\n Put_Line (File, \" --\");\n Put_Line (File, \" -- Raises Program_Error if dispatching failed.\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Dispatch_Pending (Object : Display) return Optional_Result\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Dispatch events on the default queue without reading from\");\n Put_Line (File, \" -- the display's file descriptor\");\n Put_Line (File, \" --\");\n Put_Line (File, \" -- It does not attempt to read the display's file descriptor and simply\");\n Put_Line (File, \" -- returns zero if the main queue is empty, i.e., it does not block.\");\n Put_Line (File, \" --\");\n Put_Line (File, \" -- Returns the number of dispatched events if successful.\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Prepare_Read (Object : Display) return Call_Result_Code\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Prepare to read events from the display's file descriptor\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Read_Events (Object : Display) return Call_Result_Code\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Cancel_Read (Object : Display)\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \" -- Cancel read intention on display's file descriptor\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Roundtrip (Object : Display) return Integer\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Roundtrip (Object : Display)\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Disconnect (Object : in out Display)\");\n Put_Line (File, \" with Pre => Object.Is_Connected,\");\n Put_Line (File, \" Post => not Object.Is_Connected;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Registry\");\n Put_Line (File, \" (Object : Display;\");\n Put_Line (File, \" Registry : in out Client.Registry'Class)\");\n Put_Line (File, \" with Pre => Object.Is_Connected and not Registry.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Sync (Object : Display) return Callback'Class\");\n Put_Line (File, \" with Pre => Object.Is_Connected;\");\n elsif Name = \"Compositor\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Surface (Object : Compositor;\");\n Put_Line (File, \" Surface : in out Client.Surface'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Region (Object : Compositor;\");\n Put_Line (File, \" Region : in out Client.Region'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Seat\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Pointer (Object : Seat;\");\n Put_Line (File, \" Pointer : in out Client.Pointer'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and not Pointer.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Keyboard (Object : Seat;\");\n Put_Line (File, \" Keyboard : in out Client.Keyboard'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and not Keyboard.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Touch (Object : Seat;\");\n Put_Line (File, \" Touch : in out Client.Touch'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and not Touch.Has_Proxy;\");\n elsif Name = \"Shm_Pool\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Buffer (Object : Shm_Pool;\");\n Put_Line (File, \" Offset : Natural;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural;\");\n Put_Line (File, \" Stride : Natural;\");\n Put_Line (File, \" Format : Shm_Format;\");\n Put_Line (File, \" Buffer : in out Client.Buffer'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Resize (Object : Shm_Pool;\");\n Put_Line (File, \" Size : Positive)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Shm\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Pool (Object : Shm;\");\n Put_Line (File, \" File_Descriptor : Wayland.File_Descriptor;\");\n Put_Line (File, \" Size : Positive;\");\n Put_Line (File, \" Pool : in out Shm_Pool'Class);\");\n elsif Name = \"Data_Offer\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Do_Accept (Object : Data_Offer;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Mime_Type : String)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Do_Not_Accept (Object : Data_Offer;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Receive (Object : Data_Offer;\");\n Put_Line (File, \" Mime_Type : String;\");\n Put_Line (File, \" File_Descriptor : Wayland.File_Descriptor)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Finish (Object : Data_Offer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Actions (Object : Data_Offer;\");\n Put_Line (File, \" Dnd_Actions : Data_Device_Manager_Dnd_Action;\");\n Put_Line (File, \" Preferred_Action : Data_Device_Manager_Dnd_Action)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Data_Source\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Offer (Object : Data_Source;\");\n Put_Line (File, \" Mime_Type : String)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Actions (Object : Data_Source;\");\n Put_Line (File, \" Dnd_Actions : Data_Device_Manager_Dnd_Action)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Data_Device\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Start_Drag (Object : Data_Device;\");\n Put_Line (File, \" Source : Data_Source'Class;\");\n Put_Line (File, \" Origin : Surface'Class;\");\n Put_Line (File, \" Icon : Surface'Class;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Source.Has_Proxy and Origin.Has_Proxy and Icon.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Selection (Object : Data_Device;\");\n Put_Line (File, \" Source : Data_Source'Class;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Source.Has_Proxy;\");\n elsif Name = \"Data_Device_Manager\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Data_Source (Object : Data_Device_Manager;\");\n Put_Line (File, \" Source : in out Data_Source'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Data_Device (Object : Data_Device_Manager;\");\n Put_Line (File, \" Seat : Client.Seat'Class;\");\n Put_Line (File, \" Device : in out Data_Device'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Seat.Has_Proxy;\");\n elsif Name = \"Surface\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Attach (Object : Surface;\");\n Put_Line (File, \" Buffer : Client.Buffer'Class;\");\n Put_Line (File, \" X, Y : Integer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Damage (Object : Surface;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Frame (Object : Surface; Subject : in out Callback'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and not Subject.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Opaque_Region (Object : Surface;\");\n Put_Line (File, \" Region : Client.Region'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Input_Region (Object : Surface;\");\n Put_Line (File, \" Region : Client.Region'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Commit (Object : Surface)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Buffer_Transform (Object : Surface;\");\n Put_Line (File, \" Transform : Output_Transform)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Buffer_Scale (Object : Surface;\");\n Put_Line (File, \" Scale : Positive)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Damage_Buffer (Object : Surface;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Pointer\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Cursor (Object : Pointer;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Hotspot_X : Integer;\");\n Put_Line (File, \" Hotspot_Y : Integer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Region\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Add (Object : Region;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Subtract (Object : Region;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Subcompositor\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Subsurface (Object : Subcompositor;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Parent : Client.Surface'Class;\");\n Put_Line (File, \" Subsurface : in out Client.Subsurface'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy and Parent.Has_Proxy;\");\n elsif Name = \"Subsurface\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Position (Object : Subsurface; X, Y : Integer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Place_Above (Object : Subsurface;\");\n Put_Line (File, \" Sibling : Surface'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Sibling.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Place_Below (Object : Subsurface;\");\n Put_Line (File, \" Sibling : Surface'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Sibling.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Sync (Object : Subsurface)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Desync (Object : Subsurface)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n end if;\n end Handle_Interface_Subprograms_Client;\n\n procedure Handle_Interface_Events_Client\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Display\" then\n Put_Line (File, \" with procedure Error\");\n Put_Line (File, \" (Display : in out Client.Display'Class;\");\n Put_Line (File, \" Code : Unsigned_32;\");\n Put_Line (File, \" Message : String) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Delete_Id\");\n Put_Line (File, \" (Display : in out Client.Display'Class;\");\n Put_Line (File, \" Id : Unsigned_32) is null;\");\n elsif Name = \"Registry\" then\n Put_Line (File, \" with procedure Global_Object_Added\");\n Put_Line (File, \" (Registry : in out Client.Registry'Class;\");\n Put_Line (File, \" Id : Unsigned_32;\");\n Put_Line (File, \" Name : String;\");\n Put_Line (File, \" Version : Unsigned_32);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Global_Object_Removed\");\n Put_Line (File, \" (Registry : in out Client.Registry'Class;\");\n Put_Line (File, \" Id : Unsigned_32) is null;\");\n elsif Name = \"Callback\" then\n Put_Line (File, \" with procedure Done\");\n Put_Line (File, \" (Callback : in out Client.Callback'Class;\");\n Put_Line (File, \" Callback_Data : Unsigned_32);\");\n elsif Name = \"Shm\" then\n Put_Line (File, \" with procedure Format\");\n Put_Line (File, \" (Shm : in out Client.Shm'Class;\");\n Put_Line (File, \" Format : Shm_Format);\");\n elsif Name = \"Buffer\" then\n Put_Line (File, \" with procedure Release\");\n Put_Line (File, \" (Buffer : in out Client.Buffer'Class);\");\n elsif Name = \"Data_Offer\" then\n Put_Line (File, \" with procedure Offer\");\n Put_Line (File, \" (Data_Offer : in out Client.Data_Offer'Class;\");\n Put_Line (File, \" Mime_Type : String) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Source_Actions\");\n Put_Line (File, \" (Data_Offer : in out Client.Data_Offer'Class;\");\n Put_Line (File, \" Source_Actions : Data_Device_Manager_Dnd_Action) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Action\");\n Put_Line (File, \" (Data_Offer : in out Client.Data_Offer'Class;\");\n Put_Line (File, \" Dnd_Action : Data_Device_Manager_Dnd_Action) is null;\");\n elsif Name = \"Data_Source\" then\n Put_Line (File, \" with procedure Target\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class;\");\n Put_Line (File, \" Mime_Type : String) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Send\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class;\");\n Put_Line (File, \" Mime_Type : String;\");\n Put_Line (File, \" Fd : File_Descriptor) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Cancelled\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Performed\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Finished\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Action\");\n Put_Line (File, \" (Data_Source : in out Client.Data_Source'Class;\");\n Put_Line (File, \" Dnd_Action : Data_Device_Manager_Dnd_Action) is null;\");\n elsif Name = \"Data_Device\" then\n Put_Line (File, \" with procedure Data_Offer\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class;\");\n Put_Line (File, \" Data_Offer : in out Client.Data_Offer) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Enter\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" X, Y : Fixed;\");\n Put_Line (File, \" Data_Offer : in out Client.Data_Offer) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Leave\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Motion\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" X, Y : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Drop\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Selection\");\n Put_Line (File, \" (Data_Device : in out Client.Data_Device'Class;\");\n Put_Line (File, \" Data_Offer : in out Client.Data_Offer) is null;\");\n elsif Name = \"Surface\" then\n Put_Line (File, \" with procedure Enter\");\n Put_Line (File, \" (Surface : in out Client.Surface'Class;\");\n Put_Line (File, \" Output : Client.Output) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Leave\");\n Put_Line (File, \" (Surface : in out Client.Surface'Class;\");\n Put_Line (File, \" Output : Client.Output) is null;\");\n elsif Name = \"Seat\" then\n Put_Line (File, \" with procedure Seat_Capabilities\");\n Put_Line (File, \" (Seat : in out Client.Seat'Class;\");\n Put_Line (File, \" Capabilities : Seat_Capability) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Seat_Name\");\n Put_Line (File, \" (Seat : in out Client.Seat'Class;\");\n Put_Line (File, \" Name : String) is null;\");\n elsif Name = \"Pointer\" then\n Put_Line (File, \" with procedure Pointer_Enter\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Surface_X : Fixed;\");\n Put_Line (File, \" Surface_Y : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Leave\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Motion\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Surface_X : Fixed;\");\n Put_Line (File, \" Surface_Y : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Button\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Button : Unsigned_32;\");\n Put_Line (File, \" State : Pointer_Button_State) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Scroll\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Axis : Pointer_Axis;\");\n Put_Line (File, \" Value : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Frame\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Scroll_Source\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Axis_Source : Pointer_Axis_Source) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Scroll_Stop\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Axis : Pointer_Axis) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Scroll_Discrete\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Axis : Pointer_Axis;\");\n Put_Line (File, \" Discrete : Integer) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Pointer_Scroll_Value120\");\n Put_Line (File, \" (Pointer : in out Client.Pointer'Class;\");\n Put_Line (File, \" Axis : Pointer_Axis;\");\n Put_Line (File, \" Value120 : Integer) is null;\");\n elsif Name = \"Keyboard\" then\n Put_Line (File, \" with procedure Keymap\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Format : Keyboard_Keymap_Format;\");\n Put_Line (File, \" Fd : File_Descriptor;\");\n Put_Line (File, \" Size : Unsigned_32) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Enter\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Keys : Unsigned_32_Array) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Leave\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Key\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Key : Unsigned_32;\");\n Put_Line (File, \" State : Keyboard_Key_State) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Modifiers\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Mods_Depressed : Unsigned_32;\");\n Put_Line (File, \" Mods_Latched : Unsigned_32;\");\n Put_Line (File, \" Mods_Locked : Unsigned_32;\");\n Put_Line (File, \" Group : Unsigned_32) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Repeat_Info\");\n Put_Line (File, \" (Keyboard : in out Client.Keyboard'Class;\");\n Put_Line (File, \" Rate : Integer;\");\n Put_Line (File, \" Delay_V : Integer) is null;\");\n elsif Name = \"Touch\" then\n Put_Line (File, \" with procedure Down\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Id : Integer;\");\n Put_Line (File, \" X, Y : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Up\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Id : Integer) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Motion\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class;\");\n Put_Line (File, \" Time : Unsigned_32;\");\n Put_Line (File, \" Id : Integer;\");\n Put_Line (File, \" X, Y : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Frame\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Cancel\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Shape\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class;\");\n Put_Line (File, \" Id : Integer;\");\n Put_Line (File, \" Major : Fixed;\");\n Put_Line (File, \" Minor : Fixed) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Orientation\");\n Put_Line (File, \" (Touch : in out Client.Touch'Class;\");\n Put_Line (File, \" Id : Integer;\");\n Put_Line (File, \" Orientation : Fixed) is null;\");\n elsif Name = \"Output\" then\n Put_Line (File, \" with procedure Geometry\");\n Put_Line (File, \" (Output : in out Client.Output'Class;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Physical_Width : Integer;\");\n Put_Line (File, \" Physical_Height : Integer;\");\n Put_Line (File, \" Subpixel : Output_Subpixel;\");\n Put_Line (File, \" Make : String;\");\n Put_Line (File, \" Model : String;\");\n Put_Line (File, \" Transform : Output_Transform) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Mode\");\n Put_Line (File, \" (Output : in out Client.Output'Class;\");\n Put_Line (File, \" Flags : Output_Mode;\");\n Put_Line (File, \" Width : Integer;\");\n Put_Line (File, \" Height : Integer;\");\n Put_Line (File, \" Refresh : Integer) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Done\");\n Put_Line (File, \" (Output : in out Client.Output'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Scale\");\n Put_Line (File, \" (Output : in out Client.Output'Class;\");\n Put_Line (File, \" Factor : Integer) is null;\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Client;\n\n procedure Handle_Interface_Subprograms_Xdg_Shell\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Xdg_Wm_Base\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Xdg_Wm_Base\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Pong (Object : Xdg_Wm_Base; Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Positioner\");\n Put_Line (File, \" (Object : Xdg_Wm_Base;\");\n Put_Line (File, \" Positioner : in out Xdg_Shell.Xdg_Positioner'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Surface\");\n Put_Line (File, \" (Object : Xdg_Wm_Base;\");\n Put_Line (File, \" Window : Protocols.Client.Surface'Class;\");\n Put_Line (File, \" Surface : in out Xdg_Shell.Xdg_Surface'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Window.Has_Proxy;\");\n elsif Name = \"Xdg_Positioner\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Size\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Anchor_Rect\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Anchor\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Anchor : Xdg_Positioner_Anchor)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Gravity\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Gravity : Xdg_Positioner_Gravity)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Constraint_Adjustment\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Adjustment : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Offset\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" X, Y : Integer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Reactive (Object : Xdg_Positioner)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Parent_Size\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Parent_Configure\");\n Put_Line (File, \" (Object : Xdg_Positioner;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Xdg_Surface\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Toplevel\");\n Put_Line (File, \" (Object : Xdg_Surface;\");\n Put_Line (File, \" Toplevel : in out Xdg_Shell.Xdg_Toplevel'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Popup\");\n Put_Line (File, \" (Object : Xdg_Surface;\");\n Put_Line (File, \" Parent : Xdg_Surface'Class;\");\n Put_Line (File, \" Positioner : Xdg_Shell.Xdg_Positioner'Class;\");\n Put_Line (File, \" Popup : in out Xdg_Shell.Xdg_Popup'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Window_Geometry\");\n Put_Line (File, \" (Object : Xdg_Surface;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Ack_Configure\");\n Put_Line (File, \" (Object : Xdg_Surface;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n elsif Name = \"Xdg_Toplevel\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Parent\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Parent : Xdg_Toplevel'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Parent.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Title (Object : Xdg_Toplevel; Value : String)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_App_Id (Object : Xdg_Toplevel; Value : String)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Show_Window_Menu\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Seat : Protocols.Client.Seat'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" X, Y : Integer)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Move\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Seat : Protocols.Client.Seat'Class;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Resize\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Seat : Protocols.Client.Seat'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Edges : Xdg_Toplevel_Resize_Edge)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Min_Size\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Max_Size\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Minimize (Object : Xdg_Toplevel)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Maximized (Object : Xdg_Toplevel; Enable : Boolean)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Fullscreen\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Enable : Boolean)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Fullscreen\");\n Put_Line (File, \" (Object : Xdg_Toplevel;\");\n Put_Line (File, \" Enable : Boolean;\");\n Put_Line (File, \" Output : Protocols.Client.Output'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Output.Has_Proxy;\");\n elsif Name = \"Xdg_Popup\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Grab\");\n Put_Line (File, \" (Object : Xdg_Popup;\");\n Put_Line (File, \" Seat : Protocols.Client.Seat'Class;\");\n Put_Line (File, \" Serial : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Seat.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Reposition\");\n Put_Line (File, \" (Object : Xdg_Popup;\");\n Put_Line (File, \" Positioner : Xdg_Shell.Xdg_Positioner'Class;\");\n Put_Line (File, \" Token : Unsigned_32)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Positioner.Has_Proxy;\");\n end if;\n end Handle_Interface_Subprograms_Xdg_Shell;\n\n procedure Handle_Interface_Events_Xdg_Shell\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Xdg_Wm_Base\" then\n Put_Line (File, \" with procedure Ping\");\n Put_Line (File, \" (Xdg_Wm_Base : in out Xdg_Shell.Xdg_Wm_Base'Class;\");\n Put_Line (File, \" Serial : Unsigned_32);\");\n elsif Name = \"Xdg_Surface\" then\n Put_Line (File, \" with procedure Configure\");\n Put_Line (File, \" (Xdg_Surface : in out Xdg_Shell.Xdg_Surface'Class;\");\n Put_Line (File, \" Serial : Unsigned_32);\");\n elsif Name = \"Xdg_Toplevel\" then\n Put_Line (File, \" with procedure Configure\");\n Put_Line (File, \" (Xdg_Toplevel : in out Xdg_Shell.Xdg_Toplevel'Class;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural;\");\n Put_Line (File, \" States : State_Array);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Close\");\n Put_Line (File, \" (Xdg_Toplevel : in out Xdg_Shell.Xdg_Toplevel'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Configure_Bounds\");\n Put_Line (File, \" (Xdg_Toplevel : in out Xdg_Shell.Xdg_Toplevel'Class;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Capabilities\");\n Put_Line (File, \" (Xdg_Toplevel : in out Xdg_Shell.Xdg_Toplevel'Class;\");\n Put_Line (File, \" Capabilities : Capability_Array);\");\n elsif Name = \"Xdg_Popup\" then\n Put_Line (File, \" with procedure Configure\");\n Put_Line (File, \" (Xdg_Popup : in out Xdg_Shell.Xdg_Popup'Class;\");\n Put_Line (File, \" X, Y : Integer;\");\n Put_Line (File, \" Width : Natural;\");\n Put_Line (File, \" Height : Natural);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Popup_Done\");\n Put_Line (File, \" (Xdg_Popup : in out Xdg_Shell.Xdg_Popup'Class) is null;\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Repositioned\");\n Put_Line (File, \" (Xdg_Popup : in out Xdg_Shell.Xdg_Popup'Class;\");\n Put_Line (File, \" Token : Unsigned_32) is null;\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Xdg_Shell;\n\n procedure Handle_Interface_Subprograms_Presentation_Time\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Presentation\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Presentation\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Feedback\");\n Put_Line (File, \" (Object : Presentation;\");\n Put_Line (File, \" Surface : Protocols.Client.Surface'Class;\");\n Put_Line (File, \" Feedback : in out Presentation_Feedback'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy;\");\n end if;\n end Handle_Interface_Subprograms_Presentation_Time;\n\n procedure Handle_Interface_Events_Presentation_Time\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Presentation\" then\n Put_Line (File, \" with procedure Clock\");\n Put_Line (File, \" (Presentation : in out Presentation_Time.Presentation'Class;\");\n Put_Line (File, \" Id : Unsigned_32);\");\n elsif Name = \"Presentation_Feedback\" then\n Put_Line (File, \" with procedure Synchronized_Output\");\n Put_Line (File, \" (Presentation_Feedback : in out Presentation_Time.Presentation_Feedback'Class;\");\n Put_Line (File, \" Output : Protocols.Client.Output'Class);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Presented\");\n Put_Line (File, \" (Presentation_Feedback : in out Presentation_Time.Presentation_Feedback'Class;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Refresh : Duration;\");\n Put_Line (File, \" Counter : Unsigned_64;\");\n Put_Line (File, \" Flags : Presentation_Feedback_Kind);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Discarded\");\n Put_Line (File, \" (Presentation_Feedback : in out Presentation_Time.Presentation_Feedback'Class);\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Presentation_Time;\n\n procedure Handle_Interface_Subprograms_Viewporter\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Viewporter\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Viewporter\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Viewport\");\n Put_Line (File, \" (Object : Viewporter;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Viewport : in out Protocols.Viewporter.Viewport'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy;\");\n elsif Name = \"Viewport\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Source\");\n Put_Line (File, \" (Object : Viewport;\");\n Put_Line (File, \" X, Y, Width, Height : Fixed)\");\n Put_Line (File, \" with Pre => (X = -1.0 and Y = -1.0 and Width = -1.0 and Height = -1.0)\");\n Put_Line (File, \" or (Width > 0.0 and Height > 0.0 and X >= 0.0 and Y >= 0.0);\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Destination\");\n Put_Line (File, \" (Object : Viewport;\");\n Put_Line (File, \" Width, Height : Integer)\");\n Put_Line (File, \" with Pre => (Width = -1 and Height = -1) or (Width > 0 and Height > 0);\");\n end if;\n end Handle_Interface_Subprograms_Viewporter;\n\n procedure Handle_Interface_Subprogram_Idle_Inhibit\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Idle_Inhibit_Manager_V1\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Idle_Inhibit_Manager_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Create_Inhibitor\");\n Put_Line (File, \" (Object : Idle_Inhibit_Manager_V1;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Inhibitor : in out Idle_Inhibitor_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy;\");\n elsif Name = \"Idle_Inhibitor_V1\" then\n null;\n end if;\n end Handle_Interface_Subprogram_Idle_Inhibit;\n\n procedure Handle_Interface_Subprogram_Xdg_Decoration\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Decoration_Manager_V1\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Decoration_Manager_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Toplevel_Decoration\");\n Put_Line (File, \" (Object : Decoration_Manager_V1;\");\n Put_Line (File, \" Toplevel : Xdg_Shell.Xdg_Toplevel'Class;\");\n Put_Line (File, \" Decoration : in out Toplevel_Decoration_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Toplevel.Has_Proxy;\");\n elsif Name = \"Toplevel_Decoration_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Mode\");\n Put_Line (File, \" (Object : Toplevel_Decoration_V1;\");\n Put_Line (File, \" Mode : Toplevel_Decoration_V1_Mode)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Unset_Mode (Object : Toplevel_Decoration_V1)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n end if;\n end Handle_Interface_Subprogram_Xdg_Decoration;\n\n procedure Handle_Interface_Events_Xdg_Decoration\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Toplevel_Decoration_V1\" then\n Put_Line (File, \" with procedure Configure\");\n Put_Line (File, \" (Decoration : in out Toplevel_Decoration_V1'Class;\");\n Put_Line (File, \" Mode : Toplevel_Decoration_V1_Mode);\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Xdg_Decoration;\n\n procedure Handle_Interface_Subprogram_Relative_Pointer\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Relative_Pointer_Manager_V1\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Relative_Pointer_Manager_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_Relative_Pointer\");\n Put_Line (File, \" (Object : Relative_Pointer_Manager_V1;\");\n Put_Line (File, \" Pointer : Client.Pointer'Class;\");\n Put_Line (File, \" Relative : in out Relative_Pointer_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Pointer.Has_Proxy;\");\n elsif Name = \"Relative_Pointer_V1\" then\n null;\n end if;\n end Handle_Interface_Subprogram_Relative_Pointer;\n\n procedure Handle_Interface_Events_Relative_Pointer\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Relative_Pointer_V1\" then\n Put_Line (File, \" with procedure Relative_Motion\");\n Put_Line (File, \" (Pointer : in out Relative_Pointer_V1'Class;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Dx : Fixed;\");\n Put_Line (File, \" Dy : Fixed;\");\n Put_Line (File, \" Dx_Unaccel : Fixed;\");\n Put_Line (File, \" Dy_Unaccel : Fixed);\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Relative_Pointer;\n\n procedure Handle_Interface_Subprogram_Pointer_Constraints\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Pointer_Constraints_V1\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name = \"Pointer_Constraints_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Lock_Pointer\");\n Put_Line (File, \" (Object : Pointer_Constraints_V1;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Pointer : Client.Pointer'Class;\");\n Put_Line (File, \" Region : Client.Region'Class;\");\n Put_Line (File, \" Lifetime : Pointer_Constraints_V1_Lifetime;\");\n Put_Line (File, \" Locked : in out Locked_Pointer_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy and Pointer.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Confine_Pointer\");\n Put_Line (File, \" (Object : Pointer_Constraints_V1;\");\n Put_Line (File, \" Surface : Client.Surface'Class;\");\n Put_Line (File, \" Pointer : Client.Pointer'Class;\");\n Put_Line (File, \" Region : Client.Region'Class;\");\n Put_Line (File, \" Lifetime : Pointer_Constraints_V1_Lifetime;\");\n Put_Line (File, \" Confined : in out Confined_Pointer_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Surface.Has_Proxy and Pointer.Has_Proxy;\");\n elsif Name = \"Locked_Pointer_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Cursor_Position_Hint\");\n Put_Line (File, \" (Object : Locked_Pointer_V1;\");\n Put_Line (File, \" X, Y : Fixed)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Region\");\n Put_Line (File, \" (Object : Locked_Pointer_V1;\");\n Put_Line (File, \" Region : Client.Region'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Region.Has_Proxy;\");\n elsif Name = \"Confined_Pointer_V1\" then\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Set_Region\");\n Put_Line (File, \" (Object : Confined_Pointer_V1;\");\n Put_Line (File, \" Region : Client.Region'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Region.Has_Proxy;\");\n end if;\n end Handle_Interface_Subprogram_Pointer_Constraints;\n\n procedure Handle_Interface_Events_Pointer_Constraints\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Locked_Pointer_V1\" then\n Put_Line (File, \" with procedure Locked\");\n Put_Line (File, \" (Pointer : in out Locked_Pointer_V1'Class);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Unlocked\");\n Put_Line (File, \" (Pointer : in out Locked_Pointer_V1'Class);\");\n elsif Name = \"Confined_Pointer_V1\" then\n Put_Line (File, \" with procedure Confined\");\n Put_Line (File, \" (Pointer : in out Confined_Pointer_V1'Class);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Unconfined\");\n Put_Line (File, \" (Pointer : in out Confined_Pointer_V1'Class);\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Pointer_Constraints;\n\n procedure Handle_Interface_Subprogram_Pointer_Gestures\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n procedure Print_Constructor (Name : String) is\n begin\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Get_\" & Name & \"_Gesture\");\n Put_Line (File, \" (Object : Pointer_Gestures_V1;\");\n Put_Line (File, \" Pointer : Client.Pointer'Class;\");\n Put_Line (File, \" Gesture : in out Pointer_Gesture_\" & Name & \"_V1'Class)\");\n Put_Line (File, \" with Pre => Object.Has_Proxy and Pointer.Has_Proxy;\");\n end Print_Constructor;\n\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Name in \"Pointer_Gestures_V1\" then\n Generate_Spec_Bind_Subprogram (Name);\n end if;\n\n if Name in \"Pointer_Gestures_V1\" then\n Print_Constructor (\"Swipe\");\n Print_Constructor (\"Pinch\");\n Print_Constructor (\"Hold\");\n end if;\n end Handle_Interface_Subprogram_Pointer_Gestures;\n\n procedure Handle_Interface_Events_Pointer_Gestures\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n\n if Name = \"Pointer_Gesture_Swipe_V1\" then\n Put_Line (File, \" with procedure Gesture_Begin\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Swipe_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Fingers : Unsigned_32);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Gesture_Update\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Swipe_V1'Class;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Dx, Dy : Fixed);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Gesture_End\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Swipe_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Cancelled : Boolean);\");\n elsif Name = \"Pointer_Gesture_Pinch_V1\" then\n Put_Line (File, \" with procedure Gesture_Begin\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Pinch_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Fingers : Unsigned_32);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Gesture_Update\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Pinch_V1'Class;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Dx, Dy : Fixed;\");\n Put_Line (File, \" Scale : Fixed;\");\n Put_Line (File, \" Rotation : Fixed);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Gesture_End\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Pinch_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Cancelled : Boolean);\");\n elsif Name = \"Pointer_Gesture_Hold_V1\" then\n Put_Line (File, \" with procedure Gesture_Begin\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Hold_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Surface : Client.Surface;\");\n Put_Line (File, \" Fingers : Unsigned_32);\");\n Put_Line (File, \"\");\n Put_Line (File, \" with procedure Gesture_End\");\n Put_Line (File, \" (Gesture : in out Pointer_Gesture_Hold_V1'Class;\");\n Put_Line (File, \" Serial : Unsigned_32;\");\n Put_Line (File, \" Timestamp : Duration;\");\n Put_Line (File, \" Cancelled : Boolean);\");\n end if;\n\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Events_Pointer_Gestures;\n\n procedure Handle_Interface_Common_Subprograms\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if Protocol_Name /= \"client\" or Name /= \"Display\" then\n Generate_Spec_Destroy_Subprogram (Interface_Tag);\n end if;\n Generate_Spec_Utility_Functions (Name);\n\n if Protocol_Name /= \"client\" or Name /= \"Display\" then\n Generate_Spec_User_Data_Subprogram (Name);\n end if;\n end Handle_Interface_Common_Subprograms;\n\n procedure Handle_Interface_Common_Events\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n if not Exists_Events (Interface_Tag) then\n return;\n end if;\n\n Generate_Prefix_Spec_Events;\n Put_Line (File, \" -- FIXME Add generic `with procedure`'s here\");\n Generate_Suffix_Spec_Events (Name);\n end Handle_Interface_Common_Events;\n begin\n Iterate_Over_Interfaces (Handle_Interface_Common_Subprograms'Access);\n\n if Protocol_Name = \"client\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprograms_Client'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Client'Access);\n elsif Protocol_Name = \"xdg_shell\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprograms_Xdg_Shell'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Xdg_Shell'Access);\n elsif Protocol_Name = \"presentation_time\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprograms_Presentation_Time'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Presentation_Time'Access);\n elsif Protocol_Name = \"viewporter\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprograms_Viewporter'Access);\n elsif Protocol_Name = \"idle_inhibit_unstable_v1\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprogram_Idle_Inhibit'Access);\n elsif Protocol_Name = \"xdg_decoration_unstable_v1\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprogram_Xdg_Decoration'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Xdg_Decoration'Access);\n elsif Protocol_Name = \"relative_pointer_unstable_v1\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprogram_Relative_Pointer'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Relative_Pointer'Access);\n elsif Protocol_Name = \"pointer_constraints_unstable_v1\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprogram_Pointer_Constraints'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Pointer_Constraints'Access);\n elsif Protocol_Name = \"pointer_gestures_unstable_v1\" then\n Iterate_Over_Interfaces (Handle_Interface_Subprogram_Pointer_Gestures'Access);\n Iterate_Over_Interfaces (Handle_Interface_Events_Pointer_Gestures'Access);\n else\n Iterate_Over_Interfaces (Handle_Interface_Common_Events'Access);\n end if;\n end Generate_Manually_Edited_Partial_Type_Declarations;\n\n procedure Create_Wl_Thin_Spec_File (Protocol_Name : String) is\n\n procedure Generate_Code_For_Interface_Constants is\n procedure Handle_Interface (Interface_Tag : aliased Wayland_XML.Interface_Tag) is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Interface\");\n begin\n if not Generate_Interfaces_For_Client and Protocol_Name = \"client\" then\n Put_Line (File, \" \" & Name & \" : aliased constant Interface_T\");\n Put_Line (File, \" with Import, Convention => C, External_Name => \"\"\" & Wayland_XML.Name (Interface_Tag) & \"_interface\"\";\");\n New_Line (File);\n else\n Put_Line (File, \" \" & Name & \" : aliased constant Interface_T;\");\n end if;\n end Handle_Interface;\n begin\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Code_For_Interface_Constants;\n\n procedure Generate_Private_Code_For_Interface_Constants is\n type Partial_Match (Is_Match : Boolean) is record\n case Is_Match is\n when True => null;\n when False => Index : Positive;\n end case;\n end record;\n\n type Match (Is_Match : Boolean) is record\n case Is_Match is\n when False => null;\n when True => Index : Positive;\n end case;\n end record;\n\n function Contains_At_Index\n (Index : Positive;\n Vector, Sub_Vector : Unbounded_String_Vectors.Vector) return Partial_Match\n is\n use type SU.Unbounded_String;\n begin\n for Sub_Index in Sub_Vector.First_Index .. Sub_Vector.Last_Index loop\n declare\n Vector_Index : constant Positive := Index + (Sub_Index - Sub_Vector.First_Index);\n begin\n if Vector_Index > Vector.Last_Index or else Sub_Vector (Sub_Index) /= Vector (Vector_Index) then\n return (Is_Match => False, Index => Sub_Index);\n end if;" + }, + { + "function_def": "procedure Generate_Code_For_Interface_Ptrs is", + "function_body": "procedure Handle_Interface (Interface_Tag : aliased Wayland_XML.Interface_Tag) is\n Interface_Ptr_Name : constant String :=\n Xml_Parser_Utils.Adaify_Name (Name (Interface_Tag)) & \"_Ptr\";\n begin\n if Interface_Ptr_Name /= \"Display_Ptr\" then\n Put_Line (File, \" type \" & Interface_Ptr_Name & \" is new Proxy_Ptr;\");\n New_Line (File);\n end if;\n end Handle_Interface;\n begin\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Code_For_Interface_Ptrs;\n\n procedure Generate_Code_For_Each_Interface is\n\n procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n procedure Generate_Code_For_Subprogram_Ptrs is\n\n procedure Generate_Code_For_Subprogram\n (Event_Tag : aliased Wayland_XML.Event_Tag)\n is\n V : Wayland_XML.Event_Child_Vectors.Vector;\n\n Subprogram_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Name (Interface_Tag) & \"_\" & Name (Event_Tag) & \"_Subprogram_Ptr\");\n Interface_Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Name (Interface_Tag));\n begin\n for Child of Wayland_XML.Children (Event_Tag) loop\n if Child.Kind_Id = Child_Arg then\n V.Append (Child);\n end if;\n end loop;\n\n declare\n Max_Name_Length : Natural := Interface_Name'Length;\n Dont_Care : String_Maps.Map;\n begin\n for Child of V loop\n declare\n Arg_Name : constant String\n := Xml_Parser_Utils.Adaify_Variable_Name (Name (Child.Arg_Tag.all));\n begin\n Max_Name_Length := Natural'Max (Max_Name_Length, Arg_Name'Length);" + }, + { + "function_def": "procedure Generate_Code_For_Listener_Type_Definition is", + "function_body": "function Get_Name (Event_Tag : Wayland_XML.Event_Tag) return String is\n (Xml_Parser_Utils.Adaify_Name (Name (Event_Tag)));\n\n Name_Length : Natural := 0;\n\n procedure Generate_Code_For_Record_Component\n (Event_Tag : aliased Wayland_XML.Event_Tag)\n is\n Component_Name : constant String := Get_Name (Event_Tag);\n\n Component_Type_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Name (Interface_Tag) & \"_\" &\n Name (Event_Tag) & \"_Subprogram_Ptr\");\n\n Component_Name_Aligned : constant String := SF.Head (Component_Name & (if Is_Reserved_Keyword (Component_Name) then \"_F\" else \"\"), Name_Length, ' ');\n\n use type Wayland_XML.Version_Number;\n begin\n -- Patch out events from wl_output that exist since v4 because\n -- the high level bindings assume v3\n if Wayland_XML.Name (Interface_Tag) = \"wl_output\"\n and (Exists_Since (Event_Tag) and then Since (Event_Tag) >= 4)\n then\n return;\n end if;\n\n Put_Line (File, \" \" & Component_Name_Aligned & \" : \" & Component_Type_Name & \";\");\n end Generate_Code_For_Record_Component;\n\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Listener_T\");\n Ptr_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Listener_Ptr\");\n begin\n Put_Line (File, \" type \" & Name & \" is record\");\n\n for Child of Children (Interface_Tag) loop\n if Child.Kind_Id = Child_Event then\n declare\n Arg_Name : constant String := Get_Name (Child.Event_Tag.all);\n begin\n Name_Length := Natural'Max (Name_Length, Arg_Name'Length + (if Is_Reserved_Keyword (Arg_Name) then 2 else 0));" + }, + { + "function_def": "procedure Generate_Code_For_Add_Listener_Subprogram_Declaration is", + "function_body": "Ptr_Listener_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Listener_Ptr\");\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Add_Listener\", \"Interfaces.C.int\",\n ((+\"Listener\", +Ptr_Listener_Name),\n (+\"Data\", +\"Void_Ptr\")));\n end Generate_Code_For_Add_Listener_Subprogram_Declaration;\n\n procedure Generate_Code_For_Set_User_Data_Subprogram_Declaration is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Set_User_Data\", \"\",\n (1 => (+\"Data\", +\"Void_Ptr\")));\n end Generate_Code_For_Set_User_Data_Subprogram_Declaration;\n\n procedure Generate_Code_For_Get_User_Data_Subprogram_Declaration is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Get_User_Data\", \"Void_Ptr\");\n end Generate_Code_For_Get_User_Data_Subprogram_Declaration;\n\n procedure Generate_Code_For_Get_ID_Subprogram_Declaration is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Get_ID\", \"Unsigned_32\");\n end Generate_Code_For_Get_ID_Subprogram_Declaration;\n\n procedure Generate_Code_For_Get_Version_Subprogram_Declaration is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Get_Version\", \"Unsigned_32\");\n end Generate_Code_For_Get_Version_Subprogram_Declaration;\n\n procedure Generate_Code_For_Destroy_Subprogram_Declaration is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Declaration, Interface_Tag, \"Destroy\", \"\");\n end Generate_Code_For_Destroy_Subprogram_Declaration;\n\n procedure Generate_Code_For_Requests is\n\n procedure Generate_Code_For_Subprogram_Declaration\n (Request_Tag : aliased Wayland_XML.Request_Tag)\n is\n procedure Generate_Comment (Text : String) is\n Interval_Identifier : constant Xml_Parser_Utils.Interval_Identifier := Xml_Parser_Utils.Make (Text);\n begin\n for Interval of Interval_Identifier.Intervals loop\n declare\n Comment : constant String := Trim (Text (Interval.First .. Interval.Last));\n begin\n if Comment'Length > 0 then\n Put_Line (File, \" -- \" & Comment);\n else\n Put_Line (File, \" --\");\n end if;" + }, + { + "function_def": "Put_Line (File, \" function Display_Connect return Display_Ptr;\");", + "function_body": "Put_Line (File, \"\");\n Put_Line (File, \" procedure Display_Disconnect (This : in out Display_Ptr);\");\n elsif Protocol_Name = \"xdg_decoration_unstable_v1\" then\n Put_Line (File, \" use Wayland.Protocols.Thin_Xdg_Shell;\");\n else\n Put_Line (File, \" use Wayland.Protocols.Thin_Client;\");\n end if;\n Put_Line (File, \"\");\n Generate_Code_For_Interface_Constants;\n if Generate_Interfaces_For_Client or Protocol_Name /= \"client\" then\n New_Line (File);\n Put_Line (File, \" procedure Initialize;\");\n New_Line (File);\n end if;\n\n Generate_Code_For_Interface_Ptrs;\n Generate_Code_For_Each_Interface;\n\n if Generate_Interfaces_For_Client or Protocol_Name /= \"client\" then\n Put_Line (File, \"private\");\n New_Line (File);\n\n Generate_Private_Code_For_Interface_Constants;\n New_Line (File);\n end if;\n end Create_Wl_Thin_Spec_File;\n\n procedure Generate_Use_Type_Declarions (Package_Name : String) is\n procedure Handle_Interface (Interface_Tag : aliased Wayland_XML.Interface_Tag) is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n Put_Line (File, \" use type Thin.\" & Name & \"_Ptr;\");\n end Handle_Interface;\n begin\n Put_Line (File, \" package Thin renames Wayland.Protocols.Thin_\" & Package_Name & \";\");\n Put_Line (File, \"\");\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Use_Type_Declarions;\n\n procedure Generate_Manually_Edited_Code_For_Type_Definitions is\n procedure Handle_Interface (Interface_Tag : aliased Wayland_XML.Interface_Tag) is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name (Wayland_XML.Name (Interface_Tag));\n begin\n Put_Line (File, \"\");\n Put_Line (File, \" type \" & Name & \" is tagged limited record\");\n Put_Line (File, \" Proxy : Thin.\" & Name & \"_Ptr;\");\n Put_Line (File, \" end record;\");\n -- FIXME add Initialized : Boolean := Thin.Initialize; for Xdg_Wm_Base and Wp_Presentation\n end Handle_Interface;\n begin\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Manually_Edited_Code_For_Type_Definitions;\n\n procedure Generate_Private_Code_For_The_Interface_Constants is\n procedure Handle_Interface (Interface_Tag : aliased Wayland_XML.Interface_Tag) is\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Interface\");\n begin\n Put_Line (File, \"\");\n Put_Line (File, \" \" & Name & \" : constant Interface_Type :=\");\n Put_Line (File, \" (My_Interface => Thin.\" & Name & \"'Access);\");\n end Handle_Interface;\n begin\n Iterate_Over_Interfaces (Handle_Interface'Access);\n end Generate_Private_Code_For_The_Interface_Constants;\n\n begin\n Create_File;\n end Create_Wayland_Spec_File;\n\n procedure Create_Wayland_Body_File is\n File : Ada.Text_IO.File_Type;\n\n procedure Create_Wl_Thin_Body_File;\n\n procedure Generate_Manually_Edited_Code (Protocol_Name : String);\n\n procedure Create_File is\n Protocol_Name : constant String := Get_Protocol_Name (Name (Protocol_Tag.all));\n Package_Name : constant String := Xml_Parser_Utils.Adaify_Name (Protocol_Name);\n begin\n Ada.Text_IO.Create\n (File, Ada.Text_IO.Out_File,\n \"wayland-protocols-\" & Protocol_Name & \".adb\");\n\n -- TODO Do not import System.Address_To_Access_Conversions if\n -- there are no generic *_Events packages\n Put_Line (File, \"with System.Address_To_Access_Conversions;\");\n New_Line (File);\n\n if Protocol_Name = \"client\" then\n Put_Line (File, \"with Interfaces.C.Strings;\");\n New_Line (File);\n Put_Line (File, \"with Wayland.Posix;\");\n elsif Protocol_Name in \"presentation_time\" | \"relative_pointer_unstable_v1\" then\n Put_Line (File, \"with Ada.Unchecked_Conversion;\");\n Put_Line (File, \"\");\n Put_Line (File, \"with Wayland.Protocols.Thin_Client;\");\n elsif Protocol_Name = \"xdg_decoration_unstable_v1\" then\n Put_Line (File, \"with Wayland.Protocols.Thin_Xdg_Shell;\");\n else\n Put_Line (File, \"with Wayland.Protocols.Thin_Client;\");\n end if;\n\n New_Line (File);\n Put_Line (File, \"package body Wayland.Protocols.\" & Package_Name & \" is\");\n New_Line (File);\n\n if Generate_Interfaces_For_Client or Protocol_Name /= \"client\" then\n Put_Line (File, \" procedure Initialize renames Thin.Initialize;\");\n Put_Line (File, \"\");\n end if;\n\n if Protocol_Name = \"client\" then\n Put_Line (File, \" package body Constructors is\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Buffer is\");\n Put_Line (File, \" (Proxy => Thin.Buffer_Ptr (Proxy));\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Output is\");\n Put_Line (File, \" (Proxy => Thin.Output_Ptr (Proxy));\");\n Put_Line (File, \"\");\n Put_Line (File, \" function Set_Proxy (Proxy : Secret_Proxy) return Surface is\");\n Put_Line (File, \" (Proxy => Thin.Surface_Ptr (Proxy));\");\n Put_Line (File, \" end Constructors;\");\n Put_Line (File, \"\");\n end if;\n\n Generate_Manually_Edited_Code (Protocol_Name);\n\n Put_Line (File, \"end Wayland.Protocols.\" & Package_Name & \";\");\n\n Ada.Text_IO.Close (File);\n\n -----------------------------------------------------------------------\n\n Ada.Text_IO.Create\n (File, Ada.Text_IO.Out_File,\n \"wayland-protocols-thin_\" & Protocol_Name & \".adb\");\n\n Put_Line (File, \"with Ada.Unchecked_Conversion;\");\n Put_Line (File, \"\");\n Put_Line (File, \"package body Wayland.Protocols.Thin_\" & Package_Name & \" is\");\n Put_Line (File, \"\");\n\n if Generate_Interfaces_For_Client or Protocol_Name /= \"client\" then\n Put_Line (File, \" procedure Initialize is\");\n Put_Line (File, \" begin\");\n\n Put_Line (File, \" Interface_Pointers :=\");\n for Index in All_Types.First_Index .. All_Types.Last_Index loop\n declare\n Value : constant String := +All_Types (Index);\n\n Prefix : constant String := (if Index = All_Types.First_Index then \"(\" else \" \");\n Suffix : constant String := (if Index = All_Types.Last_Index then \");\" else \",\");\n begin\n Put_Line (File, \" \" & Prefix & (if Value'Length > 0 then Xml_Parser_Utils.Adaify_Name (Value) & \"_Interface'Access\" else \"null\") & Suffix);" + }, + { + "function_def": "Put_Line (File, \" function Display_Connect return Display_Ptr is\");", + "function_body": "Put_Line (File, \" begin\");\n Put_Line (File, \" return Wayland.API.Display_Connect (Interfaces.C.Strings.Null_Ptr);\");\n Put_Line (File, \" end Display_Connect;\");\n Put_Line (File, \"\");\n Put_Line (File, \" procedure Display_Disconnect (This : in out Display_Ptr) is\");\n Put_Line (File, \" use type Wayland.API.Display_Ptr;\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" if This /= null then\");\n Put_Line (File, \" Wayland.API.Display_Disconnect (This);\");\n Put_Line (File, \" This := null;\");\n Put_Line (File, \" end if;\");\n Put_Line (File, \" end Display_Disconnect;\");\n end if;\n\n Create_Wl_Thin_Body_File;\n\n Put_Line (File, \"\");\n Put_Line (File, \"end Wayland.Protocols.Thin_\" & Package_Name & \";\");\n\n Ada.Text_IO.Close (File);\n end Create_File;\n\n procedure Create_Wl_Thin_Body_File is\n\n procedure Generate_Code_For_Protocol_Tag_Children is\n procedure Handle_Interface\n (Interface_Tag : aliased Wayland_XML.Interface_Tag)\n is\n procedure Generate_Code_For_Add_Listener_Subprogram_Implementations (Name : String) is\n Ptr_Listener_Name : constant String := Name & \"_Listener_Ptr\";\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Add_Listener\", \"Interfaces.C.int\",\n ((+\"Listener\", +Ptr_Listener_Name),\n (+\"Data\", +\"Void_Ptr\")));\n Put_Line (File, \" begin\");\n Put_Line (File, \" return Wayland.API.Proxy_Add_Listener\");\n Put_Line (File, \" (\" & Name & \".all, Listener.all'Address, Data);\");\n Put_Line (File, \" end \" & Name & \"_Add_Listener;\");\n end Generate_Code_For_Add_Listener_Subprogram_Implementations;\n\n procedure Generate_Code_For_Set_User_Data_Subprogram_Implementations (Name : String) is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Set_User_Data\", \"\",\n (1 => (+\"Data\", +\"Void_Ptr\")));\n Put_Line (File, \" begin\");\n Put_Line (File, \" Wayland.API.Proxy_Set_User_Data (\" & Name & \".all, Data);\");\n Put_Line (File, \" end \" & Name & \"_Set_User_Data;\");\n end Generate_Code_For_Set_User_Data_Subprogram_Implementations;\n\n procedure Generate_Code_For_Get_User_Data_Subprogram_Implementations (Name : String) is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Get_User_Data\", \"Void_Ptr\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" return Wayland.API.Proxy_Get_User_Data (\" & Name & \".all);\");\n Put_Line (File, \" end \" & Name & \"_Get_User_Data;\");\n end Generate_Code_For_Get_User_Data_Subprogram_Implementations;\n\n procedure Generate_Code_For_Get_ID_Subprogram_Implementations (Name : String) is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Get_ID\", \"Unsigned_32\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" return Wayland.API.Proxy_Get_Id (\" & Name & \".all);\");\n Put_Line (File, \" end \" & Name & \"_Get_ID;\");\n end Generate_Code_For_Get_ID_Subprogram_Implementations;\n\n procedure Generate_Code_For_Get_Version_Subprogram_Implementations (Name : String) is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Get_Version\", \"Unsigned_32\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" return Wayland.API.Proxy_Get_Version (\" & Name & \".all);\");\n Put_Line (File, \" end \" & Name & \"_Get_Version;\");\n end Generate_Code_For_Get_Version_Subprogram_Implementations;\n\n procedure Generate_Code_For_Destroy_Subprogram_Implementations (Name : String) is\n begin\n Generate_Pretty_Code_For_Subprogram\n (File, Implementation, Interface_Tag, \"Destroy\", \"\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" Wayland.API.Proxy_Destroy (\" & Name & \".all);\");\n Put_Line (File, \" end \" & Name & \"_Destroy;\");\n end Generate_Code_For_Destroy_Subprogram_Implementations;\n\n procedure Generate_Code_For_Requests is\n\n procedure Generate_Code_For_Subprogram_Implementation\n (Request_Tag : aliased Wayland_XML.Request_Tag)\n is\n Request_Name : constant String :=\n Xml_Parser_Utils.Adaify_Name (Name (Request_Tag));\n\n Subprogram_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Name (Interface_Tag) & \"_\" & Request_Name);\n Opcode : constant String := \"Constants.\" & Subprogram_Name;\n Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag));\n Ptr_Name : constant String\n := Xml_Parser_Utils.Adaify_Name\n (Wayland_XML.Name (Interface_Tag) & \"_Ptr\");\n\n procedure Generate_Arguments (Spaces : Natural; Null_Id : Boolean) is\n use SF;\n\n function Get_Value (Child : Wayland_XML.Arg_Tag; Value : String) return String is\n (if Exists_Enum (Child) then \"Convert (\" & Value & \")\" else Value);\n\n First_Element : Boolean := True;\n begin\n for Child of Children (Request_Tag) loop\n if Child.Kind_Id = Child_Arg then\n if not First_Element then\n Put_Line (File, \",\");\n end if;\n First_Element := False;\n if Type_Attribute (Child.Arg_Tag.all) /= Type_Object then\n if Type_Attribute (Child.Arg_Tag.all) = Type_New_Id then\n if Null_Id then\n Put (File, Spaces * \" \" & \"0\");\n end if;\n else\n Put (File, Spaces * \" \" & Get_Value (Child.Arg_Tag.all, Xml_Parser_Utils.Adaify_Variable_Name (Wayland_XML.Name (Child.Arg_Tag.all))));\n end if;\n else\n Put (File, Spaces * \" \" & \"Proxy_Ptr (\" & Get_Value (Child.Arg_Tag.all, Xml_Parser_Utils.Adaify_Variable_Name (Wayland_XML.Name (Child.Arg_Tag.all))) & \")\");\n end if;\n end if;\n end loop;\n end Generate_Arguments;\n\n procedure Generate_Code_Before_Arguments is\n Interface_Name : constant String := Xml_Parser_Utils.Adaify_Name\n (Xml_Parser_Utils.Find_Specified_Interface (Request_Tag)) & \"_Interface\";\n begin\n Put_Line (File, \" P : constant Proxy_Ptr :=\");\n Put_Line (File, \" Wayland.API.Proxy_Marshal_Constructor\");\n Put_Line (File, \" (\" & Name & \".all,\");\n Put_Line (File, \" \" & Opcode & \",\");\n Put_Line (File, \" \" & Interface_Name & \"'Access,\");\n end Generate_Code_Before_Arguments;\n\n procedure Generate_Code_After_Arguments is\n begin\n Put_Line (File, \");\");\n Put_Line (File, \" begin\");\n Put_Line (File, \" return (if P /= null then P.all'Access else null);\");\n Put_Line (File, \" end \" & Subprogram_Name & \";\");\n end Generate_Code_After_Arguments;\n\n Enum_Types : String_Maps.Map;\n\n procedure Generate_Conversion_Code_For_Args is\n procedure Generate_Convert (Cursor : String_Maps.Cursor) is\n From : constant String := String_Maps.Key (Cursor);\n To : constant String := String_Maps.Element (Cursor);\n begin\n Put_Line (File, \" function Convert is new Ada.Unchecked_Conversion\");\n Put_Line (File, \" (\" & From & \", \" & To & \");\");\n end Generate_Convert;\n begin\n Enum_Types.Iterate (Generate_Convert'Access);\n end Generate_Conversion_Code_For_Args;\n\n V : Wayland_XML.Request_Child_Vectors.Vector;\n\n Max_Name_Length : Natural := Name'Length;\n\n function Align (Value : String) return String is (SF.Head (Value, Max_Name_Length, ' '));\n begin\n Put_Line (File, \"\");\n if Xml_Parser_Utils.Is_New_Id_Argument_Present (Request_Tag) then\n if Xml_Parser_Utils.Is_Interface_Specified (Request_Tag) then\n declare\n Return_Type : constant String := Xml_Parser_Utils.Adaify_Name\n (Xml_Parser_Utils.Find_Specified_Interface (Request_Tag) & \"_Ptr\");\n begin\n Get_Max_Arg_Length (Request_Tag, V, Max_Name_Length);\n\n if Xml_Parser_Utils.Number_Of_Args (Request_Tag) > 1 then\n Put_Line (File, \" function \" & Subprogram_Name);\n Put_Line (File, \" (\" & Align (Name) & \" : \" & Ptr_Name & \";\");\n\n for Child of V loop\n if Child.Kind_Id = Child_Arg then\n Generate_Code_For_Arg\n (File,\n Interface_Tag,\n Child.Arg_Tag.all,\n Max_Name_Length,\n Child = V.Last_Element,\n Enum_Types);\n end if;\n end loop;\n\n Put_Line (File, \" return \" & Return_Type);\n Put_Line (File, \" is\");\n Generate_Conversion_Code_For_Args;\n if not Enum_Types.Is_Empty then\n Put_Line (File, \"\");\n end if;\n else\n if 27 + Subprogram_Name'Length + Name'Length + Ptr_Name'Length + Return_Type'Length <= Max_Line_Length then\n Put_Line (File, \" function \" & Subprogram_Name & \" (\" & Name & \" : \" & Ptr_Name & \") return \" & Return_Type & \" is\");\n else\n Put_Line (File, \" function \" & Subprogram_Name);\n Put_Line (File, \" (\" & Name & \" : \" & Ptr_Name & \") return \" & Return_Type);\n Put_Line (File, \" is\");\n end if;\n end if;\n Generate_Code_Before_Arguments;\n Generate_Arguments (11, True);\n Generate_Code_After_Arguments;" + }, + { + "function_def": "procedure Print_Active_Map is", + "function_body": "C: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tEP_Image: ASU.Unbounded_String;\n\tbegin\n\t\tAda.Text_IO.Put_Line (\"ACTIVE CLIENTS\");\n\t\tAda.Text_IO.Put_Line (\"==============\");\n\n\t\twhile Active_Clients.Has_Element(C) loop\n\t\t\tEP_Image := ASU.To_Unbounded_String(LLU.Image(Active_Clients.Element\n\t\t\t(C).Value.Client_EP));\n\n\t\t\tAda.Text_IO.Put_Line (ASU.To_String(Active_Clients.Element(C).Key) &\n\t\t\t\" \" &\n\t\t\tASU.To_String(Format_EP(EP_Image)) & \" \" &\n\t\t\tTime_Image(Active_Clients.Element(C).Value.Time));\n\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\t\tATI.New_Line;\n\tend Print_Active_Map;\n\n\tprocedure Print_Old_Map is\n\t\tC: Old_Clients.Cursor := Old_Clients.First(Old_Map);\n\tbegin\n\t\tAda.Text_IO.Put_Line (\"OLD CLIENTS\");\n\t\tAda.Text_IO.Put_Line (\"===========\");\n\n\t\twhile Old_Clients.Has_Element(C) loop\n\t\t\tAda.Text_IO.Put_Line (ASU.To_String(Old_Clients.Element(C).Key) &\n\t\t\t\": \" & Time_Image(Old_Clients.Element(C).Value));\n\n\t\t\tOld_Clients.Next(C);\n\t\tend loop;\n\t\tATI.New_Line;\n\tend Print_Old_Map;\n\n\n\tfunction Client_To_Ban (Active_Map: Active_Clients.Map) return ASU.Unbounded_String is\n\n\t\tC: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tMin_Time: Ada.Calendar.Time;\n\t\tNick: ASU.Unbounded_String;\n\tbegin\n\t\tMin_Time := Active_Clients.Element(C).Value.Time;\n\t\tNick := Active_Clients.Element(C).Key;\n\t\twhile Active_Clients.Has_Element(C) loop\n\n\t\t\tif Active_Clients.Element(C).Value.Time < Min_Time then\n\t\n\t\t\t\tNick := Active_Clients.Element(C).Key;\n\t\t\t\t\n\t\t\tend if;\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\t\treturn Nick;\n\tend Client_To_Ban;\n\n\tprocedure Server_To_All (Comment: ASU.Unbounded_String;\n\t\t\t O_Buffer: access LLU.Buffer_Type) is\n\t\t\n\t\tC: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tNick: ASU.Unbounded_String := ASU.To_Unbounded_String(\"Server\");\n\t\t\n\tbegin\n\t\twhile Active_Clients.Has_Element(C) loop\n\n\t\t\tCM.Server_Message (Active_Clients.Element(C).Value.Client_EP,\n\t\t\tNick,Comment,O_Buffer);\n\t\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\tend Server_To_All;\n\n\tprocedure Case_Init (I_Buffer: access LLU.Buffer_Type;\n\t\t\t O_Buffer: access LLU.Buffer_Type) is\n\t\n\t\tClient_EP_Receive: LLU.End_Point_Type;\n\t\tClient_EP_Handler: LLU.End_Point_Type;\n\t\tNick: \t\t ASU.Unbounded_String;\n\t\tBan_Nick: \t ASU.Unbounded_String;\n\t\tComment: \t ASU.Unbounded_String;\n\t\tLogout_Time: \t Ada.Calendar.Time;\n\t\tClient_Data: \t Data;\n\t\tAccepted: \t Boolean;\n\t\tSuccess: \t Boolean;\n\tbegin\n\t\t\t\n\t\tClient_EP_Receive := LLU.End_Point_Type'Input (I_Buffer);\n\t\tClient_EP_Handler := LLU.End_Point_Type'Input (I_Buffer);\n\t\tNick := ASU.Unbounded_String'Input (I_Buffer);\n\t\t\n\t\tActive_Clients.Get(Active_Map,Nick,Client_Data,Success);\n\n\t\tif Success then \n\t\t\tAccepted := False;\n\t\t\tATI.Put_Line(\"INIT received from \" & ASU.To_String(Nick)\n\t\t\t& \": IGNORED. nick already used\");\n\t\telse\n\t\t\tATI.Put_Line(\"INIT received from \" & ASU.To_String(Nick)\n\t\t\t& \": ACCEPTED\");\n\t\t\tbegin\n\t\t\t\tAccepted := True;\n\t\t\t\tClient_Data.Client_EP := Client_EP_Handler;\n\t\t\t\tClient_Data.Time := Ada.Calendar.Clock;\n\t\t\t\t\n\t\t\t\tActive_Clients.Put (Active_Map,Nick,Client_Data);\n\n\t\t\texception\n\t\t\t\twhen Active_Clients.Full_Map =>\n\t\t\t\t\t\n\t\t\t\t\tBan_Nick := Client_To_Ban(Active_Map);\n\t\t\t\t\tLogout_Time := Ada.Calendar.Clock;\n\t\t\t\t\t\n\t\t\t\t\tOld_Clients.Put (Old_Map,Ban_Nick,Logout_Time);\n\t\t\t\t\t\n\t\t\t\t\tComment := ASU.To_Unbounded_String(ASU.To_String(Ban_Nick)\n\t\t\t\t\t & \" banned for being idle too long\");\n\n\t\t\t\t\tServer_To_All (Comment,O_Buffer);\n\n\t\t\t\t\tActive_Clients.Delete (Active_Map,Ban_Nick,Success);\n\n\t\t\t\t\tActive_Clients.Put (Active_Map,Nick,Client_Data);" + }, + { + "function_def": "procedure main is", + "function_body": "inputFname : unbounded_string;\n outputFname : unbounded_string;\n img : image;\n processedImg :imageprocess.image;\n userSelection : character;\n\n -- function which gets and validates file name\n function getFilename(RWIndicator: in String) return Unbounded_String is\n\n inputFname : unbounded_string;\n outputFname : unbounded_string;\n ans: character;\n outfp: file_type;\n\n begin\n\n -- hanldle file writing\n if RWindicator = \"W\" then\n\n Put_Line (\"Enter file name to write: \");\n get_line(outputFname);\n\n if exists(to_string(outputFname)) then\n put_line(\"File exists - overwrite (Y/N)? \");\n get(ans);\n\n if ans = 'Y' then\n return outputFname;\n else\n put_line(\"Exiting - image not saved\");\n GNAT.OS_Lib.OS_Exit (0);\n end if;\n\n end if;\n\n return outputFname;\n\n end if;\n\n --handle file reading\n if RWindicator = \"R\" then\n Put_Line (\"Enter file name to read: \");\n get_line(inputFname);\n\n if not exists(to_string(inputFname)) then\n put_line(\"File does not exist: exiting - image not saved\");\n GNAT.OS_Lib.OS_Exit (0);\n end if;\n\n end if;\n\n return inputFname;" + }, + { + "function_def": "function histEQUAL(img: in image) return image is", + "function_body": "equalImage : image;\n type histArray is Array(1..256) of integer;\n type CHIntArray is Array(1..256) of integer;\n type cumuHistArray is Array(1..256) of Float;\n type PDFArray is Array(1..256) of Float;\n \n cumuHistArray1 : cumuHistArray;\n histArray1 : histArray;\n PDFArray1 : PDFArray; \n CHIntArray1 : CHIntArray;\n totalPixels : integer; \n \n begin\n \n equalImage.dx := img.dx;\n equalImage.dy := img.dy;\n \n --calculate the total number of pixels in the image\n totalPixels := equalImage.dx * equalImage.dy;\n \n --create a histogram distribution array\n for n in 1..256 loop\n histArray1(n) := 0;\n cumuHistArray1(n) := 0.0;\n PDFArray1(n) := 0.0;\n CHIntArray1(n) := 0;\n end loop; \n \n for m in 1..256 loop\n for i in 1..img.dx loop\n for j in 1..img.dy loop\n if img.pixel(i,j) = m then\n histArray1(m) := histArray1(m) + 1;\n end if;\n end loop;\n end loop;\n end loop; \n \n --Populate Probability Density Arr\n for m in 1..256 loop\n PDFArray1(m) := (Float(histArray1(m))) / (Float(totalPixels));\n end loop;\n \n --Calculate Cumulative Histogram\n cumuHistArray1(1) := PDFArray1(1);\n for m in 2..256 loop\n cumuHistArray1(m) := PDFArray1(m) + cumuHistArray1(m-1);\n end loop;\n \n --multiply the CH by 255 and round, forming a new integer array\n for m in 1..256 loop\n CHIntArray1(m) := Integer(cumuHistArray1(m) * 255.0);\n end loop;\n \n --map the new greyscale values to a histogram record\n for i in 1..img.dx loop\n for j in 1..img.dy loop \n equalImage.pixel(i,j) := CHIntArray1(img.pixel(i,j)); \n end loop;\n end loop; \n \n return equalImage;" + }, + { + "function_def": "procedure Remove_Target is", + "function_body": "use AAA.Strings;\n begin\n for I in Lines.First_Index .. Lines.Last_Index loop\n declare\n Line : constant String := Replace (Lines (I), \" \", \"\");\n begin\n\n if Armed and then Has_Prefix (Line, Target) then\n Found := True;\n Lines.Delete (I);\n exit;\n\n elsif Has_Prefix (Line, \"[[\") then\n -- Detect a plain [[array]] with optional comment\n Armed :=\n Line = Enter_Marker or else\n Has_Prefix (Line, Enter_Marker & '#');\n\n elsif Armed and then Line /= \"\" and then\n Line (Line'First) /= '[' -- not a table or different array\n then\n -- We are seeing a different entry in the same array\n -- entry; we can still remove our target if later found\n -- in this entry.\n null;\n\n elsif Line = \"\" or else Has_Prefix (Line, \"#\") then\n -- We still can remove an entry found in this array entry\n null;\n\n else\n -- Any other sighting complicates matters and we won't\n -- touch it.\n Armed := False;\n\n -- TODO: be able to remove a table in the array named as\n -- Entry, i.e., something like:\n -- [[array]]\n -- [array.entry] or [array.entry.etc]\n -- etc\n\n -- Or, be able to remove something like\n -- [[array]]\n -- entry.field = ...\n end if;" + }, + { + "function_def": "procedure Remove_Empty_Arrays is", + "function_body": "-- This might probably be done with multiline regular expressions\n\n Deletable : Natural := 0;\n -- Tracks how many empty lines we have seen since the last [[\n\n Can_Delete : Boolean := True;\n -- We can delete as long as we are only seeing empty lines\n\n use AAA.Strings;\n begin\n\n -- Traverse lines backwards\n\n for I in reverse Lines.First_Index .. Lines.Last_Index loop\n declare\n Line : constant String := Replace (Lines (I), \" \", \"\");\n begin\n if Can_Delete then\n -- Look for empty lines or the opening [[array]]\n if Line = \"\" then\n Deletable := Deletable + 1;\n\n elsif\n Line = Enter_Marker or else\n Has_Prefix (Line, Enter_Marker & '#')\n then\n -- Now we can delete the empty [[array]] plus any\n -- following empty lines.\n for J in 0 .. Deletable loop -- 0 for the current line\n Lines.Delete (I);\n end loop;\n\n -- Restart, we can still delete previous entries\n Deletable := 0;\n\n else\n -- We found something else, so do not remove entry\n Can_Delete := False;\n Deletable := 0;\n end if;\n\n else\n -- Look for a [[ that starts another array entry. We\n -- cannot rely on simply [ for tables, these could be\n -- nested array tables.\n if Has_Prefix (Line, \"[[\") then\n Can_Delete := True;\n Deletable := 0;\n -- We will look in next iterations for a precedent\n -- empty array entry.\n end if;\n end if;" + }, + { + "function_def": "procedure Day_02 is", + "function_body": "Mem: constant Memory.Block := Memory.Read_Comma_Separated;\n M: aliased Intcode.Machine(Hi_Mem => Mem'Last);\n\n use type Memory.Value;\n subtype Input is Memory.Value range 0..99;\nbegin\n for Noun in Input'Range loop\n for Verb in Input'Range loop\n M.Mem := Mem;\n M.Mem(16#1#) := Noun;\n M.Mem(16#2#) := Verb;\n declare\n E: Intcode.Executor(M'Access);\n begin\n null; -- wait for E to terminate" + }, + { + "function_def": "procedure Day_06 is", + "function_body": "subtype Name is String(1 .. 3);\n You: constant Name := \"YOU\";\n Santa: constant Name := \"SAN\";\n\n type Orbit is record\n Self, Parent: Name;\n end record;\n\n type Chain is array (Positive range <>) of Name;\n\n package Orbits is new Ada.Containers.Ordered_Maps(\n Key_Type => Name, Element_Type => Orbit);\n Locals: Orbits.Map;\n\n function Get(S: String) return Orbit is\n begin\n for I in S'Range loop\n if S(I) = ')' then\n return (Parent => S(S'First .. I - 1), Self => S(I + 1 .. S'Last));\n end if;\n end loop;\n raise Constraint_Error with \"orbit missing ')': \" & S;\n end Get;\n \n function Count_Orbits(O: Orbit) return Positive is\n E: constant Orbits.Cursor := Locals.Find(O.Parent);\n use type Orbits.Cursor;\n begin\n if E = Orbits.No_Element then\n return 1; -- only a direct orbit\n else\n return 1 + Count_Orbits(Orbits.Element(E));\n end if;\n end Count_Orbits;\n\n function Ancestors(O: Orbit) return Chain is\n Size : constant Natural := Count_Orbits(O) - 1;\n C: Chain(1 .. Size);\n Curr: Orbit := O;\n begin\n for I in C'Range loop\n C(I) := Curr.Parent;\n Curr := Locals.Element(Curr.Parent);\n end loop;\n return C;\n end Ancestors;\n\nbegin\n while (not Ada.Text_IO.End_Of_File) loop\n declare\n O: constant Orbit := Get(Ada.Text_IO.Get_Line);\n begin\n Locals.Insert(Key => O.Self, New_Item => O);" + }, + { + "function_def": "procedure Day_05 is", + "function_body": "package IO is new Ada.Text_IO.Integer_IO(Memory.Value);\n Program_Name: constant String := Ada.Command_Line.Argument(1);\n F: File_Type;\nbegin\n Open(F, In_File, Program_Name);\n declare \n Mem: constant Memory.Block := Memory.Read_Comma_Separated(F);\n M: aliased Intcode.Machine :=\n (Hi_Mem => Mem'Last,\n Mem => Mem,\n Aux_Mem => Intcode.Aux_Memory.Empty_Map,\n Input => new Intcode.Port,\n Output => new Intcode.Port);\n Exec: Intcode.Executor(M'Access);\n I: Memory.Value;\n O: Intcode.Maybe_Memory_Value;\n begin\n Ada.Text_IO.Put(\"? \");\n IO.Get(I);\n M.Input.Put(I);\n loop\n M.Output.Get(O);\n exit when not O.Present;\n IO.Put(O.Value);\n Ada.Text_IO.New_Line;\n end loop;" + }, + { + "function_def": "procedure Day_08 is", + "function_body": "function Count_Pixel(Within: Layer; Value: Pixel) return Natural is\n Total: Natural := 0;\n begin\n for P of Within loop\n if P = Value then Total := Total + 1; end if;\n end loop;\n return Total;\n end Count_Pixel;\n\n package Layer_Vector is new Ada.Containers.Vectors(\n Index_Type => Positive, Element_Type => Layer);\n\n All_Layers: Layer_Vector.Vector;\n Least_Zeroed_Layer: Layer;\n Zero_Count: Natural := Natural'Last;\nbegin\n while not Ada.Text_IO.End_Of_File loop\n declare\n L: Layer;\n Z: Natural;\n begin\n Get_Layer(L);\n Z := Count_Pixel(Within => L, Value => '0');\n if Z < Zero_Count then\n Zero_Count := Z;\n Least_Zeroed_Layer := L;\n end if;\n All_Layers.Append(L);" + }, + { + "function_def": "procedure Day_03 is", + "function_body": "type Point is record\n X, Y: Integer;\n end record;\n\n package Wire_Vec is new Ada.Containers.Vectors(\n Index_Type => Natural, Element_Type => Point);\n\n procedure Append_Comma_Separated_Wire_Points(W: in out Wire_Vec.Vector) is\n Curr: constant Point := W.Last_Element;\n Dir: Character;\n Distance: Natural;\n begin\n Ada.Text_IO.Get(Dir);\n Ada.Integer_Text_IO.Get(Distance);\n case Dir is\n when 'U' =>\n for I in 1 .. Distance loop\n W.Append(Point'(X => Curr.X, Y => Curr.Y + I));\n end loop;\n when 'D' =>\n for I in 1 .. Distance loop\n W.Append(Point'(X => Curr.X, Y => Curr.Y - I));\n end loop;\n when 'R' =>\n for I in 1 .. Distance loop\n W.Append(Point'(X => Curr.X + I, Y => Curr.Y));\n end loop;\n when 'L' =>\n for I in 1 .. Distance loop\n W.Append(Point'(X => Curr.X - I, Y => Curr.Y));\n end loop;\n when others =>\n raise Ada.IO_Exceptions.Data_Error with Character'Image(Dir);\n end case;\n end Append_Comma_Separated_Wire_Points;\n\n function Read_Wire return Wire_Vec.Vector is\n W: Wire_Vec.Vector;\n Comma: Character;\n begin\n W.Append(Point'(0, 0));\n loop\n Append_Comma_Separated_Wire_Points(W);\n exit when Ada.Text_IO.End_Of_Line;\n Ada.Text_IO.Get(Comma);\n end loop;\n return W;\n end Read_Wire;\n\n -- only used in part 1\n -- function Manhattan(P: Point) return Natural is (abs(P.X) + abs(P.Y));\n\n Wire_1: constant Wire_Vec.Vector := Read_Wire;\n Wire_2: constant Wire_Vec.Vector := Read_Wire;\n Min_Dist: Natural := Natural'Last;\nbegin\n for I in Wire_1.First_Index .. Wire_1.Last_Index loop\n declare\n P: constant Point := Wire_1(I);\n J: constant Wire_Vec.Extended_Index := Wire_2.Find_Index(P);\n Dist: constant Natural := I + J;\n begin\n if J /= Wire_Vec.No_Index and Dist > 0 then\n Min_Dist := Natural'Min(Min_Dist, Dist);\n end if;" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E099 := E099 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E111 := E111 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E054 := E054 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n Interfaces.C'Elab_Spec;\n E078 := E078 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E080 := E080 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E008 := E008 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E103 := E103 + 1;\n Ada.Streams'Elab_Spec;\n E101 := E101 + 1;\n System.File_Control_Block'Elab_Spec;\n E115 := E115 + 1;\n System.Finalization_Root'Elab_Spec;\n E114 := E114 + 1;\n Ada.Finalization'Elab_Spec;\n E112 := E112 + 1;\n System.File_Io'Elab_Body;\n E111 := E111 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E099 := E099 + 1;\n E135 := E135 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_demovec\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E099 := E099 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E111 := E111 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E054 := E054 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n Interfaces.C'Elab_Spec;\n E078 := E078 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E080 := E080 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E008 := E008 + 1;\n Ada.Numerics'Elab_Spec;\n E134 := E134 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E103 := E103 + 1;\n Ada.Streams'Elab_Spec;\n E101 := E101 + 1;\n System.File_Control_Block'Elab_Spec;\n E115 := E115 + 1;\n System.Finalization_Root'Elab_Spec;\n E114 := E114 + 1;\n Ada.Finalization'Elab_Spec;\n E112 := E112 + 1;\n System.File_Io'Elab_Body;\n E111 := E111 + 1;\n Ada.Calendar'Elab_Spec;\n Ada.Calendar'Elab_Body;\n E142 := E142 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E099 := E099 + 1;\n System.Random_Seed'Elab_Body;\n E140 := E140 + 1;\n E150 := E150 + 1;\n E136 := E136 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_mainair\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "procedure finalize_library is", + "function_body": "begin\n E099 := E099 - 1;\n declare\n procedure F1;\n pragma Import (Ada, F1, \"ada__text_io__finalize_spec\");\n begin\n F1;" + }, + { + "function_def": "procedure F2;", + "function_body": "pragma Import (Ada, F2, \"system__file_io__finalize_body\");\n begin\n E111 := E111 - 1;\n F2;" + }, + { + "function_def": "procedure Reraise_Library_Exception_If_Any;", + "function_body": "pragma Import (Ada, Reraise_Library_Exception_If_Any, \"__gnat_reraise_library_exception_if_any\");\n begin\n Reraise_Library_Exception_If_Any;" + }, + { + "function_def": "procedure adafinal is", + "function_body": "procedure s_stalib_adafinal;\n pragma Import (Ada, s_stalib_adafinal, \"system__standard_library__adafinal\");\n\n procedure Runtime_Finalize;\n pragma Import (C, Runtime_Finalize, \"__gnat_runtime_finalize\");\n\n begin\n if not Is_Elaborated then\n return;\n end if;\n Is_Elaborated := False;\n Runtime_Finalize;\n s_stalib_adafinal;\n end adafinal;\n\n type No_Param_Proc is access procedure;\n pragma Favor_Top_Level (No_Param_Proc);\n\n procedure adainit is\n Main_Priority : Integer;\n pragma Import (C, Main_Priority, \"__gl_main_priority\");\n Time_Slice_Value : Integer;\n pragma Import (C, Time_Slice_Value, \"__gl_time_slice_val\");\n WC_Encoding : Character;\n pragma Import (C, WC_Encoding, \"__gl_wc_encoding\");\n Locking_Policy : Character;\n pragma Import (C, Locking_Policy, \"__gl_locking_policy\");\n Queuing_Policy : Character;\n pragma Import (C, Queuing_Policy, \"__gl_queuing_policy\");\n Task_Dispatching_Policy : Character;\n pragma Import (C, Task_Dispatching_Policy, \"__gl_task_dispatching_policy\");\n Priority_Specific_Dispatching : System.Address;\n pragma Import (C, Priority_Specific_Dispatching, \"__gl_priority_specific_dispatching\");\n Num_Specific_Dispatching : Integer;\n pragma Import (C, Num_Specific_Dispatching, \"__gl_num_specific_dispatching\");\n Main_CPU : Integer;\n pragma Import (C, Main_CPU, \"__gl_main_cpu\");\n Interrupt_States : System.Address;\n pragma Import (C, Interrupt_States, \"__gl_interrupt_states\");\n Num_Interrupt_States : Integer;\n pragma Import (C, Num_Interrupt_States, \"__gl_num_interrupt_states\");\n Unreserve_All_Interrupts : Integer;\n pragma Import (C, Unreserve_All_Interrupts, \"__gl_unreserve_all_interrupts\");\n Detect_Blocking : Integer;\n pragma Import (C, Detect_Blocking, \"__gl_detect_blocking\");\n Default_Stack_Size : Integer;\n pragma Import (C, Default_Stack_Size, \"__gl_default_stack_size\");\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Bind_Env_Addr : System.Address;\n pragma Import (C, Bind_Env_Addr, \"__gl_bind_env_addr\");\n\n procedure Runtime_Initialize (Install_Handler : Integer);\n pragma Import (C, Runtime_Initialize, \"__gnat_runtime_initialize\");\n\n Finalize_Library_Objects : No_Param_Proc;\n pragma Import (C, Finalize_Library_Objects, \"__gnat_finalize_library_objects\");\n Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n if Is_Elaborated then\n return;\n end if;\n Is_Elaborated := True;\n Main_Priority := -1;\n Time_Slice_Value := -1;\n WC_Encoding := 'b';\n Locking_Policy := ' ';\n Queuing_Policy := ' ';\n Task_Dispatching_Policy := ' ';\n Priority_Specific_Dispatching :=\n Local_Priority_Specific_Dispatching'Address;\n Num_Specific_Dispatching := 0;\n Main_CPU := -1;\n Interrupt_States := Local_Interrupt_States'Address;\n Num_Interrupt_States := 0;\n Unreserve_All_Interrupts := 0;\n Detect_Blocking := 0;\n Default_Stack_Size := -1;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n Runtime_Initialize (1);\n\n Finalize_Library_Objects := finalize_library'access;\n\n Ada.Exceptions'Elab_Spec;\n System.Soft_Links'Elab_Spec;\n System.Exception_Table'Elab_Body;\n E025 := E025 + 1;\n Ada.Containers'Elab_Spec;\n E040 := E040 + 1;\n Ada.Io_Exceptions'Elab_Spec;\n E068 := E068 + 1;\n Ada.Strings'Elab_Spec;\n E052 := E052 + 1;\n Ada.Strings.Maps'Elab_Spec;\n E054 := E054 + 1;\n Ada.Strings.Maps.Constants'Elab_Spec;\n E058 := E058 + 1;\n Interfaces.C'Elab_Spec;\n E078 := E078 + 1;\n System.Exceptions'Elab_Spec;\n E027 := E027 + 1;\n System.Object_Reader'Elab_Spec;\n E080 := E080 + 1;\n System.Dwarf_Lines'Elab_Spec;\n E047 := E047 + 1;\n System.Os_Lib'Elab_Body;\n E072 := E072 + 1;\n System.Soft_Links.Initialize'Elab_Body;\n E021 := E021 + 1;\n E013 := E013 + 1;\n System.Traceback.Symbolic'Elab_Body;\n E039 := E039 + 1;\n E008 := E008 + 1;\n Ada.Numerics'Elab_Spec;\n E134 := E134 + 1;\n Ada.Tags'Elab_Spec;\n Ada.Tags'Elab_Body;\n E103 := E103 + 1;\n Ada.Streams'Elab_Spec;\n E101 := E101 + 1;\n System.File_Control_Block'Elab_Spec;\n E115 := E115 + 1;\n System.Finalization_Root'Elab_Spec;\n E114 := E114 + 1;\n Ada.Finalization'Elab_Spec;\n E112 := E112 + 1;\n System.File_Io'Elab_Body;\n E111 := E111 + 1;\n Ada.Calendar'Elab_Spec;\n Ada.Calendar'Elab_Body;\n E140 := E140 + 1;\n Ada.Text_Io'Elab_Spec;\n Ada.Text_Io'Elab_Body;\n E099 := E099 + 1;\n System.Random_Seed'Elab_Body;\n E138 := E138 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_test\");\n\n function main\n (argc : Integer;\n argv : System.Address;\n envp : System.Address)\n return Integer\n is\n procedure Initialize (Addr : System.Address);\n pragma Import (C, Initialize, \"__gnat_initialize\");\n\n procedure Finalize;\n pragma Import (C, Finalize, \"__gnat_finalize\");\n SEH : aliased array (1 .. 2) of Integer;\n\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n if gnat_argc = 0 then\n gnat_argc := argc;\n gnat_argv := argv;\n end if;\n gnat_envp := envp;\n\n Initialize (SEH'Address);\n adainit;\n Ada_Main_Program;\n adafinal;\n Finalize;\n return (gnat_exit_status);" + }, + { + "function_def": "function Get_Distance(C_act, C_oth : Coord) return Integer is", + "function_body": "begin\n return ((C_oth.x - C_act.x)**2 + (C_oth.y - C_act.y)**2);" + }, + { + "function_def": "function Get_Distance(AirC1,AirC2: Aircraft_Type) return Integer is", + "function_body": "Cord1 : Coord := AirC1.Pos_Airplane;\n Cord2 : Coord := AirC2.Pos_Airplane;\n begin\n return Get_Distance(Cord1,Cord2);\n exception\n when others => return -1;" + }, + { + "function_def": "procedure Main is", + "function_body": "package GL_Double_IO is new Float_IO(GL.Types.Double); \n use GL_Double_IO;\n \n package Natural_IO is new Integer_IO(Natural);\n use Natural_IO;\n \n use GL.Types;\n use GL.Types.Doubles;\n use GL.Fixed.Matrix;\n use GL.Buffers;\n use type GL.Types.Double;\n \n package CRV is new Curve(Base_Real_Type => GL.Types.Double, \n Dimension => 2);\n \n -- Constants\n ------------\n \n D : constant Gl.Types.Double := 4.0; -- Diameter of a drawn point\n WINDOW_WIDTH : constant := 800;\n WINDOW_HEIGHT : constant := 600;\n \n KNOTS_RULER_V_POS : constant Gl.Types.Double := GL.Types.Double(WINDOW_HEIGHT) - 50.0;\n KNOTS_RULER_LEFT_COORDINATE : constant := 100.0;\n KNOTS_RULER_RIGHT_COORDINATE : constant := GL.Types.Double(WINDOW_WIDTH) - 100.0;\n \n -- Types\n --------\n \n type Algorithm_Type is (DE_CASTELIJAU, DE_BOOR, CATMULL_ROM, LAGRANGE_EQUIDISTANT, LAGRANGE_CHEBYSHEV);\n \n subtype Num_Of_Control_Points_Type is Positive range 4 .. 99; -- Minumum 4 because of Catmull-Rom\n subtype Num_Of_Knots_Type is Positive range 1 .. 99;\n \n type Test_Window is new Glfw.Windows.Window with record\n \n Control_Points : CRV.Control_Points_Array(1..Num_Of_Control_Points_Type'Last) := \n (1 => (CRV.X => 10.0, CRV.Y => 100.0),\n 2 => (CRV.X => 11.0, CRV.Y => 121.0),\n 3 => (CRV.X => 15.0, CRV.Y => 225.0),\n 4 => (CRV.X => 17.0, CRV.Y => 289.0),\n 5 => (CRV.X => 20.0, CRV.Y => 400.0),\n 6 => (CRV.X => 21.0, CRV.Y => 441.0),\n 7 => (CRV.X => 22.0, CRV.Y => 484.0),\n 8 => (CRV.X => 100.0, CRV.Y => 484.0),\n 9 => (CRV.X => 150.0, CRV.Y => 484.0),\n 10 => (CRV.X => 250.0, CRV.Y => 484.0),\n others => (CRV.X => 0.0, CRV.Y => 0.0));\n \n -- Note to self - this was bad idea to use static array of maximal size and a sepearte value to \n -- represent it's actual size.\n --\n Num_Of_Control_Points : Num_Of_Control_Points_Type := 10;\n \n Original_X, Original_Y : GL.Types.Double := 0.0;\n Delta_X, Delta_Y : GL.Types.Double := 0.0;\n \n \n Selected_Point, Hovered_Point : Natural := 0;\n \n Algorithm : Algorithm_Type := DE_CASTELIJAU;\n \n Help_Overlay_Required : Boolean := False;\n \n Display_Control_Polygon : Boolean := True;\n \n Knot_Values : CRV.Knot_Values_Array (1 .. Num_Of_Knots_Type'Last) := \n (1 => 0.0, \n 2 => 0.0, \n 3 => 0.0, \n 4 => 0.1, \n 5 => 0.3, \n 6 => 0.5,\n 7 => 0.5,\n 8 => 0.5,\n 9 => 0.7,\n 10 => 0.9,\n 11 => 1.0,\n 12 => 1.0,\n 13 => 1.0,\n others => 0.0);\n \n Num_Of_Knots : Num_Of_Knots_Type := 13; \n \n Selected_Knot, Hovered_Knot : Natural := 0;\n \n Hovered_Ruler : Boolean := False;\n \n end record;\n \n -- Fwd Declared Procedures and Functions\n ------------------------------------\n function Calculate_Knot_H_Pos(Knot_Value : in CRV.Parametrization_Type) return GL.Types.Double;\n function Calculate_Knot_Value(H_Pos : in Glfw.Input.Mouse.Coordinate) return CRV.Parametrization_Type;\n \n function Calculate_B_Spline_Degree return Integer;\n procedure Uniformise_Knot_Vector(V : in out CRV.Knot_Values_Array;\n Degree : in Integer); \n \n -- Overrides\n --------------------------- \n \n overriding\n procedure Init (Object : not null access Test_Window;\n Width, Height : Glfw.Size;\n Title : String;\n Monitor : Glfw.Monitors.Monitor := Glfw.Monitors.No_Monitor;\n Share : access Glfw.Windows.Window'Class := null);\n \n overriding\n procedure Mouse_Position_Changed (Object : not null access Test_Window;\n X, Y : Glfw.Input.Mouse.Coordinate);\n overriding\n procedure Mouse_Button_Changed (Object : not null access Test_Window;\n Button : Glfw.Input.Mouse.Button;\n State : Glfw.Input.Button_State;\n Mods : Glfw.Input.Keys.Modifiers);\n \n overriding\n procedure Key_Changed (Object : not null access Test_Window;\n Key : Glfw.Input.Keys.Key;\n Scancode : Glfw.Input.Keys.Scancode;\n Action : Glfw.Input.Keys.Action;\n Mods : Glfw.Input.Keys.Modifiers);\n \n -- Procedures and Functions\n --------------------------- \n \n procedure Init (Object : not null access Test_Window;\n Width, Height : Glfw.Size;\n Title : String;\n Monitor : Glfw.Monitors.Monitor := Glfw.Monitors.No_Monitor;\n Share : access Glfw.Windows.Window'Class := null) is\n Upcast : Glfw.Windows.Window_Reference\n := Glfw.Windows.Window (Object.all)'Access;\n begin\n Upcast.Init (Width, Height, Title, Monitor, Share);\n Object.Enable_Callback (Glfw.Windows.Callbacks.Mouse_Position);\n Object.Enable_Callback (Glfw.Windows.Callbacks.Mouse_Button);\n Object.Enable_Callback (Glfw.Windows.Callbacks.Key);\n end Init;\n \n procedure Mouse_Position_Changed (Object : not null access Test_Window;\n X, Y : Glfw.Input.Mouse.Coordinate) is\n use GL.Types.Doubles;\n\n use type Glfw.Input.Button_State;\n \n subtype Knot_Index_Type is Positive range 1 .. Object.Num_Of_Knots;\n \n procedure Swap_Knots(Index_1, Index_2 : Knot_Index_Type) is \n Temp : CRV.Parametrization_Type;\n begin\n Temp := Object.Knot_Values(Index_1);\n Object.Knot_Values(Index_1) := Object.Knot_Values(Index_2);\n Object.Knot_Values(Index_2) := temp;" + }, + { + "function_def": "procedure Draw_Help_Overlay is separate;", + "function_body": "-- TODO: Postcondition - not hovered and selected at the same time\n procedure Determine_Hovered_Object is separate;\n\n \n function Calculate_B_Spline_Degree return Integer is\n begin\n return My_Window.Num_Of_Knots - My_Window.Num_Of_Control_Points - 1;" + }, + { + "function_def": "procedure Uniformise_Knot_Vector(V : in out CRV.Knot_Values_Array;", + "function_body": "Degree : in Integer) is\n begin\n if V'Last >= 2*(Degree + 1) then \n \n V(V'First .. V'First + Degree) := (others => 0.0);\n \n for I in 1 .. V'Last - 2*(Degree + 1) loop\n V(V'First + Degree + I) := CRV.Parametrization_Type(\n Float(I) / \n Float(V'Last - 2*(Degree + 1) + 1)\n );\n end loop; \n \n V(V'Last - Degree .. V'Last) := (others => 1.0);\n \n end if;" + }, + { + "function_def": "function Eval_Basis_Poly(J : in Interpolation_Nodes_Index_Type) return Base_Real_Type is", + "function_body": "D : constant Base_Real_Type := (Parametrization_Type'Last - Parametrization_Type'First) / Base_Real_Type(Control_Points'Length - 1);\n \n Numentator : Base_Real_Type := 1.0;\n Denominator : Base_Real_Type := 1.0;\n \n begin\n \n for M in Control_Points'Range loop\n \n if M /= J then\n Numentator := Numentator * ( T - Interpolation_Nodes(M) );\n \n Denominator := Denominator * ( Interpolation_Nodes(J) - Interpolation_Nodes(M) );\n end if;\n \n end loop;\n \n return Numentator / Denominator;\n \n end Eval_Basis_Poly;\n \n begin\n \n for I in Control_Points'Range loop\n \n Result := Result + Control_Points(I) * Eval_Basis_Poly(I);\n \n end loop;\n \n return Result; \n \n end Eval_Lagrange;\n \n \n function Make_Equidistant_Nodes( N : Positive ) return Interpolation_Nodes_Array is \n \n D : constant Base_Real_Type := (Parametrization_Type'Last - Parametrization_Type'First) / Base_Real_Type(N - 1);\n Res : Interpolation_Nodes_Array(1..N);\n \n begin\n \n Res(Res'First) := Parametrization_Type'First;\n \n if N /= 1 then\n \n for I in Res'First + 1 .. Res'Last - 1 loop\n \n Res(I) := Parametrization_Type'First + D * Base_Real_Type(I-1);\n \n end loop;\n \n Res(Res'Last) := Parametrization_Type'Last;\n \n end if;\n \n return Res;" + }, + { + "function_def": "procedure Draw_Help_Overlay is", + "function_body": "begin\n \n if Font_Loaded then\n \n GL.Toggles.Enable(GL.Toggles.Blend);\n GL.Blending.Set_Blend_Func(GL.Blending.Src_Alpha, GL.Blending.One_Minus_Src_Alpha);\n \n declare\n Token : Gl.Immediate.Input_Token := GL.Immediate.Start (Quads);\n begin \n Gl.Immediate.Set_Color (GL.Types.Colors.Color'(0.1, 0.1, 0.1, 0.9));\n \n GL.Immediate.Add_Vertex(Token, Vector2'(0.0, 0.0 ));\n GL.Immediate.Add_Vertex(Token, Vector2'(0.0, Double(WINDOW_HEIGHT)));\n GL.Immediate.Add_Vertex(Token, Vector2'(Double(WINDOW_WIDTH), Double(WINDOW_HEIGHT)));\n GL.Immediate.Add_Vertex(Token, Vector2'(Double(WINDOW_WIDTH), 0.0 ));" + }, + { + "function_def": "procedure Print_Active_Map is", + "function_body": "C: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tEP_Image: ASU.Unbounded_String;\n\tbegin\n\t\tAda.Text_IO.Put_Line (\"ACTIVE CLIENTS\");\n\t\tAda.Text_IO.Put_Line (\"==============\");\n\n\t\twhile Active_Clients.Has_Element(C) loop\n\n\t\t\tEP_Image := ASU.To_Unbounded_String(LLU.Image(Active_Clients.Element\n\t\t\t(C).Value.Client_EP));\n\n\t\t\tAda.Text_IO.Put_Line (ASU.To_String(Active_Clients.Element(C).Key) &\n\t\t\t\" \" &\n\t\t\tASU.To_String(Format_EP(EP_Image)) & \" \" &\n\t\t\tTime_Image(Active_Clients.Element(C).Value.Time));\n\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\t\tATI.New_Line;\n\tend Print_Active_Map;\n\n\tprocedure Print_Old_Map is\n\t\tC: Old_Clients.Cursor := Old_Clients.First(Old_Map);\n\tbegin\n\t\tAda.Text_IO.Put_Line (\"OLD CLIENTS\");\n \t\tAda.Text_IO.Put_Line (\"===========\");\n\n\t\tif not Old_Clients.Has_Element(C) then\n\t\t\tATI.Put_Line(\"Old Clients not Found\");\n\t\tend if;\n\n\t\twhile Old_Clients.Has_Element(C) loop\n\t\t\tAda.Text_IO.Put_Line (ASU.To_String(Old_Clients.Element(C).Value.Nick) &\n\t\t\t\": \" & Time_Image(Old_Clients.Element(C).Value.Time));\n\n\t\t\tOld_Clients.Next(C);\n\tend loop;\n\t\tATI.New_Line;\n\tend Print_Old_Map;\n\n\tfunction Client_To_Ban (Active_Map: Active_Clients.Map) return ASU.Unbounded_String is\n\n\t\tC: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tMin_Time: Ada.Calendar.Time;\n\t\tNick: ASU.Unbounded_String;\n\tbegin\n\t\tMin_Time := Active_Clients.Element(C).Value.Time;\n\t\tNick := Active_Clients.Element(C).Key;\n\t\twhile Active_Clients.Has_Element(C) loop\n\n\t\t\tif Active_Clients.Element(C).Value.Time < Min_Time then\n\n\t\t\t\tMin_Time := Active_Clients.Element(C).Value.Time;\n\t\t\t\tNick := Active_Clients.Element(C).Key;\n\n\t\t\tend if;\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\t\treturn Nick;\n\tend Client_To_Ban;\n\n\tprocedure Server_To_All (Comment: ASU.Unbounded_String;\n\t\t\t \t\t\tO_Buffer: access LLU.Buffer_Type) is\n\n\t\tC: Active_Clients.Cursor := Active_Clients.First(Active_Map);\n\t\tNick: ASU.Unbounded_String := ASU.To_Unbounded_String(\"Server\");\n\n\tbegin\n\t\twhile Active_Clients.Has_Element(C) loop\n\n\t\t\tCM.Server_Message (Active_Clients.Element(C).Value.Client_EP,\n\t\t\tNick,Comment,O_Buffer);\n\n\t\t\tActive_Clients.Next(C);\n\t\tend loop;\n\tend Server_To_All;\n\n\n\t\t\t\t\t\t\t\t-- CHAT CASES --\n\n\tprocedure Case_Init (I_Buffer: access LLU.Buffer_Type;\n\t\t\t \t\t\tO_Buffer: access LLU.Buffer_Type) is\n\n\t\tClient_EP_Receive:\tLLU.End_Point_Type;\n\t\tClient_EP_Handler:\tLLU.End_Point_Type;\n\t\tNick: \t\t \t\tASU.Unbounded_String;\n\t\tBan_Nick: \t \t\tASU.Unbounded_String;\n\t\tComment: \t \t\tASU.Unbounded_String;\n\t\tClient_Data: \t Data;\n\t\tOld_Client:\t\t\tOld_Data;\n\t\tAccepted: \t \tBoolean;\n\t\tSuccess: \t \t\tBoolean;\n\t\tBan_Message:\t\tASU.Unbounded_String;\n\tbegin\n\n\t\tClient_EP_Receive := LLU.End_Point_Type'Input (I_Buffer);\n\t\tClient_EP_Handler := LLU.End_Point_Type'Input (I_Buffer);\n\t\tNick := ASU.Unbounded_String'Input (I_Buffer);\n\n\t\tActive_Clients.Get(Active_Map,Nick,Client_Data,Success);\n\n\t\tif Success then\n\t\t\tAccepted := False;\n\t\t\tATI.Put_Line(\"INIT received from \" & ASU.To_String(Nick)\n\t\t\t& \": IGNORED. nick already used\");\n\t\telse\n\t\t\tATI.Put_Line(\"INIT received from \" & ASU.To_String(Nick)\n\t\t\t& \": ACCEPTED\");\n\t\t\tbegin\n\t\t\t\tAccepted := True;\n\t\t\t\tClient_Data.Client_EP := Client_EP_Handler;\n\t\t\t\tClient_Data.Time := Ada.Calendar.Clock;\n\n\t\t\t\tOld_Clients.Get(Old_Map,Nick_to_Integer(Nick),Old_Client,Success);\n\t\t\t\tif Success then\n\t\t\t\t\tOld_Clients.Delete (Old_Map,Nick_to_Integer(Nick),Success);\n\t\t\t\t\tComment := ASU.To_Unbounded_String(ASU.To_String(Nick) &\n\t\t\t\t\t\" rejoins the chat\");\n\t\t\t\telse\n\t\t\t\t\tComment := ASU.To_Unbounded_String(ASU.To_String(Nick) &\n\t\t\t\t\t\" joins the chat\");\n\t\t\t\tend if;\n\n\t\t\t\tActive_Clients.Put (Active_Map,Nick,Client_Data);\n\n\t\t\t\t-- Automatic := True\n\t\t\t\tSend_To_Readers (True,Nick,Comment,O_Buffer);\n\n\t\t\texception\n\t\t\t\twhen Active_Clients.Full_Map =>\n\n\t\t\t\t\tBan_Nick := Client_To_Ban(Active_Map);\n\t\t\t\t\tOld_Client.Nick := Ban_Nick;\n\t\t\t\t\tOld_Client.Time := Ada.Calendar.Clock;\n\n\t\t\t\t\tOld_Clients.Put (Old_Map,Nick_to_Integer(Ban_Nick),Old_Client);\n\n\t\t\t\t\tBan_Message := ASU.To_Unbounded_String(ASU.To_String(Ban_Nick)\n\t\t\t\t\t & \" banned for being idle too long\");\n\n\t\t\t\t\tServer_To_All (Ban_Message,O_Buffer);\n\n\t\t\t\t\tActive_Clients.Delete (Active_Map,Ban_Nick,Success);\n\n\t\t\t\t\tActive_Clients.Put (Active_Map,Nick,Client_Data);\n\n\t\t\t\t\t-- Automatic := True\n\t\t\t\t\tSend_To_Readers (True,Nick,Comment,O_Buffer);" + }, + { + "function_def": "procedure Unknown_Fail is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"unknown\", 1_984);\n Fail (Message => \"Exception expected\");\n\n exception\n when Error : BaseXException =>\n null;\n\n end Unknown_Fail;\n\n procedure Port_Fail is\n\n result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_985);\n Fail (Message => \"Exception expected\");\n\n exception\n when Error : BaseXException =>\n null;\n\n end Port_Fail;\n\n procedure Connect_Auth is\n\n result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"unknown\", \"test\");\n Assert (Condition => result = False, Message => \"Auth test\");\n\n Close;\n\n end Connect_Auth;\n\n procedure Connect_Pass is\n\n result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n Close;\n\n end Connect_Pass;\n\n procedure Execute_Test is\n\n result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : String := Execute (\"xquery 1+1\");\n begin\n Assert (Condition => Response = \"2\", Message => \"Execute test\");" + }, + { + "function_def": "procedure Execute_Fail is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : String := Execute (\"xquery unknown\");\n begin\n Fail (Message => \"Exception expected\");" + }, + { + "function_def": "procedure Create_Drop is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : String := Create (\"database\", \"Hello World!\");\n begin\n null;" + }, + { + "function_def": "procedure Add_Test is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : String := Create (\"database\", \"\");\n begin\n null;" + }, + { + "function_def": "procedure Replace_Test is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : String := Create (\"database\", \"\");\n begin\n null;" + }, + { + "function_def": "procedure Query_Test is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : Query := CreateQuery (\"1+1\");\n V : String_Vectors.Vector;\n begin\n V := Response.Results;\n Assert (Condition => V (0) = \"2\", Message => \"Query test\");\n\n Response.Close;" + }, + { + "function_def": "procedure Query_Bind is", + "function_body": "result : Boolean;\n\n begin\n result := Connect (\"localhost\", 1_984);\n Assert (Condition => result = True, Message => \"Connect test\");\n\n result := Authenticate (\"admin\", \"admin\");\n Assert (Condition => result = True, Message => \"Auth test\");\n\n declare\n Response : Query :=\n CreateQuery\n (\"declare variable $name external; for $i in 1 to 1 return element { $name } { $i }\");\n begin\n Response.Bind (\"name\", \"number\", \"\");\n declare\n Res : String := Response.Execute;\n begin\n Assert\n (Condition => Res = \"1\",\n Message => \"Query bind\");" + }, + { + "function_def": "procedure QueryExample is", + "function_body": "V: String_Vectors.Vector;\n\nbegin\n\n if (Connect (\"localhost\", 1_984) = False) then\n Ada.Text_IO.Put_Line (\"Connect failed.\");\n return;\n else\n if (Authenticate (\"admin\", \"admin\") = False) then\n Ada.Text_IO.Put_Line (\"Authenticate failed.\");\n\n Close;\n return;\n end if;\n end if;\n\n declare\n Response : Query := CreateQuery (\"for $i in 1 to 10 return Text { $i }\");\n begin\n V := Response.Results;\n for E of V loop\n Put_Line (E);\n end loop;\n\n Response.Close;" + }, + { + "function_def": "procedure ExampleAdd is", + "function_body": "begin\n\n if (Connect (\"localhost\", 1_984) = False) then\n Ada.Text_IO.Put_Line (\"Connect failed.\");\n return;\n else\n if (Authenticate (\"admin\", \"admin\") = False) then\n Ada.Text_IO.Put_Line (\"Authenticate failed.\");\n\n Close;\n return;\n end if;\n end if;\n\n declare\n Response : String := Execute (\"create db database\");\n begin\n Ada.Text_IO.Put_Line (Response);" + }, + { + "function_def": "procedure Example is", + "function_body": "begin\n\n if (Connect (\"localhost\", 1_984) = False) then\n Ada.Text_IO.Put_Line (\"Connect failed.\");\n return;\n else\n if (Authenticate (\"admin\", \"admin\") = False) then\n Ada.Text_IO.Put_Line (\"Authenticate failed.\");\n\n Close;\n return;\n end if;\n end if;\n\n declare\n Response : String := Execute (\"xquery 1 to 10\");\n begin\n Ada.Text_IO.Put_Line (Response);" + }, + { + "function_def": "procedure QueryExample is", + "function_body": "begin\n\n if (Connect (\"localhost\", 1_984) = False) then\n Ada.Text_IO.Put_Line (\"Connect failed.\");\n return;\n else\n if (Authenticate (\"admin\", \"admin\") = False) then\n Ada.Text_IO.Put_Line (\"Authenticate failed.\");\n\n Close;\n return;\n end if;\n end if;\n\n declare\n Response : Query :=\n CreateQuery\n (\"declare variable $name external; for $i in 1 to 10 return element { $name } { $i }\");\n begin\n Response.Bind (\"name\", \"number\", \"\");\n Ada.Text_IO.Put_Line (Response.Execute);\n Response.Close;" + }, + { + "function_def": "procedure ExampleCreate is", + "function_body": "begin\n\n if (Connect (\"localhost\", 1_984) = False) then\n Ada.Text_IO.Put_Line (\"Connect failed.\");\n return;\n else\n if (Authenticate (\"admin\", \"admin\") = False) then\n Ada.Text_IO.Put_Line (\"Authenticate failed.\");\n\n Close;\n return;\n end if;\n end if;\n\n declare\n Response : String := Create (\"database\", \"Hello World!\");\n begin\n Ada.Text_IO.Put_Line (Response);" + }, + { + "function_def": "procedure UART_429Disco is", + "function_body": "UART_Port: GPIO_Registers renames GPIOA;\n\tUART_TX_Bit: constant Port_Bit_Number := 9;\n\tUART_RX_Bit: constant Port_Bit_Number := 10;\n\n\tAPB2_Frequency : constant := 90_000_000; -- Set by board support\n\tBaud_Rate : constant := 115_200;\n\tRatio : constant := (APB2_Frequency + Baud_Rate / 2) / Baud_Rate;\n\t--Ratio : constant := 128;\n\n\tPeriod: constant Time_Span := Milliseconds(10);\n\tNow: Time := Clock;\n\n\nbegin\n\t-- clock test\n\n\t--RCC.CFGR.HPRE := AHB_Prescaler_1;\n\t--RCC.CFGR.PPRE2 := APB_Prescaler_2;\n\n\t\n\tRCC.AHB1ENR.GPIOC := True;\n\tRCC.CFGR.MCO2PRE := MCO_Prescaler_5;\n\tRCC.CFGR.MCO2 := Clock_Output_2_SYSCLK;\n\t\n\tGPIOC.OTYPER(9) := Push_Pull_Type;\n\tGPIOC.OSPEEDR(9) := Very_High_Speed;\n\tGPIOC.AFR(9) := Alternate_Functions.SYS;\n\tGPIOC.MODER(9) := Alternate_Mode;\n\n\tRCC.AHB1ENR.GPIOA := True;\n\n\n\tRCC.APB2ENR.USART1 := True;\n\n\tRCC.APB2RSTR.USART1 := True;\n\n\tRCC.APB2RSTR.USART1 := False;\n\t\n\n\t--\n\n\tUART_Port.OTYPER(UART_TX_Bit) := Push_Pull_Type;\n\tUART_Port.OSPEEDR(UART_TX_Bit) := Very_High_Speed;\n\tUART_Port.PUPDR(UART_TX_Bit) := Pull_Down;\n\tUART_Port.AFR(UART_TX_Bit) := Alternate_Functions.USART1;\n\tUART_Port.MODER(UART_TX_Bit) := Alternate_Mode;\n\n\tUART_Port.OTYPER(UART_RX_Bit) := Push_Pull_Type;\n\tUART_Port.OSPEEDR(UART_RX_Bit) := Very_High_Speed;\n\tUART_Port.PUPDR(UART_RX_Bit) := No_Pull;\n\tUART_Port.AFR(UART_RX_Bit) := Alternate_Functions.USART1;\n\tUART_Port.MODER(UART_RX_Bit) := Alternate_Mode;\n\n\t-- UART initialisation (close to ST's HAL)\n\n\tUSART1.CR1.UE := False;\n\n\n\tdeclare\n\t\tCR1: Control_Register_1 := USART1.CR1;\n\tbegin\n\t\tCR1.M := Word_8_Bits;\n\t\tCR1.PCE := False;\n\t\tCR1.PS := Even_Parity;\n\t\tCR1.TE := True;\n\t\tCR1.RE := True;\n\t\tCR1.OVER8 := False;\n\t\t\n\t\tUSART1.CR1 := CR1;" + }, + { + "function_def": "function Next_Sample_Pulse_And_Noise", + "function_body": "(Chan : in out Channel;\n Sample_Rate : Positive)\n return Sample\n with Inline;\n\n function Next_Sample_Triangle\n (Chan : in out Channel;\n Sample_Rate : Positive)\n return Sample\n with Inline;\n\n procedure Process_Seq (This : in out Instance;\n Chan_Id : Channel_ID);\n\n -----------------------\n -- Period_In_Samples --\n -----------------------\n\n function Period_In_Samples (Sample_Rate : Positive;\n Rate_In_Hertz : Frequency)\n return Float\n is (Float (Sample_Rate) / Float (Rate_In_Hertz))\n with Inline;\n\n ---------------------------------\n -- Next_Sample_Pulse_And_Noise --\n ---------------------------------\n\n function Next_Sample_Pulse_And_Noise\n (Chan : in out Channel;\n Sample_Rate : Positive)\n return Sample\n is\n Delta_Time : Float;\n Width : Float;\n Next_State : BLIT_State := Down;\n begin\n Chan.CSample_Nb := Chan.CSample_Nb + 1;\n\n -- If it is time, compute the next BLIT step\n if Chan.Next_Impulse_Time <= Chan.CSample_Nb then\n\n if Chan.State = Up then\n Width := Chan.Width;\n else\n Width := 1.0 - Chan.Width;\n end if;\n\n Delta_Time := Period_In_Samples (Sample_Rate, Chan.Freq) * Width +\n Chan.Next_Impulse_Phase;\n\n Chan.Next_Impulse_Time := Chan.Next_Impulse_Time +\n Natural (Float'Floor (Delta_Time));\n\n Chan.Next_Impulse_Phase := Delta_Time - Float'Floor (Delta_Time);\n\n case Chan.Mode is\n when Pulse =>\n\n -- Invert the state\n Next_State := (if Chan.State = Up then Down else Up);\n\n when Noise_1 | Noise_2 =>\n\n -- Next state depends on LFSR noise\n declare\n B0 : constant Unsigned_16 := Chan.LFSR and 1;\n B1 : constant Unsigned_16 := Shift_Right (Chan.LFSR, 1) and 1;\n B6 : constant Unsigned_16 := Shift_Right (Chan.LFSR, 6) and 1;\n Feedback : Unsigned_16;\n begin\n if Chan.Mode = Noise_1 then\n Feedback := B0 xor B1;\n else\n Feedback := B0 xor B6;\n end if;\n\n Next_State := (if B0 = 0 then Down else Up);\n\n Chan.LFSR := Shift_Right (Chan.LFSR, 1);\n\n if (Feedback and 1) /= 0 then\n Chan.LFSR := Chan.LFSR or 16#4000#;\n else\n Chan.LFSR := Chan.LFSR and not 16#4000#;\n end if;" + }, + { + "function_def": "function From_Sample is new To_Int (Int_T);", + "function_body": "begin\n for Elt of Buffer loop\n Elt := From_Sample (This.Next_Sample);\n end loop;\n end Next_Samples_Int;\n\n -----------------------\n -- Next_Samples_UInt --\n -----------------------\n\n procedure Next_Samples_UInt (This : in out Instance;\n Buffer : out Buffer_T)\n is\n function From_Sample is new To_UInt (UInt_T);\n begin\n for Elt of Buffer loop\n Elt := From_Sample (This.Next_Sample);\n end loop;\n end Next_Samples_UInt;\n\n -----------------\n -- Process_Seq --\n -----------------\n\n procedure Process_Seq (This : in out Instance;\n Chan_Id : Channel_ID)\n is\n Chan : Channel renames This.Channels (Chan_Id);\n begin\n if Chan.Seq_Remaining_Ticks /= 0 then\n Chan.Seq_Remaining_Ticks := Chan.Seq_Remaining_Ticks - 1;\n end if;\n\n if Chan.Seq_Remaining_Ticks = 0 then\n while Chan.Seq_Index in Chan.Seq'Range loop\n declare\n Cmd : Command renames Chan.Seq (Chan.Seq_Index);\n begin\n case Cmd.Kind is\n\n when Wait_Ticks =>\n Chan.Seq_Remaining_Ticks := Cmd.Ticks;\n\n when Wait_Note =>\n Chan.Seq_Remaining_Ticks :=\n Tick_Count ((60.0 / Float (Chan.BPM)) *\n Float (Chan.Ticks_Per_Second) *\n (case Cmd.Note is\n when Large => 8.0,\n when Long => 4.0,\n when Double => 2.0,\n when Whole => 1.0,\n when Half => 0.5,\n when Quarter => 0.25,\n when N_8th => 0.125,\n when N_16th => 0.0625,\n when N_32nd => 0.0312,\n when N_64th => 0.015625,\n when N_128th => 0.0078125,\n when N_256th => 0.0039062));\n\n when Note_On =>\n Note_On (This, Chan_Id, Cmd.Freq);\n\n when Note_Off =>\n Note_Off (This, Chan_Id);\n\n when Set_Decay =>\n Set_Decay (This, Chan_Id, Cmd.Decay_Ticks);\n\n when Set_Sweep =>\n Set_Sweep (This, Chan_Id,\n Cmd.Sweep,\n Cmd.Sweep_Len,\n Cmd.Sweep_Ticks);\n\n when Set_Volume =>\n Set_Volume (This, Chan_Id, Cmd.Vol);\n\n when Set_Mode =>\n Set_Mode (This, Chan_Id, Cmd.Mode);\n\n when Set_Width =>\n Set_Width (This, Chan_Id, Cmd.Width);\n\n end case;" + }, + { + "function_def": "procedure tsp is", + "function_body": "package random_num is new ada.numerics.discrete_random (integer);\n use random_num;\n g : generator;\n --total number of population\n population_size : integer := 1000;\n --length of gene = number of node \n gene_length : integer := 15;\n max_dist:integer := 40;\n min_dist:integer := 10;\n mutation_rate:integer:=100;\n Task_number : integer;\n Task_Load : integer;\n type gene is array (integer range 1..gene_length) of integer range 1..gene_length;\n type map_row is array (integer range 1..gene_length) of integer;\n\t--use parent(i)(j) to access parent[i][j]\n type container is array(integer range 1..population_size) of gene;\n parent : container;\n childarray :container;\n\t--use map(i)(j) to access map[i][j]\n map : array(integer range 1..gene_length) of map_row;\n\n fitness : array(integer range 1..population_size) of integer;\n --generate random map\n procedure generate_map is\n begin\n for i in 1..gene_length loop\n for j in i..gene_length loop\n map(i)(j) := (random(g) mod max_dist-min_dist+1)+min_dist;\n map(j)(i) := map(i)(j);\n if i=j then\n map(i)(j) := 0;\n end if; \n end loop;\n end loop;\n end generate_map;\n \n\t--generate first generation\n procedure generate_first is \n rand_pos : integer; \n temp :integer;\n arr : gene;\n begin\n for i in 1..population_size loop\n for j in 1..gene_length loop\n arr(j):=j;\n end loop;\n for j in 1..gene_length loop\n rand_pos := (random(g) mod (gene_length-j+1)) + 1;\n parent(i)(j) := arr(rand_pos);\n temp := arr(gene_length-j+1);\n arr(gene_length-j+1) := arr(rand_pos);\n arr(rand_pos) := temp;\n end loop;\n end loop;\n end generate_first;\n\n function selection return integer is\n sum : integer := 0;\n rand : integer;\n begin\n for i in 1..population_size loop\n sum:=sum+10000/fitness(i);\n end loop;\n rand := (random(g) mod sum) + 1;\n sum := 0;\n for i in 1..population_size loop\n sum:=sum+10000/fitness(i);\n if sum >= rand then\n return i; \n end if;\n end loop;\n return (population_size);\n end selection;\n\n procedure crossover(c_i:integer) is\n p:integer;\n longest:integer:=1;\n tmp:integer;\n r1:integer;\n r2:integer;\n begin\n p:=selection;\n for i in 1..gene_length-1 loop\n if map(parent(p)(i))(parent(p)(i+1)) > map(parent(p)(longest))(parent(p)(longest+1)) then\n longest:=i;\n end if;\n end loop;\n for i in 1..gene_length loop\n if i + longest <= gene_length then \n childarray(c_i)(i):=parent(p)(i+longest);\n else\n childarray(c_i)(i):=parent(p)((i+longest)mod gene_length);\n end if;\n end loop;\n \n if random(g) mod mutation_rate = 1 then\n r1:=random(g) mod gene_length +1;\n r2:=random(g) mod gene_length +1;\n tmp:=childarray(c_i)(r1);\n childarray(c_i)(r1):=childarray(c_i)(r2);\n childarray(c_i)(r2):=tmp;\n end if;\n end crossover;\n\n procedure arrayAtoArrayB(A : in container;B : out container) is\n begin\n for i in 1 .. population_size loop\n for j in 1 .. gene_length loop\n B(i)(j) :=A(i)(j);\n end loop;\n end loop;\n end arrayAtoArrayB;\n\n t_start:time;\n t_end:time;\n t_exe:duration;\n package Duration_IO is new Fixed_IO(Duration);\n\n\n\n -------------------------------------------------------------- \n\n\t\n\ttask type T is\n\t\tentry Compute_Fitness(i : integer);\n\tend T;\n\t\n\n\ttask body T is\n routine : integer;\n loop_number : integer;\n current_i : integer;\n\tbegin\n\t\t\n\t\taccept Compute_Fitness(i : integer) do\n current_i := i-1;\n end Compute_Fitness;\n loop_number := (Task_Load*(current_i))+1;\n\t\tfor k in loop_number..(loop_number+Task_Load-1) loop\n \troutine := 0;\n\t\t\tfor j in 1..(gene_length-1) loop\n\t\t\t\troutine := routine + map(parent(k)(j))(parent(k)(j+1));\n\t\t\tend loop;\n\t\t fitness(k) := routine;\n delay(0.001);\n end loop;\n \n\tend T;\n \n final_result :integer :=0;\n n : integer :=0;\n fit : integer :=1;\n tmp :integer :=0;\n result :integer :=0;\n taskComplete : integer := 0;\n best :integer:=5000;\n end_condition:integer;\n\t---------------------------\n\n function condition return integer is\n answer :integer :=0;\n begin\n for i in 1..(population_size-1) loop\n fit := fitness(i);\n if fitness(i+1)<=fitness(i) then\n fit := fitness(i+1);\n end if;\n end loop;\n if fitend_condition/4 then \n mutation_rate := 75;\n end if;\n if n>end_condition/2 then \n mutation_rate := 50;\n end if;\n if n>3*end_condition/4 then \n mutation_rate := 10;\n end if;\n if n>=end_condition then\n answer:=1;\n else \n answer:=0;\n end if;\n return answer;\n end condition;\n --------------------------- \n generation:integer:=1;\nbegin\n put(\"End condition : \");\n get(end_condition);\n put(\"Number of threads : \");\n get(Task_number);\n new_line;\n Task_Load:= population_size/Task_number;\n t_start:=clock;\n reset(g);\n generate_first;\n generate_map;\n ----------------------------- start find the route\n Find_route:\n loop\n declare\n Mul_Task : array(1..Task_number) of T; \n begin\n --------------------------------\n for i in 1..Task_number loop\n Mul_Task(i).Compute_Fitness(i);\n end loop;\n\n loop\n taskComplete:=0;\n for i in 1..Task_number loop\n if Mul_Task(i)'Terminated then\n taskComplete:=taskComplete+1;\n end if;\n end loop;\n if taskComplete = Task_number then \n exit;\n end if;\n end loop;\n\n result:=condition;\n final_result := fit;\n put(generation,5);\n put(\" th generation shortest length : \"); \n put(final_result,3);\n put(\" Current shortest length : \");\n put(best,3);\n new_line;\n generation:=generation+1;\n exit Find_route when result=1; \n \n --arrayAtoArrayB(parent,childarray);\n for i in 1..population_size loop\n --childgenerate;\n crossover(i);\n end loop;\n arrayAtoArrayB(childarray,parent);\n \n ------------------------------------------" + }, + { + "function_def": "function Intel_32 is new Intel_x86_buffer( Unsigned_32, 4 );", + "function_body": "function Intel_16( n: Unsigned_16 ) return Byte_buffer is\n pragma Inline(Intel_16);\n begin\n return (Unsigned_8(n and 255), Unsigned_8(Shift_Right(n, 8)));\n end Intel_16;\n\n -- 2.5.2 Byte Strings, 8-bit string length (BIFF2-BIFF5), p. 187\n function To_buf_8_bit_length(s: String) return Byte_buffer is\n b: Byte_buffer(s'Range);\n begin\n if s'Length > 255 then -- length doesn't fit in a byte\n raise Constraint_Error;\n end if;\n for i in b'Range loop\n b(i):= Character'Pos(s(i));\n end loop;\n return Unsigned_8(s'Length) & b;\n end To_buf_8_bit_length;\n\n -- 2.5.2 Byte Strings, 16-bit string length (BIFF2-BIFF5), p. 187\n function To_buf_16_bit_length(s: String) return Byte_buffer is\n b: Byte_buffer(s'Range);\n begin\n if s'Length > 2**16-1 then -- length doesn't fit in a 16-bit number\n raise Constraint_Error;\n end if;\n for i in b'Range loop\n b(i):= Character'Pos(s(i));\n end loop;\n return Intel_16(s'Length) & b;\n end To_buf_16_bit_length;\n\n -- -- 2.5.3 Unicode Strings, 16-bit string length (BIFF2-BIFF5), p. 17\n -- function To_buf_16_bit_length(s: Wide_String) return Byte_buffer is\n -- b: Byte_buffer(1 .. 2 * s'Length);\n -- j: Integer:= 1;\n -- begin\n -- if s'Length > 2**16-1 then -- length doesn't fit in a 16-bit number\n -- raise Constraint_Error;\n -- end if;\n -- for i in s'Range loop\n -- b(j) := Unsigned_8(Unsigned_32'(Wide_Character'Pos(s(i))) and 255);\n -- b(j+1):= Unsigned_8(Shift_Right(Unsigned_32'(Wide_Character'Pos(s(i))), 8));\n -- j:= j + 2;\n -- end loop;\n -- return\n -- Intel_16(s'Length) &\n -- (1 => 1) & -- Character compression (ccompr): 1 = Uncompressed (16-bit characters)\n -- b;\n -- end To_buf_16_bit_length;\n\n -- Gives a byte sequence of an IEEE 64-bit number as if taken\n -- from an Intel machine (i.e. with the same endianess).\n --\n -- http://en.wikipedia.org/wiki/IEEE_754-1985#Double-precision_64_bit\n --\n\n package IEEE_LF is new IEEE_754.Generic_Double_Precision (Long_Float);\n\n function IEEE_Double_Intel_Portable(x: Long_Float) return Byte_buffer is\n pragma Inline(IEEE_Double_Intel_Portable);\n d : Byte_buffer(1..8);\n --\n f64: constant IEEE_LF.Float_64:= IEEE_LF.To_IEEE(x);\n begin\n for i in d'Range loop\n d(i):= f64(9-i); -- Order is reversed\n end loop;\n -- Fully tested in Test_IEEE.adb\n return d;\n end IEEE_Double_Intel_Portable;\n\n -- Just spit the bytes of the long float - fast way.\n -- Of course this will work only on an Intel(-like) machine. We check this later.\n subtype Byte_buffer_8 is Byte_buffer(0..7);\n function IEEE_Double_Intel_Native is new\n Ada.Unchecked_Conversion(Long_Float, Byte_buffer_8);\n\n x_test: constant Long_Float:= -12345.0e-67;\n Can_use_native_IEEE: constant Boolean:=\n IEEE_Double_Intel_Portable(x_test) = IEEE_Double_Intel_Native(x_test);\n\n function IEEE_Double_Intel(x: Long_Float) return Byte_buffer is\n pragma Inline(IEEE_Double_Intel);\n begin\n if Can_use_native_IEEE then\n return IEEE_Double_Intel_Native(x); -- Fast, non-portable\n else\n return IEEE_Double_Intel_Portable(x); -- Slower but portable\n end if;\n end IEEE_Double_Intel;\n\n -- Workaround for the severe xxx'Read xxx'Write performance\n -- problems in the GNAT and ObjectAda compilers (as in 2009)\n -- This is possible if and only if Byte = Stream_Element and\n -- arrays types are both packed and aligned the same way.\n --\n subtype Size_test_a is Byte_buffer(1..19);\n subtype Size_test_b is Ada.Streams.Stream_Element_Array(1..19);\n workaround_possible: constant Boolean:=\n Size_test_a'Size = Size_test_b'Size and\n Size_test_a'Alignment = Size_test_b'Alignment;\n\n procedure Block_Write(\n stream : in out Ada.Streams.Root_Stream_Type'Class;\n buffer : in Byte_buffer\n )\n is\n pragma Inline(Block_Write);\n SE_Buffer : Stream_Element_Array (1 .. buffer'Length);\n for SE_Buffer'Address use buffer'Address;\n pragma Import (Ada, SE_Buffer);\n begin\n if workaround_possible then\n Ada.Streams.Write(stream, SE_Buffer);\n else\n Byte_buffer'Write(stream'Access, buffer);\n -- ^ This was 30x to 70x slower on GNAT 2009\n -- Test in the Zip-Ada project.\n end if;\n end Block_Write;\n\n ----------------\n -- Excel BIFF --\n ----------------\n\n -- The original Modula-2 code counted on certain assumptions about\n -- record packing & endianess. We write data without these assumptions.\n\n procedure WriteBiff(\n xl : Excel_Out_Stream'Class;\n biff_id: Unsigned_16;\n data : Byte_buffer\n )\n is\n pragma Inline(WriteBiff);\n begin\n Block_Write(xl.xl_stream.all, Intel_16(biff_id));\n Block_Write(xl.xl_stream.all, Intel_16(Unsigned_16(data'Length)));\n Block_Write(xl.xl_stream.all, data);\n end WriteBiff;\n\n -- 5.8 BOF: Beginning of File, p.135\n procedure Write_BOF(xl : Excel_Out_Stream'Class) is\n\n function BOF_suffix return Byte_buffer is -- 5.8.1 Record BOF\n begin\n case xl.format is\n when BIFF2 =>\n return empty_buffer;\n when BIFF3 | BIFF4 =>\n return (0,0); -- Not used\n -- when BIFF8 =>\n -- return (1,1,1,1);\n end case;\n end BOF_suffix;\n\n -- 0005H = Workbook globals\n -- 0006H = Visual Basic module\n -- 0010H = Sheet or dialogue (see SHEETPR, S5.97)\n Sheet_or_dialogue: constant:= 16#10#;\n -- 0020H = Chart\n -- 0040H = Macro sheet\n biff_record_identifier: constant array(Excel_type) of Unsigned_16:=\n (BIFF2 => 16#0009#,\n BIFF3 => 16#0209#,\n BIFF4 => 16#0409#\n -- BIFF8 => 16#0809#\n );\n biff_version: constant array(Excel_type) of Unsigned_16:=\n (BIFF2 => 16#0200#,\n BIFF3 => 16#0300#,\n BIFF4 => 16#0400#\n -- BIFF8 => 16#0600#\n );\n begin\n WriteBiff(xl,\n biff_record_identifier(xl.format),\n Intel_16(biff_version(xl.format)) &\n Intel_16(Sheet_or_dialogue) &\n BOF_suffix\n );\n end Write_BOF;\n\n -- 5.49 FORMAT (number format)\n procedure WriteFmtStr (xl : Excel_Out_Stream'Class; s : String) is\n begin\n case xl.format is\n when BIFF2 | BIFF3 =>\n WriteBiff(xl, 16#001E#, To_buf_8_bit_length(s));\n when BIFF4 =>\n WriteBiff(xl, 16#041E#, (0, 0) & To_buf_8_bit_length(s));\n -- when BIFF8 =>\n -- WriteBiff(xl, 16#041E#, (0, 0) & -- should be: format index used in other records\n -- To_buf_8_bit_length(s));\n end case;\n end WriteFmtStr;\n\n -- Write built-in number formats (internal)\n procedure WriteFmtRecords (xl : Excel_Out_Stream'Class) is\n sep_1000: constant Character:= ','; -- US format\n sep_deci: constant Character:= '.'; -- US format\n -- ^ If there is any evidence of an issue with those built-in separators,\n -- we may make them configurable. NB: MS Excel 2002 and 2007 use only\n -- the index of built-in formats and discards the strings for BIFF2, but not for BIFF3...\n begin\n -- 5.12 BUILTINFMTCOUNT\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#001F#, Intel_16(Unsigned_16(last_built_in - 5)));\n when BIFF3 =>\n WriteBiff(xl, 16#0056#, Intel_16(Unsigned_16(last_built_in - 3)));\n when BIFF4 =>\n WriteBiff(xl, 16#0056#, Intel_16(Unsigned_16(last_built_in + 1)));\n -- when BIFF8 =>\n -- null;\n end case;\n -- loop & case avoid omitting any choice\n for n in Number_format_type'First .. last_custom loop\n case n is\n when general => WriteFmtStr(xl, \"General\");\n when decimal_0 => WriteFmtStr(xl, \"0\");\n when decimal_2 => WriteFmtStr(xl, \"0\" & sep_deci & \"00\"); -- 'Comma' built-in style\n when decimal_0_thousands_separator =>\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0\");\n when decimal_2_thousands_separator =>\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0\" & sep_deci & \"00\");\n when no_currency_0 =>\n if xl.format >= BIFF4 then\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0;-#\" & sep_1000 & \"##0\");\n end if;\n when no_currency_red_0 =>\n if xl.format >= BIFF4 then\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0;-#\" & sep_1000 & \"##0\");\n -- [Red] doesn't go with non-English versions of Excel !!\n end if;\n when no_currency_2 =>\n if xl.format >= BIFF4 then\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0\" & sep_deci & \"00;\" &\n \"-#\" & sep_1000 & \"##0\" & sep_deci & \"00\");\n end if;\n when no_currency_red_2 =>\n if xl.format >= BIFF4 then\n WriteFmtStr(xl, \"#\" & sep_1000 & \"##0\" & sep_deci & \"00;\" &\n \"-#\" & sep_1000 & \"##0\" & sep_deci & \"00\");\n end if;\n when currency_0 =>\n WriteFmtStr(xl, \"$ #\" & sep_1000 & \"##0;$ -#\" & sep_1000 & \"##0\");\n when currency_red_0 =>\n WriteFmtStr(xl, \"$ #\" & sep_1000 & \"##0;$ -#\" & sep_1000 & \"##0\");\n -- [Red] doesn't go with non-English versions of Excel !!\n when currency_2 =>\n WriteFmtStr(xl, \"$ #\" & sep_1000 & \"##0\" & sep_deci & \"00;\" &\n \"$ -#\" & sep_1000 & \"##0\" & sep_deci & \"00\");\n when currency_red_2 =>\n WriteFmtStr(xl, \"$ #\" & sep_1000 & \"##0\" & sep_deci & \"00;\" &\n \"$ -#\" & sep_1000 & \"##0\" & sep_deci & \"00\");\n when percent_0 => WriteFmtStr(xl, \"0%\"); -- 'Percent' built-in style\n when percent_2 => WriteFmtStr(xl, \"0\" & sep_deci & \"00%\");\n when scientific => WriteFmtStr(xl, \"0\" & sep_deci & \"00E+00\");\n when fraction_1 =>\n if xl.format >= BIFF3 then\n WriteFmtStr(xl, \"#\\ ?/?\");\n end if;\n when fraction_2 =>\n if xl.format >= BIFF3 then\n WriteFmtStr(xl, \"#\\ ??/??\");\n end if;\n when dd_mm_yyyy => WriteFmtStr(xl, \"dd/mm/yyyy\");\n when dd_mmm_yy => WriteFmtStr(xl, \"dd/mmm/yy\");\n when dd_mmm => WriteFmtStr(xl, \"dd/mmm\");\n when mmm_yy => WriteFmtStr(xl, \"mmm/yy\");\n when h_mm_AM_PM => WriteFmtStr(xl, \"h:mm\\ AM/PM\");\n when h_mm_ss_AM_PM => WriteFmtStr(xl, \"h:mm:ss\\ AM/PM\");\n when hh_mm => WriteFmtStr(xl, \"hh:mm\");\n when hh_mm_ss => WriteFmtStr(xl, \"hh:mm:ss\");\n when dd_mm_yyyy_hh_mm => WriteFmtStr(xl, \"dd/mm/yyyy\\ hh:mm\");\n when percent_0_plus =>\n WriteFmtStr(xl, \"+0%;-0%;0%\");\n when percent_2_plus =>\n WriteFmtStr(xl, \"+0\" & sep_deci & \"00%;-0\" & sep_deci & \"00%;0\" & sep_deci & \"00%\");\n when date_iso => WriteFmtStr(xl, \"yyyy\\-mm\\-dd\");\n when date_h_m_iso => WriteFmtStr(xl, \"yyyy\\-mm\\-dd\\ hh:mm\");\n when date_h_m_s_iso => WriteFmtStr(xl, \"yyyy\\-mm\\-dd\\ hh:mm:ss\");\n -- !! Trouble: Excel (German Excel/French locale) writes yyyy, reads it,\n -- understands it and translates it into aaaa, but is unable to\n -- understand *our* yyyy\n -- Same issue as [Red] vs [Rot] above.\n end case;\n end loop;\n -- ^ Some formats in the original list caused problems, probably\n -- because of regional placeholder symbols\n case xl.format is\n when BIFF2 =>\n for i in 1..6 loop\n WriteFmtStr(xl, \"@\");\n end loop;\n when BIFF3 =>\n for i in 1..4 loop\n WriteFmtStr(xl, \"@\");\n end loop;\n when BIFF4 =>\n null;\n end case;\n -- ^ Stuffing for having the same number of built-in and EW custom\n end WriteFmtRecords;\n\n -- 5.35 DIMENSION\n procedure Write_Dimensions(xl: Excel_Out_Stream'Class) is\n -- sheet bounds: 0 2 Index to first used row\n -- 2 2 Index to last used row, increased by 1\n -- 4 2 Index to first used column\n -- 6 2 Index to last used column, increased by 1\n --\n -- Since our row / column counts are 1-based, no need to increase by 1.\n sheet_bounds: constant Byte_buffer:=\n Intel_16(0) &\n Intel_16(Unsigned_16(xl.maxrow)) &\n Intel_16(0) &\n Intel_16(Unsigned_16(xl.maxcolumn));\n -- sheet_bounds_32_16: constant Byte_buffer:=\n -- Intel_32(0) &\n -- Intel_32(Unsigned_32(xl.maxrow)) &\n -- Intel_16(0) &\n -- Intel_16(Unsigned_16(xl.maxcolumn));\n begin\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0000#, sheet_bounds);\n when BIFF3 | BIFF4 =>\n WriteBiff(xl, 16#0200#, sheet_bounds & (0,0));\n -- when BIFF8 =>\n -- WriteBiff(xl, 16#0200#, sheet_bounds_32_16 & (0,0));\n end case;\n end Write_Dimensions;\n\n procedure Define_number_format(\n xl : in out Excel_Out_Stream;\n format : out Number_format_type;\n format_string: in String\n )\n is\n begin\n xl.number_fmt:= xl.number_fmt + 1;\n format:= xl.number_fmt;\n WriteFmtStr(xl, format_string);\n end Define_number_format;\n\n procedure Write_Worksheet_header(xl : in out Excel_Out_Stream'Class) is\n\n procedure Define_style(fmt: Format_type; style_id: Unsigned_8) is\n Base_Level: constant:= 255;\n begin\n WriteBiff(xl,\n 16#0293#,\n Intel_16(Unsigned_16(fmt) + 16#8000#) & style_id & Base_Level\n );\n end Define_style;\n --\n Comma_Style : constant:= 3;\n Currency_Style : constant:= 4;\n Percent_Style : constant:= 5;\n font_for_styles, font_2, font_3 : Font_type;\n --\n function Encoding_code return Unsigned_16 is -- 5.17 CODEPAGE, p. 145\n begin\n case xl.encoding is\n when Windows_CP_874 => return 874;\n when Windows_CP_932 => return 932;\n when Windows_CP_936 => return 936;\n when Windows_CP_949 => return 949;\n when Windows_CP_950 => return 950;\n when Windows_CP_1250 => return 1250;\n when Windows_CP_1251 => return 1251;\n when Windows_CP_1252 =>\n case xl.format is\n when BIFF2 .. BIFF3 =>\n return 16#8001#;\n when BIFF4 =>\n return 1252;\n end case;\n when Windows_CP_1253 => return 1253;\n when Windows_CP_1254 => return 1254;\n when Windows_CP_1255 => return 1255;\n when Windows_CP_1256 => return 1256;\n when Windows_CP_1257 => return 1257;\n when Windows_CP_1258 => return 1258;\n when Windows_CP_1361 => return 1361;\n when Apple_Roman => return 10000;\n end case;\n end Encoding_code;\n --\n begin\n Write_BOF(xl);\n -- 5.17 CODEPAGE, p. 145\n case xl.format is\n -- when BIFF8 => -- UTF-16\n -- WriteBiff(xl, 16#0042#, Intel_16(16#04B0#));\n when others =>\n WriteBiff(xl, 16#0042#, Intel_16(Encoding_code));\n end case;\n -- 5.14 CALCMODE\n WriteBiff(xl, 16#000D#, Intel_16(1)); -- 1 => automatic\n -- 5.85 REFMODE\n WriteBiff(xl, 16#000F#, Intel_16(1)); -- 1 => A1 mode\n -- 5.28 DATEMODE\n WriteBiff(xl, 16#0022#, Intel_16(0)); -- 0 => 1900; 1 => 1904 Date system\n -- NB: the 1904 variant (Mac) is ignored by LibreOffice (<= 3.5), then wrong dates !\n --\n Define_font(xl,\"Arial\", 10, xl.def_font);\n Define_font(xl,\"Arial\", 10, font_for_styles); -- Used by BIFF3+'s styles\n Define_font(xl,\"Calibri\", 10, font_2); -- Defined in BIFF3 files written by Excel 2002\n Define_font(xl,\"Calibri\", 10, font_3); -- Defined in BIFF3 files written by Excel 2002\n WriteFmtRecords(xl);\n -- 5.111 WINDOWPROTECT\n WriteBiff(xl, 16#0019#, Intel_16(0));\n -- Define default format\n Define_format(xl, xl.def_font, general, xl.def_fmt);\n if xl.format >= BIFF3 then\n -- Don't ask why we need the following useless formats, but it is as Excel 2002\n -- write formats. Additionally, the default format is turned into decimal_2\n -- when a file without those useless formats is opened in Excel (2002) !\n Define_format(xl, font_for_styles, general, xl.def_fmt);\n Define_format(xl, font_for_styles, general, xl.def_fmt);\n Define_format(xl, font_2, general, xl.def_fmt);\n Define_format(xl, font_2, general, xl.def_fmt);\n for i in 5..15 loop\n Define_format(xl, xl.def_font, general, xl.def_fmt);\n end loop;\n -- Final default format index is the last changed xl.def_fmt\n end if;\n Use_default_format(xl);\n -- Define formats for the BIFF3+ \"styles\":\n Define_format(xl, font_for_styles, decimal_2, xl.cma_fmt);\n Define_format(xl, font_for_styles, currency_0, xl.ccy_fmt);\n Define_format(xl, font_for_styles, percent_0, xl.pct_fmt);\n -- Define styles - 5.103 STYLE p. 212\n -- NB: - it is BIFF3+ (we cheat a bit if selected format is BIFF2).\n -- - these \"styles\" seem to be a zombie feature of Excel 3\n -- - the whole purpose of including this is because format\n -- buttons (%)(,) in Excel 95 through 2007 are using these styles;\n -- if the styles are not defined, those buttons are not working\n -- when an Excel Writer sheet is open in MS Excel.\n Define_style(xl.cma_fmt, Comma_Style);\n Define_style(xl.ccy_fmt, Currency_Style);\n Define_style(xl.pct_fmt, Percent_Style);\n xl.dimrecpos:= Index(xl);\n Write_Dimensions(xl);\n xl.is_created:= True;\n end Write_Worksheet_header;\n\n type Font_or_Background is (for_font, for_background);\n type Color_pair is array(Font_or_Background) of Unsigned_16;\n auto_color: constant Color_pair:=\n (16#7FFF#, -- system window text colour\n 16#0019# -- system window background colour\n );\n\n color_code: constant array(Excel_type, Color_type) of Color_pair :=\n ( BIFF2 =>\n (\n black => (0, 0),\n white => (1, 1),\n red => (2, 2),\n green => (3, 3),\n blue => (4, 4),\n yellow => (5, 5),\n magenta => (6, 6),\n cyan => (7, 7),\n others => auto_color\n ),\n BIFF3 | BIFF4 =>\n (black => (8, 8),\n white => (9, 9),\n red => (10, 10),\n green => (11, 11),\n blue => (12, 12),\n yellow => (13, 13),\n magenta => (14, 14),\n cyan => (15, 15),\n dark_red => (16, 16),\n dark_green => (17, 17),\n dark_blue => (18, 18),\n olive => (19, 19),\n purple => (20, 20),\n teal => (21, 21),\n silver => (22, 22),\n grey => (23, 23),\n automatic => auto_color\n )\n );\n\n -- *** Exported procedures **********************************************\n\n -- 5.115 XF - Extended Format\n procedure Define_format(\n xl : in out Excel_Out_Stream;\n font : in Font_type; -- Default_font(xl), or given by Define_font\n number_format : in Number_format_type; -- built-in, or given by Define_number_format\n cell_format : out Format_type;\n -- Optional parameters --\n horizontal_align : in Horizontal_alignment:= general_alignment;\n border : in Cell_border:= no_border;\n shaded : in Boolean:= False; -- Add a dotted background pattern\n background_color : in Color_type:= automatic;\n wrap_text : in Boolean:= False;\n vertical_align : in Vertical_alignment:= bottom_alignment;\n text_orient : in Text_orientation:= normal\n )\n is\n actual_number_format: Number_format_type:= number_format;\n cell_is_locked: constant:= 1;\n -- ^ Means actually: cell formula protection is possible, and enabled when sheet is protected.\n procedure Define_BIFF2_XF is\n border_bits, mask: Unsigned_8;\n begin\n border_bits:= 0;\n mask:= 8;\n for s in Cell_border_single loop\n if border(s) then\n border_bits:= border_bits + mask;\n end if;\n mask:= mask * 2;\n end loop;\n -- 5.115.2 XF Record Contents, p. 221 for BIFF3\n WriteBiff(\n xl,\n 16#0043#, -- XF code in BIFF2\n (Unsigned_8(font),\n -- ^ Index to FONT record\n 0,\n -- ^ Not used\n Number_format_type'Pos(actual_number_format) + 16#40# * cell_is_locked,\n -- ^ Number format and cell flags\n Horizontal_alignment'Pos(horizontal_align) +\n border_bits +\n Boolean'Pos(shaded) * 128\n -- ^ Horizontal alignment, border style, and background\n )\n );\n end Define_BIFF2_XF;\n\n area_code: Unsigned_16;\n\n procedure Define_BIFF3_XF is\n begin\n -- 5.115.2 XF Record Contents, p. 221 for BIFF3\n WriteBiff(\n xl,\n 16#0243#, -- XF code in BIFF3\n (Unsigned_8(font),\n -- ^ 0 - Index to FONT record\n Number_format_type'Pos(actual_number_format),\n -- ^ 1 - Number format and cell flags\n cell_is_locked,\n -- ^ 2 - XF_TYPE_PROT (5.115.1)\n 16#FF#\n -- ^ 3 - XF_USED_ATTRIB\n ) &\n Intel_16(\n Horizontal_alignment'Pos(horizontal_align) +\n Boolean'Pos(wrap_text) * 8\n ) &\n -- ^ 4 - Horizontal alignment, text break, parent style XF\n Intel_16(area_code) &\n -- ^ 6 - XF_AREA_34\n ( Boolean'Pos(border(top_single)),\n Boolean'Pos(border(left_single)),\n Boolean'Pos(border(bottom_single)),\n Boolean'Pos(border(right_single))\n )\n -- ^ 8 - XF_BORDER_34 - thin (=1) line; we could have other line styles:\n -- Thin, Medium, Dashed, Dotted, Thick, Double, Hair\n );\n end Define_BIFF3_XF;\n\n procedure Define_BIFF4_XF is\n begin\n -- 5.115.2 XF Record Contents, p. 222 for BIFF4\n WriteBiff(\n xl,\n 16#0443#, -- XF code in BIFF4\n (Unsigned_8(font),\n -- ^ 0 - Index to FONT record\n Number_format_type'Pos(actual_number_format),\n -- ^ 1 - Number format and cell flags\n cell_is_locked, 0,\n -- ^ 2 - XF type, cell protection, and parent style XF\n Horizontal_alignment'Pos(horizontal_align) +\n Boolean'Pos(wrap_text) * 8 +\n (Vertical_alignment'Pos(vertical_align) and 3) * 16 +\n Text_orientation'Pos(text_orient) * 64,\n -- ^ 4 - Alignment (hor & ver), text break, and text orientation\n 16#FF#\n -- ^ 3 - XF_USED_ATTRIB\n ) &\n -- ^ 4 - Horizontal alignment, text break, parent style XF\n Intel_16(area_code) &\n -- ^ 6 - XF_AREA_34\n ( Boolean'Pos(border(top_single)),\n Boolean'Pos(border(left_single)),\n Boolean'Pos(border(bottom_single)),\n Boolean'Pos(border(right_single))\n )\n -- ^ 8 - XF_BORDER_34 - thin (=1) line; we could have other line styles:\n -- Thin, Medium, Dashed, Dotted, Thick, Double, Hair\n );\n end Define_BIFF4_XF;\n\n begin\n -- 2.5.12 Patterns for Cell and Chart Background Area\n -- This is for BIFF3+\n if shaded then\n area_code:=\n Boolean'Pos(shaded) * 17 + -- Sparse pattern, like BIFF2 \"shade\"\n 16#40# * color_code(BIFF3, black)(for_background) + -- pattern colour\n 16#800# * color_code(BIFF3, background_color)(for_background); -- pattern background\n elsif background_color = automatic then\n area_code:= 0;\n else\n area_code:=\n 1 + -- Full pattern\n 16#40# * color_code(BIFF3, background_color)(for_background) + -- pattern colour\n 16#800# * color_code(BIFF3, background_color)(for_background); -- pattern background\n end if;\n case xl.format is\n when BIFF2 =>\n case actual_number_format is\n when general .. no_currency_2 =>\n null;\n when currency_0 .. fraction_2 =>\n actual_number_format:= actual_number_format - 4;\n when dd_mm_yyyy .. last_custom =>\n actual_number_format:= actual_number_format - 6;\n when others =>\n null;\n end case;\n Define_BIFF2_XF;\n when BIFF3 =>\n if actual_number_format in currency_0 .. last_custom then\n actual_number_format:= actual_number_format - 4;\n end if;\n Define_BIFF3_XF;\n when BIFF4 =>\n Define_BIFF4_XF;\n -- when BIFF8 =>\n -- Define_BIFF8_XF; -- BIFF8: 16#00E0#, p. 224\n end case;\n xl.xfs:= xl.xfs + 1;\n cell_format:= Format_type(xl.xfs);\n xl.xf_def(xl.xfs):= (font => font, numb => number_format);\n end Define_format;\n\n procedure Header(xl : Excel_Out_Stream; page_header_string: String) is\n begin\n WriteBiff(xl, 16#0014#, To_buf_8_bit_length(page_header_string)); -- 5.55 p.180\n end Header;\n\n procedure Footer(xl : Excel_Out_Stream; page_footer_string: String) is\n begin\n WriteBiff(xl, 16#0015#, To_buf_8_bit_length(page_footer_string)); -- 5.48 p.173\n end Footer;\n\n procedure Left_Margin(xl : Excel_Out_Stream; inches: Long_Float) is\n begin\n WriteBiff(xl, 16#0026#, IEEE_Double_Intel(inches));\n end Left_Margin;\n\n procedure Right_Margin(xl : Excel_Out_Stream; inches: Long_Float) is\n begin\n WriteBiff(xl, 16#0027#, IEEE_Double_Intel(inches));\n end Right_Margin;\n\n procedure Top_Margin(xl : Excel_Out_Stream; inches: Long_Float) is\n begin\n WriteBiff(xl, 16#0028#, IEEE_Double_Intel(inches));\n end Top_Margin;\n\n procedure Bottom_Margin(xl : Excel_Out_Stream; inches: Long_Float) is\n begin\n WriteBiff(xl, 16#0029#, IEEE_Double_Intel(inches));\n end Bottom_Margin;\n\n procedure Margins(xl : Excel_Out_Stream; left, right, top, bottom: Long_Float) is\n begin\n Left_Margin(xl, left);\n Right_Margin(xl, right);\n Top_Margin(xl, top);\n Bottom_Margin(xl, bottom);\n end Margins;\n\n procedure Print_Row_Column_Headers(xl : Excel_Out_Stream) is\n begin\n WriteBiff(xl, 16#002A#, Intel_16(1)); -- 5.81 PRINTHEADERS p.199\n end Print_Row_Column_Headers;\n\n procedure Print_Gridlines(xl : Excel_Out_Stream) is\n begin\n WriteBiff(xl, 16#002B#, Intel_16(1)); -- 5.80 PRINTGRIDLINES p.199\n end Print_Gridlines;\n\n procedure Page_Setup(\n xl : Excel_Out_Stream;\n scaling_percents : Positive:= 100;\n fit_width_with_n_pages : Natural:= 1; -- 0: as many as possible\n fit_height_with_n_pages: Natural:= 1; -- 0: as many as possible\n orientation : Orientation_choice:= portrait;\n scale_or_fit : Scale_or_fit_choice:= scale\n )\n is\n begin\n -- 5.73 PAGESETUP p.192 - this is BIFF4+ (cheat if xl.format below)!\n WriteBiff(xl,\n 16#00A1#,\n Intel_16(0) & -- paper type undefined\n Intel_16(Unsigned_16(scaling_percents)) &\n Intel_16(1) & -- start page number\n Intel_16(Unsigned_16(fit_width_with_n_pages)) &\n Intel_16(Unsigned_16(fit_height_with_n_pages)) &\n Intel_16(2 * Orientation_choice'Pos(orientation))\n );\n -- 5.97 SHEETPR p.207 - this is BIFF3+ (cheat if xl.format below) !\n -- NB: this field contains other informations, should be delayed\n -- in case other preferences are to be set\n WriteBiff(xl,\n 16#0081#,\n Intel_16(256 * Scale_or_fit_choice'Pos(scale_or_fit))\n );\n end Page_Setup;\n\n y_scale: constant:= 20; -- scaling to obtain character point (pt) units\n\n -- 5.31 DEFAULTROWHEIGHT\n procedure Write_default_row_height (\n xl : Excel_Out_Stream;\n height : Positive\n )\n is\n default_twips: constant Byte_buffer:= Intel_16(Unsigned_16(height * y_scale));\n options_flags: constant Byte_buffer:= (1,0);\n -- 1 = Row height and default font height do not match\n begin\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0025#, default_twips);\n when BIFF3 | BIFF4 =>\n WriteBiff(xl, 16#0225#, options_flags & default_twips);\n end case;\n end Write_default_row_height;\n\n -- 5.32 DEFCOLWIDTH\n procedure Write_default_column_width (\n xl : in out Excel_Out_Stream;\n width : Positive)\n is\n begin\n WriteBiff(xl, 16#0055#, Intel_16(Unsigned_16(width)));\n xl.defcolwdth:= 256 * width;\n end Write_default_column_width;\n\n procedure Write_column_width (\n xl : in out Excel_Out_Stream;\n column : Positive;\n width : Natural)\n is\n begin\n Write_column_width(xl, column, column, width);\n end Write_column_width;\n\n procedure Write_column_width(\n xl : in out Excel_Out_Stream;\n first_column,\n last_column : Positive;\n width : Natural\n )\n is\n begin\n case xl.format is\n when BIFF2 =>\n -- 5.20 COLWIDTH (BIFF2 only)\n WriteBiff(xl, 16#0024#,\n Unsigned_8(first_column-1) &\n Unsigned_8(last_column-1) &\n Intel_16(Unsigned_16(width * 256)));\n when BIFF3 | BIFF4 =>\n -- 5.18 COLINFO (BIFF3+)\n WriteBiff(xl, 16#007D#,\n Intel_16(Unsigned_16(first_column-1)) &\n Intel_16(Unsigned_16(last_column-1)) &\n Intel_16(Unsigned_16(width * 256)) &\n Intel_16(0) & -- Index to XF record (5.115) for default column formatting\n Intel_16(0) & -- Option flags\n (0,0) -- Not used\n );\n for j in first_column .. last_column loop\n xl.std_col_width(j):= False;\n end loop;\n end case;\n end Write_column_width;\n\n -- 5.88 ROW\n -- The OpenOffice documentation tells nice stories about row blocks,\n -- but single ROW commands can also be put before in the data stream,\n -- where the column widths are set. Excel saves with blocks of ROW\n -- commands, most of them useless.\n\n procedure Write_row_height(\n xl : Excel_Out_Stream;\n row : Positive;\n height : Natural\n )\n is\n row_info_base: Byte_buffer:=\n Intel_16(Unsigned_16(row - 1)) &\n Intel_16(0) & -- col. min.\n Intel_16(255) & -- col. max.\n Intel_16(Unsigned_16(height * y_scale));\n fDyZero: Unsigned_8:= 0;\n begin\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0008#,\n row_info_base &\n (1..3 => 0) &\n Intel_16(0) -- offset to data\n );\n when BIFF3 | BIFF4 =>\n if height = 0 then -- proper hiding (needed with LibreOffice)\n fDyZero:= 1;\n row_info_base(row_info_base'Last - 1 .. row_info_base'Last):=\n Intel_16(16#8000#);\n end if;\n WriteBiff(xl, 16#0208#,\n row_info_base &\n -- http://msdn.microsoft.com/en-us/library/dd906757(v=office.12).aspx\n (0, 0, -- reserved1 (2 bytes): MUST be zero, and MUST be ignored.\n 0, 0, -- unused1 (2 bytes): Undefined and MUST be ignored.\n fDyZero * 32 + -- D - fDyZero (1 bit): row is hidden\n 1 * 64 + -- E - fUnsynced (1 bit): row height was manually set\n 0 * 128, -- F - fGhostDirty (1 bit): the row was formatted\n 1) & -- reserved3 (1 byte): MUST be 1, and MUST be ignored\n Intel_16(15)\n -- ^ ixfe_val, then 4 bits.\n -- If fGhostDirty is 0, ixfe_val is undefined and MUST be ignored.\n );\n end case;\n end Write_row_height;\n\n -- 5.45 FONT, p.171\n procedure Define_font(\n xl : in out Excel_Out_Stream;\n font_name : String;\n height : Positive;\n font : out Font_type;\n style : Font_style:= regular;\n color : Color_type:= automatic\n )\n is\n style_bits, mask: Unsigned_16;\n begin\n style_bits:= 0;\n mask:= 1;\n for s in Font_style_single loop\n if style(s) then\n style_bits:= style_bits + mask;\n end if;\n mask:= mask * 2;\n end loop;\n xl.fonts:= xl.fonts + 1;\n if xl.fonts = 4 then\n xl.fonts:= 5;\n -- Anomaly! The font with index 4 is omitted in all BIFF versions.\n -- Numbering is 0, 1, 2, 3, *5*, 6,...\n end if;\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0031#,\n Intel_16(Unsigned_16(height * y_scale)) &\n Intel_16(style_bits) &\n To_buf_8_bit_length(font_name)\n );\n if color /= automatic then\n -- 5.47 FONTCOLOR\n WriteBiff(xl, 16#0045#, Intel_16(color_code(BIFF2, color)(for_font)));\n end if;\n when BIFF3 | BIFF4 => -- BIFF8 has 16#0031#, p. 171\n WriteBiff(xl, 16#0231#,\n Intel_16(Unsigned_16(height * y_scale)) &\n Intel_16(style_bits) &\n Intel_16(color_code(BIFF3, color)(for_font)) &\n To_buf_8_bit_length(font_name)\n );\n end case;\n font:= Font_type(xl.fonts);\n end Define_font;\n\n procedure Jump_to_and_store_max(xl: in out Excel_Out_Stream; r, c: Integer) is\n pragma Inline(Jump_to_and_store_max);\n begin\n if not xl.is_created then\n raise Excel_stream_not_created;\n end if;\n Jump_to(xl, r, c); -- Store and check current position\n if r > xl.maxrow then\n xl.maxrow := r;\n end if;\n if c > xl.maxcolumn then\n xl.maxcolumn := c;\n end if;\n end Jump_to_and_store_max;\n\n -- 2.5.13 Cell Attributes (BIFF2 only)\n function Cell_attributes(xl: Excel_Out_Stream) return Byte_buffer is\n begin\n return\n (Unsigned_8(xl.xf_in_use),\n Unsigned_8(xl.xf_def(xl.xf_in_use).numb) + 16#40# *\n Unsigned_8(xl.xf_def(xl.xf_in_use).font),\n 0\n );\n end Cell_attributes;\n\n function Almost_zero(x: Long_Float) return Boolean is\n begin\n return abs x <= Long_Float'Model_Small;\n end Almost_zero;\n\n -- Internal\n --\n -- 5.71 NUMBER\n procedure Write_as_double (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n num : Long_Float\n )\n is\n pragma Inline(Write_as_double);\n begin\n Jump_to_and_store_max(xl, r, c);\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0003#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Cell_attributes(xl) &\n IEEE_Double_Intel(num)\n );\n when BIFF3 | BIFF4 =>\n WriteBiff(xl, 16#0203#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Intel_16(Unsigned_16(xl.xf_in_use)) &\n IEEE_Double_Intel(num)\n );\n end case;\n Jump_to(xl, r, c+1); -- Store and check new position\n end Write_as_double;\n\n -- Internal. This is BIFF2 only. BIFF format choice unchecked here.\n --\n procedure Write_as_16_bit_unsigned (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n num : Unsigned_16)\n is\n pragma Inline(Write_as_16_bit_unsigned);\n begin\n Jump_to_and_store_max(xl, r, c);\n -- 5.60 INTEGER\n WriteBiff(xl, 16#0002#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Cell_attributes(xl) &\n Intel_16(num)\n );\n Jump_to(xl, r, c+1); -- Store and check new position\n end Write_as_16_bit_unsigned;\n\n -- Internal. This is BIFF3+. BIFF format choice unchecked here.\n --\n procedure Write_as_30_bit_signed (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n num : Integer_32)\n is\n pragma Inline(Write_as_30_bit_signed);\n RK_val: Unsigned_32;\n RK_code: constant:= 2; -- Code for signed integer. See 2.5.5 RK Values\n begin\n if num >= 0 then\n RK_val:= Unsigned_32(num) * 4 + RK_code;\n else\n RK_val:= (-Unsigned_32(-num)) * 4 + RK_code;\n end if;\n Jump_to_and_store_max(xl, r, c);\n -- 5.87 RK\n WriteBiff(xl, 16#027E#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Intel_16(Unsigned_16(xl.xf_in_use)) &\n Intel_32(RK_val)\n );\n Jump_to(xl, r, c+1); -- Store and check new position\n end Write_as_30_bit_signed;\n\n --\n -- Profile with floating-point number\n --\n procedure Write (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n num : Long_Float\n )\n is\n max_16_u: constant:= 2.0 ** 16 - 1.0;\n min_30_s: constant:= -(2.0 ** 29);\n max_30_s: constant:= 2.0 ** 29 - 1.0;\n begin\n case xl.format is\n when BIFF2 =>\n if num >= 0.0 and then\n num <= max_16_u and then\n Almost_zero(num - Long_Float'Floor(num))\n then\n Write_as_16_bit_unsigned(xl, r, c, Unsigned_16(Long_Float'Floor(num)));\n else\n Write_as_double(xl, r, c, num);\n end if;\n when BIFF3 | BIFF4 =>\n if num >= min_30_s and then\n num <= max_30_s and then\n Almost_zero(num - Long_Float'Floor(num))\n then\n Write_as_30_bit_signed(xl, r, c, Integer_32(Long_Float'Floor(num)));\n else\n Write_as_double(xl, r, c, num);\n end if;\n end case;\n end Write;\n\n --\n -- Profile with integer number\n --\n procedure Write (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n num : Integer)\n is\n begin\n -- We use an integer representation (and small storage) if possible;\n -- we need to use a floating-point in all other cases\n case xl.format is\n when BIFF2 =>\n if num in 0..2**16-1 then\n Write_as_16_bit_unsigned(xl, r, c, Unsigned_16(num));\n else\n Write_as_double(xl, r, c, Long_Float(num));\n end if;\n when BIFF3 | BIFF4 =>\n if num in -2**29..2**29-1 then\n Write_as_30_bit_signed(xl, r, c, Integer_32(num));\n else\n Write_as_double(xl, r, c, Long_Float(num));\n end if;\n end case;\n end Write;\n\n -- -- Function taken from Wasabee.Encoding.\n -- function ISO_8859_1_to_UTF_16(s: String) return Wide_String is\n -- -- This conversion is a trivial 8-bit to 16-bit copy.\n -- r: Wide_String(s'Range);\n -- begin\n -- for i in s'Range loop\n -- r(i):= Wide_Character'Val(Character'Pos(s(i)));\n -- end loop;\n -- return r;\n -- end ISO_8859_1_to_UTF_16;\n\n -- 5.63 LABEL\n procedure Write (\n xl : in out Excel_Out_Stream;\n r,\n c : Positive;\n str : String)\n is\n begin\n Jump_to_and_store_max(xl, r, c);\n if str'Length > 0 then\n case xl.format is\n when BIFF2 =>\n WriteBiff(xl, 16#0004#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Cell_attributes(xl) &\n To_buf_8_bit_length(str)\n );\n when BIFF3 | BIFF4 =>\n WriteBiff(xl, 16#0204#,\n Intel_16(Unsigned_16(r-1)) &\n Intel_16(Unsigned_16(c-1)) &\n Intel_16(Unsigned_16(xl.xf_in_use)) &\n To_buf_16_bit_length(str)\n );\n -- when BIFF8 =>\n -- WriteBiff(xl, 16#0204#,\n -- Intel_16(Unsigned_16(r-1)) &\n -- Intel_16(Unsigned_16(c-1)) &\n -- Intel_16(Unsigned_16(xl.xf_in_use)) &\n -- To_buf_16_bit_length(ISO_8859_1_to_UTF_16(str))\n -- );\n end case;\n end if;\n Jump_to(xl, r, c+1); -- Store and check new position\n end Write;\n\n procedure Write(xl: in out Excel_Out_Stream; r,c : Positive; str : Unbounded_String)\n is\n begin\n Write(xl, r,c, To_String(str));\n end Write;\n\n -- Excel uses a floating-point type for time - ouch!\n --\n function To_Number(date: Time) return Long_Float is\n -- 1901 is the lowest year supported by Ada.Calendar.\n -- 1900 is not a leap year, but Lotus 1-2-3, then Excel, consider it\n -- as a leap year. So, with 1901, we skip that issue anyway...\n --\n function Days_since_1901 (y, m, d : Integer) return Integer is\n function Is_leap (y: Integer) return Boolean is\n begin\n if y mod 4 = 0 then\n if y mod 100 = 0 then\n if y mod 400 = 0 then\n return True;\n else\n return False;\n end if;\n else\n return True;\n end if;\n else\n return False;\n end if;\n end Is_leap;\n days_of_previous_months : Integer;\n days_of_previous_years : Integer;\n y_diff, y_diff_4, y_diff_100, y_diff_400 : Integer;\n begin\n case m is\n when 02 => days_of_previous_months := 31;\n when 03 => days_of_previous_months := 59;\n when 04 => days_of_previous_months := 90;\n when 05 => days_of_previous_months := 120;\n when 06 => days_of_previous_months := 151;\n when 07 => days_of_previous_months := 181;\n when 08 => days_of_previous_months := 212;\n when 09 => days_of_previous_months := 243;\n when 10 => days_of_previous_months := 273;\n when 11 => days_of_previous_months := 304;\n when 12 => days_of_previous_months := 334;\n when others => days_of_previous_months := 0;\n end case;\n if m > 2 and then Is_leap (y) then -- February has 29 days in leap years.\n days_of_previous_months := days_of_previous_months + 1;\n end if;\n --\n y_diff := (y - 1) - 1900;\n y_diff_4 := (y - 1) / 4 - 1900 / 4;\n y_diff_100 := (y - 1) / 100 - 1900 / 100;\n y_diff_400 := (y - 1) / 400 - 1900 / 400;\n -- Add extra days of leap years from 1901 (included) to year y (excluded).\n days_of_previous_years := 365 * y_diff + y_diff_4 - y_diff_100 + y_diff_400;\n --\n return days_of_previous_years + days_of_previous_months + d - 1;\n end Days_since_1901;\n --\n sec : constant Day_Duration := Seconds (date);\n begin\n -- With GNAT and perhaps other systems, Duration's range allows the following:\n -- return Long_Float(date - Time_Of(1901, 01, 01, 0.0)) / 86_400.0 + 367.0;\n -- With ObjectAda and perhaps other systems, we need to count days since 1900 ourselves.\n return\n Long_Float (sec) / 86_400.0 +\n Long_Float (Days_since_1901 (Year (date), Month (date), Day (date))) +\n 367.0; -- Days from 1899-12-31 to 1901-01-01.\n -- Lotus 1-2-3, then Excel, are based on 1899-12-31 (and believe it is 1900-01-01).\n end To_Number;\n\n procedure Write(xl: in out Excel_Out_Stream; r,c : Positive; date: Time)\n is\n begin\n Write(xl, r,c, To_Number(date));\n end Write;\n\n -- Ada.Text_IO - like. No need to specify row & column each time\n procedure Put(xl: in out Excel_Out_Stream; num : Long_Float) is\n begin\n Write(xl, xl.curr_row, xl.curr_col, num);\n end Put;\n\n procedure Put(xl : in out Excel_Out_Stream;\n num : in Integer;\n width : in Ada.Text_IO.Field := 0; -- ignored\n base : in Ada.Text_IO.Number_Base := 10\n )\n is\n begin\n if base = 10 then\n Write(xl, xl.curr_row, xl.curr_col, num);\n else\n declare\n use Ada.Strings.Fixed;\n s: String(1..50 + 0*width);\n -- 0*width is just to skip a warning of width being unused\n package IIO is new Ada.Text_IO.Integer_IO(Integer);\n begin\n IIO.Put(s, num, Base => base);\n Put(xl, Trim(s, Ada.Strings.Left));" + }, + { + "function_def": "function Mantissa (Value : Float_64) return Unsigned_64 is", + "function_body": "pragma Inline (Mantissa);\n begin\n return\n ( Unsigned_64 (Value (8))\n or Shift_Left (Unsigned_64 (Value (7)), 8 )\n or Shift_Left (Unsigned_64 (Value (6)), 2*8)\n or Shift_Left (Unsigned_64 (Value (5)), 3*8)\n or Shift_Left (Unsigned_64 (Value (4)), 4*8)\n or Shift_Left (Unsigned_64 (Value (3)), 5*8)\n or Shift_Left (Unsigned_64 (Value (2)) and 16#0F#, 6*8)\n or 2 ** Fraction_Bits\n );\n end Mantissa;\n\n procedure Normalize\n ( Value : Number;\n Mantissa : out Unsigned_64;\n Exponent : out Integer\n ) is\n begin\n if Number'Machine_Radix = 2 then\n --\n -- The machine radix is binary. We can use the hardware\n -- representation attributes in order to get the exponent and\n -- the fraction.\n --\n Exponent := Number'Exponent (Value) - Mantissa_Bits;\n Mantissa := Unsigned_64 (Number'Scaling (Value, -Exponent));\n else\n --\n -- OK, this gets more tricky. The number is normalized to be in\n -- the range 2**53 > X >= 2**52, by multiplying to the powers\n -- of two. Some optimization is made to factor out the powers\n -- 2**(2**n)). Though we do not use powers bigger than 30.\n --\n declare\n Accum : Number := Value;\n Shift : Integer;\n begin\n Exponent := 0;\n if Accum < 2.0**Fraction_Bits then\n Shift := 24;\n while Shift > 0 loop\n if Accum < 2.0**(Mantissa_Bits - Shift) then\n Accum := Accum * 2.0**Shift;\n Exponent := Exponent - Shift;\n else\n Shift := Shift / 2;\n end if;\n end loop;\n elsif Accum >= 2.0**Mantissa_Bits then\n Shift := 8;\n while Shift > 0 loop\n if Accum >= 2.0**(Fraction_Bits + Shift) then\n Accum := Accum / 2.0**Shift;\n Exponent := Exponent + Shift;\n else\n Shift := Shift / 2;\n end if;\n end loop;\n end if;\n Mantissa := Unsigned_64 (Accum);" + }, + { + "function_def": "procedure Select_Table_1 is new Select_Table_N (1);", + "function_body": "procedure Select_Table_10 is new Select_Table_N (10);\n\n procedure Select_Table_100 is new Select_Table_N (100);\n\n procedure Select_Table_500 is new Select_Table_N (500);\n\n procedure Select_Table_1000 is new Select_Table_N (1000);\n\n Create_SQL : Ada.Strings.Unbounded.Unbounded_String;\n\n procedure Register (Tests : in out Context_Type) is\n Driver : constant String := Tests.Get_Driver_Name;\n begin\n if Driver /= \"sqlite\" and Driver /= \"postgresql\" then\n Tests.Register (Do_Static'Access, \"DO 1\");\n end if;\n Tests.Register (Select_Static'Access, \"SELECT 1\");\n Tests.Register (Connect_Select_Static'Access, \"CONNECT; SELECT 1; CLOSE\");\n Tests.Register (Drop_Create'Access, \"DROP table; CREATE table\", 1);\n Tests.Register (Insert'Access, \"INSERT INTO table\", 10);\n Tests.Register (Select_Table_1'Access, \"SELECT * FROM table LIMIT 1\");\n Tests.Register (Select_Table_10'Access, \"SELECT * FROM table LIMIT 10\");\n Tests.Register (Select_Table_100'Access, \"SELECT * FROM table LIMIT 100\");\n Tests.Register (Select_Table_500'Access, \"SELECT * FROM table LIMIT 500\");\n Tests.Register (Select_Table_1000'Access, \"SELECT * FROM table LIMIT 1000\");\n Util.Files.Read_File (Tests.Get_Config_Path (\"create-table.sql\"), Create_SQL);\n end Register;\n\n procedure Do_Static (Context : in out Context_Type) is\n Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement (\"DO 1\");\n begin\n for I in 1 .. Context.Repeat loop\n Stmt.Execute;\n end loop;\n end Do_Static;\n\n procedure Select_Static (Context : in out Context_Type) is\n Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement (\"SELECT 1\");\n begin\n for I in 1 .. Context.Repeat loop\n Stmt.Execute;\n end loop;\n end Select_Static;\n\n procedure Connect_Select_Static (Context : in out Context_Type) is\n begin\n for I in 1 .. Context.Repeat loop\n declare\n DB : constant ADO.Sessions.Session := Context.Factory.Get_Session;\n Stmt : ADO.Statements.Query_Statement := DB.Create_Statement (\"SELECT 1\");\n begin\n Stmt.Execute;" + }, + { + "function_def": "procedure Main is", + "function_body": "WG : World_Grid (16);\n B : Boolean;\nbegin\n WG := New_World (16);\n B := Get_Spot (WG, 1, 1);\n Put_Line (\"World Size: \" & Integer'Image(WG.Size));\n Put_Line (\"Hello Ada!\");\n --Gtk.Main.Init;\n --Gtk_New (Life_Value);\n --Gtk.Main.Main;" + }, + { + "function_def": "function on_is_Label_clicked (the_Label : access Gtk_Label_Record'Class;", + "function_body": "Self : in aIDE.Editor.of_enumeration_type.view) return Boolean\n is\n pragma Unreferenced (the_Label);\n begin\n Self.Target.add_Literal (\"literal\");\n Self.freshen;\n\n return False;\n end on_is_Label_clicked;\n\n\n package Label_return_Callbacks is new Gtk.Handlers.User_Return_Callback (Gtk_Label_Record,\n Boolean,\n aIDE.Editor.of_enumeration_type.view);\n\n package body Forge\n is\n function to_Editor (the_Target : in AdaM.a_Type.enumeration_type.view) return View\n is\n use AdaM,\n Glib;\n\n Self : constant Editor.of_enumeration_type.view := new Editor.of_enumeration_type.item;\n\n the_Builder : Gtk_Builder;\n Error : aliased GError;\n Result : Guint;\n pragma Unreferenced (Result);\n\n begin\n Self.Target := the_Target;\n\n Gtk_New (the_Builder);\n\n Result := the_Builder.Add_From_File (\"glade/editor/enumeration_type_editor.glade\", Error'Access);\n\n if Error /= null then\n raise Program_Error with \"Error: adam.Editor.of_enumeration_type ~ \" & Get_Message (Error);\n end if;\n\n Self.top_Box := gtk_Box (the_Builder.get_Object (\"top_Box\"));\n Self.name_Entry := Gtk_Entry (the_Builder.get_Object (\"name_Entry\"));\n Self.is_Label := Gtk_Label (the_Builder.get_Object (\"is_Label\"));\n Self.literals_Box := gtk_Box (the_Builder.get_Object (\"literals_Box\"));\n Self.rid_Button := gtk_Button (the_Builder.get_Object (\"rid_Button\"));\n\n Self.open_parenthesis_Label := Gtk_Label (the_Builder.get_Object (\"open_parenthesis_Label\"));\n Self.close_parenthesis_Label := Gtk_Label (the_Builder.get_Object (\"close_parenthesis_Label\"));\n\n\n Self.name_Entry.Set_Text (+Self.Target.Name);\n\n declare\n use type Ada.Containers.Count_Type;\n Attributes : Pango.Attributes.Pango_Attr_List := Pango.Attributes.Pango_Attr_List_New;\n Scale : gDouble := Gdouble (2 * Self.Target.Literals.Length);\n begin\n Attributes.Change (pango.Attributes.Attr_Scale_New (Scale));\n Self. open_parenthesis_Label.set_Attributes (Attributes);\n Self.close_parenthesis_Label.set_Attributes (Attributes);\n-- Self.close_parenthesis_Label.Set_Size_Request (Height => 10);" + }, + { + "function_def": "procedure Context_is (Self : in out Item; Now : in AdaM.Context.view)", + "function_body": "is\n begin\n Self.Context := Now;\n Self.freshen;\n end Context_is;\n\n\n\n overriding function top_Widget (Self : in Item) return gtk.Widget.Gtk_Widget\n is\n begin\n return gtk.Widget.Gtk_Widget (Self.Top);\n end top_Widget;\n\n\n\n overriding\n procedure freshen (Self : in out Item)\n is\n the_Lines : constant AdaM.context_Line.Vector := Self.Context.Lines;\n begin\n loop\n declare\n the_Child : constant gtk_Widget := Self.context_lines_Box.Get_Child (0);\n begin\n exit when the_Child = null;\n the_Child.destroy;" + }, + { + "function_def": "procedure register_Usage (the_Exception : in AdaM.Declaration.of_exception.view);", + "function_body": "function fetch return AdaM.Declaration.of_exception.vector;\n end recent_Exceptions;\n\n\n package body recent_Exceptions\n is\n type exception_Usage is\n record\n the_Exception : AdaM.Declaration.of_exception.view;\n Count : Natural;\n end record;\n\n function \"<\" (L, R : in exception_Usage) return Boolean\n is\n use type AdaM.Identifier;\n begin\n return L.the_Exception.Name < R.the_Exception.Name;\n end \"<\";\n\n overriding function \"=\" (L, R : in exception_Usage) return Boolean\n is\n use type AdaM.Identifier;\n begin\n return L.the_Exception.Name = R.the_Exception.Name;\n end \"=\";\n\n package exception_Usage_Sets is new ada.Containers.Ordered_Sets (exception_Usage);\n the_usage_Stats : exception_Usage_Sets.Set;\n\n\n-- procedure register_Usage (the_Exception : in adam.Text)\n-- is\n-- use exception_Usage_Sets;\n--\n-- the_exception_Usage : exception_Usage := (the_Exception, others => <>);\n-- Current : constant exception_Usage_Sets.Cursor := the_usage_Stats.find (the_exception_Usage);\n-- begin\n-- if Current /= No_Element\n-- then\n-- the_exception_Usage.Count := Element (Current).Count + 1;\n-- the_usage_Stats.replace_Element (Current, the_exception_Usage);\n-- else\n-- the_exception_Usage.Count := 1;\n-- the_usage_Stats.insert (the_exception_Usage);\n-- end if;\n-- end register_Usage;\n\n procedure register_Usage (the_Exception : in AdaM.Declaration.of_exception.view)\n is\n use exception_Usage_Sets;\n use type AdaM.Declaration.of_exception.view;\n\n the_exception_Usage : exception_Usage := (the_Exception, others => <>);\n Current : constant exception_Usage_Sets.Cursor := the_usage_Stats.find (the_exception_Usage);\n begin\n if the_Exception = null\n then\n raise program_Error with \"NULLLLLLLL exception !!!\";\n else\n put_Line (\"ALL FINEEEEEEEEEEEEEEEEEEEEEE\");\n end if;\n\n if Current /= No_Element\n then\n the_exception_Usage.Count := Element (Current).Count + 1;\n the_usage_Stats.replace_Element (Current, the_exception_Usage);\n else\n the_exception_Usage.Count := 1;\n the_usage_Stats.insert (the_exception_Usage);\n end if;\n end register_Usage;\n\n\n\n function fetch return AdaM.Declaration.of_exception.vector\n is\n use exception_Usage_Sets,\n ada.Containers;\n\n-- the_Lines : AdaM.text_Lines;\n the_Exceptions : AdaM.Declaration.of_exception.vector;\n\n package type_Usage_Vectors is new ada.Containers.Vectors (Positive, exception_Usage);\n use type_Usage_Vectors;\n\n the_usage_List : type_Usage_Vectors.Vector;\n\n begin\n declare\n Cursor : exception_Usage_Sets.Cursor := the_usage_Stats.First;\n begin\n while has_Element (Cursor)\n loop\n if Element (Cursor).Count > 0 then\n the_usage_List.append (Element (Cursor));\n end if;\n\n exit when the_Exceptions.Length = 25; -- Limit results to 25 entries.\n next (Cursor);\n end loop;" + }, + { + "function_def": "procedure choice_is (Self : in out Item; --Now : in String;", + "function_body": "-- package_Name : in String;\n the_Exception : in AdaM.Declaration.of_exception.view)\n is\n use AdaM,\n AdaM.Assist;\n\n-- full_Name : constant String := package_Name & \".\" & Now;\n full_Name : constant String := String (the_Exception.full_Name);\n\n begin\n-- recent_Exceptions.register_Usage (+full_Name);\n recent_Exceptions.register_Usage (the_Exception);\n Self.build_recent_List;\n\n Self.Invoked_by.set_Label (String (strip_standard_Prefix (identifier_Suffix (the_Exception.full_Name, 2))));\n Self.Invoked_by.set_Tooltip_Text (full_Name);\n\n Self.Target.my_Exception_is (Self.Slot, the_Exception);\n-- Self.Target.my_add_Exception (the_Exception);\n\n Self.Top.hide;\n end choice_is;\n\n\n\n procedure show (Self : in out Item; Invoked_by : in gtk_Button;\n Target : in adam.exception_Handler.view;\n Slot : in Positive)\n is\n begin\n Self.Invoked_by := Invoked_by;\n Self.Target := Target;\n Self.Slot := Slot;\n\n Self.Top.show_All;\n end show;\n\n\n\n procedure freshen (Self : in out Item)\n is\n use Adam;\n\n-- type a_Package;\n-- type Package_view is access all a_Package;\n--\n-- package package_Vectors is new ada.Containers.Vectors (Positive, Package_view);\n-- subtype Package_vector is package_Vectors.Vector;\n--\n-- type a_Package is\n-- record\n-- Name : adam.Text;\n-- Parent : Package_view;\n-- Children : Package_vector;\n--\n-- Exceptions : adam.text_Lines;\n-- end record;\n\n-- the_Exceptions : constant adam.text_Lines := adam.Assist.known_Exceptions;\n-- Root : aliased a_Package;\n\n begin\n-- Root.Name := +\"Root\";\n\n\n -- Clear out old notebook pages.\n --\n while Self.all_Notebook.Get_N_Pages > 0\n loop\n Self.all_Notebook.Get_Nth_Page (0).Destroy;\n end loop;\n\n\n -- Build the Gui tree.\n --\n build_Gui_Tree:\n declare\n\n procedure build_Gui_for (the_Package : in AdaM.a_Package.view;\n children_Notebook : in gtk_Notebook)\n is\n the_Children : AdaM.a_Package.Vector renames the_Package.child_Packages;\n the_exceptions_Palette_package : constant Palette.of_exceptions_subpackages.view\n := aIDE.Palette.of_exceptions_subpackages.to_exceptions_Palette_package;\n begin\n -- Build the package pane.\n --\n the_exceptions_Palette_package.Parent_is (Self'unchecked_Access);\n\n the_exceptions_Palette_package.top_Widget.Reparent (children_Notebook);\n children_Notebook.set_Tab_Label_Text (the_exceptions_Palette_package.top_Widget,\n +the_Package.Name);\n\n -- Build the exceptions sub-pane.\n --\n for Each of the_Package.all_Exceptions\n loop\n the_exceptions_Palette_package.add_Exception (Each, the_Package);\n-- the_exceptions_Palette_package.add_Exception (named => Each.Name,\n-- package_Name => the_Package.Name);\n-- -- package_Name => full_Name (the_Package));\n end loop;\n\n -- Configure event handling.\n --\n-- declare\n-- use gtk.Label;\n-- the_tab_Label : constant gtk_Label\n-- := gtk_Label (children_Notebook.get_tab_Label (the_exceptions_Palette_package.top_Widget));\n-- begin\n-- the_tab_Label.set_Selectable (True);\n-- label_return_Callbacks.connect (the_tab_Label,\n-- \"button-release-event\",\n-- on_tab_Label_clicked'Access,\n-- (package_name => the_Package.Name,\n-- palette => Self'unchecked_Access));\n-- end;\n\n -- Build each childs Gui.\n --\n for i in 1 .. Integer (the_Children.Length)\n loop\n build_Gui_for (the_Children.Element (i),\n the_exceptions_Palette_package.children_Notebook); -- Recurse.\n end loop;\n\n enable_bold_Tabs_for (the_exceptions_Palette_package.children_Notebook);\n end build_Gui_for;\n\n begin\n -- Recursively add sub-gui's for each package, rooted at 'Standard'.\n --\n-- for i in 1 .. Integer (the_Environ.standard_Package.Children.Length)\n-- loop\n-- build_Gui_for (the_Environ.standard_Package.child_Packages.Element (i).all'Access,\n-- Self.all_Notebook);\n-- end loop;\n\n-- for i in 1 .. Integer (the_entity_Environ.standard_Package.child_Packages.Length)\n-- loop\n-- build_Gui_for (the_Environ.standard_Package.child_Packages.Element (i).all'Access,\n-- Self.all_Notebook);\n-- end loop;\n\n build_Gui_for (the_entity_Environ.standard_Package,\n Self.all_Notebook);\n\n Self.all_Notebook.Popup_enable;\n Self.all_Notebook.Show_All;\n end build_Gui_Tree;\n\n Self.build_recent_List; -- todo: This is useless til usage stats are made persistent.\n end freshen;\n\n\n\n procedure destroy_Callback (Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class)\n is\n begin\n Widget.destroy;\n end destroy_Callback;\n\n\n\n procedure build_recent_List (Self : in out Item)\n is\n-- the_Recent : constant adam.text_Lines := recent_Exceptions.fetch;\n the_Recent : constant adam.Declaration.of_exception.vector := recent_Exceptions.fetch;\n the_Button : gtk_Button;\n\n Row, Col : Guint := 0;\n begin\n Self.recent_Table.Foreach (destroy_Callback'Access);\n\n for i in 1 .. Integer (the_Recent.Length)\n loop\n declare\n use adam,\n ada.Strings.Unbounded;\n-- the_Exception : adam.Text renames the_Recent.Element (i);\n the_Exception : constant adam.Declaration.of_exception.view := the_Recent.Element (i);\n begin\n put_Line (\"Recent: \" & String (the_Exception.full_Name));\n put_Line (\"Named : \" & String (assist. Tail_of (the_Exception.full_Name)));\n put_Line (\"package_Name: \" & String (assist.strip_Tail_of (the_Exception.full_Name)));\n\n-- gtk_New (the_Button, +the_Exception);\n the_Button := aIDE.Palette.of_exceptions_subpackages.new_Button\n (for_Exception => the_Exception,\n Named => String (assist. Tail_of (the_Exception.full_Name)),\n package_Name => String (assist.strip_Tail_of (the_Exception.full_Name)),\n exceptions_Palette => Self'unchecked_Access,\n use_simple_Name => False);\n\n Self.recent_Table.attach (the_Button,\n Col, Col + 1,\n Row, Row + 1,\n Xoptions => 0,\n Yoptions => 0);\n the_Button.show_All;\n\n if Row = 6 then\n Row := 0;\n Col := Col + 1;\n else\n Row := Row + 1;\n end if;" + }, + { + "function_def": "procedure register_Usage (the_Exception : in AdaM.a_Type.view);", + "function_body": "function fetch return AdaM.a_Type.vector;\n end recent_Exceptions;\n\n\n package body recent_Exceptions\n is\n type exception_Usage is\n record\n the_Exception : AdaM.a_Type.view;\n Count : Natural;\n end record;\n\n function \"<\" (L, R : in exception_Usage) return Boolean\n is\n use type AdaM.Identifier;\n begin\n return L.the_Exception.Name < R.the_Exception.Name;\n end \"<\";\n\n overriding function \"=\" (L, R : in exception_Usage) return Boolean\n is\n use type AdaM.Identifier;\n begin\n return L.the_Exception.Name = R.the_Exception.Name;\n end \"=\";\n\n package exception_Usage_Sets is new ada.Containers.Ordered_Sets (exception_Usage);\n the_usage_Stats : exception_Usage_Sets.Set;\n\n\n-- procedure register_Usage (the_Exception : in adam.Text)\n-- is\n-- use exception_Usage_Sets;\n--\n-- the_exception_Usage : exception_Usage := (the_Exception, others => <>);\n-- Current : constant exception_Usage_Sets.Cursor := the_usage_Stats.find (the_exception_Usage);\n-- begin\n-- if Current /= No_Element\n-- then\n-- the_exception_Usage.Count := Element (Current).Count + 1;\n-- the_usage_Stats.replace_Element (Current, the_exception_Usage);\n-- else\n-- the_exception_Usage.Count := 1;\n-- the_usage_Stats.insert (the_exception_Usage);\n-- end if;\n-- end register_Usage;\n\n procedure register_Usage (the_Exception : in AdaM.a_Type.view)\n is\n use exception_Usage_Sets;\n use type AdaM.a_Type.view;\n\n the_exception_Usage : exception_Usage := (the_Exception, others => <>);\n Current : constant exception_Usage_Sets.Cursor := the_usage_Stats.find (the_exception_Usage);\n begin\n if the_Exception = null\n then\n raise program_Error with \"NULLLLLLLL exception !!!\";\n else\n put_Line (\"ALL FINEEEEEEEEEEEEEEEEEEEEEE\");\n end if;\n\n if Current /= No_Element\n then\n the_exception_Usage.Count := Element (Current).Count + 1;\n the_usage_Stats.replace_Element (Current, the_exception_Usage);\n else\n the_exception_Usage.Count := 1;\n the_usage_Stats.insert (the_exception_Usage);\n end if;\n end register_Usage;\n\n\n\n function fetch return AdaM.a_Type.vector\n is\n use exception_Usage_Sets,\n ada.Containers;\n\n-- the_Lines : AdaM.text_Lines;\n the_Exceptions : AdaM.a_Type.vector;\n\n package type_Usage_Vectors is new ada.Containers.Vectors (Positive, exception_Usage);\n use type_Usage_Vectors;\n\n the_usage_List : type_Usage_Vectors.Vector;\n\n begin\n declare\n Cursor : exception_Usage_Sets.Cursor := the_usage_Stats.First;\n begin\n while has_Element (Cursor)\n loop\n if Element (Cursor).Count > 0 then\n the_usage_List.append (Element (Cursor));\n end if;\n\n exit when the_Exceptions.Length = 25; -- Limit results to 25 entries.\n next (Cursor);\n end loop;" + }, + { + "function_def": "procedure choice_is (Self : in out Item; --Now : in String;", + "function_body": "-- package_Name : in String;\n the_Type : in AdaM.a_Type.view)\n is\n use AdaM,\n AdaM.Assist;\n\n-- full_Name : constant String := package_Name & \".\" & Now;\n full_Name : constant String := String (the_Type.full_Name);\n\n begin\n-- recent_Exceptions.register_Usage (+full_Name);\n recent_Exceptions.register_Usage (the_Type);\n Self.build_recent_List;\n\n Self.Invoked_by.set_Label (String (strip_standard_Prefix (identifier_Suffix (the_Type.full_Name, 2))));\n Self.Invoked_by.set_Tooltip_Text (full_Name);\n\n Self.Target.all := the_Type;\n-- Self.Target.my_add_Exception (the_Exception);\n\n Self.Top.hide;\n end choice_is;\n\n\n\n procedure show (Self : in out Item; Invoked_by : in Gtk.Button.gtk_Button;\n Target : access AdaM.a_Type.view)\n is\n begin\n Self.Invoked_by := Invoked_by;\n Self.Target := Target;\n-- Self.Slot := Slot;\n\n Self.Top.show_All;\n end show;\n\n\n\n procedure freshen (Self : in out Item)\n is\n use Adam;\n\n-- type a_Package;\n-- type Package_view is access all a_Package;\n--\n-- package package_Vectors is new ada.Containers.Vectors (Positive, Package_view);\n-- subtype Package_vector is package_Vectors.Vector;\n--\n-- type a_Package is\n-- record\n-- Name : adam.Text;\n-- Parent : Package_view;\n-- Children : Package_vector;\n--\n-- Exceptions : adam.text_Lines;\n-- end record;\n\n-- the_Exceptions : constant adam.text_Lines := adam.Assist.known_Exceptions;\n-- Root : aliased a_Package;\n\n begin\n-- Root.Name := +\"Root\";\n\n\n -- Clear out old notebook pages.\n --\n while Self.all_Notebook.Get_N_Pages > 0\n loop\n Self.all_Notebook.Get_Nth_Page (0).Destroy;\n end loop;\n\n\n -- Build the Gui tree.\n --\n build_Gui_Tree:\n declare\n\n procedure build_Gui_for (the_Package : in AdaM.a_Package.view;\n children_Notebook : in gtk_Notebook)\n is\n the_Children : AdaM.a_Package.Vector renames the_Package.child_Packages;\n the_exceptions_Palette_package : constant Palette.of_types_subpackages.view\n := aIDE.Palette.of_types_subpackages.to_exceptions_Palette_package;\n begin\n -- Build the package pane.\n --\n the_exceptions_Palette_package.Parent_is (Self'unchecked_Access);\n\n the_exceptions_Palette_package.top_Widget.Reparent (children_Notebook);\n children_Notebook.set_Tab_Label_Text (the_exceptions_Palette_package.top_Widget,\n +the_Package.Name);\n\n -- Build the exceptions sub-pane.\n --\n for Each of the_Package.all_Types\n loop\n the_exceptions_Palette_package.add_Exception (Each, the_Package);\n-- the_exceptions_Palette_package.add_Exception (named => Each.Name,\n-- package_Name => the_Package.Name);\n-- -- package_Name => full_Name (the_Package));\n end loop;\n\n -- Configure event handling.\n --\n-- declare\n-- use gtk.Label;\n-- the_tab_Label : constant gtk_Label\n-- := gtk_Label (children_Notebook.get_tab_Label (the_exceptions_Palette_package.top_Widget));\n-- begin\n-- the_tab_Label.set_Selectable (True);\n-- label_return_Callbacks.connect (the_tab_Label,\n-- \"button-release-event\",\n-- on_tab_Label_clicked'Access,\n-- (package_name => the_Package.Name,\n-- palette => Self'unchecked_Access));\n-- end;\n\n -- Build each childs Gui.\n --\n for i in 1 .. Integer (the_Children.Length)\n loop\n build_Gui_for (the_Children.Element (i),\n the_exceptions_Palette_package.children_Notebook); -- Recurse.\n end loop;\n\n enable_bold_Tabs_for (the_exceptions_Palette_package.children_Notebook);\n end build_Gui_for;\n\n begin\n -- Recursively add sub-gui's for each package, rooted at 'Standard'.\n --\n-- for i in 1 .. Integer (the_Environ.standard_Package.Children.Length)\n-- loop\n-- build_Gui_for (the_Environ.standard_Package.child_Packages.Element (i).all'Access,\n-- Self.all_Notebook);\n-- end loop;\n\n-- for i in 1 .. Integer (the_entity_Environ.standard_Package.child_Packages.Length)\n-- loop\n-- build_Gui_for (the_Environ.standard_Package.child_Packages.Element (i).all'Access,\n-- Self.all_Notebook);\n-- end loop;\n\n build_Gui_for (the_entity_Environ.standard_Package,\n Self.all_Notebook);\n\n Self.all_Notebook.Popup_enable;\n Self.all_Notebook.Show_All;\n end build_Gui_Tree;\n\n Self.build_recent_List; -- todo: This is useless til usage stats are made persistent.\n end freshen;\n\n\n\n procedure destroy_Callback (Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class)\n is\n begin\n Widget.destroy;\n end destroy_Callback;\n\n\n\n procedure build_recent_List (Self : in out Item)\n is\n-- the_Recent : constant adam.text_Lines := recent_Exceptions.fetch;\n the_Recent : constant adam.a_Type.vector := recent_Exceptions.fetch;\n the_Button : gtk_Button;\n\n Row, Col : Guint := 0;\n begin\n Self.recent_Table.Foreach (destroy_Callback'Access);\n\n for i in 1 .. Integer (the_Recent.Length)\n loop\n declare\n use adam,\n ada.Strings.Unbounded;\n-- the_Exception : adam.Text renames the_Recent.Element (i);\n the_Exception : constant adam.a_Type.view := the_Recent.Element (i);\n begin\n put_Line (\"Recent: \" & String (the_Exception.full_Name));\n put_Line (\"Named : \" & String (assist. Tail_of (the_Exception.full_Name)));\n put_Line (\"package_Name: \" & String (assist.strip_Tail_of (the_Exception.full_Name)));\n\n-- gtk_New (the_Button, +the_Exception);\n the_Button := aIDE.Palette.of_types_subpackages.new_Button\n (for_Exception => the_Exception,\n Named => String (assist. Tail_of (the_Exception.full_Name)),\n package_Name => String (assist.strip_Tail_of (the_Exception.full_Name)),\n exceptions_Palette => Self'unchecked_Access,\n use_simple_Name => False);\n\n Self.recent_Table.attach (the_Button,\n Col, Col + 1,\n Row, Row + 1,\n Xoptions => 0,\n Yoptions => 0);\n the_Button.show_All;\n\n if Row = 6 then\n Row := 0;\n Col := Col + 1;\n else\n Row := Row + 1;\n end if;" + }, + { + "function_def": "-- procedure register_Usage (package_Name : in AdaM.Text;", + "function_body": "-- the_Package : in AdaM.a_Package.view)\n-- is\n-- use package_Usage_Sets;\n--\n-- the_type_Usage : package_Usage := (the_Package, package_Name, others => <>);\n-- Current : constant package_Usage_Sets.Cursor := the_usage_Stats.find (the_type_Usage);\n-- begin\n-- if Current /= No_Element\n-- then\n-- the_type_Usage.Count := Element (Current).Count + 1;\n-- the_usage_Stats.replace_Element (Current, the_type_Usage);\n-- else\n-- the_type_Usage.Count := 1;\n-- the_usage_Stats.insert (the_type_Usage);\n-- end if;\n-- end register_Usage;\n\n\n\n\n procedure register_Usage (the_Package : in AdaM.a_Package.view)\n is\n use package_Usage_Sets;\n\n the_type_Usage : package_Usage := (the_Package, others => <>);\n Current : constant package_Usage_Sets.Cursor := the_usage_Stats.find (the_type_Usage);\n begin\n if Current /= No_Element\n then\n the_type_Usage.Count := Element (Current).Count + 1;\n the_usage_Stats.replace_Element (Current, the_type_Usage);\n else\n the_type_Usage.Count := 1;\n the_usage_Stats.insert (the_type_Usage);\n end if;\n end register_Usage;\n\n\n\n function fetch return AdaM.a_Package.vector\n is\n use package_Usage_Sets,\n ada.Containers;\n\n-- the_Lines : AdaM.text_Lines;\n the_Packages : AdaM.a_Package.vector;\n\n package type_Usage_Vectors is new ada.Containers.Vectors (Positive, package_Usage);\n use type_Usage_Vectors;\n\n the_usage_List : type_Usage_Vectors.Vector;\n\n begin\n declare\n Cursor : package_Usage_Sets.Cursor := the_usage_Stats.First;\n begin\n while has_Element (Cursor)\n loop\n if Element (Cursor).Count > 0 then\n the_usage_List.append (Element (Cursor));\n end if;\n\n exit when the_Packages.Length = 25; -- Limit results to 25 entries.\n next (Cursor);\n end loop;" + }, + { + "function_def": "procedure choice_is (Self : in out Item; package_Name : in String;", + "function_body": "the_Package : in AdaM.a_Package.view)\n is\n use AdaM,\n AdaM.Assist;\n use type AdaM.context_Line.view,\n AdaM.a_Package.view;\n\n full_Name : constant String := package_Name;\n begin\n-- recent_Packages.register_Usage (+full_Name, the_Package);\n recent_Packages.register_Usage (the_Package);\n Self.build_recent_List;\n\n if Self.Invoked_by /= null\n then\n-- Self.Invoked_by.set_Label (full_Name);\n Self.Invoked_by.set_Label (String (identifier_Suffix (the_Package.full_Name, 2)));\n Self.Invoked_by.set_Tooltip_Text (String (the_Package.full_Name));\n end if;\n\n if Self.Target /= null and Self.Target_2 /= null\n then\n raise program_Error with \"Self.Target /= null and Self.Target_2 /= null\";\n end if;\n\n if Self.Target /= null\n then\n Self.Target.Name_is (full_Name);\n Self.Target.Package_is (the_Package.all'Access);\n\n elsif Self.Target_2 /= null\n then\n-- put_Line (\"JJJJJ \" & String (Self.Target_2.Name));\n-- aIDE.Gui.set_selected_Package (to => Self.Target_2);\n put_Line (\"JJJJJ \" & String (the_Package.Name));\n aIDE.Gui.set_selected_Package (to => the_Package);\n\n else\n raise program_Error with \"No target has been set\";\n end if;\n\n Self.Top.hide;\n end choice_is;\n\n\n\n procedure show (Self : in out Item; Invoked_by : in Gtk.Button.gtk_Button;\n Target : in AdaM.context_Line.view)\n is\n begin\n Self.Invoked_by := Invoked_by;\n Self.Target := Target;\n Self.Target_2 := null;\n\n Self.Top.show_All;\n end show;\n\n\n procedure show (Self : in out Item; Invoked_by : in Gtk.Button.gtk_Button;\n Target : in AdaM.a_Package.view)\n is\n begin\n Self.Invoked_by := Invoked_by;\n Self.Target_2 := Target;\n Self.Target := null;\n\n Self.freshen;\n Self.Top.show_All;\n end show;\n\n\n\n procedure freshen (Self : in out Item)\n is\n use AdaM;\n\n-- the_Environ : AdaM.Environment.Item renames aIDE.the_Environ;\n\n begin\n -- Clear out old notebook pages.\n --\n while Self.all_Notebook.Get_N_Pages > 0\n loop\n Self.all_Notebook.Get_Nth_Page (0).Destroy;\n end loop;\n\n\n -- Build the Gui tree.\n --\n build_Gui_Tree:\n declare\n procedure build_Gui_for (the_Package : in AdaM.a_Package.view;\n children_Notebook : in gtk_Notebook)\n is\n the_Children : AdaM.a_Package.Vector renames the_Package.child_Packages;\n the_packages_Palette_package : constant Palette.of_packages_subpackages.view\n := aIDE.Palette.of_packages_subpackages.to_packages_Palette_package;\n begin\n -- Build the package pane.\n --\n the_packages_Palette_package.Parent_is (Self'unchecked_Access);\n\n the_packages_Palette_package.top_Widget.reparent (children_Notebook);\n children_Notebook.set_Tab_Label_Text (the_packages_Palette_package.top_Widget,\n +the_Package.Name);\n -- Configure event handling.\n --\n declare\n use gtk.Label;\n the_tab_Label : constant gtk_Label\n := gtk_Label (children_Notebook.get_tab_Label (the_packages_Palette_package.top_Widget));\n begin\n the_tab_Label.set_Selectable (True);\n label_return_Callbacks.connect (the_tab_Label,\n \"button-release-event\",\n on_tab_Label_clicked'Access,\n (package_name => +(+the_Package.Name),\n palette => Self'unchecked_Access,\n the_Package => the_Package));" + }, + { + "function_def": "procedure build_recent_List (Self : in out Item)", + "function_body": "is\n-- the_Recent : constant AdaM.text_Lines := recent_Packages.fetch;\n the_Recent : constant AdaM.a_Package.vector := recent_Packages.fetch;\n the_Button : gtk_Button;\n\n Row, Col : Guint := 0;\n begin\n put_Line (\"build_recent_List\");\n\n Self.recent_Table.Foreach (destroy_Callback'Access);\n\n for i in 1 .. Integer (the_Recent.Length)\n loop\n declare\n use AdaM;\n the_Package : AdaM.a_Package.view renames the_Recent.Element (i);\n begin\n the_Button := aIDE.Palette.of_packages_subpackages.new_Button (for_Package => the_Package,\n Named => +the_Package.Name,\n packages_Palette => Self'unchecked_Access);\n Self.recent_Table.attach (the_Button,\n Col, Col + 1,\n Row, Row + 1,\n Xoptions => 0,\n Yoptions => 0);\n the_Button.show_All;\n\n if Row = 6\n then\n Row := 0;\n Col := Col + 1;\n else\n Row := Row + 1;\n end if;" + }, + { + "function_def": "procedure register_Usage (the_Type : in Identifier);", + "function_body": "function fetch return text_Lines;\n end recent_Types;\n\n\n package body recent_Types\n is\n type type_Usage is\n record\n Name : Text; -- The type name.\n Count : Natural; -- Number of times the type has been used.\n end record;\n\n use type Adam.Text;\n\n function \"<\" (L, R : in type_Usage) return Boolean\n is\n begin\n return L.Name < R.Name;\n end \"<\";\n\n overriding function \"=\" (L, R : in type_Usage) return Boolean\n is\n begin\n return L.Name = R.Name;\n end \"=\";\n\n package type_Usage_Sets is new ada.Containers.Ordered_Sets (type_Usage);\n the_usage_Stats : type_Usage_Sets.Set;\n\n\n procedure register_Usage (the_Type : in Identifier)\n is\n use type_Usage_Sets;\n\n the_type_Usage : type_Usage := (+String (the_Type), others => <>);\n Current : constant type_Usage_Sets.Cursor := the_usage_Stats.find (the_type_Usage);\n begin\n if Current /= No_Element\n then\n the_type_Usage.Count := Element (Current).Count + 1;\n the_usage_Stats.replace_Element (Current, the_type_Usage);\n else\n the_type_Usage.Count := 1;\n the_usage_Stats.insert (the_type_Usage);\n end if;\n end register_Usage;\n\n\n function fetch return text_Lines\n is\n use type_Usage_Sets,\n ada.Containers;\n\n the_Lines : text_Lines;\n\n package type_Usage_Vectors is new ada.Containers.Vectors (Positive, type_Usage);\n use type_Usage_Vectors;\n\n the_usage_List : type_Usage_Vectors.Vector;\n\n begin\n declare\n Cursor : type_Usage_Sets.Cursor := the_usage_Stats.First;\n begin\n while has_Element (Cursor)\n loop\n if Element (Cursor).Count > 0 then\n the_usage_List.append (Element (Cursor));\n end if;\n\n exit when the_Lines.Length = 25;\n next (Cursor);\n end loop;" + }, + { + "function_def": "procedure choice_is (Self : in out Item; Now : in String;", + "function_body": "package_Name : in String)\n is\n full_Name : constant Identifier := Identifier (package_Name & \".\" & Now);\n begin\n recent_Types.register_Usage (full_Name);\n Self.build_recent_List;\n\n Self.Invoked_by.set_Label (assist.type_button_Name_of (full_Name));\n Self.Invoked_by.set_Tooltip_Text (String (full_Name));\n\n-- Self.Target.all := +full_Name;\n\n-- declare\n-- use type Class.view;\n-- the_Class : constant Class.view := aIDE.fetch_Class (named => package_Name);\n-- begin\n-- if the_Class = null then\n Self.Target.all := aIDE.the_entity_Environ.find (full_Name); -- .Name_is (full_Name);\n-- Self.Target.all.Class_is (null);\n-- else\n-- -- Self.Target.all.Name_is (\"\");\n-- Self.Target.all := a_Type.class_type.new_Type.all'Access; -- .Class_is (the_Class);\n-- Self.Target.all.Class_is (the_Class);\n-- end if;\n-- end;\n\n Self.Top.hide;\n end choice_is;\n\n\n\n procedure show (Self : in out Item; Invoked_by : in gtk.Button.gtk_Button;\n Target : access adam.a_Type.view)\n is\n begin\n Self.Invoked_by := Invoked_by;\n Self.Target := Target;\n\n Self.Top.show_All;\n end show;\n\n\n\n procedure freshen (Self : in out Item)\n is\n type a_Package;\n type Package_view is access all a_Package;\n\n package package_Vectors is new ada.Containers.Vectors (Positive, Package_view);\n subtype Package_vector is package_Vectors.Vector;\n\n type a_Package is\n record\n Name : Text;\n Parent : Package_view;\n Children : Package_vector;\n\n Types : adam.text_Lines;\n end record;\n\n the_Types : constant adam.a_Type.Vector := aIDE.the_entity_Environ.all_Types;\n Root : aliased a_Package;\n\n\n function full_Name (the_Package : in Package_view) return String\n is\n use ada.Strings.Unbounded,\n text_Vectors;\n the_Name : Text;\n Parent : Package_view := the_Package.Parent;\n begin\n the_Name := the_Package.Name;\n\n while Parent /= null\n loop\n if Parent.Parent /= null then\n insert (the_Name, 1, +Parent.Name & \".\");\n end if;\n\n Parent := Parent.Parent;\n end loop;\n\n return +the_Name;\n end full_Name;\n\n\n function find_Child (Parent : in Package_view;\n Named : in String) return Package_view\n is\n use Adam.Assist;\n Names : text_Lines := Split (Named);\n begin\n-- put_Line (\"Finding '\" & Named & \"' in '\" & full_Name (Parent) & \"'\");\n\n for i in 1 .. Integer (Parent.Children.Length)\n loop\n declare\n use ada.Characters.handling;\n the_Child : constant Package_view := Parent.Children.Element (i);\n begin\n if to_Lower (+the_Child.Name) = to_Lower (Named) then\n return the_Child;\n end if;" + }, + { + "function_def": "procedure build_recent_List (Self : in out Item)", + "function_body": "is\n the_Recent : constant text_Lines := recent_Types.fetch;\n the_Button : gtk_Button;\n\n Row, Col : Guint := 0;\n begin\n Self.recent_Table.Foreach (destroy_Callback'Access);\n\n for i in 1 .. Integer (the_Recent.Length)\n loop\n declare\n use ada.Strings.Unbounded;\n the_Type : Text renames the_Recent.Element (i);\n begin\n new_Line;\n put_Line (+(\"Recent: \" & the_Type));\n put_Line (\" Tail: \" & assist. Tail_of (+the_Type));\n put_Line (\" Head: \" & assist.strip_Tail_of (+the_Type));\n\n-- gtk_New (the_Button, +the_Type);\n the_Button := aIDE.Palette.types_package.new_Button (Named => assist. Tail_of (+the_Type),\n package_Name => assist.strip_Tail_of (+the_Type),\n types_Palette => Self'unchecked_Access,\n use_simple_Name => False);\n Self.recent_Table.attach (the_Button,\n Col, Col + 1,\n Row, Row + 1,\n Xoptions => 0,\n Yoptions => 0);\n the_Button.show_All;\n\n if Row = 6 then\n Row := 0;\n Col := Col + 1;\n else\n Row := Row + 1;\n end if;" + }, + { + "function_def": "procedure Name_is (Self : in out Item; Now : in String)", + "function_body": "is\n begin\n Self.Name := +Now;\n end Name_is;\n\n\n\n function full_Name (Self : in Item) return Identifier\n is\n use type Entity.view;\n begin\n if Self.parent_Entity = null\n then\n return \"Standard.\" & (+Self.Name);\n else\n return a_Package.view (Self.parent_Entity).full_Name & \".\" & (+Self.Name);\n end if;\n end full_Name;\n\n\n\n -- Streams\n --\n\n procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : in View)\n is\n use Ada.Tags;\n begin\n if Self = null\n then\n AdaM.Id'write (Stream, null_Id);\n return;\n end if;\n\n AdaM.Id'write (Stream, Self.Id);\n String 'output (Stream, external_Tag (Self.all'Tag));\n end View_write;\n\n\n\n procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : out View)\n is\n Id : AdaM.Id;\n begin\n AdaM.Id'read (Stream, Id);\n\n if Id = null_Id\n then\n Self := null;\n return;\n end if;\n\n declare\n use Ada.Tags;\n the_String : constant String := String'Input (Stream); -- Read tag as string from stream.\n the_Tag : constant Tag := Descendant_Tag (the_String, Item'Tag); -- Convert to a tag.\n begin\n Self := View (AdaM.Factory.to_View (Id, the_Tag));" + }, + { + "function_def": "procedure register_Storer (the_Storer : access procedure)", + "function_body": "is\n begin\n all_Storers.append (the_Storer);\n end register_Storer;\n\n\n procedure register_Restorer (the_Restorer : access procedure)\n is\n begin\n all_Restorers.append (the_Restorer);\n end register_Restorer;\n\n\n\n\n type to_View_function is access function (Id : in AdaM.Id) return Any_view;\n\n function Hash is new ada.Unchecked_Conversion (ada.Tags.Tag, ada.Containers.Hash_Type);\n use type ada.Tags.Tag;\n\n package tag_Maps_of_to_View_function is new ada.Containers.Hashed_Maps (Key_Type => ada.Tags.Tag,\n Element_Type => to_View_function,\n Hash => Hash,\n Equivalent_Keys => \"=\");\n\n tag_Map_of_to_View_function : tag_Maps_of_to_View_function.Map;\n\n procedure register_to_view_Function (the_Tag : in ada.Tags.Tag;\n the_Function : access function (Id : in AdaM.Id) return Any_view)\n is\n begin\n tag_Map_of_to_View_function.insert (the_Tag, the_Function);\n end register_to_view_Function;\n\n\n\n function to_View (Id : in AdaM.Id; Tag : in ada.Tags.Tag) return Any_view\n is\n use tag_Maps_of_to_View_function;\n the_Function : constant to_View_function := Element (tag_Map_of_to_View_function.Find (Tag));\n begin\n return the_Function (Id);\n end to_View;\n\n\n\n -- Pools\n --\n\n\n package body Pools\n is\n use Interfaces.C;\n\n -- Arrays and Pointers for our Pool.\n --\n\n subtype item_Id is AdaM.Id range 1 .. AdaM.Id'Last;\n\n type Items is array (item_Id range <>) of aliased Item;\n\n type Addr is mod 2 ** System.Parameters.ptr_bits;\n\n function to_Addr is new Ada.Unchecked_Conversion (View, Addr);\n function to_Ptrdiff is new Ada.Unchecked_Conversion (Addr, Interfaces.C.ptrdiff_t);\n\n Elmt_Size : constant ptrdiff_t := (Items'Component_Size + System.Storage_Unit - 1)\n / System.Storage_Unit;\n\n\n function \"-\" (Left : in View;\n Right : in View) return ptrdiff_t\n is\n begin\n if Left = null\n or else Right = null\n then\n raise constraint_Error;\n end if;\n\n return To_Ptrdiff (To_Addr (Left) - To_Addr (Right))\n / Elmt_Size;\n end \"-\";\n\n\n -- The storage pool.\n --\n Pool : Items (1 .. item_Id (max_Items));\n pool_Last : AdaM.Id := null_Id;\n\n stored_record_Version : Positive;\n\n function storage_record_Version return Positive\n is\n begin\n return stored_record_Version;\n end storage_record_Version;\n\n\n package view_Vectors is new ada.Containers.Vectors (Positive, View);\n\n freed_Views : view_Vectors.Vector;\n\n\n -- 'View' to 'Id' Resolution.\n --\n\n function to_View (Id : in AdaM.Id) return View\n is\n begin\n return Pool (Id)'Access;\n end to_View;\n\n\n function to_View (Id : in AdaM.Id) return Any_view\n is\n begin\n if Id not in item_Id\n then\n raise Constraint_Error with \"AdaM.Factory ~ Bad pool Id (\" & item_Id'Image (Id) & \") for pool \" & pool_Name;\n end if;\n\n declare\n the_View : constant View := Pool (Id)'Access;\n begin\n return Any_view (the_View);" + }, + { + "function_def": "procedure standard_package_is (Self : in out Item; Now : in AdaM.a_Package.view)", + "function_body": "is\n begin\n Self.standard_Package := Now;\n end standard_package_is;\n\n\n\n function standard_Package (Self : in Item) return AdaM.a_Package.view\n is\n begin\n return Self.standard_Package;\n end standard_Package;\n\n\n\n function all_Types (Self : in Item) return AdaM.a_Type.Vector\n is\n the_Types : AdaM.a_Type.Vector;\n\n the_Unit : AdaM.compilation_Unit.view;\n pragma Unreferenced (the_Unit);\n-- the_Entity : AdaM.Source.Entity_View;\n\n use type AdaM.a_Type.view;\n begin\n for i in 1 .. Self.Length\n loop\n the_Unit := Self.Units.Element (i);\n\n-- for j in 1 .. the_Unit.Length\n-- loop\n-- the_Entity := the_Unit.Entity (j);\n--\n-- if the_Entity.all in AdaM.a_Type.item'Class\n-- then\n-- the_Types.append (AdaM.a_Type.view (the_Entity));\n-- end if;\n-- end loop;\n end loop;\n\n return the_Types;\n end all_Types;\n\n\n\n\n\n-- -- TODO: Move these to AdaM.Assist.\n--\n-- function parent_Name (Identifier : in String) return String\n-- is\n-- use Ada.Strings,\n-- Ada.Strings.fixed;\n-- I : constant Natural := Index (Identifier, \".\", going => Backward);\n-- begin\n-- if I = 0\n-- then\n-- return \"Standard\";\n-- end if;\n--\n-- return Identifier (Identifier'First .. I - 1);\n-- end parent_Name;\n--\n--\n--\n-- function simple_Name (Identifier : in String) return String\n-- is\n-- use Ada.Strings,\n-- Ada.Strings.fixed;\n-- I : constant Natural := Index (Identifier, \".\", going => Backward);\n-- begin\n-- if I = 0\n-- then\n-- return Identifier;\n-- end if;\n--\n-- return Identifier (I + 1 .. Identifier'Last);\n-- end simple_Name;\n--\n--\n--\n-- function Split (Identifier : in String) return text_Lines\n-- is\n-- use Ada.Strings,\n-- Ada.Strings.fixed;\n--\n-- First : Natural := Identifier'First;\n-- Last : Natural;\n--\n-- I : Natural;\n-- Lines : text_Lines;\n-- begin\n-- loop\n-- I := Index (Identifier, \".\", from => First);\n--\n-- if I = 0\n-- then\n-- Last := Identifier'Last;\n-- Lines.append (+Identifier (First .. Last));\n-- exit;\n-- end if;\n--\n-- Last := I - 1;\n-- Lines.append (+Identifier (First .. Last));\n-- First := I + 1;\n-- end loop;\n--\n-- return Lines;\n-- end Split;\n\n\n\n function find (Self : in Item; Identifier : in AdaM.Identifier) return AdaM.a_Package.view\n is\n use AdaM.Assist;\n the_Package : AdaM.a_Package.view := Self.standard_Package;\n begin\n if Identifier /= \"Standard\"\n then\n declare\n use type AdaM.a_Package.view;\n Names : constant text_Lines := Split (Identifier);\n begin\n for Each of Names\n loop\n the_Package := the_Package.child_Package (+Each);\n exit when the_Package = null;\n end loop;" + }, + { + "function_def": "procedure parent_Entity_is (Self : in out Item; Now : in Entity.View)", + "function_body": "is\n begin\n Self.parent_Entity := Now;\n end parent_Entity_is;\n\n\n\n function Children (Self : access Item) return Entities_view\n is\n begin\n return Self.Children'unchecked_Access;\n end Children;\n\n\n function Children (Self : in Item) return Entities'Class\n is\n begin\n return Self.Children;\n end Children;\n\n\n procedure Children_are (Self : in out Item; Now : in Entities'Class)\n is\n begin\n Self.Children := Entities (Now);\n end Children_are;\n\n\n\n function is_Public (Self : in Item) return Boolean\n is\n begin\n return Self.is_Public;\n end is_Public;\n\n\n procedure is_Public (Self : in out Item; Now : in Boolean := True)\n is\n begin\n Self.is_Public := Now;\n end is_Public;\n\n\n\n\n ----------\n -- Streams\n --\n\n procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : in View)\n is\n use Ada.Tags;\n begin\n if Self = null\n then\n AdaM.Id'write (Stream, null_Id);\n return;\n end if;\n\n AdaM.Id'write (Stream, Self.Id);\n String 'output (Stream, external_Tag (Self.all'Tag));\n end View_write;\n\n\n\n procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : out View)\n is\n Id : AdaM.Id;\n begin\n AdaM.Id'read (Stream, Id);\n\n if Id = null_Id\n then\n Self := null;\n return;\n end if;\n\n declare\n use Ada.Tags;\n the_String : constant String := String'Input (Stream); -- Read tag as string from stream.\n the_Tag : constant Tag := Descendant_Tag (the_String, Item'Tag); -- Convert to a tag.\n begin\n Self := View (AdaM.Factory.to_View (Id, the_Tag));" + }, + { + "function_def": "-- procedure Name_is (Self : in out Item; Now : in String)", + "function_body": "-- is\n-- begin\n-- Self.Name := +Now;\n-- end Name_is;\n\n\n\n function Context (Self : in Item) return AdaM.Context.view\n is\n begin\n return Self.Context;\n end Context;\n\n\n\n-- procedure add (Self : in out Item; the_Declaration : in Source.Entity_View)\n-- is\n-- begin\n-- Self.public_Entities.append (the_Declaration); -- Add the new attribute to current attributes.\n-- end add;\n--\n--\n-- procedure rid (Self : in out Item; the_Declaration : in Source.Entity_View)\n-- is\n-- begin\n-- Self.public_Entities.delete (Self.public_Entities.find_Index (the_Declaration)); -- Remove the old attribute from current attributes.\n-- end rid;\n--\n--\n--\n--\n-- function public_Entities (Self : access Item) return access Source.Entities\n-- is\n-- begin\n-- return Self.public_Entities'Access;\n-- end public_Entities;\n--\n--\n-- procedure public_Entities_are (Self : in out Item; Now : in Source.Entities)\n-- is\n-- begin\n-- Self.public_Entities := Now;\n-- end public_Entities_are;\n--\n\n\n-- function all_Exceptions (Self : in Item) return AdaM.Declaration.of_exception.Vector\n-- is\n-- use type Declaration.of_exception.view;\n--\n-- the_Exceptions : AdaM.Declaration.of_exception.Vector;\n-- the_Exception : AdaM.Declaration.of_exception.view;\n-- begin\n-- put_Line (\"PACKAGE NAME: \" & (+Self.Name));\n--\n-- for Each of Self.public_Entities\n-- loop\n-- put_Line (\"************* Tag: \" & ada.Tags.External_Tag (Each.all'Tag));\n-- raise program_Error with \"sdfhslkad\";\n--\n-- the_Exception := Declaration.of_exception.view (Each);\n--\n-- if the_Exception /= null\n-- -- if Each in AdaM.an_Exception.item'Class\n-- then\n-- the_Exceptions.append (the_Exception);\n-- end if;\n-- end loop;\n--\n-- return the_Exceptions;\n-- end all_Exceptions;\n\n\n function all_Exceptions (Self : access Item) return AdaM.Declaration.of_exception.Vector\n is\n use type Declaration.of_exception.view;\n\n the_Exceptions : AdaM.Declaration.of_exception.Vector;\n-- the_Exception : AdaM.Declaration.of_exception.view;\n begin\n-- put_Line (\"all_Exceptions PACKAGE NAME: \" & (+Self.Name));\n\n for Each of Self.Children.all\n loop\n-- put_Line (\"************* Tag: \" & ada.Tags.External_Tag (Each.all'Tag));\n-- raise program_Error with \"sdfhslkad\";\n\n-- the_Exception := Declaration.of_exception.view (Each);\n\n-- if the_Exception /= null\n if Each.all in AdaM.Declaration.of_Exception.item'Class\n then\n the_Exceptions.append (Declaration.of_exception.view (Each));\n end if;\n end loop;\n\n return the_Exceptions;\n end all_Exceptions;\n\n\n\n\n function all_Types (Self : access Item) return AdaM.a_Type.Vector\n is\n use type a_Type.view;\n\n the_Exceptions : AdaM.a_Type.Vector;\n-- the_Exception : AdaM.Declaration.of_exception.view;\n begin\n-- put_Line (\"all_Exceptions PACKAGE NAME: \" & (+Self.Name));\n\n for Each of Self.Children.all\n loop\n-- put_Line (\"************* Tag: \" & ada.Tags.External_Tag (Each.all'Tag));\n-- raise program_Error with \"sdfhslkad\";\n\n-- the_Exception := Declaration.of_exception.view (Each);\n\n-- if the_Exception /= null\n if Each.all in AdaM.a_Type.item'Class\n then\n the_Exceptions.append (a_Type.view (Each));\n end if;\n end loop;\n\n return the_Exceptions;\n end all_Types;\n\n\n\n\n\n\n\n overriding\n function to_Source (Self : in Item) return text_Vectors.Vector\n is\n use ada.Strings.unbounded;\n\n the_Source : text_Vectors.Vector;\n\n procedure add (the_Line : in Text)\n is\n begin\n the_Source.append (the_Line);\n end add;\n\n begin\n the_Source.append (Self.Context.to_Source);\n\n add (+\"\");\n add ( \"package \" & Self.Name);\n add (+\"is\");\n\n add (+\"\");\n\n-- the_Source.append (Self.public_Entities.to_spec_Source);\n\n add (+\"\");\n add ( \"end \" & Self.Name & \";\");\n\n return the_Source;\n end to_Source;\n\n\n\n function to_spec_Source (Self : in Item) return text_Vectors.Vector\n is\n use ada.Strings.unbounded;\n\n the_Source : text_Vectors.Vector;\n\n procedure add (the_Line : in Text)\n is\n begin\n the_Source.append (the_Line);\n end add;\n\n begin\n the_Source.append (Self.Context.to_Source);\n\n add (+\"\");\n add ( \"package \" & Self.Name);\n add (+\"is\");\n\n add (+\"\");\n\n-- the_Source.append (Self.public_Entities.to_spec_Source);\n\n add (+\"\");\n add ( \"end \" & Self.Name & \";\");\n\n return the_Source;\n end to_spec_Source;\n\n\n\n function to_body_Source (Self : in Item) return text_Vectors.Vector\n is\n use ada.Strings.unbounded;\n\n the_Source : text_Vectors.Vector;\n\n procedure add (the_Line : in Text)\n is\n begin\n the_Source.append (the_Line);\n end add;\n\n begin\n the_Source.append (Self.Context.to_Source);\n\n add (+\"\");\n add ( \"package body \" & Self.Name);\n add (+\"is\");\n\n add (+\"\");\n\n-- the_Source.append (Self.public_Entities.to_body_Source);\n\n add (+\"\");\n add ( \"end \" & Self.Name & \";\");\n\n return the_Source;\n end to_body_Source;\n\n\n\n function requires_Body (Self : in Item) return Boolean\n is\n pragma Unreferenced (Self);\n-- use AdaM.Source.utility;\n begin\n return False; -- contains_Subprograms (Self.public_Entities);\n end requires_Body;\n\n\n\n procedure Parent_is (Self : in out Item; Now : in Declaration.of_package.View)\n is\n begin\n Self.Parent := Now;\n end Parent_is;\n\n\n\n function Parent (Self : in Item) return Declaration.of_package.view\n is\n begin\n return Self.Parent;\n end Parent;\n\n\n\n\n function child_Packages (Self : in Item'Class) return Declaration.of_package.Vector\n is\n begin\n return Self.child_Packages;\n end child_Packages;\n\n\n function child_Package (Self : in Item'Class; Named : in String) return Declaration.of_package.view\n is\n begin\n for Each of Self.child_Packages\n loop\n if Each.Name = Named\n then\n return Each;\n end if;\n end loop;\n\n return null;\n end child_Package;\n\n\n\n procedure add_Child (Self : in out Item; Child : in Declaration.of_package.View)\n is\n begin\n Self.child_Packages.append (Child);\n end add_Child;\n\n\n\n function find (Self : in Item; Named : in Identifier) return AdaM.a_Type.view\n is\n begin\n for Each of Self.Children.all\n loop\n-- put_Line (\"--- find type in package \" & (+Self.Name) & \" --- Tag => \" & ada.Tags.External_Tag (Each.all'Tag));\n\n if Each.all in AdaM.a_Type.item'Class\n then\n if Each.Name = Named\n then\n return AdaM.a_Type.view (Each);\n end if;\n end if;\n end loop;\n\n put_Line (String (Named) & \" NOT FOUND in package \" & (+Self.Name));\n return null;\n end find;\n\n\n\n function find (Self : in Item; Named : in Identifier) return AdaM.Declaration.of_exception.view\n is\n begin\n for Each of Self.Children.all\n loop\n-- put_Line (\"--- find type in package \" & (+Self.Name) & \" --- Tag => \" & ada.Tags.External_Tag (Each.all'Tag));\n\n if Each.all in AdaM.Declaration.of_exception.item'Class\n then\n if Each.Name = Named\n then\n return AdaM.Declaration.of_exception.view (Each);\n end if;\n end if;\n end loop;\n\n put_Line (String (Named) & \" NOT FOUND in package \" & (+Self.Name));\n return null;\n end find;\n\n\n\n\n function full_Name (Self : in Item) return Identifier\n is\n begin\n if Self.Parent = null -- Is the Standard package.\n then\n return \"Standard\";\n end if;\n\n if Self.Parent.Name = \"Standard\"\n then\n return +Self.Name;\n else\n return Self.Parent.full_Name & \".\" & (+Self.Name);\n end if;\n end full_Name;\n\n\n\n -- Streams\n --\n\n procedure Item_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : in Item)\n is\n begin\n Text'write (Stream, Self.Name);\n\n Declaration.of_package.view 'write (Stream, Self.Parent);\n Declaration.of_package.Vector'write (Stream, Self.Progenitors);\n Declaration.of_package.Vector'write (Stream, Self.child_Packages);\n\n AdaM.Context.view'write (Stream, Self.Context);\n-- Source.Entities 'write (Stream, Self.public_Entities);\n\n Entity.view 'write (Stream, Self.parent_Entity);\n Entity.Entities'write (Stream, Self.Children);\n end Item_write;\n\n\n\n procedure Item_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class;\n Self : out Item)\n is\n Version : constant Positive := Pool.storage_record_Version;\n begin\n case Version\n is\n when 1 =>\n Text'read (Stream, Self.Name);\n-- put_Line (\"KKKKKKKKKKKKKK '\" & (+Self.Name) & \"'\");\n\n Declaration.of_package.view 'read (Stream, Self.Parent);\n Declaration.of_package.Vector'read (Stream, Self.Progenitors);\n Declaration.of_package.Vector'read (Stream, Self.child_Packages);\n\n AdaM.Context.view'read (Stream, Self.Context);\n-- Source.Entities 'read (Stream, Self.public_Entities);\n\n declare\n Parent : Declaration.of_package.view;\n begin\n Declaration.of_package.view'read (Stream, Parent);\n\n if Parent /= null\n then\n-- program_Unit.item (Self).parent_Entity_is (Parent.all'Access);\n Self.parent_Entity_is (Parent.all'Access);\n end if;" + }, + { + "function_def": "-- function Is_Navigation_Disabled (N : LAL.Ada_Node) return Boolean;", + "function_body": "function Node_Filter (N : LAL.Ada_Node) return Boolean\n is\n ( Enabled_Kinds (N.Kind));\n pragma Unreferenced (Node_Filter);\n-- and then not Is_Navigation_Disabled (N));\n\n procedure Process_File (Unit : LAL.Analysis_Unit; Filename : String);\n\n-- procedure Print_Navigation (Part_Name : String;\n-- Orig, Dest : access LAL.Ada_Node_Type'Class);\n\n At_Least_Once : Boolean := False;\n\n\n\n Depth : Natural := 0;\n\n function Indent return String\n is\n use Ada.Strings.fixed;\n begin\n return Depth * \" \";\n end Indent;\n\n procedure log (Message : in String)\n is\n begin\n put_Line (Indent & Message);\n end log;\n\n\n ----------\n -- Process\n --\n\n procedure process (Node : in LAL.Ada_Node);\n\n\n\n procedure parse_Range (the_Range : in LAL.Bin_Op;\n First : out Text;\n Last : out Text)\n is\n begin\n First := +to_String (the_Range.Child (1).Text);\n Last := +to_String (the_Range.Child (3).Text);\n end parse_Range;\n\n\n\n procedure parse_subtype_Indication (Node : in LAL.Subtype_Indication;\n new_Indication : out AdaM.subtype_Indication.item'Class)\n is\n\n index_Type : constant String := to_String (Node.F_Name.Text);\n Constraint : constant LAL.Range_Constraint := LAL.Range_Constraint (Node.Child (3));\n\n begin\n Depth := Depth + 1;\n\n log (\"parse_subtype_Indication\");\n\n -- Parse children.\n --\n new_Indication.main_Type_is (Environ.find (Identifier (index_Type)));\n\n if Constraint /= null\n then\n if Constraint.Child (1).Kind = LAL.Ada_Bin_Op\n then\n new_Indication.is_Constrained (True);\n\n declare\n the_Range : constant LAL.Bin_Op := LAL.Bin_Op (Constraint.Child (1));\n First : Text;\n Last : Text;\n begin\n parse_Range (the_Range, First, Last);\n\n new_Indication.First_is (+First);\n new_Indication.Last_is (+Last);" + }, + { + "function_def": "procedure run_Tests is new AUnit.Run.Test_Runner(GStreamer.tests.Rtsp_Suit.Suit);", + "function_body": "begin\n Run_Tests (Reporter);" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (Source => GcharPtr , Target => Interfaces.C.Strings.Chars_Ptr);", + "function_body": "function To_Ada ( C : access constant Glib.Gchar) return String is\n\n begin\n return (if C /= null\n then\n Interfaces.C.Strings.Value (Convert (C.all'Unrestricted_Access))\n else\n \"\");" + }, + { + "function_def": "procedure Simple_Producer is", + "function_body": "Config : Kafka.Config_Type;\n Handle : Kafka.Handle_Type;\n Topic : Kafka.Topic_Type;\n\n package CommandTopic is new GetCommandArgument (\"-t:\", \"--topic:\", \"Topic name to use\");\nbegin\n Ada.Text_IO.Put_Line(\"Kafka version: \" & Kafka.Version);\n\n -- Create a new config object\n Config := Kafka.Config.Create;\n\n -- Configure your properties\n Kafka.Config.Set(Config, \"client.id\", GNAT.Sockets.Host_name);\n Kafka.Config.Set(Config, \"bootstrap.servers\", \"localhost:9092\");\n\n -- Create handle\n Handle := Kafka.Create_Handle(Kafka.RD_KAFKA_PRODUCER, Config);\n\n -- Create topic handle\n Topic := Kafka.Topic.Create_Topic_Handle(Handle,\n CommandTopic.Parse_Command_Line(\"test_topic\")); -- topic must already exist\n\n -- Producing a String\n Kafka.Produce(Topic,\n Kafka.RD_KAFKA_PARTITION_UA,\n \"World\", -- payload\n \"Hello\", -- key\n System.Null_Address);\n\n -- Producing binary data\n declare\n type Some_Message is record\n A : Interfaces.Unsigned_32;\n B : Interfaces.Unsigned_64;\n C : Interfaces.Unsigned_8;\n end record\n with Convention => C;\n\n for Some_Message use record\n A at 0 range 0 .. 31;\n B at 4 range 0 .. 63;\n C at 12 range 0 .. 7;\n end record;\n\n for Some_Message'Bit_Order use System.High_Order_First;\n for Some_Message'Scalar_Storage_Order use System.High_Order_First;\n\n Message : Some_Message := (A => 55, B => 40002, C => 13);\n begin\n Kafka.Produce(Topic,\n Kafka.RD_KAFKA_PARTITION_UA,\n Kafka.RD_KAFKA_MSG_F_COPY,\n Message'Address,\n 13,\n System.Null_Address, -- key is optional\n 0,\n System.Null_Address);" + }, + { + "function_def": "procedure Simple_Consumer is", + "function_body": "use type System.Address;\n use type Interfaces.C.size_t;\n\n Config : Kafka.Config_Type;\n Handle : Kafka.Handle_Type;\n \n Handler : Signal.Handler; -- basic Signal handler to stop on CTRL + C\n package KafkaTopic is new GetCommandArgument (\"-t:\", \"--topic:\", \"Topic name to use\");\nbegin\n\t-- Create configuration\n Config := Kafka.Config.Create;\n\n -- Configure\n -- see librdkafka documentation on how to configure your Kafka consumer\n -- Kafka-Ada does not add any configuration entries of its own\n Kafka.Config.Set(Config, \"group.id\", GNAT.Sockets.Host_name);\n Kafka.Config.Set(Config, \"bootstrap.servers\", \"localhost:9092\");\n Kafka.Config.Set(Config, \"auto.offset.reset\", \"earliest\");\n\n Handle := Kafka.Create_Handle(Kafka.RD_KAFKA_CONSUMER, Config);\n\n Kafka.Consumer.Poll_Set_Consumer(Handle);\n\n declare\n Partition_List : Kafka.Partition_List_Type;\n begin\n Partition_List := Kafka.Topic.Partition.Create_List(1);\n Kafka.Topic.Partition.List_Add(Partition_List,\n KafkaTopic.Parse_Command_Line(\"test_topic\"), Kafka.RD_KAFKA_PARTITION_UA);\n \n Kafka.Subscribe(Handle, Partition_List);\n Kafka.Topic.Partition.Destroy_List(Partition_List);" + }, + { + "function_def": "procedure Stemwords is", + "function_body": "use Stemmer.Factory;\n\n function Get_Language (Name : in String) return Language_Type;\n function Is_Space (C : in Character) return Boolean;\n\n function Is_Space (C : in Character) return Boolean is\n begin\n return C = ' ' or C = ASCII.HT;\n end Is_Space;\n\n function Get_Language (Name : in String) return Language_Type is\n begin\n return Language_Type'Value (\"L_\" & Name);\n\n exception\n when Constraint_Error =>\n Ada.Text_IO.Put_Line (\"Unsupported language: \" & Ada.Command_Line.Argument (1));\n return L_ENGLISH;\n\n end Get_Language;\n\n Count : constant Natural := Ada.Command_Line.Argument_Count;\nbegin\n if Count <= 1 then\n Ada.Text_IO.Put_Line (\"Usage: stemwords language file\");\n return;\n end if;\n declare\n Lang : constant Language_Type := Get_Language (Ada.Command_Line.Argument (1));\n Path : constant String := Ada.Command_Line.Argument (2);\n File : Ada.Text_IO.File_Type;\n begin\n Ada.Text_IO.Open (File, Ada.Text_IO.In_File, Path);\n while not Ada.Text_IO.End_Of_File (File) loop\n declare\n Line : constant String := Ada.Text_IO.Get_Line (File);\n Pos : Positive := Line'First;\n Last_Pos : Positive;\n Start_Pos : Positive;\n begin\n while Pos <= Line'Last loop\n Last_Pos := Pos;\n while Pos <= Line'Last and then Is_Space (Line (Pos)) loop\n Pos := Pos + 1;\n end loop;\n if Last_Pos < Pos then\n Ada.Text_IO.Put (Line (Last_Pos .. Pos - 1));\n end if;\n exit when Pos > Line'Last;\n Start_Pos := Pos;\n while Pos <= Line'Last and then not Is_Space (Line (Pos)) loop\n Pos := Pos + 1;\n end loop;\n Ada.Text_IO.Put (Stemmer.Factory.Stem (Lang, Line (Start_Pos .. Pos - 1)));\n end loop;\n Ada.Text_IO.New_Line;" + }, + { + "function_def": "procedure Stemargs is", + "function_body": "use Stemmer.Factory;\n\n function Get_Language (Name : in String) return Language_Type;\n\n function Get_Language (Name : in String) return Language_Type is\n begin\n return Language_Type'Value (\"L_\" & Name);\n\n exception\n when Constraint_Error =>\n Ada.Text_IO.Put_Line (\"Unsupported language: \" & Ada.Command_Line.Argument (1));\n return L_ENGLISH;\n\n end Get_Language;\n\n Count : constant Natural := Ada.Command_Line.Argument_Count;\nbegin\n if Count <= 1 then\n Ada.Text_IO.Put_Line (\"Usage: stemargs language words...\");\n return;\n end if;\n declare\n Lang : constant Language_Type := Get_Language (Ada.Command_Line.Argument (1));\n begin\n for I in 2 .. Count loop\n Ada.Text_IO.Put_Line (Stem (Lang, Ada.Command_Line.Argument (I)));\n end loop;" + }, + { + "function_def": "procedure Car is", + "function_body": "--class\ntype Car is tagged\n record\n wheels : Integer;\n doors : Integer;\n cylinders : Integer;\n end record;\n-- functions \n--prior to Ada 2012, passed arguments could not be written to\n--that would defeat the purpose of writing functions for records\nprocedure addWheels(myCar : in out Car; wheelsIn : Integer)\nis\nbegin\n myCar.wheels := myCar.wheels + wheelsIn;\nend addWheels; \n\nprocedure addDoors(myCar : in out Car; doorsIn : Integer)\nis\nbegin\n myCar.doors := myCar.doors + doorsIn;\nend addDoors; \n\nprocedure addCylinders(myCar : in out Car; cylindersIn : Integer)\nis\nbegin\n myCar.cylinders := myCar.cylinders + cylindersIn;\nend addCylinders; \n\nprocedure deleteWheels(myCar : in out Car; wheelsIn : Integer)\nis\nbegin\n myCar.wheels := myCar.wheels - wheelsIn;\nend deleteWheels; \n\nprocedure deleteDoors(myCar : in out Car; doorsIn : Integer)\nis\nbegin\n myCar.doors := myCar.doors - doorsIn;\nend deleteDoors; \n\nprocedure deleteCylinders(myCar : in out Car; cylindersIn : Integer)\nis\nbegin\n myCar.cylinders := myCar.cylinders - cylindersIn;\nend deleteCylinders;\n\n--main program block\nbegin\n Put_Line(\"Creating car.\");\n declare\n subaru : Car;\n begin\n subaru.wheels := 4;\n subaru.doors := 4;\n subaru.cylinders := 4;\n Put(\"Wheel check: \");\n Put(Integer'Image(subaru.wheels));\n New_Line;\n Put(\"Door check: \");\n Put(Integer'Image(subaru.doors));\n New_Line;\n Put(\"Cylinder check: \");\n Put(Integer'Image(subaru.cylinders));\n New_Line;\n New_Line;\n Put_Line(\"Adding wheel directly to car object.\");\n subaru.wheels := subaru.wheels + 1;\n Put(\"Wheel check: \");\n Put(Integer'Image(subaru.wheels));\n New_Line;\n Put(\"Door check: \");\n Put(Integer'Image(subaru.doors));\n New_Line;\n Put(\"Cylinder check: \");\n Put(Integer'Image(subaru.cylinders));\n New_Line;\n New_Line;\n Put_Line(\"Removing wheel using object method.\");\n deleteWheels(subaru, 1);\n Put(\"Wheel check: \");\n Put(Integer'Image(subaru.wheels));\n New_Line;\n Put(\"Door check: \");\n Put(Integer'Image(subaru.doors));\n New_Line;\n Put(\"Cylinder check: \");\n Put(Integer'Image(subaru.cylinders));\n New_Line;" + }, + { + "function_def": "procedure Free_Logger_Msg_Ptr is new Ada.Unchecked_Deallocation", + "function_body": "(Object => Logger_Message_Packet, Name => Logger_Message_Packet_Ptr);\n\n function Format_Log_Level\n (Use_Color : Boolean;\n Log_Level : Log_Levels)\n return Unbounded_String\n is\n Color_Prefix : Unbounded_String;\n Log_Level_Str : Unbounded_String;\n Now : constant Time := Clock;\n begin\n\n -- Add ANSI color codes if we're using color on Linux\n if Use_Color\n then\n case Log_Level is\n when EMERGERENCY =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when ALERT =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when CRITICAL =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Red);\n when ERROR =>\n Color_Prefix := To_Unbounded_String (ANSI_Red);\n when WARNING =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Yellow);\n when NOTICE =>\n Color_Prefix := To_Unbounded_String (ANSI_Yellow);\n when INFO =>\n Color_Prefix := To_Unbounded_String (ANSI_Green);\n when DEBUG =>\n Color_Prefix := To_Unbounded_String (ANSI_Light_Blue);\n end case;\n\n Log_Level_Str :=\n Color_Prefix & To_Unbounded_String (Log_Level'Image) & ANSI_Reset;\n else\n Log_Level_Str := To_Unbounded_String (Log_Level'Image);\n end if;\n\n return To_Unbounded_String\n (Image (Date => Now) & \" [\" & To_String (Log_Level_Str) & \"]\");\n end Format_Log_Level;\n\n function Create_String_From_Components\n (Components : Component_Vector.Vector)\n return Unbounded_String\n is\n Components_String : Unbounded_String;\n procedure Component_To_String (c : Component_Vector.Cursor) is\n Scratch_String : Unbounded_String;\n begin\n Scratch_String := Components (c);\n Components_String := Components_String & \"[\" & Scratch_String & \"]\";\n end Component_To_String;\n begin\n -- If there's no component, just leave it blank\n if Components.Length = 0\n then\n return To_Unbounded_String (\"\");\n end if;\n\n Components.Iterate (Component_To_String'Access);\n return Components_String;\n end Create_String_From_Components;\n\n protected body Logger_Queue_Type is\n -- Handles queue of packets for the logger thread\n entry Add_Packet (Queue : Logger_Message_Packet_Ptr) when True is\n begin\n Queued_Packets.Append (Queue);\n end Add_Packet;\n\n entry Get (Queue : out Logger_Message_Packet_Ptr)\n when Queued_Packets.Length > 0 is\n begin\n Queue := Queued_Packets.First_Element;\n Queued_Packets.Delete_First;\n end Get;\n\n entry Count (Count : out Integer) when True is\n begin\n Count := Integer (Queued_Packets.Length);\n end Count;\n\n entry Empty when True is\n begin\n declare\n procedure Dump_Vector_Data\n (c : Logger_Message_Packet_Vector.Cursor)\n is\n begin\n Free_Logger_Msg_Ptr (Queued_Packets (c));\n end Dump_Vector_Data;\n begin\n Queued_Packets.Iterate (Dump_Vector_Data'access);" + }, + { + "function_def": "procedure Process_Queue is", + "function_body": "procedure Print_Messages (c : Log_Message_Vector.Cursor) is\n Current_Msg : constant Log_Message_Record :=\n Log_Message_Vector.Element (c);\n begin\n -- This is so ugly :(\n if Log_Levels'Enum_Rep (Logger_Cfg.Log_Level) >=\n Log_Levels'Enum_Rep (Current_Msg.Log_Level)\n then\n Msg_String :=\n Format_Log_Level\n (Logger_Cfg.Use_Color, Current_Msg.Log_Level);\n Msg_String :=\n Msg_String &\n Create_String_From_Components (Current_Msg.Component);\n Msg_String := Msg_String & \" \" & Current_Msg.Message;\n Put_Line (To_String (Msg_String));\n end if;\n end Print_Messages;\n\n begin\n Logger_Queue.Count (Queues_To_Process);\n while Queues_To_Process > 0\n loop\n Logger_Queue.Get (Current_Queue);\n\n -- Get a local copy and then empty it; we don't care past that\n -- point\n if Current_Queue /= null\n then\n Current_Queue.Get_All_And_Empty (Msg_Packets);\n Msg_Packets.Iterate (Print_Messages'Access);\n Free_Logger_Msg_Ptr (Current_Queue);\n end if;\n\n Logger_Queue.Count (Queues_To_Process);\n end loop;\n\n exception\n -- Not sure if there's a better way to do this, but avoids a race\n -- condition\n when Constraint_Error =>\n begin\n null;" + }, + { + "function_def": "function To_Domain_Section is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => Domain_Section);\n begin\n Domain_Name := Domain_Name & To_Domain_Section (Raw_Data.all\n (Offset .. Stream_Element_Offset (Section_Length)));\n\n Offset := Offset + Stream_Element_Offset (Section_Length);" + }, + { + "function_def": "function Get_Byte_Fixed_Header is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => Packer_Pointer);\n begin\n -- Oh, and for more fuckery, the pointer is 16-bit ...\n Packet_Ptr := Get_Byte_Fixed_Header (Raw_Data.all\n (Offset .. Offset + 1)); -- Make the top bytes vanish\n\n -- We subtract 12-1 for the packet header\n Packet_Ptr.Packet_Offset :=\n (Packet_Ptr.Packet_Offset and 16#3fff#) - 11;\n\n -- Sanity check ourselves\n if (Section_Length and 2#11#) /= 0\n then\n -- Should never happen but you never know ...\n raise Unknown_Compression_Method;\n end if;\n\n -- Now we need to decode the whole old string ... ugh\n Decompressed_Domain_String :=\n Parse_DNS_Packet_Name_Records\n (Raw_Data,\n Stream_Element_Offset (Packet_Ptr.Packet_Offset));\n Offset := Offset + 2;\n return Domain_Name & Decompressed_Domain_String;" + }, + { + "function_def": "function To_RData is new Ada.Unchecked_Conversion", + "function_body": "(Source => Stream_Element_Array, Target => RData);\n begin\n Parsed_Response.RData := To_Unbounded_String (To_RData (Raw_Data\n (Offset .. Stream_Element_Offset (RData_Length))));\n Offset := Offset + Stream_Element_Offset (RData_Length);" + }, + { + "function_def": "procedure Start_Server is", + "function_body": "-- Input and Output Sockets\n Capture_Config : DNSCatcher.Config.Configuration;\n\n DNS_Transactions : DNSCatcher.DNS.Transaction_Manager\n .DNS_Transaction_Manager_Task;\n Receiver_Interface : DNSCatcher.Network.UDP.Receiver\n .UDP_Receiver_Interface;\n Sender_Interface : DNSCatcher.Network.UDP.Sender.UDP_Sender_Interface;\n Logger_Task : DNSCatcher.Utils.Logger.Logger;\n Transaction_Manager_Ptr : DNS_Transaction_Manager_Task_Ptr;\n Socket : Socket_Type;\n Logger_Packet : DNSCatcher.Utils.Logger.Logger_Message_Packet_Ptr;\n\n procedure Free_Transaction_Manager is new Ada.Unchecked_Deallocation\n (Object => DNS_Transaction_Manager_Task,\n Name => DNS_Transaction_Manager_Task_Ptr);\n begin\n -- Load the config file from disk\n DNSCatcher.Config.Initialize (Capture_Config);\n DNSCatcher.Config.Read_Cfg_File\n (Capture_Config, \"conf/dnscatcherd.conf\");\n\n -- Configure the logger\n Capture_Config.Logger_Config.Log_Level := DEBUG;\n Capture_Config.Logger_Config.Use_Color := True;\n\n Logger_Task.Initialize (Capture_Config.Logger_Config);\n Transaction_Manager_Ptr := new DNS_Transaction_Manager_Task;\n\n -- Connect the packet queue and start it all up\n Logger_Task.Start;\n Logger_Packet := new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message (NOTICE, \"DNSCatcher starting up ...\");\n DNSCatcher.Utils.Logger.Logger_Queue.Add_Packet (Logger_Packet);\n\n -- Socket has to be shared between receiver and sender. This likely needs\n -- to move to to a higher level class\n begin\n Create_Socket\n (Socket => Socket,\n Mode => Socket_Datagram);\n Set_Socket_Option\n (Socket => Socket,\n Level => IP_Protocol_For_IP_Level,\n Option => (GNAT.Sockets.Receive_Timeout, Timeout => 1.0));\n Bind_Socket\n (Socket => Socket,\n Address =>\n (Family => Family_Inet, Addr => Any_Inet_Addr,\n Port => Capture_Config.Local_Listen_Port));\n exception\n when Exp_Error : GNAT.Sockets.Socket_Error =>\n begin\n Logger_Packet :=\n new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message\n (ERROR, \"Socket error: \" & Exception_Information (Exp_Error));\n Logger_Packet.Log_Message (ERROR, \"Refusing to start!\");\n Logger_Queue.Add_Packet (Logger_Packet);\n goto Shutdown_Procedure;" + }, + { + "function_def": "function Uint8_To_Character is new Ada.Unchecked_Conversion", + "function_body": "(Source => Unsigned_8, Target => Character);\n function Uint16_To_String is new Ada.Unchecked_Conversion\n (Source => Unsigned_16, Target => QAttributes);\n -- Actually does the dirty work of creating a question\n function Create_QName_Record\n (Domain_Section : String)\n return String\n is\n Label : String (1 .. Domain_Section'Length + 1);\n begin\n if Domain_Section /= \".\"\n then\n Label (1) :=\n Uint8_To_Character (Unsigned_8 (Domain_Section'Length));\n Label\n (2 .. Domain_Section'Length + 1) := Domain_Section;\n else\n -- If this is a \".\" by itself, it's the terminator, and we need to\n -- do special handling\n declare\n Empty_Label : String (1 .. 1);\n begin\n Empty_Label (1) := Uint8_To_Character (Unsigned_8 (0));\n return Empty_Label;" + }, + { + "function_def": "function String_To_Packet is new Ada.Unchecked_Conversion", + "function_body": "(Source => String, Target => QData_SEA);\n\n begin\n Outbound_Packet.Raw_Data.Data :=\n new Stream_Element_Array (1 .. QData'Length);\n Outbound_Packet.Raw_Data.Data.all := String_To_Packet (QData);\n Outbound_Packet.Raw_Data_Length :=\n DNS_PACKET_HEADER_SIZE + QData'Length;" + }, + { + "function_def": "-- Parse_Procedure is an access procedure that is used as a common prototype", + "function_body": "-- for all parsing functionality dispatched from GCP_Management and other\n -- vectors.\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n type Parse_Procedure is access procedure\n (Config : in out Configuration;\n Value_Str : String);\n\n -- GCP_Management is a vector that handles dynamic dispatch to the\n -- parsing parameters above; it is used to match key/values from the\n -- config file to\n package GCP_Management is new Ada.Containers.Indefinite_Ordered_Maps\n (String, Parse_Procedure);\n\n GCP_Map : GCP_Management.Map;\n\n -- Configuration constructor\n procedure Initialize (Config : in out Configuration) is\n begin\n -- We initialize the ports to 53 by default\n Config.Local_Listen_Port := 53;\n Config.Upstream_DNS_Server_Port := 53;\n\n -- No upstream server is set\n Config.Upstream_DNS_Server := To_Unbounded_String (\"\");\n end Initialize;\n\n -- Loads the load listen value and sets it in the config record\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Local_Listen_Port\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Local_Listen_Port := Port_Type'Value (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line with \"Local_Listen_Port not a valid port number\";\n end Parse_Local_Listen_Port;\n\n -- Loads the upstream DNS Server from the config file\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Upstream_DNS_Server\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Upstream_DNS_Server := To_Unbounded_String (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line with \"Invalid upstrema DNS Server\";\n end Parse_Upstream_DNS_Server;\n\n -- Loads the upstream DNS Server port from the config file\n --\n -- @value Config\n -- Configuration struct to update\n --\n -- @value Value_Str\n -- Pure text version of the configuration argument\n --\n procedure Parse_Upstream_DNS_Server_Port\n (Config : in out Configuration;\n Value_Str : String)\n is\n begin\n Config.Upstream_DNS_Server_Port := Port_Type'Value (Value_Str);\n exception\n when Constraint_Error =>\n raise Malformed_Line\n with \"Upstream_DNS_Server_Port not a valid port number\";\n end Parse_Upstream_DNS_Server_Port;\n\n procedure Initialize_Config_Parse is\n begin\n -- Load String to Type Mapping\n GCP_Map.Insert (\"LOCAL_LISTEN_PORT\", Parse_Local_Listen_Port'Access);\n GCP_Map.Insert (\"UPSTREAM_DNS_SERVER\", Parse_Upstream_DNS_Server'Access);\n GCP_Map.Insert\n (\"UPSTREAM_DNS_SERVER_PORT\", Parse_Upstream_DNS_Server_Port'Access);\n end Initialize_Config_Parse;\n\n procedure Read_Cfg_File\n (Config : in out Configuration;\n Config_File_Path : String)\n is\n Config_File : Ada.Text_IO.File_Type;\n Line_Count : Integer := 1;\n Exception_Message : Unbounded_String;\n use GCP_Management;\n begin\n Initialize_Config_Parse;\n\n -- Try to open the configuration file\n Open\n (File => Config_File,\n Mode => Ada.Text_IO.In_File,\n Name => Config_File_Path);\n\n while not End_Of_File (Config_File)\n loop\n declare\n Current_Line : constant String := Get_Line (Config_File);\n Key_End_Loc : Integer := 0;\n Equals_Loc : Integer := 0;\n Value_Loc : Integer := 0;\n Is_Whitespace : Boolean := True;\n begin\n -- Skip lines starting with a comment or blank\n if Current_Line = \"\"\n then\n goto Config_Parse_Continue;\n end if;\n\n -- Has to be done seperately or it blows an index check\n if Current_Line (1) = '#'\n then\n goto Config_Parse_Continue;\n end if;\n\n -- Skip line if its all whitespace\n for I in Current_Line'range\n loop\n if Current_Line (I) /= ' ' and\n Current_Line (I) /= Ada.Characters.Latin_1.HT\n then\n Is_Whitespace := False;\n end if;\n\n if Current_Line (I) = '='\n then\n Equals_Loc := I;\n end if;\n\n -- Determine length of the key\n --\n -- This is a little non-obvious at first glance. We subtract 2\n -- here to remove the character we want, and the previous char\n -- because a 17 char string will be 1..18 in the array.\n\n if (Is_Whitespace or Current_Line (I) = '=') and Key_End_Loc = 0\n then\n Key_End_Loc := I - 2;\n end if;\n\n exit when Is_Whitespace and Equals_Loc /= 0;\n -- We also want to confirm there's a = in there somewhere\n end loop;\n\n -- It's all whitespace, skip it\n if Is_Whitespace\n then\n goto Config_Parse_Continue;\n end if;\n\n if Equals_Loc = 0\n then\n Exception_Message :=\n To_Unbounded_String (\"Malformed line (no = found) at\");\n Append (Exception_Message, Line_Count'Image);\n Append (Exception_Message, \": \");\n Append (Exception_Message, Current_Line);\n\n raise Malformed_Line with To_String (Exception_Message);\n end if;\n\n -- Read in the essential values\n for C in GCP_Map.Iterate\n loop\n -- Slightly annoying, but need to handle not reading past the\n -- end of Current_Line. We also need to check that the next char\n -- is a space or = so we don't match substrings by accident.\n if Key_End_Loc = Key (C)'Length\n then\n if Key (C) = To_Upper (Current_Line\n (1 .. Key (C)'Length))\n then\n -- Determine the starting character of the value\n for I in Current_Line\n (Equals_Loc + 1 .. Current_Line'Length)'range\n loop\n if Current_Line (I) /= ' ' and\n Current_Line (I) /= Ada.Characters.Latin_1.HT\n then\n Value_Loc := I;\n exit;\n end if;\n end loop;\n\n -- If Value_Loc is zero, pass an empty string in\n if Value_Loc = 0\n then\n Element (C).all (Config, \"\");\n else\n Element (C).all (Config, Current_Line\n (Value_Loc .. Current_Line'Length));\n end if;\n end if;\n end if;\n end loop;\n\n <>\n Line_Count := Line_Count + 1;" + }, + { + "function_def": "procedure DNSC is", + "function_body": "DClient : DNSCatcher.DNS.Client.Client;\n Capture_Config : DNSCatcher.Config.Configuration;\n Logger_Task : DNSCatcher.Utils.Logger.Logger;\n Transaction_Manager_Ptr : DNS_Transaction_Manager_Task_Ptr;\n Sender_Interface : DNSCatcher.Network.UDP.Sender.UDP_Sender_Interface;\n Receiver_Interface : DNSCatcher.Network.UDP.Receiver.UDP_Receiver_Interface;\n Outbound_Packet : Raw_Packet_Record_Ptr;\n Logger_Packet : DNSCatcher.Utils.Logger.Logger_Message_Packet_Ptr;\n Socket : Socket_Type;\n\nbegin\n Capture_Config.Local_Listen_Port := 41231;\n Capture_Config.Upstream_DNS_Server := To_Unbounded_String (\"4.2.2.2\");\n Capture_Config.Upstream_DNS_Server_Port := 53;\n\n -- Configure the logger\n Capture_Config.Logger_Config.Log_Level := DEBUG;\n Capture_Config.Logger_Config.Use_Color := True;\n\n Logger_Task.Initialize (Capture_Config.Logger_Config);\n Logger_Task.Start;\n Logger_Packet := new Logger_Message_Packet;\n\n Transaction_Manager_Ptr := new DNS_Transaction_Manager_Task;\n\n -- Socket has to be shared between receiver and sender. This likely needs to\n -- move to to a higher level class\n begin\n Create_Socket\n (Socket => Socket,\n Mode => Socket_Datagram);\n Set_Socket_Option\n (Socket => Socket,\n Level => IP_Protocol_For_IP_Level,\n Option => (GNAT.Sockets.Receive_Timeout, Timeout => 1.0));\n Bind_Socket\n (Socket => Socket,\n Address =>\n (Family => Family_Inet, Addr => Any_Inet_Addr,\n Port => Capture_Config.Local_Listen_Port));\n exception\n when Exp_Error : GNAT.Sockets.Socket_Error =>\n begin\n Logger_Packet := new DNSCatcher.Utils.Logger.Logger_Message_Packet;\n Logger_Packet.Log_Message\n (ERROR, \"Socket error: \" & Exception_Information (Exp_Error));\n Logger_Packet.Log_Message (ERROR, \"Refusing to start!\");\n Logger_Queue.Add_Packet (Logger_Packet);\n goto Shutdown_Procedure;" + }, + { + "function_def": "procedure DNSCatcherD is", + "function_body": "begin\n Install_Handler (Handler => Signal_Handlers.SIGINT_Handler'Access);\n DNSCatcher.DNS.Server.Start_Server;\nexception\n when Error : Ada.IO_Exceptions.Name_Error =>\n begin\n Put (Standard_Error, \"FATAL: Unable to open config file: \");\n Put_Line (Standard_Error, Exception_Message (Error));\n DNSCatcher.DNS.Server.Stop_Server;" + }, + { + "function_def": "procedure Dispose is new Ada.Unchecked_Deallocation (Dir_Entries, Pdir_Entries);", + "function_body": "procedure Resize (A : in out Pdir_Entries; Size : Integer) is\n Hlp : constant Pdir_Entries := new Dir_Entries (1 .. Size);\n begin\n if A = null then\n A := Hlp;\n else\n Hlp (1 .. Integer'Min (Size, A'Length)) := A (1 .. Integer'Min (Size, A'Length));\n Dispose (A);\n A := Hlp;\n end if;\n end Resize;\n\n -- Internal - add the catalogue entry corresponding to a\n -- compressed file in the Zip archive.\n -- The entire catalogue will be written at the end of the zip stream,\n -- and the entry as a local header just before the compressed data.\n -- The entry's is mostly incomplete in the end (name, size, ...); stream\n -- operations on the archive being built are not performed here,\n -- see Add_Stream for that.\n procedure Add_Catalogue_Entry (Info : in out Zip_Create_Info) is\n begin\n if Info.Last_Entry = 0 then\n Info.Last_Entry := 1;\n Resize (Info.Contains, 32);\n else\n Info.Last_Entry := Info.Last_Entry + 1;\n if Info.Last_Entry > Info.Contains'Last then\n -- Info.Contains is full, time to resize it!\n -- We do nothing less than double the size - better than\n -- whatever offer you'd get in your e-mails.\n Resize (Info.Contains, Info.Contains'Last * 2);\n end if;\n end if;\n declare\n Cfh : Central_File_Header renames Info.Contains (Info.Last_Entry).Head;\n begin\n -- Administration\n Cfh.Made_By_Version := 20; -- Version 2.0\n Cfh.Comment_Length := 0;\n Cfh.Disk_Number_Start := 0;\n Cfh.Internal_Attributes := 0; -- 0: binary; 1: text\n Cfh.External_Attributes := 0;\n Cfh.Short_Info.Needed_Extract_Version := 10; -- Value put by Zip/PKZip\n Cfh.Short_Info.Bit_Flag := 0;" + }, + { + "function_def": "procedure Dispose_Buffer is new Ada.Unchecked_Deallocation (Byte_Buffer, P_Byte_Buffer);", + "function_body": "Inbuf : P_Byte_Buffer; -- I/O buffers\n Outbuf : P_Byte_Buffer;\n\n Inbufidx : Positive; -- Points to next char in buffer to be read\n Outbufidx : Positive := 1; -- Points to next free space in output buffer\n\n Maxinbufidx : Natural; -- Count of valid chars in input buffer\n Inputeof : Boolean; -- End of file indicator\n\n procedure Read_Block is\n begin\n Zip.Blockread (Stream => Input, Buffer => Inbuf.all, Actually_Read => Maxinbufidx);\n Inputeof := Maxinbufidx = 0;\n Inbufidx := 1;\n end Read_Block;\n\n -- Exception for the case where compression works but produces\n -- a bigger file than the file to be compressed (data is too \"random\").\n Compression_Inefficient : exception;\n\n procedure Write_Block is\n Amount : constant Integer := Outbufidx - 1;\n begin\n Output_Size := Output_Size + File_Size_Type (Integer'Max (0, Amount));\n if Output_Size >= Input_Size then\n -- The compression so far is obviously inefficient for that file.\n -- Useless to go further.\n -- Stop immediately before growing the file more than the\n -- uncompressed size.\n raise Compression_Inefficient;\n end if;\n Zip.Blockwrite (Output, Outbuf (1 .. Amount));\n Outbufidx := 1;\n end Write_Block;\n\n procedure Put_Byte (B : Byte) is -- Put a byte, at the byte granularity level\n pragma Inline (Put_Byte);\n begin\n Outbuf (Outbufidx) := B;\n Outbufidx := Outbufidx + 1;\n if Outbufidx > Outbuf'Last then\n Write_Block;\n end if;\n end Put_Byte;\n\n procedure Flush_Byte_Buffer is\n begin\n if Outbufidx > 1 then\n Write_Block;\n end if;\n end Flush_Byte_Buffer;\n\n ------------------------------------------------------\n -- Bit code buffer, for sending data at bit level --\n ------------------------------------------------------\n\n -- Output buffer. Bits are inserted starting at the right (least\n -- significant bits). The width of bit_buffer must be at least 16 bits\n subtype U32 is Unsigned_32;\n Bit_Buffer : U32 := 0;\n -- Number of valid bits in bit_buffer. All bits above the last valid bit are always zero\n Valid_Bits : Integer := 0;\n\n procedure Flush_Bit_Buffer is\n begin\n while Valid_Bits > 0 loop\n Put_Byte (Byte (Bit_Buffer and 16#FF#));\n Bit_Buffer := Shift_Right (Bit_Buffer, 8);\n Valid_Bits := Integer'Max (0, Valid_Bits - 8);\n end loop;\n Bit_Buffer := 0;\n end Flush_Bit_Buffer;\n\n -- Bit codes are at most 15 bits for Huffman codes,\n -- or 13 for explicit codes (distance extra bits).\n subtype Code_Size_Type is Integer range 1 .. 15;\n\n -- Send a value on a given number of bits.\n procedure Put_Code (Code : U32; Code_Size : Code_Size_Type) is\n pragma Inline (Put_Code);\n begin\n -- Put bits from code at the left of existing ones. They might be shifted away\n -- partially on the left side (or even entirely if valid_bits is already = 32).\n Bit_Buffer := Bit_Buffer or Shift_Left (Code, Valid_Bits);\n Valid_Bits := Valid_Bits + Code_Size;\n if Valid_Bits > 32 then\n -- Flush 32 bits to output as 4 bytes\n Put_Byte (Byte (Bit_Buffer and 16#FF#));\n Put_Byte (Byte (Shift_Right (Bit_Buffer, 8) and 16#FF#));\n Put_Byte (Byte (Shift_Right (Bit_Buffer, 16) and 16#FF#));\n Put_Byte (Byte (Shift_Right (Bit_Buffer, 24) and 16#FF#));\n Valid_Bits := Valid_Bits - 32;\n -- Empty buffer and put on it the rest of the code\n Bit_Buffer := Shift_Right (Code, Code_Size - Valid_Bits);\n end if;\n end Put_Code;\n\n ------------------------------------------------------\n -- Deflate, post LZ encoding, with Huffman encoding --\n ------------------------------------------------------\n\n Invalid : constant := -1;\n\n subtype Huffman_Code_Range is Integer range Invalid .. Integer'Last;\n\n type Length_Code_Pair is record\n Bit_Length : Natural; -- Huffman code length, in bits\n Code : Huffman_Code_Range := Invalid; -- The code itself\n end record;\n\n procedure Invert (Lc : in out Length_Code_Pair) is\n pragma Inline (Invert);\n A : Natural := Lc.Code;\n B : Natural := 0;\n begin\n for I in 1 .. Lc.Bit_Length loop\n B := B * 2 + A mod 2;\n A := A / 2;\n end loop;\n Lc.Code := B;\n end Invert;\n\n -- The Huffman code set (and therefore the Huffman tree) is completely determined by\n -- the bit length to be used for reaching leaf nodes, thanks to two special\n -- rules (explanation in RFC 1951, section 3.2.2).\n --\n -- So basically the process is the following:\n --\n -- (A) Gather statistics (just counts) for the alphabet\n -- (B) Turn these counts into code lengths, by calling Length_limited_Huffman_code_lengths\n -- (C) Build Huffman codes (the bits to be sent) with a call to Prepare_Huffman_codes\n --\n -- In short:\n --\n -- data -> (A) -> stats -> (B) -> Huffman codes' bit lengths -> (C) -> Huffman codes\n\n type Huff_Descriptor is array (Natural range <>) of Length_Code_Pair;\n\n type Bit_Length_Array is array (Natural range <>) of Natural;\n subtype Alphabet_Lit_Len is Natural range 0 .. 287;\n subtype Bit_Length_Array_Lit_Len is Bit_Length_Array (Alphabet_Lit_Len);\n subtype Alphabet_Dis is Natural range 0 .. 31;\n subtype Bit_Length_Array_Dis is Bit_Length_Array (Alphabet_Dis);\n\n type Deflate_Huff_Descriptors is record\n -- Tree descriptor for Literal, EOB or Length encoding\n Lit_Len : Huff_Descriptor (0 .. 287);\n -- Tree descriptor for Distance encoding\n Dis : Huff_Descriptor (0 .. 31);\n end record;\n -- NB: Appnote: \"Literal codes 286-287 and distance codes 30-31 are never used\n -- but participate in the Huffman construction.\"\n -- Setting upper bound to 285 for literals leads to invalid codes, sometimes.\n\n -- Copy bit length vectors into Deflate Huffman descriptors\n\n function Build_Descriptors\n (Bl_For_Lit_Len : Bit_Length_Array_Lit_Len;\n Bl_For_Dis : Bit_Length_Array_Dis) return Deflate_Huff_Descriptors\n is\n New_D : Deflate_Huff_Descriptors;\n begin\n for I in New_D.Lit_Len'Range loop\n New_D.Lit_Len (I) := (Bit_Length => Bl_For_Lit_Len (I), Code => Invalid);\n end loop;\n for I in New_D.Dis'Range loop\n New_D.Dis (I) := (Bit_Length => Bl_For_Dis (I), Code => Invalid);\n end loop;\n return New_D;\n end Build_Descriptors;\n\n type Count_Type is range 0 .. File_Size_Type'Last / 2 - 1;\n type Stats_Type is array (Natural range <>) of Count_Type;\n\n -- The following is a translation of Zopfli's OptimizeHuffmanForRle (v. 11-May-2016).\n -- Possible gain: shorten the compression header containing the Huffman trees' bit lengths.\n -- Possible loss: since the stats do not correspond anymore exactly to the data\n -- to be compressed, the Huffman trees might be suboptimal.\n --\n -- Zopfli comment:\n -- Changes the population counts in a way that the consequent Huffman tree\n -- compression, especially its rle-part, will be more likely to compress this data\n -- more efficiently.\n procedure Tweak_For_Better_Rle (Counts : in out Stats_Type) is\n Length : Integer := Counts'Length;\n Stride : Integer;\n Symbol, Sum, Limit, New_Count : Count_Type;\n Good_For_Rle : array (Counts'Range) of Boolean := (others => False);\n begin\n -- 1) We don't want to touch the trailing zeros. We may break the\n -- rules of the format by adding more data in the distance codes.\n loop\n if Length = 0 then\n return;\n end if;\n exit when Counts (Length - 1) /= 0;\n Length := Length - 1;\n end loop;\n -- Now counts(0..length - 1) does not have trailing zeros.\n --\n -- 2) Let's mark all population counts that already can be encoded with an rle code.\n --\n -- Let's not spoil any of the existing good rle codes.\n -- Mark any seq of 0's that is longer than 5 as a good_for_rle.\n -- Mark any seq of non-0's that is longer than 7 as a good_for_rle.\n Symbol := Counts (0);\n Stride := 0;\n for I in 0 .. Length loop\n if I = Length or else Counts (I) /= Symbol then\n if (Symbol = 0 and then Stride >= 5) or else (Symbol /= 0 and then Stride >= 7) then\n for K in 0 .. Stride - 1 loop\n Good_For_Rle (I - K - 1) := True;\n end loop;\n end if;\n Stride := 1;\n if I /= Length then\n Symbol := Counts (I);\n end if;\n else\n Stride := Stride + 1;\n end if;\n end loop;\n -- 3) Let's replace those population counts that lead to more rle codes.\n Stride := 0;\n Limit := Counts (0);\n Sum := 0;\n for I in 0 .. Length loop\n if I = Length\n or else Good_For_Rle (I)\n or else (I > 0 and then Good_For_Rle (I - 1)) -- Added from Brotli, item #1\n -- Heuristic for selecting the stride ranges to collapse.\n or else abs (Counts (I) - Limit) >= 4\n then\n if Stride >= 4 or else (Stride >= 3 and then Sum = 0) then\n -- The stride must end, collapse what we have, if we have enough (4).\n -- New_Count is the average of counts on the stride's interval, upper-rounded\n New_Count :=\n Count_Type'Max (1, (Sum + Count_Type (Stride) / 2) / Count_Type (Stride));\n if Sum = 0 then\n -- Don't make an all zeros stride to be upgraded to ones.\n New_Count := 0;\n end if;\n for K in 0 .. Stride - 1 loop\n -- We don't want to change value at counts(i),\n -- that is already belonging to the next stride. Thus - 1.\n -- Replace histogram value by averaged value\n Counts (I - K - 1) := New_Count;\n end loop;\n end if;\n Stride := 0;\n Sum := 0;\n if I < Length - 3 then\n -- All interesting strides have a count of at least 4, at\n -- least when non-zeros. Limit is the average of next 4\n -- counts, upper-rounded\n Limit := (Counts (I) + Counts (I + 1) + Counts (I + 2) + Counts (I + 3) + 2) / 4;\n elsif I < Length then\n Limit := Counts (I);\n else\n Limit := 0;\n end if;\n end if;\n Stride := Stride + 1;\n if I /= Length then\n Sum := Sum + Counts (I);\n end if;\n end loop;\n end Tweak_For_Better_Rle;\n\n subtype Stats_Lit_Len_Type is Stats_Type (Alphabet_Lit_Len);\n subtype Stats_Dis_Type is Stats_Type (Alphabet_Dis);\n\n -- Phase (B) : we turn statistics into Huffman bit lengths\n function Build_Descriptors\n (Stats_Lit_Len : Stats_Lit_Len_Type;\n Stats_Dis : Stats_Dis_Type) return Deflate_Huff_Descriptors\n is\n Bl_For_Lit_Len : Bit_Length_Array_Lit_Len;\n Bl_For_Dis : Bit_Length_Array_Dis;\n\n procedure Llhcl_Lit_Len is new Length_Limited_Huffman_Code_Lengths\n (Alphabet_Lit_Len,\n Count_Type,\n Stats_Lit_Len_Type,\n Bit_Length_Array_Lit_Len,\n 15);\n\n procedure Llhcl_Dis is new Length_Limited_Huffman_Code_Lengths\n (Alphabet_Dis,\n Count_Type,\n Stats_Dis_Type,\n Bit_Length_Array_Dis,\n 15);\n\n Stats_Dis_Copy : Stats_Dis_Type := Stats_Dis;\n Used : Natural := 0;\n begin\n -- See \"PatchDistanceCodesForBuggyDecoders\" in Zopfli's deflate.c\n -- NB: here, we patch the occurrences and not the bit lengths, to avoid invalid codes.\n -- The decoding bug concerns Zlib v.<= 1.2.1, UnZip v.<= 6.0, WinZip v.10.0.\n for I in Stats_Dis_Copy'Range loop\n if Stats_Dis_Copy (I) /= 0 then\n Used := Used + 1;\n end if;\n end loop;\n if Used < 2 then\n if Used = 0 then -- No distance code used at all (data must be almost random)\n Stats_Dis_Copy (0) := 1;\n Stats_Dis_Copy (1) := 1;\n elsif Stats_Dis_Copy (0) = 0 then\n Stats_Dis_Copy (0) := 1; -- now code 0 and some other code have non-zero counts\n else\n Stats_Dis_Copy (1) := 1; -- now codes 0 and 1 have non-zero counts\n end if;\n end if;\n Llhcl_Lit_Len (Stats_Lit_Len, Bl_For_Lit_Len); -- Call the magic algorithm for setting\n Llhcl_Dis (Stats_Dis_Copy, Bl_For_Dis); -- up Huffman lengths of both trees\n return Build_Descriptors (Bl_For_Lit_Len, Bl_For_Dis);\n end Build_Descriptors;\n\n -- Here is one original part in the Taillaule algorithm: use of basic\n -- topology (L1, L2 distances) to check similarities between Huffman code sets.\n\n -- Bit length vector. Convention: 16 is unused bit length (close to the bit length for the\n -- rarest symbols, 15, and far from the bit length for the most frequent symbols, 1).\n -- Deflate uses 0 for unused.\n subtype Bl_Code is Integer_M32 range 1 .. 16;\n type Bl_Vector is array (1 .. 288 + 32) of Bl_Code;\n\n function Convert (H : Deflate_Huff_Descriptors) return Bl_Vector is\n Bv : Bl_Vector;\n J : Positive := 1;\n begin\n for I in H.Lit_Len'Range loop\n if H.Lit_Len (I).Bit_Length = 0 then\n Bv (J) := 16;\n else\n Bv (J) := Integer_M32 (H.Lit_Len (I).Bit_Length);\n end if;\n J := J + 1;\n end loop;\n for I in H.Dis'Range loop\n if H.Dis (I).Bit_Length = 0 then\n Bv (J) := 16;\n else\n Bv (J) := Integer_M32 (H.Dis (I).Bit_Length);\n end if;\n J := J + 1;\n end loop;\n return Bv;\n end Convert;\n\n -- L1 or Manhattan distance\n function L1_Distance (B1, B2 : Bl_Vector) return Natural_M32 is\n S : Natural_M32 := 0;\n begin\n for I in B1'Range loop\n S := S + abs (B1 (I) - B2 (I));\n end loop;\n return S;\n end L1_Distance;\n\n -- L1, tweaked\n Tweak : constant array (Bl_Code) of Positive_M32 :=\n -- For the origin of the tweak function, see \"za_work.xls\", sheet \"Deflate\".\n -- function f3 = 0.20 f1 [logarithmic] + 0.80 * identity\n -- NB: all values are multiplied by 100 for accuracy.\n (100, 255, 379, 490, 594, 694, 791, 885, 978, 1069, 1159, 1249, 1338, 1426, 1513, 1600);\n -- Neutral is:\n -- (100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600)\n\n function L1_Tweaked (B1, B2 : Bl_Vector) return Natural_M32 is\n S : Natural_M32 := 0;\n begin\n for I in B1'Range loop\n S := S + abs (Tweak (B1 (I)) - Tweak (B2 (I)));\n end loop;\n return S;\n end L1_Tweaked;\n\n -- L2 or Euclidean distance\n function L2_Distance_Square (B1, B2 : Bl_Vector) return Natural_M32 is\n S : Natural_M32 := 0;\n begin\n for I in B1'Range loop\n S := S + (B1 (I) - B2 (I))**2;\n end loop;\n return S;\n end L2_Distance_Square;\n\n -- L2, tweaked\n function L2_Tweaked_Square (B1, B2 : Bl_Vector) return Natural_M32 is\n S : Natural_M32 := 0;\n begin\n for I in B1'Range loop\n S := S + (Tweak (B1 (I)) - Tweak (B2 (I)))**2;\n end loop;\n return S;\n end L2_Tweaked_Square;\n\n type Distance_Type is (L1, L1_Tweaked, L2, L2_Tweaked);\n\n function Similar\n (H1, H2 : Deflate_Huff_Descriptors;\n Dist_Kind : Distance_Type;\n Threshold : Natural) return Boolean\n is\n Dist : Natural_M32;\n Thres : Natural_M32 := Natural_M32 (Threshold);\n begin\n case Dist_Kind is\n when L1 =>\n Dist := L1_Distance (Convert (H1), Convert (H2));\n when L1_Tweaked =>\n Thres := Thres * Tweak (1);\n Dist := L1_Tweaked (Convert (H1), Convert (H2));\n when L2 =>\n Thres := Thres * Thres;\n Dist := L2_Distance_Square (Convert (H1), Convert (H2));\n when L2_Tweaked =>\n Thres := (Thres * Thres) * (Tweak (1) * Tweak (1));\n Dist := L2_Tweaked_Square (Convert (H1), Convert (H2));\n end case;\n return Dist < Thres;\n end Similar;\n\n -- Another original part in the Taillaule algorithm: the possibility of recycling\n -- Huffman codes. It is possible only if previous block was not stored and if\n -- the new block's used alphabets are included in the old block's used alphabets.\n function Recyclable (H_Old, H_New : Deflate_Huff_Descriptors) return Boolean is\n begin\n for I in H_Old.Lit_Len'Range loop\n if H_Old.Lit_Len (I).Bit_Length = 0 and H_New.Lit_Len (I).Bit_Length > 0 then\n return False; -- Code used in new, but not in old\n end if;\n end loop;\n for I in H_Old.Dis'Range loop\n if H_Old.Dis (I).Bit_Length = 0 and H_New.Dis (I).Bit_Length > 0 then\n return False; -- Code used in new, but not in old\n end if;\n end loop;\n return True;\n end Recyclable;\n\n -- Phase (C): the Prepare_Huffman_codes procedure finds the Huffman code for each\n -- value, given the bit length imposed as input.\n procedure Prepare_Huffman_Codes (Hd : in out Huff_Descriptor) is\n Max_Huffman_Bits : constant := 15;\n Bl_Count, Next_Code : array (0 .. Max_Huffman_Bits) of Natural := (others => 0);\n Code : Natural := 0;\n Bl : Natural;\n begin\n -- Algorithm from RFC 1951, section 3.2.2.\n -- Step 1)\n for I in Hd'Range loop\n Bl := Hd (I).Bit_Length;\n Bl_Count (Bl) := Bl_Count (Bl) + 1; -- One more code to be defined with bit length bl\n end loop;\n -- Step 2)\n for Bits in 1 .. Max_Huffman_Bits loop\n Code := (Code + Bl_Count (Bits - 1)) * 2;\n Next_Code (Bits) := Code; -- This will be the first code for bit length \"bits\"\n end loop;\n -- Step 3)\n for N in Hd'Range loop\n Bl := Hd (N).Bit_Length;\n if Bl > 0 then\n Hd (N).Code := Next_Code (Bl);\n Next_Code (Bl) := Next_Code (Bl) + 1;\n else\n Hd (N).Code := 0;\n end if;\n end loop;\n -- Invert bit order for output:\n for I in Hd'Range loop\n Invert (Hd (I));\n end loop;\n end Prepare_Huffman_Codes;\n\n -- This is the phase (C) for the pair of alphabets used in the Deflate format\n function Prepare_Huffman_Codes\n (Dhd : Deflate_Huff_Descriptors) return Deflate_Huff_Descriptors\n is\n Dhd_Var : Deflate_Huff_Descriptors := Dhd;\n begin\n Prepare_Huffman_Codes (Dhd_Var.Lit_Len);\n Prepare_Huffman_Codes (Dhd_Var.Dis);\n return Dhd_Var;\n end Prepare_Huffman_Codes;\n\n -- Emit a variable length Huffman code\n procedure Put_Huffman_Code (Lc : Length_Code_Pair) is\n pragma Inline (Put_Huffman_Code);\n begin\n -- Huffman code of length 0 should never occur: when constructing\n -- the code lengths (LLHCL) any single occurrence in the statistics\n -- will trigger the build of a code length of 1 or more.\n Put_Code\n (Code => U32 (Lc.Code),\n Code_Size => Code_Size_Type (Lc.Bit_Length) -- Range check for length 0 (if enabled).\n );\n end Put_Huffman_Code;\n\n -- This is where the \"dynamic\" Huffman trees are sent before the block's data are sent.\n --\n -- The decoder needs to know in advance the pair of trees (first tree for literals-eob-LZ\n -- lengths, second tree for LZ distances) for decoding the compressed data.\n -- But this information takes some room. Fortunately Deflate allows for compressing it\n -- with a combination of Huffman and Run-Length Encoding (RLE) to make this header smaller.\n -- Concretely, the trees are described by the bit length of each symbol, so the header's\n -- content is a vector of length max 320, whose contents are in the 0 .. 18 range and typically\n -- look like: ... 8, 8, 9, 7, 8, 10, 6, 8, 8, 8, 8, 8, 11, 8, 9, 8, ...\n -- Clearly this vector has redundancies and can be sent in a compressed form. In this example,\n -- the RLE will compress the string of 8's with a single code 8, then a code 17\n -- (repeat x times). Anyway, the very frequent 8's will be encoded with a small number of\n -- bits (less than the 5 plain bits, or maximum 7 Huffman-encoded bits\n -- needed for encoding integers in the 0 .. 18 range).\n procedure Put_Compression_Structure\n (Dhd : Deflate_Huff_Descriptors;\n Cost_Analysis : Boolean; -- If True: just simulate the whole, and count needed bits\n Bits : in out Count_Type) -- This is incremented when cost_analysis = True\n is\n subtype Alphabet is Integer range 0 .. 18;\n type Alpha_Array is new Bit_Length_Array (Alphabet);\n Truc_Freq, Truc_Bl : Alpha_Array;\n Truc : Huff_Descriptor (Alphabet);\n -- Compression structure: cs_bl is the \"big\" array with all bit lengths\n -- for compressing data. cs_bl will be sent compressed, too.\n Cs_Bl : array (1 .. Dhd.Lit_Len'Length + Dhd.Dis'Length) of Natural;\n Last_Cs_Bl : Natural;\n Max_Used_Lln_Code : Alphabet_Lit_Len := 0;\n Max_Used_Dis_Code : Alphabet_Dis := 0;\n\n procedure Concatenate_All_Bit_Lengths is\n Idx : Natural := 0;\n begin\n for A in reverse Alphabet_Lit_Len loop\n if Dhd.Lit_Len (A).Bit_Length > 0 then\n Max_Used_Lln_Code := A;\n exit;\n end if;\n end loop;\n for A in reverse Alphabet_Dis loop\n if Dhd.Dis (A).Bit_Length > 0 then\n Max_Used_Dis_Code := A;\n exit;\n end if;\n end loop;\n -- Copy bit lengths for both trees into one array, cs_bl.\n for A in 0 .. Max_Used_Lln_Code loop\n Idx := Idx + 1;\n Cs_Bl (Idx) := Dhd.Lit_Len (A).Bit_Length;\n end loop;\n for A in 0 .. Max_Used_Dis_Code loop\n Idx := Idx + 1;\n Cs_Bl (Idx) := Dhd.Dis (A).Bit_Length;\n end loop;\n Last_Cs_Bl := Idx;\n end Concatenate_All_Bit_Lengths;\n\n Extra_Bits_Needed : constant array (Alphabet) of Natural :=\n (16 => 2, 17 => 3, 18 => 7, others => 0);\n\n type Emission_Mode is (Simulate, Effective);\n\n procedure Emit_Data_Compression_Structures (Mode : Emission_Mode) is\n procedure Emit_Data_Compression_Atom (X : Alphabet; Extra_Code : U32 := 0) is\n -- x is a bit length (value in 0..15), or a RLE instruction\n begin\n case Mode is\n when Simulate =>\n Truc_Freq (X) := Truc_Freq (X) + 1; -- +1 for x's histogram bar\n when Effective =>\n Put_Huffman_Code (Truc (X));\n declare\n Extra_Bits : constant Natural := Extra_Bits_Needed (X);\n begin\n if Extra_Bits > 0 then\n Put_Code (Extra_Code, Extra_Bits);\n end if;" + }, + { + "function_def": "procedure Llhcl is new Length_Limited_Huffman_Code_Lengths", + "function_body": "(Alphabet,\n Natural,\n Alpha_Array,\n Alpha_Array,\n 7);\n A_Non_Zero : Alphabet;\n begin\n Concatenate_All_Bit_Lengths;\n Truc_Freq := (others => 0);\n Emit_Data_Compression_Structures (Simulate);\n -- We have now statistics of all bit lengths occurrences of both Huffman\n -- trees used for compressing the data.\n -- We turn these counts into bit lengths for the local tree\n -- that helps us to store the compression structure in a more compact form.\n Llhcl (Truc_Freq, Truc_Bl); -- Call the magic algorithm for setting up Huffman lengths\n -- At least lengths for codes 16, 17, 18, 0 will always be sent,\n -- even if all other bit lengths are 0 because codes 1 to 15 are unused.\n A_Non_Zero := 3;\n for A in Alphabet loop\n if A > A_Non_Zero and then Truc_Bl (Alphabet_Permutation (A)) > 0 then\n A_Non_Zero := A;\n end if;\n end loop;\n if Cost_Analysis then\n -- In this mode, no data output: we sum up the exact\n -- number of bits needed by the compression header.\n Bits := Bits + 14 + Count_Type (1 + A_Non_Zero) * 3;\n for A in Alphabet loop\n Bits := Bits + Count_Type (Truc_Freq (A) * (Truc_Bl (A) + Extra_Bits_Needed (A)));\n end loop;\n else\n -- We output the compression header to the output stream.\n for A in Alphabet loop\n Truc (A).Bit_Length := Truc_Bl (A);\n end loop;\n Prepare_Huffman_Codes (Truc);\n -- Output of the compression structure\n Put_Code\n (U32 (Max_Used_Lln_Code - 256),\n 5); -- max_used_lln_code is always >= 256 = EOB code\n Put_Code (U32 (Max_Used_Dis_Code), 5);\n Put_Code (U32 (A_Non_Zero - 3), 4);\n -- Save the local alphabet's Huffman lengths. It's the compression structure\n -- for compressing the data compression structure. Easy, isn't it ?\n for A in 0 .. A_Non_Zero loop\n Put_Code (U32 (Truc (Alphabet_Permutation (A)).Bit_Length), 3);\n end loop;\n -- Emit the Huffman lengths for encoding the data, in the local Huffman-encoded fashion.\n Emit_Data_Compression_Structures (Effective);\n end if;\n end Put_Compression_Structure;\n\n End_Of_Block : constant := 256;\n\n -- Default Huffman trees, for \"fixed\" blocks, as defined in appnote.txt or RFC 1951\n Default_Lit_Len_Bl : constant Bit_Length_Array_Lit_Len :=\n (0 .. 143 => 8, -- For literals (\"plain text\" bytes)\n 144 .. 255 => 9, -- For more literals (\"plain text\" bytes)\n End_Of_Block => 7, -- For EOB (256)\n 257 .. 279 => 7, -- For length codes\n 280 .. 287 => 8); -- For more length codes\n Default_Dis_Bl : constant Bit_Length_Array_Dis := (others => 5);\n\n Deflate_Fixed_Descriptors : constant Deflate_Huff_Descriptors :=\n Prepare_Huffman_Codes (Build_Descriptors (Default_Lit_Len_Bl, Default_Dis_Bl));\n\n -- Current tree descriptors\n Curr_Descr : Deflate_Huff_Descriptors := Deflate_Fixed_Descriptors;\n\n -- Write a normal, \"clear-text\" (post LZ, pre Huffman), 8-bit character (literal)\n procedure Put_Literal_Byte (B : Byte) is\n begin\n Put_Huffman_Code (Curr_Descr.Lit_Len (Integer (B)));\n end Put_Literal_Byte;\n\n -- Possible ranges for distance and length encoding in the Zip-Deflate format:\n subtype Length_Range is Integer range 3 .. 258;\n subtype Distance_Range is Integer range 1 .. 32768;\n\n -- This is where LZ distance-length tokens are written to the output stream.\n -- The Deflate format defines a sort of logarithmic compression, with codes\n -- for various distance and length ranges, plus extra bits for specifying the\n -- exact values. The codes are sent as Huffman codes with variable bit lengths\n -- (nothing to do with the lengths of LZ distance-length tokens).\n\n -- Length Codes\n -- ------------\n -- Extra Extra Extra Extra\n -- Code Bits Length Code Bits Lengths Code Bits Lengths Code Bits Length(s)\n -- ---- ---- ------ ---- ---- ------- ---- ---- ------- ---- ---- ---------\n -- 257 0 3 265 1 11,12 273 3 35-42 281 5 131-162\n -- 258 0 4 266 1 13,14 274 3 43-50 282 5 163-194\n -- 259 0 5 267 1 15,16 275 3 51-58 283 5 195-226\n -- 260 0 6 268 1 17,18 276 3 59-66 284 5 227-257\n -- 261 0 7 269 2 19-22 277 4 67-82 285 0 258\n -- 262 0 8 270 2 23-26 278 4 83-98\n -- 263 0 9 271 2 27-30 279 4 99-114\n -- 264 0 10 272 2 31-34 280 4 115-130\n --\n -- Example: the code # 266 means the LZ length (# of message bytes to be copied)\n -- shall be 13 or 14, depending on the extra bit value.\n\n Deflate_Code_For_Lz_Length : constant array (Length_Range) of Natural :=\n (3 => 257, -- Codes 257..264, with no extra bit\n 4 => 258,\n 5 => 259,\n 6 => 260,\n 7 => 261,\n 8 => 262,\n 9 => 263,\n 10 => 264,\n 11 .. 12 => 265, -- Codes 265..268, with 1 extra bit\n 13 .. 14 => 266,\n 15 .. 16 => 267,\n 17 .. 18 => 268,\n 19 .. 22 => 269, -- Codes 269..272, with 2 extra bits\n 23 .. 26 => 270,\n 27 .. 30 => 271,\n 31 .. 34 => 272,\n 35 .. 42 => 273, -- Codes 273..276, with 3 extra bits\n 43 .. 50 => 274,\n 51 .. 58 => 275,\n 59 .. 66 => 276,\n 67 .. 82 => 277, -- Codes 277..280, with 4 extra bits\n 83 .. 98 => 278,\n 99 .. 114 => 279,\n 115 .. 130 => 280,\n 131 .. 162 => 281, -- Codes 281..284, with 5 extra bits\n 163 .. 194 => 282,\n 195 .. 226 => 283,\n 227 .. 257 => 284,\n 258 => 285); -- Code 285, with no extra bit\n\n Extra_Bits_For_Lz_Length_Offset : constant array (Length_Range) of Integer :=\n (3 .. 10 | 258 => Invalid, -- just placeholder, there is no extra bit there!\n 11 .. 18 => 11,\n 19 .. 34 => 19,\n 35 .. 66 => 35,\n 67 .. 130 => 67,\n 131 .. 257 => 131);\n\n Extra_Bits_For_Lz_Length : constant array (Length_Range) of Natural :=\n (3 .. 10 | 258 => 0,\n 11 .. 18 => 1,\n 19 .. 34 => 2,\n 35 .. 66 => 3,\n 67 .. 130 => 4,\n 131 .. 257 => 5);\n\n procedure Put_Dl_Code (Distance : Distance_Range; Length : Length_Range) is\n Extra_Bits : Natural;\n begin\n Put_Huffman_Code (Curr_Descr.Lit_Len (Deflate_Code_For_Lz_Length (Length)));\n -- Extra bits are needed to differentiate lengths sharing the same code.\n Extra_Bits := Extra_Bits_For_Lz_Length (Length);\n if Extra_Bits > 0 then\n -- We keep only the last extra_bits bits of the length (minus given offset).\n -- Example: if extra_bits = 1, only the parity is sent (0 or 1);\n -- the rest has been already sent with Put_Huffman_code above.\n -- Equivalent: x:= x mod (2 ** extra_bits);\n Put_Code\n (U32 (Length - Extra_Bits_For_Lz_Length_Offset (Length)) and\n (Shift_Left (U32'(1), Extra_Bits) - 1),\n Extra_Bits);\n end if;\n -- Distance Codes\n -- --------------\n -- Extra Extra Extra Extra\n -- Code Bits Dist Code Bits Dist Code Bits Distance Code Bits Distance\n -- ---- ---- ---- ---- ---- ------ ---- ---- -------- ---- ---- --------\n -- 0 0 1 8 3 17-24 16 7 257-384 24 11 4097-6144\n -- 1 0 2 9 3 25-32 17 7 385-512 25 11 6145-8192\n -- 2 0 3 10 4 33-48 18 8 513-768 26 12 8193-12288\n -- 3 0 4 11 4 49-64 19 8 769-1024 27 12 12289-16384\n -- 4 1 5,6 12 5 65-96 20 9 1025-1536 28 13 16385-24576\n -- 5 1 7,8 13 5 97-128 21 9 1537-2048 29 13 24577-32768\n -- 6 2 9-12 14 6 129-192 22 10 2049-3072\n -- 7 2 13-16 15 6 193-256 23 10 3073-4096\n --\n --\n -- Example: the code # 10 means the LZ distance (# positions back in the circular\n -- message buffer for starting the copy) shall be 33, plus the value given\n -- by the 4 extra bits (between 0 and 15).\n case Distance is\n when 1 .. 4 => -- Codes 0..3, with no extra bit\n Put_Huffman_Code (Curr_Descr.Dis (Distance - 1));\n when 5 .. 8 => -- Codes 4..5, with 1 extra bit\n Put_Huffman_Code (Curr_Descr.Dis (4 + (Distance - 5) / 2));\n Put_Code (U32 ((Distance - 5) mod 2), 1);\n when 9 .. 16 => -- Codes 6..7, with 2 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (6 + (Distance - 9) / 4));\n Put_Code (U32 ((Distance - 9) mod 4), 2);\n when 17 .. 32 => -- Codes 8..9, with 3 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (8 + (Distance - 17) / 8));\n Put_Code (U32 ((Distance - 17) mod 8), 3);\n when 33 .. 64 => -- Codes 10..11, with 4 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (10 + (Distance - 33) / 16));\n Put_Code (U32 ((Distance - 33) mod 16), 4);\n when 65 .. 128 => -- Codes 12..13, with 5 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (12 + (Distance - 65) / 32));\n Put_Code (U32 ((Distance - 65) mod 32), 5);\n when 129 .. 256 => -- Codes 14..15, with 6 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (14 + (Distance - 129) / 64));\n Put_Code (U32 ((Distance - 129) mod 64), 6);\n when 257 .. 512 => -- Codes 16..17, with 7 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (16 + (Distance - 257) / 128));\n Put_Code (U32 ((Distance - 257) mod 128), 7);\n when 513 .. 1024 => -- Codes 18..19, with 8 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (18 + (Distance - 513) / 256));\n Put_Code (U32 ((Distance - 513) mod 256), 8);\n when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (20 + (Distance - 1025) / 512));\n Put_Code (U32 ((Distance - 1025) mod 512), 9);\n when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (22 + (Distance - 2049) / 1024));\n Put_Code (U32 ((Distance - 2049) mod 1024), 10);\n when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (24 + (Distance - 4097) / 2048));\n Put_Code (U32 ((Distance - 4097) mod 2048), 11);\n when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (26 + (Distance - 8193) / 4096));\n Put_Code (U32 ((Distance - 8193) mod 4096), 12);\n when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits\n Put_Huffman_Code (Curr_Descr.Dis (28 + (Distance - 16385) / 8192));\n Put_Code (U32 ((Distance - 16385) mod 8192), 13);\n end case;\n end Put_Dl_Code;\n\n function Deflate_Code_For_Lz_Distance (Distance : Distance_Range) return Natural is\n begin\n case Distance is\n when 1 .. 4 => -- Codes 0..3, with no extra bit\n return Distance - 1;\n when 5 .. 8 => -- Codes 4..5, with 1 extra bit\n return 4 + (Distance - 5) / 2;\n when 9 .. 16 => -- Codes 6..7, with 2 extra bits\n return 6 + (Distance - 9) / 4;\n when 17 .. 32 => -- Codes 8..9, with 3 extra bits\n return 8 + (Distance - 17) / 8;\n when 33 .. 64 => -- Codes 10..11, with 4 extra bits\n return 10 + (Distance - 33) / 16;\n when 65 .. 128 => -- Codes 12..13, with 5 extra bits\n return 12 + (Distance - 65) / 32;\n when 129 .. 256 => -- Codes 14..15, with 6 extra bits\n return 14 + (Distance - 129) / 64;\n when 257 .. 512 => -- Codes 16..17, with 7 extra bits\n return 16 + (Distance - 257) / 128;\n when 513 .. 1024 => -- Codes 18..19, with 8 extra bits\n return 18 + (Distance - 513) / 256;\n when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits\n return 20 + (Distance - 1025) / 512;\n when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits\n return 22 + (Distance - 2049) / 1024;\n when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits\n return 24 + (Distance - 4097) / 2048;\n when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits\n return 26 + (Distance - 8193) / 4096;\n when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits\n return 28 + (Distance - 16385) / 8192;\n end case;\n end Deflate_Code_For_Lz_Distance;\n\n -----------------\n -- LZ Buffer --\n -----------------\n\n -- We buffer the LZ codes (plain, or distance/length) in order to\n -- analyse them and try to do smart things.\n\n Max_Expand : constant := 14;\n -- *Tuned* Sometimes it is better to store data and expand short strings\n\n Code_For_Max_Expand : constant := 266;\n subtype Expanded_Data is Byte_Buffer (1 .. Max_Expand);\n\n type Lz_Atom_Kind is (Plain_Byte, Distance_Length);\n type Lz_Atom is record\n Kind : Lz_Atom_Kind;\n Plain : Byte;\n Lz_Distance : Natural;\n Lz_Length : Natural;\n Lz_Expanded : Expanded_Data;\n end record;\n\n -- *Tuned*. Min: 2**14, = 16384 (min half buffer 8192)\n -- Optimal so far: 2**17\n Lz_Buffer_Size : constant := 2**17;\n type Lz_Buffer_Index_Type is mod Lz_Buffer_Size;\n type Lz_Buffer_Type is array (Lz_Buffer_Index_Type range <>) of Lz_Atom;\n\n Empty_Lit_Len_Stat : constant Stats_Lit_Len_Type := (End_Of_Block => 1, others => 0);\n -- End_Of_Block will have to happen once, but never appears in the LZ statistics...\n Empty_Dis_Stat : constant Stats_Dis_Type := (others => 0);\n\n -- Compute statistics for both Literal-length, and Distance alphabets,\n -- from a LZ buffer\n procedure Get_Statistics\n (Lzb : in Lz_Buffer_Type;\n Stats_Lit_Len : out Stats_Lit_Len_Type;\n Stats_Dis : out Stats_Dis_Type)\n is\n Lit_Len : Alphabet_Lit_Len;\n Dis : Alphabet_Dis;\n begin\n Stats_Lit_Len := Empty_Lit_Len_Stat;\n Stats_Dis := Empty_Dis_Stat;\n for I in Lzb'Range loop\n case Lzb (I).Kind is\n when Plain_Byte =>\n Lit_Len := Alphabet_Lit_Len (Lzb (I).Plain);\n Stats_Lit_Len (Lit_Len) :=\n Stats_Lit_Len (Lit_Len) + 1; -- +1 for this literal\n when Distance_Length =>\n Lit_Len := Deflate_Code_For_Lz_Length (Lzb (I).Lz_Length);\n Stats_Lit_Len (Lit_Len) :=\n Stats_Lit_Len (Lit_Len) + 1; -- +1 for this length code\n Dis := Deflate_Code_For_Lz_Distance (Lzb (I).Lz_Distance);\n Stats_Dis (Dis) :=\n Stats_Dis (Dis) + 1; -- +1 for this distance code\n end case;\n end loop;\n end Get_Statistics;\n\n -- Send a LZ buffer using currently defined Huffman codes\n procedure Put_Lz_Buffer (Lzb : Lz_Buffer_Type) is\n begin\n for I in Lzb'Range loop\n case Lzb (I).Kind is\n when Plain_Byte =>\n Put_Literal_Byte (Lzb (I).Plain);\n when Distance_Length =>\n Put_Dl_Code (Lzb (I).Lz_Distance, Lzb (I).Lz_Length);\n end case;\n end loop;\n end Put_Lz_Buffer;\n\n Block_To_Finish : Boolean := False;\n Last_Block_Marked : Boolean := False;\n type Block_Type is (Stored, Fixed, Dynamic, Reserved); -- Appnote, 5.5.2\n -- If last_block_type = dynamic, we may recycle previous block's Huffman codes\n Last_Block_Type : Block_Type := Reserved;\n\n procedure Mark_New_Block (Last_Block_For_Stream : Boolean) is\n begin\n if Block_To_Finish and Last_Block_Type in Fixed .. Dynamic then\n Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); -- Finish previous block\n end if;\n Block_To_Finish := True;\n Put_Code (Code => Boolean'Pos (Last_Block_For_Stream), Code_Size => 1);\n Last_Block_Marked := Last_Block_For_Stream;\n end Mark_New_Block;\n\n -- Send a LZ buffer completely decoded as literals (LZ compression is discarded)\n procedure Expand_Lz_Buffer (Lzb : Lz_Buffer_Type; Last_Block : Boolean) is\n B1, B2 : Byte;\n To_Be_Sent : Natural_M32 := 0;\n -- To_Be_Sent is not always equal to lzb'Length: sometimes you have a DL code\n Mid : Lz_Buffer_Index_Type;\n begin\n for I in Lzb'Range loop\n case Lzb (I).Kind is\n when Plain_Byte =>\n To_Be_Sent := To_Be_Sent + 1;\n when Distance_Length =>\n To_Be_Sent := To_Be_Sent + Natural_M32 (Lzb (I).Lz_Length);\n end case;\n end loop;\n if To_Be_Sent > 16#FFFF# then -- Ow, cannot send all that in one chunk.\n -- Instead of a tedious block splitting, just divide and conquer:\n Mid := Lz_Buffer_Index_Type ((Natural_M32 (Lzb'First) + Natural_M32 (Lzb'Last)) / 2);\n Expand_Lz_Buffer (Lzb (Lzb'First .. Mid), Last_Block => False);\n Expand_Lz_Buffer (Lzb (Mid + 1 .. Lzb'Last), Last_Block => Last_Block);\n return;\n end if;\n B1 := Byte (To_Be_Sent mod 256);\n B2 := Byte (To_Be_Sent / 256);\n Mark_New_Block (Last_Block_For_Stream => Last_Block);\n Last_Block_Type := Stored;\n Put_Code (Code => 0, Code_Size => 2); -- Signals a \"stored\" block\n Flush_Bit_Buffer; -- Go to byte boundary\n Put_Byte (B1);\n Put_Byte (B2);\n Put_Byte (not B1);\n Put_Byte (not B2);\n for I in Lzb'Range loop\n case Lzb (I).Kind is\n when Plain_Byte =>\n Put_Byte (Lzb (I).Plain);\n when Distance_Length =>\n for J in 1 .. Lzb (I).Lz_Length loop\n Put_Byte (Lzb (I).Lz_Expanded (J));\n end loop;\n end case;\n end loop;\n end Expand_Lz_Buffer;\n\n -- Extra bits that need to be sent after various Deflate codes\n\n Extra_Bits_For_Lz_Length_Code : constant array (257 .. 285) of Natural :=\n (257 .. 264 => 0,\n 265 .. 268 => 1,\n 269 .. 272 => 2,\n 273 .. 276 => 3,\n 277 .. 280 => 4,\n 281 .. 284 => 5,\n 285 => 0);\n\n Extra_Bits_For_Lz_Distance_Code : constant array (0 .. 29) of Natural :=\n (0 .. 3 => 0,\n 4 .. 5 => 1,\n 6 .. 7 => 2,\n 8 .. 9 => 3,\n 10 .. 11 => 4,\n 12 .. 13 => 5,\n 14 .. 15 => 6,\n 16 .. 17 => 7,\n 18 .. 19 => 8,\n 20 .. 21 => 9,\n 22 .. 23 => 10,\n 24 .. 25 => 11,\n 26 .. 27 => 12,\n 28 .. 29 => 13);\n\n subtype Long_Length_Codes is\n Alphabet_Lit_Len range Code_For_Max_Expand + 1 .. Alphabet_Lit_Len'Last;\n Zero_Bl_Long_Lengths : constant Stats_Type (Long_Length_Codes) := (others => 0);\n\n -- Send_as_block.\n --\n -- lzb (can be a slice of the principal buffer) will be sent as:\n -- * a new \"dynamic\" block, preceded by a compression structure header\n -- or * the continuation of previous \"dynamic\" block\n -- or * a new \"fixed\" block, if lz data's Huffman descriptor is close enough to \"fixed\"\n -- or * a new \"stored\" block, if lz data are too random\n procedure Send_As_Block (Lzb : Lz_Buffer_Type; Last_Block : Boolean) is\n New_Descr, New_Descr_2 : Deflate_Huff_Descriptors;\n\n procedure Send_Fixed_Block is\n begin\n if Last_Block_Type = Fixed then\n -- Cool, we don't need to mark a block boundary: the Huffman codes are already\n -- the expected ones. We can just continue sending the LZ atoms.\n null;\n else\n Mark_New_Block (Last_Block_For_Stream => Last_Block);\n Curr_Descr := Deflate_Fixed_Descriptors;\n Put_Code (Code => 1, Code_Size => 2); -- Signals a \"fixed\" block\n Last_Block_Type := Fixed;\n end if;\n Put_Lz_Buffer (Lzb);\n end Send_Fixed_Block;\n\n Stats_Lit_Len, Stats_Lit_Len_2 : Stats_Lit_Len_Type;\n Stats_Dis, Stats_Dis_2 : Stats_Dis_Type;\n\n procedure Send_Dynamic_Block (Dyn : Deflate_Huff_Descriptors) is\n Dummy : Count_Type := 0;\n begin\n Mark_New_Block (Last_Block_For_Stream => Last_Block);\n Curr_Descr := Prepare_Huffman_Codes (Dyn);\n Put_Code (Code => 2, Code_Size => 2); -- Signals a \"dynamic\" block\n Put_Compression_Structure (Curr_Descr, Cost_Analysis => False, Bits => Dummy);\n Put_Lz_Buffer (Lzb);\n Last_Block_Type := Dynamic;\n end Send_Dynamic_Block;\n\n -- The following variables will contain the *exact* number of bits taken\n -- by the block to be sent, using different Huffman encodings, or stored.\n Stored_Format_Bits, -- Block is stored (no compression)\n Fixed_Format_Bits, -- Fixed (preset) Huffman codes\n Dynamic_Format_Bits, -- Dynamic Huffman codes using block's statistics\n Dynamic_Format_Bits_2, -- Dynamic Huffman codes after Tweak_for_better_RLE\n Recycled_Format_Bits : Count_Type :=\n 0; -- Continue previous block, use current Huffman codes\n Stored_Format_Possible : Boolean; -- Can we store (needs expansion of DL codes) ?\n Recycling_Possible : Boolean; -- Can we recycle current Huffman codes ?\n\n procedure Compute_Sizes_Of_Variants is\n C : Count_Type;\n Extra : Natural;\n begin\n -- We count bits taken by literals, for each block format variant\n for I in 0 .. 255 loop\n C := Stats_Lit_Len (I); -- This literal appears c times in the LZ buffer\n Stored_Format_Bits := Stored_Format_Bits + 8 * C;\n Fixed_Format_Bits := Fixed_Format_Bits + Count_Type (Default_Lit_Len_Bl (I)) * C;\n Dynamic_Format_Bits :=\n Dynamic_Format_Bits + Count_Type (New_Descr.Lit_Len (I).Bit_Length) * C;\n Dynamic_Format_Bits_2 :=\n Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Lit_Len (I).Bit_Length) * C;\n Recycled_Format_Bits :=\n Recycled_Format_Bits + Count_Type (Curr_Descr.Lit_Len (I).Bit_Length) * C;\n end loop;\n\n -- We count bits taken by DL codes\n if Stored_Format_Possible then\n for I in Lzb'Range loop\n case Lzb (I).Kind is\n when Plain_Byte =>\n null; -- Already counted\n when Distance_Length =>\n -- In the stored format, DL codes are expanded\n Stored_Format_Bits := Stored_Format_Bits + 8 * Count_Type (Lzb (I).Lz_Length);\n end case;\n end loop;\n end if;\n\n -- For compressed formats, count Huffman bits and extra bits\n for I in 257 .. 285 loop\n C := Stats_Lit_Len (I); -- This length code appears c times in the LZ buffer\n Extra := Extra_Bits_For_Lz_Length_Code (I);\n Fixed_Format_Bits :=\n Fixed_Format_Bits + Count_Type (Default_Lit_Len_Bl (I) + Extra) * C;\n Dynamic_Format_Bits :=\n Dynamic_Format_Bits + Count_Type (New_Descr.Lit_Len (I).Bit_Length + Extra) * C;\n Dynamic_Format_Bits_2 :=\n Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Lit_Len (I).Bit_Length + Extra) * C;\n Recycled_Format_Bits :=\n Recycled_Format_Bits + Count_Type (Curr_Descr.Lit_Len (I).Bit_Length + Extra) * C;\n end loop;\n\n for I in 0 .. 29 loop\n C := Stats_Dis (I); -- This distance code appears c times in the LZ buffer\n Extra := Extra_Bits_For_Lz_Distance_Code (I);\n Fixed_Format_Bits := Fixed_Format_Bits + Count_Type (Default_Dis_Bl (I) + Extra) * C;\n Dynamic_Format_Bits :=\n Dynamic_Format_Bits + Count_Type (New_Descr.Dis (I).Bit_Length + Extra) * C;\n Dynamic_Format_Bits_2 :=\n Dynamic_Format_Bits_2 + Count_Type (New_Descr_2.Dis (I).Bit_Length + Extra) * C;\n Recycled_Format_Bits :=\n Recycled_Format_Bits + Count_Type (Curr_Descr.Dis (I).Bit_Length + Extra) * C;\n end loop;\n\n -- Supplemental bits to be counted\n Stored_Format_Bits :=\n Stored_Format_Bits +\n (1 + (Stored_Format_Bits / 8) / 65_535) -- Number of stored blocks needed\n * 5 -- 5 bytes per header\n * 8; -- ... converted into bits\n\n C := 1; -- Is-last-block flag\n if Block_To_Finish and Last_Block_Type in Fixed .. Dynamic then\n C := C + Count_Type (Curr_Descr.Lit_Len (End_Of_Block).Bit_Length);\n end if;\n\n Stored_Format_Bits := Stored_Format_Bits + C;\n Fixed_Format_Bits := Fixed_Format_Bits + C + 2;\n Dynamic_Format_Bits := Dynamic_Format_Bits + C + 2;\n Dynamic_Format_Bits_2 := Dynamic_Format_Bits_2 + C + 2;\n\n -- For both dynamic formats, we also counts the bits taken by\n -- the compression header!\n Put_Compression_Structure (New_Descr, Cost_Analysis => True, Bits => Dynamic_Format_Bits);\n Put_Compression_Structure\n (New_Descr_2,\n Cost_Analysis => True,\n Bits => Dynamic_Format_Bits_2);\n end Compute_Sizes_Of_Variants;\n\n Optimal_Format_Bits : Count_Type;\n begin\n Get_Statistics (Lzb, Stats_Lit_Len, Stats_Dis);\n New_Descr := Build_Descriptors (Stats_Lit_Len, Stats_Dis);\n Stats_Lit_Len_2 := Stats_Lit_Len;\n Stats_Dis_2 := Stats_Dis;\n Tweak_For_Better_Rle (Stats_Lit_Len_2);\n Tweak_For_Better_Rle (Stats_Dis_2);\n New_Descr_2 := Build_Descriptors (Stats_Lit_Len_2, Stats_Dis_2);\n -- For \"stored\" block format, prevent expansion of DL codes with length > max_expand\n -- We check stats are all 0 for long length codes:\n Stored_Format_Possible := Stats_Lit_Len (Long_Length_Codes) = Zero_Bl_Long_Lengths;\n Recycling_Possible :=\n Last_Block_Type = Fixed -- The \"fixed\" alphabets use all symbols, then always recyclable\n or else (Last_Block_Type = Dynamic and then Recyclable (Curr_Descr, New_Descr));\n Compute_Sizes_Of_Variants;\n if not Stored_Format_Possible then\n Stored_Format_Bits := Count_Type'Last;\n end if;\n if not Recycling_Possible then\n Recycled_Format_Bits := Count_Type'Last;\n end if;\n Optimal_Format_Bits :=\n Count_Type'Min\n (Count_Type'Min (Stored_Format_Bits, Fixed_Format_Bits),\n Count_Type'Min\n (Count_Type'Min (Dynamic_Format_Bits, Dynamic_Format_Bits_2),\n Recycled_Format_Bits));\n\n -- Selection of the block format with smallest size\n if Fixed_Format_Bits = Optimal_Format_Bits then\n Send_Fixed_Block;\n elsif Dynamic_Format_Bits = Optimal_Format_Bits then\n Send_Dynamic_Block (New_Descr);\n elsif Dynamic_Format_Bits_2 = Optimal_Format_Bits then\n Send_Dynamic_Block (New_Descr_2);\n elsif Recycled_Format_Bits = Optimal_Format_Bits then\n Put_Lz_Buffer (Lzb);\n else -- We have stored_format_bits = optimal_format_bits\n Expand_Lz_Buffer (Lzb, Last_Block);\n end if;\n end Send_As_Block;\n\n subtype Full_Range_Lz_Buffer_Type is Lz_Buffer_Type (Lz_Buffer_Index_Type);\n type P_Full_Range_Lz_Buffer_Type is access Full_Range_Lz_Buffer_Type;\n procedure Dispose is new Ada.Unchecked_Deallocation\n (Full_Range_Lz_Buffer_Type,\n P_Full_Range_Lz_Buffer_Type);\n\n -- This is the main, big, fat, circular buffer containing LZ codes,\n -- each LZ code being a literal or a DL code.\n -- Heap allocation is needed because default stack is too small on some targets.\n Lz_Buffer : P_Full_Range_Lz_Buffer_Type;\n Lz_Buffer_Index : Lz_Buffer_Index_Type := 0;\n Past_Lz_Data : Boolean := False;\n -- When True: some LZ_buffer_size data before lz_buffer_index (modulo!) are real, past data\n\n ---------------------------------------------------------------------------------\n -- Scanning and sampling: the really sexy part of the Taillaule algorithm... --\n ---------------------------------------------------------------------------------\n\n -- We examine similarities in the LZ data flow at different step sizes.\n -- If the optimal Huffman encoding for this portion is very different, we choose to\n -- cut current block and start a new one. The shorter the step, the higher the threshold\n -- for starting a dynamic block, since the compression header is taking some room each time.\n\n -- *Tuned* (a bit...)\n Min_Step : constant := 750;\n\n type Step_Threshold_Metric is record\n Slider_Step : Lz_Buffer_Index_Type; -- Should be a multiple of Min_Step\n Cutting_Threshold : Positive;\n Metric : Distance_Type;\n end record;\n\n -- *Tuned* thresholds\n -- NB: the enwik8, then silesia, then others tests are tough for lowering any!\n Step_Choice : constant array (Positive range <>) of Step_Threshold_Metric :=\n ((8 * Min_Step, 420, L1_Tweaked), -- Deflate_1, Deflate_2, Deflate_3 (enwik8)\n (4 * Min_Step, 430, L1_Tweaked), -- Deflate_2, Deflate_3 (silesia)\n (Min_Step, 2050, L1_Tweaked)); -- Deflate_3 (DB test)\n\n Max_Choice : constant array (Taillaule_Deflation_Method) of Positive :=\n (Deflate_1 => 1,\n Deflate_2 => 2,\n Deflate_3 => Step_Choice'Last);\n\n Slider_Size : constant := 4096;\n Half_Slider_Size : constant := Slider_Size / 2;\n Slider_Max : constant := Slider_Size - 1;\n\n -- Phases (A) and (B) are done in a single function: we get Huffman\n -- descriptors that should be good for encoding a given sequence of LZ atoms.\n function Build_Descriptors (Lzb : Lz_Buffer_Type) return Deflate_Huff_Descriptors is\n Stats_Lit_Len : Stats_Lit_Len_Type;\n Stats_Dis : Stats_Dis_Type;\n begin\n Get_Statistics (Lzb, Stats_Lit_Len, Stats_Dis);\n return Build_Descriptors (Stats_Lit_Len, Stats_Dis);\n end Build_Descriptors;\n\n procedure Scan_And_Send_From_Main_Buffer\n (From, To : Lz_Buffer_Index_Type;\n Last_Flush : Boolean)\n is\n -- The following descriptors are *not* used for compressing, but for detecting similarities.\n Initial_Hd, Sliding_Hd : Deflate_Huff_Descriptors;\n Start, Slide_Mid, Send_From : Lz_Buffer_Index_Type;\n Sliding_Hd_Computed : Boolean;\n begin\n if To - From < Slider_Max then\n Send_As_Block (Lz_Buffer (From .. To), Last_Flush);\n return;\n end if;\n -- For further comments: n := LZ_buffer_size\n if Past_Lz_Data then -- We have n / 2 previous data before 'from'.\n Start := From - Lz_Buffer_Index_Type (Half_Slider_Size);\n else\n Start := From; -- Cannot have past data\n end if;\n\n -- Looped over, (mod n). Slider data are in two chunks in main buffer\n if Start > From then\n -- put_line(from'img & to'img & start'img);\n declare\n Copy_From : Lz_Buffer_Index_Type := Start;\n Copy : Lz_Buffer_Type (0 .. Slider_Max);\n begin\n for I in Copy'Range loop\n Copy (I) := Lz_Buffer (Copy_From);\n Copy_From := Copy_From + 1; -- Loops over (mod n)\n end loop;\n Initial_Hd := Build_Descriptors (Copy);" + }, + { + "function_def": "procedure Encode is", + "function_body": "X_Percent : Natural;\n Bytes_In : Natural; -- Count of input file bytes processed\n User_Aborting : Boolean;\n Pctdone : Natural;\n\n function Read_Byte return Byte is\n B : Byte;\n begin\n B := Inbuf (Inbufidx);\n Inbufidx := Inbufidx + 1;\n Zip.CRC.Update (CRC, (1 => B));\n Bytes_In := Bytes_In + 1;\n if Feedback /= null then\n if Bytes_In = 1 then\n Feedback (0, User_Aborting);\n end if;\n if X_Percent > 0\n and then ((Bytes_In - 1) mod X_Percent = 0 or Bytes_In = Integer (Input_Size))\n then\n Pctdone := Integer ((100.0 * Float (Bytes_In)) / Float (Input_Size));\n Feedback (Pctdone, User_Aborting);\n if User_Aborting then\n raise User_Abort;\n end if;\n end if;\n end if;\n return B;\n end Read_Byte;\n\n function More_Bytes return Boolean is\n begin\n if Inbufidx > Maxinbufidx then\n Read_Block;\n end if;\n return not Inputeof;\n end More_Bytes;\n\n -- LZ77 parameters\n Look_Ahead : constant Integer := 258;\n String_Buffer_Size : constant := 2**15; -- Required: 2**15 for Deflate, 2**16 for Deflate_e\n type Text_Buffer_Index is mod String_Buffer_Size;\n type Text_Buffer is array (Text_Buffer_Index) of Byte;\n Text_Buf : Text_Buffer;\n R : Text_Buffer_Index;\n\n -- If the DLE coding doesn't fit the format constraints, we need\n -- to decode it as a simple sequence of literals. The buffer used is\n -- called \"Text\" buffer by reference to \"clear-text\", but actually it\n -- is any binary data.\n\n procedure Lz77_Emits_Dl_Code (Distance, Length : Integer) is\n -- NB: no worry, all arithmetics in Text_buffer_index are modulo String_buffer_size\n B : Byte;\n Copy_Start : Text_Buffer_Index;\n Expand : Expanded_Data;\n Ie : Positive := 1;\n begin\n if Distance =\n String_Buffer_Size\n then -- Happens with 7-Zip, cannot happen with Info-Zip\n Copy_Start := R;\n else\n Copy_Start := R - Text_Buffer_Index (Distance);\n end if;\n -- Expand into the circular text buffer to have it up to date\n for K in 0 .. Text_Buffer_Index (Length - 1) loop\n B := Text_Buf (Copy_Start + K);\n Text_Buf (R) := B;\n R := R + 1;\n if Ie <= Max_Expand then -- Also memorize short sequences for LZ buffer\n Expand (Ie) := B; -- for the case a block needs to be stored in clear\n Ie := Ie + 1;\n end if;\n end loop;\n if Distance in Distance_Range and Length in Length_Range then\n Put_Or_Delay_Dl_Code (Distance, Length, Expand);\n else\n for K in 0 .. Text_Buffer_Index (Length - 1) loop\n Put_Or_Delay_Literal_Byte (Text_Buf (Copy_Start + K));\n end loop;\n end if;\n end Lz77_Emits_Dl_Code;\n\n procedure Lz77_Emits_Literal_Byte (B : Byte) is\n begin\n Text_Buf (R) := B;\n R := R + 1;\n Put_Or_Delay_Literal_Byte (B);\n end Lz77_Emits_Literal_Byte;\n\n Lz77_Choice : constant array (Deflation_Method) of Lz77.Method_Type :=\n (Deflate_Fixed => Lz77.Iz_4,\n Deflate_1 => Lz77.Iz_6, -- Level 6 is the default in Info-Zip's zip.exe\n Deflate_2 => Lz77.Iz_8,\n Deflate_3 => Lz77.Iz_10);\n\n procedure My_Lz77 is new Lz77.Encode\n (String_Buffer_Size => String_Buffer_Size,\n Look_Ahead => Look_Ahead,\n Threshold => 2, -- From a string match length > 2, a DL code is sent\n Method => Lz77_Choice (Method),\n Read_Byte => Read_Byte,\n More_Bytes => More_Bytes,\n Write_Literal => Lz77_Emits_Literal_Byte,\n Write_Dl_Code => Lz77_Emits_Dl_Code);\n begin\n Read_Block;\n R := Text_Buffer_Index (String_Buffer_Size - Look_Ahead);\n Bytes_In := 0;\n X_Percent := Integer (Input_Size / 40);\n case Method is\n when Deflate_Fixed => -- \"Fixed\" (predefined) compression structure\n -- We have only one compressed data block, then it is already the last one.\n Put_Code (Code => 1, Code_Size => 1); -- Signals last block\n Put_Code (Code => 1, Code_Size => 2); -- Signals a \"fixed\" block\n when Taillaule_Deflation_Method =>\n null; -- No start data sent, all is delayed\n end case;\n\n -- The whole compression is happening in the following line:\n My_Lz77;\n\n -- Done. Send the code signaling the end of compressed data block:\n case Method is\n when Deflate_Fixed =>\n Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));\n when Taillaule_Deflation_Method =>\n if Lz_Buffer_Index * 2 = 0 then -- Already flushed at latest Push, or empty data\n if Block_To_Finish and then Last_Block_Type in Fixed .. Dynamic then\n Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));\n end if;\n else\n Flush_Half_Buffer (Last_Flush => True);\n if Last_Block_Type in Fixed .. Dynamic then\n Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));\n end if;\n end if;\n if not Last_Block_Marked then\n -- Add a fake fixed block, just to have a final block...\n Put_Code (Code => 1, Code_Size => 1); -- Signals last block\n Put_Code (Code => 1, Code_Size => 2); -- Signals a \"fixed\" block\n Curr_Descr := Deflate_Fixed_Descriptors;\n Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block));\n end if;\n end case;\n end Encode;\n\nbegin\n -- Allocate input and output buffers\n Inbuf := new Byte_Buffer\n (1 .. Integer'Min (Integer'Max (8, Integer (Input_Size)), Default_Buffer_Size));\n Outbuf := new Byte_Buffer (1 .. Default_Buffer_Size);\n Output_Size := 0;\n Lz_Buffer := new Full_Range_Lz_Buffer_Type;\n\n begin\n Encode;\n Compression_Ok := True;\n Flush_Bit_Buffer;\n Flush_Byte_Buffer;\n exception\n when Compression_Inefficient =>\n -- Escaped from Encode\n Compression_Ok := False;" + }, + { + "function_def": "function Intel_Nb is new Intel_X86_Number (Unsigned_16);", + "function_body": "function Intel_Nb is new Intel_X86_Number (Unsigned_32);\n\n -- Put numbers with correct endianess as bytes\n\n generic\n type Number is mod <>; -- range <> in Ada83 version (fake Interfaces)\n Size : Stream_Element_Count;\n function Intel_X86_Buffer (N : Number) return Stream_Element_Array;\n\n function Intel_X86_Buffer (N : Number) return Stream_Element_Array is\n B : Stream_Element_Array (1 .. Size);\n M : Number := N;\n begin\n for I in B'Range loop\n B (I) := Stream_Element (M and 255);\n M := M / 256;\n end loop;\n return B;\n end Intel_X86_Buffer;\n\n function Intel_Bf is new Intel_X86_Buffer (Unsigned_16, 2);\n function Intel_Bf is new Intel_X86_Buffer (Unsigned_32, 4);\n\n ---------------------\n -- PK signatures --\n ---------------------\n\n function Pk_Signature (Buf : Stream_Element_Array; Code : Stream_Element) return Boolean is\n begin\n return Buf (Buf'First .. Buf'First + 3) = (16#50#, 16#4B#, Code, Code + 1);\n -- PK12, PK34, ...\n end Pk_Signature;\n\n procedure Pk_Signature (Buf : in out Stream_Element_Array; Code : Stream_Element) is\n begin\n Buf (1 .. 4) := (16#50#, 16#4B#, Code, Code + 1); -- PK12, PK34, ...\n end Pk_Signature;\n\n ---------------------------------------------------------\n -- PKZIP file header, as in central directory - PK12 --\n ---------------------------------------------------------\n procedure Read_And_Check\n (Stream : in out Root_Zipstream_Type'Class;\n Header : out Central_File_Header)\n is\n Chb : Stream_Element_Array (1 .. 46);\n begin\n Blockread (Stream, Chb);\n\n if not Pk_Signature (Chb, 1) then\n raise Bad_Central_Header;\n end if;\n\n Header.Made_By_Version := Intel_Nb (Chb (5 .. 6));\n Header.Short_Info.Needed_Extract_Version := Intel_Nb (Chb (7 .. 8));\n Header.Short_Info.Bit_Flag := Intel_Nb (Chb (9 .. 10));\n Header.Short_Info.Zip_Type := Intel_Nb (Chb (11 .. 12));\n Header.Short_Info.File_Timedate :=\n DCF.Streams.Convert (Unsigned_32'(Intel_Nb (Chb (13 .. 16))));\n Header.Short_Info.Dd.Crc_32 := Intel_Nb (Chb (17 .. 20));\n Header.Short_Info.Dd.Compressed_Size := Intel_Nb (Chb (21 .. 24));\n Header.Short_Info.Dd.Uncompressed_Size := Intel_Nb (Chb (25 .. 28));\n Header.Short_Info.Filename_Length := Intel_Nb (Chb (29 .. 30));\n Header.Short_Info.Extra_Field_Length := Intel_Nb (Chb (31 .. 32));\n Header.Comment_Length := Intel_Nb (Chb (33 .. 34));\n Header.Disk_Number_Start := Intel_Nb (Chb (35 .. 36));\n Header.Internal_Attributes := Intel_Nb (Chb (37 .. 38));\n Header.External_Attributes := Intel_Nb (Chb (39 .. 42));\n Header.Local_Header_Offset := Intel_Nb (Chb (43 .. 46));\n\n if not Valid_Version (Header.Short_Info) then\n raise Bad_Central_Header with \"Archive needs invalid version to extract\";\n end if;\n\n if Header.Disk_Number_Start /= 0 then\n raise Bad_Central_Header with \"Archive may not span multiple volumes\";\n end if;\n\n if not Valid_Bitflag (Header.Short_Info) then\n raise Bad_Central_Header with \"Archive uses prohibited features\";\n end if;\n end Read_And_Check;\n\n procedure Write (Stream : in out Root_Zipstream_Type'Class; Header : in Central_File_Header) is\n Chb : Stream_Element_Array (1 .. 46);\n begin\n Pk_Signature (Chb, 1);\n\n Chb (5 .. 6) := Intel_Bf (Header.Made_By_Version);\n Chb (7 .. 8) := Intel_Bf (Header.Short_Info.Needed_Extract_Version);\n Chb (9 .. 10) := Intel_Bf (Header.Short_Info.Bit_Flag);\n Chb (11 .. 12) := Intel_Bf (Header.Short_Info.Zip_Type);\n Chb (13 .. 16) := Intel_Bf (DCF.Streams.Convert (Header.Short_Info.File_Timedate));\n Chb (17 .. 20) := Intel_Bf (Header.Short_Info.Dd.Crc_32);\n Chb (21 .. 24) := Intel_Bf (Header.Short_Info.Dd.Compressed_Size);\n Chb (25 .. 28) := Intel_Bf (Header.Short_Info.Dd.Uncompressed_Size);\n Chb (29 .. 30) := Intel_Bf (Header.Short_Info.Filename_Length);\n Chb (31 .. 32) := Intel_Bf (Header.Short_Info.Extra_Field_Length);\n Chb (33 .. 34) := Intel_Bf (Header.Comment_Length);\n Chb (35 .. 36) := Intel_Bf (Header.Disk_Number_Start);\n Chb (37 .. 38) := Intel_Bf (Header.Internal_Attributes);\n Chb (39 .. 42) := Intel_Bf (Header.External_Attributes);\n Chb (43 .. 46) := Intel_Bf (Header.Local_Header_Offset);\n\n Stream.Write (Chb);\n end Write;\n\n -------------------------------------------------------------------------\n -- PKZIP local file header, in front of every file in archive - PK34 --\n -------------------------------------------------------------------------\n procedure Read_And_Check\n (Stream : in out Root_Zipstream_Type'Class;\n Header : out Local_File_Header)\n is\n Lhb : Stream_Element_Array (1 .. 30);\n begin\n Blockread (Stream, Lhb);\n\n if not Pk_Signature (Lhb, 3) then\n raise Bad_Local_Header;\n end if;\n\n Header.Needed_Extract_Version := Intel_Nb (Lhb (5 .. 6));\n Header.Bit_Flag := Intel_Nb (Lhb (7 .. 8));\n Header.Zip_Type := Intel_Nb (Lhb (9 .. 10));\n Header.File_Timedate :=\n DCF.Streams.Convert (Unsigned_32'(Intel_Nb (Lhb (11 .. 14))));\n Header.Dd.Crc_32 := Intel_Nb (Lhb (15 .. 18));\n Header.Dd.Compressed_Size := Intel_Nb (Lhb (19 .. 22));\n Header.Dd.Uncompressed_Size := Intel_Nb (Lhb (23 .. 26));\n Header.Filename_Length := Intel_Nb (Lhb (27 .. 28));\n Header.Extra_Field_Length := Intel_Nb (Lhb (29 .. 30));\n\n if not Valid_Version (Header) then\n raise Bad_Local_Header with \"Archived file needs invalid version to extract\";\n end if;\n\n if not Valid_Bitflag (Header) then\n raise Bad_Local_Header with \"Archived file uses prohibited features\";\n end if;\n end Read_And_Check;\n\n procedure Write (Stream : in out Root_Zipstream_Type'Class; Header : in Local_File_Header) is\n Lhb : Stream_Element_Array (1 .. 30);\n begin\n Pk_Signature (Lhb, 3);\n\n Lhb (5 .. 6) := Intel_Bf (Header.Needed_Extract_Version);\n Lhb (7 .. 8) := Intel_Bf (Header.Bit_Flag);\n Lhb (9 .. 10) := Intel_Bf (Header.Zip_Type);\n Lhb (11 .. 14) := Intel_Bf (DCF.Streams.Convert (Header.File_Timedate));\n Lhb (15 .. 18) := Intel_Bf (Header.Dd.Crc_32);\n Lhb (19 .. 22) := Intel_Bf (Header.Dd.Compressed_Size);\n Lhb (23 .. 26) := Intel_Bf (Header.Dd.Uncompressed_Size);\n Lhb (27 .. 28) := Intel_Bf (Header.Filename_Length);\n Lhb (29 .. 30) := Intel_Bf (Header.Extra_Field_Length);\n\n Stream.Write (Lhb);\n end Write;\n\n ---------------------------------------------\n -- PKZIP end-of-central-directory - PK56 --\n ---------------------------------------------\n procedure Copy_And_Check (Buffer : in Stream_Element_Array; The_End : out End_Of_Central_Dir) is\n O : constant Stream_Element_Offset := Buffer'First - 1;\n begin\n if not Pk_Signature (Buffer, 5) then\n raise Bad_End;\n end if;\n\n The_End.Disknum := Intel_Nb (Buffer (O + 5 .. O + 6));\n The_End.Disknum_With_Start := Intel_Nb (Buffer (O + 7 .. O + 8));\n The_End.Disk_Total_Entries := Intel_Nb (Buffer (O + 9 .. O + 10));\n The_End.Total_Entries := Intel_Nb (Buffer (O + 11 .. O + 12));\n The_End.Central_Dir_Size := Intel_Nb (Buffer (O + 13 .. O + 16));\n The_End.Central_Dir_Offset := Intel_Nb (Buffer (O + 17 .. O + 20));\n The_End.Main_Comment_Length := Intel_Nb (Buffer (O + 21 .. O + 22));\n end Copy_And_Check;\n\n procedure Read_And_Check\n (Stream : in out Root_Zipstream_Type'Class;\n The_End : out End_Of_Central_Dir)\n is\n Buffer : Stream_Element_Array (1 .. 22);\n begin\n Blockread (Stream, Buffer);\n Copy_And_Check (Buffer, The_End);\n end Read_And_Check;\n\n procedure Load (Stream : in out Root_Zipstream_Type'Class; The_End : out End_Of_Central_Dir) is\n Min_End_Start : Zs_Index_Type; -- min_end_start >= 1\n Max_Comment : constant := 65_535;\n -- In appnote.txt :\n -- .ZIP file comment length 2 bytes\n begin\n if Size (Stream) < 22 then\n raise Bad_End;\n end if;\n -- 20-Jun-2001: abandon search below min_end_start.\n if Size (Stream) <= Max_Comment then\n Min_End_Start := 1;\n else\n Min_End_Start := Size (Stream) - Max_Comment;\n end if;\n Set_Index (Stream, Min_End_Start);\n declare\n -- We copy a large chunk of the zip stream's tail into a buffer.\n Large_Buffer : Stream_Element_Array\n (0 .. Stream_Element_Count (Size (Stream) - Min_End_Start));\n Ilb : Stream_Element_Offset;\n X : Zs_Size_Type;\n begin\n Blockread (Stream, Large_Buffer);\n for I in reverse Min_End_Start .. Size (Stream) - 21 loop\n -- Yes, we must _search_ for the header...\n -- because PKWARE put a variable-size comment _after_ it 8-(\n Ilb := Stream_Element_Offset (I - Min_End_Start);\n if Pk_Signature (Large_Buffer (Ilb .. Ilb + 3), 5) then\n Copy_And_Check (Large_Buffer (Ilb .. Ilb + 21), The_End);\n -- At this point, the buffer was successfully read, the_end is\n -- is set with its standard contents.\n --\n -- This is the *real* position of the end-of-central-directory block to begin with:\n X := I;\n -- We subtract the *theoretical* (stored) position of the end-of-central-directory.\n -- The theoretical position is equal to central_dir_offset + central_dir_size.\n -- The theoretical position should be smaller or equal than the real position -\n -- unless the archive is corrupted.\n -- We do it step by step, because ZS_Size_Type was modular until rev. 644.\n -- Now it's a signed 64 bits, but we don't want to change anything again...\n X := X - 1;\n -- i >= 1, so no dragons here. The \"- 1\" is for adapting\n -- from the 1-based Ada index.\n\n -- Fuzzy value, will trigger bad_end\n exit when Zs_Size_Type (The_End.Central_Dir_Offset) > X;\n\n -- Fuzzy value, will trigger bad_end\n X := X - Zs_Size_Type (The_End.Central_Dir_Offset);\n exit when Zs_Size_Type (The_End.Central_Dir_Size) > X;\n\n X := X - Zs_Size_Type (The_End.Central_Dir_Size);\n -- Now, x is the difference : real - theoretical.\n -- x > 0 if the archive was appended to another file (typically an executable\n -- for self-extraction purposes).\n -- x = 0 if this is a \"pure\" Zip archive.\n The_End.Offset_Shifting := X;\n Set_Index (Stream, I + 22);\n return; -- The_End found and filled -> exit\n end if;\n end loop;\n raise Bad_End; -- Definitely no \"end-of-central-directory\" in this stream" + }, + { + "function_def": "procedure Dispose is new Ada.Unchecked_Deallocation (Huft_Table, P_Huft_Table);", + "function_body": "procedure Dispose is new Ada.Unchecked_Deallocation (Table_List, P_Table_List);\n\n Current : P_Table_List;\n begin\n while Tl /= null loop\n Dispose (Tl.Table); -- Destroy the Huffman table\n Current := Tl;\n Tl := Tl.Next;\n Dispose (Current); -- Destroy the current node\n end loop;\n end Huft_Free;\n\n -- Build huffman table from code lengths given by array b\n\n procedure Huft_Build\n (B : Length_Array;\n S : Integer;\n D, E : Length_Array;\n Tl : out P_Table_List;\n M : in out Integer;\n Huft_Incomplete : out Boolean)\n is\n B_Max : constant := 16;\n B_Maxp1 : constant := B_Max + 1;\n\n -- Bit length count table\n Count : array (0 .. B_Maxp1) of Integer := (others => 0);\n\n F : Integer; -- I repeats in table every f entries\n G : Integer; -- Maximum code length\n I : Integer; -- Counter, current code\n J : Integer; -- Counter\n Kcc : Integer; -- Number of bits in current code\n\n C_Idx, V_Idx : Natural; -- Array indices\n\n Current_Table_Ptr : P_Huft_Table := null;\n Current_Node_Ptr : P_Table_List := null; -- Current node for the current table\n New_Node_Ptr : P_Table_List; -- New node for the new table\n\n New_Entry : Huft; -- Table entry for structure assignment\n\n U : array (0 .. B_Max) of P_Huft_Table; -- Table stack\n\n N_Max : constant := 288;\n -- Values in order of bit length\n V : array (0 .. N_Max) of Integer := (others => 0);\n El_V, El_V_M_S : Integer;\n\n W : Natural := 0; -- Bits before this table\n\n Offset, Code_Stack : array (0 .. B_Maxp1) of Integer;\n\n Table_Level : Integer := -1;\n Bits : array (Integer'(-1) .. B_Maxp1) of Integer;\n -- ^ bits(table_level) = # bits in table of level table_level\n\n Y : Integer; -- Number of dummy codes added\n Z : Natural := 0; -- Number of entries in current table\n El : Integer; -- Length of eob code=code 256\n\n No_Copy_Length_Array : constant Boolean := D'Length = 0 or E'Length = 0;\n\n begin\n Tl := null;\n\n if B'Length > 256 then -- Set length of EOB code, if any\n El := B (256);\n else\n El := B_Max;\n end if;\n\n -- Generate counts for each bit length\n\n for K in B'Range loop\n if B (K) > B_Max then\n -- m := 0; -- GNAT 2005 doesn't like it (warning).\n raise Huft_Error;\n end if;\n Count (B (K)) := Count (B (K)) + 1;\n end loop;\n\n if Count (0) = B'Length then\n M := 0;\n Huft_Incomplete := False; -- Spotted by Tucker Taft, 19-Aug-2004\n return; -- Complete\n end if;\n\n -- Find minimum and maximum length, bound m by those\n\n J := 1;\n while J <= B_Max and then Count (J) = 0 loop\n J := J + 1;\n end loop;\n Kcc := J;\n if M < J then\n M := J;\n end if;\n I := B_Max;\n while I > 0 and then Count (I) = 0 loop\n I := I - 1;\n end loop;\n G := I;\n if M > I then\n M := I;\n end if;\n\n -- Adjust last length count to fill out codes, if needed\n\n Y := Integer (Shift_Left (Unsigned_32'(1), J)); -- y:= 2 ** j;\n while J < I loop\n Y := Y - Count (J);\n if Y < 0 then\n raise Huft_Error;\n end if;\n Y := Y * 2;\n J := J + 1;\n end loop;\n\n Y := Y - Count (I);\n if Y < 0 then\n raise Huft_Error;\n end if;\n Count (I) := Count (I) + Y;\n\n -- Generate starting offsets into the value table for each length\n\n Offset (1) := 0;\n J := 0;\n for Idx in 2 .. I loop\n J := J + Count (Idx - 1);\n Offset (Idx) := J;\n end loop;\n\n -- Make table of values in order of bit length\n\n for Idx in B'Range loop\n J := B (Idx);\n if J /= 0 then\n V (Offset (J)) := Idx - B'First;\n Offset (J) := Offset (J) + 1;\n end if;\n end loop;\n\n -- Generate huffman codes and for each, make the table entries\n\n Code_Stack (0) := 0;\n I := 0;\n V_Idx := V'First;\n Bits (-1) := 0;\n\n -- Go through the bit lengths (kcc already is bits in shortest code)\n for K in Kcc .. G loop\n for Am1 in reverse 0 .. Count (K) - 1 loop -- A counts codes of length k\n -- Here i is the huffman code of length k bits for value v(v_idx)\n while K > W + Bits (Table_Level) loop\n W := W + Bits (Table_Level); -- Length of tables to this position\n Table_Level := Table_Level + 1;\n Z := G - W; -- Compute min size table <= m bits\n if Z > M then\n Z := M;\n end if;\n J := K - W;\n F := Integer (Shift_Left (Unsigned_32'(1), J)); -- f:= 2 ** j;\n if F > Am1 + 2 then\n -- Try a k-w bit table\n F := F - (Am1 + 2);\n C_Idx := K;\n\n -- Try smaller tables up to z bits\n loop\n J := J + 1;\n exit when J >= Z;\n F := F * 2;\n C_Idx := C_Idx + 1;\n exit when F - Count (C_Idx) <= 0;\n F := F - Count (C_Idx);\n end loop;\n end if;\n\n if W + J > El and then W < El then\n J := El - W; -- Make EOB code end at table\n end if;\n if W = 0 then\n J := M; -- Fix: main table always m bits!\n end if;\n Z := Integer (Shift_Left (Unsigned_32'(1), J)); -- z:= 2 ** j;\n Bits (Table_Level) := J;\n\n -- Allocate and link new table\n\n begin\n Current_Table_Ptr := new Huft_Table (0 .. Z);\n New_Node_Ptr := new Table_List'(Current_Table_Ptr, null);\n exception\n when Storage_Error =>\n raise Huft_Out_Of_Memory;" + }, + { + "function_def": "procedure Dispose is new Ada.Unchecked_Deallocation (Dir_Node, P_Dir_Node);", + "function_body": "procedure Dispose is new Ada.Unchecked_Deallocation (String, P_String);\n\n package Binary_Tree_Rebalancing is\n procedure Rebalance (Root : in out P_Dir_Node);\n end Binary_Tree_Rebalancing;\n\n package body Binary_Tree_Rebalancing is\n\n -------------------------------------------------------------------\n -- Tree Rebalancing in Optimal Time and Space --\n -- QUENTIN F. STOUT and BETTE L. WARREN --\n -- Communications of the ACM September 1986 Volume 29 Number 9 --\n -------------------------------------------------------------------\n -- http://www.eecs.umich.edu/~qstout/pap/CACM86.pdf\n --\n -- Translated by (New) P2Ada v. 15-Nov-2006\n\n procedure Tree_To_Vine (Root : P_Dir_Node; Size : out Integer) is\n -- Transform the tree with pseudo-root \"root^\" into a vine with\n -- pseudo-root node \"root^\", and store the number of nodes in \"size\"\n Vine_Tail, Remainder, Temp : P_Dir_Node;\n begin\n Vine_Tail := Root;\n Remainder := Vine_Tail.Right;\n Size := 0;\n while Remainder /= null loop\n if Remainder.Left = null then\n -- Move vine-tail down one:\n Vine_Tail := Remainder;\n Remainder := Remainder.Right;\n Size := Size + 1;\n else\n -- Rotate:\n Temp := Remainder.Left;\n Remainder.Left := Temp.Right;\n Temp.Right := Remainder;\n Remainder := Temp;\n Vine_Tail.Right := Temp;\n end if;\n end loop;\n end Tree_To_Vine;\n\n procedure Vine_To_Tree (Root : P_Dir_Node; Size_Given : Integer) is\n -- Convert the vine with \"size\" nodes and pseudo-root\n -- node \"root^\" into a balanced tree\n Leaf_Count : Integer;\n Size : Integer := Size_Given;\n\n procedure Compression (Root_Compress : P_Dir_Node; Count : Integer) is\n -- Compress \"count\" spine nodes in the tree with pseudo-root \"root_compress^\"\n Scanner, Child : P_Dir_Node;\n begin\n Scanner := Root_Compress;\n for Counter in reverse 1 .. Count loop\n Child := Scanner.Right;\n Scanner.Right := Child.Right;\n Scanner := Scanner.Right;\n Child.Right := Scanner.Left;\n Scanner.Left := Child;\n end loop;\n end Compression;\n\n -- Returns n - 2 ** Integer( Float'Floor( log( Float(n) ) / log(2.0) ) )\n -- without Float-Point calculation and rounding errors with too short floats\n function Remove_Leading_Binary_1 (N : Integer) return Integer is\n X : Integer := 2**16; -- supposed maximum\n begin\n if N < 1 then\n return N;\n end if;\n while N mod X = N loop\n X := X / 2;\n end loop;\n return N mod X;\n end Remove_Leading_Binary_1;\n\n begin -- Vine_to_tree\n Leaf_Count := Remove_Leading_Binary_1 (Size + 1);\n Compression (Root, Leaf_Count); -- create deepest leaves\n -- Use Perfect_leaves instead for a perfectly balanced tree\n Size := Size - Leaf_Count;\n while Size > 1 loop\n Compression (Root, Size / 2);\n Size := Size / 2;\n end loop;\n end Vine_To_Tree;\n\n procedure Rebalance (Root : in out P_Dir_Node) is\n -- Rebalance the binary search tree with root \"root.all\",\n -- with the result also rooted at \"root.all\".\n -- Uses the Tree_to_vine and Vine_to_tree procedures\n Pseudo_Root : P_Dir_Node;\n Size : Integer;\n begin\n Pseudo_Root := new Dir_Node (Name_Len => 0);\n Pseudo_Root.Right := Root;\n Tree_To_Vine (Pseudo_Root, Size);\n Vine_To_Tree (Pseudo_Root, Size);\n Root := Pseudo_Root.Right;\n Dispose (Pseudo_Root);\n end Rebalance;\n\n end Binary_Tree_Rebalancing;\n\n -- 19-Jun-2001: Enhanced file name identification\n -- a) when case insensitive -> all UPPER (current)\n -- b) '\\' and '/' identified -> all '/' (new)\n\n function Normalize (S : String; Case_Sensitive : Boolean) return String is\n Sn : String := (if Case_Sensitive then S else Ada.Characters.Handling.To_Upper (S));\n begin\n for I in Sn'Range loop\n if Sn (I) = '\\' then\n Sn (I) := '/';\n end if;\n end loop;\n return Sn;\n end Normalize;\n\n function Get_Node (Info : in Zip_Info; Name : in String) return P_Dir_Node is\n Aux : P_Dir_Node := Info.Dir_Binary_Tree;\n Up_Name : constant String := Normalize (Name, Info.Case_Sensitive);\n begin\n while Aux /= null loop\n if Up_Name > Aux.Dico_Name then\n Aux := Aux.Right;\n elsif Up_Name < Aux.Dico_Name then\n Aux := Aux.Left;\n else -- entry found !\n return Aux;\n end if;\n end loop;\n return null;\n end Get_Node;\n\n Boolean_To_Encoding : constant array (Boolean) of Zip_Name_Encoding :=\n (False => IBM_437, True => UTF_8);\n\n -------------------------------------------------------------\n -- Load Zip_info from a stream containing the .zip archive --\n -------------------------------------------------------------\n\n procedure Load\n (Info : out Zip_Info;\n From : in out DCF.Streams.Root_Zipstream_Type'Class;\n Case_Sensitive : in Boolean := False)\n is\n procedure Insert\n (Dico_Name : String; -- UPPER if case-insensitive search\n File_Name : String;\n File_Index : DCF.Streams.Zs_Index_Type;\n Comp_Size, Uncomp_Size : File_Size_Type;\n Crc_32 : Unsigned_32;\n Date_Time : Time;\n Method : Pkzip_Method;\n Name_Encoding : Zip_Name_Encoding;\n Read_Only : Boolean;\n Encrypted_2_X : Boolean;\n Root_Node : in out P_Dir_Node)\n is\n procedure Insert_Into_Tree (Node : in out P_Dir_Node) is\n begin\n if Node = null then\n Node :=\n new Dir_Node'\n ((Name_Len => File_Name'Length,\n Left => null,\n Right => null,\n Dico_Name => Dico_Name,\n File_Name => File_Name,\n File_Index => File_Index,\n Comp_Size => Comp_Size,\n Uncomp_Size => Uncomp_Size,\n Crc_32 => Crc_32,\n Date_Time => Date_Time,\n Method => Method,\n Name_Encoding => Name_Encoding,\n Read_Only => Read_Only,\n Encrypted_2_X => Encrypted_2_X));\n elsif Dico_Name > Node.Dico_Name then\n Insert_Into_Tree (Node.Right);\n elsif Dico_Name < Node.Dico_Name then\n Insert_Into_Tree (Node.Left);\n else\n -- Here we have a case where the entry name already exists\n -- in the dictionary\n raise Duplicate_Name with\n \"Entry name '\" & Dico_Name & \"' appears twice in archive\";\n end if;\n end Insert_Into_Tree;\n begin\n Insert_Into_Tree (Root_Node);\n end Insert;\n\n The_End : Zip.Headers.End_Of_Central_Dir;\n Header : Zip.Headers.Central_File_Header;\n P : P_Dir_Node := null;\n Main_Comment : P_String;\n begin\n if Info.Loaded then\n raise Program_Error;\n end if;\n\n Zip.Headers.Load (From, The_End);\n\n -- We take the opportunity to read the main comment, which is right\n -- after the end-of-central-directory block\n Main_Comment := new String (1 .. Integer (The_End.Main_Comment_Length));\n String'Read (From'Access, Main_Comment.all);\n\n -- Process central directory\n From.Set_Index\n (DCF.Streams.Zs_Index_Type (1 + The_End.Central_Dir_Offset) + The_End.Offset_Shifting);\n\n for I in 1 .. The_End.Total_Entries loop\n Zip.Headers.Read_And_Check (From, Header);\n declare\n This_Name : String (1 .. Natural (Header.Short_Info.Filename_Length));\n begin\n String'Read (From'Access, This_Name);\n -- Skip extra field and entry comment\n From.Set_Index\n (From.Index +\n DCF.Streams.Zs_Size_Type\n (Header.Short_Info.Extra_Field_Length + Header.Comment_Length));\n -- Now the whole i_th central directory entry is behind\n Insert\n (Dico_Name => Normalize (This_Name, Case_Sensitive),\n File_Name => Normalize (This_Name, True),\n File_Index =>\n DCF.Streams.Zs_Index_Type (1 + Header.Local_Header_Offset) +\n The_End.Offset_Shifting,\n Comp_Size => Header.Short_Info.Dd.Compressed_Size,\n Uncomp_Size => Header.Short_Info.Dd.Uncompressed_Size,\n Crc_32 => Header.Short_Info.Dd.Crc_32,\n Date_Time => Header.Short_Info.File_Timedate,\n Method => Method_From_Code (Header.Short_Info.Zip_Type),\n Name_Encoding =>\n Boolean_To_Encoding\n ((Header.Short_Info.Bit_Flag and Zip.Headers.Language_Encoding_Flag_Bit) /= 0),\n Read_Only =>\n Header.Made_By_Version / 256 = 0 and -- DOS-like\n (Header.External_Attributes and 1) = 1,\n Encrypted_2_X =>\n (Header.Short_Info.Bit_Flag and Zip.Headers.Encryption_Flag_Bit) /= 0,\n Root_Node => P);\n -- Since the files are usually well ordered, the tree as inserted\n -- is very unbalanced; we need to rebalance it from time to time\n -- during loading, otherwise the insertion slows down dramatically\n -- for zip files with plenty of files - converges to\n -- O(total_entries ** 2)...\n if I mod 256 = 0 then\n Binary_Tree_Rebalancing.Rebalance (P);\n end if;" + }, + { + "function_def": "procedure Init_Buffers;", + "function_body": "function Read_Byte_Decrypted return Unsigned_8; -- NB: reading goes on a while even if\n pragma Inline (Read_Byte_Decrypted); -- Zip_EOF is set: just gives garbage\n\n package Bit_Buffer is\n procedure Init;\n -- Read at least n bits into the bit buffer, returns the n first bits\n function Read (N : Natural) return Integer;\n pragma Inline (Read);\n function Read_U32 (N : Natural) return Unsigned_32;\n pragma Inline (Read_U32);\n -- Dump n bits no longer needed from the bit buffer\n procedure Dump (N : Natural);\n pragma Inline (Dump);\n procedure Dump_To_Byte_Boundary;\n function Read_And_Dump (N : Natural) return Integer;\n pragma Inline (Read_And_Dump);\n function Read_And_Dump_U32 (N : Natural) return Unsigned_32;\n pragma Inline (Read_And_Dump_U32);\n end Bit_Buffer;\n\n procedure Flush (X : Natural); -- directly from slide to output stream\n\n procedure Flush_If_Full (W : in out Integer);\n pragma Inline (Flush_If_Full);\n\n procedure Copy (Distance, Length : Natural; Index : in out Natural);\n pragma Inline (Copy);\n end Unz_Io;\n\n package Unz_Meth is\n procedure Copy_Stored (Size : Ada.Streams.Stream_Element_Offset);\n procedure Inflate;\n end Unz_Meth;\n\n ------------------------------\n -- Bodies of UnZ_* packages --\n ------------------------------\n package body Unz_Io is\n\n procedure Init_Buffers is\n begin\n Unz_Glob.Inpos := 0; -- Input buffer position\n Unz_Glob.Readpos := -1; -- Nothing read\n Unz_Glob.Slide_Index := 0;\n Unz_Glob.Reachedsize := 0;\n Zip_Eof := False;\n Zip.CRC.Init (CRC_Value);\n Bit_Buffer.Init;\n end Init_Buffers;\n\n procedure Process_Compressed_End_Reached is\n begin\n if Zip_Eof then -- We came already here once\n raise Zip.Archive_Corrupted with\n \"Decoding went past compressed data size plus one buffer length\";\n -- Avoid infinite loop on data with exactly buffer's length and no end marker\n else\n Unz_Glob.Readpos := Unz_Glob.Inbuf'Length;\n -- Simulates reading -> no blocking.\n -- The buffer is full of \"random\" data and we hope for a wrong code or a CRC error\n Zip_Eof := True;\n end if;\n end Process_Compressed_End_Reached;\n\n procedure Read_Buffer is\n begin\n if Unz_Glob.Reachedsize > Compressed_Size + 2 then\n -- +2: last code is smaller than requested!\n Process_Compressed_End_Reached;\n else\n begin\n Zip.Blockread\n (Stream => Zip_File,\n Buffer => Unz_Glob.Inbuf,\n Actually_Read => Unz_Glob.Readpos);\n exception\n when others => -- I/O error\n Process_Compressed_End_Reached;" + }, + { + "function_def": "procedure Init is", + "function_body": "begin\n B := 0;\n K := 0;\n end Init;\n\n procedure Need (N : Natural) is\n pragma Inline (Need);\n begin\n while K < N loop\n B := B or Shift_Left (Unsigned_32 (Read_Byte_Decrypted), K);\n K := K + 8;\n end loop;\n end Need;\n\n procedure Dump (N : Natural) is\n begin\n B := Shift_Right (B, N);\n K := K - N;\n end Dump;\n\n procedure Dump_To_Byte_Boundary is\n begin\n Dump (K mod 8);\n end Dump_To_Byte_Boundary;\n\n function Read_U32 (N : Natural) return Unsigned_32 is\n begin\n Need (N);\n return B and (Shift_Left (1, N) - 1);\n end Read_U32;\n\n function Read (N : Natural) return Integer is\n begin\n return Integer (Read_U32 (N));\n end Read;\n\n function Read_And_Dump (N : Natural) return Integer is\n Res : Integer;\n begin\n Res := Read (N);\n Dump (N);\n return Res;\n end Read_And_Dump;\n\n function Read_And_Dump_U32 (N : Natural) return Unsigned_32 is\n Res : Unsigned_32;\n begin\n Res := Read_U32 (N);\n Dump (N);\n return Res;\n end Read_And_Dump_U32;\n\n end Bit_Buffer;\n\n procedure Flush (X : Natural) is\n use Zip;\n use Ada.Streams;\n begin\n begin\n Blockwrite (Output_Stream_Access.all, Unz_Glob.Slide (0 .. X - 1));\n exception\n when others =>\n raise Unzip.Write_Error;" + }, + { + "function_def": "procedure Inflate_Stored_Block is -- Actually, nothing to inflate", + "function_body": "N : Integer;\n begin\n Unz_Io.Bit_Buffer.Dump_To_Byte_Boundary;\n -- Get the block length and its complement\n N := Unz_Io.Bit_Buffer.Read_And_Dump (16);\n if N /= Integer ((not Unz_Io.Bit_Buffer.Read_And_Dump_U32 (16)) and 16#ffff#) then\n raise Zip.Archive_Corrupted;\n end if;\n while N > 0 and then not Zip_Eof loop\n -- Read and output the non-compressed data\n N := N - 1;\n Unz_Glob.Slide (Unz_Glob.Slide_Index) :=\n Zip.Byte (Unz_Io.Bit_Buffer.Read_And_Dump (8));\n Unz_Glob.Slide_Index := Unz_Glob.Slide_Index + 1;\n Unz_Io.Flush_If_Full (Unz_Glob.Slide_Index);\n end loop;\n end Inflate_Stored_Block;\n\n -- Copy lengths for literal codes 257..285\n\n Copy_Lengths_Literal : constant Length_Array (0 .. 30) :=\n (3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n 13,\n 15,\n 17,\n 19,\n 23,\n 27,\n 31,\n 35,\n 43,\n 51,\n 59,\n 67,\n 83,\n 99,\n 115,\n 131,\n 163,\n 195,\n 227,\n 258,\n 0,\n 0);\n\n -- Extra bits for literal codes 257..285\n\n Extra_Bits_Literal : constant Length_Array (0 .. 30) :=\n (0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 2,\n 2,\n 2,\n 2,\n 3,\n 3,\n 3,\n 3,\n 4,\n 4,\n 4,\n 4,\n 5,\n 5,\n 5,\n 5,\n 0,\n Invalid,\n Invalid);\n\n -- Copy offsets for distance codes 0..29 (30..31: deflate_e)\n\n Copy_Offset_Distance : constant Length_Array (0 .. 31) :=\n (1,\n 2,\n 3,\n 4,\n 5,\n 7,\n 9,\n 13,\n 17,\n 25,\n 33,\n 49,\n 65,\n 97,\n 129,\n 193,\n 257,\n 385,\n 513,\n 769,\n 1025,\n 1537,\n 2049,\n 3073,\n 4097,\n 6145,\n 8193,\n 12289,\n 16385,\n 24577,\n 32769,\n 49153);\n\n -- Extra bits for distance codes\n\n Extra_Bits_Distance : constant Length_Array (0 .. 31) :=\n (0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 2,\n 2,\n 3,\n 3,\n 4,\n 4,\n 5,\n 5,\n 6,\n 6,\n 7,\n 7,\n 8,\n 8,\n 9,\n 9,\n 10,\n 10,\n 11,\n 11,\n 12,\n 12,\n 13,\n 13,\n 14,\n 14);\n\n Max_Dist : constant Integer := 29; -- changed to 31 for deflate_e\n\n Length_List_For_Fixed_Block_Literals : constant Length_Array (0 .. 287) :=\n (0 .. 143 => 8, 144 .. 255 => 9, 256 .. 279 => 7, 280 .. 287 => 8);\n\n procedure Inflate_Fixed_Block is\n Tl, -- literal/length code table\n Td : P_Table_List; -- distance code table\n Bl, Bd : Integer; -- lookup bits for tl/bd\n Huft_Incomplete : Boolean;\n begin\n -- Make a complete, but wrong [why ?] code set (see Appnote: 5.5.2, RFC 1951: 3.2.6)\n Bl := 7;\n Huft_Build\n (Length_List_For_Fixed_Block_Literals,\n 257,\n Copy_Lengths_Literal,\n Extra_Bits_Literal,\n Tl,\n Bl,\n Huft_Incomplete);\n -- Make an incomplete code set (see Appnote: 5.5.2, RFC 1951: 3.2.6)\n Bd := 5;\n begin\n Huft_Build\n ((0 .. Max_Dist => 5),\n 0,\n Copy_Offset_Distance,\n Extra_Bits_Distance,\n Td,\n Bd,\n Huft_Incomplete);\n exception\n when Huft_Out_Of_Memory | Huft_Error =>\n Huft_Free (Tl);\n raise Zip.Archive_Corrupted;" + }, + { + "function_def": "procedure Inflate_Dynamic_Block is", + "function_body": "Lbits : constant := 9;\n Dbits : constant := 6;\n\n Current_Length : Natural;\n Defined, Number_Of_Lengths : Natural;\n\n Tl : P_Table_List; -- literal/length code tables\n Td : P_Table_List; -- distance code tables\n\n Ct : P_Huft_Table; -- current table\n Ct_Idx : Natural; -- current table's index\n\n Bl, Bd : Integer; -- lookup bits for tl/bd\n Nb : Natural; -- number of bit length codes\n Nl : Natural; -- number of literal length codes\n Nd : Natural; -- number of distance codes\n\n -- literal/length and distance code lengths\n Ll : Length_Array (0 .. 288 + 32 - 1) := (others => 0);\n\n Huft_Incomplete : Boolean;\n\n procedure Repeat_Length_Code (Amount : Natural) is\n begin\n if Defined + Amount > Number_Of_Lengths then\n raise Zip.Archive_Corrupted;\n end if;\n for C in reverse 1 .. Amount loop\n Ll (Defined) := Current_Length;\n Defined := Defined + 1;\n end loop;\n end Repeat_Length_Code;\n\n begin\n -- Read in table lengths\n Nl := 257 + Unz_Io.Bit_Buffer.Read_And_Dump (5);\n Nd := 1 + Unz_Io.Bit_Buffer.Read_And_Dump (5);\n Nb := 4 + Unz_Io.Bit_Buffer.Read_And_Dump (4);\n\n if Nl > 288 or else Nd > 32 then\n raise Zip.Archive_Corrupted;\n end if;\n\n -- Read in bit-length-code lengths for decoding the compression structure.\n -- The rest, Ll( Bit_Order( Nb .. 18 ) ), is already = 0\n for J in 0 .. Nb - 1 loop\n Ll (Bit_Order_For_Dynamic_Block (J)) := Unz_Io.Bit_Buffer.Read_And_Dump (3);\n end loop;\n\n -- Build decoding table for trees--single level, 7 bit lookup\n Bl := 7;\n begin\n Huft_Build (Ll (0 .. 18), 19, Empty, Empty, Tl, Bl, Huft_Incomplete);\n if Huft_Incomplete then\n Huft_Free (Tl);\n raise Zip.Archive_Corrupted with\n \"Incomplete code set for compression structure\";\n end if;\n exception\n when Zip.Archive_Corrupted =>\n raise;\n when others =>\n raise Zip.Archive_Corrupted with\n \"Error when building tables for compression structure\";" + }, + { + "function_def": "procedure Inflate is", + "function_body": "Is_Last_Block : Boolean;\n Blocks, Blocks_Fix, Blocks_Dyn : Long_Integer := 0;\n begin\n loop\n Blocks := Blocks + 1;\n Inflate_Block (Is_Last_Block, Blocks_Fix, Blocks_Dyn);\n exit when Is_Last_Block;\n end loop;\n Unz_Io.Flush (Unz_Glob.Slide_Index);\n Unz_Glob.Slide_Index := 0;\n end Inflate;\n end Unz_Meth;\n\n procedure Process_Descriptor_Store (Descriptor : out Zip.Headers.Data_Descriptor) is\n Buffer : Ada.Streams.Stream_Element_Array (1 .. 16);\n begin\n Zip.Blockread (Zip_File, Buffer);\n Zip.Headers.Copy_And_Check (Buffer, Descriptor);\n end Process_Descriptor_Store;\n\n procedure Process_Descriptor_Deflate (Descriptor : out Zip.Headers.Data_Descriptor) is\n Buffer : Ada.Streams.Stream_Element_Array (1 .. 16);\n begin\n Unz_Io.Bit_Buffer.Dump_To_Byte_Boundary;\n for I in Buffer'Range loop\n Buffer (I) := Ada.Streams.Stream_Element (Unz_Io.Read_Byte_Decrypted);\n end loop;\n Zip.Headers.Copy_And_Check (Buffer, Descriptor);\n end Process_Descriptor_Deflate;\n\n use Zip;\n begin\n Unz_Io.Init_Buffers;\n\n -- Unzip correct type\n case Format is\n when Store =>\n Unz_Meth.Copy_Stored (Ada.Streams.Stream_Element_Offset (Compressed_Size));\n when Deflate =>\n Unz_Meth.Inflate;\n end case;\n\n if Verify_Integrity then\n CRC_Value := Zip.CRC.Final (CRC_Value);\n end if;\n\n if Data_Descriptor_After_Data then -- Sizes and CRC at the end\n declare\n Memo_Uncomp_Size : constant Unsigned_32 := Hint.Dd.Uncompressed_Size;\n begin\n case Format is\n when Store =>\n Process_Descriptor_Store (Hint.Dd);\n when Deflate =>\n Process_Descriptor_Deflate (Hint.Dd);\n end case;\n\n -- CRC is for checking; sizes are for informing user\n if Memo_Uncomp_Size < Unsigned_32'Last\n and then Memo_Uncomp_Size /= Hint.Dd.Uncompressed_Size\n then\n raise Uncompressed_Size_Error;\n end if;\n exception\n when Zip.Headers.Bad_Data_Descriptor =>\n raise Zip.Archive_Corrupted;" + }, + { + "function_def": "procedure UnzipDCF is", + "function_body": "package Dirs renames Ada.Directories;\n package SU renames Ada.Strings.Unbounded;\n\n List_Files : Boolean := False;\n Test_Data : Boolean := False;\n Comment : Boolean := False;\n\n Quiet : Boolean := False;\n\n No_Directories : Boolean := False;\n Lower_Case : Boolean := False;\n\n Last_Option : Natural := 0;\n\n Extraction_Directory : SU.Unbounded_String\n := SU.To_Unbounded_String (Dirs.Current_Directory);\n\n Name_Conflict_Decision : DCF.Unzip.Name_Conflict_Intervention := DCF.Unzip.Yes;\n\n procedure Help is\n begin\n Put_Line (\"UnZipDCF \" & DCF.Zip.Version & \" - unzip document container files\");\n New_Line;\n Put_Line (\"Usage: unzipdcf [-options[modifiers]] [-d exdir] file [list]\");\n New_Line;\n Put_Line (\" -l list files\");\n Put_Line (\" -t test integrity of files, no write\");\n Put_Line (\" -z display archive comment only\");\n Put_Line (\" -d extract to \"\"exdir\"\"\");\n Put_Line (\"modifiers:\");\n Put_Line (\" -n never overwrite existing files -q quiet mode\");\n Put_Line (\" -o always overwrite existing files\");\n Put_Line (\" -j junk archived directory structure -L make names lower case\");\n end Help;\n\n procedure Resolve_Conflict\n (Name : in String;\n Action : out DCF.Unzip.Name_Conflict_Intervention;\n New_Name : out String;\n New_Name_Length : out Natural)\n is\n C : Character;\n\n use all type DCF.Unzip.Name_Conflict_Intervention;\n begin\n loop\n Put (\"replace \" & Name & \"? [y]es, [n]o, [A]ll, [N]one, [r]ename: \");\n declare\n Input : constant String := Get_Line;\n begin\n C := Input (Input'First);\n exit when C = 'y' or C = 'n' or C = 'A' or C = 'N' or C = 'r';\n Put_Line (\"error: invalid response [\" & Input & \"]\");" + }, + { + "function_def": "procedure List_File_From_Stream (File : DCF.Zip.Archived_File) is", + "function_body": "Date_Time : constant Ada.Calendar.Time\n := DCF.Streams.Calendar.Convert (File.Date_Time);\n Date : constant String := Ada.Calendar.Formatting.Image\n (Date_Time, Time_Zone => Ada.Calendar.Time_Zones.UTC_Time_Offset (Date_Time));\n begin\n Total_Uncompressed_Size := Total_Uncompressed_Size + File.Uncompressed_Size;\n Total_Compressed_Size := Total_Compressed_Size + File.Compressed_Size;\n\n -- Print date and time without seconds\n Mod_IO.Put (File.Uncompressed_Size, 10);\n Int_IO.Put (Percentage (File.Compressed_Size, File.Uncompressed_Size), 4);\n Put_Line (\"% \" & Date (Date'First .. Date'Last - 3) & \" \" & File.Name);\n end List_File_From_Stream;\n\n procedure List_All_Files is new DCF.Zip.Traverse (List_File_From_Stream);\n begin\n Put_Line (\" Length Cmpr Date Time Name\");\n Put_Line (\"---------- ---- ---------- ----- ----\");\n\n List_All_Files (Info);\n\n Put_Line (\"---------- ---- -------\");\n Mod_IO.Put (Total_Uncompressed_Size, 10);\n Int_IO.Put (Percentage (Total_Compressed_Size, Total_Uncompressed_Size), 4);\n Put (\"% \" & Info.Entries'Image);\n Put_Line (if Info.Entries > 1 then \" files\" else \" file\");" + }, + { + "function_def": "procedure Extract_All_Files is new DCF.Zip.Traverse (Extract_From_Stream);", + "function_body": "procedure Extract_One_File is new DCF.Zip.Traverse_One_File (Extract_From_Stream);\n begin\n if not Test_Data and then not Dirs.Exists (Extraction_Folder) then\n Dirs.Create_Path (Extraction_Folder);\n end if;\n\n if Extract_All then\n Extract_All_Files (Info);\n else\n for I in Last_Option + 2 .. Argument_Count loop\n Extract_One_File (Info, Argument (I));\n end loop;\n end if;" + }, + { + "function_def": "procedure ZipDCF is", + "function_body": "package Dirs renames Ada.Directories;\n package SU renames Ada.Strings.Unbounded;\n\n Quiet : Boolean := False;\n\n Add_Directories : Boolean := True;\n Recursive : Boolean := False;\n Junk_Directories : Boolean := False;\n\n Comment : SU.Unbounded_String;\n Compression_Method : DCF.Zip.Compress.Compression_Method := DCF.Zip.Compress.Deflate_2;\n\n Last_Option : Natural := 0;\n\n procedure Help is\n begin\n Put_Line (\"ZipDCF \" & DCF.Zip.Version & \" - create document container files\");\n New_Line;\n Put_Line (\"Usage: zipdcf [-options] [-z comment] file list\");\n New_Line;\n Put_Line (\" -D no directory entries -q quiet mode\");\n Put_Line (\" -r recurse into directories -j junk directory structure\");\n Put_Line (\" -0 store files uncompressed\");\n Put_Line (\" -1 use faster compression -z add archive file comment\");\n Put_Line (\" -9 use better compression\");\n end Help;\n\n function Maybe_Trash_Dir (Name : String) return String is\n Index : constant Natural := Ada.Strings.Fixed.Index (Name, \"/\", Ada.Strings.Backward);\n begin\n return (if Junk_Directories then Name (Index + 1 .. Name'Last) else Name);\n end Maybe_Trash_Dir;\nbegin\n if Argument_Count = 0 then\n Help;\n return;\n end if;\n\n for I in 1 .. Argument_Count loop\n if Argument (I) (1) = '-' then\n if Last_Option = I then\n null; -- Argument for a previous option\n else\n Last_Option := I;\n\n if Argument (I)'Length = 1 then\n Help;\n return;\n end if;\n\n for J in 2 .. Argument (I)'Last loop\n case Argument (I) (J) is\n when 'D' =>\n Add_Directories := False;\n when 'r' =>\n Recursive := True;\n when '0' =>\n Compression_Method := DCF.Zip.Compress.Store;\n when '1' =>\n Compression_Method := DCF.Zip.Compress.Deflate_1;\n when '9' =>\n Compression_Method := DCF.Zip.Compress.Deflate_3;\n when 'q' =>\n Quiet := True;\n when 'j' =>\n Junk_Directories := True;\n when 'z' =>\n if I = Argument_Count then\n Help;\n return;\n end if;\n\n Comment := SU.To_Unbounded_String (Argument (I + 1));\n Last_Option := I + 1;\n when others =>\n Help;\n return;\n end case;\n end loop;\n end if;\n end if;\n end loop;\n\n if Argument_Count = Last_Option then\n Help;\n return;\n end if;\n\n declare\n Archive : constant String := Argument (Last_Option + 1);\n begin\n if Dirs.Exists (Archive) then\n Put_Line (\"Archive file '\" & Archive & \"' already exists\");\n return;\n end if;\n\n if not Quiet then\n Put_Line (\"Archive: \" & Archive);\n end if;\n\n declare\n Archive_Stream : aliased DCF.Streams.File_Zipstream\n := DCF.Streams.Create (Archive);\n Info : DCF.Zip.Create.Zip_Create_Info;\n\n procedure Add_File (Path : String) is\n Name : constant String := Maybe_Trash_Dir (Path);\n begin\n if not Dirs.Exists (Path) then\n Put_Line (\"warning: \" & Name & \" does not exist\");\n return;\n end if;\n\n declare\n use all type Dirs.File_Kind;\n\n File_Is_Directory : constant Boolean := Dirs.Kind (Path) = Directory;\n begin\n if not File_Is_Directory then\n if not Quiet then\n Put_Line (\" adding: \" & Name);\n end if;\n\n declare\n File_Stream : aliased DCF.Streams.File_Zipstream\n := DCF.Streams.Open (Path);\n begin\n DCF.Streams.Set_Name (File_Stream, Name);\n DCF.Streams.Set_Time (File_Stream,\n DCF.Streams.Calendar.Convert (Dirs.Modification_Time (Path)));\n DCF.Zip.Create.Add_Stream (Info, File_Stream);" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion", + "function_body": "(System.Address,\n Float_Star);\n\n function Convert is new Ada.Unchecked_Conversion\n (System.Address,\n paTestData_Ptr);\n\n --------------------\n -- paTestCallback --\n --------------------\n\n function paTestCallback\n (inputBuffer : System.Address;\n outputBuffer : System.Address;\n framesPerBuffer : Interfaces.C.unsigned_long;\n timeInfo : access PA_Stream_Callback_Time_Info;\n statusFlags : PA_Stream_Callback_Flags;\n userData : System.Address)\n return PA_Stream_Callback_Result\n is\n pragma Unreferenced (inputBuffer);\n pragma Unreferenced (timeInfo);\n pragma Unreferenced (statusFlags);\n\n oBuff : Float_Star := Convert (outputBuffer);\n lData : constant paTestData_Ptr := Convert (userData);\n begin\n for i in 1 .. Integer (framesPerBuffer) loop\n declare\n output : Float := 0.0;\n phaseInc : Long_Float := 0.02;\n phase : Long_Float;\n begin\n for j in 1 .. lData.all.numSines loop\n\n -- Advance phase of next oscillator.\n\n phase := lData.all.phases (j);\n phase := phase + phaseInc;\n\n if phase > Two_Pi then\n phase := phase - Two_Pi;\n end if;\n\n phaseInc := phaseInc * 1.02;\n\n if phaseInc > 0.5 then\n phaseInc := phaseInc * 0.5;\n end if;\n\n -- This is not a very efficient way to calc sines.\n\n output := output + Sin (Float (phase));\n lData.all.phases (j) := phase;\n\n end loop;\n\n oBuff.all := output / Float (lData.all.numSines);\n Float_Ptrs.Increment (oBuff);" + }, + { + "function_def": "procedure exercise8 is", + "function_body": "Count_Failed : exception; -- Exception to be raised when counting fails\n Gen : Generator; -- Random number generator\n\n protected type Transaction_Manager (N : Positive) is\n entry Finished;\n entry Wait_Until_Aborted;\n procedure Signal_Abort;\n private\n Finished_Gate_Open : Boolean := False;\n Aborted : Boolean := False;\n end Transaction_Manager;\n protected body Transaction_Manager is\n -- PART 1 --\n entry Finished when Finished_Gate_Open or Finished'Count = N is\n begin\n\t\t\t if Finished'Count = N - 1 then\n\t\t\t\t Finished_Gate_Open := True;\n\t\t\t end if;\n\n\t\t\t if Finished'Count = 0 then\n\t\t\t\t Finished_Gate_Open := False;\n\t\t\t end if;\n end Finished;\n\n -- PART 2 --\n entry Wait_Until_Aborted when Aborted is\n begin\n if Wait_Until_Aborted'Count = 0 then\n Aborted := False;\n end if;\n end Wait_Until_Aborted;\n\n\n procedure Signal_Abort is\n begin\n Aborted := True;\n end Signal_Abort;\n\n end Transaction_Manager;\n\n\n\n\n function Unreliable_Slow_Add (x : Integer) return Integer is\n Error_Rate : Constant := 0.125; -- (between 0 and 1)\n Random_Num : Float := 0.0;\n begin\n Random_Num := Random(Gen);\n delay Duration(Random_Num * 4.0);\n if Random_Num > Error_Rate then\n \treturn x + 10;\n else\n \traise Count_Failed;\n end if;\n end Unreliable_Slow_Add;\n\n\n\n\n task type Transaction_Worker (Initial : Integer; Manager : access Transaction_Manager);\n task body Transaction_Worker is\n Num : Integer := Initial;\n Prev : Integer := Num;\n Round_Num : Integer := 0;\n begin\n Put_Line (\"Worker\" & Integer'Image(Initial) & \" started\");\n\n loop\n Put_Line (\"Worker\" & Integer'Image(Initial) & \" started round\" & Integer'Image(Round_Num));\n Round_Num := Round_Num + 1;\n -- PART 1 --\n select\n \tManager.Wait_Until_Aborted;\n \tNum := Prev + 5;\n \tPut_Line( \"Forward error recovery: Worker\"\n \t\t& Integer'Image( Initial ) & \" commiting\" & Integer'Image( Num ) );\n then abort\n\t begin\n\t\t Num := Unreliable_Slow_Add( Num );\n\t\t Manager.Finished;\n\t\t Put_Line (\" Worker\" & Integer'Image(Initial) & \" comitting\" & Integer'Image(Num));\n\t\t\t\texception\n\t\t\t\t\twhen Count_Failed =>\n\t\t\t\t\t begin\n\t\t\t\t\t\t Put_Line( \" Worker\" & Integer'Image( Initial ) & \" aborting\" );\n\t\t\t\t\t\t Manager.Signal_Abort;\n\t\t\t\t\t\t Manager.Finished;" + }, + { + "function_def": "procedure exercise7 is", + "function_body": "Count_Failed : exception; -- Exception to be raised when counting fails\n Gen : Generator; -- Random number generator\n\n protected type Transaction_Manager (N : Positive) is\n entry Finished;\n function Commit return Boolean;\n procedure Signal_Abort;\n private\n Finished_Gate_Open : Boolean := False;\n Aborted : Boolean := False;\n Should_Commit : Boolean := True;\n end Transaction_Manager;\n protected body Transaction_Manager is\n entry Finished when Finished_Gate_Open or Finished'Count = N is\n begin\n ------------------------------------------\n -- PART 3: Complete the exit protocol here\n ------------------------------------------\n if Finished'Count = N - 1 then\n\t\t\t\t Finished_Gate_Open := True;\n\t\t\t\t Should_Commit := True;\n\t\t\t end if;\n\t\t\t if Aborted then\n\t\t\t\t Should_Commit := False;\n\t\t\t end if;\n\t\t\t if Finished'Count = 0 then\n\t\t\t\t Finished_Gate_Open := False;\n\t\t\t\t Aborted := False;\n\t\t\t end if;\n end Finished;\n\n procedure Signal_Abort is\n begin\n Aborted := True;\n end Signal_Abort;\n\n function Commit return Boolean is\n begin\n return Should_Commit;\n end Commit;\n\n end Transaction_Manager;\n\n\n\n\n function Unreliable_Slow_Add (x : Integer) return Integer is\n Error_Rate : Constant := 0.15; -- (between 0 and 1)\n begin\n -------------------------------------------\n -- PART 1: Create the transaction work here\n -------------------------------------------\n Random_Num := Random(Gen);\n delay Duration(Random_Num * 4.0);\n if Random_Num > Error_Rate then\n return x + 10;\n else\n \t raise Count_Failed;\n end if;\n end Unreliable_Slow_Add;\n\n\n\n\n task type Transaction_Worker (Initial : Integer; Manager : access Transaction_Manager);\n task body Transaction_Worker is\n Num : Integer := Initial;\n Prev : Integer := Num;\n Round_Num : Integer := 0;\n begin\n Put_Line (\"Worker\" & Integer'Image(Initial) & \" started\");\n\n loop\n Put_Line (\"Worker\" & Integer'Image(Initial) & \" started round\" & Integer'Image(Round_Num));\n Round_Num := Round_Num + 1;\n\n ---------------------------------------\n -- PART 2: Do the transaction work here\n ---------------------------------------\n begin\n Num := Unreliable_Slow_Add( Num );\n Manager.Finished;\n exception\n when Count_Failed =>\n begin\n Put_Line( \" Worker\" & Integer'Image( Initial ) & \" aborting\" );\n Manager.Signal_Abort;\n Manager.Finished;" + }, + { + "function_def": "procedure Convert_Card_Identification_Data_Register", + "function_body": "(W0, W1, W2, W3 : UInt32;\n Res : out Card_Identification_Data_Register);\n -- Convert the R2 reply to CID\n\n procedure Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3 : UInt32;\n Card_Type : Supported_SD_Memory_Cards;\n CSD : out Card_Specific_Data_Register);\n -- Convert the R2 reply to CSD\n\n procedure Convert_SDCard_Configuration_Register\n (W0, W1 : UInt32;\n SCR : out SDCard_Configuration_Register);\n -- Convert W0 (MSB) / W1 (LSB) to SCR.\n\n function Compute_Card_Capacity\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt64;\n -- Compute the card capacity (in bytes) from the CSD\n\n function Compute_Card_Block_Size\n (CSD : Card_Specific_Data_Register;\n Card_Type : Supported_SD_Memory_Cards) return UInt32;\n -- Compute the card block size (in bytes) from the CSD.\n\n function Get_Transfer_Rate\n (CSD : Card_Specific_Data_Register) return Natural;\n -- Compute transfer rate from CSD\n\n function Swap32 (Val : UInt32) return UInt32 with Inline_Always;\n\n function BE32_To_Host (Val : UInt32) return UInt32 with Inline_Always;\n\n -- Swap bytes in a word\n ------------\n -- Swap32 --\n ------------\n\n function Swap32 (Val : UInt32) return UInt32 is\n begin\n return Shift_Left (Val and 16#00_00_00_ff#, 24)\n or Shift_Left (Val and 16#00_00_ff_00#, 8)\n or Shift_Right (Val and 16#00_ff_00_00#, 8)\n or Shift_Right (Val and 16#ff_00_00_00#, 24);\n end Swap32;\n\n ------------------\n -- BE32_To_Host --\n ------------------\n\n function BE32_To_Host (Val : UInt32) return UInt32 is\n use System;\n begin\n if Default_Bit_Order = Low_Order_First then\n return Swap32 (Val);\n else\n return Val;\n end if;\n end BE32_To_Host;\n\n ---------------------------------\n -- Card_Identification_Process --\n ---------------------------------\n\n procedure Card_Identification_Process\n (This : in out SDMMC_Driver'Class;\n Info : out Card_Information;\n Status : out SD_Error)\n is\n Rsp : UInt32;\n W0, W1, W2, W3 : UInt32;\n Rca : UInt32;\n\n begin\n -- Reset controller\n This.Reset (Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD0: Sets the SDCard state to Idle\n Send_Cmd (This, Go_Idle_State, 0, Status);\n\n if Status /= OK then\n return;\n end if;\n\n -- CMD8: IF_Cond, voltage supplied: 0x1 (2.7V - 3.6V)\n -- It is mandatory for the host compliant to Physical Spec v2.00\n -- to send CMD8 before ACMD41\n Send_Cmd (This, Send_If_Cond, 16#1a5#, Status);\n\n if Status = OK then\n -- at least SD Card 2.0\n Info.Card_Type := STD_Capacity_SD_Card_v2_0;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and 16#fff#) /= 16#1a5# then\n -- Bad voltage or bad pattern.\n Status := Error;\n return;\n end if;\n else\n -- If SD Card, then it's v1.1\n Info.Card_Type := STD_Capacity_SD_Card_V1_1;\n end if;\n\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD55: APP_CMD\n -- This is done manually to handle error (this command is not\n -- supported by mmc).\n Send_Cmd (This, Cmd_Desc (App_Cmd), 0, Status);\n\n if Status /= OK then\n if Status = Command_Timeout_Error\n and then I = 1\n and then Info.Card_Type = STD_Capacity_SD_Card_V1_1\n then\n -- Not an SDCard. Suppose MMC.\n Info.Card_Type := Multimedia_Card;\n exit;\n end if;\n return;\n end if;\n\n -- ACMD41: SD_SEND_OP_COND (no crc check)\n -- Arg: HCS=1, XPC=0, S18R=0\n Send_Cmd\n (This, Acmd_Desc (SD_App_Send_Op_Cond), 16#40ff_0000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_High_Capacity) = SD_OCR_High_Capacity then\n Info.Card_Type := High_Capacity_SD_Card;\n end if;\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n\n else\n Status := OK;\n exit;\n end if;\n end loop;\n\n if Status = Command_Timeout_Error\n and then Info.Card_Type = Multimedia_Card\n then\n for I in 1 .. 5 loop\n This.Delay_Milliseconds (200);\n\n -- CMD1: SEND_OP_COND query voltage\n Send_Cmd (This, Cmd_Desc (Send_Op_Cond), 16#00ff_8000#, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp48 (This, Rsp);\n\n if (Rsp and SD_OCR_Power_Up) = 0 then\n Status := Error;\n else\n if (Rsp and 16#00ff_8000#) /= 16#00ff_8000# then\n Status := Error;\n return;\n end if;\n Status := OK;\n exit;\n end if;\n end loop;\n end if;\n\n if Status /= OK then\n return;\n end if;\n\n -- TODO: Switch voltage\n\n -- CMD2: ALL_SEND_CID (136 bits)\n Send_Cmd (This, All_Send_CID, 0, Status);\n if Status /= OK then\n return;\n end if;\n\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Identification_Data_Register (W0, W1, W2, W3, Info.SD_CID);\n\n -- CMD3: SEND_RELATIVE_ADDR\n case Info.Card_Type is\n when Multimedia_Card =>\n Rca := 16#01_0000#;\n when others =>\n Rca := 0;\n end case;\n\n Send_Cmd (This, Send_Relative_Addr, Rca, Status);\n if Status /= OK then\n return;\n end if;\n case Info.Card_Type is\n when Multimedia_Card =>\n null;\n when others =>\n Read_Rsp48 (This, Rsp);\n Rca := Rsp and 16#ffff_0000#;\n if (Rsp and 16#e100#) /= 16#0100# then\n return;\n end if;\n end case;\n Info.RCA := UInt16 (Shift_Right (Rca, 16));\n\n -- Switch to 25Mhz\n case Info.Card_Type is\n when Multimedia_Card =>\n Set_Clock (This, Get_Transfer_Rate (Info.SD_CSD));\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Set_Clock (This, 25_000_000);\n when others =>\n -- Not yet handled\n raise Program_Error;\n end case;\n\n -- CMD10: SEND_CID (136 bits)\n Send_Cmd (This, Send_CID, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD9: SEND_CSD\n Send_Cmd (This, Send_CSD, Rca, Status);\n if Status /= OK then\n return;\n end if;\n Read_Rsp136 (This, W0, W1, W2, W3);\n Convert_Card_Specific_Data_Register\n (W0, W1, W2, W3, Info.Card_Type, Info.SD_CSD);\n Info.Card_Capacity :=\n Compute_Card_Capacity (Info.SD_CSD, Info.Card_Type);\n Info.Card_Block_Size :=\n Compute_Card_Block_Size (Info.SD_CSD, Info.Card_Type);\n\n -- CMD7: SELECT\n Send_Cmd (This, Select_Card, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- CMD13: STATUS\n Send_Cmd (This, Send_Status, Rca, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Bus size\n case Info.Card_Type is\n when STD_Capacity_SD_Card_V1_1\n | STD_Capacity_SD_Card_v2_0\n | High_Capacity_SD_Card =>\n Send_ACmd (This, SD_App_Set_Bus_Width, Info.RCA, 2, Status);\n if Status /= OK then\n return;\n else\n Set_Bus_Size (This, Wide_Bus_4B);\n end if;\n when others =>\n null;\n end case;\n\n if (Info.SD_CSD.Card_Command_Class and 2**10) /= 0 then\n -- Class 10 supported.\n declare\n subtype Switch_Status_Type is UInt32_Array (1 .. 16);\n\n Switch_Status : Switch_Status_Type;\n begin\n -- CMD6\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#00_fffff0#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Handle endianness\n for I in Switch_Status'Range loop\n Switch_Status (I) := BE32_To_Host (Switch_Status (I));\n end loop;\n\n -- Switch tp 50Mhz if possible.\n if (Switch_Status (4) and 2**(16 + 1)) /= 0 then\n Read_Cmd (This, Cmd_Desc (Switch_Func), 16#80_fffff1#,\n Switch_Status, Status);\n if Status /= OK then\n return;\n end if;\n\n -- Switch to 50Mhz\n Set_Clock (This, 50_000_000);\n end if;" + }, + { + "function_def": "function Convert is new Ada.Unchecked_Conversion (HALFS.Status_Code, Status_Code);", + "function_body": "function Convert is new Ada.Unchecked_Conversion (File_Mode, HALFS.File_Mode);\n function Convert is new Ada.Unchecked_Conversion (File_Size, HALFS.File_Size);\n function Convert is new Ada.Unchecked_Conversion (HALFS.File_Size, File_Size);\n function Convert is new Ada.Unchecked_Conversion (Seek_Mode, HALFS.Seek_Mode);\n\n type Mount_Record is record\n Is_Free : Boolean := True;\n Name : String (1 .. Max_Mount_Name_Length);\n Name_Len : Positive;\n FS : Any_Filesystem_Driver;\n end record;\n\n subtype Mount_Index is Integer range 0 .. Max_Mount_Points;\n subtype Valid_Mount_Index is Mount_Index range 1 .. Max_Mount_Points;\n type Mount_Array is array (Valid_Mount_Index) of Mount_Record;\n\n type VFS_Directory_Handle is new Directory_Handle with record\n Is_Free : Boolean := True;\n Mount_Id : Mount_Index;\n end record;\n\n overriding function Get_FS\n (Dir : VFS_Directory_Handle) return Any_Filesystem_Driver;\n -- Return the filesystem the handle belongs to.\n\n overriding function Read\n (Dir : in out VFS_Directory_Handle;\n Handle : out Any_Node_Handle) return HALFS.Status_Code;\n -- Reads the next directory entry. If no such entry is there, an error\n -- code is returned in Status.\n\n overriding procedure Reset (Dir : in out VFS_Directory_Handle);\n -- Resets the handle to the first node\n\n overriding procedure Close (Dir : in out VFS_Directory_Handle);\n -- Closes the handle, and free the associated resources.\n\n function Open\n (Path : String;\n Handle : out Any_Directory_Handle)\n return Status_Code;\n\n function Open\n (Path : String;\n Mode : File_Mode;\n Handle : out Any_File_Handle)\n return Status_Code;\n\n Mount_Points : Mount_Array;\n\n Handles : array (1 .. 2) of aliased VFS_Directory_Handle;\n\n function Name (Point : Mount_Record) return Mount_Path;\n procedure Set_Name (Point : in out Mount_Record;\n Path : Mount_Path);\n procedure Split\n (Path : String;\n FS : out Any_Filesystem_Driver;\n Start_Index : out Natural);\n\n ----------\n -- Open --\n ----------\n\n function Open\n (File : in out File_Descriptor;\n Name : String;\n Mode : File_Mode)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Is_Open (File) then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Mode, File.Handle);\n\n if Ret /= OK then\n File.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (File : in out File_Descriptor) is\n begin\n if File.Handle /= null then\n File.Handle.Close;\n File.Handle := null;\n end if;\n end Close;\n\n -------------\n -- Is_Open --\n -------------\n\n function Is_Open\n (File : File_Descriptor)\n return Boolean\n is (File.Handle /= null);\n\n -----------\n -- Flush --\n -----------\n\n function Flush\n (File : File_Descriptor)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Flush);\n else\n return Invalid_Parameter;\n end if;\n end Flush;\n\n ----------\n -- Size --\n ----------\n\n function Size\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle = null then\n return 0;\n else\n return Convert (File.Handle.Size);\n end if;\n end Size;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Read (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n function Write\n (File : File_Descriptor;\n Addr : System.Address;\n Length : File_Size)\n return File_Size\n is\n Ret : HALFS.File_Size;\n Status : Status_Code;\n begin\n if File.Handle = null then\n return 0;\n end if;\n\n Ret := Convert (Length);\n Status := Convert (File.Handle.Write (Addr, Ret));\n\n if Status /= OK then\n return 0;\n else\n return Convert (Ret);\n end if;\n end Write;\n\n ------------\n -- Offset --\n ------------\n\n function Offset\n (File : File_Descriptor)\n return File_Size\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Offset);\n else\n return 0;\n end if;\n end Offset;\n\n ----------\n -- Seek --\n ----------\n\n function Seek\n (File : in out File_Descriptor;\n Origin : Seek_Mode;\n Amount : in out File_Size)\n return Status_Code\n is\n Ret : Status_Code;\n HALFS_Amount : HALFS.File_Size;\n begin\n if File.Handle /= null then\n HALFS_Amount := Convert (Amount);\n Ret := Convert (File.Handle.Seek (Convert (Origin), HALFS_Amount));\n Amount := Convert (HALFS_Amount);\n return Ret;\n else\n return Invalid_Parameter;\n end if;\n end Seek;\n\n -------------------\n -- Generic_Write --\n -------------------\n\n function Generic_Write\n (File : File_Descriptor;\n Value : T)\n return Status_Code\n is\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Write (Value'Address, T'Size / 8));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Write;\n\n ------------------\n -- Generic_Read --\n ------------------\n\n function Generic_Read\n (File : File_Descriptor;\n Value : out T)\n return Status_Code\n is\n L : HALFS.File_Size := T'Size / 8;\n begin\n if File.Handle /= null then\n return Convert (File.Handle.Read (Value'Address, L));\n else\n return Invalid_Parameter;\n end if;\n end Generic_Read;\n\n ----------\n -- Open --\n ----------\n\n function Open\n (Dir : in out Directory_Descriptor;\n Name : String)\n return Status_Code\n is\n Ret : Status_Code;\n begin\n if Dir.Handle /= null then\n return Invalid_Parameter;\n end if;\n Ret := Open (Name, Dir.Handle);\n\n if Ret /= OK then\n Dir.Handle := null;\n end if;\n\n return Ret;\n end Open;\n\n -----------\n -- Close --\n -----------\n\n procedure Close (Dir : in out Directory_Descriptor) is\n begin\n if Dir.Handle /= null then\n Dir.Handle.Close;\n end if;\n end Close;\n\n ----------\n -- Read --\n ----------\n\n function Read (Dir : in out Directory_Descriptor)\n return Directory_Entry\n is\n Node : Any_Node_Handle;\n Status : Status_Code;\n begin\n if Dir.Handle = null then\n return Invalid_Dir_Entry;\n end if;\n\n Status := Convert (Dir.Handle.Read (Node));\n if Status /= OK then\n return Invalid_Dir_Entry;\n end if;\n\n declare\n Name : constant String := Node.Basename;\n Ret : Directory_Entry (Name_Length => Name'Length);\n begin\n Ret.Name := Name;\n Ret.Subdirectory := Node.Is_Subdirectory;\n Ret.Read_Only := Node.Is_Read_Only;\n Ret.Hidden := Node.Is_Hidden;\n Ret.Symlink := Node.Is_Symlink;\n Ret.Size := Convert (Node.Size);\n Node.Close;\n return Ret;" + }, + { + "function_def": "function To_Data is new Ada.Unchecked_Conversion", + "function_body": "(FAT_Directory_Entry, Entry_Data);\n function To_Data is new Ada.Unchecked_Conversion\n (VFAT_Directory_Entry, Entry_Data);\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index;\n -- Finds a sequence of deleted entries that can fit Num_Entries.\n -- Returns the first entry of this sequence\n\n --------------\n -- Set_Size --\n --------------\n\n procedure Set_Size\n (E : in out FAT_Node;\n Size : FAT_File_Size)\n is\n begin\n if E.Size /= Size then\n E.Size := Size;\n E.Is_Dirty := True;\n end if;\n end Set_Size;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (Parent : FAT_Node;\n Filename : FAT_Name;\n DEntry : out FAT_Node) return Status_Code\n is\n -- We use a copy of the handle, so as not to touch the state of initial\n -- handle\n Status : Status_Code;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Parent.FS.Cluster_To_Block (Cluster);\n Index : Entry_Index := 0;\n\n begin\n loop\n Status := Next_Entry\n (FS => Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Index,\n DEntry => DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Long_Name (DEntry) = Filename or else\n (DEntry.L_Name.Len = 0 and then Short_Name (DEntry) = Filename)\n then\n return OK;\n end if;\n end loop;\n end Find;\n\n ----------\n -- Find --\n ----------\n\n function Find\n (FS : in out FAT_Filesystem;\n Path : String;\n DEntry : out FAT_Node) return Status_Code\n is\n Status : Status_Code;\n Idx : Natural; -- Idx is used to walk through the Path\n Token : FAT_Name;\n\n begin\n DEntry := Root_Entry (FS);\n\n -- Looping through the Path. We start at 2 as we ignore the initial '/'\n Idx := Path'First + 1;\n\n while Idx <= Path'Last loop\n Token.Len := 0;\n\n for J in Idx .. Path'Last loop\n if Path (J) = '/' then\n exit;\n end if;\n\n Token.Len := Token.Len + 1;\n Token.Name (Token.Len) := Path (J);\n end loop;\n\n Idx := Idx + Token.Len + 1;\n\n Status := Find (DEntry, Token, DEntry);\n\n if Status /= OK then\n return No_Such_File;\n end if;\n\n if Idx < Path'Last then\n -- Intermediate entry: needs to be a directory\n if not Is_Subdirectory (DEntry) then\n return No_Such_Path;\n end if;\n end if;\n end loop;\n\n return OK;\n end Find;\n\n ------------------\n -- Update_Entry --\n ------------------\n\n function Update_Entry\n (Parent : FAT_Node;\n Value : in out FAT_Node) return Status_Code\n is\n subtype Entry_Block is Block (1 .. 32);\n function To_Block is new\n Ada.Unchecked_Conversion (FAT_Directory_Entry, Entry_Block);\n function To_Entry is new\n Ada.Unchecked_Conversion (Entry_Block, FAT_Directory_Entry);\n\n Ent : FAT_Directory_Entry;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Offset : FAT_File_Size := FAT_File_Size (Value.Index) * 32;\n Block_Off : Natural;\n Block : Block_Offset;\n Ret : Status_Code;\n\n begin\n if not Value.Is_Dirty then\n return OK;\n end if;\n\n while Offset > Parent.FS.Cluster_Size loop\n Cluster := Parent.FS.Get_FAT (Cluster);\n Offset := Offset - Parent.FS.Cluster_Size;\n end loop;\n\n Block := Block_Offset (Offset / Parent.FS.Block_Size);\n Block_Off := Natural (Offset mod Parent.FS.Block_Size);\n\n Ret := Parent.FS.Ensure_Block\n (Parent.FS.Cluster_To_Block (Cluster) + Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n Ent := To_Entry (Parent.FS.Window (Block_Off .. Block_Off + 31));\n\n -- For now only the size can be modified, so just apply this\n -- modification\n Ent.Size := Value.Size;\n Value.Is_Dirty := False;\n\n Parent.FS.Window (Block_Off .. Block_Off + 31) := To_Block (Ent);\n Ret := Parent.FS.Write_Window;\n\n return Ret;\n end Update_Entry;\n\n ----------------\n -- Root_Entry --\n ----------------\n\n function Root_Entry (FS : in out FAT_Filesystem) return FAT_Node\n is\n Ret : FAT_Node;\n begin\n Ret.FS := FS'Unchecked_Access;\n Ret.Attributes := (Subdirectory => True,\n others => False);\n Ret.Is_Root := True;\n Ret.L_Name := (Name => (others => ' '),\n Len => 0);\n if FS.Version = FAT16 then\n Ret.Start_Cluster := 0;\n else\n Ret.Start_Cluster := FS.Root_Dir_Cluster;\n end if;\n Ret.Index := 0;\n\n return Ret;\n end Root_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Directory_Entry) return Status_Code\n is\n subtype Entry_Data is Block (1 .. 32);\n function To_Entry is new Ada.Unchecked_Conversion\n (Entry_Data, FAT_Directory_Entry);\n\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n if Current_Index = 16#FFFF# then\n return No_More_Entries;\n end if;\n\n if Current_Cluster = 0 and then FS.Version = FAT16 then\n if Current_Index >\n Entry_Index (FS.FAT16_Root_Dir_Num_Entries)\n then\n return No_More_Entries;\n else\n Block_Off :=\n Natural (FAT_File_Size (Current_Index * 32) mod\n FS.Block_Size);\n Current_Block :=\n FS.Root_Dir_Area +\n Block_Offset\n (FAT_File_Size (Current_Index * 32) / FS.Block_Size);\n end if;\n\n else\n Block_Off := Natural\n (FAT_File_Size (Current_Index * 32) mod FS.Block_Size);\n\n -- Check if we're on a block boundare\n if Unsigned_32 (Block_Off) = 0 and then Current_Index /= 0 then\n Current_Block := Current_Block + 1;\n end if;\n\n -- Check if we're on the boundary of a new cluster\n if Current_Block - FS.Cluster_To_Block (Current_Cluster)\n = FS.Blocks_Per_Cluster\n then\n -- The block we need to read is outside of the current cluster.\n -- Let's move on to the next\n\n -- Read the FAT table to determine the next cluster\n Current_Cluster := FS.Get_FAT (Current_Cluster);\n\n if Current_Cluster = 1\n or else FS.Is_Last_Cluster (Current_Cluster)\n then\n return Internal_Error;\n end if;\n\n Current_Block := FS.Cluster_To_Block (Current_Cluster);\n end if;\n end if;\n\n Ret := FS.Ensure_Block (Current_Block);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n if FS.Window (Block_Off) = 0 then\n -- End of entries: we stick the index here to make sure that further\n -- calls to Next_Entry always end-up here\n return No_More_Entries;\n end if;\n\n DEntry := To_Entry (FS.Window (Block_Off .. Block_Off + 31));\n Current_Index := Current_Index + 1;\n\n return OK;\n end Next_Entry;\n\n ----------------\n -- Next_Entry --\n ----------------\n\n function Next_Entry\n (FS : access FAT_Filesystem;\n Current_Cluster : in out Cluster_Type;\n Current_Block : in out Block_Offset;\n Current_Index : in out Entry_Index;\n DEntry : out FAT_Node) return Status_Code\n is\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural);\n -- Prepends Name to Full\n\n -------------\n -- Prepend --\n -------------\n\n procedure Prepend\n (Name : Wide_String;\n Full : in out String;\n Idx : in out Natural)\n is\n Val : Unsigned_16;\n begin\n for J in reverse Name'Range loop\n Val := Wide_Character'Pos (Name (J));\n if Val /= 16#FFFF#\n and then Val /= 0\n then\n Idx := Idx - 1;\n\n exit when Idx not in Full'Range;\n\n if Val < 255 then\n Full (Idx) := Character'Val (Val);\n elsif Val = 16#F029# then\n -- Path ends with a '.'\n Full (Idx) := '.';\n elsif Val = 16#F028# then\n -- Path ends with a ' '\n Full (Idx) := ' ';\n else\n Full (Idx) := '?';\n end if;\n end if;\n end loop;\n end Prepend;\n\n Ret : Status_Code;\n D_Entry : FAT_Directory_Entry;\n V_Entry : VFAT_Directory_Entry;\n function To_VFAT_Entry is new Ada.Unchecked_Conversion\n (FAT_Directory_Entry, VFAT_Directory_Entry);\n\n C : Unsigned_8;\n Last_Seq : VFAT_Sequence_Number := 0;\n CRC : Unsigned_8 := 0;\n Matches : Boolean;\n Current_CRC : Unsigned_8;\n L_Name : String (1 .. MAX_FILENAME_LENGTH);\n L_Name_First : Natural;\n\n begin\n L_Name_First := L_Name'Last + 1;\n\n loop\n Ret := Next_Entry\n (FS,\n Current_Cluster => Current_Cluster,\n Current_Block => Current_Block,\n Current_Index => Current_Index,\n DEntry => D_Entry);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Check if we have a VFAT entry here by checking that the\n -- attributes are 16#0F# (e.g. all attributes set except\n -- subdirectory and archive)\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n V_Entry := To_VFAT_Entry (D_Entry);\n\n if V_Entry.VFAT_Attr.Stop_Bit then\n L_Name_First := L_Name'Last + 1;\n\n else\n if Last_Seq = 0\n or else Last_Seq - 1 /= V_Entry.VFAT_Attr.Sequence\n then\n L_Name_First := L_Name'Last + 1;\n end if;\n end if;\n\n Last_Seq := V_Entry.VFAT_Attr.Sequence;\n\n Prepend (V_Entry.Name_3, L_Name, L_Name_First);\n Prepend (V_Entry.Name_2, L_Name, L_Name_First);\n Prepend (V_Entry.Name_1, L_Name, L_Name_First);\n\n if V_Entry.VFAT_Attr.Sequence = 1 then\n CRC := V_Entry.Checksum;\n end if;\n\n -- Ignore Volumes and deleted files\n elsif not D_Entry.Attributes.Volume_Label\n and then Character'Pos (D_Entry.Filename (1)) /= 16#E5#\n then\n if L_Name_First not in L_Name'Range then\n Matches := False;\n else\n Current_CRC := 0;\n Last_Seq := 0;\n\n for Ch of String'(D_Entry.Filename & D_Entry.Extension) loop\n C := Character'Enum_Rep (Ch);\n Current_CRC := Shift_Right (Current_CRC and 16#FE#, 1)\n or Shift_Left (Current_CRC and 16#01#, 7);\n -- Modulo addition\n Current_CRC := Current_CRC + C;\n end loop;\n\n Matches := Current_CRC = CRC;\n end if;\n\n DEntry :=\n (FS => FAT_Filesystem_Access (FS),\n L_Name => <>,\n S_Name => D_Entry.Filename,\n S_Name_Ext => D_Entry.Extension,\n Attributes => D_Entry.Attributes,\n Start_Cluster => (if FS.Version = FAT16\n then Cluster_Type (D_Entry.Cluster_L)\n else Cluster_Type (D_Entry.Cluster_L) or\n Shift_Left\n (Cluster_Type (D_Entry.Cluster_H), 16)),\n Size => D_Entry.Size,\n Index => Current_Index - 1,\n Is_Root => False,\n Is_Dirty => False);\n\n if Matches then\n DEntry.L_Name := -L_Name (L_Name_First .. L_Name'Last);\n else\n DEntry.L_Name.Len := 0;\n end if;\n\n return OK;\n end if;\n end loop;\n end Next_Entry;\n\n ----------\n -- Read --\n ----------\n\n function Read\n (Dir : in out FAT_Directory_Handle;\n DEntry : out FAT_Node) return Status_Code\n is\n begin\n return Next_Entry\n (Dir.FS,\n Current_Cluster => Dir.Current_Cluster,\n Current_Block => Dir.Current_Block,\n Current_Index => Dir.Current_Index,\n DEntry => DEntry);\n end Read;\n\n -------------------\n -- Create_Subdir --\n -------------------\n\n function Create_Subdir\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_Dir : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n Block : Block_Offset;\n Dot : FAT_Directory_Entry;\n Dot_Dot : FAT_Directory_Entry;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n E => New_Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Block := Dir.FS.Cluster_To_Block (New_Dir.Start_Cluster);\n Ret := Handle.FS.Ensure_Block (Block);\n if Ret /= OK then\n return Ret;\n end if;\n\n -- Allocate '.', '..' and the directory entry terminator\n Dot :=\n (Filename => (1 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32\n (New_Dir.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (New_Dir.Start_Cluster and 16#FFFF#),\n Size => 0);\n Dot_Dot :=\n (Filename => (1 .. 2 => '.', others => ' '),\n Extension => (others => ' '),\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => True,\n Archive => False),\n Reserved => (others => ASCII.NUL),\n Cluster_H =>\n Unsigned_16\n (Shift_Right\n (Unsigned_32 (Handle.Start_Cluster) and 16#FFFF_0000#, 16)),\n Time => 0,\n Date => 0,\n Cluster_L => Unsigned_16 (Handle.Start_Cluster and 16#FFFF#),\n Size => 0);\n\n Handle.FS.Window (0 .. 31) := To_Data (Dot);\n Handle.FS.Window (32 .. 63) := To_Data (Dot_Dot);\n Handle.FS.Window (64 .. 95) := (others => 0);\n Ret := Handle.FS.Write_Window;\n\n Close (Handle.all);\n\n return Ret;\n end Create_Subdir;\n\n ----------------------\n -- Create_File_Node --\n ----------------------\n\n function Create_File_Node\n (Dir : FAT_Node;\n Name : FAT_Name;\n New_File : out FAT_Node) return Status_Code\n is\n Handle : FAT_Directory_Handle_Access;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n Ret := Allocate_Entry\n (Parent => Handle,\n Name => Name,\n Attributes => (Read_Only => False,\n Hidden => False,\n System_File => False,\n Volume_Label => False,\n Subdirectory => False,\n Archive => True),\n E => New_File);\n\n Close (Handle.all);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Create_File_Node;\n\n -------------------\n -- Delete_Subdir --\n -------------------\n\n function Delete_Subdir\n (Dir : FAT_Node;\n Recursive : Boolean) return Status_Code\n is\n Parent : FAT_Node;\n Handle : FAT_Directory_Handle_Access;\n Ent : FAT_Node;\n Ret : Status_Code;\n\n begin\n Ret := Dir.FAT_Open (Handle);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Ent) = OK loop\n if -Long_Name (Ent) = \".\" then\n null;\n elsif -Long_Name (Ent) = \"..\" then\n Parent := Ent;\n elsif not Recursive then\n return Non_Empty_Directory;\n else\n if Ent.Attributes.Subdirectory then\n Ret := Delete_Subdir (Ent, True);\n else\n Ret := Delete_Entry (Dir, Ent);\n end if;\n\n if Ret /= OK then\n Close (Handle.all);\n\n return Ret;\n end if;\n end if;\n end loop;\n\n Close (Handle.all);\n\n -- Free the clusters associated to the subdirectory\n Ret := Delete_Entry (Parent, Dir);\n\n if Ret /= OK then\n return Ret;\n end if;\n\n return Ret;\n end Delete_Subdir;\n\n ------------------\n -- Delete_Entry --\n ------------------\n\n function Delete_Entry\n (Dir : FAT_Node;\n Ent : FAT_Node) return Status_Code\n is\n Current : Cluster_Type := Ent.Start_Cluster;\n Handle : FAT_Directory_Handle_Access;\n Next : Cluster_Type;\n Child_Ent : FAT_Node;\n Ret : Status_Code;\n Block_Off : Natural;\n\n begin\n -- Mark the entry's cluster chain as available\n loop\n Next := Ent.FS.Get_FAT (Current);\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n end loop;\n\n -- Mark the parent's entry as deleted\n Ret := Dir.FAT_Open (Handle);\n if Ret /= OK then\n return Ret;\n end if;\n\n while Read (Handle.all, Child_Ent) = OK loop\n if Long_Name (Child_Ent) = Long_Name (Ent) then\n Block_Off := Natural\n ((FAT_File_Size (Handle.Current_Index - 1) * 32)\n mod Dir.FS.Block_Size);\n -- Mark the entry as deleted: first basename character set to\n -- 16#E5#\n Handle.FS.Window (Block_Off) := 16#E5#;\n Ret := Handle.FS.Write_Window;\n\n exit;\n end if;\n end loop;\n\n Close (Handle.all);\n\n return Ret;\n end Delete_Entry;\n\n ---------------------\n -- Adjust_Clusters --\n ---------------------\n\n function Adjust_Clusters (Ent : FAT_Node) return Status_Code\n is\n B_Per_Cluster : constant FAT_File_Size :=\n FAT_File_Size (Ent.FS.Blocks_Per_Cluster) *\n Ent.FS.Block_Size;\n Size : FAT_File_Size := Ent.Size;\n Current : Cluster_Type := Ent.Start_Cluster;\n Next : Cluster_Type;\n Ret : Status_Code := OK;\n\n begin\n if Ent.Attributes.Subdirectory then\n -- ??? Do nothing for now\n return OK;\n end if;\n\n loop\n Next := Ent.FS.Get_FAT (Current);\n\n if Size > B_Per_Cluster then\n -- Current cluster is fully used\n Size := Size - B_Per_Cluster;\n elsif Size > 0 or else Current = Ent.Start_Cluster then\n -- Partially used cluster, but the last one\n Size := 0;\n if Next /= LAST_CLUSTER_VALUE then\n Ret := Ent.FS.Set_FAT (Current, LAST_CLUSTER_VALUE);\n end if;\n else\n -- We don't need more clusters\n Ret := Ent.FS.Set_FAT (Current, FREE_CLUSTER_VALUE);\n end if;\n\n exit when Ret /= OK;\n exit when Ent.FS.Is_Last_Cluster (Next);\n Current := Next;\n Size := Size - B_Per_Cluster;\n end loop;\n\n return Ret;\n end Adjust_Clusters;\n\n -------------------------------\n -- Find_Empty_Entry_Sequence --\n -------------------------------\n\n function Find_Empty_Entry_Sequence\n (Parent : access FAT_Directory_Handle;\n Num_Entries : Natural) return Entry_Index\n is\n Status : Status_Code;\n D_Entry : FAT_Directory_Entry;\n Sequence : Natural := 0;\n Ret : Entry_Index;\n Cluster : Cluster_Type := Parent.Start_Cluster;\n Block : Block_Offset := Cluster_To_Block (Parent.FS.all, Cluster);\n begin\n Parent.Current_Index := 0;\n loop\n Status := Next_Entry\n (Parent.FS,\n Current_Cluster => Cluster,\n Current_Block => Block,\n Current_Index => Parent.Current_Index,\n DEntry => D_Entry);\n\n if Status /= OK then\n return Null_Index;\n end if;\n\n if D_Entry.Attributes = VFAT_Directory_Entry_Attribute then\n if Sequence = 0 then\n -- Parent.Current_Index points to the next unread value.\n -- So the just read entry is at Parent.Current_Index - 1\n Ret := Parent.Current_Index - 1;\n end if;\n\n Sequence := Sequence + 1;\n\n elsif Character'Pos (D_Entry.Filename (1)) = 16#E5# then\n -- A deleted entry has been found\n if Sequence >= Num_Entries then\n return Ret;\n else\n Sequence := 0;\n end if;\n\n else\n Sequence := 0;\n end if;\n end loop;\n end Find_Empty_Entry_Sequence;\n\n --------------------\n -- Allocate_Entry --\n --------------------\n\n function Allocate_Entry\n (Parent : access FAT_Directory_Handle;\n Name : FAT_Name;\n Attributes : FAT_Directory_Entry_Attribute;\n E : out FAT_Node) return Status_Code\n is\n subtype Short_Name is String (1 .. 8);\n subtype Extension is String (1 .. 3);\n\n function Is_Legal_Character (C : Character) return Boolean\n is (C in 'A' .. 'Z'\n or else C in '0' .. '9'\n or else C = '!'\n or else C = '#'\n or else C = '$'\n or else C = '%'\n or else C = '&'\n or else C = '''\n or else C = '('\n or else C = ')'\n or else C = '-'\n or else C = '@'\n or else C = '^'\n or else C = '_'\n or else C = '`'\n or else C = '{'\n or else C = '}'\n or else C = '~');\n\n Block_Off : Natural;\n Status : Status_Code;\n DEntry : FAT_Node;\n SName : Short_Name := (others => ' ');\n SExt : Extension := (others => ' ');\n Index : Entry_Index;\n\n -- Retrieve the number of VFAT entries that are needed, plus one for\n -- the regular FAT entry.\n N_Entries : Natural := Get_Num_VFAT_Entries (Name) + 1;\n Bytes : Entry_Data;\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension);\n -- Translates a long name into short 8.3 name\n -- If the long name is mixed or lower case. then 8.3 will be uppercased\n -- If the long name contains characters not allowed in an 8.3 name, then\n -- the name is stripped of invalid characters such as space and extra\n -- periods. Other unknown characters are changed to underscores.\n -- The stripped name is then truncated, followed by a ~1. Inc_SName\n -- below will increase the digit number in case there's overloaded 8.3\n -- names.\n -- If the long name is longer than 8.3, then ~1 suffix will also be\n -- used.\n\n function To_Upper (C : Character) return Character is\n (if C in 'a' .. 'z'\n then Character'Val\n (Character'Pos (C) + Character'Pos ('A') - Character'Pos ('a'))\n else C);\n\n function Value (S : String) return Natural;\n -- For a positive int represented in S, returns its value\n\n procedure Inc_SName (SName : in out String);\n -- Increment the suffix of the short FAT name\n -- e.g.:\n -- ABCDEFGH => ABCDEF~1\n -- ABC => ABC~1\n -- ABC~9 => ABC~10\n -- ABCDEF~9 => ABCDE~10\n\n procedure To_WString\n (S : FAT_Name;\n Idx : in out Natural;\n WS : in out Wide_String);\n -- Dumps S (Idx .. Idx + WS'Length - 1) into WS and increments Idx\n\n -----------\n -- Value --\n -----------\n\n function Value (S : String) return Natural\n is\n Val : constant String := Trim (S);\n Digit : Natural;\n Ret : Natural := 0;\n begin\n for J in Val'Range loop\n Digit := Character'Pos (Val (J)) - Character'Pos ('0');\n Ret := Ret * 10 + Digit;\n end loop;\n\n return Ret;\n end Value;\n\n -------------------\n -- To_Short_Name --\n -------------------\n\n procedure To_Short_Name\n (Name : FAT_Name;\n SName : out Short_Name;\n Ext : out Extension)\n is\n S_Idx : Natural := 0;\n Add_Tilde : Boolean := False;\n Last : Natural := Name.Len;\n\n begin\n -- Copy the file extension\n\n Ext := (others => ' ');\n\n for J in reverse 1 .. Name.Len loop\n if Name.Name (J) = '.' then\n if J = Name.Len then\n -- Take care of names ending with a '.' (e.g. no extension,\n -- the final '.' is part of the basename)\n Last := J;\n Ext := (others => ' ');\n else\n Last := J - 1;\n S_Idx := Ext'First;\n\n for K in J + 1 .. Name.Len loop\n Ext (S_Idx) := To_Upper (Name.Name (K));\n S_Idx := S_Idx + 1;\n -- In case the extension is more than 3 characters, we\n -- keep the first 3 ones.\n exit when S_Idx > Ext'Last;\n end loop;\n end if;\n\n exit;\n end if;\n end loop;\n\n S_Idx := 0;\n SName := (others => ' ');\n\n for J in 1 .. Last loop\n exit when Add_Tilde and then S_Idx >= 6;\n exit when not Add_Tilde and then S_Idx = 8;\n\n if Name.Name (J) in 'a' .. 'z' then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := To_Upper (Name.Name (J));\n\n elsif Is_Legal_Character (Name.Name (J)) then\n S_Idx := S_Idx + 1;\n SName (S_Idx) := Name.Name (J);\n\n elsif Name.Name (J) = '.'\n or else Name.Name (J) = ' '\n then\n -- dots that are not used as extension delimiters are invalid\n -- in FAT short names and ignored in long names to short names\n -- translation\n Add_Tilde := True;\n\n else\n -- Any other character is translated as '_'\n Add_Tilde := True;\n S_Idx := S_Idx + 1;\n SName (S_Idx) := '_';\n end if;\n end loop;\n\n if Add_Tilde then\n if S_Idx >= 6 then\n SName (7 .. 8) := \"~1\";\n else\n SName (S_Idx + 1 .. S_Idx + 2) := \"~1\";\n end if;\n end if;\n end To_Short_Name;\n\n ---------------\n -- Inc_SName --\n ---------------\n\n procedure Inc_SName (SName : in out String)\n is\n Idx : Natural := 0;\n Num : Natural := 0;\n\n begin\n for J in reverse SName'Range loop\n if Idx = 0 then\n if SName (J) = ' ' then\n null;\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n else\n SName (SName'Last - 1 .. SName'Last) := \"~1\";\n\n return;\n end if;\n\n elsif SName (J) in '0' .. '9' then\n Idx := J;\n\n elsif SName (J) = '~' then\n Num := Value (SName (Idx .. SName'Last)) + 1;\n -- make Idx point to '~'\n Idx := J;\n\n declare\n N_Suffix : String := Natural'Image (Num);\n begin\n N_Suffix (N_Suffix'First) := '~';\n\n if Idx + N_Suffix'Length - 1 > SName'Last then\n SName (SName'Last - N_Suffix'Length + 1 .. SName'Last) :=\n N_Suffix;\n else\n SName (Idx .. Idx + N_Suffix'Length - 1) := N_Suffix;\n end if;\n\n return;" + }, + { + "function_def": "function To_Disk_Parameter is new Ada.Unchecked_Conversion", + "function_body": "(Disk_Parameter_Block, FAT_Disk_Parameter);\n\n subtype FSInfo_Block is Block (0 .. 11);\n function To_FSInfo is new Ada.Unchecked_Conversion\n (FSInfo_Block, FAT_FS_Info);\n\n begin\n FS.Window_Block := 16#FFFF_FFFF#;\n Status := FS.Ensure_Block (0);\n\n if Status /= OK then\n return;\n end if;\n\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.Disk_Parameters :=\n To_Disk_Parameter (FS.Window (0 .. 91));\n\n if FS.Version = FAT32 then\n Status :=\n FS.Ensure_Block (Block_Offset (FS.FSInfo_Block_Number));\n\n if Status /= OK then\n return;\n end if;\n\n -- Check the generic FAT block signature\n if FS.Window (510 .. 511) /= (16#55#, 16#AA#) then\n Status := No_Filesystem;\n return;\n end if;\n\n FS.FSInfo :=\n To_FSInfo (FS.Window (16#1E4# .. 16#1EF#));\n FS.FSInfo_Changed := False;\n end if;\n\n declare\n FAT_Size_In_Block : constant Unsigned_32 :=\n FS.FAT_Table_Size_In_Blocks *\n Unsigned_32 (FS.Number_Of_FATs);\n Root_Dir_Size : Block_Offset;\n begin\n FS.FAT_Addr := Block_Offset (FS.Reserved_Blocks);\n FS.Data_Area := FS.FAT_Addr + Block_Offset (FAT_Size_In_Block);\n\n if FS.Version = FAT16 then\n -- Add space for the root directory\n FS.Root_Dir_Area := FS.Data_Area;\n Root_Dir_Size :=\n (Block_Offset (FS.FAT16_Root_Dir_Num_Entries) * 32 +\n Block_Offset (FS.Block_Size) - 1) /\n Block_Offset (FS.Block_Size);\n -- Align on clusters\n Root_Dir_Size :=\n ((Root_Dir_Size + FS.Blocks_Per_Cluster - 1) /\n FS.Blocks_Per_Cluster) *\n FS.Blocks_Per_Cluster;\n\n FS.Data_Area := FS.Data_Area + Root_Dir_Size;\n end if;\n\n FS.Num_Clusters :=\n Cluster_Type\n ((FS.Total_Number_Of_Blocks - Unsigned_32 (FS.Data_Area)) /\n Unsigned_32 (FS.Blocks_Per_Cluster));" + }, + { + "function_def": "procedure List (Path : String);", + "function_body": "----------\n -- List --\n ----------\n\n procedure List (Path : String) is\n DD : Directory_Descriptor;\n Status : Status_Code;\n First : Boolean := True;\n begin\n Status := Open (DD, Path);\n if Status /= OK then\n Put (\"Cannot open directory '\" & Path & \"': \" & Status'Img);\n return;\n end if;\n\n if Recursive then\n Put_Line (Path & \":\");\n end if;\n\n loop\n declare\n Ent : constant Directory_Entry := Read (DD);\n begin\n exit when Ent = Invalid_Dir_Entry;\n\n if not Ent.Hidden or else Show_All then\n if First then\n Put (Ent.Name);\n First := False;\n else\n Put (\" \" & Ent.Name);\n end if;\n end if;" + }, + { + "function_def": "procedure Display_File (Path : String);", + "function_body": "------------------\n -- Display_File --\n ------------------\n\n procedure Display_File (Path : String) is\n FD : File_Descriptor;\n Status : Status_Code;\n Data : String (1 .. 512);\n Amount : File_Size;\n begin\n Status := Open (FD, Path, Read_Only);\n if Status /= OK then\n Put_Line (\"Cannot open file '\" & Path & \"': \" & Status'Img);\n return;\n end if;\n\n loop\n Amount := Read (FD, Data'Address, Data'Length);\n exit when Amount = 0;\n Put (Data (Data'First .. Data'First + Natural (Amount) - 1));\n end loop;\n Close (FD);\n end Display_File;\n\n begin\n loop\n declare\n Arg : constant String := Args.Next;\n begin\n if Arg'Length = 0 then\n return;\n end if;\n Display_File (Arg);" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out SPI_Port'Class) is\n begin\n if This'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2ENR.SAI1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n pragma Assert (This'Address = SAI_Base);\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address /= SAI_Base then\n raise Unknown_Device;\n end if;\n\n Input_Selector := RCC_Periph.DCKCFGR.SAI1ASRC;\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DCKCFGR.PLLIS2DIVQ + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDIOEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDIORST := True;\n RCC_Periph.APB2RSTR.SDIORST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDIO_Clock_Source)\n is\n Src_Val : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address /= SDIO_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DCKCFGR.SDMMCSEL := Src_Val;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2ENR.SDMMC2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.APB2RSTR.SDMMC2RST := True;\n RCC_Periph.APB2RSTR.SDMMC2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n Sel_Value : constant Boolean := Src = Src_Sysclk;\n begin\n if This.Periph.all'Address = SDMMC1_Base then\n RCC_Periph.DKCFGR2.SDMMC1SEL := Sel_Value;\n elsif This.Periph.all'Address = SDMMC2_Base then\n RCC_Periph.DKCFGR2.SDMMC2SEL := Sel_Value;\n else\n raise Unknown_Device;\n end if;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant\n UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant\n UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2ENR.USART1EN := True;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1ENR.USART2EN := True;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1ENR.USART3EN := True;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1ENR.UART4EN := True;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1ENR.UART5EN := True;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2ENR.USART6EN := True;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1ENR.UART7ENR := True;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1ENR.UART8ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out USART) is\n begin\n if This.Periph.all'Address = USART1_Base then\n RCC_Periph.APB2RSTR.USART1RST := True;\n RCC_Periph.APB2RSTR.USART1RST := False;\n elsif This.Periph.all'Address = USART2_Base then\n RCC_Periph.APB1RSTR.UART2RST := True;\n RCC_Periph.APB1RSTR.UART2RST := False;\n elsif This.Periph.all'Address = USART3_Base then\n RCC_Periph.APB1RSTR.UART3RST := True;\n RCC_Periph.APB1RSTR.UART3RST := False;\n elsif This.Periph.all'Address = UART4_Base then\n RCC_Periph.APB1RSTR.UART4RST := True;\n RCC_Periph.APB1RSTR.UART4RST := False;\n elsif This.Periph.all'Address = UART5_Base then\n RCC_Periph.APB1RSTR.UART5RST := True;\n RCC_Periph.APB1RSTR.UART5RST := False;\n elsif This.Periph.all'Address = USART6_Base then\n RCC_Periph.APB2RSTR.USART6RST := True;\n RCC_Periph.APB2RSTR.USART6RST := False;\n elsif This.Periph.all'Address = UART7_Base then\n RCC_Periph.APB1RSTR.UART7RST := True;\n RCC_Periph.APB1RSTR.UART7RST := False;\n elsif This.Periph.all'Address = UART8_Base then\n RCC_Periph.APB1RSTR.UART8RST := True;\n RCC_Periph.APB1RSTR.UART8RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base\n or else\n This.Periph.all'Address = I2S2ext_Base\n then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base\n or else\n This.Periph.all'Address = I2S3ext_Base\n then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Reset_All_ADC_Units is", + "function_body": "begin\n RCC_Periph.APB2RSTR.ADCRST := True;\n RCC_Periph.APB2RSTR.ADCRST := False;\n end Reset_All_ADC_Units;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out Digital_To_Analog_Converter)\n is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1ENR.DACEN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out Digital_To_Analog_Converter) is\n pragma Unreferenced (This);\n begin\n RCC_Periph.APB1RSTR.DACRST := True;\n RCC_Periph.APB1RSTR.DACRST := False;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n-- procedure Enable_Clock (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2ENR.USART1EN := True;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1ENR.USART2EN := True;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1ENR.USART3EN := True;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1ENR.UART4EN := True;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1ENR.UART5EN := True;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2ENR.USART6EN := True;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1ENR.UART7ENR := True;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1ENR.UART8ENR := True;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n-- procedure Reset (This : aliased in out USART) is\n-- begin\n-- if This'Address = USART1_Base then\n-- RCC_Periph.APB2RSTR.USART1RST := True;\n-- RCC_Periph.APB2RSTR.USART1RST := False;\n-- elsif This'Address = USART2_Base then\n-- RCC_Periph.APB1RSTR.UART2RST := True;\n-- RCC_Periph.APB1RSTR.UART2RST := False;\n-- elsif This'Address = USART3_Base then\n-- RCC_Periph.APB1RSTR.UART3RST := True;\n-- RCC_Periph.APB1RSTR.UART3RST := False;\n-- elsif This'Address = UART4_Base then\n-- RCC_Periph.APB1RSTR.UART4RST := True;\n-- RCC_Periph.APB1RSTR.UART4RST := False;\n-- elsif This'Address = UART5_Base then\n-- RCC_Periph.APB1RSTR.UART5RST := True;\n-- RCC_Periph.APB1RSTR.UART5RST := False;\n-- elsif This'Address = USART6_Base then\n-- RCC_Periph.APB2RSTR.USART6RST := True;\n-- RCC_Periph.APB2RSTR.USART6RST := False;\n-- elsif This'Address = UART7_Base then\n-- RCC_Periph.APB1RSTR.UART7RST := True;\n-- RCC_Periph.APB1RSTR.UART7RST := False;\n-- elsif This'Address = UART8_Base then\n-- RCC_Periph.APB1RSTR.UART8RST := True;\n-- RCC_Periph.APB1RSTR.UART8RST := False;\n-- else\n-- raise Unknown_Device;\n-- end if;\n-- end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1ENR.DMA1EN := True;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1ENR.DMA2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : aliased in out DMA_Controller) is\n begin\n if This'Address = STM32_SVD.DMA1_Base then\n RCC_Periph.AHB1RSTR.DMA1RST := True;\n RCC_Periph.AHB1RSTR.DMA1RST := False;\n elsif This'Address = STM32_SVD.DMA2_Base then\n RCC_Periph.AHB1RSTR.DMA2RST := True;\n RCC_Periph.AHB1RSTR.DMA2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ----------------\n -- As_Port_Id --\n ----------------\n\n function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is\n begin\n if Port.Periph.all'Address = I2C1_Base then\n return I2C_Id_1;\n elsif Port.Periph.all'Address = I2C2_Base then\n return I2C_Id_2;\n elsif Port.Periph.all'Address = I2C3_Base then\n return I2C_Id_3;\n elsif Port.Periph.all'Address = I2C4_Base then\n return I2C_Id_4;\n else\n raise Unknown_Device;\n end if;\n end As_Port_Id;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : aliased I2C_Port'Class) is\n begin\n Enable_Clock (As_Port_Id (This));\n end Enable_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1ENR.I2C1EN := True;\n when I2C_Id_2 =>\n RCC_Periph.APB1ENR.I2C2EN := True;\n when I2C_Id_3 =>\n RCC_Periph.APB1ENR.I2C3EN := True;\n when I2C_Id_4 =>\n RCC_Periph.APB1ENR.I2C4EN := True;\n end case;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port'Class) is\n begin\n Reset (As_Port_Id (This));\n end Reset;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : I2C_Port_Id) is\n begin\n case This is\n when I2C_Id_1 =>\n RCC_Periph.APB1RSTR.I2C1RST := True;\n RCC_Periph.APB1RSTR.I2C1RST := False;\n when I2C_Id_2 =>\n RCC_Periph.APB1RSTR.I2C2RST := True;\n RCC_Periph.APB1RSTR.I2C2RST := False;\n when I2C_Id_3 =>\n RCC_Periph.APB1RSTR.I2C3RST := True;\n RCC_Periph.APB1RSTR.I2C3RST := False;\n when I2C_Id_4 =>\n RCC_Periph.APB1RSTR.I2C4RST := True;\n RCC_Periph.APB1RSTR.I2C4RST := False;\n end case;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI4ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : SPI_Port'Class) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2ENR.SPI1EN := True;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1ENR.SPI2EN := True;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1ENR.SPI3EN := True;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2ENR.SPI5ENR := True;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2ENR.SPI6ENR := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out I2S_Port) is\n begin\n if This.Periph.all'Address = SPI1_Base then\n RCC_Periph.APB2RSTR.SPI1RST := True;\n RCC_Periph.APB2RSTR.SPI1RST := False;\n elsif This.Periph.all'Address = SPI2_Base then\n RCC_Periph.APB1RSTR.SPI2RST := True;\n RCC_Periph.APB1RSTR.SPI2RST := False;\n elsif This.Periph.all'Address = SPI3_Base then\n RCC_Periph.APB1RSTR.SPI3RST := True;\n RCC_Periph.APB1RSTR.SPI3RST := False;\n elsif This.Periph.all'Address = SPI4_Base then\n RCC_Periph.APB2RSTR.SPI4RST := True;\n RCC_Periph.APB2RSTR.SPI4RST := False;\n elsif This.Periph.all'Address = SPI5_Base then\n RCC_Periph.APB2RSTR.SPI5RST := True;\n RCC_Periph.APB2RSTR.SPI5RST := False;\n elsif This.Periph.all'Address = SPI6_Base then\n RCC_Periph.APB2RSTR.SPI6RST := True;\n RCC_Periph.APB2RSTR.SPI6RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2ENR.TIM1EN := True;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1ENR.TIM2EN := True;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1ENR.TIM3EN := True;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1ENR.TIM4EN := True;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1ENR.TIM5EN := True;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1ENR.TIM6EN := True;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1ENR.TIM7EN := True;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2ENR.TIM8EN := True;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2ENR.TIM9EN := True;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2ENR.TIM10EN := True;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2ENR.TIM11EN := True;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1ENR.TIM12EN := True;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1ENR.TIM13EN := True;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1ENR.TIM14EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out Timer) is\n begin\n if This'Address = TIM1_Base then\n RCC_Periph.APB2RSTR.TIM1RST := True;\n RCC_Periph.APB2RSTR.TIM1RST := False;\n elsif This'Address = TIM2_Base then\n RCC_Periph.APB1RSTR.TIM2RST := True;\n RCC_Periph.APB1RSTR.TIM2RST := False;\n elsif This'Address = TIM3_Base then\n RCC_Periph.APB1RSTR.TIM3RST := True;\n RCC_Periph.APB1RSTR.TIM3RST := False;\n elsif This'Address = TIM4_Base then\n RCC_Periph.APB1RSTR.TIM4RST := True;\n RCC_Periph.APB1RSTR.TIM4RST := False;\n elsif This'Address = TIM5_Base then\n RCC_Periph.APB1RSTR.TIM5RST := True;\n RCC_Periph.APB1RSTR.TIM5RST := False;\n elsif This'Address = TIM6_Base then\n RCC_Periph.APB1RSTR.TIM6RST := True;\n RCC_Periph.APB1RSTR.TIM6RST := False;\n elsif This'Address = TIM7_Base then\n RCC_Periph.APB1RSTR.TIM7RST := True;\n RCC_Periph.APB1RSTR.TIM7RST := False;\n elsif This'Address = TIM8_Base then\n RCC_Periph.APB2RSTR.TIM8RST := True;\n RCC_Periph.APB2RSTR.TIM8RST := False;\n elsif This'Address = TIM9_Base then\n RCC_Periph.APB2RSTR.TIM9RST := True;\n RCC_Periph.APB2RSTR.TIM9RST := False;\n elsif This'Address = TIM10_Base then\n RCC_Periph.APB2RSTR.TIM10RST := True;\n RCC_Periph.APB2RSTR.TIM10RST := False;\n elsif This'Address = TIM11_Base then\n RCC_Periph.APB2RSTR.TIM11RST := True;\n RCC_Periph.APB2RSTR.TIM11RST := False;\n elsif This'Address = TIM12_Base then\n RCC_Periph.APB1RSTR.TIM12RST := True;\n RCC_Periph.APB1RSTR.TIM12RST := False;\n elsif This'Address = TIM13_Base then\n RCC_Periph.APB1RSTR.TIM13RST := True;\n RCC_Periph.APB1RSTR.TIM13RST := False;\n elsif This'Address = TIM14_Base then\n RCC_Periph.APB1RSTR.TIM14RST := True;\n RCC_Periph.APB1RSTR.TIM14RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2ENR.SAI1EN := True;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2ENR.SAI2EN := True;\n else\n raise Unknown_Device;\n end if;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SAI_Port)\n is\n begin\n if This'Address = SAI1_Base then\n RCC_Periph.APB2RSTR.SAI1RST := True;\n RCC_Periph.APB2RSTR.SAI1RST := False;\n elsif This'Address = SAI2_Base then\n RCC_Periph.APB2RSTR.SAI2RST := True;\n RCC_Periph.APB2RSTR.SAI2RST := False;\n else\n raise Unknown_Device;\n end if;\n end Reset;\n\n ---------------------\n -- Get_Input_Clock --\n ---------------------\n\n function Get_Input_Clock (Periph : SAI_Port) return UInt32\n is\n Input_Selector : UInt2;\n VCO_Input : UInt32;\n SAI_First_Level : UInt32;\n begin\n if Periph'Address = SAI1_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI1SEL;\n elsif Periph'Address = SAI2_Base then\n Input_Selector := RCC_Periph.DKCFGR1.SAI2SEL;\n else\n raise Unknown_Device;\n end if;\n\n\n -- This driver doesn't support external source clock\n if Input_Selector > 1 then\n raise Constraint_Error\n with \"External PLL SAI source clock unsupported\";\n end if;\n\n if not RCC_Periph.PLLCFGR.PLLSRC then\n -- PLLSAI SRC is HSI\n VCO_Input := HSI_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n else\n -- PLLSAI SRC is HSE\n VCO_Input := HSE_VALUE / UInt32 (RCC_Periph.PLLCFGR.PLLM);\n end if;\n\n if Input_Selector = 0 then\n -- PLLSAI is the clock source\n\n -- VCO out = VCO in & PLLSAIN\n -- SAI firstlevel = VCO out / PLLSAIQ\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIN) /\n UInt32 (RCC_Periph.PLLSAICFGR.PLLSAIQ);\n\n -- SAI frequency is SAI First level / PLLSAIDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLSAIDIVQ);\n\n else\n -- PLLI2S as clock source\n SAI_First_Level :=\n VCO_Input * UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SN) /\n UInt32 (RCC_Periph.PLLI2SCFGR.PLLI2SQ);\n -- SAI frequency is SAI First level / PLLI2SDIVQ\n return SAI_First_Level / UInt32 (RCC_Periph.DKCFGR1.PLLI2SDIV + 1);\n end if;\n end Get_Input_Clock;\n\n ------------------\n -- Enable_Clock --\n ------------------\n\n procedure Enable_Clock (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2ENR.SDMMC1EN := True;\n end Enable_Clock;\n\n -----------\n -- Reset --\n -----------\n\n procedure Reset (This : in out SDMMC_Controller)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.APB2RSTR.SDMMC1RST := True;\n RCC_Periph.APB2RSTR.SDMMC1RST := False;\n end Reset;\n\n ----------------------\n -- Set_Clock_Source --\n ----------------------\n\n procedure Set_Clock_Source\n (This : in out SDMMC_Controller;\n Src : SDMMC_Clock_Source)\n is\n begin\n if This.Periph.all'Address /= SDMMC_Base then\n raise Unknown_Device;\n end if;\n\n RCC_Periph.DKCFGR2.SDMMCSEL := Src = Src_Sysclk;\n\n case Src is\n when Src_Sysclk =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, System_Clock_Frequencies.SYSCLK);\n when Src_48Mhz =>\n STM32.SDMMC.Set_Clk_Src_Speed\n (This, 48_000_000);\n end case;\n end Set_Clock_Source;\n\n ------------------------------\n -- System_Clock_Frequencies --\n ------------------------------\n\n function System_Clock_Frequencies return RCC_System_Clocks\n is\n Source : constant UInt2 := RCC_Periph.CFGR.SWS;\n Result : RCC_System_Clocks;\n begin\n Result.I2SCLK := 0;\n\n case Source is\n when 0 =>\n -- HSI as source\n Result.SYSCLK := HSI_VALUE;\n when 1 =>\n -- HSE as source\n Result.SYSCLK := HSE_VALUE;\n when 2 =>\n -- PLL as source\n declare\n HSE_Source : constant Boolean := RCC_Periph.PLLCFGR.PLLSRC;\n Pllm : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLM);\n Plln : constant UInt32 :=\n UInt32 (RCC_Periph.PLLCFGR.PLLN);\n Pllp : constant UInt32 :=\n (UInt32 (RCC_Periph.PLLCFGR.PLLP) + 1) * 2;\n Pllvco : UInt32;\n begin\n if not HSE_Source then\n Pllvco := HSI_VALUE;\n else\n Pllvco := HSE_VALUE;\n end if;\n\n Pllvco := Pllvco / Pllm;\n\n Result.I2SCLK := Pllvco;\n\n Pllvco := Pllvco * Plln;\n\n Result.SYSCLK := Pllvco / Pllp;" + }, + { + "function_def": "procedure Disable", + "function_body": "(This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.EN1 := False;\n when Channel_2 =>\n This.CR.EN2 := False;\n end case;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.EN1;\n when Channel_2 =>\n return This.CR.EN2;\n end case;\n end Enabled;\n\n ----------------\n -- Set_Output --\n ----------------\n\n procedure Set_Output\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Channel is\n\n when Channel_1 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R1.DACC1DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R1.DACC1DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n when Channel_2 =>\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12L2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12R2.DACC2DHR :=\n UInt12 (Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8R2.DACC2DHR := UInt8 (Value and Max_8bit_Resolution);\n end case;\n\n end case;\n end Set_Output;\n\n ------------------------------------\n -- Trigger_Conversion_By_Software --\n ------------------------------------\n\n procedure Trigger_Conversion_By_Software\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SWTRIGR.SWTRIG.Arr (1) := True; -- cleared by hardware\n when Channel_2 =>\n This.SWTRIGR.SWTRIG.Arr (2) := True; -- cleared by hardware\n end case;\n end Trigger_Conversion_By_Software;\n\n ----------------------------\n -- Converted_Output_Value --\n ----------------------------\n\n function Converted_Output_Value\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return UInt32\n is\n begin\n case Channel is\n when Channel_1 =>\n return UInt32 (This.DOR1.DACC1DOR);\n when Channel_2 =>\n return UInt32 (This.DOR2.DACC2DOR);\n end case;\n end Converted_Output_Value;\n\n ------------------------------\n -- Set_Dual_Output_Voltages --\n ------------------------------\n\n procedure Set_Dual_Output_Voltages\n (This : in out Digital_To_Analog_Converter;\n Channel_1_Value : UInt32;\n Channel_2_Value : UInt32;\n Resolution : DAC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n case Resolution is\n when DAC_Resolution_12_Bits =>\n case Alignment is\n when Left_Aligned =>\n This.DHR12LD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12LD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n when Right_Aligned =>\n This.DHR12RD.DACC1DHR :=\n UInt12 (Channel_1_Value and Max_12bit_Resolution);\n This.DHR12RD.DACC2DHR :=\n UInt12 (Channel_2_Value and Max_12bit_Resolution);\n end case;\n when DAC_Resolution_8_Bits =>\n This.DHR8RD.DACC1DHR :=\n UInt8 (Channel_1_Value and Max_8bit_Resolution);\n This.DHR8RD.DACC2DHR :=\n UInt8 (Channel_2_Value and Max_8bit_Resolution);\n end case;\n end Set_Dual_Output_Voltages;\n\n ---------------------------------\n -- Converted_Dual_Output_Value --\n ---------------------------------\n\n function Converted_Dual_Output_Value (This : Digital_To_Analog_Converter)\n return Dual_Channel_Output\n is\n Result : Dual_Channel_Output;\n begin\n Result.Channel_1_Data := UInt16 (This.DOR1.DACC1DOR);\n Result.Channel_2_Data := UInt16 (This.DOR2.DACC2DOR);\n return Result;\n end Converted_Dual_Output_Value;\n\n --------------------------\n -- Enable_Output_Buffer --\n --------------------------\n\n procedure Enable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := True;\n when Channel_2 =>\n This.CR.BOFF2 := True;\n end case;\n end Enable_Output_Buffer;\n\n ---------------------------\n -- Disable_Output_Buffer --\n ---------------------------\n\n procedure Disable_Output_Buffer\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.BOFF1 := False;\n when Channel_2 =>\n This.CR.BOFF2 := False;\n end case;\n end Disable_Output_Buffer;\n\n ---------------------------\n -- Output_Buffer_Enabled --\n ---------------------------\n\n function Output_Buffer_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.BOFF1;\n when Channel_2 =>\n return This.CR.BOFF2;\n end case;\n end Output_Buffer_Enabled;\n\n --------------------\n -- Select_Trigger --\n --------------------\n\n procedure Select_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Trigger : External_Event_Trigger_Selection)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TSEL1 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n when Channel_2 =>\n This.CR.TSEL2 :=\n External_Event_Trigger_Selection'Enum_Rep (Trigger);\n end case;\n end Select_Trigger;\n\n -----------------------\n -- Trigger_Selection --\n -----------------------\n\n function Trigger_Selection\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return External_Event_Trigger_Selection\n is\n begin\n case Channel is\n when Channel_1 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL1);\n when Channel_2 =>\n return External_Event_Trigger_Selection'Val (This.CR.TSEL2);\n end case;\n end Trigger_Selection;\n\n --------------------\n -- Enable_Trigger --\n --------------------\n\n procedure Enable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := True;\n when Channel_2 =>\n This.CR.TEN2 := True;\n end case;\n end Enable_Trigger;\n\n ---------------------\n -- Disable_Trigger --\n ---------------------\n\n procedure Disable_Trigger\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.TEN1 := False;\n when Channel_2 =>\n This.CR.TEN2 := False;\n end case;\n end Disable_Trigger;\n\n ---------------------\n -- Trigger_Enabled --\n ---------------------\n\n function Trigger_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.TEN1;\n when Channel_2 =>\n return This.CR.TEN2;\n end case;\n end Trigger_Enabled;\n\n ----------------\n -- Enable_DMA --\n ----------------\n\n procedure Enable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := True;\n when Channel_2 =>\n This.CR.DMAEN2 := True;\n end case;\n end Enable_DMA;\n\n -----------------\n -- Disable_DMA --\n -----------------\n\n procedure Disable_DMA\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.CR.DMAEN1 := False;\n when Channel_2 =>\n This.CR.DMAEN2 := False;\n end case;\n end Disable_DMA;\n\n -----------------\n -- DMA_Enabled --\n -----------------\n\n function DMA_Enabled\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Boolean\n is\n begin\n case Channel is\n when Channel_1 =>\n return This.CR.DMAEN1;\n when Channel_2 =>\n return This.CR.DMAEN2;\n end case;\n end DMA_Enabled;\n\n ------------\n -- Status --\n ------------\n\n function Status\n (This : Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n return Boolean\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n return This.SR.DMAUDR1;\n when DMA_Underrun_Channel_2 =>\n return This.SR.DMAUDR2;\n end case;\n end Status;\n\n ------------------\n -- Clear_Status --\n ------------------\n\n procedure Clear_Status\n (This : in out Digital_To_Analog_Converter;\n Flag : DAC_Status_Flag)\n is\n begin\n case Flag is\n when DMA_Underrun_Channel_1 =>\n This.SR.DMAUDR1 := True; -- set to 1 to clear\n when DMA_Underrun_Channel_2 =>\n This.SR.DMAUDR2 := True; -- set to 1 to clear\n end case;\n end Clear_Status;\n\n -----------------------\n -- Enable_Interrupts --\n -----------------------\n\n procedure Enable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := True;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := True;\n end case;\n end Enable_Interrupts;\n\n ------------------------\n -- Disable_Interrupts --\n ------------------------\n\n procedure Disable_Interrupts\n (This : in out Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n This.CR.DMAUDRIE1 := False;\n when DMA_Underrun_Channel_2 =>\n This.CR.DMAUDRIE2 := False;\n end case;\n end Disable_Interrupts;\n\n -----------------------\n -- Interrupt_Enabled --\n -----------------------\n\n function Interrupt_Enabled\n (This : Digital_To_Analog_Converter;\n Source : DAC_Interrupts)\n return Boolean\n is\n begin\n case Source is\n when DMA_Underrun_Channel_1 =>\n return This.CR.DMAUDRIE1;\n when DMA_Underrun_Channel_2 =>\n return This.CR.DMAUDRIE2;\n end case;\n end Interrupt_Enabled;\n\n ----------------------\n -- Interrupt_Source --\n ----------------------\n\n function Interrupt_Source\n (This : Digital_To_Analog_Converter)\n return DAC_Interrupts\n is\n begin\n if This.CR.DMAUDRIE1 then\n return DMA_Underrun_Channel_1;\n else\n return DMA_Underrun_Channel_2;\n end if;\n end Interrupt_Source;\n\n -----------------------------\n -- Clear_Interrupt_Pending --\n -----------------------------\n\n procedure Clear_Interrupt_Pending\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n is\n begin\n case Channel is\n when Channel_1 =>\n This.SR.DMAUDR1 := False;\n when Channel_2 =>\n This.SR.DMAUDR2 := False;\n end case;\n end Clear_Interrupt_Pending;\n\n ----------------------------\n -- Select_Wave_Generation --\n ----------------------------\n\n procedure Select_Wave_Generation\n (This : in out Digital_To_Analog_Converter;\n Channel : DAC_Channel;\n Selection : Wave_Generation)\n is\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Noise_Wave_Mask_Selection, Target => UInt4);\n\n function As_UInt4 is new Ada.Unchecked_Conversion\n (Source => Triangle_Wave_Amplitude_Selection, Target => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n This.CR.WAVE1 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n when Channel_2 =>\n This.CR.WAVE2 :=\n Wave_Generation_Selection'Enum_Rep (Selection.Kind);\n end case;\n\n case Selection.Kind is\n\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Mask);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Mask);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n This.CR.MAMP1 := As_UInt4 (Selection.Amplitude);\n when Channel_2 =>\n This.CR.MAMP2 := As_UInt4 (Selection.Amplitude);\n end case;\n\n end case;\n end Select_Wave_Generation;\n\n ------------------------------\n -- Selected_Wave_Generation --\n ------------------------------\n\n function Selected_Wave_Generation\n (This : Digital_To_Analog_Converter;\n Channel : DAC_Channel)\n return Wave_Generation\n is\n Kind : Wave_Generation_Selection;\n\n function As_Mask is new Ada.Unchecked_Conversion\n (Target => Noise_Wave_Mask_Selection, Source => UInt4);\n\n function As_Amplitude is new Ada.Unchecked_Conversion\n (Target => Triangle_Wave_Amplitude_Selection, Source => UInt4);\n\n begin\n case Channel is\n when Channel_1 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE1);\n when Channel_2 =>\n Kind := Wave_Generation_Selection'Val (This.CR.WAVE2);\n end case;\n declare\n Result : Wave_Generation (Kind);\n begin\n case Kind is\n when No_Wave_Generation =>\n null;\n\n when Noise_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Mask := As_Mask (This.CR.MAMP1);\n when Channel_2 =>\n Result.Mask := As_Mask (This.CR.MAMP2);\n end case;\n\n when Triangle_Wave =>\n case Channel is\n when Channel_1 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP1);\n when Channel_2 =>\n Result.Amplitude := As_Amplitude (This.CR.MAMP2);\n end case;\n end case;\n\n return Result;" + }, + { + "function_def": "procedure Disable (This : in out Analog_To_Digital_Converter) is", + "function_body": "begin\n This.CR2.ADON := False;\n end Disable;\n\n -------------\n -- Enabled --\n -------------\n\n function Enabled (This : Analog_To_Digital_Converter) return Boolean is\n (This.CR2.ADON);\n\n ----------------------\n -- Conversion_Value --\n ----------------------\n\n function Conversion_Value\n (This : Analog_To_Digital_Converter)\n return UInt16\n is\n begin\n return This.DR.DATA;\n end Conversion_Value;\n\n ---------------------------\n -- Data_Register_Address --\n ---------------------------\n\n function Data_Register_Address\n (This : Analog_To_Digital_Converter)\n return System.Address\n is\n (This.DR'Address);\n\n -------------------------------\n -- Injected_Conversion_Value --\n -------------------------------\n\n function Injected_Conversion_Value\n (This : Analog_To_Digital_Converter;\n Rank : Injected_Channel_Rank)\n return UInt16\n is\n begin\n case Rank is\n when 1 =>\n return This.JDR1.JDATA;\n when 2 =>\n return This.JDR2.JDATA;\n when 3 =>\n return This.JDR3.JDATA;\n when 4 =>\n return This.JDR4.JDATA;\n end case;\n end Injected_Conversion_Value;\n\n --------------------------------\n -- Multimode_Conversion_Value --\n --------------------------------\n\n function Multimode_Conversion_Value return UInt32 is\n (C_ADC_Periph.CDR.Val);\n\n --------------------\n -- Configure_Unit --\n --------------------\n\n procedure Configure_Unit\n (This : in out Analog_To_Digital_Converter;\n Resolution : ADC_Resolution;\n Alignment : Data_Alignment)\n is\n begin\n This.CR1.RES := ADC_Resolution'Enum_Rep (Resolution);\n This.CR2.ALIGN := Alignment = Left_Aligned;\n end Configure_Unit;\n\n ------------------------\n -- Current_Resolution --\n ------------------------\n\n function Current_Resolution\n (This : Analog_To_Digital_Converter)\n return ADC_Resolution\n is (ADC_Resolution'Val (This.CR1.RES));\n\n -----------------------\n -- Current_Alignment --\n -----------------------\n\n function Current_Alignment\n (This : Analog_To_Digital_Converter)\n return Data_Alignment\n is ((if This.CR2.ALIGN then Left_Aligned else Right_Aligned));\n\n ---------------------------------\n -- Configure_Common_Properties --\n ---------------------------------\n\n procedure Configure_Common_Properties\n (Mode : Multi_ADC_Mode_Selections;\n Prescalar : ADC_Prescalars;\n DMA_Mode : Multi_ADC_DMA_Modes;\n Sampling_Delay : Sampling_Delay_Selections)\n is\n begin\n C_ADC_Periph.CCR.MULT := Multi_ADC_Mode_Selections'Enum_Rep (Mode);\n C_ADC_Periph.CCR.DELAY_k :=\n Sampling_Delay_Selections'Enum_Rep (Sampling_Delay);\n C_ADC_Periph.CCR.DMA := Multi_ADC_DMA_Modes'Enum_Rep (DMA_Mode);\n C_ADC_Periph.CCR.ADCPRE := ADC_Prescalars'Enum_Rep (Prescalar);\n end Configure_Common_Properties;\n\n -----------------------------------\n -- Configure_Regular_Conversions --\n -----------------------------------\n\n procedure Configure_Regular_Conversions\n (This : in out Analog_To_Digital_Converter;\n Continuous : Boolean;\n Trigger : Regular_Channel_Conversion_Trigger;\n Enable_EOC : Boolean;\n Conversions : Regular_Channel_Conversions)\n is\n begin\n This.CR2.EOCS := Enable_EOC;\n This.CR2.CONT := Continuous;\n\n This.CR1.SCAN := Conversions'Length > 1;\n\n if Trigger.Enabler /= Trigger_Disabled then\n This.CR2.EXTSEL := External_Events_Regular_Group'Enum_Rep (Trigger.Event);\n This.CR2.EXTEN := External_Trigger'Enum_Rep (Trigger.Enabler);\n else\n This.CR2.EXTSEL := 0;\n This.CR2.EXTEN := 0;\n end if;\n\n for Rank in Conversions'Range loop\n declare\n Conversion : Regular_Channel_Conversion renames Conversions (Rank);\n begin\n Configure_Regular_Channel\n (This, Conversion.Channel, Rank, Conversion.Sample_Time);\n\n -- We check the VBat first because that channel is also used for\n -- the temperature sensor channel on some MCUs, in which case the\n -- VBat conversion is the only one done. This order reflects that\n -- hardware behavior.\n if VBat_Conversion (This, Conversion.Channel) then\n Enable_VBat_Connection;\n elsif VRef_TemperatureSensor_Conversion (This, Conversion.Channel)\n then\n Enable_VRef_TemperatureSensor_Connection;\n end if;" + }, + { + "function_def": "procedure Disable_Interrupt", + "function_body": "(This : in out SDMMC_Controller;\n Interrupt : SDMMC_Interrupts)\n is\n begin\n case Interrupt is\n when Data_End_Interrupt =>\n This.Periph.MASK.DATAENDIE := False;\n when Data_CRC_Fail_Interrupt =>\n This.Periph.MASK.DCRCFAILIE := False;\n when Data_Timeout_Interrupt =>\n This.Periph.MASK.DTIMEOUTIE := False;\n when TX_FIFO_Empty_Interrupt =>\n This.Periph.MASK.TXFIFOEIE := False;\n when RX_FIFO_Full_Interrupt =>\n This.Periph.MASK.RXFIFOFIE := False;\n when TX_Underrun_Interrupt =>\n This.Periph.MASK.TXUNDERRIE := False;\n when RX_Overrun_Interrupt =>\n This.Periph.MASK.RXOVERRIE := False;\n end case;\n end Disable_Interrupt;\n\n ------------------------\n -- Delay_Milliseconds --\n ------------------------\n\n overriding procedure Delay_Milliseconds\n (This : SDMMC_Controller;\n Amount : Natural)\n is\n pragma Unreferenced (This);\n begin\n delay until Clock + Milliseconds (Amount);\n end Delay_Milliseconds;\n\n -----------\n -- Reset --\n -----------\n\n overriding procedure Reset\n (This : in out SDMMC_Controller;\n Status : out SD_Error)\n is\n begin\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n This.Periph.POWER.PWRCTRL := Power_Off;\n\n -- Use the Default SDMMC peripheral configuration for SD card init\n This.Periph.CLKCR := (others => <>);\n This.Set_Clock (400_000);\n This.Periph.DTIMER := SD_DATATIMEOUT;\n\n This.Periph.CLKCR.CLKEN := False;\n DCTRL_Write_Delay;\n This.Periph.POWER.PWRCTRL := Power_On;\n\n -- Wait for the clock to stabilize.\n DCTRL_Write_Delay;\n\n This.Periph.CLKCR.CLKEN := True;\n\n delay until Clock + Milliseconds (20);\n\n Status := OK;\n end Reset;\n\n ---------------\n -- Set_Clock --\n ---------------\n\n overriding procedure Set_Clock\n (This : in out SDMMC_Controller;\n Freq : Natural)\n is\n Div : UInt32;\n CLKCR : CLKCR_Register;\n begin\n Div := (This.CLK_In + UInt32 (Freq) - 1) / UInt32 (Freq);\n\n -- Make sure the POWER register is writable by waiting a bit after\n -- the Power_Off command\n DCTRL_Write_Delay;\n\n if Div <= 1 then\n This.Periph.CLKCR.BYPASS := True;\n else\n Div := Div - 2;\n CLKCR := This.Periph.CLKCR;\n CLKCR.BYPASS := False;\n\n if Div > UInt32 (CLKCR_CLKDIV_Field'Last) then\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field'Last;\n else\n CLKCR.CLKDIV := CLKCR_CLKDIV_Field (Div);\n end if;\n\n This.Periph.CLKCR := CLKCR;\n end if;\n end Set_Clock;\n\n ------------------\n -- Set_Bus_Size --\n ------------------\n\n overriding procedure Set_Bus_Size\n (This : in out SDMMC_Controller;\n Mode : Wide_Bus_Mode)\n is\n function To_WIDBUS_Field is new Ada.Unchecked_Conversion\n (Wide_Bus_Mode, CLKCR_WIDBUS_Field);\n begin\n This.Periph.CLKCR.WIDBUS := To_WIDBUS_Field (Mode);\n end Set_Bus_Size;\n\n ------------------\n -- Send_Command --\n ------------------\n\n overriding procedure Send_Cmd\n (This : in out SDMMC_Controller;\n Cmd : Cmd_Desc_Type;\n Arg : UInt32;\n Status : out SD_Error)\n is\n CMD_Reg : CMD_Register := This.Periph.CMD;\n begin\n if Cmd.Rsp = Rsp_Invalid or else Cmd.Tfr = Tfr_Invalid then\n raise Program_Error with \"Not implemented\";\n end if;\n\n This.Periph.ARG := Arg;\n CMD_Reg.CMDINDEX := CMD_CMDINDEX_Field (Cmd.Cmd);\n CMD_Reg.WAITRESP := (case Cmd.Rsp is\n when Rsp_No => No_Response,\n when Rsp_R2 => Long_Response,\n when others => Short_Response);\n CMD_Reg.WAITINT := False;\n CMD_Reg.CPSMEN := True;\n This.Periph.CMD := CMD_Reg;\n\n case Cmd.Rsp is\n when Rsp_No =>\n Status := This.Command_Error;\n\n when Rsp_R1 | Rsp_R1B =>\n Status := This.Response_R1_Error (Cmd.Cmd);\n\n when Rsp_R2 =>\n Status := This.Response_R2_Error;\n\n when Rsp_R3 =>\n Status := This.Response_R3_Error;\n\n when Rsp_R6 =>\n declare\n RCA : UInt32;\n begin\n Status := This.Response_R6_Error (Cmd.Cmd, RCA);\n This.RCA := UInt16 (Shift_Right (RCA, 16));" + }, + { + "function_def": "procedure Disable_Data", + "function_body": "(This : in out SDMMC_Controller)\n is\n begin\n This.Periph.DCTRL := (others => <>);\n end Disable_Data;\n\n --------------------------\n -- Enable_DMA_Transfers --\n --------------------------\n\n procedure Enable_DMA_Transfers\n (This : in out SDMMC_Controller;\n RX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n TX_Int : not null STM32.DMA.Interrupts.DMA_Interrupt_Controller_Access;\n SD_Int : not null STM32.SDMMC_Interrupt.SDMMC_Interrupt_Handler_Access)\n is\n begin\n This.TX_DMA_Int := TX_Int;\n This.RX_DMA_Int := RX_Int;\n This.SD_Int := SD_Int;\n end Enable_DMA_Transfers;\n\n --------------------------\n -- Has_Card_Information --\n --------------------------\n\n function Has_Card_Information\n (This : SDMMC_Controller)\n return Boolean\n is (This.Has_Info);\n\n ----------------------\n -- Card_Information --\n ----------------------\n\n function Card_Information\n (This : SDMMC_Controller)\n return HAL.SDMMC.Card_Information\n is\n begin\n return This.Info;\n end Card_Information;\n\n ----------------------------\n -- Clear_Card_Information --\n ----------------------------\n\n procedure Clear_Card_Information\n (This : in out SDMMC_Controller)\n is\n begin\n This.Has_Info := False;\n end Clear_Card_Information;\n\n ---------------\n -- Read_FIFO --\n ---------------\n\n function Read_FIFO\n (Controller : in out SDMMC_Controller) return UInt32\n is\n begin\n return Controller.Periph.FIFO;\n end Read_FIFO;\n\n -------------------\n -- Command_Error --\n -------------------\n\n function Command_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n begin\n while not Controller.Periph.STA.CMDSENT loop\n if Clock - Start > Milliseconds (1000) then\n return Timeout_Error;\n end if;\n end loop;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Command_Error;\n\n -----------------------\n -- Response_R1_Error --\n -----------------------\n\n function Response_R1_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n R1 : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n R1 := Controller.Periph.RESP1;\n\n if (R1 and SD_OCR_ERRORMASK) = 0 then\n return OK;\n end if;\n\n if (R1 and SD_OCR_ADDR_OUT_OF_RANGE) /= 0 then\n return Address_Out_Of_Range;\n elsif (R1 and SD_OCR_ADDR_MISALIGNED) /= 0 then\n return Address_Missaligned;\n elsif (R1 and SD_OCR_BLOCK_LEN_ERR) /= 0 then\n return Block_Length_Error;\n elsif (R1 and SD_OCR_ERASE_SEQ_ERR) /= 0 then\n return Erase_Seq_Error;\n elsif (R1 and SD_OCR_BAD_ERASE_PARAM) /= 0 then\n return Bad_Erase_Parameter;\n elsif (R1 and SD_OCR_WRITE_PROT_VIOLATION) /= 0 then\n return Write_Protection_Violation;\n elsif (R1 and SD_OCR_LOCK_UNLOCK_FAILED) /= 0 then\n return Lock_Unlock_Failed;\n elsif (R1 and SD_OCR_COM_CRC_FAILED) /= 0 then\n return CRC_Check_Fail;\n elsif (R1 and SD_OCR_ILLEGAL_CMD) /= 0 then\n return Illegal_Cmd;\n elsif (R1 and SD_OCR_CARD_ECC_FAILED) /= 0 then\n return Card_ECC_Failed;\n elsif (R1 and SD_OCR_CC_ERROR) /= 0 then\n return CC_Error;\n elsif (R1 and SD_OCR_GENERAL_UNKNOWN_ERROR) /= 0 then\n return General_Unknown_Error;\n elsif (R1 and SD_OCR_STREAM_READ_UNDERRUN) /= 0 then\n return Stream_Read_Underrun;\n elsif (R1 and SD_OCR_STREAM_WRITE_UNDERRUN) /= 0 then\n return Stream_Write_Underrun;\n elsif (R1 and SD_OCR_CID_CSD_OVERWRITE) /= 0 then\n return CID_CSD_Overwrite;\n elsif (R1 and SD_OCR_WP_ERASE_SKIP) /= 0 then\n return WP_Erase_Skip;\n elsif (R1 and SD_OCR_CARD_ECC_DISABLED) /= 0 then\n return Card_ECC_Disabled;\n elsif (R1 and SD_OCR_ERASE_RESET) /= 0 then\n return Erase_Reset;\n elsif (R1 and SD_OCR_AKE_SEQ_ERROR) /= 0 then\n return AKE_SEQ_Error;\n else\n return General_Unknown_Error;\n end if;\n end Response_R1_Error;\n\n -----------------------\n -- Response_R2_Error --\n -----------------------\n\n function Response_R2_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R2_Error;\n\n -----------------------\n -- Response_R3_Error --\n -----------------------\n\n function Response_R3_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n end if;\n\n Clear_Static_Flags (Controller);\n\n return OK;\n end Response_R3_Error;\n\n -----------------------\n -- Response_R6_Error --\n -----------------------\n\n function Response_R6_Error\n (Controller : in out SDMMC_Controller;\n Command_Index : SD_Command;\n RCA : out UInt32) return SD_Error\n is\n Response : UInt32;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n null;\n end loop;\n\n if Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n end if;\n\n if SD_Command (Controller.Periph.RESPCMD.RESPCMD) /=\n Command_Index\n then\n return Illegal_Cmd;\n end if;\n\n Clear_Static_Flags (Controller);\n\n Response := Controller.Periph.RESP1;\n\n if (Response and SD_R6_Illegal_Cmd) = SD_R6_Illegal_Cmd then\n return Illegal_Cmd;\n\n elsif (Response and SD_R6_General_Unknown_Error) =\n SD_R6_General_Unknown_Error\n then\n return General_Unknown_Error;\n\n elsif (Response and SD_R6_Com_CRC_Failed) = SD_R6_Com_CRC_Failed then\n return CRC_Check_Fail;\n end if;\n\n RCA := Response and 16#FFFF_0000#;\n\n return OK;\n end Response_R6_Error;\n\n -----------------------\n -- Response_R7_Error --\n -----------------------\n\n function Response_R7_Error\n (Controller : in out SDMMC_Controller) return SD_Error\n is\n Start : constant Time := Clock;\n Timeout : Boolean := False;\n begin\n while not Controller.Periph.STA.CCRCFAIL\n and then not Controller.Periph.STA.CMDREND\n and then not Controller.Periph.STA.CTIMEOUT\n loop\n if Clock - Start > Milliseconds (1000) then\n Timeout := True;\n\n exit;\n end if;\n end loop;\n\n if Timeout or else Controller.Periph.STA.CTIMEOUT then\n -- Card is not v2.0 compliant or card does not support the set\n -- voltage range\n Controller.Periph.ICR.CTIMEOUTC := True;\n\n return Timeout_Error;\n\n elsif Controller.Periph.STA.CCRCFAIL then\n Controller.Periph.ICR.CCRCFAILC := True;\n\n return CRC_Check_Fail;\n\n elsif Controller.Periph.STA.CMDREND then\n Controller.Periph.ICR.CMDRENDC := True;\n\n return OK;\n\n else\n return Error;\n end if;\n end Response_R7_Error;\n\n -------------------\n -- Stop_Transfer --\n -------------------\n\n function Stop_Transfer\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n Send_Cmd (This, Cmd_Desc (Stop_Transmission), 0, Ret);\n\n return Ret;\n end Stop_Transfer;\n\n -----------------------\n -- Set_Clk_Src_Speed --\n -----------------------\n\n procedure Set_Clk_Src_Speed\n (This : in out SDMMC_Controller;\n CLK : UInt32)\n is\n begin\n This.CLK_In := CLK;\n end Set_Clk_Src_Speed;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize\n (This : in out SDMMC_Controller) return SD_Error\n is\n Ret : SD_Error;\n begin\n SDMMC_Init.Card_Identification_Process (This, This.Info, Ret);\n This.Card_Type := This.Info.Card_Type;\n This.RCA := This.Info.RCA;\n\n return Ret;\n end Initialize;\n\n ----------\n -- Read --\n ----------\n\n overriding\n function Read\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : out HAL.Block_Drivers.Block) return Boolean\n is\n Ret : Boolean;\n SD_Err : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n\n Ensure_Card_Informations (This);\n\n if This.RX_DMA_Int = null or else This.SD_Int = null then\n SD_Err := Read_Blocks\n (This,\n Block_Number * 512,\n Data);\n return SD_Err = OK;\n end if;\n\n This.SD_Int.Set_Transfer_State (This);\n\n SD_Err := Read_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.RX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.SD_Int.Wait_Transfer (SD_Err);\n\n if SD_Err /= OK then\n This.RX_DMA_Int.Clear_Transfer_State;\n else\n This.RX_DMA_Int.Wait_For_Completion (DMA_Err);\n\n loop\n exit when not Get_Flag (This, RX_Active);\n end loop;\n end if;\n\n Ret := SD_Err = OK and then DMA_Err = DMA_No_Error;\n\n if Last_Operation (This) =\n Read_Multiple_Blocks_Operation\n then\n SD_Err := Stop_Transfer (This);\n Ret := Ret and then SD_Err = OK;\n end if;\n\n Clear_All_Status (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable (This.RX_DMA_Int.Controller.all, This.RX_DMA_Int.Stream);\n Disable_Data (This);\n Clear_Static_Flags (This);\n\n Cortex_M.Cache.Invalidate_DCache\n (Start => Data'Address,\n Len => Data'Length);\n\n return Ret;\n end Read;\n\n -----------\n -- Write --\n -----------\n\n overriding\n function Write\n (This : in out SDMMC_Controller;\n Block_Number : UInt64;\n Data : HAL.Block_Drivers.Block) return Boolean\n is\n Ret : SD_Error;\n DMA_Err : DMA_Error_Code;\n begin\n if This.TX_DMA_Int = null then\n raise Program_Error with \"No TX DMA controller\";\n end if;\n\n if This.SD_Int = null then\n raise Program_Error with \"No SD interrupt controller\";\n end if;\n\n Ensure_Card_Informations (This);\n\n -- Flush the data cache\n Cortex_M.Cache.Clean_DCache\n (Start => Data (Data'First)'Address,\n Len => Data'Length);\n\n This.SD_Int.Set_Transfer_State (This);\n\n Ret := Write_Blocks_DMA\n (This,\n Block_Number * 512,\n Data);\n -- this always leaves the last 12 byte standing. Why?\n -- also...NDTR is not what it should be.\n\n if Ret /= OK then\n This.TX_DMA_Int.Clear_Transfer_State;\n This.SD_Int.Clear_Transfer_State;\n This.TX_DMA_Int.Abort_Transfer (DMA_Err);\n\n return False;\n end if;\n\n This.TX_DMA_Int.Wait_For_Completion (DMA_Err); -- this unblocks\n This.SD_Int.Wait_Transfer (Ret); -- TX underrun!\n\n -- this seems slow. Do we have to wait?\n loop\n -- FIXME: some people claim, that this goes wrong with multiblock, see\n -- http://blog.frankvh.com/2011/09/04/stm32f2xx-sdio-sd-card-interface/\n exit when not Get_Flag (This, TX_Active);\n end loop;\n\n if Last_Operation (This) =\n Write_Multiple_Blocks_Operation\n then\n Ret := Stop_Transfer (This);\n end if;\n\n Clear_All_Status (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n Disable (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream);\n\n declare\n Data_Incomplete : constant Boolean :=\n This.TX_DMA_Int.Buffer_Error and then\n Items_Transferred (This.TX_DMA_Int.Controller.all, This.TX_DMA_Int.Stream)\n /= Data'Length / 4;\n begin\n return Ret = OK\n and then DMA_Err = DMA_No_Error\n and then not Data_Incomplete;" + }, + { + "function_def": "function To_Word is new Ada.Unchecked_Conversion (System.Address, UInt32);", + "function_body": "function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32 with Inline_Always;\n\n DMA2D_Init_Transfer_Int : DMA2D_Sync_Procedure := null;\n DMA2D_Wait_Transfer_Int : DMA2D_Sync_Procedure := null;\n\n ------------------\n -- DMA2D_DeInit --\n ------------------\n\n procedure DMA2D_DeInit is\n begin\n RCC_Periph.AHB1ENR.DMA2DEN := False;\n DMA2D_Init_Transfer_Int := null;\n DMA2D_Wait_Transfer_Int := null;\n end DMA2D_DeInit;\n\n ----------------\n -- DMA2D_Init --\n ----------------\n\n procedure DMA2D_Init\n (Init : DMA2D_Sync_Procedure;\n Wait : DMA2D_Sync_Procedure)\n is\n begin\n if DMA2D_Init_Transfer_Int = Init then\n return;\n end if;\n\n DMA2D_DeInit;\n\n DMA2D_Init_Transfer_Int := Init;\n DMA2D_Wait_Transfer_Int := Wait;\n\n RCC_Periph.AHB1ENR.DMA2DEN := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := True;\n RCC_Periph.AHB1RSTR.DMA2DRST := False;\n end DMA2D_Init;\n\n ------------\n -- Offset --\n ------------\n\n function Offset (Buffer : DMA2D_Buffer;\n X, Y : Integer) return UInt32\n is\n Off : constant UInt32 := UInt32 (X + Buffer.Width * Y);\n begin\n case Buffer.Color_Mode is\n when ARGB8888 =>\n return 4 * Off;\n when RGB888 =>\n return 3 * Off;\n when ARGB1555 | ARGB4444 | RGB565 | AL88 =>\n return 2 * Off;\n when L8 | AL44 | A8 =>\n return Off;\n when L4 | A4 =>\n return Off / 2;\n end case;\n end Offset;\n\n ----------------\n -- DMA2D_Fill --\n ----------------\n\n procedure DMA2D_Fill\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR.CM := As_UInt3 (Buffer.Color_Mode);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr);\n DMA2D_Periph.OOR := (LO => 0, others => <>);\n DMA2D_Periph.NLR := (NL => UInt16 (Buffer.Height),\n PL => UInt14 (Buffer.Width),\n others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill;\n\n ---------------------\n -- DMA2D_Fill_Rect --\n ---------------------\n\n procedure DMA2D_Fill_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer;\n Synchronous : Boolean := False)\n is\n function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);\n Off : constant UInt32 := Offset (Buffer, X, Y);\n\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);\n DMA2D_Periph.OPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode),\n others => <>);\n DMA2D_Periph.OCOLR := Conv (Color);\n DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;\n DMA2D_Periph.OOR.LO := UInt14 (Buffer.Width - Width);\n DMA2D_Periph.NLR :=\n (NL => UInt16 (Height), PL => UInt14 (Width), others => <>);\n\n DMA2D_Init_Transfer_Int.all;\n if Synchronous then\n DMA2D_Wait_Transfer_Int.all;\n end if;\n end DMA2D_Fill_Rect;\n\n ---------------------\n -- DMA2D_Draw_Rect --\n ---------------------\n\n procedure DMA2D_Draw_Rect\n (Buffer : DMA2D_Buffer;\n Color : UInt32;\n X : Integer;\n Y : Integer;\n Width : Integer;\n Height : Integer)\n is\n begin\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y, Width);\n DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y + Height - 1, Width);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X, Y, Height);\n DMA2D_Draw_Vertical_Line (Buffer, Color, X + Width - 1, Y, Height, True);\n end DMA2D_Draw_Rect;\n\n ---------------------\n -- DMA2D_Copy_Rect --\n ---------------------\n\n procedure DMA2D_Copy_Rect\n (Src_Buffer : DMA2D_Buffer;\n X_Src : Natural;\n Y_Src : Natural;\n Dst_Buffer : DMA2D_Buffer;\n X_Dst : Natural;\n Y_Dst : Natural;\n Bg_Buffer : DMA2D_Buffer;\n X_Bg : Natural;\n Y_Bg : Natural;\n Width : Natural;\n Height : Natural;\n Synchronous : Boolean := False)\n is\n Src_Off : constant UInt32 := Offset (Src_Buffer, X_Src, Y_Src);\n Dst_Off : constant UInt32 := Offset (Dst_Buffer, X_Dst, Y_Dst);\n begin\n DMA2D_Wait_Transfer_Int.all;\n\n if Bg_Buffer /= Null_Buffer then\n -- PFC and blending\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_BLEND);\n\n elsif Src_Buffer.Color_Mode = Dst_Buffer.Color_Mode then\n -- Direct memory transfer\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M);\n else\n DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_PFC);\n end if;\n\n -- SOURCE CONFIGURATION\n DMA2D_Periph.FGPFCCR :=\n (CM => DMA2D_Color_Mode'Enum_Rep (Src_Buffer.Color_Mode),\n AM => DMA2D_AM'Enum_Rep (NO_MODIF),\n ALPHA => 255,\n others => <>);\n\n if Src_Buffer.Color_Mode = L8 or else Src_Buffer.Color_Mode = L4 then\n\n if Src_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Source CLUT address required\";\n end if;\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n\n DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);\n DMA2D_Periph.FGPFCCR.CS := (case Src_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.FGPFCCR.CCM := Src_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.FGPFCCR.START := True;\n\n while DMA2D_Periph.FGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;\n\n DMA2D_Periph.FGOR := (LO => UInt14 (Src_Buffer.Width - Width),\n others => <>);\n DMA2D_Periph.FGMAR := To_Word (Src_Buffer.Addr) + Src_Off;\n\n if Bg_Buffer /= Null_Buffer then\n declare\n Bg_Off : constant UInt32 := Offset (Bg_Buffer, X_Bg, Y_Bg);\n begin\n DMA2D_Periph.BGPFCCR.CM :=\n DMA2D_Color_Mode'Enum_Rep (Bg_Buffer.Color_Mode);\n DMA2D_Periph.BGMAR := To_Word (Bg_Buffer.Addr) + Bg_Off;\n DMA2D_Periph.BGPFCCR.CS := 0;\n DMA2D_Periph.BGPFCCR.START := False;\n DMA2D_Periph.BGOR :=\n (LO => UInt14 (Bg_Buffer.Width - Width), others => <>);\n\n if Bg_Buffer.Color_Mode = L8 or else Bg_Buffer.Color_Mode = L4 then\n\n if Bg_Buffer.CLUT_Addr = System.Null_Address then\n raise Program_Error with \"Background CLUT address required\";\n end if;\n\n DMA2D_Periph.BGCMAR := To_Word (Bg_Buffer.CLUT_Addr);\n DMA2D_Periph.BGPFCCR.CS := (case Bg_Buffer.Color_Mode is\n when L8 => 2**8 - 1,\n when L4 => 2**4 - 1,\n when others => 0);\n -- Set CLUT mode to RGB888\n DMA2D_Periph.BGPFCCR.CCM := Bg_Buffer.CLUT_Color_Mode = RGB888;\n\n -- Start loading the CLUT\n DMA2D_Periph.BGPFCCR.START := True;\n\n while DMA2D_Periph.BGPFCCR.START loop\n -- Wait for CLUT loading...\n null;\n end loop;\n end if;" + }, + { + "function_def": "procedure Demo_Timer_PWM is -- low-level demo of the PWM capabilities", + "function_body": "Period : constant := 1000;\n\n Output_Channel : constant Timer_Channel := Channel_2;\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode for Timer_4. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n\n --------------------\n -- Configure_LEDs --\n --------------------\n\n procedure Configure_LEDs;\n\n procedure Configure_LEDs is\n begin\n Enable_Clock (GPIO_D);\n\n Configure_IO\n (All_LEDs,\n (Mode_AF,\n AF => GPIO_AF_TIM4_2,\n AF_Speed => Speed_50MHz,\n AF_Output_Type => Push_Pull,\n Resistors => Floating));\n end Configure_LEDs;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_LEDs;\n\n Enable_Clock (Timer_4);\n\n Reset (Timer_4);\n\n Configure\n (Timer_4,\n Prescaler => 1,\n Period => Period,\n Clock_Divisor => Div1,\n Counter_Mode => Up);\n\n Configure_Channel_Output\n (Timer_4,\n Channel => Output_Channel,\n Mode => PWM1,\n State => Enable,\n Pulse => 0,\n Polarity => High);\n\n Set_Autoreload_Preload (Timer_4, True);\n\n Enable_Channel (Timer_4, Output_Channel);\n\n Enable (Timer_4);\n\n declare\n Arg : Long_Float := 0.0;\n Pulse : UInt16;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of optimization is observable.\n begin\n loop\n Pulse := UInt16 (Long_Float (Period / 2) * (1.0 + Sine (Arg)));\n Set_Compare_Value (Timer_4, Output_Channel, Pulse);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_PWM_ADT is -- demo the higher-level PWM abstract data type", + "function_body": "Selected_Timer : STM32.Timers.Timer renames Timer_4;\n -- NOT arbitrary! We drive the on-board LEDs that are tied to the channels\n -- of Timer_4 on some boards. Not all boards have this association. If you\n -- use a different board, select a GPIO point connected to your selected\n -- timer and drive that instead.\n\n Timer_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_TIM4_2;\n -- Note that this value MUST match the corresponding timer selected!\n\n Output_Channel : constant Timer_Channel := Channel_2; -- arbitrary\n -- The LED driven by this example is determined by the channel selected.\n -- That is so because each channel of Timer_4 is connected to a specific\n -- LED in the alternate function configuration on this board. We will\n -- initialize all of the LEDs to be in the AF mode. The\n -- particular channel selected is completely arbitrary, as long as the\n -- selected GPIO port/pin for the LED matches the selected channel.\n --\n -- Channel_1 is connected to the green LED.\n -- Channel_2 is connected to the orange LED.\n -- Channel_3 is connected to the red LED.\n -- Channel_4 is connected to the blue LED.\n LED_For : constant array (Timer_Channel) of User_LED :=\n (Channel_1 => Green_LED,\n Channel_2 => Orange_LED,\n Channel_3 => Red_LED,\n Channel_4 => Blue_LED);\n\n Requested_Frequency : constant Hertz := 30_000; -- arbitrary\n\n Power_Control : PWM_Modulator;\n\n -- The SFP run-time library for these boards is intended for certified\n -- environments and so does not contain the full set of facilities defined\n -- by the Ada language. The elementary functions are not included, for\n -- example. In contrast, the Ravenscar \"full\" run-times do have these\n -- functions.\n function Sine (Input : Long_Float) return Long_Float;\n\n -- Therefore there are four choices: 1) use the \"ravescar-full-stm32f4\"\n -- runtime library, 2) pull the sources for the language-defined elementary\n -- function package into the board's run-time library and rebuild the\n -- run-time, 3) pull the sources for those packages into the source\n -- directory of your application and rebuild your application, or 4) roll\n -- your own approximation to the functions required by your application.\n\n -- In this demonstration we roll our own approximation to the sine function\n -- so that it doesn't matter which runtime library is used.\n\n function Sine (Input : Long_Float) return Long_Float is\n Pi : constant Long_Float := 3.14159_26535_89793_23846;\n X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);\n B : constant Long_Float := 4.0 / Pi;\n C : constant Long_Float := (-4.0) / (Pi * Pi);\n Y : constant Long_Float := B * X + C * X * abs (X);\n P : constant Long_Float := 0.225;\n begin\n return P * (Y * abs (Y) - Y) + Y;\n end Sine;\n\n -- We use the sine function to drive the power applied to the LED, thereby\n -- making the LED increase and decrease in brightness. We attach the timer\n -- to the LED and then control how much power is supplied by changing the\n -- value of the timer's output compare register. The sine function drives\n -- that value, thus the waxing/waning effect.\n\nbegin\n Configure_PWM_Timer (Selected_Timer'Access, Requested_Frequency);\n\n Power_Control.Attach_PWM_Channel\n (Selected_Timer'Access,\n Output_Channel,\n LED_For (Output_Channel),\n Timer_AF);\n\n Power_Control.Enable_Output;\n\n declare\n Arg : Long_Float := 0.0;\n Value : Percentage;\n Increment : constant Long_Float := 0.00003;\n -- The Increment value controls the rate at which the brightness\n -- increases and decreases. The value is more or less arbitrary, but\n -- note that the effect of compiler optimization is observable.\n begin\n loop\n Value := Percentage (50.0 * (1.0 + Sine (Arg)));\n Power_Control.Set_Duty_Cycle (Value);\n Arg := Arg + Increment;\n end loop;" + }, + { + "function_def": "procedure Demo_DAC_Basic is", + "function_body": "Output_Channel : constant DAC_Channel := Channel_1; -- arbitrary\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel);\n -- Once the channel is enabled, the corresponding GPIO pin is automatically\n -- connected to the analog converter output. However, in order to avoid\n -- parasitic consumption, the PA4 pin (Channel_1) or PA5 pin (Channel_2)\n -- should first be configured to analog mode. See the note in the RM, page\n -- 431.\n\n procedure Print (Value : UInt32);\n -- Prints the image of the arg at a fixed location\n\n procedure Await_Button;\n -- Wait for the user to press and then release the blue user button\n\n -----------\n -- Print --\n -----------\n\n procedure Print (Value : UInt32) is\n Value_Image : constant String := Value'Img;\n begin\n LCD_Std_Out.Put (170, 52, Value_Image (2 .. Value_Image'Last) & \" \");\n end Print;\n\n ------------------\n -- Await_Button --\n ------------------\n\n procedure Await_Button is\n begin\n Await_Pressed : loop\n exit Await_Pressed when Set (User_Button_Point);\n end loop Await_Pressed;\n\n Await_Released : loop\n exit Await_Released when not Set (User_Button_Point);\n end loop Await_Released;\n end Await_Button;\n\n ------------------------\n -- Configure_DAC_GPIO --\n ------------------------\n\n procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel) is\n Output : constant GPIO_Point := (if Output_Channel = Channel_1\n then DAC_Channel_1_IO\n else DAC_Channel_2_IO);\n begin\n Enable_Clock (Output);\n Configure_IO (Output, (Mode => Mode_Analog, Resistors => Floating));\n end Configure_DAC_GPIO;\n\nbegin\n Initialize_LEDs;\n All_LEDs_Off;\n\n LCD_Std_Out.Clear_Screen;\n\n Configure_User_Button_GPIO;\n\n Configure_DAC_GPIO (Output_Channel);\n\n Enable_Clock (DAC_1);\n\n Reset (DAC_1);\n\n Select_Trigger (DAC_1, Output_Channel, Software_Trigger);\n\n Enable_Trigger (DAC_1, Output_Channel);\n\n Enable (DAC_1, Output_Channel);\n\n declare\n Value : UInt32 := 0;\n Percent : UInt32;\n\n Resolution : constant DAC_Resolution := DAC_Resolution_12_Bits;\n -- Arbitrary, change as desired. Counts will automatically adjust.\n\n Max_Counts : constant UInt32 := (if Resolution = DAC_Resolution_12_Bits\n then Max_12bit_Resolution\n else Max_8bit_Resolution);\n begin\n Put (0, 0, \"VRef+ is 2.95V\"); -- measured\n Put (0, 25, \"Button advances\");\n Put (0, 52, \"Current %:\");\n loop\n for K in UInt32 range 0 .. 10 loop\n Percent := K * 10;\n Print (Percent);\n\n Value := (Percent * Max_Counts) / 100;\n\n Set_Output\n (DAC_1,\n Output_Channel,\n Value,\n Resolution,\n Right_Aligned);\n\n Trigger_Conversion_By_Software (DAC_1, Output_Channel);\n\n Await_Button;\n end loop;\n end loop;" + }, + { + "function_def": "procedure Demo_CRC is", + "function_body": "Checksum_CPU : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses the CPU to transfer\n -- the memory block to the CRC processor\n\n Checksum_DMA : UInt32 := 0;\n -- the checksum obtained by calling a routine that uses DMA to transfer the\n -- memory block to the CRC processor\n\n -- see the STM32Cube_FW_F4_V1.6.0\\Projects\\ CRC example for data and\n -- expected CRC checksum value\n\n Section1 : constant Block_32 :=\n (16#00001021#, 16#20423063#, 16#408450A5#, 16#60C670E7#, 16#9129A14A#, 16#B16BC18C#,\n 16#D1ADE1CE#, 16#F1EF1231#, 16#32732252#, 16#52B54294#, 16#72F762D6#, 16#93398318#,\n 16#A35AD3BD#, 16#C39CF3FF#, 16#E3DE2462#, 16#34430420#, 16#64E674C7#, 16#44A45485#,\n 16#A56AB54B#, 16#85289509#, 16#F5CFC5AC#, 16#D58D3653#, 16#26721611#, 16#063076D7#,\n 16#569546B4#, 16#B75BA77A#, 16#97198738#, 16#F7DFE7FE#, 16#C7BC48C4#, 16#58E56886#,\n 16#78A70840#, 16#18612802#, 16#C9CCD9ED#, 16#E98EF9AF#, 16#89489969#, 16#A90AB92B#,\n 16#4AD47AB7#, 16#6A961A71#, 16#0A503A33#, 16#2A12DBFD#, 16#FBBFEB9E#, 16#9B798B58#,\n 16#BB3BAB1A#, 16#6CA67C87#, 16#5CC52C22#, 16#3C030C60#, 16#1C41EDAE#, 16#FD8FCDEC#,\n 16#AD2ABD0B#, 16#8D689D49#, 16#7E976EB6#, 16#5ED54EF4#, 16#2E321E51#, 16#0E70FF9F#);\n\n Section2 : constant Block_32 :=\n (16#EFBEDFDD#, 16#CFFCBF1B#, 16#9F598F78#, 16#918881A9#, 16#B1CAA1EB#, 16#D10CC12D#,\n 16#E16F1080#, 16#00A130C2#, 16#20E35004#, 16#40257046#, 16#83B99398#, 16#A3FBB3DA#,\n 16#C33DD31C#, 16#E37FF35E#, 16#129022F3#, 16#32D24235#, 16#52146277#, 16#7256B5EA#,\n 16#95A88589#, 16#F56EE54F#, 16#D52CC50D#, 16#34E224C3#, 16#04817466#, 16#64475424#,\n 16#4405A7DB#, 16#B7FA8799#, 16#E75FF77E#, 16#C71DD73C#, 16#26D336F2#, 16#069116B0#,\n 16#76764615#, 16#5634D94C#, 16#C96DF90E#, 16#E92F99C8#, 16#B98AA9AB#, 16#58444865#,\n 16#78066827#, 16#18C008E1#, 16#28A3CB7D#, 16#DB5CEB3F#, 16#FB1E8BF9#, 16#9BD8ABBB#,\n 16#4A755A54#, 16#6A377A16#, 16#0AF11AD0#, 16#2AB33A92#, 16#ED0FDD6C#, 16#CD4DBDAA#,\n 16#AD8B9DE8#, 16#8DC97C26#, 16#5C644C45#, 16#3CA22C83#, 16#1CE00CC1#, 16#EF1FFF3E#,\n 16#DF7CAF9B#, 16#BFBA8FD9#, 16#9FF86E17#, 16#7E364E55#, 16#2E933EB2#, 16#0ED11EF0#);\n\n -- expected CRC value for the data above is 379E9F06 hex, or 933142278 dec\n Expected_Checksum : constant UInt32 := 933142278;\n\n Next_DMA_Interrupt : DMA_Interrupt;\n\n procedure Panic with No_Return;\n -- flash the on-board LEDs, indefinitely, to indicate a failure\n\n procedure Panic is\n begin\n loop\n Toggle_LEDs (All_LEDs);\n delay until Clock + Milliseconds (100);\n end loop;\n end Panic;\n\nbegin\n Clear_Screen;\n Initialize_LEDs;\n\n Enable_Clock (CRC_Unit);\n\n -- get the checksum using the CPU to transfer memory to the CRC processor;\n -- verify it is the expected value\n\n Update_CRC (CRC_Unit, Input => Section1, Output => Checksum_CPU);\n Update_CRC (CRC_Unit, Input => Section2, Output => Checksum_CPU);\n\n Put_Line (\"CRC:\" & Checksum_CPU'Img);\n\n if Checksum_CPU /= Expected_Checksum then\n Panic;\n end if;\n\n -- get the checksum using DMA to transfer memory to the CRC processor\n\n Enable_Clock (Controller);\n\n Reset (Controller);\n\n Reset_Calculator (CRC_Unit);\n\n Update_CRC (CRC_Unit, Controller'Access, Stream, Input => Section1);\n\n DMA_IRQ_Handler.Await_Event (Next_DMA_Interrupt);\n\n if Next_DMA_Interrupt /= Transfer_Complete_Interrupt then\n Panic;\n end if;\n\n -- In this code fragment we use the approach suited for the case in which\n -- we are calculating the CRC for a section of system memory rather than a\n -- block of application data. We pretend that Section2 is a memory section.\n -- All we need is a known starting address and a known length. Given that,\n -- we can create a view of it as if it is an object of type Block_32 (or\n -- whichever block type is appropriate).\n declare\n subtype Memory_Section is Block_32 (1 .. Section2'Length);\n type Section_Pointer is access all Memory_Section with Storage_Size => 0;\n function As_Memory_Section_Reference is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Section_Pointer);\n begin\n Update_CRC\n (CRC_Unit,\n Controller'Access,\n Stream,\n Input => As_Memory_Section_Reference (Section2'Address).all);" + }, + { + "function_def": "procedure DSB is", + "function_body": "begin\n Asm (\"dsb\", Volatile => True);\n end DSB;\n\n ---------\n -- ISB --\n ---------\n\n procedure ISB is\n begin\n Asm (\"isb\", Volatile => True);\n end ISB;\n\n -----------------------\n -- Cache_Maintenance --\n -----------------------\n\n procedure Cache_Maintenance\n (Start : System.Address;\n Len : Natural)\n is\n begin\n if not D_Cache_Enabled then\n return;\n end if;\n\n declare\n function To_U32 is new Ada.Unchecked_Conversion\n (System.Address, UInt32);\n\n Op_Size : Integer_32 := Integer_32 (Len);\n Op_Addr : UInt32 := To_U32 (Start);\n Reg : UInt32 with Volatile, Address => Reg_Address;\n\n begin\n DSB;\n\n while Op_Size > 0 loop\n Reg := Op_Addr;\n Op_Addr := Op_Addr + Data_Cache_Line_Size;\n Op_Size := Op_Size - Integer_32 (Data_Cache_Line_Size);\n end loop;\n\n DSB;\n ISB;" + }, + { + "function_def": "function To_Char is new Ada.Unchecked_Conversion (Source => UInt8,", + "function_body": "Target => Character);\n function To_UInt8 is new Ada.Unchecked_Conversion (Source => Character,\n Target => UInt8);\n\n procedure Write (This : in out TP_Device; Cmd : String);\n procedure Read (This : in out TP_Device; Str : out String);\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : in out TP_Device; Cmd : String) is\n Status : UART_Status;\n Data : UART_Data_8b (Cmd'Range);\n begin\n\n for Index in Cmd'Range loop\n Data (Index) := To_UInt8 (Cmd (Index));\n end loop;\n\n This.Port.Transmit (Data, Status);\n\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n -- This.Time.Delay_Microseconds ((11 * 1000000 / 19_2000) + Cmd'Length);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read (This : in out TP_Device; Str : out String) is\n Status : UART_Status;\n Data : UART_Data_8b (Str'Range);\n begin\n This.Port.Receive (Data, Status);\n if Status /= Ok then\n -- No error handling...\n raise Program_Error;\n end if;\n\n for Index in Str'Range loop\n Str (Index) := To_Char (Data (Index));\n end loop;\n end Read;\n\n ----------------------\n -- Set_Line_Spacing --\n ----------------------\n\n procedure Set_Line_Spacing (This : in out TP_Device; Spacing : UInt8) is\n begin\n Write (This, ASCII.ESC & '3' & To_Char (Spacing));\n end Set_Line_Spacing;\n\n ---------------\n -- Set_Align --\n ---------------\n\n procedure Set_Align (This : in out TP_Device; Align : Text_Align) is\n Mode : Character;\n begin\n case Align is\n when Left => Mode := '0';\n when Center => Mode := '1';\n when Right => Mode := '2';\n end case;\n Write (This, ASCII.ESC & 'a' & Mode);\n end Set_Align;\n\n ----------------------\n -- Set_Font_Enlarge --\n ----------------------\n\n procedure Set_Font_Enlarge (This : in out TP_Device; Height, Width : Boolean) is\n Data : UInt8 := 0;\n begin\n if Height then\n Data := Data or 16#01#;\n end if;\n if Width then\n Data := Data or 16#10#;\n end if;\n Write (This, ASCII.GS & '!' & To_Char (Data));\n end Set_Font_Enlarge;\n\n --------------\n -- Set_Bold --\n --------------\n\n procedure Set_Bold (This : in out TP_Device; Bold : Boolean) is\n begin\n Write (This, ASCII.ESC & 'E' & To_Char (if Bold then 1 else 0));\n end Set_Bold;\n\n ----------------------\n -- Set_Double_Width --\n ----------------------\n\n procedure Set_Double_Width (This : in out TP_Device; Double : Boolean) is\n begin\n if Double then\n Write (This, ASCII.ESC & ASCII.SO);\n else\n Write (This, ASCII.ESC & ASCII.DC4);\n end if;\n end Set_Double_Width;\n\n ----------------\n -- Set_UpDown --\n ----------------\n\n procedure Set_UpDown (This : in out TP_Device; UpDown : Boolean) is\n begin\n Write (This, ASCII.ESC & '{' & To_Char (if UpDown then 1 else 0));\n end Set_UpDown;\n\n ------------------\n -- Set_Reversed --\n ------------------\n\n procedure Set_Reversed (This : in out TP_Device; Reversed : Boolean) is\n begin\n Write (This, ASCII.GS & 'B' & To_Char (if Reversed then 1 else 0));\n end Set_Reversed;\n\n --------------------------\n -- Set_Underline_Height --\n --------------------------\n\n procedure Set_Underline_Height (This : in out TP_Device; Height : Underline_Height) is\n begin\n Write (This, ASCII.ESC & '-' & To_Char (Height));\n end Set_Underline_Height;\n\n -----------------------\n -- Set_Character_Set --\n -----------------------\n\n procedure Set_Character_Set (This : in out TP_Device; Set : Character_Set) is\n begin\n Write (This, ASCII.ESC & 't' & To_Char (Character_Set'Pos (Set)));\n end Set_Character_Set;\n\n ----------\n -- Feed --\n ----------\n\n procedure Feed (This : in out TP_Device; Rows : UInt8) is\n begin\n Write (This, ASCII.ESC & 'd' & To_Char (Rows));\n end Feed;\n\n ------------------\n -- Print_Bitmap --\n ------------------\n\n procedure Print_Bitmap (This : in out TP_Device;\n BM : Thermal_Printer_Bitmap)\n is\n Nbr_Of_Rows : constant Natural := BM'Length (2);\n Nbr_Of_Columns : constant Natural := BM'Length (1);\n Str : String (1 .. Nbr_Of_Columns / 8);\n begin\n\n Write (This, ASCII.DC2 & 'v' &\n To_Char (UInt8 (Nbr_Of_Rows rem 256)) &\n To_Char (UInt8 (Nbr_Of_Rows / 256)));\n\n for Row in 0 .. Nbr_Of_Rows - 1 loop\n for Colum in 0 .. (Nbr_Of_Columns / 8) - 1 loop\n declare\n BM_Index : constant Natural := BM'First (1) + Colum * 8;\n Str_Index : constant Natural := Str'First + Colum;\n B : UInt8 := 0;\n begin\n for X in 0 .. 7 loop\n B := B or (if BM (BM_Index + X,\n BM'First (2) + Row)\n then 2**X else 0);\n end loop;\n Str (Str_Index) := To_Char (B);" + }, + { + "function_def": "function As_UInt8 is new Ada.Unchecked_Conversion", + "function_body": "(Source => High_Pass_Filter_Mode, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => High_Pass_Cutoff_Frequency, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Power_Mode_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Output_Data_Rate_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Axes_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Bandwidth_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Block_Data_Update_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Endian_Data_Selection, Target => UInt8);\n\n function As_UInt8 is new Ada.Unchecked_Conversion\n (Source => Full_Scale_Selection, Target => UInt8);\n\n type Angle_Rate_Pointer is access all Angle_Rate with Storage_Size => 0;\n\n function As_Angle_Rate_Pointer is new Ada.Unchecked_Conversion\n (Source => System.Address, Target => Angle_Rate_Pointer);\n -- So that we can treat the address of a UInt8 as a pointer to a two-UInt8\n -- sequence representing a signed integer quantity.\n\n procedure Swap2 (Location : System.Address) with Inline;\n -- Swaps the two UInt8s at Location and Location+1\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean);\n -- Enable or disable SPI mode communication with the device. This is named\n -- \"chip select\" in other demos/examples.\n\n ----------------\n -- Initialize --\n ----------------\n\n procedure Initialize\n (This : in out Three_Axis_Gyroscope;\n Port : Any_SPI_Port;\n Chip_Select : Any_GPIO_Point)\n is\n begin\n This.Port := Port;\n This.CS := Chip_Select;\n\n SPI_Mode (This, Enabled => False);\n end Initialize;\n\n -----------------\n -- SPI_Mode --\n -----------------\n\n procedure SPI_Mode (This : Three_Axis_Gyroscope; Enabled : Boolean) is\n -- When the pin is low (cleared), the device is in SPI mode.\n -- When the pin is high (set), the device is in I2C mode.\n -- We want SPI mode communication, so Enabled, when True,\n -- means we must drive the pin low.\n begin\n if Enabled then\n This.CS.Clear;\n else\n This.CS.Set;\n end if;\n end SPI_Mode;\n\n -----------\n -- Write --\n -----------\n\n procedure Write (This : Three_Axis_Gyroscope; Addr : Register; Data : UInt8)\n is\n Status : SPI_Status;\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr)), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Transmit (SPI_Data_8b'(1 => Data), Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n SPI_Mode (This, Enabled => False);\n end Write;\n\n ----------\n -- Read --\n ----------\n\n procedure Read\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Data : out UInt8)\n is\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD),\n Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Data := Tmp_Data (Tmp_Data'First);\n\n SPI_Mode (This, Enabled => False);\n end Read;\n\n ----------------\n -- Read_UInt8s --\n ----------------\n\n procedure Read_UInt8s\n (This : Three_Axis_Gyroscope;\n Addr : Register;\n Buffer : out SPI_Data_8b;\n Count : Natural)\n is\n Index : Natural := Buffer'First;\n Status : SPI_Status;\n Tmp_Data : SPI_Data_8b (1 .. 1);\n begin\n SPI_Mode (This, Enabled => True);\n\n This.Port.Transmit\n (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD or MultiUInt8_CMD),\n Status);\n\n if Status /= Ok then\n raise Program_Error;\n end if;\n\n for K in 1 .. Count loop\n This.Port.Receive (Tmp_Data, Status);\n if Status /= Ok then\n raise Program_Error;\n end if;\n Buffer (Index) := Tmp_Data (Tmp_Data'First);\n Index := Index + 1;\n end loop;\n\n SPI_Mode (This, Enabled => False);\n end Read_UInt8s;\n\n ---------------\n -- Configure --\n ---------------\n\n procedure Configure\n (This : in out Three_Axis_Gyroscope;\n Power_Mode : Power_Mode_Selection;\n Output_Data_Rate : Output_Data_Rate_Selection;\n Axes_Enable : Axes_Selection;\n Bandwidth : Bandwidth_Selection;\n BlockData_Update : Block_Data_Update_Selection;\n Endianness : Endian_Data_Selection;\n Full_Scale : Full_Scale_Selection)\n is\n Ctrl1 : UInt8;\n Ctrl4 : UInt8;\n begin\n Ctrl1 := As_UInt8 (Power_Mode) or\n As_UInt8 (Output_Data_Rate) or\n As_UInt8 (Axes_Enable) or\n As_UInt8 (Bandwidth);\n\n Ctrl4 := As_UInt8 (BlockData_Update) or\n As_UInt8 (Endianness) or\n As_UInt8 (Full_Scale);\n\n Write (This, CTRL_REG1, Ctrl1);\n Write (This, CTRL_REG4, Ctrl4);\n end Configure;\n\n -----------\n -- Sleep --\n -----------\n\n procedure Sleep (This : in out Three_Axis_Gyroscope) is\n Ctrl1 : UInt8;\n Sleep_Mode : constant := 2#1000#; -- per the Datasheet, Table 22, pg 32\n begin\n Read (This, CTRL_REG1, Ctrl1);\n Ctrl1 := Ctrl1 or Sleep_Mode;\n Write (This, CTRL_REG1, Ctrl1);\n end Sleep;\n\n --------------------------------\n -- Configure_High_Pass_Filter --\n --------------------------------\n\n procedure Configure_High_Pass_Filter\n (This : in out Three_Axis_Gyroscope;\n Mode_Selection : High_Pass_Filter_Mode;\n Cutoff_Frequency : High_Pass_Cutoff_Frequency)\n is\n Ctrl2 : UInt8;\n begin\n -- note that the two high-order bits must remain zero, per the datasheet\n Ctrl2 := As_UInt8 (Mode_Selection) or As_UInt8 (Cutoff_Frequency);\n Write (This, CTRL_REG2, Ctrl2);\n end Configure_High_Pass_Filter;\n\n -----------------------------\n -- Enable_High_Pass_Filter --\n -----------------------------\n\n procedure Enable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set HPen bit\n Ctrl5 := Ctrl5 or HighPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_High_Pass_Filter;\n\n ------------------------------\n -- Disable_High_Pass_Filter --\n ------------------------------\n\n procedure Disable_High_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not HighPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_High_Pass_Filter;\n\n ----------------------------\n -- Enable_Low_Pass_Filter --\n ----------------------------\n\n procedure Enable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or LowPass_Filter_Enable;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_Low_Pass_Filter;\n\n -----------------------------\n -- Disable_Low_Pass_Filter --\n -----------------------------\n\n procedure Disable_Low_Pass_Filter (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- clear HPen bit\n Ctrl5 := Ctrl5 and (not LowPass_Filter_Enable);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_Low_Pass_Filter;\n\n ---------------------\n -- Reference_Value --\n ---------------------\n\n function Reference_Value (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Reference, Result);\n return Result;\n end Reference_Value;\n\n -------------------\n -- Set_Reference --\n -------------------\n\n procedure Set_Reference (This : in out Three_Axis_Gyroscope; Value : UInt8) is\n begin\n Write (This, Reference, Value);\n end Set_Reference;\n\n -----------------\n -- Data_Status --\n -----------------\n\n function Data_Status (This : Three_Axis_Gyroscope) return Gyro_Data_Status is\n Result : UInt8;\n function As_Gyro_Data_Status is\n new Ada.Unchecked_Conversion (Source => UInt8,\n Target => Gyro_Data_Status);\n begin\n Read (This, Status, Result);\n return As_Gyro_Data_Status (Result);\n end Data_Status;\n\n ---------------\n -- Device_Id --\n ---------------\n\n function Device_Id (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, Who_Am_I, Result);\n return Result;\n end Device_Id;\n\n -----------------\n -- Temperature --\n -----------------\n\n function Temperature (This : Three_Axis_Gyroscope) return UInt8 is\n Result : UInt8;\n begin\n Read (This, OUT_Temp, Result);\n return Result;\n end Temperature;\n\n ------------\n -- Reboot --\n ------------\n\n procedure Reboot (This : Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n -- set the boot bit\n Ctrl5 := Ctrl5 or Boot_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Reboot;\n\n ----------------------------\n -- Full_Scale_Sensitivity --\n ----------------------------\n\n function Full_Scale_Sensitivity (This : Three_Axis_Gyroscope) return Float is\n Ctrl4 : UInt8;\n Result : Float;\n Fullscale_Selection : UInt8;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Fullscale_Selection := Ctrl4 and Fullscale_Selection_Bits;\n\n if Fullscale_Selection = L3GD20_Fullscale_250'Enum_Rep then\n Result := Sensitivity_250dps;\n elsif Fullscale_Selection = L3GD20_Fullscale_500'Enum_Rep then\n Result := Sensitivity_500dps;\n else\n Result := Sensitivity_2000dps;\n end if;\n\n return Result;\n end Full_Scale_Sensitivity;\n\n -------------------------\n -- Get_Raw_Angle_Rates --\n -------------------------\n\n procedure Get_Raw_Angle_Rates\n (This : Three_Axis_Gyroscope;\n Rates : out Angle_Rates)\n is\n\n Ctrl4 : UInt8;\n\n UInt8s_To_Read : constant Integer := 6; -- ie, three 2-UInt8 integers\n -- the number of UInt8s in an Angle_Rates record object\n\n Received : SPI_Data_8b (1 .. UInt8s_To_Read);\n\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n -- The above has the effect of separate reads, as follows:\n -- Read (This, OUT_X_L, Received (1));\n -- Read (This, OUT_X_H, Received (2));\n -- Read (This, OUT_Y_L, Received (3));\n -- Read (This, OUT_Y_H, Received (4));\n -- Read (This, OUT_Z_L, Received (5));\n -- Read (This, OUT_Z_H, Received (6));\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n Swap2 (Received (1)'Address);\n Swap2 (Received (3)'Address);\n Swap2 (Received (5)'Address);\n end if;\n\n Rates.X := As_Angle_Rate_Pointer (Received (1)'Address).all;\n Rates.Y := As_Angle_Rate_Pointer (Received (3)'Address).all;\n Rates.Z := As_Angle_Rate_Pointer (Received (5)'Address).all;\n end Get_Raw_Angle_Rates;\n\n --------------------------\n -- Configure_Interrupt1 --\n --------------------------\n\n procedure Configure_Interrupt1\n (This : in out Three_Axis_Gyroscope;\n Triggers : Threshold_Event_List;\n Latched : Boolean := False;\n Active_Edge : Interrupt1_Active_Edge := L3GD20_Interrupt1_High_Edge;\n Combine_Events : Boolean := False;\n Sample_Count : Sample_Counter := 0)\n is\n Config : UInt8;\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and 16#DF#;\n Ctrl3 := Ctrl3 or Active_Edge'Enum_Rep;\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n\n if Sample_Count > 0 then\n Set_Duration_Counter (This, Sample_Count);\n end if;\n\n Config := 0;\n\n if Latched then\n Config := Config or Int1_Latch_Enable_Bit;\n end if;\n\n if Combine_Events then\n Config := Config or Logically_And_Or_Events_Bit;\n end if;\n\n for Event of Triggers loop\n Config := Config or Axes_Interrupt_Enablers (Event.Axis);\n end loop;\n\n Write (This, INT1_CFG, Config);\n\n for Event of Triggers loop\n Set_Threshold (This, Event.Axis, Event.Threshold);\n end loop;\n end Configure_Interrupt1;\n\n ----------------------------\n -- Set_Interrupt_Pin_Mode --\n ----------------------------\n\n procedure Set_Interrupt_Pin_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : Pin_Modes)\n is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not Interrupt_Pin_Mode_Bit);\n Ctrl3 := Ctrl3 or Mode'Enum_Rep;\n Write (This, CTRL_REG3, Ctrl3);\n end Set_Interrupt_Pin_Mode;\n\n -----------------------\n -- Enable_Interrupt1 --\n -----------------------\n\n procedure Enable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 or INT1_Interrupt_Enable;\n Write (This, CTRL_REG3, Ctrl3);\n end Enable_Interrupt1;\n\n ------------------------\n -- Disable_Interrupt1 --\n ------------------------\n\n procedure Disable_Interrupt1 (This : in out Three_Axis_Gyroscope) is\n Ctrl3 : UInt8;\n begin\n Read (This, CTRL_REG3, Ctrl3);\n Ctrl3 := Ctrl3 and (not INT1_Interrupt_Enable);\n Write (This, CTRL_REG3, Ctrl3);\n end Disable_Interrupt1;\n\n -----------------------\n -- Interrupt1_Status --\n -----------------------\n\n function Interrupt1_Source (This : Three_Axis_Gyroscope) return Interrupt1_Sources is\n Result : UInt8;\n function As_Interrupt_Source is new Ada.Unchecked_Conversion\n (Source => UInt8, Target => Interrupt1_Sources);\n begin\n Read (This, INT1_SRC, Result);\n return As_Interrupt_Source (Result);\n end Interrupt1_Source;\n\n --------------------------\n -- Set_Duration_Counter --\n --------------------------\n\n procedure Set_Duration_Counter\n (This : in out Three_Axis_Gyroscope;\n Value : Sample_Counter)\n is\n Wait_Bit : constant := 2#1000_0000#;\n begin\n Write (This, INT1_Duration, UInt8 (Value) or Wait_Bit);\n end Set_Duration_Counter;\n\n ------------------\n -- Enable_Event --\n ------------------\n\n procedure Enable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config or Axes_Interrupt_Enablers (Event);\n Write (This, INT1_CFG, Config);\n end Enable_Event;\n\n -------------------\n -- Disable_Event --\n -------------------\n\n procedure Disable_Event\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts)\n is\n Config : UInt8;\n begin\n Read (This, INT1_CFG, Config);\n Config := Config and (not Axes_Interrupt_Enablers (Event));\n Write (This, INT1_CFG, Config);\n end Disable_Event;\n\n -------------------\n -- Set_Threshold --\n -------------------\n\n procedure Set_Threshold\n (This : in out Three_Axis_Gyroscope;\n Event : Axes_Interrupts;\n Value : Axis_Sample_Threshold)\n is\n begin\n case Event is\n when Z_High_Interrupt | Z_Low_Interrupt =>\n Write (This, INT1_TSH_ZL, UInt8 (Value));\n Write (This, INT1_TSH_ZH, UInt8 (Shift_Right (Value, 8)));\n\n when Y_High_Interrupt | Y_Low_Interrupt =>\n Write (This, INT1_TSH_YL, UInt8 (Value));\n Write (This, INT1_TSH_YH, UInt8 (Shift_Right (Value, 8)));\n\n when X_High_Interrupt | X_Low_Interrupt =>\n Write (This, INT1_TSH_XL, UInt8 (Value));\n Write (This, INT1_TSH_XH, UInt8 (Shift_Right (Value, 8)));\n end case;\n end Set_Threshold;\n\n -------------------\n -- Set_FIFO_Mode --\n -------------------\n\n procedure Set_FIFO_Mode\n (This : in out Three_Axis_Gyroscope;\n Mode : FIFO_Modes)\n is\n FIFO : UInt8;\n begin\n Read (This, FIFO_CTRL, FIFO);\n FIFO := FIFO and (not FIFO_Mode_Bits); -- clear the current bits\n FIFO := FIFO or Mode'Enum_Rep;\n Write (This, FIFO_CTRL, FIFO);\n end Set_FIFO_Mode;\n\n -----------------\n -- Enable_FIFO --\n -----------------\n\n procedure Enable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 or FIFO_Enable_Bit;\n Write (This, CTRL_REG5, Ctrl5);\n end Enable_FIFO;\n\n ------------------\n -- Disable_FIFO --\n ------------------\n\n procedure Disable_FIFO (This : in out Three_Axis_Gyroscope) is\n Ctrl5 : UInt8;\n begin\n Read (This, CTRL_REG5, Ctrl5);\n Ctrl5 := Ctrl5 and (not FIFO_Enable_Bit);\n Write (This, CTRL_REG5, Ctrl5);\n end Disable_FIFO;\n\n ------------------------\n -- Set_FIFO_Watermark --\n ------------------------\n\n procedure Set_FIFO_Watermark\n (This : in out Three_Axis_Gyroscope;\n Level : FIFO_Level)\n is\n Value : UInt8;\n begin\n Read (This, FIFO_CTRL, Value);\n Value := Value and (not Watermark_Threshold_Bits); -- clear the bits\n Value := Value or UInt8 (Level);\n Write (This, FIFO_CTRL, Value);\n end Set_FIFO_Watermark;\n\n ------------------------------\n -- Get_Raw_Angle_Rates_FIFO --\n ------------------------------\n\n procedure Get_Raw_Angle_Rates_FIFO\n (This : in out Three_Axis_Gyroscope;\n Buffer : out Angle_Rates_FIFO_Buffer)\n is\n Ctrl4 : UInt8;\n\n Angle_Rate_Size : constant Integer := 6; -- UInt8s\n UInt8s_To_Read : constant Integer := Buffer'Length * Angle_Rate_Size;\n Received : SPI_Data_8b (0 .. UInt8s_To_Read - 1)\n with Alignment => 2;\n begin\n Read (This, CTRL_REG4, Ctrl4);\n\n Read_UInt8s (This, OUT_X_L, Received, UInt8s_To_Read);\n\n if (Ctrl4 and Endian_Selection_Mask) = L3GD20_Big_Endian'Enum_Rep then\n declare\n J : Integer := 0;\n begin\n for K in Received'First .. Received'Last / 2 loop\n Swap2 (Received (J)'Address);\n J := J + 2;\n end loop;" + }, + { + "function_def": "function Read_Revision (This : VL53L0X_Ranging_Sensor) return HAL.UInt8", + "function_body": "is\n Ret : UInt8;\n Status : Boolean;\n begin\n Read (This, REG_IDENTIFICATION_REVISION_ID, Ret, Status);\n\n if not Status then\n return 0;\n else\n return Ret;\n end if;\n end Read_Revision;\n\n ------------------------\n -- Set_Device_Address --\n ------------------------\n\n procedure Set_Device_Address\n (This : in out VL53L0X_Ranging_Sensor;\n Addr : HAL.I2C.I2C_Address;\n Status : out Boolean)\n is\n begin\n Write (This, REG_I2C_SLAVE_DEVICE_ADDRESS, UInt8 (Addr / 2), Status);\n if Status then\n This.I2C_Address := Addr;\n end if;\n end Set_Device_Address;\n\n ---------------\n -- Data_Init --\n ---------------\n\n procedure Data_Init\n (This : in out VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n Regval : UInt8;\n begin\n -- Set I2C Standard mode\n Write (This, 16#88#, UInt8'(16#00#), Status);\n\n if not Status then\n return;\n end if;\n\n-- This.Device_Specific_Params.Read_Data_From_Device_Done := False;\n--\n-- -- Set default static parameters:\n-- -- set first temporary value 9.44MHz * 65536 = 618_660\n-- This.Device_Specific_Params.Osc_Frequency := 618_660;\n--\n-- -- Set default cross talk compenstation rate to 0\n-- This.Device_Params.X_Talk_Compensation_Rate_Mcps := 0.0;\n--\n-- This.Device_Params.Device_Mode := Single_Ranging;\n-- This.Device_Params.Histogram_Mode := Disabled;\n\n -- TODO: Sigma estimator variable\n if Status then\n Write (This, 16#80#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Read (This, 16#91#, This.Stop_Variable, Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n -- disable SIGNAL_RATE_MSRC (bit 1) and SIGNAL_RATE_PRE_RANGE (bit 4)\n -- limit checks\n if Status then\n Read (This, REG_MSRC_CONFIG_CONTROL, Regval, Status);\n end if;\n\n if Status then\n Write (This, REG_MSRC_CONFIG_CONTROL, Regval or 16#12#, Status);\n end if;\n\n if Status then\n -- Set final range signal rate limit to 0.25 MCPS\n Status := Set_Signal_Rate_Limit (This, 0.25);\n end if;\n\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#FF#), Status);\n end if;\n end Data_Init;\n\n -----------------\n -- Static_Init --\n -----------------\n\n procedure Static_Init\n (This : in out VL53L0X_Ranging_Sensor;\n GPIO_Function : VL53L0X_GPIO_Functionality;\n Status : out Boolean)\n is\n type SPAD_Map is array (UInt8 range 1 .. 48) of Boolean\n with Pack, Size => 48;\n subtype SPAD_Map_Bytes is UInt8_Array (1 .. 6);\n function To_Map is new Ada.Unchecked_Conversion\n (SPAD_Map_Bytes, SPAD_Map);\n function To_Bytes is new Ada.Unchecked_Conversion\n (SPAD_Map, SPAD_Map_Bytes);\n\n SPAD_Count : UInt8;\n SPAD_Is_Aperture : Boolean;\n Ref_SPAD_Map_Bytes : SPAD_Map_Bytes;\n Ref_SPAD_Map : SPAD_Map;\n First_SPAD : UInt8;\n SPADS_Enabled : UInt8;\n Timing_Budget : UInt32;\n\n begin\n Status := SPAD_Info (This, SPAD_Count, SPAD_Is_Aperture);\n\n if not Status then\n return;\n end if;\n\n Read\n (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n Ref_SPAD_Map := To_Map (Ref_SPAD_Map_Bytes);\n\n -- Set reference spads\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_REF_EN_START_OFFSET,\n UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD,\n UInt8'(16#2C#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, REG_GLOBAL_CONFIG_REF_EN_START_SELECT,\n UInt8'(16#B4#), Status);\n end if;\n\n if Status then\n if SPAD_Is_Aperture then\n First_SPAD := 13;\n else\n First_SPAD := 1;\n end if;\n\n SPADS_Enabled := 0;\n\n for J in UInt8 range 1 .. 48 loop\n\n if J < First_SPAD or else SPADS_Enabled = SPAD_Count then\n -- This bit is lower than the first one that should be enabled,\n -- or SPAD_Count bits have already been enabled, so zero this\n -- bit\n Ref_SPAD_Map (J) := False;\n\n elsif Ref_SPAD_Map (J) then\n SPADS_Enabled := SPADS_Enabled + 1;\n end if;\n end loop;\n end if;\n\n if Status then\n Ref_SPAD_Map_Bytes := To_Bytes (Ref_SPAD_Map);\n Write (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,\n Ref_SPAD_Map_Bytes, Status);\n end if;\n\n -- Load tuning Settings\n -- default tuning settings from vl53l0x_tuning.h\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#09#, UInt8'(16#00#), Status);\n Write (This, 16#10#, UInt8'(16#00#), Status);\n Write (This, 16#11#, UInt8'(16#00#), Status);\n\n Write (This, 16#24#, UInt8'(16#01#), Status);\n Write (This, 16#25#, UInt8'(16#FF#), Status);\n Write (This, 16#75#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#4E#, UInt8'(16#2C#), Status);\n Write (This, 16#48#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#20#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#30#, UInt8'(16#09#), Status);\n Write (This, 16#54#, UInt8'(16#00#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#32#, UInt8'(16#03#), Status);\n Write (This, 16#40#, UInt8'(16#83#), Status);\n Write (This, 16#46#, UInt8'(16#25#), Status);\n Write (This, 16#60#, UInt8'(16#00#), Status);\n Write (This, 16#27#, UInt8'(16#00#), Status);\n Write (This, 16#50#, UInt8'(16#06#), Status);\n Write (This, 16#51#, UInt8'(16#00#), Status);\n Write (This, 16#52#, UInt8'(16#96#), Status);\n Write (This, 16#56#, UInt8'(16#08#), Status);\n Write (This, 16#57#, UInt8'(16#30#), Status);\n Write (This, 16#61#, UInt8'(16#00#), Status);\n Write (This, 16#62#, UInt8'(16#00#), Status);\n Write (This, 16#64#, UInt8'(16#00#), Status);\n Write (This, 16#65#, UInt8'(16#00#), Status);\n Write (This, 16#66#, UInt8'(16#A0#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#22#, UInt8'(16#32#), Status);\n Write (This, 16#47#, UInt8'(16#14#), Status);\n Write (This, 16#49#, UInt8'(16#FF#), Status);\n Write (This, 16#4A#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#7A#, UInt8'(16#0A#), Status);\n Write (This, 16#7B#, UInt8'(16#00#), Status);\n Write (This, 16#78#, UInt8'(16#21#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#23#, UInt8'(16#34#), Status);\n Write (This, 16#42#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#FF#), Status);\n Write (This, 16#45#, UInt8'(16#26#), Status);\n Write (This, 16#46#, UInt8'(16#05#), Status);\n Write (This, 16#40#, UInt8'(16#40#), Status);\n Write (This, 16#0E#, UInt8'(16#06#), Status);\n Write (This, 16#20#, UInt8'(16#1A#), Status);\n Write (This, 16#43#, UInt8'(16#40#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#34#, UInt8'(16#03#), Status);\n Write (This, 16#35#, UInt8'(16#44#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#31#, UInt8'(16#04#), Status);\n Write (This, 16#4B#, UInt8'(16#09#), Status);\n Write (This, 16#4C#, UInt8'(16#05#), Status);\n Write (This, 16#4D#, UInt8'(16#04#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#44#, UInt8'(16#00#), Status);\n Write (This, 16#45#, UInt8'(16#20#), Status);\n Write (This, 16#47#, UInt8'(16#08#), Status);\n Write (This, 16#48#, UInt8'(16#28#), Status);\n Write (This, 16#67#, UInt8'(16#00#), Status);\n Write (This, 16#70#, UInt8'(16#04#), Status);\n Write (This, 16#71#, UInt8'(16#01#), Status);\n Write (This, 16#72#, UInt8'(16#FE#), Status);\n Write (This, 16#76#, UInt8'(16#00#), Status);\n Write (This, 16#77#, UInt8'(16#00#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#0D#, UInt8'(16#01#), Status);\n\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#01#), Status);\n Write (This, 16#01#, UInt8'(16#F8#), Status);\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, 16#8E#, UInt8'(16#01#), Status);\n Write (This, 16#00#, UInt8'(16#01#), Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n Set_GPIO_Config (This, GPIO_Function, Polarity_High, Status);\n\n if Status then\n Timing_Budget := Measurement_Timing_Budget (This);\n\n -- Disable MSRC and TCC by default\n -- MSRC = Minimum Signal Rate Check\n -- TCC = Target CenterCheck\n\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n\n -- Recalculate the timing Budget\n if Status then\n Set_Measurement_Timing_Budget (This, Timing_Budget, Status);\n end if;\n end Static_Init;\n\n ------------------------------------\n -- Perform_Single_Ref_Calibration --\n ------------------------------------\n\n procedure Perform_Single_Ref_Calibration\n (This : VL53L0X_Ranging_Sensor;\n VHV_Init : UInt8;\n Status : out Boolean)\n is\n Val : UInt8;\n\n begin\n Write (This, REG_SYSRANGE_START, VHV_Init or 16#01#, Status);\n\n if not Status then\n return;\n end if;\n\n loop\n Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);\n exit when not Status;\n exit when (Val and 16#07#) /= 0;\n end loop;\n\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_SYSRANGE_START, UInt8'(16#00#), Status);\n end Perform_Single_Ref_Calibration;\n\n -----------------------------\n -- Perform_Ref_Calibration --\n -----------------------------\n\n procedure Perform_Ref_Calibration\n (This : in out VL53L0X_Ranging_Sensor;\n Status : out Boolean)\n is\n begin\n -- VHV calibration\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#01#), Status);\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#40#, Status);\n end if;\n\n -- Phase calibration\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#02#), Status);\n end if;\n\n if Status then\n Perform_Single_Ref_Calibration (This, 16#00#, Status);\n end if;\n\n -- Restore the sequence config\n if Status then\n Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);\n end if;\n end Perform_Ref_Calibration;\n\n ----------------------\n -- Start_Continuous --\n ----------------------\n\n procedure Start_Continuous (This : VL53L0X.VL53L0X_Ranging_Sensor;\n Period_Ms : HAL.UInt32;\n Status : out Boolean) is\n -- From vl53l0xStartContinuous() in\n -- crazyflie-firmware/src/drivers/src/vl53l0x.c\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#ff#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#91#, UInt8'(This.Stop_Variable), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#ff#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n if not Status then\n return;\n end if;\n if Period_Ms /= 0 then\n -- continuous timed mode\n declare\n procedure Set_Inter_Measurement_Period_Milliseconds;\n -- The Crazyflie code indicates that this is a missing\n -- function that they've inlined.\n procedure Set_Inter_Measurement_Period_Milliseconds is\n Osc_Calibrate_Val : UInt16;\n Period : UInt32 := Period_Ms;\n begin\n Read (This, REG_OSC_CALIBRATE_VAL, Osc_Calibrate_Val, Status);\n if Status and then Osc_Calibrate_Val /= 0 then\n Period := Period * UInt32 (Osc_Calibrate_Val);\n end if;\n if Status then\n Write\n (This, REG_SYSTEM_INTERMEASUREMENT_PERIOD, Period, Status);\n end if;\n end Set_Inter_Measurement_Period_Milliseconds;\n begin\n Set_Inter_Measurement_Period_Milliseconds;\n if Status then\n Write (This,\n REG_SYSRANGE_START,\n UInt8'(REG_SYSRANGE_MODE_TIMED),\n Status);\n end if;" + }, + { + "function_def": "function To_U32 is new Ada.Unchecked_Conversion", + "function_body": "(Fix_Point_16_16, UInt32);\n Val : UInt16;\n Status : Boolean;\n begin\n -- Expecting Fixed Point 9.7\n Val := UInt16 (Shift_Right (To_U32 (Limit_Mcps), 9) and 16#FF_FF#);\n Write (This,\n REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Val,\n Status);\n return Status;\n end Set_Signal_Rate_Limit;\n\n ---------------\n -- SPAD_Info --\n ---------------\n\n function SPAD_Info\n (This : VL53L0X_Ranging_Sensor;\n SPAD_Count : out HAL.UInt8;\n Is_Aperture : out Boolean) return Boolean\n is\n Status : Boolean;\n Tmp : UInt8;\n begin\n Write (This, 16#80#, UInt8'(16#01#), Status);\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#00#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp or 16#04#, Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#07#), Status);\n end if;\n if Status then\n Write (This, 16#81#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#80#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#94#, UInt8'(16#6B#), Status);\n end if;\n if Status then\n Write (This, 16#83#, UInt8'(16#00#), Status);\n end if;\n\n loop\n exit when not Status;\n Read (This, 16#83#, Tmp, Status);\n exit when Tmp /= 0;\n end loop;\n\n if Status then\n Write (This, 16#83#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Read (This, 16#92#, Tmp, Status);\n end if;\n\n if Status then\n SPAD_Count := Tmp and 16#7F#;\n Is_Aperture := (Tmp and 16#80#) /= 0;\n\n Write (This, 16#81#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#06#), Status);\n end if;\n if Status then\n Read (This, 16#83#, Tmp, Status);\n end if;\n if Status then\n Write (This, 16#83#, Tmp and not 16#04#, Status);\n end if;\n if Status then\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n end if;\n if Status then\n Write (This, 16#00#, UInt8'(16#01#), Status);\n end if;\n\n if Status then\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n end if;\n if Status then\n Write (This, 16#80#, UInt8'(16#00#), Status);\n end if;\n\n return Status;\n end SPAD_Info;\n\n ---------------------------\n -- Set_Signal_Rate_Limit --\n ---------------------------\n\n procedure Set_Signal_Rate_Limit\n (This : VL53L0X_Ranging_Sensor;\n Rate_Limit : Fix_Point_16_16)\n is\n function To_U32 is new Ada.Unchecked_Conversion\n (Fix_Point_16_16, UInt32);\n Reg : UInt16;\n Status : Boolean with Unreferenced;\n begin\n -- Encoded as Fixed Point 9.7. Let's translate.\n Reg := UInt16 (Shift_Right (To_U32 (Rate_Limit), 9) and 16#FFFF#);\n Write (This, REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,\n Reg, Status);\n end Set_Signal_Rate_Limit;\n\n --------------------------------------\n -- Set_Vcsel_Pulse_Period_Pre_Range --\n --------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Pre_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Pre_Range, Status);\n end Set_VCSEL_Pulse_Period_Pre_Range;\n\n ----------------------------------------\n -- Set_Vcsel_Pulse_Period_Final_Range --\n ----------------------------------------\n\n procedure Set_VCSEL_Pulse_Period_Final_Range\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Status : out Boolean)\n is\n begin\n Set_VCSel_Pulse_Period (This, Period, Final_Range, Status);\n end Set_VCSEL_Pulse_Period_Final_Range;\n\n ----------------------------\n -- Set_VCSel_Pulse_Period --\n ----------------------------\n\n procedure Set_VCSel_Pulse_Period\n (This : VL53L0X_Ranging_Sensor;\n Period : UInt8;\n Sequence : VL53L0x_Sequence_Step;\n Status : out Boolean)\n is\n Encoded : constant UInt8 := Shift_Right (Period, 1) - 1;\n Phase_High : UInt8;\n Pre_Timeout : UInt32;\n Final_Timeout : UInt32;\n Msrc_Timeout : UInt32;\n Timeout_Mclks : UInt32;\n Steps_Enabled : constant VL53L0x_Sequence_Step_Enabled :=\n Sequence_Step_Enabled (This);\n Budget : UInt32;\n Sequence_Cfg : UInt8;\n\n begin\n -- Save the measurement timing budget\n Budget := Measurement_Timing_Budget (This);\n\n case Sequence is\n when Pre_Range =>\n Pre_Timeout := Sequence_Step_Timeout (This, Pre_Range);\n Msrc_Timeout := Sequence_Step_Timeout (This, MSRC);\n\n case Period is\n when 12 =>\n Phase_High := 16#18#;\n when 14 =>\n Phase_High := 16#30#;\n when 16 =>\n Phase_High := 16#40#;\n when 18 =>\n Phase_High := 16#50#;\n when others =>\n Status := False;\n\n return;\n end case;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,\n Encoded, Status);\n if not Status then\n return;\n end if;\n\n -- Update the timeouts\n Timeout_Mclks := To_Timeout_Mclks (Pre_Timeout, Period);\n Write (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,\n UInt16 (Timeout_Mclks), Status);\n\n Timeout_Mclks := To_Timeout_Mclks (Msrc_Timeout, Period);\n if Timeout_Mclks > 256 then\n Timeout_Mclks := 255;\n else\n Timeout_Mclks := Timeout_Mclks - 1;\n end if;\n\n Write (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,\n UInt8 (Timeout_Mclks), Status);\n\n when Final_Range =>\n Pre_Timeout := Sequence_Step_Timeout\n (This, Pre_Range, As_Mclks => True);\n Final_Timeout := Sequence_Step_Timeout (This, Final_Range);\n\n declare\n Phase_High : UInt8;\n Width : UInt8;\n Cal_Timeout : UInt8;\n Cal_Lim : UInt8;\n begin\n case Period is\n when 8 =>\n Phase_High := 16#10#;\n Width := 16#02#;\n Cal_Timeout := 16#0C#;\n Cal_Lim := 16#30#;\n when 10 =>\n Phase_High := 16#28#;\n Width := 16#03#;\n Cal_Timeout := 16#09#;\n Cal_Lim := 16#20#;\n when 12 =>\n Phase_High := 16#38#;\n Width := 16#03#;\n Cal_Timeout := 16#08#;\n Cal_Lim := 16#20#;\n when 14 =>\n Phase_High := 16#48#;\n Width := 16#03#;\n Cal_Timeout := 16#07#;\n Cal_Lim := 16#20#;\n when others =>\n return;\n end case;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,\n Phase_High, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,\n UInt8'(16#08#), Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_GLOBAL_CONFIG_VCSEL_WIDTH,\n Width, Status);\n if not Status then\n return;\n end if;\n\n Write (This, REG_ALGO_PHASECAL_CONFIG_TIMEOUT,\n Cal_Timeout, Status);\n if not Status then\n return;\n end if;\n\n Write (This, 16#FF#, UInt8'(16#01#), Status);\n Write (This, REG_ALGO_PHASECAL_LIM,\n Cal_Lim, Status);\n Write (This, 16#FF#, UInt8'(16#00#), Status);\n if not Status then\n return;\n end if;" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT6206_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n begin\n if Touch_Id not in FT6206_Px_Regs'Range then\n return (0, 0, 0);\n end if;\n\n if Touch_Id > This.Active_Touch_Points then\n return (0, 0, 0);\n end if;\n\n -- X/Y are swaped from the screen coordinates\n\n Regs := FT6206_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT6206_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n if Ret.Weight = 0 then\n Ret.Weight := 50;\n end if;\n\n Ret.X := Natural'Max (0, Ret.X);\n Ret.Y := Natural'Max (0, Ret.Y);\n Ret.X := Natural'Min (This.LCD_Natural_Width - 1, Ret.X);\n Ret.Y := Natural'Min (This.LCD_Natural_Height - 1, Ret.Y);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "function Read_Register (This : STMPE811_Device;", + "function_body": "Reg_Addr : UInt8) return UInt8\n is\n Data : TSC_Data (1 .. 1);\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Read (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n Data,\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n\n return Data (1);\n end Read_Register;\n\n --------------------\n -- Write_Register --\n --------------------\n\n procedure Write_Register (This : in out STMPE811_Device;\n Reg_Addr : UInt8;\n Data : UInt8) is\n Status : I2C_Status;\n\n begin\n This.Port.Mem_Write (This.I2C_Addr,\n UInt16 (Reg_Addr),\n Memory_Size_8b,\n (1 => Data),\n Status);\n\n if Status /= Ok then\n raise Program_Error with \"Timeout while reading TC data\";\n end if;\n end Write_Register;\n\n ---------------\n -- IOE_Reset --\n ---------------\n\n procedure IOE_Reset (This : in out STMPE811_Device) is\n begin\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#02#);\n\n -- Give some time for the reset\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_SYS_CTRL1, 16#00#);\n end IOE_Reset;\n\n --------------------------\n -- IOE_Function_Command --\n --------------------------\n\n procedure IOE_Function_Command (This : in out STMPE811_Device;\n Func : UInt8;\n Enabled : Boolean)\n is\n Reg : UInt8 := This.Read_Register (IOE_REG_SYS_CTRL2);\n begin\n -- CTRL2 functions are disabled when corresponding bit is set\n\n if Enabled then\n Reg := Reg and (not Func);\n else\n Reg := Reg or Func;\n end if;\n\n This.Write_Register (IOE_REG_SYS_CTRL2, Reg);\n end IOE_Function_Command;\n\n -------------------\n -- IOE_AF_Config --\n -------------------\n\n procedure IOE_AF_Config (This : in out STMPE811_Device;\n Pin : UInt8;\n Enabled : Boolean) is\n Reg : UInt8 := This.Read_Register (IOE_REG_GPIO_AF);\n begin\n if Enabled then\n Reg := Reg or Pin;\n else\n Reg := Reg and (not Pin);\n end if;\n\n This.Write_Register (IOE_REG_GPIO_AF, Reg);\n end IOE_AF_Config;\n\n ----------------\n -- Get_IOE_ID --\n ----------------\n\n function Get_IOE_ID (This : in out STMPE811_Device) return UInt16 is\n begin\n return (UInt16 (This.Read_Register (0)) * (2**8))\n or UInt16 (This.Read_Register (1));\n end Get_IOE_ID;\n\n ----------------\n -- Initialize --\n ----------------\n\n function Initialize (This : in out STMPE811_Device) return Boolean\n is\n begin\n\n This.Time.Delay_Milliseconds (100);\n\n if This.Get_IOE_ID /= 16#0811# then\n return False;\n end if;\n\n This.IOE_Reset;\n\n This.IOE_Function_Command (IOE_ADC_FCT, True);\n This.IOE_Function_Command (IOE_TSC_FCT, True);\n\n This.Write_Register (IOE_REG_ADC_CTRL1, 16#49#);\n\n This.Time.Delay_Milliseconds (2);\n\n This.Write_Register (IOE_REG_ADC_CTRL2, 16#01#);\n\n This.IOE_AF_Config (TOUCH_IO_ALL, False);\n\n This.Write_Register (IOE_REG_TSC_CFG, 16#9A#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n\n This.Write_Register (IOE_REG_FIFO_TH, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_FRACT_Z, 16#00#);\n\n This.Write_Register (IOE_REG_TSC_I_DRIVE, 16#01#);\n\n This.Write_Register (IOE_REG_TSC_CTRL, 16#01#);\n\n This.Write_Register (IOE_REG_INT_STA, 16#FF#);\n\n return True;\n end Initialize;\n\n ----------------\n -- Set_Bounds --\n ----------------\n\n overriding\n procedure Set_Bounds (This : in out STMPE811_Device;\n Width : Natural;\n Height : Natural;\n Swap : HAL.Touch_Panel.Swap_State)\n is\n begin\n This.LCD_Natural_Width := Width;\n This.LCD_Natural_Height := Height;\n This.Swap := Swap;\n end Set_Bounds;\n\n -------------------------\n -- Active_Touch_Points --\n -------------------------\n\n overriding\n function Active_Touch_Points (This : in out STMPE811_Device)\n return Touch_Identifier\n is\n Val : constant UInt8 := This.Read_Register (IOE_REG_TSC_CTRL) and 16#80#;\n begin\n if Val = 0 then\n This.Write_Register (IOE_REG_FIFO_STA, 16#01#);\n This.Write_Register (IOE_REG_FIFO_STA, 16#00#);\n\n return 0;\n else\n return 1;\n end if;\n end Active_Touch_Points;\n\n ---------------------\n -- Get_Touch_Point --\n ---------------------\n\n overriding\n function Get_Touch_Point (This : in out STMPE811_Device;\n Touch_Id : Touch_Identifier)\n return TP_Touch_State\n is\n State : TP_Touch_State;\n Raw_X : UInt32;\n Raw_Y : UInt32;\n Raw_Z : UInt32;\n X : Integer;\n Y : Integer;\n Tmp : Integer;\n\n begin\n\n -- Check Touch detected bit in CTRL register\n if Touch_Id /= 1 or else This.Active_Touch_Points = 0 then\n return (0, 0, 0);\n end if;\n\n declare\n Data_X : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_X, 2);\n Data_Y : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Y, 2);\n Data_Z : constant TSC_Data := This.Read_Data (IOE_REG_TSC_DATA_Z, 1);\n Z_Frac : constant TSC_Data := This.Read_Data (IOE_REG_TSC_FRACT_Z, 1);\n\n begin\n Raw_X := 2 ** 12 -\n (Shift_Left (UInt32 (Data_X (1)) and 16#0F#, 8) or UInt32 (Data_X (2)));\n Raw_Y :=\n Shift_Left (UInt32 (Data_Y (1)) and 16#0F#, 8) or UInt32 (Data_Y (2));\n Raw_Z :=\n Shift_Right (UInt32 (Data_Z (1)), Natural (Z_Frac (1) and 2#111#));" + }, + { + "function_def": "function To_UInt16 is", + "function_body": "new Ada.Unchecked_Conversion (UInt16_HL_Type, UInt16);\n\n Ret : TP_Touch_State;\n Regs : FT5336_Pressure_Registers;\n Tmp : UInt16_HL_Type;\n Status : Boolean;\n\n begin\n -- X/Y are swaped from the screen coordinates\n\n if Touch_Id not in FT5336_Px_Regs'Range\n or else Touch_Id > This.Active_Touch_Points\n then\n return (0, 0, 0);\n end if;\n\n Regs := FT5336_Px_Regs (Touch_Id);\n\n Tmp.Low := This.I2C_Read (Regs.XL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.XH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.Y := Natural (To_UInt16 (Tmp));\n\n Tmp.Low := This.I2C_Read (Regs.YL_Reg, Status);\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Tmp.High := This.I2C_Read (Regs.YH_Reg, Status) and\n FT5336_TOUCH_POS_MSB_MASK;\n\n if not Status then\n return (0, 0, 0);\n end if;\n\n Ret.X := Natural (To_UInt16 (Tmp));\n\n Ret.Weight := Natural (This.I2C_Read (Regs.Weight_Reg, Status));\n\n if not Status then\n Ret.Weight := 0;\n end if;\n\n Ret.X :=\n Natural'Min (Natural'Max (0, Ret.X), This.LCD_Natural_Width - 1);\n Ret.Y :=\n Natural'Min (Natural'Max (0, Ret.Y), This.LCD_Natural_Height - 1);\n\n if (This.Swap and Invert_X) /= 0 then\n Ret.X := This.LCD_Natural_Width - Ret.X - 1;\n end if;\n if (This.Swap and Invert_Y) /= 0 then\n Ret.Y := This.LCD_Natural_Height - Ret.Y - 1;\n end if;\n if (This.Swap and Swap_XY) /= 0 then\n declare\n Tmp_X : constant Integer := Ret.X;\n begin\n Ret.X := Ret.Y;\n Ret.Y := Tmp_X;" + }, + { + "function_def": "procedure adainit is", + "function_body": "Binder_Sec_Stacks_Count : Natural;\n pragma Import (Ada, Binder_Sec_Stacks_Count, \"__gnat_binder_ss_count\");\n\n Default_Secondary_Stack_Size : System.Parameters.Size_Type;\n pragma Import (C, Default_Secondary_Stack_Size, \"__gnat_default_ss_size\");\n Default_Sized_SS_Pool : System.Address;\n pragma Import (Ada, Default_Sized_SS_Pool, \"__gnat_default_ss_pool\");\n\n begin\n null;\n\n ada_main'Elab_Body;\n Default_Secondary_Stack_Size := System.Parameters.Runtime_Default_Sec_Stack_Size;\n Binder_Sec_Stacks_Count := 1;\n Default_Sized_SS_Pool := Sec_Default_Sized_Stacks'Address;\n\n\n E78 := E78 + 1;\n Cortex_M.Nvic'Elab_Spec;\n E76 := E76 + 1;\n E70 := E70 + 1;\n E28 := E28 + 1;\n Nrf.Interrupts'Elab_Body;\n E72 := E72 + 1;\n E34 := E34 + 1;\n E37 := E37 + 1;\n E58 := E58 + 1;\n E56 := E56 + 1;\n E41 := E41 + 1;\n E44 := E44 + 1;\n E48 := E48 + 1;\n Nrf.Device'Elab_Spec;\n Nrf.Device'Elab_Body;\n E16 := E16 + 1;\n NRF52_DK.LEDS'ELAB_BODY;\n E81 := E81 + 1;\n NRF52_DK.TIME'ELAB_BODY;\n E54 := E54 + 1;\n NRF52_DK.BUTTONS'ELAB_BODY;\n E52 := E52 + 1;\n end adainit;\n\n procedure Ada_Main_Program;\n pragma Import (Ada, Ada_Main_Program, \"_ada_main\");\n\n procedure main is\n Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;\n pragma Volatile (Ensure_Reference);\n\n begin\n adainit;\n Ada_Main_Program;" + }, + { + "function_def": "procedure Test is", + "function_body": "begin\n for I in 1 .. 10 loop\n I := 3;\n end loop;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(A, A: integer) is begin New_Line; end;\nbegin\n P(0,1);" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A, B: Character; end record;\n X: R;\n function F return R is\n begin\n return X;" + }, + { + "function_def": "procedure Test is", + "function_body": "X : Integer;\nbegin\n X := 'a';" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A, B: Character; end record;\n X: R;\n function F return R is\n begin\n return X;" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record Foo: R; end record;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(X: Integer) is begin X := 0; end;\nbegin\n P(42);" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(X: Integer) return integer is begin X:= 1; return 0; end;\nbegin\n if F(42) = 0 then new_line; end if;" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A: Integer; end record;\n X : R;\nbegin\n X.A := 'a';" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(A: integer; A: character) return integer is begin return 0; end;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(X: in out Integer) is begin new_line; end;\nbegin\n P(42);" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(X: in out Integer) return integer is begin return 0; end;\nbegin\n if F(42) = 0 then new_line; end if;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(A: integer; A: character) is begin New_Line; end;\nbegin\n P(0,'a');" + }, + { + "function_def": "procedure Test is", + "function_body": "type T;\n procedure P is begin New_Line; end;\n type T is record A: Integer; end record;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(X: in Integer) is begin X := 0; end;\nbegin\n P(42);" + }, + { + "function_def": "procedure Test is", + "function_body": "type T is record A: Integer; end record;\n T: Integer;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A: Integer; end record;\n procedure P(X: in R) is begin X.A := 0; end;\n v: R;\nbegin\n P(v);" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A: Integer; end record;\n procedure P(X: in R) is begin X.A := 0; end;\n v: R;\nbegin\n P(v);" + }, + { + "function_def": "procedure P is", + "function_body": "type t is record x: integer; end record;\n type t is record y: integer; end record;\nbegin\n new_line;" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(X: in Integer) return integer is begin X:= 1; return 0; end;\nbegin\n if F(42) = 0 then new_line; end if;" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(A, A: integer) return integer is begin return 0; end;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "begin\n for I in 'a' .. 10 loop\n New_Line;\n end loop;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(X: in out Integer) is begin new_line; end;\n type r is record a: integer; end record;\n function f return access r is begin return new r; end;\nbegin\n P(f.a);" + }, + { + "function_def": "procedure Test is", + "function_body": "X: Integer;\n procedure P is\n procedure X is begin New_Line; end;\n begin\n X;" + }, + { + "function_def": "procedure Test is", + "function_body": "function Oups(N: Integer) return Integer is\n L : Integer := Oups(N);\n begin\n return 0;" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record Foo: access R; end record;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "X: Integer;\n procedure P is\n type X is record A: Integer; end record;\n V: X;\n begin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "function F return character is begin return f; end;\nbegin\n put(f);" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A: Integer; end record;\n X : access R;\nbegin\n X := null;" + }, + { + "function_def": "procedure Test is", + "function_body": "X: Integer;\n procedure P is\n X: Character;\n begin\n Put(X);" + }, + { + "function_def": "procedure Test is", + "function_body": "type R;\n type P is access R;\n type R is record Foo: P; end record;\nbegin\n New_Line;" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure P(X: in out Integer) is begin X := 0; end;\n v: integer;\nbegin\n P(V);" + }, + { + "function_def": "procedure Test is", + "function_body": "procedure R is begin R; end;\nbegin\n R;" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A: Integer; end record;\n type T is access R;\n procedure P(X: in T) is begin X.A := 0; end;\n v: T := new R;\nbegin\n P(v);" + }, + { + "function_def": "procedure Oups is", + "function_body": "type R is record A: Integer; end record;\n V : access R := null;\nbegin\n if V.A = 1 then New_Line; end if;" + }, + { + "function_def": "procedure Oups is", + "function_body": "V : Integer := 0;\nbegin\n if 1 / V = 1 then New_Line; end if;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "for i in 1 . . 10 loop p; end loop;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "if 0=1 then Q(0); else Q(1); elsif 1=2 then Q(2); end if;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "for i in 1 .. 10 loop p; end loop" + }, + { + "function_def": "procedure Test is begin", + "function_body": "for i in 1 .. 10 p; end loop;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "for i in 1 .. 10 loop p; end;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "if 0=1 then Q(0); else Q(1); else Q(2); end if;" + }, + { + "function_def": "procedure Test is begin", + "function_body": "if 0=1 then Q(0); elsif 1=2 then Q(1); end if;" + }, + { + "function_def": "procedure Test is", + "function_body": "begin\n for I in 1 .. 10 loop Put('A'); end loop; New_Line;\n for I in 10 .. 1 loop Put('B'); end loop; New_Line;\n for I in reverse 1 .. 10 loop Put('C'); end loop; New_Line;\n for I in reverse 10 .. 1 loop Put('D'); end loop; New_Line;" + }, + { + "function_def": "procedure Record4 is", + "function_body": "type R is record A, B: Character; end record;\n type S is record C: Character; D: R; E: Character; end record;\n\n V, W: R;\n X, Y: S;\n\n procedure PrintR(x: R) is\n begin\n Put('[');\n Put(x.A);\n Put(',');\n Put(x.B);\n Put(']');" + }, + { + "function_def": "procedure Test is", + "function_body": "begin\n Put('A');\n New_Line;" + }, + { + "function_def": "procedure Power is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A, B: Integer; end record;\n\n procedure P1(X, Y: in out R) is\n begin\n X.A := 0;\n X.B := 1;\n Y.A := 2;\n Y.B := 3;\n if X = Y then Put('a'); end if;\n X := Y;\n if X = Y then Put('d'); end if;" + }, + { + "function_def": "procedure Syracuse is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure length is", + "function_body": "v,j : integer;\n procedure step is\n begin\n v := v+1; if j = 2*(j/2) then j := j/2; else j := 3*j+1; end if;" + }, + { + "function_def": "procedure Record3 is", + "function_body": "type R is record A, B: Character; end record;\n type S is record C: Character; D: R; E: Character; end record;\n\n procedure PrintR(x: R) is\n begin\n Put('[');\n Put(x.A);\n Put(',');\n Put(x.B);\n Put(']');" + }, + { + "function_def": "procedure Quine is", + "function_body": "type str;\n\ttype u is access str;\n\ttype str is record\n\t\tvalue : integer;\n\t\ttail : u;\n\tend record;\n\tprocedure puts(s : u) is begin\n\t\tif s /= null then\n\t\t\tput(character'val(s.value)); \n\t\t\tputs(s.tail);\n\t\tend if;" + }, + { + "function_def": "procedure Print_int is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure Test is", + "function_body": "function F(X: Integer) return Integer is\n begin\n Put('F');\n return X;" + }, + { + "function_def": "procedure josephus is", + "function_body": "type Node;\n type List is access Node;\n type Node is record\n Value: Integer;\n Prev, Next: List;\n end record;\n function Singleton(V: Integer) return List is\n L: List := new Node;\n begin\n L.Value := V;\n L.Prev := L;\n L.Next := L;\n return L;" + }, + { + "function_def": "procedure NQueens is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure Mandelbrot is", + "function_body": "-- Ada 2012\n -- function Add(x, y: in Integer) return Integer is (X+Y);\n -- function Sub(x, y: in Integer) return Integer is (X-Y);\n -- function Mul(x, y: in Integer) return Integer is ((X * Y + 8192 / 2) / 8192);\n -- function Div(x, y: in Integer) return Integer is ((X * 8192 + y / 2) / Y);\n -- function OfInt(x: in Integer) return Integer is (X * 8192);\n\n function Add(x, y: in Integer) return Integer is\n begin\n return X+Y;\n end Add;\n function Sub(x, y: in Integer) return Integer is\n begin\n return X-Y;\n end Sub;\n function Mul(x, y: in Integer) return Integer is\n T : Integer := X * Y;\n begin\n return (t + 8192 / 2) / 8192;\n end Mul;\n function Div(x, y: in Integer) return Integer is\n T : Integer := X * 8192;\n begin\n return (t + y / 2) / y;\n end Div;\n function OfInt(x: in Integer) return Integer is\n begin\n return X * 8192;\n end OfInt;\n\n function iter(N, A, B, Xn, Yn: in Integer) return Boolean is\n xn2, Yn2 : Integer;\n begin\n if n = 100 then return true; end if;\n xn2 := mul(xn, xn);\n yn2 := mul(yn, yn);\n if add(xn2, yn2) > ofint(4) then return false; end if;\n return iter(n+1, a, b, add(sub(xn2, yn2), a),\n add(mul(ofint(2), mul(xn, yn)), b));" + }, + { + "function_def": "procedure Pascal is", + "function_body": "type Node;\n type List is access Node;\n type Node is record\n Value: Integer;\n Next: List;\n end record;\n\n function Get(L: List; I: Integer) return Integer is\n begin\n if I = 0 then return L.Value; end if;\n return Get(L.next, I - 1);" + }, + { + "function_def": "procedure Fact is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure Test is", + "function_body": "type R is record A, B: Integer; end record;\n\n procedure P1(X, Y: in out R) is\n begin\n X.A := 0;\n X.B := 1;\n Y.A := 2;\n Y.B := 3;\n if X.A = Y.A and X.B = Y.B then Put('a'); end if;\n X := Y;\n if X.A = Y.A and X.B = Y.B then Put('d'); end if;" + }, + { + "function_def": "procedure Test_a is", + "function_body": "procedure R(N: Integer) is\n begin\n if N = 0 then return; end if;\n Put('a');\n R(N - 1);" + }, + { + "function_def": "procedure Test is", + "function_body": "function F return character is\n begin return 'a';\n end F;\n function G(C: Character) return character is\n begin return c;\n end G;\nbegin\n Put(F); New_Line;\n Put(G('b')); New_Line;\n Put(G(F)); New_Line;" + }, + { + "function_def": "procedure BST is", + "function_body": "type Node;\n type BST is access Node;\n type Node is record\n Value: Integer;\n Left, Right: BST;\n end record;\n -- insertion utilisant le passage par r\u00e9f\u00e9rence\n procedure Add(X: Integer; B: in out BST) is\n begin\n if B = null then B := new Node; B.Value := X; return; end if;\n if X < B.Value then\n Add(X, B.Left);\n elsif X > B.Value then\n Add(X, B.Right);\n end if;" + }, + { + "function_def": "procedure Fib is", + "function_body": "procedure PrintInt(N: Integer) is\n C: Integer := N rem 10;\n begin\n if N > 9 then PrintInt(N / 10); end if;\n Put(Character'Val(48 + C));" + }, + { + "function_def": "procedure somme is", + "function_body": "tmp : integer;\n begin fib(n-2); tmp := f; fib(n-1); f := f + Tmp; end;\n begin\n if n <= 1 then f := N; else somme; end if;" + }, + { + "function_def": "procedure Clear is", + "function_body": "begin\n null;\n end Clear;\n\n -- ------------------------------\n -- Generate a random bitstream.\n -- ------------------------------\n procedure Generate_Id (Rand : out Ada.Streams.Stream_Element_Array) is\n use Ada.Streams;\n use Interfaces;\n\n Size : constant Stream_Element_Offset := Rand'Length / 4;\n begin\n -- Generate the random sequence.\n for I in 0 .. Size - 1 loop\n declare\n Value : constant Unsigned_32 := Id_Random.Random (Random);\n begin\n Rand (4 * I) := Stream_Element (Value and 16#0FF#);\n Rand (4 * I + 1) := Stream_Element (Shift_Right (Value, 8) and 16#0FF#);\n Rand (4 * I + 2) := Stream_Element (Shift_Right (Value, 16) and 16#0FF#);\n Rand (4 * I + 3) := Stream_Element (Shift_Right (Value, 24) and 16#0FF#);" + }, + { + "function_def": "procedure Dispatch (Server : in Rest_Servlet;", + "function_body": "Method : in Method_Type;\n Request : in out Requests.Request'Class;\n Response : in out Responses.Response'Class) is\n pragma Unreferenced (Server);\n\n begin\n if not Request.Has_Route then\n Response.Set_Status (Responses.SC_NOT_FOUND);\n Response.Set_Committed;\n return;\n end if;\n declare\n Route : constant Routes.Route_Type_Accessor := Request.Get_Route;\n begin\n if not (Route in Routes.Servlets.Rest.API_Route_Type'Class) then\n Response.Set_Status (Responses.SC_NOT_FOUND);\n Response.Set_Committed;\n return;\n end if;\n declare\n Api : constant access Routes.Servlets.Rest.API_Route_Type'Class\n := Routes.Servlets.Rest.API_Route_Type'Class (Route.Element.all)'Access;\n Desc : constant Descriptor_Access := Api.Descriptors (Method);\n Output : constant Streams.Print_Stream := Response.Get_Output_Stream;\n Mime : Mime_Access;\n begin\n if Desc = null then\n Response.Set_Status (Responses.SC_NOT_FOUND);\n Response.Set_Committed;\n return;\n end if;\n Mime := Desc.Get_Mime_Type (Request);\n if Mime = null or else Mime.all = Util.Http.Mimes.Json then\n declare\n Stream : Streams.JSON.Print_Stream;\n begin\n Streams.JSON.Initialize (Stream, Output);\n Response.Set_Content_Type (\"application/json; charset=utf-8\");\n Api.Descriptors (Method).Dispatch (Request, Response, Stream);" + }, + { + "function_def": "function Get_Permission (Handler : in Descriptor)", + "function_body": "return Security.Permissions.Permission_Index is\n begin\n return Handler.Permission;\n end Get_Permission;\n\n -- ------------------------------\n -- Get the mime type selected for the operation.\n -- ------------------------------\n function Get_Mime_Type (Handler : in Descriptor;\n Req : in Servlet.Rest.Request'Class) return Mime_Access is\n Accept_Header : constant String := Req.Get_Header (\"Accept\");\n begin\n if Handler.Mimes /= null then\n return Util.Http.Headers.Get_Accepted (Accept_Header, Handler.Mimes.all);\n else\n return null;\n end if;\n end Get_Mime_Type;\n\n -- ------------------------------\n -- Register the API descriptor in a list.\n -- ------------------------------\n procedure Register (List : in out Descriptor_Access;\n Item : in Descriptor_Access) is\n begin\n Item.Next := List;\n List := Item;\n end Register;\n\n -- ------------------------------\n -- Register the list of API descriptors for a given servlet and a root path.\n -- ------------------------------\n procedure Register (Registry : in out Servlet.Core.Servlet_Registry;\n Name : in String;\n URI : in String;\n ELContext : in EL.Contexts.ELContext'Class;\n List : in Descriptor_Access) is\n procedure Insert (Route : in out Servlet.Routes.Route_Type_Ref);\n Item : Descriptor_Access := List;\n\n procedure Insert (Route : in out Servlet.Routes.Route_Type_Ref) is\n begin\n if not Route.Is_Null then\n declare\n R : constant Servlet.Routes.Route_Type_Accessor := Route.Value;\n D : access Servlet.Routes.Servlets.Rest.API_Route_Type'Class;\n begin\n if not (R in Servlet.Routes.Servlets.Rest.API_Route_Type'Class) then\n Log.Error (\"Route API for {0}/{1} already used by another page\",\n URI, Item.Pattern.all);\n return;\n end if;\n D := Servlet.Routes.Servlets.Rest.API_Route_Type'Class (R.Element.all)'Access;\n if D.Descriptors (Item.Method) /= null then\n Log.Error (\"Route API for {0}/{1} is already used\", URI, Item.Pattern.all);\n end if;\n D.Descriptors (Item.Method) := Item;" + }, + { + "function_def": "procedure Dispatch (Handler : in Static_Descriptor;", + "function_body": "Req : in out Servlet.Rest.Request'Class;\n Reply : in out Servlet.Rest.Response'Class;\n Stream : in out Output_Stream'Class) is\n begin\n Handler.Handler (Req, Reply, Stream);\n end Dispatch;\n\n -- ------------------------------\n -- Register the API definition in the servlet registry.\n -- ------------------------------\n procedure Register (Registry : in out Servlet.Core.Servlet_Registry'Class;\n Definition : in Descriptor_Access) is\n use type Servlet.Core.Servlet_Access;\n procedure Insert (Route : in out Routes.Route_Type_Ref);\n\n Dispatcher : constant Servlet.Core.Request_Dispatcher\n := Registry.Get_Request_Dispatcher (Definition.Pattern.all);\n Servlet : constant Core.Servlet_Access := Core.Get_Servlet (Dispatcher);\n\n procedure Insert (Route : in out Routes.Route_Type_Ref) is\n begin\n if not Route.Is_Null then\n declare\n R : constant Routes.Route_Type_Accessor := Route.Value;\n D : access Routes.Servlets.Rest.API_Route_Type'Class;\n begin\n if not (R in Routes.Servlets.Rest.API_Route_Type'Class) then\n Log.Error (\"Route API for {0} already used by another page\",\n Definition.Pattern.all);\n D := Core.Rest.Create_Route (Servlet);\n Route := Routes.Route_Type_Refs.Create (D.all'Access);\n else\n D := Routes.Servlets.Rest.API_Route_Type'Class (R.Element.all)'Access;\n end if;\n if D.Descriptors (Definition.Method) /= null then\n Log.Error (\"Route API for {0} is already used\", Definition.Pattern.all);\n end if;\n D.Descriptors (Definition.Method) := Definition;" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => Binding_Array,\n Name => Binding_Array_Access);\n procedure Free is\n new Ada.Unchecked_Deallocation (Object => Binding,\n Name => Binding_Access);\n\n -- ------------------------------\n -- Get the current registry associated with the current request being processed\n -- by the current thread. Returns null if there is no current request.\n -- ------------------------------\n function Current return Servlet.Core.Servlet_Registry_Access is\n begin\n return Task_Context.Value.Application;\n end Current;\n\n -- ------------------------------\n -- Set the current registry (for unit testing mostly).\n -- ------------------------------\n procedure Set_Context (Context : in Servlet.Core.Servlet_Registry_Access) is\n C : Request_Context;\n begin\n C.Application := Context;\n C.Request := null;\n C.Response := null;\n Set_Context (C);\n end Set_Context;\n\n -- ------------------------------\n -- Set the current registry. This is called by Service once the\n -- registry is identified from the URI.\n -- ------------------------------\n procedure Set_Context (Context : in Request_Context) is\n begin\n Task_Context.Set_Value (Context);\n end Set_Context;\n\n -- ------------------------------\n -- Give access to the current request and response object to the `Process`\n -- procedure. If there is no current request for the thread, do nothing.\n -- ------------------------------\n procedure Update_Context (Process : not null access\n procedure (Request : in out Requests.Request'Class;\n Response : in out Responses.Response'Class)) is\n Ctx : constant Request_Context := Task_Context.Value;\n begin\n Process (Ctx.Request.all, Ctx.Response.all);\n end Update_Context;\n\n -- ------------------------------\n -- Register the application to serve requests\n -- ------------------------------\n procedure Register_Application (Server : in out Container;\n URI : in String;\n Context : in Core.Servlet_Registry_Access) is\n Count : constant Natural := Server.Nb_Bindings;\n Apps : constant Binding_Array_Access := new Binding_Array (1 .. Count + 1);\n Old : Binding_Array_Access := Server.Applications;\n begin\n Log.Info (\"Register application {0}\", URI);\n\n if Old /= null then\n Apps (1 .. Count) := Server.Applications (1 .. Count);\n end if;\n Apps (Count + 1) := new Binding '(Len => URI'Length, Context => Context, Base_URI => URI);\n\n -- Inform the servlet registry about the base URI.\n Context.Register_Application (URI);\n\n -- Start the application if the container is started.\n if Server.Is_Started and then Context.Get_Status = Core.Ready then\n Context.Start;\n end if;\n\n -- Update the binding.\n Server.Applications := Apps;\n Server.Nb_Bindings := Count + 1;\n if Old /= null then\n Free (Old);\n end if;\n end Register_Application;\n\n -- ------------------------------\n -- Remove the application\n -- ------------------------------\n procedure Remove_Application (Server : in out Container;\n Context : in Core.Servlet_Registry_Access) is\n use type Servlet.Core.Servlet_Registry_Access;\n\n Count : constant Natural := Server.Nb_Bindings;\n Old : Binding_Array_Access := Server.Applications;\n Apps : Binding_Array_Access;\n begin\n for I in 1 .. Count loop\n if Old (I).Context = Context then\n Log.Info (\"Removed application {0}\", Old (I).Base_URI);\n Free (Old (I));\n if I < Count then\n Old (I) := Old (Count);\n end if;\n if Count > 1 then\n Apps := new Binding_Array (1 .. Count - 1);\n Apps.all := Old (1 .. Count - 1);\n else\n Apps := null;\n end if;\n Server.Applications := Apps;\n Server.Nb_Bindings := Count - 1;\n Free (Old);\n return;\n end if;\n end loop;\n end Remove_Application;\n\n -- ------------------------------\n -- Start the applications that have been registered.\n -- ------------------------------\n procedure Start (Server : in out Container) is\n begin\n if Server.Applications /= null then\n for Application of Server.Applications.all loop\n if Application.Context.Get_Status = Core.Ready then\n Log.Info (\"Starting application {0}\", Application.Base_URI);\n Application.Context.Start;\n end if;\n end loop;\n end if;\n Server.Is_Started := True;\n end Start;\n\n -- ------------------------------\n -- Receives standard HTTP requests from the public service method and\n -- dispatches them to the Do_XXX methods defined in this class. This method\n -- is an HTTP-specific version of the Servlet.service(Request, Response)\n -- method. There's no need to override this method.\n -- ------------------------------\n procedure Service (Server : in Container;\n Request : in out Requests.Request'Class;\n Response : in out Responses.Response'Class) is\n\n use Util.Strings;\n\n URI : constant String := Request.Get_Request_URI;\n Slash_Pos : constant Natural := Index (URI, '/', URI'First + 1);\n Apps : constant Binding_Array_Access := Server.Applications;\n Prefix_End : Natural;\n begin\n if Apps = null then\n Response.Set_Status (Responses.SC_NOT_FOUND);\n Server.Default.Send_Error_Page (Request, Response);\n return;\n end if;\n\n -- Find the module and action to invoke\n if Slash_Pos > 1 then\n Prefix_End := Slash_Pos - 1;\n else\n Prefix_End := URI'Last;\n end if;\n\n for Application of Apps.all loop\n if Application.Base_URI = URI (URI'First .. Prefix_End)\n and then Application.Context.Get_Status = Core.Started\n then\n declare\n Req : Request_Context;\n Context : constant Core.Servlet_Registry_Access := Application.Context;\n Page : constant String := URI (Prefix_End + 1 .. URI'Last);\n Dispatcher : constant Core.Request_Dispatcher\n := Context.Get_Request_Dispatcher (Page);\n begin\n Log.Info (\"{0} {1}\", Request.Get_Method, Page);\n Req.Request := Request'Unchecked_Access;\n Req.Response := Response'Unchecked_Access;\n Req.Application := Context;\n Set_Context (Req);\n Core.Forward (Dispatcher, Request, Response);\n case Response.Get_Status / 100 is\n when 2 | 3 =>\n null;\n\n when others =>\n if not Response.Is_Committed then\n Context.Send_Error_Page (Request, Response);\n end if;\n\n end case;\n Set_Context (Null_Context);\n return;\n\n exception\n when E : others =>\n Context.Error (Request, Response, E);\n Set_Context (Null_Context);\n return;" + }, + { + "function_def": "function Get_Request_Dispatcher (Context : in Servlet_Registry;", + "function_body": "Path : in String)\n return Request_Dispatcher is\n use type Filters.Filter_List_Access;\n begin\n return R : Request_Dispatcher do\n Context.Routes.Find_Route (Path, R.Context);\n if not Routes.Is_Null (R.Context) then\n declare\n use Routes.Servlets;\n\n Route : constant Routes.Route_Type_Accessor := Routes.Get_Route (R.Context);\n begin\n if Route in Routes.Servlets.Servlet_Route_Type'Class then\n declare\n Servlet_Route : constant access Routes.Servlets.Servlet_Route_Type'Class\n := Routes.Servlets.Servlet_Route_Type'Class (Route.Element.all)'Access;\n Proxy : Routes.Servlets.Proxy_Route_Type_Access;\n begin\n if Servlet_Route.Filters /= null then\n R.Filters := Servlet_Route.Filters.all'Access;\n end if;\n if Servlet_Route.all in Routes.Servlets.Proxy_Route_Type'Class then\n Proxy := Proxy_Route_Type'Class (Servlet_Route.all)'Access;\n Routes.Change_Route (R.Context, Proxy.Route);\n R.Servlet\n := Servlet_Route_Type'Class (Proxy.Route.Value.Element.all).Servlet;\n else\n R.Servlet := Servlet_Route.Servlet;\n end if;" + }, + { + "function_def": "function Get_Name_Dispatcher (Context : in Servlet_Registry;", + "function_body": "Name : in String)\n return Request_Dispatcher is\n Pos : constant Servlet_Maps.Cursor := Context.Servlets.Find (Name);\n begin\n if not Servlet_Maps.Has_Element (Pos) then\n raise Servlet_Error with \"No servlet \" & Name;\n end if;\n return R : Request_Dispatcher do\n R.Servlet := Servlet_Maps.Element (Pos);\n end return;\n end Get_Name_Dispatcher;\n\n -- ------------------------------\n -- Returns the context path of the web application.\n -- The context path is the portion of the request URI that is used to select the context\n -- of the request. The context path always comes first in a request URI. The path starts\n -- with a \"/\" character but does not end with a \"/\" character. For servlets in the default\n -- (root) context, this method returns \"\".\n -- ------------------------------\n function Get_Context_Path (Context : in Servlet_Registry) return String is\n begin\n return To_String (Context.Context_Path);\n end Get_Context_Path;\n\n -- ------------------------------\n -- Returns a String containing the value of the named context-wide initialization\n -- parameter, or null if the parameter does not exist.\n --\n -- This method can make available configuration information useful to an entire\n -- \"web application\". For example, it can provide a webmaster's email address\n -- or the name of a system that holds critical data.\n -- ------------------------------\n function Get_Init_Parameter (Context : in Servlet_Registry;\n Name : in String;\n Default : in String := \"\") return String is\n begin\n return Context.Config.Get (Name, Default);\n end Get_Init_Parameter;\n\n function Get_Init_Parameter (Context : in Servlet_Registry;\n Name : in String;\n Default : in String := \"\")\n return Ada.Strings.Unbounded.Unbounded_String is\n begin\n if Context.Config.Exists (Name) then\n return Context.Config.Get (Name);\n else\n return Ada.Strings.Unbounded.To_Unbounded_String (Default);\n end if;\n end Get_Init_Parameter;\n\n -- ------------------------------\n -- Set the init parameter identified by Name to the value Value.\n -- ------------------------------\n procedure Set_Init_Parameter (Context : in out Servlet_Registry;\n Name : in String;\n Value : in String) is\n begin\n Log.Debug (\"Set {0}={1}\", Name, Value);\n\n Context.Config.Set (Name, Value);\n end Set_Init_Parameter;\n\n -- ------------------------------\n -- Set the init parameters by copying the properties defined in Params.\n -- Existing parameters will be overriding by the new values.\n -- ------------------------------\n procedure Set_Init_Parameters (Context : in out Servlet_Registry;\n Params : in Util.Properties.Manager'Class) is\n begin\n Context.Config.Copy (Params);\n end Set_Init_Parameters;\n\n -- ------------------------------\n -- Get access to the init parameters.\n -- ------------------------------\n procedure Get_Init_Parameters (Context : in Servlet_Registry;\n Process : not null access\n procedure (Params : in Util.Properties.Manager'Class)) is\n begin\n Process (Context.Config);\n end Get_Init_Parameters;\n\n -- ------------------------------\n -- Returns the absolute path of the resource identified by the given relative path.\n -- The resource is searched in a list of directories configured by the application.\n -- The path must begin with a \"/\" and is interpreted as relative to the current\n -- context root.\n --\n -- This method allows the servlet container to make a resource available to\n -- servlets from any source.\n --\n -- This method returns an empty string if the resource could not be localized.\n -- ------------------------------\n function Get_Resource (Context : in Servlet_Registry;\n Path : in String) return String is\n Paths : constant String := Context.Get_Init_Parameter (\"view.dir\");\n Result : constant String := Util.Files.Find_File_Path (Name => Path, Paths => Paths);\n begin\n if Result = Path then\n return \"\";\n else\n return Result;\n end if;\n end Get_Resource;\n\n -- ------------------------------\n -- Registers the given servlet instance with this ServletContext under\n -- the given servletName.\n --\n -- If this ServletContext already contains a preliminary\n -- ServletRegistration for a servlet with the given servletName,\n -- it will be completed (by assigning the class name of the given\n -- servlet instance to it) and returned.\n -- ------------------------------\n procedure Add_Servlet (Registry : in out Servlet_Registry;\n Name : in String;\n Server : in Servlet_Access) is\n begin\n Log.Info (\"Add servlet '{0}'\", Name);\n\n if Server.Context /= null then\n Log.Error (\"Servlet '{0}' already registered in a servlet registry\", Server.Get_Name);\n raise Servlet_Error;\n end if;\n\n Server.Name := To_Unbounded_String (Name);\n Server.Context := Registry'Unchecked_Access;\n Servlet_Maps.Include (Registry.Servlets, Name, Server);\n end Add_Servlet;\n\n -- ------------------------------\n -- Registers the given filter instance with this Servlet context.\n -- ------------------------------\n procedure Add_Filter (Registry : in out Servlet_Registry;\n Name : in String;\n Filter : in Filter_Access) is\n begin\n Log.Info (\"Add servlet filter '{0}'\", Name);\n\n Filter_Maps.Include (Registry.Filters, Name,\n Filter.all'Unchecked_Access);\n end Add_Filter;\n\n -- ------------------------------\n -- Causes the next filter in the chain to be invoked, or if the calling\n -- filter is the last filter in the chain, causes the resource at the end\n -- of the chain to be invoked.\n -- ------------------------------\n procedure Do_Filter (Chain : in out Filter_Chain;\n Request : in out Requests.Request'Class;\n Response : in out Responses.Response'Class) is\n begin\n if Chain.Filter_Pos = 0 then\n Chain.Servlet.Service (Request, Response);\n else\n declare\n Filter : constant Filters.Filter_Access := Chain.Filters (Chain.Filter_Pos);\n begin\n Chain.Filter_Pos := Chain.Filter_Pos - 1;\n Filter.Do_Filter (Request, Response, Chain);" + }, + { + "function_def": "procedure Make_Route;", + "function_body": "procedure Initialize_Filter (Key : in String;\n Filter : in Filter_Access);\n procedure Initialize_Servlet (Pos : in Servlet_Maps.Cursor);\n\n procedure Process (URI : in String;\n Route : in Routes.Route_Type_Accessor) is\n Iter : Util.Strings.Vectors.Cursor := Registry.Filter_Patterns.First;\n Servlet_Route : access Routes.Servlets.Servlet_Route_Type'Class;\n begin\n if not (Route in Routes.Servlets.Servlet_Route_Type'Class) then\n return;\n end if;\n Servlet_Route := Routes.Servlets.Servlet_Route_Type'Class (Route.Element.all)'Access;\n while Util.Strings.Vectors.Has_Element (Iter) loop\n declare\n Pattern : constant String := Util.Strings.Vectors.Element (Iter);\n Filter : Filter_List_Access;\n begin\n if Match_Pattern (Pattern, URI) then\n Filter := Registry.Filter_Rules.Element (Pattern);\n for I in Filter'Range loop\n Routes.Servlets.Append_Filter (Servlet_Route.all, Filter (I).all'Access);\n end loop;\n end if;" + }, + { + "function_def": "procedure Make_Route is", + "function_body": "Context : aliased EL.Contexts.Default.Default_Context;\n Iter : Util.Strings.Vectors.Cursor := Registry.Filter_Patterns.First;\n begin\n while Util.Strings.Vectors.Has_Element (Iter) loop\n declare\n use Routes.Servlets;\n procedure Insert (Ref : in out Routes.Route_Type_Ref);\n\n Pattern : constant String := Util.Strings.Vectors.Element (Iter);\n Route : Routes.Route_Context_Type;\n\n procedure Insert (Ref : in out Routes.Route_Type_Ref) is\n Proxy : Routes.Servlets.Proxy_Route_Type_Access;\n begin\n if Ref.Is_Null then\n Proxy := new Routes.Servlets.Proxy_Route_Type;\n Proxy.Route := Route.Get_Route;\n\n -- If the route is also a proxy, get the real route pointed to by the proxy.\n if Proxy.Route.Value in Proxy_Route_Type'Class then\n Proxy.Route\n := Proxy_Route_Type'Class (Proxy.Route.Value.Element.all).Route;\n end if;\n Ref := Routes.Route_Type_Refs.Create (Proxy.all'Access);\n end if;\n end Insert;\n\n begin\n Registry.Routes.Find_Route (Pattern, Route);\n if not Route.Is_Null then\n Registry.Routes.Add_Route (Pattern, Context, Insert'Access);\n end if;" + }, + { + "function_def": "procedure Disable (Registry : in out Servlet_Registry) is", + "function_body": "begin\n case Registry.Status is\n when Ready =>\n Registry.Status := Disabled;\n\n when Started =>\n Registry.Status := Suspended;\n\n when Disabled | Suspended | Stopped =>\n null;\n\n end case;\n end Disable;\n\n -- ------------------------------\n -- Enable the application.\n -- ------------------------------\n procedure Enable (Registry : in out Servlet_Registry) is\n begin\n case Registry.Status is\n when Disabled =>\n Registry.Status := Ready;\n\n when Suspended =>\n Registry.Status := Started;\n\n when Ready | Started | Stopped =>\n null;\n\n end case;\n end Enable;\n\n -- ------------------------------\n -- Stop the application.\n -- ------------------------------\n procedure Stop (Registry : in out Servlet_Registry) is\n begin\n case Registry.Status is\n when Ready | Disabled | Stopped =>\n null;\n\n when Started | Suspended =>\n Registry.Status := Stopped;\n\n end case;\n end Stop;\n\n procedure Free is\n new Ada.Unchecked_Deallocation (Object => Filters.Filter_List,\n Name => Filter_List_Access);\n\n -- ------------------------------\n -- Add a filter mapping with the given pattern\n -- If the URL pattern is already mapped to a different servlet,\n -- no updates will be performed.\n -- ------------------------------\n procedure Add_Filter_Mapping (Registry : in out Servlet_Registry;\n Pattern : in String;\n Name : in String) is\n procedure Append (Key : in String;\n List : in out Filter_List_Access);\n\n Pos : constant Filter_Maps.Cursor := Registry.Filters.Find (Name);\n Rule : constant Filter_List_Maps.Cursor := Registry.Filter_Rules.Find (Pattern);\n\n -- ------------------------------\n -- Append the filter in the filter list.\n -- ------------------------------\n procedure Append (Key : in String;\n List : in out Filter_List_Access) is\n pragma Unreferenced (Key);\n use Filters;\n\n Filter : constant Filters.Filter_Access := Filter_Maps.Element (Pos).all'Access;\n New_List : Filter_List_Access;\n begin\n -- Check that the filter is not already executed.\n for I in List'Range loop\n if List (I) = Filter then\n return;\n end if;\n end loop;\n\n New_List := new Filters.Filter_List (1 .. List'Last + 1);\n New_List.all (2 .. New_List'Last) := List.all;\n New_List (New_List'First) := Filter;\n Free (List);\n List := New_List;\n end Append;\n\n List : Filter_List_Access;\n\n begin\n Log.Info (\"Add filter mapping {0} -> {1}\", Pattern, Name);\n\n if not Filter_Maps.Has_Element (Pos) then\n Log.Error (\"No servlet filter {0}\", Name);\n raise Servlet_Error with \"No servlet filter \" & Name;\n end if;\n if not Filter_List_Maps.Has_Element (Rule) then\n Registry.Filter_Patterns.Append (Pattern);\n List := new Filters.Filter_List (1 .. 1);\n List (List'First) := Filter_Maps.Element (Pos).all'Access;\n Registry.Filter_Rules.Insert (Pattern, List);\n else\n Registry.Filter_Rules.Update_Element (Rule, Append'Access);\n end if;\n end Add_Filter_Mapping;\n\n -- ------------------------------\n -- Add a servlet mapping with the given pattern\n -- If the URL pattern is already mapped to a different servlet,\n -- no updates will be performed.\n -- ------------------------------\n procedure Add_Mapping (Registry : in out Servlet_Registry;\n Pattern : in String;\n Name : in String) is\n Pos : constant Servlet_Maps.Cursor := Registry.Servlets.Find (Name);\n begin\n if not Servlet_Maps.Has_Element (Pos) then\n Log.Error (\"No servlet {0}\", Name);\n raise Servlet_Error with \"No servlet \" & Name;\n end if;\n\n Log.Info (\"Add servlet mapping {0} -> {1}\", Pattern, Name);\n Registry.Add_Mapping (Pattern, Servlet_Maps.Element (Pos));\n end Add_Mapping;\n\n -- ------------------------------\n -- Add a servlet mapping with the given pattern\n -- If the URL pattern is already mapped to a different servlet,\n -- no updates will be performed.\n -- ------------------------------\n procedure Add_Mapping (Registry : in out Servlet_Registry;\n Pattern : in String;\n Server : in Servlet_Access) is\n procedure Insert (Route : in out Routes.Route_Type_Ref);\n\n procedure Insert (Route : in out Routes.Route_Type_Ref) is\n To : Routes.Servlets.Servlet_Route_Type_Access;\n begin\n if Route.Is_Null then\n To := new Routes.Servlets.Servlet_Route_Type;\n To.Servlet := Server;\n Route := Routes.Route_Type_Refs.Create (To.all'Access);\n else\n Log.Warn (\"Mapping {0} already defined\", Pattern);\n end if;\n end Insert;\n\n Context : aliased EL.Contexts.Default.Default_Context;\n begin\n if Pattern'Length = 0 or else Server = null then\n return;\n end if;\n Registry.Routes.Add_Route (Pattern, Context, Insert'Access);\n end Add_Mapping;\n\n -- ------------------------------\n -- Add a route associated with the given path pattern. The pattern is split into components.\n -- Some path components can be a fixed string (/home) and others can be variable.\n -- When a path component is variable, the value can be retrieved from the route context.\n -- Once the route path is created, the Process procedure is called with the route\n -- reference.\n -- ------------------------------\n procedure Add_Route (Registry : in out Servlet_Registry;\n Pattern : in String;\n ELContext : in EL.Contexts.ELContext'Class;\n Process : not null access\n procedure (Route : in out Routes.Route_Type_Ref)) is\n begin\n Registry.Routes.Add_Route (Pattern, ELContext, Process);\n end Add_Route;\n\n -- ------------------------------\n -- Set the error page that will be used if a servlet returns an error.\n -- ------------------------------\n procedure Set_Error_Page (Server : in out Servlet_Registry;\n Error : in Integer;\n Page : in String) is\n begin\n Log.Info (\"Using page {0} for http error {1}\", Page, Integer'Image (Error));\n\n Server.Error_Pages.Include (Error, Page);\n end Set_Error_Page;\n\n function Hash (N : Integer) return Ada.Containers.Hash_Type is\n begin\n return Ada.Containers.Hash_Type (N);\n end Hash;\n\n -- ------------------------------\n -- Send the error page content defined by the response status.\n -- ------------------------------\n procedure Send_Error_Page (Server : in Servlet_Registry;\n Request : in out Requests.Request'Class;\n Response : in out Responses.Response'Class) is\n URI : constant String := Request.Get_Request_URI;\n Status : constant Natural := Response.Get_Status;\n Pos : constant Error_Maps.Cursor := Server.Error_Pages.Find (Status);\n begin\n Request.Set_Attribute (\"servlet.error.status_code\", EL.Objects.To_Object (Integer (Status)));\n Request.Set_Attribute (\"servlet.error.request_uri\", EL.Objects.To_Object (URI));\n\n if Error_Maps.Has_Element (Pos) then\n declare\n Page : constant String := Error_Maps.Element (Pos);\n Dispatcher : constant Request_Dispatcher\n := Server.Get_Request_Dispatcher (Page);\n begin\n Forward (Dispatcher, Request, Response);\n return;\n\n exception\n when others =>\n null;" + }, + { + "function_def": "procedure Register_Application (Registry : in out Servlet_Registry;", + "function_body": "URI : in String) is\n begin\n Registry.Context_Path := To_Unbounded_String (URI);\n end Register_Application;\n\n -- ------------------------------\n -- Finalize the servlet registry releasing the internal mappings.\n -- ------------------------------\n overriding\n procedure Finalize (Registry : in out Servlet_Registry) is\n begin\n -- Release the filter mapping lists that have been allocated.\n while not Registry.Filter_Rules.Is_Empty loop\n declare\n Pos : Filter_List_Maps.Cursor := Registry.Filter_Rules.First;\n Filter : Filter_List_Access := Filter_List_Maps.Element (Pos).all'Access;\n begin\n Free (Filter);\n Registry.Filter_Rules.Delete (Pos);" + }, + { + "function_def": "procedure Free is", + "function_body": "new Ada.Unchecked_Deallocation (Object => String, Name => String_Access);\n begin\n Free (Context.Path);\n end Finalize;\n\n -- ------------------------------\n -- Insert the route node at the correct place in the children list\n -- according to the rule kind.\n -- ------------------------------\n procedure Insert (Parent : in Route_Node_Access;\n Node : in Route_Node_Access;\n Kind : in Route_Match_Type) is\n Previous, Current : Route_Node_Access;\n begin\n Current := Parent.Children;\n case Kind is\n -- Add at head of the list.\n when YES_MATCH =>\n null;\n\n when MAYBE_MATCH =>\n while Current /= null loop\n if not (Current.all in Path_Node_Type'Class) then\n exit;\n end if;\n Previous := Current;\n Current := Current.Next_Route;\n end loop;\n\n -- Add before the\n when EXT_MATCH =>\n while Current /= null loop\n if not (Current.all in Path_Node_Type'Class)\n and then not (Current.all in Param_Node_Type'Class)\n and then not (Current.all in EL_Node_Type'Class)\n then\n exit;\n end if;\n Previous := Current;\n Current := Current.Next_Route;\n end loop;\n\n when WILDCARD_MATCH =>\n while Current /= null loop\n Previous := Current;\n Current := Current.Next_Route;\n end loop;\n\n when others =>\n null;\n\n end case;\n if Previous /= null then\n Node.Next_Route := Previous.Next_Route;\n Previous.Next_Route := Node;\n else\n Node.Next_Route := Parent.Children;\n Parent.Children := Node;\n end if;\n end Insert;\n\n -- ------------------------------\n -- Add a route associated with the given path pattern. The pattern is split into components.\n -- Some path components can be a fixed string (/home) and others can be variable.\n -- When a path component is variable, the value can be retrieved from the route context.\n -- Once the route path is created, the Process procedure is called with the route\n -- reference.\n -- ------------------------------\n procedure Add_Route (Router : in out Router_Type;\n Pattern : in String;\n ELContext : in EL.Contexts.ELContext'Class;\n Process : not null access procedure (Route : in out Route_Type_Ref)) is\n First : Natural := Pattern'First;\n Pos : Natural;\n Node : Route_Node_Access := Router.Route.Children;\n Match : Route_Match_Type := NO_MATCH;\n New_Path : Path_Node_Access;\n Parent : Route_Node_Access := Router.Route'Unchecked_Access;\n Parent2 : Route_Node_Access;\n Found : Boolean;\n begin\n Log.Info (\"Adding route {0}\", Pattern);\n loop\n -- Ignore consecutive '/'.\n while First <= Pattern'Last and then Pattern (First) = '/' loop\n First := First + 1;\n end loop;\n\n -- Find the path component's end.\n Pos := Util.Strings.Index (Pattern, '/', First);\n if Pos = 0 then\n Pos := Pattern'Last;\n else\n Pos := Pos - 1;\n end if;\n if First > Pattern'Last then\n Found := False;\n\n -- Find an exact match for this component.\n while Node /= null loop\n if Node.all in Path_Node_Type'Class then\n Match := Node.Matches (Pattern (First .. Pos), Pos = Pattern'Last);\n if Match = YES_MATCH then\n Parent := Node;\n Node := Node.Children;\n Found := True;\n exit;\n end if;\n end if;\n Node := Node.Next_Route;\n end loop;\n\n -- Add a path node matching the component at beginning of the children list.\n -- (before the Param_Node and EL_Node instances if any).\n if not Found then\n New_Path := new Path_Node_Type (Len => 0);\n Insert (Parent, New_Path.all'Access, YES_MATCH);\n Parent := Parent.Children;\n end if;\n elsif Pattern (First) = '#' then\n declare\n E : EL_Node_Access;\n begin\n Found := False;\n\n -- Find the EL_Node that have the same EL expression.\n while Node /= null loop\n if Node.all in EL_Node_Type'Class then\n E := EL_Node_Type'Class (Node.all)'Access;\n if E.Value.Get_Expression = Pattern (First .. Pos) then\n Parent := Node;\n Node := Node.Children;\n Found := True;\n exit;\n end if;\n end if;\n Node := Node.Next_Route;\n end loop;\n\n if not Found then\n E := new EL_Node_Type;\n E.Value := EL.Expressions.Create_Expression (Pattern (First .. Pos), ELContext);\n Insert (Parent, E.all'Access, MAYBE_MATCH);\n Parent := E.all'Access;\n end if;" + }, + { + "function_def": "procedure Set_Permission_Manager (Filter : in out Auth_Filter;", + "function_body": "Manager : in Policies.Policy_Manager_Access) is\n begin\n Filter.Manager := Manager;\n end Set_Permission_Manager;\n\n -- ------------------------------\n -- Filter the request to make sure the user is authenticated.\n -- Invokes the Do_Login procedure if there is no user.\n -- If a permission manager is defined, check that the user has the permission\n -- to view the page. Invokes the Do_Deny procedure if the permission\n -- is denied.\n -- ------------------------------\n overriding\n procedure Do_Filter (F : in Auth_Filter;\n Request : in out Servlet.Requests.Request'Class;\n Response : in out Servlet.Responses.Response'Class;\n Chain : in out Servlet.Core.Filter_Chain) is\n use Ada.Strings.Unbounded;\n use Policies.URLs;\n use type Policies.Policy_Manager_Access;\n\n Session : Servlet.Sessions.Session;\n SID : Unbounded_String;\n AID : Unbounded_String;\n Auth : Servlet.Principals.Principal_Access;\n\n pragma Unreferenced (SID);\n\n procedure Fetch_Cookie (Cookie : in Servlet.Cookies.Cookie);\n\n -- ------------------------------\n -- Collect the AID and SID cookies.\n -- ------------------------------\n procedure Fetch_Cookie (Cookie : in Servlet.Cookies.Cookie) is\n Name : constant String := Servlet.Cookies.Get_Name (Cookie);\n begin\n if Name = SID_COOKIE then\n SID := To_Unbounded_String (Servlet.Cookies.Get_Value (Cookie));\n elsif Name = AID_COOKIE then\n AID := To_Unbounded_String (Servlet.Cookies.Get_Value (Cookie));\n end if;\n end Fetch_Cookie;\n\n Context : aliased Contexts.Security_Context;\n begin\n Request.Iterate_Cookies (Fetch_Cookie'Access);\n\n -- Get a session but avoid creating it.\n Session := Request.Get_Session (Create => False);\n if Session.Is_Valid then\n Auth := Session.Get_Principal;\n end if;\n\n -- If the session does not have a principal, try to authenticate the user with\n -- the auto-login cookie.\n if Auth = null and then Length (AID) > 0 then\n Auth_Filter'Class (F).Authenticate (Request, Response, Session, To_String (AID), Auth);\n if Auth /= null then\n\n -- Now we must make sure we have a valid session and create it if necessary.\n if not Session.Is_Valid then\n Session := Request.Get_Session (Create => True);\n end if;\n Session.Set_Principal (Auth);\n end if;\n end if;\n\n -- A permission manager is installed, check that the user can display the page.\n if F.Manager /= null then\n if Auth = null then\n Context.Set_Context (F.Manager, null);\n else\n Context.Set_Context (F.Manager, Auth.all'Access);\n end if;\n declare\n Servlet : constant String := Request.Get_Servlet_Path;\n URL : constant String := Servlet & Request.Get_Path_Info;\n Perm : constant Policies.URLs.URL_Permission (URL'Length)\n := URL_Permission '(Len => URL'Length, URL => URL);\n begin\n if not F.Manager.Has_Permission (Context, Perm) then\n if Auth = null then\n -- No permission and no principal, redirect to the login page.\n Log.Info (\"Page need authentication on {0}\", URL);\n Auth_Filter'Class (F).Do_Login (Request, Response);\n else\n Log.Info (\"Deny access on {0}\", URL);\n Auth_Filter'Class (F).Do_Deny (Request, Response);\n end if;\n return;\n end if;\n Log.Debug (\"Access granted on {0}\", URL);" + }, + { + "function_def": "procedure List (Data : in out Test_API;", + "function_body": "Req : in out Servlet.Rest.Request'Class;\n Reply : in out Servlet.Rest.Response'Class;\n Stream : in out Servlet.Rest.Output_Stream'Class) is\n pragma Unreferenced (Data);\n begin\n if Req.Get_Path_Parameter_Count = 0 then\n Stream.Start_Document;\n Stream.Start_Array (\"list\");\n for I in 1 .. 10 loop\n Stream.Start_Entity (\"item\");\n Stream.Write_Attribute (\"id\", I);\n Stream.Write_Attribute (\"name\", \"Item \" & Natural'Image (I));\n Stream.End_Entity (\"item\");\n end loop;\n Stream.End_Array (\"list\");\n Stream.End_Document;\n else\n declare\n Id : constant String := Req.Get_Path_Parameter (1);\n begin\n if Id = \"100\" then\n Reply.Set_Status (Servlet.Responses.SC_NOT_FOUND);\n elsif Id /= \"44\" then\n Reply.Set_Status (Servlet.Responses.SC_GONE);\n end if;" + }, + { + "function_def": "procedure Test_Request_Dispatcher (T : in out Test) is", + "function_body": "Ctx : Servlet_Registry;\n\n S1 : aliased Test_Servlet1;\n begin\n Ctx.Add_Servlet (\"Faces\", S1'Unchecked_Access);\n\n Ctx.Add_Mapping (Pattern => \"*.jsf\", Name => \"Faces\");\n\n Ctx.Add_Mapping (Pattern => \"/p1/p2/p3/*\", Name => \"Faces\");\n\n Check_Request (T, Ctx, \"/home/test.jsf\", \"/home/test.jsf\", \"\");\n end Test_Request_Dispatcher;\n\n -- ------------------------------\n -- Test mapping and servlet path on a request.\n -- ------------------------------\n procedure Test_Servlet_Path (T : in out Test) is\n Ctx : Servlet_Registry;\n\n S1 : aliased Test_Servlet1;\n begin\n Ctx.Add_Servlet (\"Faces\", S1'Unchecked_Access);\n\n Ctx.Add_Mapping (Pattern => \"*.jsf\", Name => \"Faces\");\n\n Ctx.Add_Mapping (Pattern => \"/p1/p2/p3/*\", Name => \"Faces\");\n\n Check_Request (T, Ctx, \"/p1/p2/p3/home/test.html\", \"/p1/p2/p3\", \"/home/test.html\");\n Check_Request (T, Ctx, \"/root/home/test.jsf\", \"/root/home/test.jsf\", \"\");\n Check_Request (T, Ctx, \"/test.jsf\", \"/test.jsf\", \"\");\n end Test_Servlet_Path;\n\n -- ------------------------------\n -- Test mapping and servlet path on a request.\n -- ------------------------------\n procedure Test_Filter_Mapping (T : in out Test) is\n Ctx : Servlet_Registry;\n\n S1 : aliased Test_Servlet1;\n S2 : aliased Test_Servlet2;\n F1 : aliased Filters.Dump.Dump_Filter;\n F2 : aliased Filters.Dump.Dump_Filter;\n begin\n Ctx.Add_Servlet (\"Faces\", S1'Unchecked_Access);\n Ctx.Add_Servlet (\"Json\", S2'Unchecked_Access);\n Ctx.Add_Filter (\"Dump\", F1'Unchecked_Access);\n Ctx.Add_Filter (\"Dump2\", F2'Unchecked_Access);\n Ctx.Add_Mapping (Pattern => \"*.html\", Name => \"Faces\");\n Ctx.Add_Mapping (Pattern => \"*.json\", Name => \"Json\");\n Ctx.Add_Filter_Mapping (Pattern => \"/dump/file.html\", Name => \"Dump\");\n Ctx.Add_Filter_Mapping (Pattern => \"/dump/result/test.html\", Name => \"Dump\");\n Ctx.Add_Filter_Mapping (Pattern => \"/dump/result/test.html\", Name => \"Dump2\");\n Ctx.Start;\n T.Check_Mapping (Ctx, \"test.html\", S1'Unchecked_Access);\n T.Check_Mapping (Ctx, \"file.html\", S1'Unchecked_Access);\n T.Check_Mapping (Ctx, \"/dump/test.html\", S1'Unchecked_Access);\n T.Check_Mapping (Ctx, \"/dump/file.html\", S1'Unchecked_Access, 1);\n T.Check_Mapping (Ctx, \"/dump/result/test.html\", S1'Unchecked_Access, 2);\n T.Check_Mapping (Ctx, \"test.json\", S2'Unchecked_Access);\n end Test_Filter_Mapping;\n\n -- ------------------------------\n -- Test execution of filters\n -- ------------------------------\n procedure Test_Filter_Execution (T : in out Test) is\n Ctx : Servlet_Registry;\n\n S1 : aliased Test_Servlet1;\n S2 : aliased Test_Servlet2;\n F1 : aliased Filters.Tests.Test_Filter;\n F2 : aliased Filters.Tests.Test_Filter;\n begin\n Ctx.Add_Servlet (\"Faces\", S1'Unchecked_Access);\n Ctx.Add_Servlet (\"Json\", S2'Unchecked_Access);\n Ctx.Add_Filter (\"F1\", F1'Unchecked_Access);\n Ctx.Add_Filter (\"F2\", F2'Unchecked_Access);\n Ctx.Add_Mapping (Pattern => \"*.html\", Name => \"Faces\");\n Ctx.Add_Mapping (Pattern => \"*.json\", Name => \"Json\");\n Ctx.Add_Filter_Mapping (Pattern => \"/html/*.html\", Name => \"F1\");\n Ctx.Add_Filter_Mapping (Pattern => \"/json/*.json\", Name => \"F2\");\n Ctx.Add_Filter_Mapping (Pattern => \"/list/*.html\", Name => \"F1\");\n Ctx.Add_Filter_Mapping (Pattern => \"/list/*.json\", Name => \"F1\");\n Ctx.Add_Filter_Mapping (Pattern => \"/list/admin/*.html\", Name => \"F2\");\n Ctx.Add_Filter_Mapping (Pattern => \"/list/admin/*.json\", Name => \"F2\");\n Ctx.Start;\n Ctx.Dump_Routes (Util.Log.INFO_LEVEL);\n\n -- Filter not traversed.\n T.Check_Mapping (Ctx, \"test.html\", S1'Unchecked_Access);\n T.Check_Mapping (Ctx, \"test.json\", S2'Unchecked_Access);\n T.Check_Request (Ctx, \"test.html\", \"test.html\", \"\");\n Assert_Equals (T, 0, F1.Counter, \"Filter was not executed for *.html and *.json\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for *.html and *.json\");\n\n T.Check_Mapping (Ctx, \"/html/test.json\", S2'Unchecked_Access);\n T.Check_Request (Ctx, \"/html/test.json\", \"/html/test.json\", \"\");\n Assert_Equals (T, 0, F1.Counter, \"Filter was executed for /html/*.json\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for /html/*.json\");\n\n T.Check_Mapping (Ctx, \"/json/test.html\", S1'Unchecked_Access);\n T.Check_Request (Ctx, \"/json/test.html\", \"/json/test.html\", \"\");\n Assert_Equals (T, 0, F1.Counter, \"Filter was not executed for /json/*.html\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was executed for /json/*.html\");\n\n -- Only one filter is traversed.\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/html/test.html\", S1'Unchecked_Access, 1);\n T.Check_Request (Ctx, \"/html/test.html\", \"/html/test.html\", \"\");\n Assert_Equals (T, 8, F1.Counter, \"Filter was executed for /html/*.html\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for /html/*.html\");\n\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/json/test.json\", S2'Unchecked_Access, 1);\n T.Check_Request (Ctx, \"/json/test.json\", \"/json/test.json\", \"\");\n Assert_Equals (T, 0, F1.Counter, \"Filter was not executed for /json/*.json\");\n Assert_Equals (T, 8, F2.Counter, \"Filter was executed for /json/*.json\");\n\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/list/test.html\", S1'Unchecked_Access, 1);\n T.Check_Request (Ctx, \"/list/test.html\", \"/list/test.html\", \"\");\n Assert_Equals (T, 8, F1.Counter, \"Filter was executed for /list/*.html\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for /list/*.html\");\n\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/list/test.json\", S2'Unchecked_Access, 1);\n T.Check_Request (Ctx, \"/list/test.json\", \"/list/test.json\", \"\");\n Assert_Equals (T, 8, F1.Counter, \"Filter was executed for /list/*.json\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for /list/*.json\");\n\n -- Both filters are traversed.\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/list/admin/test.json\", S2'Unchecked_Access, 2);\n T.Check_Request (Ctx, \"/list/admin/test.json\", \"/list/admin/test.json\", \"\");\n Assert_Equals (T, 8, F1.Counter, \"Filter was executed for /list/admin/*.json\");\n Assert_Equals (T, 8, F2.Counter, \"Filter was executed for /list/admin/*.json\");\n\n F1.Counter := 0;\n F2.Counter := 0;\n T.Check_Mapping (Ctx, \"/list/admin/test.html\", S1'Unchecked_Access, 2);\n T.Check_Request (Ctx, \"/list/admin/test.html\", \"/list/admin/test.html\", \"\");\n Assert_Equals (T, 8, F1.Counter, \"Filter was executed for /list/admin/*.html\");\n Assert_Equals (T, 8, F2.Counter, \"Filter was executed for /list/admin/*.html\");\n end Test_Filter_Execution;\n\n -- ------------------------------\n -- Test execution of filters on complex mapping.\n -- ------------------------------\n procedure Test_Complex_Filter_Execution (T : in out Test) is\n use Util.Beans.Objects;\n procedure Insert (Route : in out Routes.Route_Type_Ref);\n\n Ctx : Servlet_Registry;\n S1 : aliased Test_Servlet1;\n F1 : aliased Filters.Tests.Test_Filter;\n F2 : aliased Filters.Tests.Test_Filter;\n User : aliased Form_Bean;\n EL_Ctx : EL.Contexts.Default.Default_Context;\n Request : Requests.Mockup.Request;\n Reply : Responses.Mockup.Response;\n\n procedure Insert (Route : in out Routes.Route_Type_Ref) is\n To : Routes.Servlets.Faces.Faces_Route_Type_Access;\n begin\n To := new Routes.Servlets.Faces.Faces_Route_Type;\n To.Servlet := S1'Unchecked_Access;\n Route := Routes.Route_Type_Refs.Create (To.all'Access);\n end Insert;\n begin\n Ctx.Add_Servlet (\"Faces\", S1'Unchecked_Access);\n Ctx.Add_Filter (\"F1\", F1'Unchecked_Access);\n Ctx.Add_Filter (\"F2\", F2'Unchecked_Access);\n Ctx.Add_Route (Pattern => \"/wikis/#{user.name}/#{user.email}/view.html\",\n ELContext => EL_Ctx,\n Process => Insert'Access);\n\n Ctx.Add_Route (Pattern => \"/wikis/#{user.name}/#{user.email}/view\",\n ELContext => EL_Ctx,\n Process => Insert'Access);\n Ctx.Add_Mapping (Pattern => \"/wikis/*.html\", Name => \"Faces\");\n Ctx.Add_Filter_Mapping (Pattern => \"/wikis/*\", Name => \"F1\");\n Ctx.Add_Filter_Mapping (Pattern => \"/wikis/admin/*\", Name => \"F2\");\n Ctx.Start;\n Ctx.Dump_Routes (Util.Log.INFO_LEVEL);\n Request.Set_Attribute (\"user\",\n To_Object (Value => User'Unchecked_Access, Storage => STATIC));\n Request.Set_Method (\"GET\");\n declare\n Dispatcher : constant Request_Dispatcher\n := Ctx.Get_Request_Dispatcher (Path => \"/wikis/Gandalf/Mithrandir/view.html\");\n Result : Ada.Strings.Unbounded.Unbounded_String;\n begin\n Request.Set_Request_URI (\"/wikis/Gandalf/Mithrandir/view.html\");\n Forward (Dispatcher, Request, Reply);\n\n -- Check the response after the Test_Servlet1.Do_Get method execution.\n Reply.Read_Content (Result);\n Assert_Equals (T, Responses.SC_OK, Reply.Get_Status, \"Invalid status\");\n Assert_Equals (T, \"URI: /wikis/Gandalf/Mithrandir/view.html\", Result, \"Invalid content\");\n Assert_Equals (T, \"Gandalf\", User.Name, \"User name was not extracted from the URI\");\n\n -- And verify that the filter are traversed.\n Assert_Equals (T, 1, F1.Counter, \"Filter was executed for /html/*.html\");\n Assert_Equals (T, 0, F2.Counter, \"Filter was not executed for /html/*.html\");" + }, + { + "function_def": "procedure Test_Name_Dispatcher (T : in out Test) is", + "function_body": "Ctx : Servlet_Registry;\n S1 : aliased Test_Servlet1;\n S2 : aliased Test_Servlet1;\n begin\n Ctx.Add_Servlet (Name => \"Faces\", Server => S1'Unchecked_Access);\n Ctx.Add_Servlet (Name => \"Text\", Server => S2'Unchecked_Access);\n declare\n Disp : constant Request_Dispatcher := Ctx.Get_Name_Dispatcher (\"Faces\");\n begin\n T.Assert (Get_Servlet (Disp) /= null, \"Get_Name_Dispatcher returned null\");" + }, + { + "function_def": "procedure Free is new Ada.Unchecked_Deallocation (Cookie_Array, Cookie_Array_Access);", + "function_body": "package Caller is new Util.Test_Caller (Test, \"Cookies\");\n\n procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is\n begin\n Caller.Add_Test (Suite, \"Test Servlet.Cookies.Create_Cookie\",\n Test_Create_Cookie'Access);\n Caller.Add_Test (Suite, \"Test Servlet.Cookies.To_Http_Header\",\n Test_To_Http_Header'Access);\n Caller.Add_Test (Suite, \"Test Servlet.Cookies.Get_Cookies\",\n Test_Parse_Http_Header'Access);\n end Add_Tests;\n\n -- ------------------------------\n -- Test creation of cookie\n -- ------------------------------\n procedure Test_Create_Cookie (T : in out Test) is\n C : constant Cookie := Create (\"cookie\", \"value\");\n begin\n T.Assert_Equals (\"cookie\", Get_Name (C), \"Invalid name\");\n T.Assert_Equals (\"value\", Get_Value (C), \"Invalid value\");\n T.Assert (not Is_Secure (C), \"Invalid is_secure\");\n end Test_Create_Cookie;\n\n -- ------------------------------\n -- Test conversion of cookie for HTTP header\n -- ------------------------------\n procedure Test_To_Http_Header (T : in out Test) is\n\n procedure Test_Cookie (C : in Cookie) is\n S : constant String := To_Http_Header (C);\n begin\n Log.Info (\"Cookie {0}: {1}\", Get_Name (C), S);\n T.Assert (S'Length > 0, \"Invalid cookie length for: \" & S);\n T.Assert (Index (S, \"=\") > 0, \"Invalid cookie format; \" & S);\n end Test_Cookie;\n\n procedure Test_Cookie (Name : in String; Value : in String) is\n C : Cookie := Create (Name, Value);\n begin\n Test_Cookie (C);\n for I in 1 .. 24 loop\n Set_Max_Age (C, I * 3600 + I);\n Test_Cookie (C);\n end loop;\n Set_Secure (C, True);\n Test_Cookie (C);\n Set_Http_Only (C, True);\n Test_Cookie (C);\n Set_Domain (C, \"world.com\");\n Test_Cookie (C);\n Set_Path (C, \"/some-path\");\n Test_Cookie (C);\n end Test_Cookie;\n\n begin\n Test_Cookie (\"a\", \"b\");\n Test_Cookie (\"session_id\", \"79e2317bcabe731e2f681f5725bbc621-&v=1\");\n Test_Cookie (\"p_41_zy\", \"\");\n Test_Cookie (\"p_34\", \"\"\"quoted\\t\"\"\");\n Test_Cookie (\"d\", \"s\");\n declare\n C : Cookie := Create (\"cookie-name\", \"79e2317bcabe731e2f681f5725bbc621\");\n Start : Util.Measures.Stamp;\n begin\n Set_Path (C, \"/home\");\n Set_Domain (C, \".mydomain.example.com\");\n Set_Max_Age (C, 1000);\n Set_Http_Only (C, True);\n Set_Secure (C, True);\n Set_Comment (C, \"some comment\");\n for I in 1 .. 1000 loop\n declare\n S : constant String := To_Http_Header (C);\n begin\n if S'Length < 10 then\n T.Assert (S'Length > 10, \"Invalid cookie generation\");\n end if;" + }, + { + "function_def": "procedure Free is new Unchecked_Deallocation (Vector, Access_Vector);", + "function_body": "-----------------------------------------------------------------------------\n --| By calling the following Reset functions, it is user's responsibility |--\n --| to keep track of dynamically allocated Access_Vector to prevent |--\n --| dangling memory space. |--\n -----------------------------------------------------------------------------\n --| Reset with new seed and new keys |--\n --| Gen.Keys = null to remove Keys |--\n procedure Reset (G : in Generator;\n New_Seed : in Seed_Type;\n New_Keys : in Access_Vector)\n is\n Gen : Access_Generator := G'Unrestricted_Access;\n begin\n Gen.Seed := New_Seed;\n Free (Gen.Keys);\n Gen.Keys := New_Keys;\n Init_By_Keys (G);\n end Reset;\n\n -----------------------------------------------------------------------------\n --| Reset with new keys |--\n --| Gen.Keys = null to remove Keys |--\n procedure Reset (G : in Generator;\n New_Keys : in Access_Vector)\n is\n Gen : Access_Generator := G'Unrestricted_Access;\n begin\n Free (Gen.Keys);\n Gen.Keys := New_Keys;\n Init_By_Keys (G);\n end Reset;\n\n -----------------------------------------------------------------------------\n --| Reset with saved Generator in string buffer |--\n procedure Reset (G : in Generator;\n G_String : in String)\n is\n Gen : Access_Generator := G'Unrestricted_Access;\n State_Length : Positive := G.State'Size / Standard.Character'Size;\n State_Buffer : String (1 .. State_Length);\n for State_Buffer use at G.State'Address;\n\n Seed_Length : Positive := G.Seed'Size / Standard.Character'Size;\n Seed_Buffer : String (1 .. Seed_Length);\n for Seed_Buffer use at G.Seed'Address;\n\n Keys_Length : Integer := 0;\n Start, Stop : Integer;\n begin\n --| Sanity check if G_String is saved state of generator |--\n if G_String (G_String'First .. G_String'First + Gen_Tag'Length - 1)\n /= Gen_Tag then\n raise Constraint_Error;\n end if;\n\n --| Get the number of keys saved, 0 if no keys |--\n --| Skip the tag and \"<\": |--\n Start := G_String'First + Gen_Tag'Length + 1;\n Stop := Start;\n while G_String (Stop) /= '>' loop\n Stop := Stop + 1;\n end loop;\n Keys_Length := Integer'Value (G_String (Start .. (Stop - 1)));\n\n --| Get State |--\n Start := Stop + 1;\n declare\n Target : String (1 .. State_Length);\n for Target use at Gen.State'Address;\n begin\n Stop := Start + State_Length;\n Target := G_String (Start .. Stop - 1);" + }, + { + "function_def": "procedure Main is", + "function_body": "function Convert_Clock(Tmp:Integer) return String is\n function Trans (I:Integer) return String is\n\t T:String(1..2);\n begin\n\t T := \"00\";\n\t if I>=10 and I<=99 then \n\t T(1..2):=Integer'Image(I)(2..3);\n\t elsif I>0 then\n\t T(2):=Integer'Image(I)(2); \n\t end if;\n\t return T;\n end Trans;\n S:String(1..8):=\" \";\n Hour,Min,Sec:Integer;\n begin\n Hour := Tmp/3600;\n S(1..2):=Trans(Hour);\n S(3):=':';\n Min := (Tmp-3600*Hour)/60;\n S(4..5) := Trans(Min);\n S(6):=':';\n Sec:=Tmp-3600*Hour-60*Min;\n S(7..8):=Trans(Sec);\n return(S);\n end Convert_Clock;\n \n Main_Error : exception;\n type MY_FIXED is delta 0.1 range -9999.9..9999.9;\n package FIXED_IO is new TEXT_IO.FIXED_IO ( MY_FIXED ) ;\n\n Has_Book : Boolean := False;\n Cast : Castling := (others=>True);\n Col, My_Col : Color;\n En_Passant :Integer := -1;\n Res : Integer :=0;\n P2 : Piece;\n N_En_Passant : Integer;\n N_Castles: Castling;\n Promote : Boolean;\n Matw, Matb : Integer;\n Valid : Boolean;\n Prof : Integer;\n Dur,Min_Delay : Float:=0.7635432;\n St : State;\n Lcb : array (0..63) of Piece;\n Today,Full_Start_Time,Start_Time,End_Time : Time;\n Full_Start_Time_Real,Start_Time_Real : Ada.Real_Time.Time;\n Have_Time : Float;\n Real_Dur : Ada.Real_Time.Time_Span;\n Max_Delay : Float;\n Tmp: Integer;\n Alpha, Beta:Integer;\n G : AdaMT19937.Generator;\n Keys : AdaMT19937.Access_Vector := new AdaMT19937.Vector (0 .. 3);\n Fail_Low,Fail_High : Boolean;\n Old_From:Integer :=-1;\n Old_To : Integer:=-1;\n Old_Xotime : Integer :=0;\n Period : Ada.Real_Time.Time_Span;\nbegin\n\n-- time 20000\n-- go\n-- Init_Boards(\"8/pR3pk1/8/2r3PP/Pn6/6K1/8/ w - - 1 40\",Col,Cast,En_Passant,Matw,Matb); \n-- This board is the classical starting board\n Init_Boards(\"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\",Col,Cast,En_Passant,Matw,Matb);\n\n Init_Masks;\n Init_Attacks;\n Has_Book := Load_All;\n Make_Z_I(Col);\n First_Ply := 0;\n Movenum:=0;\n Keys.all := (16#123#, 16#234#, 16#345#, 16#456#);\n AdaMT19937.Reset (G, Keys);\n\n-- for I in 0..63 loop\n-- Print_Intboard(King_Vicinity_I(I));\n-- Put_Line(\"\");\n-- end loop;\n-- Print_Chessboard;\n-- Tmp := Valeur(Col,Matw,Matb,Cast);\n-- raise Main_Error;\n\n\n Move_From := -1;Move_To := -1;My_Col := Black;\n\n while True loop\n <>\n if Col/=My_Col or Xboard_Force then\n if Xboard_Force then Read_Xboard(-1,-1);\n else Read_Xboard(Move_From,Move_To); end if;\n\tif Movenum /= 0 then --xtime est maintenant a jour\n\t Put(Game_Log,\" {[%eval \");\n\t if Res<-9999 then \n\t Res := -(9999-(Res+32766));\n\t elsif \n\t Res>9999 then \n\t Res:=9999+(Res-32766); \n\t end if;\n\t Fixed_Io.Put(Game_Log,My_Fixed(Float(Res)));\n\t Put(Game_Log,\"]\");\n\t Put(Game_Log,\"[%emt \");\n\t Tmp := Integer(Dur+0.5);\n\t Put(Game_Log,Convert_Clock(Tmp));\n\t Put(Game_Log,\"]\");\n\t Put(Game_Log,\"[%clk \");\n\t Put(Game_Log,Convert_Clock((Xtime+50)/100));\n\t Put(Game_Log,\"]\");\n\t Put(Game_Log,\"}\");\n\t Flush(Game_Log);\n\tend if;\n\t\n if Xboard_From=-3 then\n Init_Boards(Xboard_Fen(1..Xboard_Fen_Last),Col,Cast,En_Passant,Matw,Matb);\n Put_Line(File_Log,\"Material Start: \"&Integer'Image(Matw)&\" \"&Integer'Image(Matb));\n Init_Masks;\n Init_Attacks;\n Make_Z_I(Col);\n My_Col := -Col;\n Print_Chessboard(File_Log);\n goto Do_It_Again;\n end if;\n Move_From := Xboard_From;\n Move_To := Xboard_To;\n Res := 0;\n Put_Line(File_Log,\"Color:\"&Color'Image(Col)&\" My_col:\"&Color'Image(My_Col)&\" xboard_force:\"\n &Boolean'Image(Xboard_Force));\n if Move_From = -1 then My_Col := Col; end if;\n Put_Line(File_Log,\"Color:\"&Color'Image(Col)&\" My_col:\"&Color'Image(My_Col)&\" xboard_force:\"\n &Boolean'Image(Xboard_Force));\n Print_Chessboard(File_Log);\n end if;\n if Movenum=0 then\n Put_Line(File_Log,\"Starting pgn log\");\n Put_Line(Game_Log,\"[Event \"\"Freechess test\"\"]\");\n Put_Line(Game_Log,\"[Site \"\"Freechess\"\"]\");\n Today := Clock;\n Put_Line(Game_Log,\"[Date \"\"\"&\n Integer'Image(Year(Today))&\".\"&\n Integer'Image(Month(Today))&\".\"&\n Integer'Image(Day(Today))&\n \"\"\"]\");\n if XT1/=0 then\n Put_Line(Game_Log,\"[TimeControl \"\"\"&Integer'Image(Xt1)&\"/\"&Integer'Image(Xt2*60)&\n \"\"\"]\");\n else\n if Xt3=0 then\n Put_Line(Game_Log,\"[TimeControl \"\"\"&Integer'Image(Xt2*60)&\"\"\"]\");\n else\n Put_Line(Game_Log,\"[TimeControl \"\"\"&Integer'Image(Xt2*60)&\"+\"&Integer'Image(Xt3)&\"\"\"]\");\n end if;\n end if;\n if My_Col=Black then\n Put_Line(Game_Log,\"[White \"\"\"&Xname(1..Xname_Last)&\"\"\"]\");\n Put_Line(Game_Log,\"[Black \"\"Lovelace\"\"]\");\n Put_Line(Game_Log,\"[WhiteElo \"\"\"&Integer'Image(XratingO)&\"\"\"]\");\n Put_Line(Game_Log,\"[BlackElo \"\"\"&Integer'Image(XratingC)&\"\"\"]\");\n else\n Put_Line(Game_Log,\"[White \"\"Lovelace\"\"]\");\n Put_Line(Game_Log,\"[Black \"\"\"&Xname(1..Xname_Last)&\"\"\"]\");\n Put_Line(Game_Log,\"[WhiteElo \"\"\"&Integer'Image(XratingC)&\"\"\"]\");\n Put_Line(Game_Log,\"[BlackElo \"\"\"&Integer'Image(XratingO)&\"\"\"]\");\n end if;\n Put_Line(Game_Log,\"\");\n Flush(Game_Log);\n end if;\n if Col = My_Col and not Xboard_Force Then\n begin\n Full_Start_Time := Clock;\n Full_Start_Time_Real := Ada.Real_Time.Clock;\n Move_From := -1;Move_To := -1;Old_From:=-1;Old_To:=-1;\n\t Prof := 10;Alpha:=-32767;Beta:=32767;\n Have_Time := Float(Xtime)/100.0;\n if Have_Time<5.0 then Min_Delay:=0.2;\n elsif Have_Time<15.0 then Min_Delay:=0.3;\n elsif Have_Time<30.0 then Min_Delay:=0.5;\n\t elsif Have_Time<60.0 then Min_Delay:=0.75;\n\t elsif Have_Time<120.0 then Min_Delay:=1.0;\n else Min_Delay := 1.5; end if;\n Put_Line(File_Log,\"Xtime=\"&Integer'Image(Xtime));\n if Has_Book then\n Get_Book(Move_From,Move_To,Col,Cast,En_Passant);\n if Move_From/=-1 then\n Put_Line(File_Log,\"Raising end_thinking in get_book\");\n raise End_Thinking;\n end if;\n end if;\n loop\n Put_Line(File_Log,\"Starting main loop\");\n Start_Time_real := Ada.Real_Time.Clock;\n Start_Time := Clock;\n if XT1/=0 then\n Tmp := (Movenum/2) mod XT1;\n Tmp := XT1 - Tmp;\n Max_Delay := Have_Time/Float(Tmp+1);\n Max_Delay := (4.0*Max_Delay)/3.0;\n Put_Line(File_Log,\"Max_delay=\"&Float'Image(Max_Delay)\n &\" Tmp=\"&Integer'Image(Tmp)&\" Have_time=\"&Float'Image(Have_Time)\n &\" Movenum=\"&Integer'Image(Movenum));\n else\n Tmp := Integer'Max(30-abs(Matw+Matb)/100,10);\n Max_Delay := Float(XT3)+Have_Time/Float(Tmp);\n Put_Line(File_Log,\n \"Max_delay=\"&Float'Image(Max_Delay)\n &\" Have_time=\"&Float'Image(Have_Time)\n &\" Movenum=\"&Integer'Image(Movenum)\n &\" mat=\"&Integer'Image(Tmp));\n end if;\n if Max_DelayAlpha and Res Max_Delay/3.0) and (Float(End_Time-Full_Start_Time)>Min_Delay) then\n Put_Line(File_Log,\n \"Raising end_thinking. Dur=\"&Float'Image(Dur)&\n \" max_delay=\"&Float'Image(Max_Delay)&\n \" min_delay=\"&Float'Image(Min_Delay));\n raise End_Thinking;\n end if;\n if Prof>=2000 then\n Put_Line(File_Log,\"Raising End_thinking because prof>=2000\");\n raise End_Thinking;\n end if;\n Prof := Prof+10;\n Put_Line(File_Log,\"Adding 10 to prof. New prof:\"&Integer'Image(Prof));\n end select;\n end loop;\n exception\n when End_Thinking =>\n Put_Line(File_Log,\"End thinking\");\n Real_Dur := Ada.Real_Time.\"-\"(Ada.Real_Time.Clock,Full_Start_Time_Real);\n Dur := Float(Clock-Full_Start_Time);\n if Dur=0) and (J<=7) and (J>=0));\n end Is_In_Bounds;\n\n procedure Init_Knight_Attacks is\n Knight_Moves : array (0..7,0..1) of Integer := ((1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1));\n begin\n for I in 0..63 loop\n Knight_Attacks_I(I) := 0;\n Knight_Mobility(I) := 0;\n end loop;\n for I in 0..7 loop\n for J in 0..7 loop\n for K in 0..7 loop\n if Is_In_Bounds(I+Knight_Moves(K,0),J+Knight_Moves(K,1)) then\n Knight_Attacks_B(I*8+J)((I+Knight_Moves(K,0))*8+J+Knight_Moves(K,1)) := 1;\n Knight_Mobility(I*8+J):=Knight_Mobility(I*8+J)+1;\n end if;\n end loop;\n end loop;\n end loop;\n end Init_Knight_Attacks;\n\n procedure Init_King_Attacks is\n King_Moves : array (0..7,0..1) of Integer := ((1,1),(1,0),(1,-1),(0,1),(0,-1),(-1,1),(-1,0),(-1,-1));\n begin\n for I in 0..63 loop\n King_Attacks_I(I) := 0;\n end loop;\n for I in 0..7 loop\n for J in 0..7 loop\n for K in 0..7 loop\n if Is_In_Bounds(I+King_Moves(K,0),J+King_Moves(K,1)) then\n King_Attacks_B(I*8+J)((I+King_Moves(K,0))*8+J+King_Moves(K,1)) := 1; end if;\n end loop;\n end loop;\n end loop;\n end Init_King_Attacks;\n\n procedure Init_White_Pawn_Attacks is\n Pawn_Inc : array (0..1,0..1) of Integer := ((1,1),(1,-1));\n I : Integer :=0;\n J : Integer :=0;\n begin\n for I in 0..63 loop\n White_Pawn_Attacks_I(I):=0;\n end loop;\n for I in 0..7 loop\n for J in 0..7 loop\n for K in 0..1 loop\n if Is_In_Bounds(I+Pawn_Inc(K,0),J+Pawn_Inc(K,1)) then\n White_Pawn_Attacks_B(I*8+J)((I+Pawn_Inc(K,0))*8+J+Pawn_Inc(K,1)) := 1;\n end if;\n end loop;\n end loop;\n end loop;\n end Init_White_Pawn_Attacks;\n\n procedure Init_Black_Pawn_Attacks is\n Pawn_Inc : array (0..1,0..1) of Integer := ((-1,1),(-1,-1));\n begin\n for I in 0..63 loop\n Black_Pawn_Attacks_I(I):=0;\n end loop;\n for I in 0..7 loop\n for J in 0..7 loop\n for K in 0..1 loop\n if Is_In_Bounds(I+Pawn_Inc(K,0),J+Pawn_Inc(K,1)) then\n Black_Pawn_Attacks_B(I*8+J)((I+Pawn_Inc(K,0))*8+J+Pawn_Inc(K,1)) := 1; end if;\n end loop;\n end loop;\n end loop;\n end Init_Black_Pawn_Attacks;\n\n\n procedure Init_White_Pawn_Moves1 is\n begin\n for I in 0..63 loop\n White_Pawn_Moves1_I(I):=0;\n end loop;\n for I in 1..7 loop\n for J in 0..7 loop\n if Is_In_Bounds(I+1,J) then\n White_Pawn_Moves1_B(I*8+J)((I+1)*8+J) := 1; end if;\n end loop;\n end loop;\n end Init_White_Pawn_Moves1;\n\n procedure Init_Black_Pawn_Moves1 is\n begin\n for I in 0..63 loop\n Black_Pawn_Moves1_I(I):=0;\n end loop;\n for I in 0..6 loop\n for J in 0..7 loop\n if Is_In_Bounds(I-1,J) then\n Black_Pawn_Moves1_B(I*8+J)((I-1)*8+J) := 1; end if;\n end loop;\n end loop;\n end Init_Black_Pawn_Moves1;\n\n procedure Init_White_Pawn_Moves2 is\n begin\n for I in 0..63 loop\n White_Pawn_Moves2_I(I):=0;\n end loop;\n for J in 0..7 loop\n White_Pawn_Moves2_B(8+J)(24+J) := 1;\n end loop;\n end Init_White_Pawn_Moves2;\n\n procedure Init_Black_Pawn_Moves2 is\n begin\n for I in 0..63 loop\n Black_Pawn_Moves2_I(I):=0;\n end loop;\n for J in 0..7 loop\n Black_Pawn_Moves2_B(48+J)(32+J) := 1;\n end loop;\n end Init_Black_Pawn_Moves2;\n\n -- All_Pieces_90_B(8*I+J) := All_Pieces_B(8*(7-J)+I);\n\n function Find_Rank(B:Natural) return Natural is\n begin\n return Natural(Shift_Right(All_Pieces_I and (Shift_Left(255,8*(B/8))),8*(B/8)));\n end Find_Rank;\n\n function Find_Rank_90(B:Natural) return Natural is\n begin\n return Natural(Shift_Right(All_Pieces_90_I and (Shift_Left(255,8*(B mod 8))),8*(B mod 8)));\n end Find_Rank_90;\n\n function Find_Rank_45r (B:Natural) return Natural is\n begin\n return Natural(Shift_Right((All_Pieces_45r_I and Mask_45r_rev(B)),Start_45r_Rev(B)));\n end Find_Rank_45r;\n\n function Find_Rank_45l (B:Natural) return Natural is\n begin\n return Natural(Shift_Right((All_Pieces_45l_I and Mask_45l_rev(B)),Start_45l_Rev(B)));\n end Find_Rank_45l;\n\n procedure Init_Rank_Attacks is\n Base,Ind : Integer;\n R : Unsigned_8;\n Final_I : Intboard;\n Final_B : Bitboard;\n pragma Import(Ada,Final_B);\n for Final_B'Address use Final_I'Address;\n L,D : Integer;\n begin\n for I in 0..63 loop\n Base := I/8;Ind := I mod 8;\n for J in Unsigned_8 (0) .. Unsigned_8(255) loop\n Rank_Mobility(I,Integer(J)) := 0;\n Rank_Mobility_90(I,Integer(J)) := 0;\n Rank_Mobility_45r(I,Integer(J)) := 0;\n Rank_Mobility_45l(I,Integer(J)) := 0;\n R:=0;\n for K in reverse 0 .. Ind-1 loop\n R := R or Shift_Left(1,K);\n Rank_Mobility(I,Integer(J)) := Rank_Mobility(I,Integer(J))+1;\n exit when (J and Shift_Left(1,K))/=0;\n end loop;\n for K in Ind+1 .. 7 loop\n R := R or Shift_Left(1,K);\n Rank_Mobility(I,Integer(J)) := Rank_Mobility(I,Integer(J))+1;\n exit when (J and Shift_Left(1,K))/=0;\n end loop;\n Rank_Attacks_I(I,Integer(J)) := Shift_Left(Intboard(R),(8*Base));\n end loop;\n end loop;\n\n for I in 0..7 loop\n for J in 0..7 loop\n for M in 0..255 loop\n for B in 0..7 loop\n Rank_Attacks_90_B(8*I+J,M)(8*(7-B)+J) := Rank_Attacks_B(7-I,M)(B);\n if Rank_Attacks_B(7-I,M)(B)=1 then\n Rank_Mobility_90(8*I+J,M):= Rank_Mobility_90(8*I+J,M)+1;\n end if;\n end loop;\n end loop;\n end loop;\n end loop;\n\n for B in 0..63 loop\n L := To_45r(B);\n for J in 0..(2**Length_45r(L)-1) loop\n Rank_Attacks_45r_I(B,J) := 0;\n Final_I := Rank_Attacks_I(Pos_45r(L),J) and (2**Length_45r(L)-1);\n for K in 0 .. Length_45r(L)-1 loop\n D := From_45r(K+Start_45r(L));\n Rank_Attacks_45r_B(B,J)(D) := Final_B(K);\n if Final_B(K)=1 then\n Rank_Mobility_45r(B,J):=Rank_Mobility_45r(B,J)+1;\n end if;\n end loop;\n end loop;\n end loop;\n\n for B in 0..63 loop\n L := To_45l(B);\n for J in 0..(2**Length_45l(L)-1) loop\n Rank_Attacks_45l_I(B,J) := 0;\n Final_I := Rank_Attacks_I(Pos_45l(L),J) and (2**Length_45l(L)-1);\n for K in 0 .. Length_45l(L)-1 loop\n D := From_45l(K+Start_45l(L));\n Rank_Attacks_45l_B(B,J)(D) := Final_B(K);\n if Final_B(K)=1 then\n Rank_Mobility_45l(B,J):=Rank_Mobility_45l(B,J)+1;\n end if;\n end loop;\n end loop;\n end loop;\n\n\n end Init_Rank_Attacks;\n\n procedure Init_Attacks is\n begin\n Init_Knight_Attacks;\n Init_King_Attacks;\n Init_White_Pawn_Attacks;\n Init_Black_Pawn_Attacks;\n Init_White_Pawn_Moves1;\n Init_Black_Pawn_Moves1;\n Init_White_Pawn_Moves2;\n Init_Black_Pawn_Moves2;\n Init_Rank_Attacks;\n end Init_Attacks;\n\n procedure Print_Bitboard (B:Bitboard) is\n begin\n for I in reverse 0..7 loop\n for J in 0 .. 7 loop\n if B(I*8+J)=1 then Put(\"X \"); else Put(\". \"); end if;\n end loop;\n Put_Line(\"\");\n end loop;\n end Print_Bitboard;\n\n procedure Print_Bitboard_45 (B:Bitboard) is\n L : Integer := 1;\n K : Integer := 1;\n Base : Integer := 63;\n begin\n while L <=15 loop\n for I in 1..8-K loop\n Put(\" \");\n end loop;\n for I in Base..Base+K-1 loop\n if B(I)=1 then Put(\"X \"); else Put(\". \"); end if;\n Put(\" \");\n end loop;\n Put_Line(\"\");\n L := L+1;\n if L<=8 then K:=L; else K := 16-L; end if;\n Base := Base - K;\n end loop;\n end Print_Bitboard_45;\n\n\n procedure Print_Chessboard is\n K : Integer;\n begin\n for I in reverse 0..7 loop\n for J in 0..7 loop\n K := I*8+J;\n if All_Pieces_B(K)=1 then\n begin\n if White_Rooks_B(K)=1 then Put(\"R \"); end if;\n if Black_Rooks_B(K)=1 then Put(\"r \"); end if;\n if White_Knights_B(K)=1 then Put(\"N \"); end if;\n if Black_Knights_B(K)=1 then Put(\"n \"); end if;\n if White_Bishops_B(K)=1 then Put(\"B \"); end if;\n if Black_Bishops_B(K)=1 then Put(\"b \"); end if;\n if White_Queens_B(K)=1 then Put(\"Q \"); end if;\n if Black_Queens_B(K)=1 then Put(\"q \"); end if;\n if White_Kings_B(K)=1 then Put(\"K \"); end if;\n if Black_Kings_B(K)=1 then Put(\"k \"); end if;\n if White_Pawns_B(K)=1 then Put(\"P \"); end if;\n if Black_Pawns_B(K)=1 then Put(\"p \"); end if;" + }, + { + "function_def": "procedure Store is", + "function_body": "begin\n Table(Ind).Low := Integer_16(Low); Table(Ind).High := Integer_16(High);\n Table(Ind).From := Unsigned_6(From); Table(Ind).To := Unsigned_6(To);\n Table(Ind).Prof := Integer_10(Prof); Table(Ind).Movenum := Unsigned_8(Movenum);\n Table(Ind).Valid := Valid;Table(Ind).I := Z_I;\n\t \n--\t for I in 0..63 loop\n--\t Plus := Unsigned_4(Chess_Board(I));\n\t --Codage bizarre transformant le codage du roi blanc (3) en 4\n\t --Comme le 4 n'existe pas cela permet de stocker la couleur (!)\n--\t if Plus = 3 and C=Black then Plus:=4; end if;\n--\t Table(Ind).Board(I):=Plus;\n--\t end loop;\n\t \n end Store;\n pragma Inline(Store);\n begin\n Ind := Integer(Shift_Right(Z_I,64-Nb_Bits));\n if Z_I = Table(Ind).I then\n -- Exactly same position\n if Prof >= Integer(Table(Ind).Prof) then\n --Same position researched deeper\n Store;\n else\n -- Same position, lower depth, store should not happen?\n -- raise Hash_Error;\n null;\n end if;\n else\n -- New position=> collision. Shall we replace the other one?\n if Movenum /= Integer(Table(Ind).Movenum) or else Prof >= Integer(Table(Ind).Prof) then\n --store if different move, or better prof\n Store;\n end if;\n end if;" + }, + { + "function_def": "function AddElemToAllLists (LL : Partition_Type; I : Integer) return Partition_Type", + "function_body": "is\n\t\t\t\t\t-- sub function to add an integer to the front of a partition\n\t\t\t\t\tfunction AddElemToFront (L : Partition; I : Integer) return Partition\n\t\t\t\t\tis\n\t\t\t\t\t\tRetL : Partition;\n\t\t\t\t\tbegin\n\t\t\t\t\t\tfor J in L'Range loop\n\t\t\t\t\t\t\t-- adds to front\n\t\t\t\t\t\t\tif (J = 0) then\n\t\t\t\t\t\t\t\tRetL (J) := I;\n\t\t\t\t\t\t\t-- cuts off last digit in initial partition\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tRetL (J) := L(J - 1);\n\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\tend loop;\n\t\t\t\t\t\treturn RetL;\n\t\t\t\t\tend AddElemToFront;\n\n\t\t\t\t\tLLFirst : Partition := LL(0);\n\t\t\t\t\tRetLL : Partition_Type (LL'Range);\n\n\t\t\t\tbegin\n\t\t\t\t\t-- -1 is the initialization value for all indices in the array\n\t\t\t\t\tif (LLFirst (0) = -1) then\n\t\t\t\t\t\treturn LL;\n\t\t\t\t\telse\n\t\t\t\t\t\t-- iterates through all lists and adds element\n\t\t\t\t\t\tfor J in LL'Range loop\n\t\t\t\t\t\t\tRetLL (J) := AddElemToFront ((LL (J)), I);\n\t\t\t\t\t\tend loop;\n\t\t\t\t\tend if;\n\t\t\t\t\treturn RetLL;\n\t\t\t\tend AddElemToAllLists;\n\n\t\t\t\t-- adds two lists of lists together\n\t\t\t\tfunction ConcatList (LL1, LL2 : Partition_Type) return Partition_Type\n\t\t\t\tis\n\t\t\t\t\tRetLL : Partition_Type (0 .. (LL1'Length + LL2'Length - 1));\n\t\t\t\t\tLL1First : Partition := LL1 (0);\n\t\t\t\t\tLL2First : Partition := LL2 (0);\n\t\t\t\tbegin\n\t\t\t\t\t-- checks emptinesses of lists\n\t\t\t\t\tif ((LL1First (0) = -1) and (LL2First (0) = -1)) then\n\t\t\t\t\t\treturn LL1;\n\t\t\t\t\telsif (LL1First (0) = -1) then\n\t\t\t\t\t\treturn LL2;\n\t\t\t\t\telsif (LL2First (0) = -1) then\n\t\t\t\t\t\treturn LL1;\n\t\t\t\t\telse\n\t\t\t\t\t\t-- puts in LL1\n\t\t\t\t\t\tfor I in LL1'Range loop\n\t\t\t\t\t\t\tRetLL (I) := LL1 (I);\n\t\t\t\t\t\tend loop;\n\t\t\t\t\t\t-- puts in LL2\n\t\t\t\t\t\tfor I in LL2'Range loop\n\t\t\t\t\t\t\tRetLL (I + LL1'Length) := LL2(I);\n\t\t\t\t\t\tend loop;\n\t\t\t\t\tend if;\n\t\t\t\t\treturn RetLL;\n\t\t\t\tend ConcatList;\n\t\t\t\t\n\t\t\t\t-- compiles a list of partitions\n\t\t\t\tfunction PrimePartition (N, K, J : Integer) return Partition_Type\n\t\t\t\tis\n\t\t\t\t\tEmpty_Partition : Partition := (others => -1);\n\t\t\t\t\tEmpty_Partition_Type : Partition_Type (0 .. 0) := (0 => Empty_Partition);\n\t\t\t\t\tPrimes : Sieve_Type := SievePrimes (N, K);\n\t\t\t\t\tIPrime : Integer := 0;\n\t\t\t\t\tNPrimePartition : Partition := (0 => N, others => -1);\n\t\t\t\t\tNPrimeList : Partition_Type (0 .. 0) := (0 => NPrimePartition);\n\t\t\t\tbegin\n\t\t\t\t\t-- gets the lowest prime between K and N\n\t\t\t\t\tfor I in Primes'Range loop\n\t\t\t\t\t\tif (Primes (I)) then\n\t\t\t\t\t\t\tIPrime := I;\n\t\t\t\t\t\t\texit when True;\n\t\t\t\t\t\tend if;\n\t\t\t\t\tend loop;\n\t\t\t\t\t-- if no primes then return empty list\n\t\t\t\t\tif (IPrime = 0) then\n\t\t\t\t\t\treturn Empty_Partition_Type;\n\t\t\t\t\tend if;\n\t\t\t\t\t-- if bad input then return empty list\n\t\t\t\t\tif ((N <= 1) or (N < K)) then\n\t\t\t\t\t\treturn Empty_Partition_Type;\n\t\t\t\t\t-- if n is prime and first call with n as n\n\t\t\t\t\telsif ((IsPrime (N)) and (J = 1)) then\n\t\t\t\t\t\t-- add the prime to the sub partitions returned concatenated with partitions using the same n concatenated with n\n\t\t\t\t\t\treturn ConcatList ((ConcatList ((AddElemToAllLists ((PrimePartition ((N - IPrime), (IPrime + 1), 1)), IPrime)), (primePartition (N, (IPrime + 1), (J + 1))))), NPrimeList);\n\t\t\t\t\telse\n\t\t\t\t\t\t-- same as above but don't concat n\n\t\t\t\t\t\treturn ConcatList ((AddElemToAllLists ((PrimePartition ((N - IPrime), (IPrime + 1), 1)), IPrime)), (primePartition (N, (IPrime + 1), (J + 1))));\n\t\t\t\t\tend if;\n\t\t\t\tend PrimePartition;\n\n\t\t\t\t-- prints a list of partitions in the desired format\n\t\t\t\tprocedure PrintLL (LL : Partition_Type)\n\t\t\t\tis\n\t\t\t\tbegin\n\t\t\t\t\tfor I in LL'Range loop\n\t\t\t\t\t\tdeclare\n\t\t\t\t\t\t\tL : Partition := (LL (I));\n\t\t\t\t\t\tbegin\n\t\t\t\t\t\t\tfor J in L'Range loop\n\t\t\t\t\t\t\t\tif ((L (J)) = -1) then\n\t\t\t\t\t\t\t\t\texit;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tAda.Text_IO.Put(Integer'Image (L (J)) & \" \");\n\t\t\t\t\t\t\t\tend if;\n\t\t\t\t\t\t\tend loop;" + }, + { + "function_def": "procedure words is", + "function_body": "package ASU renames Ada.Strings.Unbounded;\n\tpackage ACL renames Ada.Command_Line;\n\tpackage ATI renames Ada.Text_IO;\n\tpackage WL renames Word_Lists;\n\n\tFile_Name: ASU.Unbounded_String;\n\tFich: Ada.Text_IO.File_Type;\n\tList: WL.Word_List_Type;\n\tWord: ASU.Unbounded_String;\n\tCount: Natural;\n\n\n\tprocedure Print_Menu is\n\t\n\t--Imprime el men\u00fa interactivo\n\n\tbegin\n\t\tATI.New_Line;\n\t\tATI.Put_Line(\"Options\");\n\t\tATI.Put_Line(\"1 Add Word\");\n\t\tATI.Put_Line(\"2 Delete Word\");\n\t\tATI.Put_Line(\"3 Search Word\");\n\t\tATI.Put_Line(\"4 Show all words\");\n\t\tATI.Put_Line(\"5 Quit\");\n\t\tATI.New_Line;\n\t\tATI.Put(\"Your option? \");\n\tend Print_Menu;\n\n\t--Divide las l\u00edneas en palabras y las almacena en la lista\n\n\tprocedure Divide_In_Words (Line: in out Asu.Unbounded_String; Delimiter: in string) is\n\n\t\tWord: ASU.Unbounded_String; \n\t\tEol: Boolean;\n\t\tPosition: Integer;\n\n\tbegin\n\t\tEol := False;\n\t\twhile not Eol loop\n\t\t\t\n\t\t\tPosition := ASU.Index(Line, Delimiter);\n\t\t\t\n\t\t\t-- Si la l\u00ednea no tiene m\u00e1s palabras\n\t\t\tif ASU.Length(Line) = 0 then \n\t\t\t\tEol := True;\n\n\t\t\t-- Si ya no hay mas delimitadores\n\t\t\telsif ASU.Index(Line, Delimiter) = 0 then\n\n\t\t\t\tWord := ASU.Tail(Line, ASU.Length(Line) - Position);\n\t\t\t\tWL.Add_Word(List, Word);\n\t\t\t\tEol := True;\n\t\t\telse\n\t\t\t\tEol := False;\n\t\t\n\t\t\t\t-- Si hay dos blancos seguidos\n\t\t\t\tif (Position - 1) = 0 then\n\t\t\t\t\t-- Me salta el blanco\n\t\t\t\t\tASU.Tail(Line, ASU.Length(Line) - Position);\n\t\t\t\telse\n\t\t\t\t\tWord := ASU.Head (Line, Position - 1);\n\t\t\t\t\tASU.Tail(Line, ASU.Length(Line) - Position);\n\t\t\t\t\tWL.Add_Word(List, Word);\n\t\t\t\tend if;\n\t\t\tend if;\n\t\tend loop;\n\tend Divide_In_Words;\n\n\t--Lee el fichero\n\n\tprocedure Read_Fich is\n\n\tLine: ASU.Unbounded_String;\n\n\tbegin\n\t\twhile not ATI.End_Of_File(Fich) loop\n\t\t\tLine := ASU.To_Unbounded_String(Ada.Text_IO.Get_Line(Fich));\n\t\t\tDivide_In_Words(Line, \" \");\n\t\tend loop;\n\tend Read_Fich;\n\n\tprocedure Basic_Mode (List: in out WL.Word_List_Type;\n\t\t\t\tWord: in out ASU.Unbounded_String;\n\t\t\t\tCount: in out Natural) is\n\t\n\tbegin\n\t\tWL.Max_Word(List, Word, Count);\n\t\tATI.Put(\"The most frequent word: \");\n\t\tATI.Put(\"|\" & ASU.To_String(Word) & \"| -\" );\n\t\tATI.Put_Line(Integer'Image(Count));\n\t\tATI.New_Line;\n\t\tATI.New_Line;\n\n\tend Basic_Mode;\n\n\tprocedure Interactive_Mode (List: in out WL.Word_List_Type;\n\t\t\t\t\tWord: in out ASU.Unbounded_String;\n\t\t\t\t\tCount: in out Natural) is\n\t\n\tOption: Integer;\n\n\tbegin\n\t\t-- Muestra el men\u00fa y realiza las diferentes funciones hasta que pulsamos el quit\n\t\tloop\n\t\t\tbegin\n\t\t\t\tPrint_Menu;\t \n\t\t\t\tOption := Integer'Value(ATI.Get_Line);\n\n\t\t\t\t\tcase Option is\n\n\t\t\t\t\t-- A\u00f1ade una palabra a la lista\n\t\t\t\t\twhen 1 =>\n\t\t\t\t\t\tATI.Put(\"Word? \");\n\t\t\t\t\t\tWord := ASU.To_Unbounded_String(ATI.Get_Line);\n\t\t\t\t\t\tWL.Add_Word(List, Word);\n\t\t\t\t\t\tATI.Put_Line(\"Word |\" & ASU.To_String(Word)\n\t\t\t\t\t\t& \"| added\");\n\n\t\t\t\t\t-- Borra una palabra de la lista\n\t\t\t\t\twhen 2 =>\n\t\t\t\t\t\tATI.Put(\"Word? \");\n\t\t\t\t\t\tWord := ASU.To_Unbounded_String(ATI.Get_Line);\n\t\t\t\t\t\tWL.Delete_Word (List, Word);\n\n\t\t\t\t\t\tATI.New_Line;\n\t\t\t\t\t\tATI.Put(\"|\" & ASU.To_String(Word) & \"| \"\n\t\t\t\t\t\t& \"deleted\");\n\t\t\t\t\t\tATI.New_Line;\n\t\t\t\t\n\t\t\t\t\t-- Busca una palabra en la lista\n\t\t\t\t\twhen 3 =>\n\t\t\t\t\t\tATI.Put(\"Word? \");\n\t\t\t\t\t\tWord := ASU.To_Unbounded_String(ATI.Get_Line);\n\t\t\t\t\t\tWL.Search_Word(List, Word, Count);\n\n\t\t\t\t\t\tATI.New_Line;\n\t\t\t\t\t\tATI.Put(\"|\" & ASU.To_String(Word) & \"| - \" );\n\t\t\t\t\t\tATI.Put_Line(Integer'Image(Count));\n\n\t\t\t\t\t-- Imprime la lista\n\t\t\t\t\twhen 4 =>\n\t\t\t\t\t\tWL.Print_All(List);\n\n\t\t\t\t\t-- Imprime la palabra que m\u00e1s aparece y sale del bucle \n\t\t\t\t\twhen 5 =>\n\t\t\t\t\t\tWL.Max_Word(List, Word, Count);\n\t\t\t\t\t\tATI.Put(\"The most frequent word: \");\n\t\t\t\t\t\tATI.Put(\"|\" & ASU.To_String(Word) & \"| -\" );\n\t\t\t\t\t\tATI.Put_Line(Integer'Image(Count));\n\t\t\t\t\t\tATI.New_Line;\n\t\t\t\t\t\tATI.New_Line;\n\t\t\t\t\twhen others =>\n\t\t\t\t\t\tATI.Put_Line(\"Not implemented\");\n\n\t\t\t\t\tend case;\n\n\t\t\texception\n\t\t\t\twhen Constraint_Error =>\n\t\t\t\tATI.Put_Line(\"Incorrect Option\");" + }, + { + "function_def": "procedure Close is", + "function_body": "begin\n GNAT.Sockets.Close_Socket(Sender_Socket);\n end Close;\n\n procedure Send_Vram(Vram : in Emulator_8080.Processor.Vram_Type) is\n use Ada.Streams;\n Data : Ada.Streams.Stream_Element_Array(1 .. Vram'Length);\n Counter : Ada.Streams.Stream_Element_Offset := Data'First;\n Last : Ada.Streams.Stream_Element_Offset;\n begin\n for I in Vram'Range loop\n Data(Counter) := Ada.Streams.Stream_Element(Vram(I));\n Counter := Counter + 1;\n end loop;\n Gnat.Sockets.Send_Socket (Sender_Socket, Data, Last, Address);" + }, + { + "function_def": "procedure Finish (Data : in out Snapshot_Type) is", + "function_body": "begin\n Data.Offset := Data.Offset + Data.Count;\n end Finish;\n\n -- ------------------------------\n -- Set the value in the snapshot.\n -- ------------------------------\n procedure Set_Value (Into : in out Snapshot_Type;\n Def : in Schemas.Definition_Type_Access;\n Value : in Uint64) is\n begin\n if Def /= null and then Def.Index > 0 then\n Into.Values (Def.Index + Into.Offset) := Value;\n end if;\n end Set_Value;\n\n -- ------------------------------\n -- Iterate over the values in the snapshot and collected for the definition node.\n -- ------------------------------\n procedure Iterate (Data : in Helios.Datas.Snapshot_Type;\n Node : in Helios.Schemas.Definition_Type_Access;\n Process : not null access procedure (Value : in Uint64)) is\n Count : constant Helios.Datas.Value_Array_Index := Data.Count;\n Pos : Helios.Datas.Value_Array_Index := Node.Index;\n begin\n Log.Debug (\"Iterate {0} from {1} to {2} step {3}\", Node.Name,\n Value_Array_Index'Image (Count),\n Value_Array_Index'Image (Pos));\n while Pos < Data.Offset loop\n Process (Data.Values (Pos));\n Pos := Pos + Count;\n end loop;\n end Iterate;\n\n -- ------------------------------\n -- Iterate over the values in the snapshot and collected for the definition node.\n -- ------------------------------\n procedure Iterate (Data : in Helios.Datas.Snapshot_Type;\n Node : in Helios.Schemas.Definition_Type_Access;\n Process_Snapshot : not null access\n procedure (D : in Snapshot_Type;\n N : in Definition_Type_Access);\n Process_Values : not null access\n procedure (D : in Snapshot_Type;\n N : in Definition_Type_Access)) is\n Child : Helios.Schemas.Definition_Type_Access;\n begin\n Child := Node.Child;\n while Child /= null loop\n if Child.Child /= null then\n Process_Snapshot (Data, Child);\n elsif Child.Index > 0 then\n Process_Values (Data, Child);\n end if;\n Child := Child.Next;\n end loop;\n end Iterate;\n\n -- ------------------------------\n -- Iterate over the values of the reports.\n -- ------------------------------\n procedure Iterate (Report : in Report_Queue_Type;\n Process : not null access procedure (Data : in Snapshot_Type;\n Node : in Definition_Type_Access)) is\n begin\n if not Report.Snapshot.Is_Null then\n declare\n List : constant Snapshot_Accessor := Report.Snapshot.Value;\n Snapshot : Snapshot_Type_Access := List.First;\n begin\n while Snapshot /= null loop\n Process (Snapshot.all, Snapshot.Schema);\n Snapshot := Snapshot.Next;\n end loop;" + }, + { + "function_def": "procedure Register (Op : in out Operation'Class;", + "function_body": "Name : String := Image (Subprogram_Name);\n Disabled : Boolean := False;\n Parallelize : Boolean := True) is\n begin\n null;\n end Register;\n pragma Unreferenced (Register);\n\n function Num_Total_Tests (Self : Gather) return Integer is\n use all type Ada.Containers.Count_Type;\n begin\n return Integer(Self.Parallel_Tests.Length + Self.Sequential_Tests.Length);\n end Num_Total_Tests;\n\n overriding\n procedure Register (Self : in out Gather;\n Name : String := Image (Subprogram_Name);\n Disabled : Boolean := False;\n Parallelize : Boolean := True) is\n package ASU renames Ada.Strings.Unbounded;\n begin\n -- TODO: Test filter to go here.\n if Disabled then\n raise Test_Registered;\n end if;\n\n Self.Current_Name := ASU.To_Unbounded_String(Name);\n\n if Parallelize then\n Self.Parallel_Tests.Append(Self.Current_Test);\n Ada.Text_IO.Put_Line (\"// PARALLEL // \" & ASU.To_String(Self.Current_Name));\n else\n Self.Sequential_Tests.Append(Self.Current_Test);\n Ada.Text_IO.Put_Line (\"--SEQUENTIAL-- \" & ASU.To_String(Self.Current_Name));\n end if;\n\n raise Test_Registered;\n end Register;\n\n overriding\n procedure Register (T : in out List;\n Name : String := Image (Subprogram_Name);\n Disabled : Boolean := False;\n Parallelize : Boolean := True) is\n begin\n pragma Unreferenced (T, Disabled, Parallelize);\n Ada.Text_IO.Put_Line (Name);\n end Register;\n\n overriding\n procedure Register (T : in out Test;\n Name : String := Image (Subprogram_Name);\n Disabled : Boolean := False;\n Parallelize : Boolean := True) is\n begin\n pragma Unreferenced(Parallelize);\n\n T.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);\n\n if Disabled then\n raise Test_Disabled;\n end if;\n end Register;\n\n procedure Report_Failure (Op : in out Operation'Class;\n Message : String;\n Loc : Source_Location) is\n Error : constant String := (if Message /= \"\" then Message else \"Condition false\");\n begin\n pragma Unreferenced (Op);\n raise Test_Failure with \"Assertion Failed: (\" & Error & \") at \" & Image (Loc);\n end Report_Failure;\n\n function \"and\" (Left, Right: Test_Result) return Test_Result is\n Either_Failed : constant Boolean := Left = Failed or else Right = Failed;\n Both_Skipped : constant Boolean := Left = Skipped and then Right = Skipped;\n begin\n return (if Either_Failed then Failed else (if Both_Skipped then Skipped else Passed));\n end \"and\";\n\n procedure Register (TG : in Test_Group) is\n begin\n All_Test_Groups.Append (TG);\n end Register;\n\n function Run (TG : Test_Group) return Test_Result is\n Passes : Natural := 0;\n Fails : Natural := 0;\n Total : Natural := 0;\n Instance : Test;\n\n use Ada.Text_IO;\n use Ada.Strings.Unbounded.Text_IO;\n use type Ada.Strings.Unbounded.Unbounded_String;\n begin\n for T of TG loop\n declare\n begin\n T.all (Instance);\n Put_Line (\"[ PASS ] \" & Instance.Name);\n Passes := Passes + 1;\n exception\n when Test_Disabled =>\n Put_Line (\"[ SKIP ] \" & Instance.Name);\n when Error : Test_Failure =>\n Put_Line (\"[ FAIL ] \" & Instance.Name);\n Put_Line (\" \" & Ada.Exceptions.Exception_Message (Error));\n Fails := Fails + 1;" + }, + { + "function_def": "procedure Main is", + "function_body": "-- On utilise des chaines de taille variable\n package Ada_Strings_Io is new Ada.Text_Io.Bounded_Io (Sb);\n use Ada_Strings_Io;\n\n type T_Menu is\n (Menu_Principal, Menu_Registre, Menu_Registre_Consultation_Selection,\n Menu_Registre_Consultation_Personne,\n Menu_Registre_Consultation_Recherche, Menu_Registre_Ajout,\n Menu_Registre_Modification, Menu_Arbre_Selection,\n Menu_Arbre_Consultation, Menu_Arbre_Ajouter_Relation,\n Menu_Arbre_Supprimer_Relation, Menu_Arbre_Parente, Menu_Statistiques,\n Quitter);\n\n -- Etat global du programme\n type T_Etat is record\n Arbre : T_Arbre_Genealogique;\n Cle : Integer;\n Menu : T_Menu;\n end record;\n\n -- Affiche la phrase \"Votre choix [1, 2, ... `Nb_Choix`]\"\n -- et capture la saisie de l'utilisateur dans `Choix`.\n procedure Choisir (Nb_Choix : in Integer; Choix : out Integer) is\n procedure Afficher_Liste_Choix is\n begin\n for I in 1 .. Nb_Choix - 2 loop\n Put (I, 0);\n Put (\", \");\n end loop;\n Put (Nb_Choix - 1, 0);\n Put (\" ou \");\n Put (Nb_Choix - 0, 0);\n end Afficher_Liste_Choix;\n Correct : Boolean := False;\n -- Premiere_Entree : Boolean := True;\n begin\n while not Correct loop\n Put (\"Votre choix [\");\n Afficher_Liste_Choix;\n -- Fonctionnalit\u00e9 desactiv\u00e9e :\n --if not Premiere_Entree then\n -- Put (\" / 0 pour quitter\");\n --end if;\n Put (\"] : \");\n begin\n Get (Choix);\n Correct := Choix in 1 .. Nb_Choix;\n --Correct := Choix in 0 .. Nb_Choix;\n exception\n when Ada.Io_Exceptions.Data_Error =>\n Correct := False;" + }, + { + "function_def": "procedure Choisir_Cle (Cle : out Integer) is", + "function_body": "Correct : Boolean := False;\n Premiere_Entree : Boolean := True;\n begin\n while not Correct loop\n Put (\"Votre choix\");\n if not Premiere_Entree then\n Put (\" [0 pour retour]\");\n end if;\n Put (\" : \");\n begin\n Get (Cle);\n Correct := Cle >= 0;\n exception\n -- Si la valeur entr\u00e9e n'est pas un entier\n when Ada.Io_Exceptions.Data_Error =>\n Correct := False;" + }, + { + "function_def": "procedure Afficher_Menu_Registre (Etat : in out T_Etat) is", + "function_body": "Choix : Integer;\n begin\n Put_Line (\"* Registre *\");\n New_Line;\n Put_Line (\"Menu :\");\n Put_Line (\"1. Consulter une personne a partir de sa cl\u00e9\");\n Put_Line (\"2. Chercher une personne a partir de son nom\");\n Put_Line (\"3. Ajouter une personne\");\n Put_Line (\"4. Retour\");\n New_Line;\n Choisir (4, Choix);\n New_Line;\n case Choix is\n when 1 =>\n Etat.Menu := Menu_Registre_Consultation_Selection;\n when 2 =>\n Etat.Menu := Menu_Registre_Consultation_Recherche;\n when 3 =>\n Etat.Menu := Menu_Registre_Ajout;\n when 4 =>\n Etat.Menu := Menu_Principal;\n when others =>\n Etat.Menu := Quitter;\n end case;\n end Afficher_Menu_Registre;\n\n -- Affiche toutes les informations d'une personne.\n procedure Afficher_Personne (Cle : in Integer; Personne : in T_Personne) is\n begin\n Put (\"<\");\n Put (Cle, 0);\n Put (\">\");\n New_Line;\n Put (Personne.Nom_Usuel);\n New_Line;\n Put (\" * Nom complet : \");\n Put (Personne.Nom_Complet);\n New_Line;\n Put (\" * Sexe : \");\n Put (T_Genre'Image (Personne.Genre));\n New_Line;\n Put (\" * N\u00e9 le \");\n Put (Personne.Date_De_Naissance.Jour, 0);\n Put (\" \");\n Put (T_Mois'Image (Personne.Date_De_Naissance.Mois));\n Put (\" \");\n Put (Personne.Date_De_Naissance.Annee, 0);\n Put (\" a \");\n Put (Personne.Lieu_De_Naissance);\n New_Line;\n end Afficher_Personne;\n\n procedure Afficher_Nom_Usuel (Etat : in T_Etat; Cle : in Integer) is\n Personne : T_Personne;\n begin\n Personne := Lire_Registre (Etat.Arbre, Cle);\n Put (Personne.Nom_Usuel);\n Put (\" <\");\n Put (Cle, 0);\n Put (\">\");\n end Afficher_Nom_Usuel;\n\n -- Affiche le menu qui permet de choisir une personne a consulter dans le registre.\n procedure Afficher_Menu_Registre_Consultation_Selection\n (Etat : in out T_Etat)\n is\n Cle : Integer;\n Correct : Boolean;\n begin\n Correct := False;\n while not Correct loop\n Put_Line\n (\"Entrez la cl\u00e9 de la personne que vous voulez consulter [0 pour retour].\");\n Choisir_Cle (Cle);\n Correct := Cle = 0 or else Existe_Registre (Etat.Arbre, Cle);\n if not Correct then\n Put_Line (\"Cl\u00e9 inconnue.\");\n New_Line;\n end if;\n end loop;\n New_Line;\n if Cle = 0 then\n Etat.Menu := Menu_Registre;\n else\n Etat.Cle := Cle;\n Etat.Menu := Menu_Registre_Consultation_Personne;\n end if;\n end Afficher_Menu_Registre_Consultation_Selection;\n\n -- Affiche les r\u00e9sultats de la recherche.\n procedure Afficher_Resultats (Etat : in out T_Etat; Recherche : in String)\n is\n Nombre_Resultats : Integer := 0;\n\n procedure Tester_Personne (Cle : in Integer; Personne : in T_Personne) is\n begin\n if Sb.Index (Personne.Nom_Usuel, Recherche) > 0\n or else Sb.Index (Personne.Nom_Complet, Recherche) > 0\n then\n Nombre_Resultats := Nombre_Resultats + 1;\n Put (\" * \");\n Put (Personne.Nom_Usuel);\n Put (\" <\");\n Put (Cle, 0);\n Put (\">\");\n New_Line;\n end if;\n end Tester_Personne;\n procedure Rechercher is new Appliquer_Sur_Registre (Tester_Personne);\n begin\n Put_Line (\"R\u00e9sultats de la recherche :\");\n Rechercher (Etat.Arbre);\n if Nombre_Resultats = 0 then\n Put_Line (\"Aucun r\u00e9sultat.\");\n Etat.Menu := Menu_Registre;\n else\n Etat.Menu := Menu_Registre_Consultation_Selection;\n end if;\n New_Line;\n end Afficher_Resultats;\n\n -- Affiche le menu qui permet de rechercher dans le registre.\n procedure Afficher_Menu_Registre_Consultation_Recherche\n (Etat : in out T_Etat)\n is\n Recherche : Sb.Bounded_String;\n begin\n Put_Line (\"* Recherche dans le registre *\");\n New_Line;\n Put (\"Nom a rechercher [Entr\u00e9e pour retour] : \");\n Recherche := Get_Line;\n New_Line;\n if Sb.Length (Recherche) > 0 then\n Afficher_Resultats (Etat, Sb.To_String (Recherche));\n else\n Etat.Menu := Menu_Registre;\n end if;\n end Afficher_Menu_Registre_Consultation_Recherche;\n\n -- Affiche le menu des possibilit\u00e9s pour une personne du registre.\n procedure Afficher_Menu_Registre_Consultation_Personne\n (Etat : in out T_Etat)\n is\n Personne : T_Personne;\n Choix : Integer;\n begin\n Personne := Lire_Registre (Etat.Arbre, Etat.Cle);\n Afficher_Personne (Etat.Cle, Personne);\n New_Line;\n Put_Line (\"Menu : \");\n Put_Line (\"1. Consulter son arbre g\u00e9n\u00e9alogique\");\n Put_Line (\"2. Modifier les informations\");\n Put_Line (\"3. Retour\");\n New_Line;\n Choisir (3, Choix);\n New_Line;\n case Choix is\n when 1 =>\n Etat.Menu := Menu_Arbre_Consultation;\n when 2 =>\n Etat.Menu := Menu_Registre_Modification;\n when 3 =>\n Etat.Menu := Menu_Registre;\n when others =>\n Etat.Menu := Quitter;\n end case;\n end Afficher_Menu_Registre_Consultation_Personne;\n\n -- Demande a l'utilisateur toutes les informations pour peupler `Personne`.\n procedure Saisir_Personne (Personne : out T_Personne) is\n Nom_Complet : Sb.Bounded_String;\n Nom_Usuel : Sb.Bounded_String;\n Genre : T_Genre;\n Date_De_Naissance : T_Date;\n Lieu_De_Naissance : Sb.Bounded_String;\n\n Correct : Boolean;\n Date_Lue : Integer;\n Genre_Lu : Character;\n begin\n Put (\"Nom usuel : \");\n Nom_Usuel := Get_Line;\n Put (\"Nom Complet : \");\n Nom_Complet := Get_Line;\n Put (\"Sexe [F pour f\u00e9minin, M pour masculin, A pour autre] : \");\n Get (Genre_Lu);\n Skip_Line;\n case Genre_Lu is\n when 'f' | 'F' =>\n Genre := Feminin;\n when 'm' | 'M' =>\n Genre := Masculin;\n when others =>\n Genre := Autre;\n end case;\n\n Correct := False; -- La date entr\u00e9e est correcte ?\n while not Correct loop\n Put (\"Date de naissance [au format JJMMAAAA] : \");\n begin\n Get (Date_Lue);\n Date_De_Naissance :=\n Creer_Date\n (Date_Lue / 1000000, (Date_Lue / 10000) mod 100,\n Date_Lue mod 10000);\n Correct := True;\n exception\n when Ada.Io_Exceptions.Data_Error | Date_Incorrecte =>\n Correct := False;" + }, + { + "function_def": "procedure Afficher_Menu_Registre_Ajout (Etat : in out T_Etat) is", + "function_body": "Cle : Integer;\n Personne : T_Personne;\n\n Choix : Character;\n begin\n Put_Line (\"* Ajouter une personne au registre *\");\n New_Line;\n Put_Line\n (\"Informations requises : nom usuel, nom complet, sexe, date et lieu de naissance.\");\n New_Line;\n Saisir_Personne (Personne);\n\n Put (\"Confirmer l'ajout [O pour oui, autre pour non] : \");\n Get (Choix);\n Skip_Line;\n\n if Choix = 'o' or Choix = 'O' then\n Ajouter_Personne (Etat.Arbre, Personne, Cle);\n Put (\"Personne ajout\u00e9e avec la cl\u00e9 : \");\n Put (Cle, 0);\n else\n Put (\"Ajout annul\u00e9.\");\n end if;\n New_Line;\n New_Line;\n\n Etat.Menu := Menu_Registre;\n\n end Afficher_Menu_Registre_Ajout;\n\n -- Permet de modifier une personne enregistr\u00e9e.\n procedure Afficher_Menu_Registre_Modification (Etat : in out T_Etat) is\n Personne : T_Personne;\n Choix : Character;\n begin\n Put_Line (\"* Modification d'une personne du registre *\");\n New_Line;\n Put_Line (\"Informations actuelles : \");\n Personne := Lire_Registre (Etat.Arbre, Etat.Cle);\n Afficher_Personne (Etat.Cle, Personne);\n New_Line;\n Saisir_Personne (Personne);\n New_Line;\n Put (\"Confirmer la modification [O pour oui, autre pour non] : \");\n Get (Choix);\n Skip_Line;\n\n if Choix = 'o' or Choix = 'O' then\n Attribuer_Registre (Etat.Arbre, Etat.Cle, Personne);\n Put_Line (\"Personne modifi\u00e9e avec succ\u00e8s.\");\n else\n Put_Line (\"Modification annul\u00e9e.\");\n end if;\n New_Line;\n\n Etat.Menu := Menu_Registre;\n end Afficher_Menu_Registre_Modification;\n\n -- Demande une cl\u00e9 pour afficher les relations d'une personne.\n procedure Afficher_Menu_Arbre_Selection (Etat : in out T_Etat) is\n Cle : Integer;\n Correct : Boolean;\n begin\n Put_Line (\"* Arbre g\u00e9n\u00e9alogique *\");\n New_Line;\n Correct := False;\n while not Correct loop\n Put_Line\n (\"Entrez la cl\u00e9 de la personne dont vous voulez consulter l'arbre [0 pour retour].\");\n Choisir_Cle (Cle);\n Correct := Cle = 0 or else Existe_Registre (Etat.Arbre, Cle);\n if not Correct then\n Put_Line (\"Cl\u00e9 inconnue.\");\n New_Line;\n end if;\n end loop;\n New_Line;\n if Cle = 0 then\n Etat.Menu := Menu_Principal;\n else\n Etat.Cle := Cle;\n Etat.Menu := Menu_Arbre_Consultation;\n end if;\n end Afficher_Menu_Arbre_Selection;\n\n -- Affiche les relations d'une personne.\n procedure Afficher_Menu_Arbre_Consultation (Etat : in out T_Etat) is\n\n -- Groupe toutes les relations de m\u00eame \u00e9tiquette ensemble.\n procedure Afficher_Relations_Groupees\n (Etat : in T_Etat; Etiquette : in T_Etiquette_Arete; Titre : in String)\n is\n Liste : T_Liste_Relations;\n Relation : T_Arete_Etiquetee;\n Titre_Affiche : Boolean := False;\n begin\n Liste_Relations (Liste, Etat.Arbre, Etat.Cle);\n -- On affiche toutes les relations not\u00e9es Etiquette\n while Liste_Non_Vide (Liste) loop\n Relation_Suivante (Liste, Relation);\n if Relation.Etiquette = Etiquette then\n if not Titre_Affiche then\n Put_Line (Titre);\n Titre_Affiche := True;\n end if;\n Put (\" * \");\n Afficher_Nom_Usuel (Etat, Relation.Destination);\n New_Line;\n end if;\n end loop;\n end Afficher_Relations_Groupees;\n\n Liste : T_Liste_Relations;\n Choix : Integer;\n begin\n Afficher_Nom_Usuel (Etat, Etat.Cle);\n New_Line;\n New_Line;\n Liste_Relations (Liste, Etat.Arbre, Etat.Cle);\n if not Liste_Non_Vide (Liste) then\n Put_Line (\"Aucune relation.\");\n else\n Afficher_Relations_Groupees (Etat, A_Pour_Parent, \"Parent(s) :\");\n Afficher_Relations_Groupees (Etat, A_Pour_Enfant, \"Enfant(s) :\");\n Afficher_Relations_Groupees (Etat, A_Pour_Conjoint, \"Conjoint(e) :\");\n end if;\n New_Line;\n Put_Line (\"Menu :\");\n Put_Line (\"1. Consulter dans le registre\");\n Put_Line (\"2. Consulter une autre personne\");\n Put_Line (\"3. Ajouter une relation\");\n Put_Line (\"4. Supprimer une relation\");\n Put_Line (\"5. Afficher un arbre de parent\u00e9\");\n Put_Line (\"6. Retour\");\n New_Line;\n Choisir (6, Choix);\n New_Line;\n case Choix is\n when 1 =>\n Etat.Menu := Menu_Registre_Consultation_Personne;\n when 2 =>\n Etat.Menu := Menu_Arbre_Selection;\n when 3 =>\n Etat.Menu := Menu_Arbre_Ajouter_Relation;\n when 4 =>\n Etat.Menu := Menu_Arbre_Supprimer_Relation;\n when 5 =>\n Etat.Menu := Menu_Arbre_Parente;\n when 6 =>\n Etat.Menu := Menu_Principal;\n when others =>\n Etat.Menu := Quitter;\n end case;\n end Afficher_Menu_Arbre_Consultation;\n\n -- Permet d'ajouter une relation.\n procedure Afficher_Menu_Arbre_Ajouter_Relation (Etat : in out T_Etat) is\n Dates_Incompatibles : exception;\n\n Personne_Origine : T_Personne;\n Personne_Destination : T_Personne;\n\n Cle_Destination : Integer;\n Relation_Lue : Integer;\n Correct : Boolean;\n begin\n Put_Line (\"Ajouter une relation :\");\n Put_Line (\"1. Ajouter un parent\");\n Put_Line (\"2. Ajouter un enfant\");\n Put_Line (\"3. Ajouter un conjoint\");\n New_Line;\n Choisir (3, Relation_Lue);\n New_Line;\n\n Correct := False;\n while not Correct loop\n Put_Line (\"Entrez la cl\u00e9 de la personne a lier [0 pour retour].\");\n Choisir_Cle (Cle_Destination);\n Correct :=\n Cle_Destination = 0\n or else Existe_Registre (Etat.Arbre, Cle_Destination);\n if not Correct then\n Put_Line (\"Cl\u00e9 inconnue.\");\n New_Line;\n end if;\n end loop;\n\n if Cle_Destination = 0 then\n Put_Line (\"Ajout annul\u00e9.\");\n else\n Personne_Origine := Lire_Registre (Etat.Arbre, Etat.Cle);\n Personne_Destination := Lire_Registre (Etat.Arbre, Cle_Destination);\n begin\n case Relation_Lue is\n when 1 =>\n -- On v\u00e9rifie qu'un parent est plus vieux que son enfant\n if D1_Inf_D2\n (Personne_Origine.Date_De_Naissance,\n Personne_Destination.Date_De_Naissance)\n then\n raise Dates_Incompatibles;\n end if;\n Ajouter_Relation\n (Etat.Arbre, Etat.Cle, A_Pour_Parent, Cle_Destination);\n when 2 =>\n if D1_Inf_D2\n (Personne_Destination.Date_De_Naissance,\n Personne_Origine.Date_De_Naissance)\n then\n raise Dates_Incompatibles;\n end if;\n Ajouter_Relation\n (Etat.Arbre, Etat.Cle, A_Pour_Enfant, Cle_Destination);\n when 3 =>\n Ajouter_Relation\n (Etat.Arbre, Etat.Cle, A_Pour_Conjoint, Cle_Destination);\n when others =>\n null;\n end case;\n Put_Line (\"Relation ajout\u00e9e.\");\n exception\n when Dates_Incompatibles =>\n Put_Line (\"Un parent doit etre plus ag\u00e9 que son enfant.\");\n when Relation_Existante =>\n Put_Line\n (\"Une relation entre ces deux personnes existe d\u00e9ja.\");" + }, + { + "function_def": "procedure Initialiser (Graphe : out T_Graphe) is", + "function_body": "begin\n Graphe := null;\n end Initialiser;\n\n procedure Desallouer_Sommet is new Ada.Unchecked_Deallocation (T_Sommet,\n T_Graphe);\n procedure Desallouer_Arete is new Ada.Unchecked_Deallocation (T_Arete,\n T_Liste_Adjacence);\n\n procedure Detruire_Arete (Adjacence : in out T_Liste_Adjacence) is\n begin\n if Adjacence /= null then\n Detruire_Arete (Adjacence.all.Suivante);\n end if;\n Desallouer_Arete (Adjacence);\n end Detruire_Arete;\n\n procedure Detruire (Graphe : in out T_Graphe) is\n begin\n if Graphe /= null then\n -- D\u00e9truit proprement un sommet\n Detruire_Arete (Graphe.all.Arete);\n Detruire (Graphe.all.Suivant);\n end if;\n Desallouer_Sommet (Graphe);\n end Detruire;\n\n function Trouver_Pointeur_Sommet\n (Graphe : T_Graphe; Etiquette : T_Etiquette_Sommet) return T_Graphe\n is\n begin\n if Graphe = null then\n raise Sommet_Non_Trouve;\n elsif Graphe.all.Etiquette = Etiquette then\n return Graphe;\n else\n return Trouver_Pointeur_Sommet (Graphe.all.Suivant, Etiquette);\n end if;\n end Trouver_Pointeur_Sommet;\n\n procedure Ajouter_Sommet\n (Graphe : in out T_Graphe; Etiquette : T_Etiquette_Sommet)\n is\n Nouveau_Graphe : T_Graphe;\n begin\n begin\n -- On ignore l'ajout si une \u00e9tiquette du m\u00eame nom existe d\u00e9j\u00e0\n Nouveau_Graphe := Trouver_Pointeur_Sommet (Graphe, Etiquette);\n exception\n when Sommet_Non_Trouve =>\n Nouveau_Graphe := new T_Sommet;\n Nouveau_Graphe.all := (Etiquette, null, Graphe);\n Graphe := Nouveau_Graphe;" + }, + { + "function_def": "procedure Main is", + "function_body": "Fail_Cnt : Natural := 0;\n Pass_Cnt : Natural := 0;\n\n procedure Test (Str : String;\n Expected_Error : String := \"\";\n Allow_Custom : Boolean := False);\n\n procedure Test (Str : String;\n Expected_Error : String := \"\";\n Allow_Custom : Boolean := False)\n is\n begin\n declare\n Exp : constant SPDX.Expression := SPDX.Parse (Str, Allow_Custom);\n Error : constant String :=\n (if SPDX.Valid (Exp) then \"\" else SPDX.Error (Exp));\n begin\n if Error /= Expected_Error then\n Put_Line (\"FAIL: '\" & Str & \"'\");\n if Expected_Error /= \"\" then\n Put_Line (\" Expected error: '\" & Expected_Error & \"'\");\n Put_Line (\" but got : '\" & Error & \"'\");\n else\n Put_Line (\" Unexpected error: '\" & Error & \"'\");\n end if;\n\n Fail_Cnt := Fail_Cnt + 1;\n\n elsif Expected_Error = \"\"\n and then\n Allow_Custom\n and then\n not SPDX.Has_Custom (Exp)\n then\n Put_Line (\"FAIL: '\" & Str & \"'\");\n Put_Line (\" Has_Custom returned False\");\n Fail_Cnt := Fail_Cnt + 1;\n else\n Put_Line (\"PASS: '\" & Str & \"'\");\n Pass_Cnt := Pass_Cnt + 1;\n end if;" + } +] \ No newline at end of file