Example #1
0
File: dump.go Project: reusee/ggi
func DumpCallableInfo(info *C.GICallableInfo) {
	throwsError := C.g_callable_info_can_throw_gerror(info) == C.gboolean(1)
	p("can throws error %v\n", throwsError)
	nArgs := C.g_callable_info_get_n_args(info)
	for i := C.gint(0); i < nArgs; i++ {
		argInfo := C.g_callable_info_get_arg(info, i)
		DumpArgInfo(argInfo)
	}
	returnOwnership := C.g_callable_info_get_caller_owns(info)
	p("return value ownership %s\n", TransferGetName(returnOwnership))
	returnType := C.g_callable_info_get_return_type(info)
	defer C.g_base_info_unref(asBaseInfo(returnType))
	p("return type %v\n", returnType)
	DumpTypeInfo(returnType)
	isMethod := C.g_callable_info_is_method(info) == C.gboolean(1)
	p("is method %v\n", isMethod)
	var iter C.GIAttributeIter
	var key, value *C.char
	for C.g_callable_info_iterate_return_attributes(info, &iter, &key, &value) == C.gboolean(1) {
		p("Attr %s = %s\n", C.GoString(key), C.GoString(value))
	}
	mayReturnNull := C.g_callable_info_may_return_null(info) == C.gboolean(1)
	p("may return null %v\n", mayReturnNull)
	skipReturn := C.g_callable_info_skip_return(info) == C.gboolean(1)
	p("skip return %v\n", skipReturn)
}
Example #2
0
// g_callable_info_get_arg
func (ci *CallableInfo) Arg(n int) *ArgInfo {
	ptr := &BaseInfo{(*C.GIBaseInfo)(C.g_callable_info_get_arg((*C.GICallableInfo)(ci.c), C.gint(n)))}
	return (*ArgInfo)(unsafe.Pointer(_SetBaseInfoFinalizer(ptr)))
}
Example #3
0
File: info.go Project: dradtke/gogi
func (info *GiInfo) GetArg(n int) *GiInfo {
	return NewGiInfo((*C.GIBaseInfo)(C.g_callable_info_get_arg((*C.GICallableInfo)(info.ptr), GlibInt(n))))
}
Example #4
0
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

}