2024-08-06 01:03:23 +00:00
|
|
|
package main
|
|
|
|
|
2024-08-07 06:51:51 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppParameter struct {
|
|
|
|
ParameterName string
|
2024-08-08 05:51:10 +00:00
|
|
|
ParameterType string
|
|
|
|
Const bool
|
|
|
|
Pointer bool
|
|
|
|
ByRef bool
|
2024-08-08 06:55:22 +00:00
|
|
|
Optional bool
|
2024-08-08 05:51:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-08-14 06:33:47 +00:00
|
|
|
func (p CppParameter) IntType() bool {
|
|
|
|
switch p.ParameterType {
|
2024-08-15 07:49:05 +00:00
|
|
|
case "int", "unsigned int", "uint",
|
|
|
|
"short", "unsigned short", "ushort", "qint16", "quint16",
|
|
|
|
"qint8", "quint8",
|
2024-08-14 06:33:47 +00:00
|
|
|
// "char", "uchar", // Don't count char or char* as integer types that need cast assertions
|
2024-08-15 07:49:05 +00:00
|
|
|
"long", "unsigned long", "ulong", "qint32", "quint32",
|
|
|
|
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
|
2024-08-14 06:33:47 +00:00
|
|
|
"double", "float", "qreal":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppProperty struct {
|
|
|
|
PropertyName string
|
|
|
|
PropertyType string
|
|
|
|
Visibility string
|
2024-08-06 01:03:23 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppMethod struct {
|
2024-08-09 23:45:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
func (nm CppMethod) SafeMethodName() string {
|
2024-08-07 06:51:51 +00:00
|
|
|
// Operator-overload methods have names not representable in binding
|
|
|
|
// languages. Replace more specific cases first
|
|
|
|
replacer := strings.NewReplacer(
|
|
|
|
|
|
|
|
`==`, `Equal`,
|
2024-08-14 06:26:51 +00:00
|
|
|
`!=`, `NotEqual`,
|
2024-08-07 06:51:51 +00:00
|
|
|
`>=`, `GreaterOrEqual`,
|
|
|
|
`<=`, `LesserOrEqual`,
|
|
|
|
`=`, `Assign`,
|
|
|
|
`>`, `Greater`,
|
|
|
|
`<`, `Lesser`,
|
|
|
|
|
|
|
|
`+`, `Plus`,
|
|
|
|
`-`, `Minus`,
|
|
|
|
`*`, `Multiply`,
|
|
|
|
`/`, `Divide`,
|
|
|
|
`%`, `Modulo`,
|
|
|
|
|
|
|
|
`&&`, `LogicalAnd`,
|
|
|
|
`||`, `LogicalOr`,
|
|
|
|
`!`, `Not`,
|
|
|
|
`&`, `BitwiseAnd`,
|
|
|
|
`|`, `BitwiseOr`,
|
|
|
|
`~`, `BitwiseXor`,
|
|
|
|
`^`, `BitwiseNot`,
|
|
|
|
|
|
|
|
`->`, `PointerDereference`,
|
|
|
|
`[]`, `Subscript`,
|
|
|
|
`()`, `Call`,
|
|
|
|
)
|
|
|
|
|
2024-08-08 05:51:46 +00:00
|
|
|
tmp := replacer.Replace(nm.MethodName)
|
|
|
|
|
|
|
|
// Also make the first letter uppercase so it becomes public in Go
|
2024-08-15 07:50:50 +00:00
|
|
|
return titleCase(tmp)
|
2024-08-07 06:51:51 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppClass struct {
|
|
|
|
ClassName string
|
2024-08-10 00:53:26 +00:00
|
|
|
Abstract bool
|
2024-08-07 06:56:14 +00:00
|
|
|
Ctors []CppMethod // only use the parameters
|
2024-08-10 00:54:26 +00:00
|
|
|
Inherits []string // other class names
|
2024-08-07 06:56:14 +00:00
|
|
|
Methods []CppMethod
|
|
|
|
Props []CppProperty
|
2024-08-06 01:03:23 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 06:26:42 +00:00
|
|
|
type CppTypedef struct {
|
|
|
|
Name string
|
|
|
|
Typedef string
|
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppParsedHeader struct {
|
2024-08-14 06:26:42 +00:00
|
|
|
Typedefs []CppTypedef
|
|
|
|
Classes []CppClass
|
2024-08-06 01:03:23 +00:00
|
|
|
}
|