示例#1
0
func ProcessStructInfo(si *gi.StructInfo) {
	name := si.Name()
	size := si.Size()

	if si.IsGTypeStruct() {
		return
	}
	if strings.HasSuffix(name, "Private") {
		return
	}

	fullnm := strings.ToLower(si.Namespace()) + "." + name
	if _, ok := GConfig.Sys.DisguisedTypes[fullnm]; ok {
		size = -1
	}

	if !IsBlacklisted("structdefs", name) {
		switch size {
		case -1:
			printf("type %s struct { Pointer unsafe.Pointer }\n", name)
		case 0:
			printf("type %s struct {}\n", name)
		default:
			printf("type %s struct {\n", name)
			offset := 0
			for i, n := 0, si.NumField(); i < n; i++ {
				field := si.Field(i)
				fo := field.Offset()
				ft := field.Type()
				nm := field.Name()
				if fo != offset {
					pad := fo - offset
					printf("\t_ [%d]byte\n", pad)
					offset += pad
				}
				if TypeNeedsWrapper(ft) {
					printf("\t%s0 %s\n", nm, CgoType(ft, TypeExact))
				} else {
					printf("\t%s %s\n", LowerCaseToCamelCase(nm),
						GoType(ft, TypeExact))
				}
				offset += TypeSize(ft, TypeExact)
			}
			if size != offset {
				printf("\t_ [%d]byte\n", size-offset)
			}
			printf("}\n")
			//printf("type %s struct { data [%d]byte }\n", name, size)
		}

		// for each field that needs a wrapper, generate it
		for i, n := 0, si.NumField(); i < n; i++ {
			field := si.Field(i)
			ft := field.Type()
			nm := field.Name()

			if !TypeNeedsWrapper(ft) {
				continue
			}

			gotype := GoType(ft, TypeReturn)
			printf("func (this0 *%s) %s() %s {\n",
				name, LowerCaseToCamelCase(nm), gotype)
			printf("\tvar %s1 %s\n", nm, gotype)
			conv := CgoToGo(ft, "this0."+nm+"0", nm+"1",
				ConvOwnNone)
			printf("%s", PrintLinesWithIndent(conv))
			printf("\treturn %s1\n", nm)
			printf("}\n")
		}
	}

	for i, n := 0, si.NumMethod(); i < n; i++ {
		meth := si.Method(i)
		if IsMethodBlacklisted(name, meth.Name()) {
			continue
		}

		ProcessFunctionInfo(meth, gi.ToBaseInfo(si))
	}
}
示例#2
0
func (this *binding_generator) process_struct_info(si *gi.StructInfo) {
	p := printer_to(&this.go_bindings)

	name := si.Name()
	size := si.Size()

	if si.IsGTypeStruct() {
		return
	}
	if strings.HasSuffix(name, "Private") {
		return
	}

	fullnm := strings.ToLower(si.Namespace()) + "." + name
	if config.is_disguised(fullnm) {
		size = -1
	}

	if !config.is_blacklisted("structdefs", name) {
		switch size {
		case -1:
			p("type %s struct { Pointer unsafe.Pointer }\n", name)
		case 0:
			p("type %s struct {}\n", name)
		default:
			p("type %s struct {\n", name)
			offset := 0
			for i, n := 0, si.NumField(); i < n; i++ {
				field := si.Field(i)
				fo := field.Offset()
				ft := field.Type()
				nm := field.Name()
				if fo != offset {
					pad := fo - offset
					p("\t_ [%d]byte\n", pad)
					offset += pad
				}
				if type_needs_wrapper(ft) {
					p("\t%s0 %s\n", nm, cgo_type(ft, type_exact))
				} else {
					p("\t%s %s\n", lower_case_to_camel_case(nm),
						go_type(ft, type_exact))
				}
				offset += type_size(ft, type_exact)
			}
			if size != offset {
				p("\t_ [%d]byte\n", size-offset)
			}
			p("}\n")
			//printf("type %s struct { data [%d]byte }\n", name, size)
		}

		// for each field that needs a wrapper, generate it
		for i, n := 0, si.NumField(); i < n; i++ {
			field := si.Field(i)
			ft := field.Type()
			nm := field.Name()

			if !type_needs_wrapper(ft) {
				continue
			}

			gotype := go_type(ft, type_return)
			p("func (this0 *%s) %s() %s {\n",
				name, lower_case_to_camel_case(nm), gotype)
			p("\tvar %s1 %s\n", nm, gotype)
			conv := cgo_to_go(ft, "this0."+nm+"0", nm+"1",
				conv_own_none)
			p("%s", print_lines_with_indent(conv))
			p("\treturn %s1\n", nm)
			p("}\n")
		}
	}

	for i, n := 0, si.NumMethod(); i < n; i++ {
		meth := si.Method(i)
		if config.is_method_blacklisted(name, meth.Name()) {
			continue
		}

		this.process_function_info(meth)
	}
}