mirror of
https://github.com/mappu/miqt.git
synced 2025-01-03 14:18:37 +00:00
genbindings: include QList header in cpp but not in h
This commit is contained in:
parent
8ac598fbb5
commit
97b9e01451
@ -153,16 +153,23 @@ func emitParametersCABI2CppForwarding(params []CppParameter) (preamble string, f
|
|||||||
return preamble, strings.Join(tmp, ", ")
|
return preamble, strings.Join(tmp, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getReferencedTypes finds all referenced Qt types in this file.
|
||||||
func getReferencedTypes(src *CppParsedHeader) []string {
|
func getReferencedTypes(src *CppParsedHeader) []string {
|
||||||
// Find all referenced Qt types in this file
|
|
||||||
foundTypes := map[string]struct{}{}
|
foundTypes := map[string]struct{}{}
|
||||||
for _, c := range src.Classes {
|
for _, c := range src.Classes {
|
||||||
|
|
||||||
foundTypes[c.ClassName] = struct{}{}
|
foundTypes[c.ClassName] = struct{}{}
|
||||||
|
|
||||||
for _, ctor := range c.Ctors {
|
for _, ctor := range c.Ctors {
|
||||||
for _, p := range ctor.Parameters {
|
for _, p := range ctor.Parameters {
|
||||||
if p.QtClassType() {
|
if p.QtClassType() {
|
||||||
foundTypes[p.ParameterType] = struct{}{}
|
foundTypes[p.ParameterType] = struct{}{}
|
||||||
}
|
}
|
||||||
|
if t, ok := p.QListOf(); ok && t.QtClassType() {
|
||||||
|
foundTypes["QList"] = struct{}{}
|
||||||
|
foundTypes[t.ParameterType] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, m := range c.Methods {
|
for _, m := range c.Methods {
|
||||||
@ -170,12 +177,21 @@ func getReferencedTypes(src *CppParsedHeader) []string {
|
|||||||
if p.QtClassType() {
|
if p.QtClassType() {
|
||||||
foundTypes[p.ParameterType] = struct{}{}
|
foundTypes[p.ParameterType] = struct{}{}
|
||||||
}
|
}
|
||||||
|
if t, ok := p.QListOf(); ok && t.QtClassType() {
|
||||||
|
foundTypes["QList"] = struct{}{}
|
||||||
|
foundTypes[t.ParameterType] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if m.ReturnType.QtClassType() {
|
if m.ReturnType.QtClassType() {
|
||||||
foundTypes[m.ReturnType.ParameterType] = struct{}{}
|
foundTypes[m.ReturnType.ParameterType] = struct{}{}
|
||||||
}
|
}
|
||||||
|
if t, ok := m.ReturnType.QListOf(); ok && t.QtClassType() {
|
||||||
|
foundTypes["QList"] = struct{}{}
|
||||||
|
foundTypes[t.ParameterType] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foundTypesList := make([]string, 0, len(foundTypes))
|
foundTypesList := make([]string, 0, len(foundTypes))
|
||||||
for ft := range foundTypes {
|
for ft := range foundTypes {
|
||||||
if strings.HasPrefix(ft, "QList<") {
|
if strings.HasPrefix(ft, "QList<") {
|
||||||
@ -214,12 +230,18 @@ extern "C" {
|
|||||||
ret.WriteString("#ifdef __cplusplus\n")
|
ret.WriteString("#ifdef __cplusplus\n")
|
||||||
|
|
||||||
for _, ft := range foundTypesList {
|
for _, ft := range foundTypesList {
|
||||||
|
if ft == "QList" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ret.WriteString(`class ` + ft + ";\n")
|
ret.WriteString(`class ` + ft + ";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.WriteString("#else\n")
|
ret.WriteString("#else\n")
|
||||||
|
|
||||||
for _, ft := range foundTypesList {
|
for _, ft := range foundTypesList {
|
||||||
|
if ft == "QList" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ret.WriteString(`typedef struct ` + ft + " " + ft + ";\n")
|
ret.WriteString(`typedef struct ` + ft + " " + ft + ";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +284,9 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
for _, ref := range getReferencedTypes(src) {
|
for _, ref := range getReferencedTypes(src) {
|
||||||
|
if ref[0] != 'Q' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ret.WriteString(`#include <` + ref + ">\n")
|
ret.WriteString(`#include <` + ref + ">\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user