123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(*
* Copyright 2017-2019 Cedric LE MOIGNE, cedlemo@gmx.com
* This file is part of OCaml-GObject-Introspection.
*
* OCaml-GObject-Introspection is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* OCaml-GObject-Introspection is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OCaml-GObject-Introspection. If not, see <http://www.gnu.org/licenses/>.
*)openCtypesopenForeigntypetletfunctioninfo:tstructuretyp=structure"Function_info"letget_symbol=foreign"g_function_info_get_symbol"(ptrfunctioninfo@->returningstring)letall_flags:(int64*Bindings.Function_info.flags)list=[Stubs.Function_info.gi_function_is_method,Is_method;Stubs.Function_info.gi_function_is_constructor,Is_constructor;Stubs.Function_info.gi_function_is_getter,Is_getter;Stubs.Function_info.gi_function_is_setter,Is_setter;Stubs.Function_info.gi_function_wraps_vfunc,Wraps_vfunc;Stubs.Function_info.gi_function_throws,Throws;]letflags_list=Utils.generate_flags_list_viewStubs.Function_info.flagsall_flagsletget_flags=foreign"g_function_info_get_flags"(ptrfunctioninfo@->returningflags_list)letget_propertyinfo=letflags=get_flagsinfoinletrecfind_set_get=function|[]->false|h::q->matchhwith|Bindings.Function_info.Is_setter|Bindings.Function_info.Is_getter->true|_->find_set_getqinif(find_set_getflags)then(letget_property_raw=foreign"g_function_info_get_property"(ptrfunctioninfo@->returning(ptr_optProperty_info.propertyinfo))inmatchget_property_rawinfowith|None->None|Someinfo'->letinfo''=Property_info.add_unref_finaliserinfo'inSomeinfo'')elseNoneletget_vfuncinfo=letflags=get_flagsinfoinletrechas_wraps_vfunc=function|[]->false|h::q->ifh==Bindings.Function_info.Wraps_vfuncthentrueelsehas_wraps_vfuncqinif(has_wraps_vfuncflags)thenletget_vfunc_raw=foreign"g_function_info_get_vfunc"(ptrfunctioninfo@->returning(ptr_optCallable_info.callableinfo))inmatchget_vfunc_rawinfowith|None->None|Someinfo'->letinfo''=Callable_info.add_unref_finaliserinfo'inSomeinfo''elseNone(* TODO : check that the info can be casted to function info ? *)letcast_from_baseinfoinfo=coerce(ptrBase_info.baseinfo)(ptrfunctioninfo)infoletcast_to_baseinfoinfo=coerce(ptrfunctioninfo)(ptrBase_info.baseinfo)infoletadd_unref_finaliserinfo=let_=Gc.finalise(funi->leti'=cast_to_baseinfoiinBase_info.base_info_unrefi')infoininfoletfrom_baseinfoinfo=let_=Base_info.base_info_refinfoinletinfo'=cast_from_baseinfoinfoinadd_unref_finaliserinfo'letto_baseinfoinfo=letinfo'=cast_to_baseinfoinfoinlet_=Base_info.base_info_refinfo'inlet_=Gc.finalise(funi->Base_info.base_info_unrefi)info'ininfo'letcast_from_callableinfoinfo=coerce(ptrCallable_info.callableinfo)(ptrfunctioninfo)infoletcast_to_callableinfoinfo=coerce(ptrfunctioninfo)(ptrCallable_info.callableinfo)infoletto_callableinfoinfo=letinfo'=cast_to_baseinfoinfoinlet_=Base_info.base_info_refinfo'inletinfo''=cast_to_callableinfoinfoinCallable_info.add_unref_finaliserinfo''letfrom_callableinfoinfo=letinfo'=Callable_info.cast_to_baseinfoinfoinlet_=Base_info.base_info_refinfo'inletinfo''=cast_from_callableinfoinfoinlet_=Gc.finalise(funi->leti'=cast_to_baseinfoiinBase_info.base_info_unrefi')info''ininfo''