miqt/cmd/genbindings/intermediate.go

112 lines
2.5 KiB
Go
Raw Normal View History

2024-08-06 01:03:23 +00:00
package main
import (
"strings"
)
type CppParameter struct {
ParameterName string
ParameterType string
Const bool
Pointer bool
ByRef bool
Optional bool
}
2024-08-08 07:06:14 +00:00
func (p CppParameter) QtClassType() bool {
return p.ParameterType[0] == 'Q'
}
2024-08-11 04:37:18 +00:00
func (p CppParameter) QListOf() (CppParameter, bool) {
if strings.HasPrefix(p.ParameterType, "QList<") && strings.HasSuffix(p.ParameterType, `>`) {
return parseSingleTypeString(p.ParameterType[6 : len(p.ParameterType)-1]), true
}
return CppParameter{}, false
}
func (p CppParameter) IntType() bool {
switch p.ParameterType {
case "int", "unsigned int", "uint",
"short", "unsigned short", "ushort", "qint16", "quint16",
"qint8", "quint8",
// "char", "uchar", // Don't count char or char* as integer types that need cast assertions
"long", "unsigned long", "ulong", "qint32", "quint32",
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
"double", "float", "qreal":
return true
default:
return false
}
}
type CppProperty struct {
PropertyName string
PropertyType string
Visibility string
2024-08-06 01:03:23 +00:00
}
type CppMethod struct {
MethodName string
OverrideMethodName string // Present only if we changed the target
ReturnType CppParameter // Name not used
Parameters []CppParameter
2024-08-06 01:03:23 +00:00
}
func (nm CppMethod) SafeMethodName() string {
// Operator-overload methods have names not representable in binding
// languages. Replace more specific cases first
replacer := strings.NewReplacer(
`==`, `Equal`,
`!=`, `NotEqual`,
`>=`, `GreaterOrEqual`,
`<=`, `LesserOrEqual`,
`=`, `Assign`,
`>`, `Greater`,
`<`, `Lesser`,
`+`, `Plus`,
`-`, `Minus`,
`*`, `Multiply`,
`/`, `Divide`,
`%`, `Modulo`,
`&&`, `LogicalAnd`,
`||`, `LogicalOr`,
`!`, `Not`,
`&`, `BitwiseAnd`,
`|`, `BitwiseOr`,
`~`, `BitwiseXor`,
`^`, `BitwiseNot`,
`->`, `PointerDereference`,
`[]`, `Subscript`,
`()`, `Call`,
)
tmp := replacer.Replace(nm.MethodName)
// Also make the first letter uppercase so it becomes public in Go
return strings.ToUpper(tmp[0:1]) + tmp[1:]
}
type CppClass struct {
ClassName string
2024-08-10 00:53:26 +00:00
Abstract bool
Ctors []CppMethod // only use the parameters
2024-08-10 00:54:26 +00:00
Inherits []string // other class names
Methods []CppMethod
Props []CppProperty
2024-08-06 01:03:23 +00:00
}
type CppTypedef struct {
Name string
Typedef string
}
type CppParsedHeader struct {
Typedefs []CppTypedef
Classes []CppClass
2024-08-06 01:03:23 +00:00
}