2016-12-11 23:03:06 +03:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2017-01-07 00:45:13 +03:00
|
|
|
"sort"
|
2016-12-11 23:03:06 +03:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/therecipe/qt/internal/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
SIGNAL = "signal"
|
|
|
|
SLOT = "slot"
|
|
|
|
|
|
|
|
IMPURE = "impure"
|
|
|
|
PURE = "pure"
|
|
|
|
|
|
|
|
PLAIN = "plain"
|
|
|
|
CONSTRUCTOR = "constructor"
|
|
|
|
COPY_CONSTRUCTOR = "copy-constructor"
|
|
|
|
MOVE_CONSTRUCTOR = "move-constructor"
|
|
|
|
DESTRUCTOR = "destructor"
|
|
|
|
|
|
|
|
CONNECT = "Connect"
|
|
|
|
DISCONNECT = "Disconnect"
|
|
|
|
CALLBACK = "callback"
|
|
|
|
|
|
|
|
GETTER = "getter"
|
|
|
|
SETTER = "setter"
|
|
|
|
|
|
|
|
VOID = "void"
|
|
|
|
|
|
|
|
TILDE = "~"
|
2017-01-02 19:01:18 +03:00
|
|
|
|
|
|
|
MOC = "moc"
|
2016-12-11 23:03:06 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func IsPackedList(v string) bool {
|
|
|
|
return (strings.HasPrefix(v, "QList<") ||
|
|
|
|
strings.HasPrefix(v, "QVector<") ||
|
|
|
|
strings.HasPrefix(v, "QStack<") ||
|
|
|
|
strings.HasPrefix(v, "QQueue<")) &&
|
|
|
|
|
|
|
|
strings.Count(v, "<") == 1 &&
|
|
|
|
!strings.Contains(v, ":") &&
|
2017-01-02 19:01:18 +03:00
|
|
|
State.ClassMap[UnpackedList(v)] != nil
|
2016-12-11 23:03:06 +03:00
|
|
|
}
|
|
|
|
|
2016-12-23 23:35:16 +03:00
|
|
|
func CleanValue(v string) string {
|
|
|
|
for _, b := range []string{"*", "const", "&", "&", ";"} {
|
|
|
|
v = strings.Replace(v, b, "", -1)
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CleanName(name, value string) string {
|
|
|
|
switch name {
|
|
|
|
case
|
|
|
|
"type",
|
|
|
|
"func",
|
|
|
|
"range",
|
|
|
|
"string",
|
|
|
|
"int",
|
|
|
|
"map",
|
|
|
|
"const",
|
|
|
|
"interface",
|
|
|
|
"select",
|
|
|
|
"strings",
|
|
|
|
"new",
|
|
|
|
"signal",
|
|
|
|
"ptr",
|
|
|
|
"register":
|
|
|
|
{
|
|
|
|
return name[:len(name)-2]
|
|
|
|
}
|
|
|
|
|
|
|
|
case "":
|
|
|
|
{
|
|
|
|
return fmt.Sprintf("v%v", strings.Replace(strings.ToLower(CleanValue(value)[:2]), ".", "", -1))
|
2016-12-11 23:03:06 +03:00
|
|
|
}
|
|
|
|
}
|
2016-12-23 23:35:16 +03:00
|
|
|
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnpackedList(v string) string {
|
2016-12-11 23:03:06 +03:00
|
|
|
return CleanValue(strings.Split(strings.Split(v, "<")[1], ">")[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
var LibDeps = map[string][]string{
|
|
|
|
"Core": {"Widgets", "Gui"}, //Widgets, Gui
|
|
|
|
"AndroidExtras": {"Core"},
|
|
|
|
"Gui": {"Widgets", "Core"}, //Widgets
|
|
|
|
"Network": {"Core"},
|
|
|
|
"Xml": {"XmlPatterns", "Core"}, //XmlPatterns
|
|
|
|
"DBus": {"Core"},
|
|
|
|
"Nfc": {"Core"},
|
|
|
|
"Script": {"Core"},
|
|
|
|
"Sensors": {"Core"},
|
|
|
|
"Positioning": {"Core"},
|
|
|
|
"Widgets": {"Gui", "Core"},
|
|
|
|
"Sql": {"Widgets", "Gui", "Core"}, //Widgets, Gui
|
|
|
|
"MacExtras": {"Gui", "Core"},
|
|
|
|
"Qml": {"Network", "Core"},
|
|
|
|
"WebSockets": {"Network", "Core"},
|
|
|
|
"XmlPatterns": {"Network", "Core"},
|
|
|
|
"Bluetooth": {"Core"},
|
|
|
|
"WebChannel": {"Network", "Qml", "Core"}, //Network (needed for static linking ios)
|
|
|
|
"Svg": {"Widgets", "Gui", "Core"},
|
|
|
|
"Multimedia": {"MultimediaWidgets", "Widgets", "Network", "Gui", "Core"}, //MultimediaWidgets, Widgets
|
|
|
|
"Quick": {"QuickWidgets", "Widgets", "Network", "Qml", "Gui", "Core"}, //QuickWidgets, Widgets, Network (needed for static linking ios)
|
|
|
|
"Help": {"Sql", "CLucene", "Network", "Widgets", "Gui", "Core"}, //Sql + CLucene + Network (needed for static linking ios)
|
|
|
|
"Location": {"Positioning", "Quick", "Gui", "Core"},
|
|
|
|
"ScriptTools": {"Script", "Widgets", "Core"}, //Script, Widgets
|
|
|
|
"UiTools": {"Widgets", "Gui", "Core"},
|
|
|
|
"X11Extras": {"Gui", "Core"},
|
|
|
|
"WinExtras": {"Gui", "Core"},
|
|
|
|
"WebEngine": {"Widgets", "WebEngineWidgets", "WebChannel", "Network", "WebEngineCore", "Quick", "Gui", "Qml", "Core"}, //Widgets, WebEngineWidgets, WebChannel, Network
|
|
|
|
"TestLib": {"Widgets", "Gui", "Core"}, //Widgets, Gui
|
|
|
|
"SerialPort": {"Core"},
|
|
|
|
"SerialBus": {"Core"},
|
|
|
|
"PrintSupport": {"Widgets", "Gui", "Core"},
|
|
|
|
//"PlatformHeaders": []string{}, //TODO: uncomment
|
|
|
|
"Designer": {"UiPlugin", "Widgets", "Gui", "Xml", "Core"},
|
|
|
|
"Scxml": {"Network", "Qml", "Core"}, //Network (needed for static linking ios)
|
|
|
|
"Gamepad": {"Gui", "Core"},
|
|
|
|
|
2016-12-17 03:18:44 +03:00
|
|
|
"Purchasing": {"Core"},
|
|
|
|
"DataVisualization": {"Gui", "Core"},
|
|
|
|
"Charts": {"Widgets", "Gui", "Core"},
|
2017-01-02 19:01:18 +03:00
|
|
|
//"Quick2DRenderer": {}, //TODO: uncomment
|
2016-12-11 23:03:06 +03:00
|
|
|
|
|
|
|
"Sailfish": {"Core"},
|
|
|
|
|
|
|
|
MOC: make([]string, 0),
|
|
|
|
"build_ios": {"Core", "Gui", "Network", "Sql", "Xml", "DBus", "Nfc", "Script", "Sensors", "Positioning", "Widgets", "Qml", "WebSockets", "XmlPatterns", "Bluetooth", "WebChannel", "Svg", "Multimedia", "Quick", "Help", "Location", "ScriptTools", "MultimediaWidgets", "UiTools", "PrintSupport"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var Libs = []string{
|
|
|
|
"Core",
|
|
|
|
"AndroidExtras",
|
|
|
|
"Gui",
|
|
|
|
"Network",
|
|
|
|
"Xml",
|
|
|
|
"DBus",
|
|
|
|
"Nfc",
|
|
|
|
"Script", //depreached (planned) in 5.6
|
|
|
|
"Sensors",
|
|
|
|
"Positioning",
|
|
|
|
"Widgets",
|
|
|
|
"Sql",
|
|
|
|
"MacExtras",
|
|
|
|
"Qml",
|
|
|
|
"WebSockets",
|
|
|
|
"XmlPatterns",
|
|
|
|
"Bluetooth",
|
|
|
|
"WebChannel",
|
|
|
|
"Svg",
|
|
|
|
"Multimedia",
|
|
|
|
"Quick",
|
|
|
|
"Help",
|
|
|
|
"Location",
|
|
|
|
"ScriptTools", //depreached (planned) in 5.6
|
|
|
|
"UiTools",
|
|
|
|
"X11Extras",
|
|
|
|
"WinExtras",
|
|
|
|
"WebEngine",
|
|
|
|
"TestLib",
|
|
|
|
"SerialPort",
|
|
|
|
"SerialBus",
|
|
|
|
"PrintSupport",
|
|
|
|
//"PlatformHeaders", //missing imports/guards
|
|
|
|
"Designer",
|
|
|
|
"Scxml",
|
|
|
|
"Gamepad",
|
|
|
|
|
2016-12-17 03:18:44 +03:00
|
|
|
"Purchasing", //GPLv3 & LGPLv3
|
|
|
|
"DataVisualization", //GPLv3
|
|
|
|
"Charts", //GPLv3
|
2016-12-11 23:03:06 +03:00
|
|
|
//"Quick2DRenderer", //GPLv3
|
|
|
|
|
|
|
|
"Sailfish",
|
|
|
|
}
|
|
|
|
|
2017-01-02 19:01:18 +03:00
|
|
|
func ShouldBuild(module string) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
func GetLibs() []string {
|
|
|
|
for i := len(Libs) - 1; i >= 0; i-- {
|
|
|
|
switch {
|
|
|
|
case
|
|
|
|
!(runtime.GOOS == "darwin" || runtime.GOOS == "linux") && Libs[i] == "WebEngine",
|
|
|
|
runtime.GOOS != "windows" && Libs[i] == "WinExtras",
|
|
|
|
runtime.GOOS != "darwin" && Libs[i] == "MacExtras",
|
|
|
|
runtime.GOOS != "linux" && Libs[i] == "X11Extras":
|
|
|
|
{
|
|
|
|
Libs = append(Libs[:i], Libs[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Libs
|
|
|
|
}
|
|
|
|
|
|
|
|
func Dump() {
|
2017-01-02 19:01:18 +03:00
|
|
|
for _, c := range State.ClassMap {
|
2016-12-11 23:03:06 +03:00
|
|
|
var bb = new(bytes.Buffer)
|
|
|
|
defer bb.Reset()
|
|
|
|
|
|
|
|
fmt.Fprint(bb, "funcs\n\n")
|
|
|
|
for _, f := range c.Functions {
|
|
|
|
fmt.Fprintln(bb, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprint(bb, "\n\nenums\n\n")
|
|
|
|
for _, e := range c.Enums {
|
|
|
|
fmt.Fprintln(bb, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.MkdirAll(utils.GoQtPkgPath("internal", "binding", "dump", c.Module))
|
|
|
|
utils.SaveBytes(utils.GoQtPkgPath("internal", "binding", "dump", c.Module, fmt.Sprintf("%v.txt", c.Name)), bb.Bytes())
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 00:45:13 +03:00
|
|
|
|
2017-01-07 02:55:15 +03:00
|
|
|
func SortedClassNamesForModule(module string, template bool) []string {
|
2017-01-07 00:45:13 +03:00
|
|
|
var output = make([]string, 0)
|
|
|
|
for _, class := range State.ClassMap {
|
|
|
|
if class.Module == module {
|
|
|
|
output = append(output, class.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Stable(sort.StringSlice(output))
|
|
|
|
|
2017-01-07 02:55:15 +03:00
|
|
|
if State.Moc && template {
|
2017-01-07 00:45:13 +03:00
|
|
|
var items = make(map[string]string)
|
|
|
|
|
|
|
|
for _, cn := range output {
|
|
|
|
if class, exist := State.ClassMap[cn]; exist {
|
|
|
|
items[cn] = class.Bases
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmpOutput = make([]string, 0)
|
|
|
|
|
|
|
|
for len(items) > 0 {
|
|
|
|
for item, dep := range items {
|
|
|
|
|
|
|
|
var c, exist = State.ClassMap[dep]
|
|
|
|
if exist && c.Module != MOC {
|
|
|
|
tmpOutput = append(tmpOutput, item)
|
|
|
|
delete(items, item)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, key := range tmpOutput {
|
|
|
|
if key == dep {
|
|
|
|
tmpOutput = append(tmpOutput, item)
|
|
|
|
delete(items, item)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output = tmpOutput
|
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2017-01-07 02:55:15 +03:00
|
|
|
func SortedClassesForModule(module string, template bool) []*Class {
|
2017-01-07 00:45:13 +03:00
|
|
|
var (
|
2017-01-07 02:55:15 +03:00
|
|
|
classNames = SortedClassNamesForModule(module, template)
|
2017-01-07 00:45:13 +03:00
|
|
|
output = make([]*Class, len(classNames))
|
|
|
|
)
|
|
|
|
for i, name := range classNames {
|
|
|
|
output[i] = State.ClassMap[name]
|
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|