mirror of
https://github.com/mappu/miqt.git
synced 2025-02-02 03:20:25 +00:00
genbindings: improvements for deleted ctors/dtors/overloads
This commit is contained in:
parent
2e2b436a51
commit
1ea3f220e6
@ -146,6 +146,7 @@ func parseHeader(topLevel []interface{}) (*CppParsedHeader, error) {
|
|||||||
func processClassType(node map[string]interface{}, className string) (CppClass, error) {
|
func processClassType(node map[string]interface{}, className string) (CppClass, error) {
|
||||||
var ret CppClass
|
var ret CppClass
|
||||||
ret.ClassName = className
|
ret.ClassName = className
|
||||||
|
ret.CanDelete = true
|
||||||
|
|
||||||
inner, _ := node["inner"].([]interface{}) // Cannot fail, the parent call already checked that `inner` was present
|
inner, _ := node["inner"].([]interface{}) // Cannot fail, the parent call already checked that `inner` was present
|
||||||
|
|
||||||
@ -241,7 +242,7 @@ nextMethod:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is `= delete`
|
// Check if this is `= delete`
|
||||||
if explicitlyDeleted, ok := node["explicitlyDeleted"].(bool); ok && explicitlyDeleted {
|
if isExplicitlyDeleted(node) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +271,19 @@ nextMethod:
|
|||||||
case "CXXDestructorDecl":
|
case "CXXDestructorDecl":
|
||||||
// We don't need to expose destructors in the binding beyond offering
|
// We don't need to expose destructors in the binding beyond offering
|
||||||
// a regular delete function
|
// a regular delete function
|
||||||
|
// However if this destructor is private or deleted, we should
|
||||||
|
// not bind it
|
||||||
|
|
||||||
|
if !visibility {
|
||||||
|
ret.CanDelete = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is `= delete`
|
||||||
|
if isExplicitlyDeleted(node) {
|
||||||
|
ret.CanDelete = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
case "CXXMethodDecl":
|
case "CXXMethodDecl":
|
||||||
if !visibility {
|
if !visibility {
|
||||||
@ -277,7 +291,7 @@ nextMethod:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is `= delete`
|
// Check if this is `= delete`
|
||||||
if explicitlyDeleted, ok := node["explicitlyDeleted"].(bool); ok && explicitlyDeleted {
|
if isExplicitlyDeleted(node) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +348,20 @@ nextMethod:
|
|||||||
return ret, nil // done
|
return ret, nil // done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isExplicitlyDeleted checks if this node is marked `= delete`.
|
||||||
|
func isExplicitlyDeleted(node map[string]interface{}) bool {
|
||||||
|
|
||||||
|
if explicitlyDeleted, ok := node["explicitlyDeleted"].(bool); ok && explicitlyDeleted {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if explicitlyDefaulted, ok := node["explicitlyDefaulted"].(string); ok && explicitlyDefaulted == "deleted" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
var ErrTooComplex error = errors.New("Type declaration is too complex to parse")
|
var ErrTooComplex error = errors.New("Type declaration is too complex to parse")
|
||||||
|
|
||||||
func parseMethod(node map[string]interface{}, mm *CppMethod) error {
|
func parseMethod(node map[string]interface{}, mm *CppMethod) error {
|
||||||
|
@ -394,7 +394,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
if AllowDelete(c) {
|
if c.CanDelete {
|
||||||
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self);\n", c.ClassName, c.ClassName))
|
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self);\n", c.ClassName, c.ClassName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
if AllowDelete(c) {
|
if c.CanDelete {
|
||||||
ret.WriteString(fmt.Sprintf(
|
ret.WriteString(fmt.Sprintf(
|
||||||
"void %s_Delete(%s* self) {\n"+
|
"void %s_Delete(%s* self) {\n"+
|
||||||
"\tdelete self;\n"+
|
"\tdelete self;\n"+
|
||||||
|
@ -400,7 +400,7 @@ import "C"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if AllowDelete(c) {
|
if c.CanDelete {
|
||||||
ret.WriteString(`
|
ret.WriteString(`
|
||||||
func (this *` + c.ClassName + `) Delete() {
|
func (this *` + c.ClassName + `) Delete() {
|
||||||
C.` + c.ClassName + `_Delete(this.h)
|
C.` + c.ClassName + `_Delete(this.h)
|
||||||
|
@ -39,18 +39,6 @@ func AllowHeader(fullpath string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func AllowDelete(c CppClass) bool {
|
|
||||||
switch c.ClassName {
|
|
||||||
case "QClipboard",
|
|
||||||
"QSessionManager",
|
|
||||||
"QTextObject",
|
|
||||||
"QTextBlockGroup",
|
|
||||||
"QInputMethod":
|
|
||||||
return false // The destructor is marked private. TODO grab this from the AST
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ImportHeaderForClass(className string) bool {
|
func ImportHeaderForClass(className string) bool {
|
||||||
if className[0] != 'Q' {
|
if className[0] != 'Q' {
|
||||||
return false
|
return false
|
||||||
|
@ -169,6 +169,7 @@ type CppClass struct {
|
|||||||
Inherits []string // other class names
|
Inherits []string // other class names
|
||||||
Methods []CppMethod
|
Methods []CppMethod
|
||||||
Props []CppProperty
|
Props []CppProperty
|
||||||
|
CanDelete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CppTypedef struct {
|
type CppTypedef struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user