func (self *Generator) getGoTypeStr(typeInfo *C.GITypeInfo) (ret string) { argTypeTag := C.g_type_info_get_tag(typeInfo) // map to basic type ret = tagMapToGoType(argTypeTag) if ret != "" { if C.g_type_info_is_pointer(typeInfo) == True && ret != "string" { // is pointer ret = "*" + ret } return } // complex type if argTypeTag == C.GI_TYPE_TAG_INTERFACE { ifaceInfo := C.g_type_info_get_interface(typeInfo) //GIBaseInfo if ifaceInfo != nil { ifaceType := C.g_base_info_get_type(ifaceInfo) //GIInfoType ifaceName := fromGStr(C.g_base_info_get_name(ifaceInfo)) switch ifaceType { case C.GI_INFO_TYPE_STRUCT: /* ret = "*C." + strings.ToUpper(self.CPrefix) + ifaceName p("%s %s\n", self.currentFunctionName, ifaceName) return */ //TODO we need c:type here. girepository is not exposing. default: //p("INTERFACE %s %s\n", fromGStr(C.g_info_type_to_string(ifaceType)), ifaceName) } } } // fallback return "interface{}" }
func DumpObjectInfo(info *C.GIObjectInfo) { isAbstract := C.g_object_info_get_abstract(info) == C.gboolean(1) p("is abstract %v\n", isAbstract) parent := C.g_object_info_get_parent(info) if parent != nil { parentName := fromGStr(C.g_base_info_get_name(asBaseInfo(parent))) p("parent %s\n", parentName) } typeName := fromGStr(C.g_object_info_get_type_name(info)) p("type name %s\n", typeName) typeInit := fromGStr(C.g_object_info_get_type_init(info)) p("type init %s\n", typeInit) nConsts := C.g_object_info_get_n_constants(info) p("%d consts\n", nConsts) for i := C.gint(0); i < nConsts; i++ { constInfo := C.g_object_info_get_constant(info, i) DumpConstantInfo(constInfo) } nFields := C.g_object_info_get_n_fields(info) p("%d fields\n", nFields) for i := C.gint(0); i < nFields; i++ { field := C.g_object_info_get_field(info, i) DumpFieldInfo(field) } nInterfaces := C.g_object_info_get_n_interfaces(info) p("%d interfaces\n", nInterfaces) for i := C.gint(0); i < nInterfaces; i++ { interf := C.g_object_info_get_interface(info, i) DumpInterfaceInfo(interf) } nMethods := C.g_object_info_get_n_methods(info) p("%d methods\n", nMethods) for i := C.gint(0); i < nMethods; i++ { f := C.g_object_info_get_method(info, i) DumpFunctionInfo(f) } nProperties := C.g_object_info_get_n_properties(info) p("%d properties\n", nProperties) for i := C.gint(0); i < nProperties; i++ { property := C.g_object_info_get_property(info, i) DumpPropertyInfo(property) } nSignals := C.g_object_info_get_n_signals(info) p("%d signals\n", nSignals) for i := C.gint(0); i < nSignals; i++ { signal := C.g_object_info_get_signal(info, i) DumpSignalInfo(signal) } nVFuncs := C.g_object_info_get_n_vfuncs(info) p("%d vfuncs\n", nVFuncs) for i := C.gint(0); i < nVFuncs; i++ { vfunc := C.g_object_info_get_vfunc(info, i) DumpVFuncInfo(vfunc) } }
// g_base_info_get_name func (bi *BaseInfo) Name() string { return _GStringToGoString(C.g_base_info_get_name(bi.c)) }
func DumpValueInfo(valueInfo *C.GIValueInfo) { name := fromGStr(C.g_base_info_get_name(asBaseInfo(valueInfo))) value := C.g_value_info_get_value(valueInfo) p("%s = %v\n", name, value) }
func dump() { repo := C.g_irepository_get_default() lib := os.Args[1] var err *C.GError C.g_irepository_require(repo, toGStr(lib), nil, 0, &err) if err != nil { log.Fatal(fromGStr(err.message)) } nInfos := C.g_irepository_get_n_infos(repo, toGStr(lib)) var nObjects int for i := C.gint(0); i < nInfos; i++ { baseInfo := C.g_irepository_get_info(repo, toGStr(lib), i) if C.g_base_info_is_deprecated(baseInfo) == C.gboolean(1) { // skip deprecated continue } name := fromGStr(C.g_base_info_get_name(baseInfo)) // name p("=> %s\n", name) var iter C.GIAttributeIter var key, value *C.char for C.g_base_info_iterate_attributes(baseInfo, &iter, &key, &value) == C.gboolean(1) { p("Attr %s = %s\n", C.GoString(key), C.GoString(value)) } t := C.g_base_info_get_type(baseInfo) // type p("%s\n", fromGStr(C.g_info_type_to_string(t))) switch t { // dump case C.GI_INFO_TYPE_OBJECT: info := (*C.GIObjectInfo)(unsafe.Pointer(baseInfo)) p("Object\n") DumpObjectInfo(info) nObjects++ case C.GI_INFO_TYPE_STRUCT: p("Struct\n") info := (*C.GIStructInfo)(unsafe.Pointer(baseInfo)) DumpStructInfo(info) case C.GI_INFO_TYPE_FLAGS: p("Flags\n") info := (*C.GIEnumInfo)(unsafe.Pointer(baseInfo)) DumpEnumInfo(info) case C.GI_INFO_TYPE_CALLBACK: p("Callback\n") info := (*C.GIFunctionInfo)(unsafe.Pointer(baseInfo)) DumpFunctionInfo(info) case C.GI_INFO_TYPE_INTERFACE: p("Interface\n") info := (*C.GIInterfaceInfo)(unsafe.Pointer(baseInfo)) DumpInterfaceInfo(info) case C.GI_INFO_TYPE_UNION: p("Union\n") info := (*C.GIUnionInfo)(unsafe.Pointer(baseInfo)) DumpUnionInfo(info) case C.GI_INFO_TYPE_ENUM: p("Enum\n") info := (*C.GIEnumInfo)(unsafe.Pointer(baseInfo)) DumpEnumInfo(info) case C.GI_INFO_TYPE_FUNCTION: p("Function\n") info := (*C.GIFunctionInfo)(unsafe.Pointer(baseInfo)) DumpFunctionInfo(info) case C.GI_INFO_TYPE_CONSTANT: p("Constant\n") info := (*C.GIConstantInfo)(unsafe.Pointer(baseInfo)) DumpConstantInfo(info) default: panic(fmt.Sprintf("unknown type %d", t)) } C.g_base_info_unref(baseInfo) p(strings.Repeat("-", 64)) p("\n") } p("%d\n", nInfos) p("%d object types\n", nObjects) }
func (info *GiInfo) GetName() string { return GoString(C.g_base_info_get_name(info.ptr)) }
func (self *Generator) GenFunction(info *C.GIFunctionInfo) { // name name := fromGStr(C.g_base_info_get_name(asBaseInfo(info))) self.currentFunctionName = name goName := convertFuncName(name) w(self.FuncsWriter, "func %s", goName) // collect args var inArgs, outArgs []*C.GIArgInfo nArgs := C.g_callable_info_get_n_args(asCallableInfo(info)) for i := C.gint(0); i < nArgs; i++ { arg := C.g_callable_info_get_arg(asCallableInfo(info), i) argDirection := C.g_arg_info_get_direction(arg) switch argDirection { case C.GI_DIRECTION_IN: inArgs = append(inArgs, arg) case C.GI_DIRECTION_OUT: outArgs = append(outArgs, arg) case C.GI_DIRECTION_INOUT: inArgs = append(inArgs, arg) outArgs = append(outArgs, arg) } } // output in args w(self.FuncsWriter, "(") for _, arg := range inArgs { argName := convertArgName(fromGStr(C.g_base_info_get_name(asBaseInfo(arg)))) goTypeStr := self.getGoTypeStr(C.g_arg_info_get_type(arg)) /* argCallerAllocates := C.g_arg_info_is_caller_allocates(arg) == True if argCallerAllocates { goTypeStr = "*" + goTypeStr } */ w(self.FuncsWriter, "%s %s,", argName, goTypeStr) } w(self.FuncsWriter, ")") w(self.FuncsWriter, "{}\n") //TODO body // symbol symbol := fromGStr(C.g_function_info_get_symbol(info)) _ = symbol // error throwsError := C.g_callable_info_can_throw_gerror(asCallableInfo(info)) == True _ = throwsError // args /* nArgs := C.g_callable_info_get_n_args(asCallableInfo(info)) for i := C.gint(0); i < nArgs; i++ { argCallerAllocates := C.g_arg_info_is_caller_allocates(arg) == True if argCallerAllocates { p(" CALLER_ALLOCATES") } if argTypeTag == C.GI_TYPE_TAG_ARRAY { arrayType := C.g_type_info_get_array_type(argType) p(" ARRAY of %s", ArrayTypeToString(arrayType)) if arrayType == C.GI_ARRAY_TYPE_C { elemType := C.g_type_info_get_param_type(argType, 0) elemTypeTag := C.g_type_info_get_tag(elemType) p(" %s", fromGStr(C.g_type_tag_to_string(elemTypeTag))) } } p("\n") } */ // return returnType := C.g_callable_info_get_return_type(asCallableInfo(info)) _ = returnType //TODO same as arg type mayReturnNull := C.g_callable_info_may_return_null(asCallableInfo(info)) == True _ = mayReturnNull skipReturn := C.g_callable_info_skip_return(asCallableInfo(info)) == True _ = skipReturn }