Skip to content

Commit

Permalink
Added AST node type NoAliasAttr. Fixes #769 (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamphaus authored and elliotchance committed Jun 21, 2018
1 parent f7afaef commit 525340c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
44 changes: 44 additions & 0 deletions ast/no_alias_attr.go
Original file line number Diff line number Diff line change
@@ -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<position>.*)>",
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
}
17 changes: 17 additions & 0 deletions ast/no_alias_attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ast

import (
"testing"
)

func TestNoAliasAttr(t *testing.T) {
nodes := map[string]Node{
`0x7fa3b88bbb38 <line:4:1, line:13:1>`: &NoAliasAttr{
Addr: 0x7fa3b88bbb38,
Pos: NewPositionFromString("line:4:1, line:13:1"),
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
}
2 changes: 2 additions & 0 deletions ast/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 525340c

Please sign in to comment.