mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 00:48:38 +00:00
genbindings: allow some classes to inherit from QList<>
This commit is contained in:
parent
4997641327
commit
c36d14c540
@ -146,10 +146,10 @@ func AllowClass(className string) bool {
|
|||||||
|
|
||||||
switch className {
|
switch className {
|
||||||
case
|
case
|
||||||
"QTextStreamManipulator", // Only seems to contain garbage methods
|
"QTextStreamManipulator", // Only seems to contain garbage methods
|
||||||
"QException", // Extends std::exception, too hard
|
"QException", // Extends std::exception, too hard
|
||||||
"QUnhandledException", // As above (child class)
|
"QUnhandledException", // As above (child class)
|
||||||
"QItemSelection", // Extends a QList<>, too hard
|
// "QItemSelection", // Extends a QList<>, too hard
|
||||||
"QXmlStreamAttributes", // Extends a QList<>, too hard
|
"QXmlStreamAttributes", // Extends a QList<>, too hard
|
||||||
"QPolygon", // Extends a QVector<QPoint> template class, too hard
|
"QPolygon", // Extends a QVector<QPoint> template class, too hard
|
||||||
"QPolygonF", // Extends a QVector<QPoint> template class, too hard
|
"QPolygonF", // Extends a QVector<QPoint> template class, too hard
|
||||||
|
@ -738,7 +738,10 @@ import "C"
|
|||||||
// on these types already
|
// on these types already
|
||||||
for _, base := range c.DirectInherits {
|
for _, base := range c.DirectInherits {
|
||||||
|
|
||||||
if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
if strings.HasPrefix(base, `QList<`) {
|
||||||
|
ret.WriteString("/* Also inherits unprojectable " + base + " */\n")
|
||||||
|
|
||||||
|
} else if pkg, ok := KnownClassnames[base]; ok && pkg.PackageName != gfs.currentPackageName {
|
||||||
// Cross-package parent class
|
// Cross-package parent class
|
||||||
ret.WriteString("*" + path.Base(pkg.PackageName) + "." + cabiClassName(base) + "\n")
|
ret.WriteString("*" + path.Base(pkg.PackageName) + "." + cabiClassName(base) + "\n")
|
||||||
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
gfs.imports[importPathForQtPackage(pkg.PackageName)] = struct{}{}
|
||||||
@ -788,12 +791,9 @@ import "C"
|
|||||||
extraUnsafeArgs += ", h_" + cabiClassName(base) + " unsafe.Pointer"
|
extraUnsafeArgs += ", h_" + cabiClassName(base) + " unsafe.Pointer"
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, base := range c.DirectInherits {
|
for _, pkg := range c.DirectInheritClassInfo() {
|
||||||
ctorPrefix := ""
|
ctorPrefix := ""
|
||||||
pkg, ok := KnownClassnames[base]
|
base := pkg.Class.ClassName
|
||||||
if !ok {
|
|
||||||
panic("Class " + c.ClassName + " has unknown parent " + base)
|
|
||||||
}
|
|
||||||
|
|
||||||
constructRequiresParams := pkg.Class.AllInherits()
|
constructRequiresParams := pkg.Class.AllInherits()
|
||||||
var ixxParams []string = make([]string, 0, len(constructRequiresParams)+1)
|
var ixxParams []string = make([]string, 0, len(constructRequiresParams)+1)
|
||||||
|
@ -435,10 +435,12 @@ func (c *CppClass) VirtualMethods() []CppMethod {
|
|||||||
// Only allow virtual overrides for direct inherits, not all inherits -
|
// Only allow virtual overrides for direct inherits, not all inherits -
|
||||||
// Go will automatically allow virtual overrides for the base type because
|
// Go will automatically allow virtual overrides for the base type because
|
||||||
// the parent struct is nested
|
// the parent struct is nested
|
||||||
for _, inh := range c.DirectInherits { // AllInherits() {
|
for _, cinfo := range c.DirectInheritClassInfo() {
|
||||||
cinfo, ok := KnownClassnames[inh]
|
|
||||||
if !ok {
|
// If a base class is permanently unprojectable, the child classes
|
||||||
panic("Class " + c.ClassName + " inherits from unknown class " + inh)
|
// should be too
|
||||||
|
if !AllowVirtualForClass(cinfo.Class.ClassName) {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range cinfo.Class.Methods {
|
for _, m := range cinfo.Class.Methods {
|
||||||
@ -491,15 +493,9 @@ func (c *CppClass) AllInherits() []string {
|
|||||||
|
|
||||||
// FIXME prevent duplicates arising from diamond inheritance
|
// FIXME prevent duplicates arising from diamond inheritance
|
||||||
|
|
||||||
for _, baseClass := range c.DirectInherits {
|
for _, baseClassInfo := range c.DirectInheritClassInfo() {
|
||||||
|
|
||||||
ret = append(ret, baseClass)
|
ret = append(ret, baseClassInfo.Class.ClassName)
|
||||||
|
|
||||||
// And everything that class inherits - unless - we've seen it before
|
|
||||||
baseClassInfo, ok := KnownClassnames[baseClass]
|
|
||||||
if !ok {
|
|
||||||
panic("Class " + c.ClassName + " inherits from unknown class " + baseClass)
|
|
||||||
}
|
|
||||||
|
|
||||||
recurseInfo := baseClassInfo.Class.AllInherits()
|
recurseInfo := baseClassInfo.Class.AllInherits()
|
||||||
for _, childClass := range recurseInfo {
|
for _, childClass := range recurseInfo {
|
||||||
@ -510,6 +506,28 @@ func (c *CppClass) AllInherits() []string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DirectInheritClassInfo looks up the CppClass for each entry in DirectInherits.
|
||||||
|
func (c *CppClass) DirectInheritClassInfo() []lookupResultClass {
|
||||||
|
var ret []lookupResultClass
|
||||||
|
|
||||||
|
for _, inh := range c.DirectInherits { // AllInherits() {
|
||||||
|
cinfo, ok := KnownClassnames[inh]
|
||||||
|
if !ok {
|
||||||
|
if strings.HasPrefix(inh, `QList<`) {
|
||||||
|
// OK, allow this one to slip through
|
||||||
|
// e.g. QItemSelection extends a QList<>
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
panic("Class " + c.ClassName + " inherits from unknown class " + inh)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, cinfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
type CppTypedef struct {
|
type CppTypedef struct {
|
||||||
Alias string
|
Alias string
|
||||||
UnderlyingType CppParameter
|
UnderlyingType CppParameter
|
||||||
|
Loading…
Reference in New Issue
Block a user