2016-05-21 23:50:57 +03:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Variable struct {
|
2016-12-11 23:03:06 +03:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Fullname string `xml:"fullname,attr"`
|
|
|
|
Href string `xml:"href,attr"`
|
|
|
|
Status string `xml:"status,attr"`
|
|
|
|
Access string `xml:"access,attr"`
|
|
|
|
Filepath string `xml:"filepath,attr"`
|
|
|
|
Static bool `xml:"static,attr"`
|
|
|
|
Output string `xml:"type,attr"`
|
|
|
|
Brief string `xml:"brief,attr"`
|
|
|
|
Getter []struct{} `xml:"getter"`
|
|
|
|
Setter []struct{} `xml:"setter"`
|
2017-06-12 20:52:01 +03:00
|
|
|
|
|
|
|
IsMocSynthetic bool
|
2017-06-14 17:12:17 +03:00
|
|
|
PureGoType string
|
2018-04-07 22:05:41 +03:00
|
|
|
Connect int
|
|
|
|
ConnectGet bool
|
|
|
|
ConnectSet bool
|
|
|
|
ConnectChanged bool
|
|
|
|
Target string
|
|
|
|
Inbound bool
|
2016-05-21 23:50:57 +03:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
func (v *Variable) Class() (*Class, bool) {
|
2017-02-15 19:48:35 +03:00
|
|
|
var class, ok = State.ClassMap[v.ClassName()]
|
|
|
|
return class, ok
|
2016-12-11 23:03:06 +03:00
|
|
|
}
|
2017-01-02 19:01:18 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
func (v *Variable) ClassName() string {
|
2016-12-01 20:35:01 +03:00
|
|
|
var s = strings.Split(v.Fullname, "::")
|
|
|
|
if len(s) == 3 {
|
|
|
|
return s[1]
|
|
|
|
}
|
|
|
|
return s[0]
|
|
|
|
}
|
2016-05-21 23:50:57 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
func (v *Variable) varToFunc() []*Function {
|
|
|
|
var funcs = make([]*Function, 0)
|
|
|
|
|
2017-02-15 19:48:35 +03:00
|
|
|
var class, ok = v.Class()
|
|
|
|
if !ok || class.HasFunctionWithName(v.Name) {
|
2016-12-11 23:03:06 +03:00
|
|
|
return funcs
|
2016-05-21 23:50:57 +03:00
|
|
|
}
|
2016-12-11 23:03:06 +03:00
|
|
|
|
|
|
|
funcs = append(funcs, &Function{
|
|
|
|
Name: v.Name,
|
|
|
|
Fullname: v.Fullname,
|
|
|
|
Href: v.Href,
|
|
|
|
Status: v.Status,
|
|
|
|
Access: v.Access,
|
|
|
|
Filepath: v.Filepath,
|
|
|
|
Static: v.Static,
|
|
|
|
Output: v.Output,
|
|
|
|
Meta: GETTER,
|
|
|
|
Brief: v.Brief,
|
|
|
|
})
|
|
|
|
|
|
|
|
if strings.Contains(v.Output, "const") {
|
|
|
|
return funcs
|
|
|
|
}
|
|
|
|
|
|
|
|
funcs = append(funcs, &Function{
|
2016-05-21 23:50:57 +03:00
|
|
|
Name: fmt.Sprintf("set%v", strings.Title(v.Name)),
|
2016-12-11 23:03:06 +03:00
|
|
|
Fullname: fmt.Sprintf("%v::set%v", v.ClassName(), strings.Title(v.Name)),
|
2016-05-21 23:50:57 +03:00
|
|
|
Href: v.Href,
|
|
|
|
Status: v.Status,
|
|
|
|
Access: v.Access,
|
|
|
|
Filepath: v.Filepath,
|
|
|
|
Static: v.Static,
|
|
|
|
Output: "void",
|
2016-12-11 23:03:06 +03:00
|
|
|
Meta: SETTER,
|
2016-10-22 01:50:26 +03:00
|
|
|
Parameters: []*Parameter{{Value: v.Output}},
|
2016-05-21 23:50:57 +03:00
|
|
|
TmpName: v.Name,
|
2016-11-01 21:52:59 +03:00
|
|
|
Brief: v.Brief,
|
2016-12-11 23:03:06 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
return funcs
|
2016-05-21 23:50:57 +03:00
|
|
|
}
|
2016-11-01 21:52:59 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
func (v *Variable) propToFunc(c *Class) []*Function {
|
|
|
|
var funcs = make([]*Function, 0)
|
2016-11-01 21:52:59 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
if len(v.Getter) != 0 {
|
2016-11-01 21:52:59 +03:00
|
|
|
return funcs
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
if !(c.HasFunctionWithName(v.Name) ||
|
|
|
|
c.HasFunctionWithName(fmt.Sprintf("is%v", strings.Title(v.Name))) ||
|
|
|
|
c.HasFunctionWithName(fmt.Sprintf("has%v", strings.Title(v.Name)))) {
|
|
|
|
|
2017-06-10 22:37:03 +03:00
|
|
|
tmpF := &Function{
|
2017-06-12 20:52:01 +03:00
|
|
|
Name: v.Name,
|
|
|
|
Fullname: v.Fullname,
|
|
|
|
Href: v.Href,
|
|
|
|
Status: v.Status,
|
|
|
|
Access: v.Access,
|
|
|
|
Filepath: v.Filepath,
|
|
|
|
Static: v.Static,
|
|
|
|
Output: v.Output,
|
2017-06-14 17:12:17 +03:00
|
|
|
Meta: PLAIN,
|
|
|
|
Virtual: func() string {
|
2017-06-12 20:52:01 +03:00
|
|
|
if c.Module == MOC && !v.IsMocSynthetic {
|
2017-06-14 17:12:17 +03:00
|
|
|
return IMPURE
|
2017-06-12 20:52:01 +03:00
|
|
|
}
|
2017-06-14 17:12:17 +03:00
|
|
|
return ""
|
2017-06-12 20:52:01 +03:00
|
|
|
}(),
|
2017-06-10 22:37:03 +03:00
|
|
|
Signature: "()",
|
|
|
|
IsMocFunction: c.Module == MOC,
|
2017-06-12 20:52:01 +03:00
|
|
|
IsMocProperty: c.Module == MOC,
|
2016-12-11 23:03:06 +03:00
|
|
|
}
|
2016-11-01 21:52:59 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
if tmpF.Output == "bool" {
|
2017-06-21 18:32:20 +03:00
|
|
|
if !strings.HasPrefix(strings.ToLower(v.Name), "is") {
|
|
|
|
tmpF.Name = fmt.Sprintf("is%v", strings.Title(tmpF.Name))
|
|
|
|
}
|
2016-12-11 23:03:06 +03:00
|
|
|
tmpF.Fullname = fmt.Sprintf("%v::%v", tmpF.ClassName(), tmpF.Name)
|
2016-11-01 21:52:59 +03:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
funcs = append(funcs, tmpF)
|
2016-11-01 21:52:59 +03:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
if len(v.Setter) != 0 || c.HasFunctionWithName(fmt.Sprintf("set%v", strings.Title(v.Name))) {
|
|
|
|
return funcs
|
|
|
|
}
|
2016-11-01 21:52:59 +03:00
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
funcs = append(funcs, &Function{
|
2017-06-12 20:52:01 +03:00
|
|
|
Name: fmt.Sprintf("set%v", strings.Title(v.Name)),
|
|
|
|
Fullname: fmt.Sprintf("%v::set%v", v.ClassName(), strings.Title(v.Name)),
|
|
|
|
Href: v.Href,
|
|
|
|
Status: v.Status,
|
|
|
|
Access: v.Access,
|
|
|
|
Filepath: v.Filepath,
|
|
|
|
Static: v.Static,
|
|
|
|
Output: "void",
|
2017-06-14 17:12:17 +03:00
|
|
|
Meta: PLAIN,
|
|
|
|
Virtual: func() string {
|
2017-06-12 20:52:01 +03:00
|
|
|
if c.Module == MOC && !v.IsMocSynthetic {
|
2017-06-14 17:12:17 +03:00
|
|
|
return IMPURE
|
2017-06-12 20:52:01 +03:00
|
|
|
}
|
2017-06-14 17:12:17 +03:00
|
|
|
return ""
|
2017-06-12 20:52:01 +03:00
|
|
|
}(),
|
2017-06-10 22:37:03 +03:00
|
|
|
Parameters: []*Parameter{{Name: v.Name, Value: v.Output}},
|
|
|
|
Signature: "()",
|
|
|
|
IsMocFunction: c.Module == MOC,
|
2017-06-12 20:52:01 +03:00
|
|
|
IsMocProperty: c.Module == MOC,
|
2016-12-11 23:03:06 +03:00
|
|
|
})
|
2016-11-01 21:52:59 +03:00
|
|
|
|
2017-01-18 21:28:40 +03:00
|
|
|
if c.Module == MOC {
|
2017-01-13 22:14:08 +03:00
|
|
|
funcs = append(funcs, &Function{
|
2017-06-10 22:37:03 +03:00
|
|
|
Name: fmt.Sprintf("%vChanged", v.Name),
|
|
|
|
Fullname: fmt.Sprintf("%v::%vChanged", v.ClassName(), v.Name),
|
|
|
|
Status: v.Status,
|
|
|
|
Access: v.Access,
|
|
|
|
Output: "void",
|
|
|
|
Meta: SIGNAL,
|
|
|
|
Parameters: []*Parameter{{Name: v.Name, Value: v.Output}},
|
|
|
|
Signature: "()",
|
|
|
|
IsMocFunction: true,
|
2017-01-13 22:14:08 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
//add all overloaded property functions from base classes
|
2017-01-13 22:14:08 +03:00
|
|
|
//TODO: move rest into seperate function, as this func is called multiple times
|
2016-12-11 23:03:06 +03:00
|
|
|
|
|
|
|
for _, bc := range c.GetAllBases() {
|
2017-02-15 19:48:35 +03:00
|
|
|
var bclass, ok = State.ClassMap[bc]
|
|
|
|
if !ok {
|
2016-12-11 23:03:06 +03:00
|
|
|
continue
|
2016-11-01 21:52:59 +03:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:03:06 +03:00
|
|
|
for _, bcf := range bclass.Functions {
|
|
|
|
if bcf.Name != fmt.Sprintf("set%v", strings.Title(v.Name)) || !bcf.Overload {
|
|
|
|
continue
|
2016-11-01 21:52:59 +03:00
|
|
|
}
|
2016-12-11 23:03:06 +03:00
|
|
|
|
|
|
|
var tmpF = *bcf
|
|
|
|
|
|
|
|
tmpF.Name = fmt.Sprintf("set%v", strings.Title(v.Name))
|
|
|
|
tmpF.Fullname = fmt.Sprintf("%v::%v", v.ClassName(), tmpF.Name)
|
|
|
|
|
|
|
|
funcs = append(funcs, &tmpF)
|
2016-11-01 21:52:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return funcs
|
|
|
|
}
|