예제 #1
0
파일: function_go.go 프로젝트: xland/qt
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
}
예제 #2
0
파일: function_go.go 프로젝트: mouse225/qt
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
}