Files
gnatcoll-bindings/python/gnatcoll-any_types-python.adb

102 lines
3.9 KiB
Ada
Raw Permalink Normal View History

------------------------------------------------------------------------------
-- G N A T C O L L --
-- --
-- Copyright (C) 2009-2021, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
* build_command_manager.adb: (Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type. * builder_facility_module.adb: (On_Compute_Build_Targets): This now returns an Any_Type. The structure of this Any_Type is described in shell_commands.xml. (Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now returns an Any_Type, adapt. (Add_Menu_For_Target): Likewise. * gnatcoll-any_types.adb: Initial revision. * gnatcoll-any_types.ads: Initial revision. * gnatcoll-scripts-shell.adb: Implement overriding subprogram Execute [Any_Type]. * gnatcoll-scripts-shell.ads: Declare overriding subprogram Execute [Any_Type]. * gnatcoll-scripts.ads: (Execute): New abstract subprogram, returning an Any_Type. * gnatcoll-any_types-python.adb: Initial revision. * gnatcoll-any_types-python.ads: Initial revision. * gnatcoll-scripts-python.adb: (Execute): Declare overriding subprogram. Implement. (Execute_Command): New subprogram. * gnatcoll-scripts-python.ads: (Execute_Command): New subprogram. * gps-kernel-hooks.adb: (Command_Handler_Return_Any): New subprogram. (Wrapper_Return_Any): New type. (Execute): Implement wrappers. (Destroy): Implement. (Run_Hook_Until_Not_Empty): New subprogram. (Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an Any_Type. * gps-kernel-hooks.ads: Add functions allowing to launch hooks that return Any_Types. Add documentation. * Makefile.py: Adapt to new return types of compute_build_targets hook. * shell_commands.xml: Document new return type of compute_build_targets hook. Follow-up on I302-024. We want to display the base names of "main" targets in the Build menu, and we also want the hook to contain the full path to the main file in order to support "%TT". We cannot do a simple "base_name" on the target when it comes to adding it to the menu, because this suppresses useful information coming from targets from Makefile.py. To solve this, the hook "compute_build_targets" now returns a list of targets, with, for each target, the name to display in the menu, and the full name. In order to implement this, we introduce a way for hooks to return complex information, mapping a subset of the Python types. git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
with GNATCOLL.Python.State; use GNATCOLL.Python.State;
* build_command_manager.adb: (Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type. * builder_facility_module.adb: (On_Compute_Build_Targets): This now returns an Any_Type. The structure of this Any_Type is described in shell_commands.xml. (Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now returns an Any_Type, adapt. (Add_Menu_For_Target): Likewise. * gnatcoll-any_types.adb: Initial revision. * gnatcoll-any_types.ads: Initial revision. * gnatcoll-scripts-shell.adb: Implement overriding subprogram Execute [Any_Type]. * gnatcoll-scripts-shell.ads: Declare overriding subprogram Execute [Any_Type]. * gnatcoll-scripts.ads: (Execute): New abstract subprogram, returning an Any_Type. * gnatcoll-any_types-python.adb: Initial revision. * gnatcoll-any_types-python.ads: Initial revision. * gnatcoll-scripts-python.adb: (Execute): Declare overriding subprogram. Implement. (Execute_Command): New subprogram. * gnatcoll-scripts-python.ads: (Execute_Command): New subprogram. * gps-kernel-hooks.adb: (Command_Handler_Return_Any): New subprogram. (Wrapper_Return_Any): New type. (Execute): Implement wrappers. (Destroy): Implement. (Run_Hook_Until_Not_Empty): New subprogram. (Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an Any_Type. * gps-kernel-hooks.ads: Add functions allowing to launch hooks that return Any_Types. Add documentation. * Makefile.py: Adapt to new return types of compute_build_targets hook. * shell_commands.xml: Document new return type of compute_build_targets hook. Follow-up on I302-024. We want to display the base names of "main" targets in the Build menu, and we also want the hook to contain the full path to the main file in order to support "%TT". We cannot do a simple "base_name" on the target when it comes to adding it to the menu, because this suppresses useful information coming from targets from Makefile.py. To solve this, the hook "compute_build_targets" now returns a list of targets, with, for each target, the name to display in the menu, and the full name. In order to implement this, we introduce a way for hooks to return complex information, mapping a subset of the Python types. git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
package body GNATCOLL.Any_Types.Python is
-------------------
-- From_PyObject --
-------------------
function From_PyObject (Object : PyObject) return Any_Type is
Lock : Ada_GIL_Lock with Unreferenced;
* build_command_manager.adb: (Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type. * builder_facility_module.adb: (On_Compute_Build_Targets): This now returns an Any_Type. The structure of this Any_Type is described in shell_commands.xml. (Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now returns an Any_Type, adapt. (Add_Menu_For_Target): Likewise. * gnatcoll-any_types.adb: Initial revision. * gnatcoll-any_types.ads: Initial revision. * gnatcoll-scripts-shell.adb: Implement overriding subprogram Execute [Any_Type]. * gnatcoll-scripts-shell.ads: Declare overriding subprogram Execute [Any_Type]. * gnatcoll-scripts.ads: (Execute): New abstract subprogram, returning an Any_Type. * gnatcoll-any_types-python.adb: Initial revision. * gnatcoll-any_types-python.ads: Initial revision. * gnatcoll-scripts-python.adb: (Execute): Declare overriding subprogram. Implement. (Execute_Command): New subprogram. * gnatcoll-scripts-python.ads: (Execute_Command): New subprogram. * gps-kernel-hooks.adb: (Command_Handler_Return_Any): New subprogram. (Wrapper_Return_Any): New type. (Execute): Implement wrappers. (Destroy): Implement. (Run_Hook_Until_Not_Empty): New subprogram. (Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an Any_Type. * gps-kernel-hooks.ads: Add functions allowing to launch hooks that return Any_Types. Add documentation. * Makefile.py: Adapt to new return types of compute_build_targets hook. * shell_commands.xml: Document new return type of compute_build_targets hook. Follow-up on I302-024. We want to display the base names of "main" targets in the Build menu, and we also want the hook to contain the full path to the main file in order to support "%TT". We cannot do a simple "base_name" on the target when it comes to adding it to the menu, because this suppresses useful information coming from targets from Makefile.py. To solve this, the hook "compute_build_targets" now returns a list of targets, with, for each target, the name to display in the menu, and the full name. In order to implement this, we introduce a way for hooks to return complex information, mapping a subset of the Python types. git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
begin
if Object = null
or else Object = Py_None
then
return Empty_Any_Type;
end if;
if PyInt_Check (Object) then
declare
A : Any_Type (Integer_Type, 0);
begin
A.Int := PyInt_AsLong (Object);
return A;
end;
elsif PyString_Check (Object) then
declare
S : constant String := PyString_AsString (Object);
A : Any_Type (String_Type, S'Length);
begin
A.Str := S;
return A;
end;
elsif PyUnicode_Check (Object) then
declare
S : constant String := Unicode_AsString (Object);
A : Any_Type (String_Type, S'Length);
begin
A.Str := S;
return A;
end;
* build_command_manager.adb: (Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type. * builder_facility_module.adb: (On_Compute_Build_Targets): This now returns an Any_Type. The structure of this Any_Type is described in shell_commands.xml. (Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now returns an Any_Type, adapt. (Add_Menu_For_Target): Likewise. * gnatcoll-any_types.adb: Initial revision. * gnatcoll-any_types.ads: Initial revision. * gnatcoll-scripts-shell.adb: Implement overriding subprogram Execute [Any_Type]. * gnatcoll-scripts-shell.ads: Declare overriding subprogram Execute [Any_Type]. * gnatcoll-scripts.ads: (Execute): New abstract subprogram, returning an Any_Type. * gnatcoll-any_types-python.adb: Initial revision. * gnatcoll-any_types-python.ads: Initial revision. * gnatcoll-scripts-python.adb: (Execute): Declare overriding subprogram. Implement. (Execute_Command): New subprogram. * gnatcoll-scripts-python.ads: (Execute_Command): New subprogram. * gps-kernel-hooks.adb: (Command_Handler_Return_Any): New subprogram. (Wrapper_Return_Any): New type. (Execute): Implement wrappers. (Destroy): Implement. (Run_Hook_Until_Not_Empty): New subprogram. (Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an Any_Type. * gps-kernel-hooks.ads: Add functions allowing to launch hooks that return Any_Types. Add documentation. * Makefile.py: Adapt to new return types of compute_build_targets hook. * shell_commands.xml: Document new return type of compute_build_targets hook. Follow-up on I302-024. We want to display the base names of "main" targets in the Build menu, and we also want the hook to contain the full path to the main file in order to support "%TT". We cannot do a simple "base_name" on the target when it comes to adding it to the menu, because this suppresses useful information coming from targets from Makefile.py. To solve this, the hook "compute_build_targets" now returns a list of targets, with, for each target, the name to display in the menu, and the full name. In order to implement this, we introduce a way for hooks to return complex information, mapping a subset of the Python types. git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
elsif PyList_Check (Object) then
declare
Size : constant Integer := PyList_Size (Object);
Arr : Any_Type_Array (1 .. Size);
A : Any_Type (List_Type, Size);
begin
for J in 1 .. Size loop
Arr (J) := new Any_Type'
(From_PyObject (PyList_GetItem (Object, J - 1)));
end loop;
A.List := Arr;
return A;
end;
elsif PyTuple_Check (Object) then
declare
Size : constant Integer := PyTuple_Size (Object);
Arr : Any_Type_Array (1 .. Size);
A : Any_Type (Tuple_Type, Size);
begin
for J in 1 .. Size loop
Arr (J) := new Any_Type'
(From_PyObject (PyTuple_GetItem (Object, J - 1)));
end loop;
A.Tuple := Arr;
return A;
end;
else
-- When adding support for new types, add the corresponding cases
-- here.
null;
end if;
return Empty_Any_Type;
end From_PyObject;
end GNATCOLL.Any_Types.Python;