Esempio n. 1
0
func (this *config_type) is_object_blacklisted(bi *gi.BaseInfo) bool {
	switch bi.Type() {
	case gi.INFO_TYPE_UNION:
		return config.is_blacklisted("unions", bi.Name())
	case gi.INFO_TYPE_STRUCT:
		return config.is_blacklisted("structs", bi.Name())
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		return config.is_blacklisted("enums", bi.Name())
	case gi.INFO_TYPE_CONSTANT:
		return config.is_blacklisted("constants", bi.Name())
	case gi.INFO_TYPE_CALLBACK:
		return config.is_blacklisted("callbacks", bi.Name())
	case gi.INFO_TYPE_FUNCTION:
		c := bi.Container()
		if c != nil {
			return config.is_method_blacklisted(c.Name(), bi.Name())
		}
		return config.is_blacklisted("functions", bi.Name())
	case gi.INFO_TYPE_INTERFACE:
		return config.is_blacklisted("interfaces", bi.Name())
	case gi.INFO_TYPE_OBJECT:
		return config.is_blacklisted("objects", bi.Name())
	default:
		println("TODO: %s (%s)\n", bi.Name(), bi.Type())
		return true
	}
	panic("unreachable")
}
Esempio n. 2
0
func CForwardDeclaration30(bi *gi.BaseInfo) {
	fullnm := strings.ToLower(bi.Namespace()) + "." + bi.Name()

	switch bi.Type() {
	case gi.INFO_TYPE_STRUCT:
		si := gi.ToStructInfo(bi)
		size := si.Size()
		if _, ok := GConfig.Sys.DisguisedTypes[fullnm]; ok {
			return
		}
		cctype := CTypeForInterface(bi, TypeNone)
		if size == 0 {
			printf("struct _%s {};\n", cctype)
		} else {
			printf("struct _%s { uint8_t _data[%d]; };\n", cctype, size)
		}
	case gi.INFO_TYPE_UNION:
		ui := gi.ToUnionInfo(bi)
		size := ui.Size()
		cctype := CTypeForInterface(bi, TypeNone)
		if size == 0 {
			printf("struct _%s {};\n", cctype)
		} else {
			printf("struct _%s { uint8_t _data[%d]; };\n", cctype, size)
		}
	}
}
Esempio n. 3
0
func CForwardDeclaration10(bi *gi.BaseInfo) {
	switch bi.Type() {
	case gi.INFO_TYPE_OBJECT:
		cctype := CTypeForInterface(bi, TypeNone)
		printf("typedef struct _%s %s;\n", cctype, cctype)
	case gi.INFO_TYPE_FLAGS, gi.INFO_TYPE_ENUM:
		ei := gi.ToEnumInfo(bi)
		printf("typedef %s %s;\n", CTypeForTag(ei.StorageType(), TypeNone),
			CTypeForInterface(bi, TypeNone))
	case gi.INFO_TYPE_STRUCT, gi.INFO_TYPE_INTERFACE, gi.INFO_TYPE_UNION:
		fullnm := strings.ToLower(bi.Namespace()) + "." + bi.Name()
		cctype := CTypeForInterface(bi, TypeNone)
		if _, ok := GConfig.Sys.DisguisedTypes[fullnm]; ok {
			printf("typedef void *%s;\n", cctype)
		} else {
			printf("typedef struct _%s %s;\n", cctype, cctype)
		}
	case gi.INFO_TYPE_CALLBACK:
		ctype := CTypeForInterface(bi, TypeNone)
		// type doesn't matter here, it's just a pointer after all
		printf("typedef void* %s;\n", ctype)
		// also generate wrapper declarations
		printf("extern void _%s_c_wrapper();\n", ctype)
		printf("extern void _%s_c_wrapper_once();\n", ctype)
	}
}
Esempio n. 4
0
func CForwardDeclaration20(bi *gi.BaseInfo) {
	switch bi.Type() {
	case gi.INFO_TYPE_FUNCTION:
		fi := gi.ToFunctionInfo(bi)
		CFuncForwardDeclaration(fi, nil)
	case gi.INFO_TYPE_OBJECT:
		oi := gi.ToObjectInfo(bi)
		for i, n := 0, oi.NumMethod(); i < n; i++ {
			meth := oi.Method(i)
			CFuncForwardDeclaration(meth, bi)
		}
		printf("extern GType %s();\n", oi.TypeInit())
	case gi.INFO_TYPE_INTERFACE:
		ii := gi.ToInterfaceInfo(bi)
		for i, n := 0, ii.NumMethod(); i < n; i++ {
			meth := ii.Method(i)
			CFuncForwardDeclaration(meth, bi)
		}
		printf("extern GType %s();\n", ii.TypeInit())
	case gi.INFO_TYPE_STRUCT:
		si := gi.ToStructInfo(bi)
		for i, n := 0, si.NumMethod(); i < n; i++ {
			meth := si.Method(i)
			CFuncForwardDeclaration(meth, bi)
		}
	case gi.INFO_TYPE_UNION:
		ui := gi.ToUnionInfo(bi)
		for i, n := 0, ui.NumMethod(); i < n; i++ {
			meth := ui.Method(i)
			CFuncForwardDeclaration(meth, bi)
		}
	}
}
Esempio n. 5
0
func (this *binding_generator) c_forward_declaration30(bi *gi.BaseInfo) {
	p := printer_to(this.out_h)
	fullnm := strings.ToLower(bi.Namespace()) + "." + bi.Name()

	switch bi.Type() {
	case gi.INFO_TYPE_STRUCT:
		si := gi.ToStructInfo(bi)
		size := si.Size()
		if config.is_disguised(fullnm) {
			return
		}
		cctype := c_type_for_interface(bi, type_none)
		if size == 0 {
			p("struct _%s {};\n", cctype)
		} else {
			p("struct _%s { uint8_t _data[%d]; };\n", cctype, size)
		}
	case gi.INFO_TYPE_UNION:
		ui := gi.ToUnionInfo(bi)
		size := ui.Size()
		cctype := c_type_for_interface(bi, type_none)
		if size == 0 {
			p("struct _%s {};\n", cctype)
		} else {
			p("struct _%s { uint8_t _data[%d]; };\n", cctype, size)
		}
	}
}
Esempio n. 6
0
func (this *binding_generator) c_forward_declaration20(bi *gi.BaseInfo) {
	p := printer_to(this.out_h)
	switch bi.Type() {
	case gi.INFO_TYPE_FUNCTION:
		fi := gi.ToFunctionInfo(bi)
		this.c_func_forward_declaration(fi)
	case gi.INFO_TYPE_OBJECT:
		oi := gi.ToObjectInfo(bi)
		for i, n := 0, oi.NumMethod(); i < n; i++ {
			meth := oi.Method(i)
			this.c_func_forward_declaration(meth)
		}
		p("extern GType %s();\n", oi.TypeInit())
	case gi.INFO_TYPE_INTERFACE:
		ii := gi.ToInterfaceInfo(bi)
		for i, n := 0, ii.NumMethod(); i < n; i++ {
			meth := ii.Method(i)
			this.c_func_forward_declaration(meth)
		}
		p("extern GType %s();\n", ii.TypeInit())
	case gi.INFO_TYPE_STRUCT:
		si := gi.ToStructInfo(bi)
		for i, n := 0, si.NumMethod(); i < n; i++ {
			meth := si.Method(i)
			this.c_func_forward_declaration(meth)
		}
	case gi.INFO_TYPE_UNION:
		ui := gi.ToUnionInfo(bi)
		for i, n := 0, ui.NumMethod(); i < n; i++ {
			meth := ui.Method(i)
			this.c_func_forward_declaration(meth)
		}
	}
}
Esempio n. 7
0
func (this *binding_generator) c_forward_declaration10(bi *gi.BaseInfo) {
	p := printer_to(this.out_h)
	switch bi.Type() {
	case gi.INFO_TYPE_OBJECT:
		cctype := c_type_for_interface(bi, type_none)
		p("typedef struct _%s %s;\n", cctype, cctype)
	case gi.INFO_TYPE_FLAGS, gi.INFO_TYPE_ENUM:
		ei := gi.ToEnumInfo(bi)
		p("typedef %s %s;\n", c_type_for_tag(ei.StorageType(), type_none),
			c_type_for_interface(bi, type_none))
	case gi.INFO_TYPE_STRUCT, gi.INFO_TYPE_INTERFACE, gi.INFO_TYPE_UNION:
		fullnm := strings.ToLower(bi.Namespace()) + "." + bi.Name()
		cctype := c_type_for_interface(bi, type_none)
		if config.is_disguised(fullnm) {
			p("typedef void *%s;\n", cctype)
		} else {
			p("typedef struct _%s %s;\n", cctype, cctype)
		}
	case gi.INFO_TYPE_CALLBACK:
		pc := printer_to(this.out_c)
		ctype := c_type_for_interface(bi, type_none)

		// type doesn't matter here, it's just a pointer after all
		p("typedef void* %s;\n", ctype)

		// and wrapper declarations for .c file only (cgo has problems
		// with that)
		pc("extern void _%s_c_wrapper();\n", ctype)
		pc("extern void _%s_c_wrapper_once();\n", ctype)
	}
}
Esempio n. 8
0
func CgoToGoForInterface(bi *gi.BaseInfo, arg1, arg2 string, flags ConvFlags) string {
	var out bytes.Buffer
	printf := PrinterTo(&out)

	switch bi.Type() {
	case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
		gotype := GoTypeForInterface(bi, TypeReturn)
		if flags&ConvOwnEverything != 0 {
			printf("%s = (*%s)(%sObjectWrap(unsafe.Pointer(%s), false))",
				arg2, gotype, Config.Sys.GNS, arg1)
		} else {
			printf("%s = (*%s)(%sObjectWrap(unsafe.Pointer(%s), true))",
				arg2, gotype, Config.Sys.GNS, arg1)
		}
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		gotype := GoTypeForInterface(bi, TypeReturn)
		printf("%s = %s(%s)", arg2, gotype, arg1)
	case gi.INFO_TYPE_STRUCT, gi.INFO_TYPE_UNION:
		ns := bi.Namespace()
		if ns == "cairo" {
			printf(CairoCgoToGoForInterface(bi, arg1, arg2, flags))
			break
		}

		fullnm := strings.ToLower(ns) + "." + bi.Name()
		gotype := GoTypeForInterface(bi, TypeReturn)

		if flags&ConvListMember != 0 {
			printf("%s = *(*%s)(unsafe.Pointer(%s))",
				arg2, gotype, arg1)
			break
		}

		if _, ok := GConfig.Sys.DisguisedTypes[fullnm]; ok {
			printf("%s = %s{unsafe.Pointer(%s)}",
				arg2, gotype, arg1)
			break
		}

		if flags&ConvPointer != 0 {
			printf("%s = (*%s)(unsafe.Pointer(%s))",
				arg2, gotype, arg1)
		} else {
			printf("%s = *(*%s)(unsafe.Pointer(&%s))",
				arg2, gotype, arg1)
		}
	}
	return out.String()
}
Esempio n. 9
0
func GoToCgoForInterface(bi *gi.BaseInfo, arg0, arg1 string, flags ConvFlags) string {
	var out bytes.Buffer
	printf := PrinterTo(&out)

	switch bi.Type() {
	case gi.INFO_TYPE_OBJECT:
		prefix := gi.DefaultRepository().CPrefix(bi.Namespace())
		printf("if %s != nil {\n", arg0)
		printf("\t%s = %s.InheritedFrom%s%s()\n",
			arg1, arg0, prefix, bi.Name())
		printf("}")
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		ctype := CgoTypeForInterface(bi, TypeNone)
		printf("%s = %s(%s)", arg1, ctype, arg0)
	case gi.INFO_TYPE_INTERFACE:
		prefix := gi.DefaultRepository().CPrefix(bi.Namespace())
		printf("if %s != nil {\n", arg0)
		printf("\t%s = %s.Implements%s%s()",
			arg1, arg0, prefix, bi.Name())
		printf("}")
	case gi.INFO_TYPE_STRUCT:
		ns := bi.Namespace()
		if ns == "cairo" {
			printf(CairoGoToCgoForInterface(bi, arg0, arg1, flags))
			break
		}

		fullnm := strings.ToLower(ns) + "." + bi.Name()
		if _, ok := GConfig.Sys.DisguisedTypes[fullnm]; ok {
			flags &^= ConvPointer
		}
		ctype := CgoTypeForInterface(bi, TypeNone)
		if flags&ConvPointer != 0 {
			printf("%s = (*%s)(unsafe.Pointer(%s))",
				arg1, ctype, arg0)
		} else {
			printf("%s = *(*%s)(unsafe.Pointer(&%s))",
				arg1, ctype, arg0)
		}
	case gi.INFO_TYPE_CALLBACK:
		printf("if %s != nil {\n", arg0)
		printf("\t%s = unsafe.Pointer(&%s)", arg1, arg0)
		printf("}")
	}

	return out.String()
}
Esempio n. 10
0
func cgo_type_for_interface(bi *gi.BaseInfo, flags type_flags) string {
	var out bytes.Buffer

	switch bi.Type() {
	case gi.INFO_TYPE_CALLBACK:
		out.WriteString("unsafe.Pointer")
	default:
		ns := bi.Namespace()
		nm := bi.Name()
		fullnm := strings.ToLower(ns) + "." + nm

		if flags&type_pointer != 0 && !config.is_disguised(fullnm) {
			out.WriteString("*")
		}

		out.WriteString("C.")
		out.WriteString(gi.DefaultRepository().CPrefix(ns))
		out.WriteString(bi.Name())
	}
	return out.String()
}
Esempio n. 11
0
func (this *binding_generator) process_base_info(bi *gi.BaseInfo) {
	p := printer_to(&this.go_bindings)

	if config.is_object_blacklisted(bi) {
		p("// blacklisted: %s (%s)\n", bi.Name(), bi.Type())
		return
	}

	switch bi.Type() {
	case gi.INFO_TYPE_UNION:
		this.process_union_info(gi.ToUnionInfo(bi))
	case gi.INFO_TYPE_STRUCT:
		this.process_struct_info(gi.ToStructInfo(bi))
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		this.process_enum_info(gi.ToEnumInfo(bi))
	case gi.INFO_TYPE_CONSTANT:
		this.process_constant_info(gi.ToConstantInfo(bi))
	case gi.INFO_TYPE_CALLBACK:
		this.process_callback_info(gi.ToCallableInfo(bi))
	case gi.INFO_TYPE_FUNCTION:
		this.process_function_info(gi.ToFunctionInfo(bi))
	case gi.INFO_TYPE_INTERFACE:
		this.process_interface_info(gi.ToInterfaceInfo(bi))
	case gi.INFO_TYPE_OBJECT:
		this.process_object_info(gi.ToObjectInfo(bi))
	default:
		p("// TODO: %s (%s)\n", bi.Name(), bi.Type())
	}
}
Esempio n. 12
0
func CgoTypeForInterface(bi *gi.BaseInfo, flags TypeFlags) string {
	var out bytes.Buffer

	switch bi.Type() {
	case gi.INFO_TYPE_CALLBACK:
		out.WriteString("unsafe.Pointer")
	default:
		ns := bi.Namespace()
		nm := bi.Name()
		fullnm := strings.ToLower(ns) + "." + nm

		_, disguised := GConfig.Sys.DisguisedTypes[fullnm]
		if flags&TypePointer != 0 && !disguised {
			out.WriteString("*")
		}

		out.WriteString("C.")
		out.WriteString(gi.DefaultRepository().CPrefix(ns))
		out.WriteString(bi.Name())
	}
	return out.String()
}
Esempio n. 13
0
func TypeSizeForInterface(bi *gi.BaseInfo, flags TypeFlags) int {
	ptrsize := int(unsafe.Sizeof(unsafe.Pointer(nil)))
	if flags&TypePointer != 0 {
		return ptrsize
	}

	switch t := bi.Type(); t {
	case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
		return ptrsize
	case gi.INFO_TYPE_STRUCT:
		si := gi.ToStructInfo(bi)
		return si.Size()
	case gi.INFO_TYPE_UNION:
		ui := gi.ToUnionInfo(bi)
		return ui.Size()
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		ei := gi.ToEnumInfo(bi)
		return TypeSizeForTag(ei.StorageType(), flags)
	case gi.INFO_TYPE_CALLBACK:
		return ptrsize
	}
	panic("unreachable: " + bi.Type().String())
}
Esempio n. 14
0
func ProcessBaseInfo(bi *gi.BaseInfo) {
	switch bi.Type() {
	case gi.INFO_TYPE_UNION:
		if IsBlacklisted("unions", bi.Name()) {
			goto blacklisted
		}
		ProcessUnionInfo(gi.ToUnionInfo(bi))
	case gi.INFO_TYPE_STRUCT:
		if IsBlacklisted("structs", bi.Name()) {
			goto blacklisted
		}
		ProcessStructInfo(gi.ToStructInfo(bi))
	case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS:
		if IsBlacklisted("enums", bi.Name()) {
			goto blacklisted
		}
		ProcessEnumInfo(gi.ToEnumInfo(bi))
	case gi.INFO_TYPE_CONSTANT:
		if IsBlacklisted("constants", bi.Name()) {
			goto blacklisted
		}
		ProcessConstantInfo(gi.ToConstantInfo(bi))
	case gi.INFO_TYPE_CALLBACK:
		if IsBlacklisted("callbacks", bi.Name()) {
			goto blacklisted
		}
		ProcessCallbackInfo(gi.ToCallableInfo(bi))
	case gi.INFO_TYPE_FUNCTION:
		if IsBlacklisted("functions", bi.Name()) {
			goto blacklisted
		}
		ProcessFunctionInfo(gi.ToFunctionInfo(bi), nil)
	case gi.INFO_TYPE_INTERFACE:
		if IsBlacklisted("interfaces", bi.Name()) {
			goto blacklisted
		}
		ProcessInterfaceInfo(gi.ToInterfaceInfo(bi))
	case gi.INFO_TYPE_OBJECT:
		if IsBlacklisted("objects", bi.Name()) {
			goto blacklisted
		}
		ProcessObjectInfo(gi.ToObjectInfo(bi))
	default:
		printf("// TODO: %s (%s)\n", bi.Name(), bi.Type())
	}
	return

blacklisted:
	printf("// blacklisted: %s (%s)\n", bi.Name(), bi.Type())
}
Esempio n. 15
0
func GoTypeForInterface(bi *gi.BaseInfo, flags TypeFlags) string {
	var out bytes.Buffer
	printf := PrinterTo(&out)
	ns := bi.Namespace()
	fullnm := strings.ToLower(ns) + "." + bi.Name()

	if flags&TypeListMember != 0 {
		switch bi.Type() {
		case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
			return GoTypeForInterface(bi, TypePointer|TypeReturn)
		default:
			return GoTypeForInterface(bi, TypeReturn)
		}
	}

	switch t := bi.Type(); t {
	case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
		if flags&TypeExact != 0 {
			// exact type for object/interface is always an unsafe.Pointer
			printf("unsafe.Pointer")
			break
		}

		if flags&(TypeReturn|TypeReceiver) != 0 && flags&TypePointer != 0 {
			// receivers and return values are actual types,
			// and a pointer most likely
			printf("*")
		}
		if ns != Config.Namespace {
			// prepend foreign types with appropriate namespace
			printf("%s.", strings.ToLower(ns))
		}
		printf(bi.Name())
		if flags&(TypeReturn|TypeReceiver) == 0 {
			// ordinary function arguments are substituted by their *Like
			// counterparts
			printf("Like")
		}
		if flags&TypeReceiver != 0 && t == gi.INFO_TYPE_INTERFACE {
			// special case for interfaces, we use *Impl structures
			// as receivers
			printf("Impl")
		}
	case gi.INFO_TYPE_CALLBACK:
		if flags&TypeExact != 0 {
			printf("unsafe.Pointer")
			break
		}
		goto handle_default
	case gi.INFO_TYPE_STRUCT:
		if ns == "cairo" {
			printf(CairoGoTypeForInterface(bi, flags))
			break
		}
		goto handle_default
	default:
		goto handle_default
	}
	return out.String()
handle_default:
	_, disguised := GConfig.Sys.DisguisedTypes[fullnm]
	if flags&TypePointer != 0 && !disguised {
		printf("*")
	}
	if ns != Config.Namespace {
		printf("%s.", strings.ToLower(ns))
	}
	printf(bi.Name())
	return out.String()
}
Esempio n. 16
0
func go_type_for_interface(bi *gi.BaseInfo, flags type_flags) string {
	var out bytes.Buffer
	printf := printer_to(&out)
	ns := bi.Namespace()
	fullnm := strings.ToLower(ns) + "." + bi.Name()

	if flags&type_list_member != 0 {
		switch bi.Type() {
		case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
			return go_type_for_interface(bi, type_pointer|type_return)
		default:
			return go_type_for_interface(bi, type_return)
		}
	}

	switch t := bi.Type(); t {
	case gi.INFO_TYPE_OBJECT, gi.INFO_TYPE_INTERFACE:
		if flags&type_exact != 0 {
			// exact type for object/interface is always an unsafe.Pointer
			printf("unsafe.Pointer")
			break
		}

		if flags&(type_return|type_receiver) != 0 && flags&type_pointer != 0 {
			// receivers and return values are actual types,
			// and a pointer most likely
			printf("*")
		}
		if ns != config.namespace {
			// prepend foreign types with appropriate namespace
			printf("%s.", strings.ToLower(ns))
		}
		printf(bi.Name())
		if flags&(type_return|type_receiver) == 0 {
			// ordinary function arguments are substituted by their *Like
			// counterparts
			printf("Like")
		}
		if flags&type_receiver != 0 && t == gi.INFO_TYPE_INTERFACE {
			// special case for interfaces, we use *Impl structures
			// as receivers
			printf("Impl")
		}
	case gi.INFO_TYPE_CALLBACK:
		if flags&type_exact != 0 {
			printf("unsafe.Pointer")
			break
		}
		goto handle_default
	case gi.INFO_TYPE_STRUCT:
		if ns == "cairo" {
			printf(cairo_go_type_for_interface(bi, flags))
			break
		}
		goto handle_default
	default:
		goto handle_default
	}
	return out.String()
handle_default:
	if flags&type_pointer != 0 && !config.is_disguised(fullnm) {
		printf("*")
	}
	if ns != config.namespace {
		printf("%s.", strings.ToLower(ns))
	}
	printf(bi.Name())
	return out.String()
}