Ejemplo n.º 1
0
func CppBodyInput(f *parser.Function) (o string) {

	if f.Meta == "slot" {
		for _, p := range f.Parameters {
			o += fmt.Sprintf(", Q_ARG(%v, %v)", CppBodyInputSlotValue(f, p), cppInput(p.Name, p.Value, f))
		}
		return
	}

	if f.Meta == "signal" {
		for _, p := range f.Parameters {

			if isEnum(f.Class(), cleanValue(p.Value)) {
				o += fmt.Sprintf("%v, ", cppEnum(f, cleanValue(p.Value), true))
			} else {
				o += fmt.Sprintf("%v, ", p.Value)
			}
		}
		return strings.TrimSuffix(o, ", ")
	}

	for _, p := range f.Parameters {
		o += fmt.Sprintf("%v, ", cppInput(p.Name, p.Value, f))
	}

	return strings.TrimSuffix(o, ", ")
}
Ejemplo n.º 2
0
func IsPrivateSignal(f *parser.Function) bool {

	var fData string

	switch runtime.GOOS {
	case "darwin":
		fData = utils.Load(fmt.Sprintf("/usr/local/Qt5.5.1/5.5/clang_64/lib/%v.framework/Versions/5/Headers/%v", strings.Title(parser.ClassMap[f.Class()].DocModule), filepath.Base(f.Filepath)))

	case "windows":
		fData = utils.Load(fmt.Sprintf("C:\\Qt\\Qt5.5.1\\5.5\\mingw492_32\\include\\%v\\%v", strings.Title(parser.ClassMap[f.Class()].DocModule), filepath.Base(f.Filepath)))

	case "linux":
		switch runtime.GOARCH {
		case "amd64":
			{
				fData = utils.Load(fmt.Sprintf("/usr/local/Qt5.5.1/5.5/gcc_64/include/%v/%v", strings.Title(parser.ClassMap[f.Class()].DocModule), filepath.Base(f.Filepath)))
			}
		case "386":
			{
				fData = utils.Load(fmt.Sprintf("/usr/local/Qt5.5.1/5.5/gcc/include/%v/%v", strings.Title(parser.ClassMap[f.Class()].DocModule), filepath.Base(f.Filepath)))
			}
		}
	}

	if fData != "" {
		return strings.Contains(strings.Split(strings.Split(fData, f.Name+"(")[1], ")")[0], "QPrivateSignal")
	} else {
		fmt.Println("converter.IsPrivateSignal", f.Class())
	}

	return false
}
Ejemplo n.º 3
0
Archivo: input.go Proyecto: xland/qt
func goInput(name string, value string, f *parser.Function) string {
	var vOld = value

	name = cleanName(name)
	value = cleanValue(value)

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("C.CString(strings.Join(%v, \"|\"))", name)
		}

	case "uchar", "char", "QString":
		{
			if strings.Contains(vOld, "**") {
				return fmt.Sprintf("C.CString(strings.Join(%v, \"|\"))", name)
			}
			return fmt.Sprintf("C.CString(%v)", name)
		}

	case "bool":
		{
			return fmt.Sprintf("C.int(qt.GoBoolToInt(%v))", name)
		}

	case "int":
		{
			return fmt.Sprintf("C.int(%v)", name)
		}

	case "qreal":
		{
			return fmt.Sprintf("C.double(%v)", name)
		}

	case "jclass":
		{
			return name
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			return fmt.Sprintf("C.int(%v)", name)
		}

	case isClass(value):
		{
			if m := module(parser.ClassMap[value].Module); m != module(f) {
				return fmt.Sprintf("%v.PointerFrom%v(%v)", m, strings.Title(value), name)
			}
			return fmt.Sprintf("PointerFrom%v(%v)", strings.Title(value), name)
		}
	}

	f.Access = "unsupported_goInput"
	return f.Access
}
Ejemplo n.º 4
0
func goOutputFailed(value string, f *parser.Function) string {
	var vOld = value

	value = cleanValue(value)

	switch value {
	case "bool":
		return "false"

	case "int", "qreal", "qint64":
		return "0"

	case "uchar", "char", "QString":
		return "\"\""

	case "QStringList":
		return "make([]string, 0)"

	case "void", "":
		if strings.Contains(vOld, "*") {
			return "nil"
		}
		return ""

	case "T", "JavaVM", "jclass", "jobject":

		switch f.TemplateMode {
		case "Int":
			{
				return "0"
			}
		case "Boolean":
			{
				return "false"
			}
		case "Void":
			{
				return ""
			}
		}

		return "nil"
	}

	switch {
	case isEnum(f.Class(), value):
		return "0"

	case isClass(value):
		return "nil"

	default:
		f.Access = "unsupported_GoBodyOutputFailed"
		return f.Access
	}
}
Ejemplo n.º 5
0
Archivo: type.go Proyecto: xland/qt
func cppType(f *parser.Function, value string) string {
	var vOld = value

	value = cleanValue(value)

	switch value {
	case "uchar", "char", "QString", "QStringList":
		{
			return "char*"
		}

	case "bool", "int":
		{
			return "int"
		}

	case "void", "":
		{
			if strings.Contains(vOld, "*") {
				return "void*"
			}
			return "void"
		}

	case "T", "JavaVM", "jclass":
		{
			return "void*"
		}

	case "qreal":
		{
			return "double"
		}

	case "...":
		{
			return ""
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			return "int"
		}

	case isClass(value):
		{
			return "void*"
		}
	}

	f.Access = "unsupported_cppType"
	return f.Access
}
Ejemplo n.º 6
0
func isBlocked(f *parser.Function) bool {
	for _, n := range []string{"relations", "scriptValueFromQMetaObject", "fromScriptValue", "QPlaceProposedSearchResult", "evaluateTo", "detected", "isRecordType", "replace", "insert", "remove", "find", "changedStates", "requestTexture", "draw", "setTabPositions", "setExtraSelections", "disconnect", "QJsonObject", "QJsonArray", "QAccessibleStateChangeEvent", "hitTest", "setupUi", "setEditFocus", "toUnicode", "registerConverter", "registerEqualsComparator", "registerComparators", "hasRegisteredConverterFunction", "hasRegisteredComparators", "setNavigationMode", "navigationMode", "setNativeArguments", "setAlphaChannel", "setDefaultAction", "unregisterEventNotifier", "QXmlStreamWriter", "hasEditFocus", "QTextStream", "QStringRef", "QSignalBlocker", "defaultAction", "canConvert", "queryItemValue", "hasQueryItem", "hasEncodedQueryItem", "hasLocalData", "registerEventNotifier", "registerTimer", "setYMD", "nativeArguments"} {
		if f.Name == n {
			f.Access = "unsupported_isBlocked"
			return true
		}
	}

	for _, n := range []string{"QAccessibleInterface::state", "QAccessibleWidget::state"} {
		if f.Fullname == n {
			f.Access = "unsupported_isBlocked"
			return true
		}
	}

	//Android Only
	for _, blockedAndroid := range []string{"setAsDockMenu", "setSelect"} {
		if f.Name == blockedAndroid {
			f.Access = "unsupported_isBlocked_Android"
			return true
		}
	}

	if f.Name == "value" && f.Class() == "QVariant" {
		f.Access = "unsupported_goFunction"
		return true
	}

	if f.Class() == "QAudioBuffer" && strings.Contains(f.Output, "T") {
		f.Access = "unsupported_goFunction"
		return true
	}

	return false
}
Ejemplo n.º 7
0
func CppBodyInputSlotValue(f *parser.Function, p *parser.Parameter) string {
	if strings.Contains(p.Value, "*") {
		return fmt.Sprintf("%v*", cleanValue(p.Value))
	}

	if isEnum(f.Class(), p.Value) {
		return cppEnum(f, p.Value, false)
	}

	return cleanValue(p.Value)
}
Ejemplo n.º 8
0
func CppBodyInputCallback(f *parser.Function) (o string) {
	for _, p := range f.Parameters {

		if isEnum(f.Class(), cleanValue(p.Value)) {
			o += fmt.Sprintf("%v %v, ", cppEnum(f, cleanValue(p.Value), true), cleanName(p.Name))
		} else {
			o += fmt.Sprintf("%v %v, ", p.Value, cleanName(p.Name))
		}
	}

	return strings.TrimSuffix(o, ", ")
}
Ejemplo n.º 9
0
Archivo: output.go Proyecto: xland/qt
func cgoOutput(name string, value string, f *parser.Function) string {

	name = cleanName(name)
	value = cleanValue(value)

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("strings.Split(%v, \"|\")", cgoOutput(name, "QString", f))
		}

	case "uchar", "char", "QString":
		{
			return fmt.Sprintf("C.GoString(%v)", name)
		}

	case "int":
		{
			return fmt.Sprintf("int(%v)", name)
		}

	case "bool":
		{
			return fmt.Sprintf("%v != 0", cgoOutput(name, "int", f))
		}

	case "void", "":
		{
			return ""
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			if c, exists := parser.ClassMap[class(cppEnum(f, value, false))]; exists && module(c.Module) != module(f) && module(c.Module) != "" {
				return fmt.Sprintf("%v.%v(%v)", module(c.Module), goEnum(f, value), name)
			}
			return fmt.Sprintf("%v(%v)", goEnum(f, value), name)
		}

	case isClass(value):
		{
			if m := module(parser.ClassMap[value].Module); m != module(f) {
				return fmt.Sprintf("%v.New%vFromPointer(%v)", m, value, name)
			}
			return fmt.Sprintf("New%vFromPointer(%v)", value, name)
		}
	}

	f.Access = "unsupported_cgoOutput"
	return f.Access
}
Ejemplo n.º 10
0
func cppFunction(f *parser.Function) string {

	if isGeneric(f) {
		var tmp string
		for _, m := range jniGenericModes(f) {
			f.TemplateMode = m
			tmp += fmt.Sprintf("%v{\n\t%v\n}\n", cppFunctionHeader(f), cppFunctionBody(f))
		}
		f.TemplateMode = ""
		return tmp
	}

	return fmt.Sprintf("%v{\n\t%v\n}", cppFunctionHeader(f), cppFunctionBody(f))
}
Ejemplo n.º 11
0
func goFunction(f *parser.Function) string {
	if f.Meta == "signal" && !f.Overload {
		var tmp string
		for _, signalMode := range []string{"Connect", "Disconnect", "callback"} {
			f.SignalMode = signalMode
			if signalMode == "callback" {
				tmp += fmt.Sprintf("//export callback%v%v\n", f.Class(), strings.Title(f.Name))
			}
			tmp += fmt.Sprintf("%v{\n%v\n}\n\n", goFunctionHeader(f), goFunctionBody(f))
		}
		f.SignalMode = ""
		return tmp
	}
	return fmt.Sprintf("%v{\n%v\n}", goFunctionHeader(f), goFunctionBody(f))
}
Ejemplo n.º 12
0
Archivo: type.go Proyecto: mouse225/qt
func cgoType(f *parser.Function, value string) string {

	value = cleanValue(value)

	switch value {
	case "uchar", "char", "QString", "QStringList":
		{
			return "*C.char"
		}

	case "bool", "int":
		{
			return "C.int"
		}

	case "void", "":
		{
			return ""
		}

	case "qreal":
		{
			return "C.double"
		}

	case "qint64":
		{
			return "C.longlong"
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			return "C.int"
		}

	case isClass(value):
		{
			return "unsafe.Pointer"
		}
	}

	f.Access = "unsupported_cgoType"
	return f.Access
}
Ejemplo n.º 13
0
func isDerivedFromSlot(of *parser.Function) bool {

	var c = parser.ClassMap[of.Class()]

	for _, bcName := range c.GetAllBases([]string{}) {
		if bc, exists := parser.ClassMap[bcName]; exists {
			for _, f := range bc.Functions {
				if strings.Contains(f.Virtual, "impure") && f.Output == "void" {
					if of.Name == f.Name && (of.Meta == "slot" || f.Meta == "slot") {
						return true
					}
				}
			}
		}
	}

	return false
}
Ejemplo n.º 14
0
func CppBodyOutputCallback(f *parser.Function) (o string) {

	//TODO: parse from docs
	var this = "this"
	if strings.Contains(strings.Split(f.Signature, ")")[1], "const") {
		this = fmt.Sprintf("const_cast<My%v*>(this)", f.Class())
	}

	if parser.ClassMap[f.Class()].IsQObjectSubClass() {
		o += fmt.Sprintf("%v, %v", this, cppOutput("this->objectName()", "QString", f))
	} else {
		o += fmt.Sprintf("%v, %v", this, cppOutput("this->objectNameAbs()", "QString", f))
	}

	for _, p := range f.Parameters {
		o += fmt.Sprintf(", %v", cppOutput(p.Name, p.Value, f))
	}
	return
}
Ejemplo n.º 15
0
func isDerivedFromPure(of *parser.Function) bool {

	var c = parser.ClassMap[of.Class()]

	for _, bcName := range c.GetAllBases([]string{}) {
		if bc, exists := parser.ClassMap[bcName]; exists {
			for _, f := range bc.Functions {
				if f.Virtual == "impure" && !isDerivedFromSlot(of) {
					return false
				}
				if f.Virtual == "pure" && f.Output == "void" {
					if of.Name == f.Name {
						return true
					}
				}
			}
		}
	}

	return false
}
Ejemplo n.º 16
0
func GoHeaderName(f *parser.Function) (o string) {

	if f.SignalMode == "callback" {
		var tmp = fmt.Sprintf("callback%v%v", f.Class(), strings.Replace(strings.Title(f.Name), "~", "Destroy", -1))
		if f.Overload {
			tmp += f.OverloadNumber
		}
		return tmp
	}

	if f.Static {
		o += fmt.Sprintf("%v_", strings.Split(f.Fullname, "::")[0])
	}

	switch f.Meta {
	case "constructor":
		o += "New"

	case "destructor":
		o += "Destroy"
	}

	o += f.SignalMode

	o += strings.Title(f.Name)

	o += f.TemplateMode

	if f.Overload {
		o += f.OverloadNumber
	}

	if strings.ContainsAny(o, "&<>=/!()[]{}-^|*+-") || strings.Contains(o, "Operator") {
		f.Access = "unsupported_GoHeaderName"
		return f.Access
	}

	return strings.Replace(o, "~", "", -1)
}
Ejemplo n.º 17
0
func goFunction(f *parser.Function) string {
	if f.Meta == "signal" || strings.Contains(f.Virtual, "impure") && f.Output == "void" {
		var tmp string
		for _, signalMode := range []string{"Connect", "Disconnect", "callback"} {
			f.SignalMode = signalMode
			if signalMode == "callback" {
				tmp += fmt.Sprintf("//export callback%v%v", f.Class(), strings.Replace(strings.Title(f.Name), "~", "Destroy", -1))
				if f.Overload {
					tmp += f.OverloadNumber
				}
				tmp += "\n"
			}
			tmp += fmt.Sprintf("%v{\n%v\n}\n\n", goFunctionHeader(f), goFunctionBody(f))
		}
		f.SignalMode = ""

		var isPrivate bool
		if f.Meta == "signal" {
			isPrivate = converter.IsPrivateSignal(f)
		}

		var tmpMeta = f.Meta
		f.Meta = "plain"
		if !isPrivate {
			tmp += fmt.Sprintf("%v{\n%v\n}\n\n", goFunctionHeader(f), goFunctionBody(f))
			if tmpMeta != "signal" {
				var tmpTmp = strings.Replace(fmt.Sprintf("%v{\n%v\n}\n\n", goFunctionHeader(f), goFunctionBody(f)), "_"+strings.Title(f.Name)+"(", "_"+strings.Title(f.Name)+"Default(", -1)
				tmp += strings.Replace(tmpTmp, ")"+strings.Title(f.Name)+"(", ")"+strings.Title(f.Name)+"Default(", -1)
			}
		}
		f.Meta = tmpMeta

		return tmp
	}

	if isGeneric(f) {
		var tmp string
		for _, m := range jniGenericModes(f) {
			f.TemplateMode = m
			tmp += fmt.Sprintf("%v{\n%v\n}\n", goFunctionHeader(f), goFunctionBody(f))
		}
		f.TemplateMode = ""
		return tmp
	}

	return fmt.Sprintf("%v{\n%v\n}", goFunctionHeader(f), goFunctionBody(f))
}
Ejemplo n.º 18
0
func GoHeaderInput(f *parser.Function) (o string) {

	if f.SignalMode == "callback" {
		o += "ptr unsafe.Pointer, ptrName *C.char"
		for _, p := range f.Parameters {
			if v := cgoType(f, p.Value); v != "" {
				o += fmt.Sprintf(", %v %v", cleanName(p.Name), v)
			}
		}
		return strings.TrimSuffix(o, ", ")
	}

	if (f.Meta == "signal" || strings.Contains(f.Virtual, "impure")) && f.SignalMode == "Connect" {
		o += "f func ("
	}

	if (f.Meta == "signal" || strings.Contains(f.Virtual, "impure")) && f.SignalMode != "Connect" {
		if strings.Contains(f.Virtual, "impure") && f.SignalMode == "" {
		} else {
			return
		}
	}

	for _, p := range f.Parameters {
		if v := goType(f, p.Value); v != "" {
			if isClass(v) {
				if (f.Meta == "signal" || strings.Contains(f.Virtual, "impure")) && f.SignalMode == "Connect" {
					o += fmt.Sprintf("%v *%v, ", cleanName(p.Name), v)
				} else {
					o += fmt.Sprintf("%v %v_ITF, ", cleanName(p.Name), v)
				}
			} else {
				o += fmt.Sprintf("%v %v, ", cleanName(p.Name), v)
			}
		} else {
			f.Access = "unsupported_GoHeaderInput"
			return f.Access
		}
	}

	o = strings.TrimSuffix(o, ", ")

	if (f.Meta == "signal" || strings.Contains(f.Virtual, "impure")) && f.SignalMode == "Connect" {
		o += ")"
	}

	return
}
Ejemplo n.º 19
0
func goFunctionBody(f *parser.Function) (o string) {

	if !f.Static && f.Meta != "constructor" && f.SignalMode != "callback" {
		o += fmt.Sprintf("if ptr.Pointer() != nil {\n")
	}

	if converter.GoHeaderOutput(f) != "" {
		o += "return "
	}

	/*
		if (f.Meta == "destructor" && isObjectSubClass(f.Class())) || (f.Meta == "slot" && strings.Contains(f.Name, "deleteLater")) {
			o += "getSignal(ptr.ObjectName(), \"destroyed\").(func(QObject, QObject))(ptr, ptr)\n"
		}
	*/

	if f.SignalMode == "callback" {
		o += fmt.Sprintf("qt.GetSignal(C.GoString(ptrName), \"%v\").(%v)(%v)", f.Name, converter.GoHeaderInputSignalFunction(f), converter.GoBodyInputSignalValues(f))
	} else {
		o += converter.GoBodyOutput(f, fmt.Sprintf("C.%v(%v)", converter.CppHeaderName(f), converter.GoBodyInput(f)))
	}

	if f.SignalMode == "Connect" {
		o += fmt.Sprintf("\nqt.ConnectSignal(ptr.ObjectName(), \"%v\", f)", f.Name)
	}

	if f.SignalMode == "Disconnect" {
		o += fmt.Sprintf("\nqt.DisconnectSignal(ptr.ObjectName(), \"%v\")", f.Name)
	}

	if (f.Meta == "destructor" && isObjectSubClass(f.Class())) || (f.Meta == "slot" && strings.Contains(f.Name, "deleteLater")) {
		o += "\nptr.SetPointer(nil)"
	}

	if !f.Static && f.Meta != "constructor" && f.SignalMode != "callback" {
		o += "\n}"
		if converter.GoHeaderOutput(f) != "" {
			o += fmt.Sprintf("\nreturn %v", converter.GoBodyOutputFailed(f.Output, f))
		}
	}

	if parser.ClassMap[f.Class()].Stub {
		if f.Meta == "constructor" {
			return fmt.Sprintf("\nreturn New%vFromPointer(%v)", f.Class(), converter.GoBodyOutputFailed(f.Class(), f))
		} else {
			return fmt.Sprintf("\nreturn %v", converter.GoBodyOutputFailed(f.Output, f))
		}
	}

	return o
}
Ejemplo n.º 20
0
func CppHeaderInput(f *parser.Function) (o string) {
	if !(f.Static || f.Meta == "constructor") {
		o += "void* ptr, "
	}

	if f.Meta == "signal" {
		return strings.TrimSuffix(o, ", ")
	}

	for _, p := range f.Parameters {
		if v := cppType(f, p.Value); !(v == "") {
			o += fmt.Sprintf("%v %v, ", v, cleanName(p.Name))
		} else {
			f.Access = "unsupported_CppHeaderInput"
			return f.Access
		}
	}

	return strings.TrimSuffix(o, ", ")
}
Ejemplo n.º 21
0
Archivo: helper.go Proyecto: xland/qt
func cppEnum(f *parser.Function, value string, exact bool) string {

	if outE, outT := findEnum(class(f), value, false); outE != "" {
		if exact {

			if outT == "" {
				return outE
			}

			if !strings.Contains(outT, "::") {
				outT = fmt.Sprintf("%v::%v", class(outE), outT)
			}

			return cppEnumExact(value, outE, outT)
		}

		return outE
	}

	f.Access = "unsupported_cppEnum"
	return f.Access
}
Ejemplo n.º 22
0
func GoHeaderInputSignalFunction(f *parser.Function) (o string) {

	o += "func ("

	for _, p := range f.Parameters {
		if v := goType(f, p.Value); v != "" {
			if isClass(v) {
				o += fmt.Sprintf("*%v, ", v)
			} else {
				o += fmt.Sprintf("%v, ", v)
			}
		} else {
			f.Access = "unsupported_GoHeaderInputSignalFunction"
			return f.Access
		}
	}

	o = strings.TrimSuffix(o, ", ")

	o += ")"

	return
}
Ejemplo n.º 23
0
Archivo: input.go Proyecto: mouse225/qt
func goInput(name string, value string, f *parser.Function) string {
	var vOld = value

	name = cleanName(name)
	value = cleanValue(value)

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("C.CString(strings.Join(%v, \"|\"))", name)
		}

	case "uchar", "char", "QString":
		{
			if strings.Contains(vOld, "**") {
				return fmt.Sprintf("C.CString(strings.Join(%v, \"|\"))", name)
			}
			return fmt.Sprintf("C.CString(%v)", name)
		}

	case "bool":
		{
			return fmt.Sprintf("C.int(qt.GoBoolToInt(%v))", name)
		}

	case "int":
		{
			return fmt.Sprintf("C.int(%v)", name)
		}

	case "qreal":
		{
			return fmt.Sprintf("C.double(%v)", name)
		}

	case "qint64":
		{
			return fmt.Sprintf("C.longlong(%v)", name)
		}

	case "jclass", "jobject":
		{
			return name
		}

	case "...":
		{
			var tmp string
			for i := 0; i < 10; i++ {
				tmp += fmt.Sprintf("p%v, ", i)
			}
			return strings.TrimSuffix(tmp, ", ")
		}

	case "T":
		{
			switch f.TemplateMode {
			case "Int":
				return fmt.Sprintf("C.int(%v)", name)

			case "Boolean":
				return fmt.Sprintf("C.int(qt.GoBoolToInt(%v))", name)
			}

			if module(f) == "androidextras" {
				return "p0"
			}
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			return fmt.Sprintf("C.int(%v)", name)
		}

	case isClass(value):
		{
			if m := module(parser.ClassMap[value].Module); m != module(f) {
				if parser.ClassMap[f.Class()].WeakLink[parser.ClassMap[value].Module] {
					return name
				}
				return fmt.Sprintf("%v.PointerFrom%v(%v)", m, strings.Title(value), name)
			}
			return fmt.Sprintf("PointerFrom%v(%v)", strings.Title(value), name)
		}
	}

	f.Access = "unsupported_goInput"
	return f.Access
}
Ejemplo n.º 24
0
Archivo: input.go Proyecto: mouse225/qt
func cppInput(name string, value string, f *parser.Function) string {
	var vOld = value

	name = cleanName(name)
	value = cleanValue(value)

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("%v.split(\"|\", QString::SkipEmptyParts)", cppInput(name, "QString", f))
		}

	case "QString":
		{
			if strings.Contains(vOld, "&") {
				if strings.Contains(vOld, "const") {
					return fmt.Sprintf("%v(%v)", value, name)
				}
				f.Access = "unsupported_CppInput"
				return f.Access
			}

			if strings.Contains(vOld, "*") {
				return fmt.Sprintf("new %v(%v)", value, name)
			}

			return fmt.Sprintf("%v(%v)", value, name)
		}

	case "bool":
		{
			if strings.Contains(vOld, "*") {
				return "NULL"
			}
			return fmt.Sprintf("%v != 0", name)
		}

	case "int":
		{
			if strings.Contains(vOld, "*") {
				return fmt.Sprintf("&%v", name)
			}

			if strings.Contains(vOld, "&") && name == "argc" {
				return "argcs"
			}

			return name
		}

	case "char":
		{
			if strings.Contains(vOld, "const") {
				if strings.Contains(vOld, "*") {
					return fmt.Sprintf("const_cast<const %v*>(%v)", value, name)
				}
			}

			if strings.Contains(vOld, "**") {
				return "argvs"
				//return "const_cast<char **>(argvs.data())"
			}

			if strings.Contains(vOld, "*") {
				return name
			}

			return fmt.Sprintf("*%v", name)
		}

	case "qreal":
		{
			if strings.Contains(vOld, "*") {
				f.Access = "unsupported_CppInput"
				return f.Access
				//return fmt.Sprintf("&static_cast<double>(%v)", name)
			}

			return fmt.Sprintf("static_cast<double>(%v)", name)
		}

	case "qint64":
		{
			if strings.Contains(vOld, "*") {
				f.Access = "unsupported_CppInput"
				return f.Access
			}

			return fmt.Sprintf("static_cast<long long>(%v)", name)
		}

	case "jclass", "jobject":
		{
			return fmt.Sprintf("static_cast<%v>(%v)", value, name)
		}

	case "...":
		{
			var tmp string
			for i := 0; i < 10; i++ {
				if i == 9 {
					tmp += fmt.Sprintf("static_cast<jobject>(%v), ", name)
				} else {
					tmp += fmt.Sprintf("static_cast<jobject>(%v%v), ", name, i)
				}
			}
			return strings.TrimSuffix(tmp, ", ")
		}

	case "T":
		{
			switch f.TemplateMode {
			case "Int", "Boolean":
				return name
			}

			if module(f) == "androidextras" {
				return fmt.Sprintf("static_cast<jobject>(%v)", name)
			}
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			if !strings.Contains(vOld, "*") {
				return fmt.Sprintf("static_cast<%v>(%v)", cppEnum(f, value, false), name)
			}
		}

	case isClass(value):
		{
			if strings.Contains(vOld, "*") {
				if strings.Contains(vOld, "&") {
					break
				}
				return fmt.Sprintf("static_cast<%v*>(%v)", value, name)
			}

			return fmt.Sprintf("*static_cast<%v*>(%v)", value, name)
		}
	}

	f.Access = "unsupported_CppInput"
	return f.Access
}
Ejemplo n.º 25
0
Archivo: input.go Proyecto: xland/qt
func cppInput(name string, value string, f *parser.Function) string {
	var vOld = value

	name = cleanName(name)
	value = cleanValue(value)

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("%v.split(\"|\", QString::SkipEmptyParts)", cppInput(name, "QString", f))
		}

	case "QString":
		{
			if strings.Contains(vOld, "&") {
				if strings.Contains(vOld, "const") {
					return fmt.Sprintf("%v(%v)", value, name)
				}
				f.Access = "unsupported_CppInput"
				return f.Access
			}

			if strings.Contains(vOld, "*") {
				return fmt.Sprintf("new %v(%v)", value, name)
			}

			return fmt.Sprintf("%v(%v)", value, name)
		}

	case "bool":
		{
			if strings.Contains(vOld, "*") {
				return "NULL"
			}
			return fmt.Sprintf("%v != 0", name)
		}

	case "int":
		{
			if strings.Contains(vOld, "*") {
				return fmt.Sprintf("&%v", name)
			}

			if strings.Contains(vOld, "&") && name == "argc" {
				return "argcs"
			}

			return name
		}

	case "char":
		{
			if strings.Contains(vOld, "const") {
				if strings.Contains(vOld, "*") {
					return fmt.Sprintf("const_cast<const %v*>(%v)", value, name)
				}
			}

			if strings.Contains(vOld, "**") {
				return "argvs"
				//return "const_cast<char **>(argvs.data())"
			}

			if strings.Contains(vOld, "*") {
				return name
			}

			return fmt.Sprintf("*%v", name)
		}

	case "qreal":
		{
			if strings.Contains(vOld, "*") {
				f.Access = "unsupported_CppInput"
				return f.Access
				//return fmt.Sprintf("&static_cast<qreal>(%v)", name)
			}

			return fmt.Sprintf("static_cast<qreal>(%v)", name)
		}

	case "jclass":
		{
			return fmt.Sprintf("static_cast<%v>(%v)", value, name)
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			if !strings.Contains(vOld, "*") {
				return fmt.Sprintf("static_cast<%v>(%v)", cppEnum(f, value, false), name)
			}
		}

	case isClass(value):
		{
			if strings.Contains(vOld, "*") {
				if strings.Contains(vOld, "&") {
					break
				}
				return fmt.Sprintf("static_cast<%v*>(%v)", value, name)
			}

			return fmt.Sprintf("*static_cast<%v*>(%v)", value, name)
		}
	}

	f.Access = "unsupported_CppInput"
	return f.Access
}
Ejemplo n.º 26
0
Archivo: type.go Proyecto: xland/qt
func goType(f *parser.Function, value string) string {
	var vOld = value

	value = cleanValue(value)

	switch value {
	case "uchar", "char", "QString":
		{
			if strings.Contains(vOld, "**") {
				return "[]string"
			}

			return "string"
		}

	case "QStringList":
		{
			return "[]string"
		}

	case "void":
		{
			if strings.Contains(vOld, "*") {
				return "unsafe.Pointer"
			}
			return ""
		}

	case "bool", "int", "":
		{
			return value
		}

	case "T", "JavaVM", "jclass":
		{
			return "unsafe.Pointer"
		}

	case "qreal":
		{
			return "float64"
		}

	case "...":
		{
			return ""
		}
	}

	switch {
	case isEnum(f.Class(), value):
		{
			if c, exists := parser.ClassMap[class(cppEnum(f, value, false))]; exists && module(c.Module) != module(f) && module(c.Module) != "" {
				return module(c.Module) + "." + goEnum(f, value)
			}
			return goEnum(f, value)
		}

	case isClass(value):
		{
			if m := module(parser.ClassMap[value].Module); m != module(f) {
				return m + "." + value
			}
			return value
		}
	}

	f.Access = "unsupported_goType"
	return f.Access
}
Ejemplo n.º 27
0
func cppFunctionSignal(f *parser.Function) string {
	return fmt.Sprintf("void Signal_%v(%v){callback%v%v(%v);}", strings.Title(f.Name), converter.CppBodyInputCallback(f), f.Class(), strings.Title(f.Name), converter.CppBodyOutputCallback(f))
}
Ejemplo n.º 28
0
func cppFunctionBody(f *parser.Function) (o string) {

	/*
		for _, p := range f.Parameters {
			if strings.Contains(p.Value, "**") && p.Name == "argv" {
				o += "QList<QByteArray> aList = QByteArray(argv).split('|');\n"
				o += "\tQVarLengthArray<const char*> argvs(argc);\n"
				o += "\tstatic int argcs = argc;\n"
				o += "\tfor (int i = 0; i < argc; i++)\n"
				o += "\t\targvs[i] = static_cast<const char*>(aList[i].constData());\n\n\t"
			}
		}
	*/

	for _, p := range f.Parameters {
		if strings.Contains(p.Value, "**") && p.Name == "argv" {
			o += "QList<QByteArray> aList = QByteArray(argv).split('|');\n"
			o += "\tchar *argvs[argc];\n"
			o += "\tstatic int argcs = argc;\n"
			o += "\tfor (int i = 0; i < argc; i++)\n"
			o += "\t\targvs[i] = aList[i].data();\n\n\t"
		}
	}

	if converter.CppHeaderOutput(f) != "void" {
		o += "return "
	}

	switch f.Meta {
	case "constructor":
		o += fmt.Sprintf("new %v(%v)", f.Class(), converter.CppBodyInput(f))

	case "slot":
		if f.Static {
			o += fmt.Sprintf("QMetaObject::invokeMethod(%v::instance(), \"%v\"%v)", f.Class(), f.Name, converter.CppBodyInput(f))
		} else {
			o += fmt.Sprintf("QMetaObject::invokeMethod(static_cast<%v*>(ptr), \"%v\"%v)", f.Class(), f.Name, converter.CppBodyInput(f))
		}

	case "plain", "destructor":
		if f.Static {
			o += converter.CppBodyOutput(f, fmt.Sprintf("%v::%v(%v)", f.Class(), f.Name, converter.CppBodyInput(f)))
		} else {
			if f.Output == "T" && f.Class() == "QObject" {
				o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<%v*>(ptr)->%v<QObject*>(%v)", f.Class(), f.Name, converter.CppBodyInput(f)))
			} else if f.Output == "T" && f.Class() == "QMediaService" {
				o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<%v*>(ptr)->%v<QMediaControl*>(%v)", f.Class(), f.Name, converter.CppBodyInput(f)))
			} else {
				o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<%v*>(ptr)->%v(%v)", f.Class(), f.Name, converter.CppBodyInput(f)))
			}
		}

	case "signal":
		if converter.PrivateSignal(f) {
			o += fmt.Sprintf("QObject::%v(%v, &%v::%v, static_cast<My%v*>(ptr), static_cast<%v (My%v::*)(%v)>(&My%v::Signal_%v));", strings.ToLower(f.SignalMode), fmt.Sprintf("static_cast<%v*>(%v)", f.Class(), "ptr"), f.Class(), f.Name, f.Class(), f.Output, f.Class(), converter.CppBodyInput(f), f.Class(), strings.Title(f.Name))
		} else {
			o += fmt.Sprintf("QObject::%v(%v, static_cast<void (%v::*)(%v)>(&%v::%v), static_cast<My%v*>(ptr), static_cast<%v (My%v::*)(%v)>(&My%v::Signal_%v));", strings.ToLower(f.SignalMode), fmt.Sprintf("static_cast<%v*>(%v)", f.Class(), "ptr"), f.Class(), converter.CppBodyInput(f), f.Class(), f.Name, f.Class(), f.Output, f.Class(), converter.CppBodyInput(f), f.Class(), strings.Title(f.Name))
		}
	default:
		f.Access = "unsupported_CppFunctionBody"
		return f.Access
	}

	return fmt.Sprintf("%v;", o)
}
Ejemplo n.º 29
0
func goFunctionBody(f *parser.Function) (o string) {

	if parser.ClassMap[f.Class()].Stub {
		if converter.GoHeaderOutput(f) != "" {
			return fmt.Sprintf("\nreturn %v", converter.GoBodyOutputFailed(f))
		}
		return ""
	}

	if f.SignalMode != "" {
		o += fmt.Sprintf("defer qt.Recovering(\"%v %v\")\n\n", strings.ToLower(f.SignalMode), f.Fullname)
	} else {
		o += fmt.Sprintf("defer qt.Recovering(\"%v\")\n\n", f.Fullname)
	}

	//o += fmt.Sprintf("println(\"%v\")\n\n", f.Fullname)

	if !f.Static && f.Meta != "constructor" && f.SignalMode != "callback" {
		o += fmt.Sprintf("if ptr.Pointer() != nil {\n")
	}

	for _, p := range f.Parameters {
		if p.Value == "..." {
			for i := 0; i < 10; i++ {
				o += fmt.Sprintf("var p%v,d%v = assertion(%v, v...)\n", i, i, i)
				o += fmt.Sprintf("if d%v != nil {\ndefer d%v()\n}\n", i, i)
			}
		}

		if p.Value == "T" && parser.ClassMap[f.Class()].Module == "QtAndroidExtras" && f.TemplateMode == "" {
			o += fmt.Sprintf("var p0,d0 = assertion(0, %v)\n", p.Name)
			o += "if d0 != nil {\ndefer d0()\n}\n"
		}
	}

	if converter.GoHeaderOutput(f) != "" {
		o += "return "
	}

	/*
		if (f.Meta == "destructor" && isObjectSubClass(f.Class())) || (f.Meta == "slot" && strings.Contains(f.Name, "deleteLater")) {
			o += "getSignal(ptr.ObjectName(), \"destroyed\").(func(QObject, QObject))(ptr, ptr)\n"
		}
	*/

	if f.SignalMode == "callback" {

		o += fmt.Sprintf("if signal := qt.GetSignal(C.GoString(ptrName), \"%v%v\"); signal != nil {\n", f.Name, cppFunctionSignalOverload(f))

		o += fmt.Sprintf("\tsignal.(%v)(%v)\n", converter.GoHeaderInputSignalFunction(f), converter.GoBodyInputSignalValues(f))

		if f.Virtual == "impure" {
			if isDerivedFromPure(f) {
				o += "}\n"
			} else {
				if f.Meta == "slot" || isDerivedFromSlot(f) {
					o += fmt.Sprintf("\treturn true\n}\nreturn false\n")
				} else {
					o += fmt.Sprintf("} else {\n\tNew%vFromPointer(ptr).%vDefault(%v)\n}", f.Class(), strings.Title(f.Name), converter.GoBodyInputSignalValues(f))
				}
			}
		} else {
			o += "}\n"
		}

	} else {
		if strings.Contains(f.Virtual, "impure") && f.SignalMode != "" {
		} else {
			o += converter.GoBodyOutput(f, fmt.Sprintf("C.%v(%v)", converter.CppHeaderName(f), converter.GoBodyInput(f)))
		}
	}

	if f.SignalMode == "Connect" {
		if parser.ClassMap[f.Class()].IsQObjectSubClass() {
			o += fmt.Sprintf("\nqt.ConnectSignal(ptr.ObjectName(), \"%v%v\", f)", f.Name, cppFunctionSignalOverload(f))
		} else {
			o += fmt.Sprintf("\nqt.ConnectSignal(ptr.ObjectNameAbs(), \"%v%v\", f)", f.Name, cppFunctionSignalOverload(f))
		}
	}

	if f.SignalMode == "Disconnect" {
		if parser.ClassMap[f.Class()].IsQObjectSubClass() {
			o += fmt.Sprintf("\nqt.DisconnectSignal(ptr.ObjectName(), \"%v%v\")", f.Name, cppFunctionSignalOverload(f))
		} else {
			o += fmt.Sprintf("\nqt.DisconnectSignal(ptr.ObjectNameAbs(), \"%v%v\")", f.Name, cppFunctionSignalOverload(f))
		}
	}

	if (f.Meta == "destructor" && isObjectSubClass(f.Class())) || (f.Meta == "slot" && strings.Contains(f.Name, "deleteLater")) {
		o += "\nptr.SetPointer(nil)"
	}

	if !f.Static && f.Meta != "constructor" && f.SignalMode != "callback" {
		o += "\n}"
		if converter.GoHeaderOutput(f) != "" {
			o += fmt.Sprintf("\nreturn %v", converter.GoBodyOutputFailed(f))
		}
	}

	return o
}
Ejemplo n.º 30
0
func goFunctionHeader(f *parser.Function) string {
	if f.Static || f.Meta == "constructor" || f.SignalMode == "callback" {
		return fmt.Sprintf("func %v", goInterface(f))
	}
	return fmt.Sprintf("func (ptr *%v)%v", f.Class(), goInterface(f))
}