Implement new type system. Working wrapper for simple Objective-C
interfaces.
This commit is contained in:
@@ -14,6 +14,17 @@ func dbg(f string, xs ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Node) HasFunc() bool {
|
||||
if n == nil {
|
||||
return false
|
||||
}
|
||||
for _,c := range n.Children {
|
||||
if c.Kind == "Function" || c.HasFunc() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Parse(s string) (*Node, error) {
|
||||
s2, n := TypeName(s,NewNode("AST"))
|
||||
@@ -83,6 +94,11 @@ func (n *Node) PointsTo() *Node {
|
||||
return n.stripAbstract("Pointer")
|
||||
}
|
||||
|
||||
//IsPointer returns true if the node is a pointer
|
||||
func (n *Node) IsPointer() bool {
|
||||
return n.PointsTo != nil
|
||||
}
|
||||
|
||||
//ArrayOf, when called on an array node returns a node describing the type
|
||||
//of the elements of the array. Otherwise returns nil when called on
|
||||
//non-array types.
|
||||
@@ -91,3 +107,26 @@ func (n *Node) ArrayOf() *Node {
|
||||
return n.stripAbstract("Array")
|
||||
}
|
||||
|
||||
//IsArray returns true if the node is an array
|
||||
func (n *Node) IsArray() bool {
|
||||
return n.ArrayOf() != nil
|
||||
}
|
||||
|
||||
func (n *Node) IsStruct() bool {
|
||||
if n == nil || len(n.Children) < 1 {
|
||||
return false
|
||||
}
|
||||
return n.Children[0].Kind == "Struct"
|
||||
}
|
||||
|
||||
//BaseType strips off all layers of pointer indirection
|
||||
func (n *Node) BaseType() *Node {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
if n2 := n.PointsTo(); n2 == nil {
|
||||
return n
|
||||
} else {
|
||||
return n2.BaseType()
|
||||
}
|
||||
}
|
||||
|
||||
+16
-3
@@ -67,8 +67,21 @@ func (n *Node) AddChild(c *Node) *Node {
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *Node) CtypeSimplified() string {
|
||||
ignore := map[string]bool{
|
||||
"NullableAnnotation": true,
|
||||
"TypeQualifier": true,
|
||||
"GenericList": true,
|
||||
}
|
||||
return n._Ctype(ignore)
|
||||
}
|
||||
|
||||
func (n *Node) Ctype() string {
|
||||
if n == nil {
|
||||
return n._Ctype(map[string]bool{})
|
||||
}
|
||||
|
||||
func (n *Node) _Ctype(ignore map[string]bool) string {
|
||||
if n == nil || ignore[n.Kind] {
|
||||
return ""
|
||||
}
|
||||
var ret strings.Builder
|
||||
@@ -76,8 +89,8 @@ func (n *Node) Ctype() string {
|
||||
if n == nil { return []string{} }
|
||||
ret := []string{}
|
||||
for _,c := range n.Children {
|
||||
if x := c.Ctype(); x != "" {
|
||||
ret = append(ret, c.Ctype())
|
||||
if x := c._Ctype(ignore); x != "" {
|
||||
ret = append(ret, x)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user