diff --git a/ast/ast.go b/ast/ast.go index bc98e1d01..d28ea7e2c 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -172,6 +172,8 @@ func Parse(fullline string) Node { return parseMemberExpr(line) case "ModeAttr": return parseModeAttr(line) + case "NoAliasAttr": + return parseNoAliasAttr(line) case "NoInlineAttr": return parseNoInlineAttr(line) case "NoThrowAttr": diff --git a/ast/no_alias_attr.go b/ast/no_alias_attr.go new file mode 100644 index 000000000..bf442a9a8 --- /dev/null +++ b/ast/no_alias_attr.go @@ -0,0 +1,44 @@ +package ast + +// NoAliasAttr is a type of attribute that is optionally attached to a function declaration. +type NoAliasAttr struct { + Addr Address + Pos Position + ChildNodes []Node +} + +func parseNoAliasAttr(line string) *NoAliasAttr { + groups := groupsFromRegex( + "<(?P.*)>", + line, + ) + + return &NoAliasAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *NoAliasAttr) 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 *NoAliasAttr) 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 *NoAliasAttr) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *NoAliasAttr) Position() Position { + return n.Pos +} diff --git a/ast/no_alias_attr_test.go b/ast/no_alias_attr_test.go new file mode 100644 index 000000000..6d431878f --- /dev/null +++ b/ast/no_alias_attr_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestNoAliasAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb38 `: &NoAliasAttr{ + Addr: 0x7fa3b88bbb38, + Pos: NewPositionFromString("line:4:1, line:13:1"), + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/position.go b/ast/position.go index e0ff44c17..931f58bc2 100644 --- a/ast/position.go +++ b/ast/position.go @@ -335,6 +335,8 @@ func setPosition(node Node, position Position) { n.Pos = position case *ModeAttr: n.Pos = position + case *NoAliasAttr: + n.Pos = position case *NoInlineAttr: n.Pos = position case *NoThrowAttr: