forked from elliotchance/c2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
member_expr.go
60 lines (52 loc) · 1.14 KB
/
member_expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ast
type MemberExpr struct {
Address string
Position string
Type string
Lvalue bool
Name string
Address2 string
Children []Node
}
func parseMemberExpr(line string) *MemberExpr {
groups := groupsFromRegex(
`<(?P<position>.*)>
'(?P<type>.*?)'
(?P<tags>.*?)
(?P<name>\w+)
(?P<address2>[0-9a-fx]+)`,
line,
)
return &MemberExpr{
Address: groups["address"],
Position: groups["position"],
Type: groups["type"],
Lvalue: true,
Name: groups["name"],
Address2: groups["address2"],
Children: []Node{},
}
}
// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *MemberExpr) AddChild(node Node) {
n.Children = append(n.Children, node)
}
// GetDeclRefExpr gets DeclRefExpr from MemberExpr, or nil if there is no DeclRefExpr
func (n *MemberExpr) GetDeclRefExpr() *DeclRefExpr {
for _, child := range n.Children {
res, ok := child.(*DeclRefExpr)
if ok {
return res
}
cast, ok := child.(*ImplicitCastExpr)
if ok {
res, ok = cast.Children[0].(*DeclRefExpr)
if ok {
return res
}
}
}
// There is no DeclRefExpr
return nil
}