Identify methods from interfaces and categories, determine their

parameter and return types.
This commit is contained in:
gmp
2019-04-09 23:19:49 -04:00
parent 6a9c5c2811
commit bcb4a0680d
10 changed files with 377 additions and 51 deletions
+4
View File
@@ -186,6 +186,8 @@ func Parse(fullline string) Node {
return parseNonNullAttr(line)
case "NotTailCalledAttr":
return parseNotTailCalledAttr(line)
case "ObjCCategoryDecl":
return parseObjCCategoryDecl(line)
case "ObjCInterface":
return parseObjCInterface(line)
case "ObjCInterfaceType":
@@ -206,6 +208,8 @@ func Parse(fullline string) Node {
return parseObjCObjectPointerType(line)
case "ObjCProtocol":
return parseObjCProtocol(line)
case "ObjCPropertyDecl":
return parseObjCPropertyDecl(line)
case "OffsetOfExpr":
return parseOffsetOfExpr(line)
case "PackedAttr":
+56
View File
@@ -0,0 +1,56 @@
package ast
import (
// "fmt"
"strings"
)
// ObjCCategoryDecl is node represents a category declaration.
type ObjCCategoryDecl struct {
Addr Address
Pos Position
Position2 string
Name string
ChildNodes []Node
}
func parseObjCCategoryDecl(line string) *ObjCCategoryDecl {
groups := groupsFromRegex(
`(?:prev (?P<prev>0x[0-9a-f]+) )?
<(?P<position><invalid sloc>|.*)>
(?P<position2> <invalid sloc>| col:\d+| line:\d+:\d+)
(?P<name> \w+)?`,
line,
)
return &ObjCCategoryDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
ChildNodes: []Node{},
}
}
// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *ObjCCategoryDecl) AddChild(node Node) {
n.ChildNodes = append(n.ChildNodes, node)
}
// Address returns the numeric address of the node. See the documentation for
// the Address type for more information.
func (n *ObjCCategoryDecl) Address() Address {
return n.Addr
}
// Children returns the child nodes. If this node does not have any children or
// this node does not support children it will always return an empty slice.
func (n *ObjCCategoryDecl) Children() []Node {
return n.ChildNodes
}
// Position returns the position in the original source code.
func (n *ObjCCategoryDecl) Position() Position {
return n.Pos
}
+3 -3
View File
@@ -3,19 +3,19 @@ package ast
// ObjCInterface is an Objective-C interface
type ObjCInterface struct {
Addr Address
Type string
Name string
ChildNodes []Node
}
func parseObjCInterface(line string) *ObjCInterface {
groups := groupsFromRegex(
"'(?P<type>.*)'",
"'(?P<name>.*)'",
line,
)
return &ObjCInterface{
Addr: ParseAddress(groups["address"]),
Type: groups["type"],
Name: groups["name"],
ChildNodes: []Node{},
}
}
+15 -7
View File
@@ -12,7 +12,9 @@ type ObjCMethodDecl struct {
Implicit bool
ClassMethod bool
Name string
Parameters []string
Type string
Type2 string
Attr string
ChildNodes []Node
}
@@ -25,13 +27,17 @@ func parseObjCMethodDecl(line string) *ObjCMethodDecl {
(?P<implicit> implicit)?
(?P<methodtype> \+| \-)
(?P<names>.*?)
(?P<type>'.*')
'(?P<type>[^']*?)'
(:'(?P<type2>.*?)')?
(?P<attr> .*)?`,
line,
)
/*
(?P<position2> <invalid sloc>| col:\d+| line:\d+:\d+)?
*/
names := strings.TrimSpace(groups["names"])
parts := strings.Split(strings.TrimSpace(groups["names"]),":")
params := []string{}
if names[len(names)-1] == ':' {
params = parts[:len(parts)-1]
}
return &ObjCMethodDecl{
Addr: ParseAddress(groups["address"]),
@@ -39,9 +45,11 @@ func parseObjCMethodDecl(line string) *ObjCMethodDecl {
Position2: strings.TrimSpace(groups["position2"]),
Implicit: len(groups["implicit"])>0,
ClassMethod: groups["methodtype"] == " +",
Name: groups["names"],
Type: groups["type"],
Attr: groups["attr"],
Name: parts[0],
Parameters: params,
Type: strings.TrimSpace(groups["type"]),
Type2: strings.TrimSpace(groups["type2"]),
Attr: strings.TrimSpace(groups["attr"]),
ChildNodes: []Node{},
}
}
+64
View File
@@ -0,0 +1,64 @@
package ast
import (
"strings"
)
// ObjCPropertyDecl is node represents an Objective-C property declaration
type ObjCPropertyDecl struct {
Addr Address
Pos Position
Position2 string
Name string
Type string
Type2 string
Attr string
ChildNodes []Node
}
func parseObjCPropertyDecl(line string) *ObjCPropertyDecl {
groups := groupsFromRegex(
`(?:prev (?P<prev>0x[0-9a-f]+) )?
<(?P<position>.*<scratch space>.*?|.*<built-in>.*?|.*<invalid sloc>|.*?)>
(?P<position2> <invalid sloc>| col:\d+| line:\d+:\d+)?
(?P<name>.*?)
'(?P<type>[^']*?)'
(:'(?P<type2>.*?)')?
(?P<attr> .*)?`,
line,
)
return &ObjCPropertyDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
Type: strings.TrimSpace(groups["type"]),
Type2: strings.TrimSpace(groups["type2"]),
Attr: strings.TrimSpace(groups["attr"]),
ChildNodes: []Node{},
}
}
// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *ObjCPropertyDecl) AddChild(node Node) {
n.ChildNodes = append(n.ChildNodes, node)
}
// Address returns the numeric address of the node. See the documentation for
// the Address type for more information.
func (n *ObjCPropertyDecl) Address() Address {
return n.Addr
}
// Children returns the child nodes. If this node does not have any children or
// this node does not support children it will always return an empty slice.
func (n *ObjCPropertyDecl) Children() []Node {
return n.ChildNodes
}
// Position returns the position in the original source code.
func (n *ObjCPropertyDecl) Position() Position {
return n.Pos
}
+5 -3
View File
@@ -3,19 +3,21 @@ package ast
// ObjCProtocol is an Objective-C protocol
type ObjCProtocol struct {
Addr Address
Type string
Name string
Content string
ChildNodes []Node
}
func parseObjCProtocol(line string) *ObjCProtocol {
groups := groupsFromRegex(
"'(?P<type>.*)'",
"'(?P<name>.*)'",
line,
)
return &ObjCProtocol{
Addr: ParseAddress(groups["address"]),
Type: groups["type"],
Name: groups["name"],
Content: groups["content"],
ChildNodes: []Node{},
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ func parseParmVarDecl(line string) *ParmVarDecl {
return &ParmVarDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Pos: NewPositionFromString(groups["position"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
Type: groups["type"],