示例#1
0
文件: templater.go 项目: xland/qt
func isBlocked(f *parser.Function) bool {
	for _, n := range []string{"scriptValueFromQMetaObject", "fromScriptValue", "QPlaceProposedSearchResult", "evaluateTo", "detected", "isRecordType", "replace", "insert", "remove", "find", "changedStates", "state", "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
		}
	}

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

	if f.Name == "exec" && runtime.GOOS == "linux" && !strings.Contains(f.Class(), "Sql") {
		f.Output = "void"
	}

	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
}
示例#2
0
文件: input.go 项目: 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
}
示例#3
0
文件: output.go 项目: mouse225/qt
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
	}
}
示例#4
0
文件: type.go 项目: 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
}
示例#5
0
文件: output.go 项目: 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
}
示例#6
0
文件: header.go 项目: mouse225/qt
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
}
示例#7
0
文件: type.go 项目: 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
}
示例#8
0
文件: header.go 项目: mouse225/qt
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, ", ")
}
示例#9
0
文件: helper.go 项目: 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
}
示例#10
0
文件: header.go 项目: mouse225/qt
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)
}
示例#11
0
文件: header.go 项目: mouse225/qt
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
}
示例#12
0
文件: output.go 项目: mouse225/qt
func goOutput(name string, value string, f *parser.Function) string {
	var vOld = value

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

	switch value {
	case "QStringList":
		{
			return fmt.Sprintf("strings.Split(%v, \"|\")", goOutput(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", name)
		}

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

	case "T", "JavaVM", "jclass", "jobject":
		{
			switch f.TemplateMode {
			case "Int":
				{
					return fmt.Sprintf("int(%v)", name)
				}
			case "Boolean":
				{
					return fmt.Sprintf("int(%v) != 0", name)
				}
			case "Void":
				{
					return name
				}
			}
			return fmt.Sprintf("unsafe.Pointer(%v)", name)
		}

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

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

	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) != "" {
				if parser.ClassMap[f.Class()].WeakLink[c.Module] {
					return fmt.Sprintf("int64(%v)", name)
				}
				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) {
				if parser.ClassMap[f.Class()].WeakLink[parser.ClassMap[value].Module] {
					return fmt.Sprintf("unsafe.Pointer(%v)", name)
				}
				return fmt.Sprintf("%v.New%vFromPointer(%v)", m, value, name)
			}

			if f.Meta == "constructor" {
				return fmt.Sprintf("new%vFromPointer(%v)", value, name)
			}
			return fmt.Sprintf("New%vFromPointer(%v)", value, name)
		}
	}

	f.Access = "unsupported_goOutput"
	return f.Access
}
示例#13
0
文件: function_cpp.go 项目: xland/qt
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)
}
示例#14
0
文件: type.go 项目: 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
}
示例#15
0
文件: output.go 项目: xland/qt
func cppOutput(name string, value string, f *parser.Function) string {

	var vOld = value

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

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

	case "QString":
		{
			if strings.Contains(vOld, "*") {
				return fmt.Sprintf("%v->toUtf8().data()", name)
			}
			return fmt.Sprintf("%v.toUtf8().data()", name)
		}

	case "bool", "int", "void", "", "T", "JavaVM", "jclass":
		{
			if value == "void" {
				if strings.Contains(vOld, "*") {
					if strings.Contains(vOld, "const") {
						return fmt.Sprintf("const_cast<%v*>(%v)", value, name)
					}
					return name
				}
			}

			return name
		}

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

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

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

			switch value {
			case "QModelIndex":
				{
					return fmt.Sprintf("%v.internalPointer()", name)
				}
			case "QJSValue", "QScriptValue", "QVariant", "QStringRef", "QDateTime", "QTimeZone", "QRegularExpressionMatchIterator", "QRegularExpressionMatch", "QRegularExpression", "QDir", "QByteArray", "QEasingCurve", "QCommandLineOption", "QRegExp", "QJsonObject", "QJsonArray", "QJsonDocument", "QRegion", "QBrush", "QColor":
				{
					return fmt.Sprintf("new %v(%v)", value, name)
				}

			case "QAndroidJniObject":
				{
					return name
				}
			}
		}
	}

	f.Access = "unsupported_cppOutput"
	return f.Access
}
示例#16
0
文件: input.go 项目: 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
}
示例#17
0
文件: input.go 项目: 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
}
示例#18
0
文件: type.go 项目: mouse225/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":
		{
			switch f.TemplateMode {
			case "Int":
				{
					return "int"
				}
			case "Boolean":
				{
					return "bool"
				}
			case "Void":
				return ""
			}

			if module(f) == "androidextras" && f.Name != "object" {
				return fmt.Sprintf("interface{}")
			}

			return "unsafe.Pointer"
		}

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

	case "...":
		{
			if parser.ClassMap[f.Class()].Module == "QtAndroidExtras" {
				return "...interface{}"
			}
		}

	case "qreal":
		{
			return "float64"
		}

	case "qint64":
		{
			return "int64"
		}
	}

	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) != "" {
				if parser.ClassMap[f.Class()].WeakLink[c.Module] {
					return "int64"
				}
				return module(c.Module) + "." + goEnum(f, value)
			}
			return goEnum(f, value)
		}

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

	f.Access = "unsupported_goType"
	return f.Access
}
示例#19
0
文件: type.go 项目: mouse225/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":
		{
			switch f.TemplateMode {
			case "Int":
				{
					return "int"
				}
			case "Boolean":
				{
					return "int"
				}
			case "Void":
				{
					return "void"
				}
			}

			return "void*"
		}

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

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

	case "qreal":
		{
			return "double"
		}

	case "qint64":
		{
			return "long long"
		}
	}

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

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

	f.Access = "unsupported_cppType"
	return f.Access
}
示例#20
0
文件: input.go 项目: 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
}
示例#21
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 f.Name == "objectNameAbs" || f.Name == "setObjectNameAbs" {
		o += fmt.Sprintf("if (dynamic_cast<My%v*>(static_cast<%v*>(ptr))) {\n\t\t", f.Class(), f.Class())
	}

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

	var tmpMeta string
	if strings.Contains(f.Virtual, "impure") {
		if isDerivedFromSlot(f) {
			tmpMeta = f.Meta
			f.Meta = "slot"
		}
	}

	switch f.Meta {
	case "constructor":
		{
			if hasVirtualFunction(parser.ClassMap[f.Class()]) {
				o += fmt.Sprintf("new My%v(%v)", f.Class(), converter.CppBodyInput(f))
			} else {
				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(%v)", f.Class(), f.Name, converter.DeduceGeneric(f), 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 {
					if parser.ClassMap[f.Class()].IsQObjectSubClass() {
						o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<%v*>(ptr)->%v%v(%v)", f.Class(), f.Name, converter.DeduceGeneric(f), converter.CppBodyInput(f)))
					} else {
						if f.Name == "objectNameAbs" || f.Name == "setObjectNameAbs" {
							o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<My%v*>(ptr)->%v%v(%v)", f.Class(), f.Name, converter.DeduceGeneric(f), converter.CppBodyInput(f)))
						} else {
							o += converter.CppBodyOutput(f, fmt.Sprintf("static_cast<%v*>(ptr)->%v%v(%v)", f.Class(), f.Name, converter.DeduceGeneric(f), converter.CppBodyInput(f)))
						}
					}
				}
			}
		}
	case "signal":
		{
			if converter.IsPrivateSignal(f) {
				o += fmt.Sprintf("QObject::%v(%v, &%v::%v, static_cast<My%v*>(ptr), static_cast<%v (My%v::*)(%v)>(&My%v::Signal_%v%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), cppFunctionSignalOverload(f))
			} 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%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), cppFunctionSignalOverload(f))
			}
		}
	default:
		{
			f.Access = "unsupported_CppFunctionBody"
			return f.Access
		}
	}

	if tmpMeta != "" {
		f.Meta = tmpMeta
	}

	if f.Name == "objectNameAbs" {
		o += fmt.Sprintf(";\n\t}\n\treturn QString(\"%v_BASE\").toUtf8().data()", f.Class())
	} else if f.Name == "setObjectNameAbs" {
		return o + ";\n\t}"
	}

	return o + ";"
}