mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings: variable pointer depth
This commit is contained in:
parent
cde78306c2
commit
4ca4c0dd9e
@ -707,6 +707,7 @@ func parseSingleTypeString(p string) CppParameter {
|
||||
|
||||
} else if tok == "*" {
|
||||
insert.Pointer = true
|
||||
insert.PointerCount++
|
||||
|
||||
} else if len(tok) > 4 && strings.HasSuffix(tok, "List") {
|
||||
// Classes ending in --List are usually better represented as a QList
|
||||
|
@ -81,3 +81,18 @@ func TestParseInnerListTypes(t *testing.T) {
|
||||
t.Errorf("expected QWidget, got %q", tok.ParameterType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPointerDepth(t *testing.T) {
|
||||
for _, testCase := range []string{`char**`, `char * *`} {
|
||||
l := parseSingleTypeString(testCase)
|
||||
if l.ParameterType != "char" {
|
||||
t.Error("expected char")
|
||||
}
|
||||
if !l.Pointer {
|
||||
t.Error("expected pointer")
|
||||
}
|
||||
if l.PointerCount != 2 {
|
||||
t.Errorf("expected pointerCount=2, got %d", l.PointerCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,12 @@ func (p CppParameter) RenderTypeCabi() string {
|
||||
}
|
||||
}
|
||||
|
||||
if p.Pointer || p.ByRef {
|
||||
if p.ByRef {
|
||||
ret += "*"
|
||||
}
|
||||
if p.Pointer {
|
||||
ret += strings.Repeat("*", p.PointerCount)
|
||||
}
|
||||
|
||||
return ret // ignore const
|
||||
}
|
||||
@ -91,7 +94,7 @@ func (p CppParameter) RenderTypeQtCpp() string {
|
||||
cppType = "const " + cppType
|
||||
}
|
||||
if p.Pointer {
|
||||
cppType += "*"
|
||||
cppType += strings.Repeat("*", p.PointerCount)
|
||||
}
|
||||
if p.ByRef {
|
||||
cppType += "&"
|
||||
|
@ -32,6 +32,7 @@ type CppParameter struct {
|
||||
TypeAlias string // If we rewrote QStringList->QList<String>, this field contains the original QStringList
|
||||
Const bool
|
||||
Pointer bool
|
||||
PointerCount int
|
||||
ByRef bool
|
||||
Optional bool
|
||||
}
|
||||
@ -52,6 +53,7 @@ func (p *CppParameter) CopyWithAlias(alias CppParameter) CppParameter {
|
||||
// WARNING: This can't work for double indirection
|
||||
ret.Const = ret.Const || alias.Const
|
||||
ret.Pointer = ret.Pointer || alias.Pointer
|
||||
ret.PointerCount += alias.PointerCount
|
||||
ret.ByRef = ret.ByRef || alias.ByRef
|
||||
return ret
|
||||
}
|
||||
@ -168,7 +170,9 @@ func IsArgcArgv(params []CppParameter, pos int) bool {
|
||||
params[pos].ParameterType == "int" &&
|
||||
params[pos].ByRef &&
|
||||
params[pos+1].ParameterName == "argv" &&
|
||||
params[pos+1].ParameterType == "char **")
|
||||
params[pos+1].ParameterType == "char") &&
|
||||
params[pos+1].Pointer &&
|
||||
params[pos+1].PointerCount == 2
|
||||
}
|
||||
|
||||
func IsReceiverMethod(params []CppParameter, pos int) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user