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-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 {
|
|
|
|
MethodName string
|
2024-08-08 05:51:10 +00:00
|
|
|
ReturnType CppParameter // Name not used
|
2024-08-07 06:56:14 +00:00
|
|
|
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`,
|
|
|
|
`>=`, `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
|
|
|
|
return strings.ToUpper(tmp[0:1]) + tmp[1:]
|
2024-08-07 06:51:51 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppClass struct {
|
|
|
|
ClassName string
|
|
|
|
Ctors []CppMethod // only use the parameters
|
|
|
|
Extends []string
|
|
|
|
Methods []CppMethod
|
|
|
|
Props []CppProperty
|
2024-08-06 01:03:23 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 06:56:14 +00:00
|
|
|
type CppParsedHeader struct {
|
|
|
|
Classes []CppClass
|
2024-08-06 01:03:23 +00:00
|
|
|
}
|