Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with tree finding when the underlying slice needs to be resized. #2150

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions runtime/Go/antlr/trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,28 @@ func TreesfindAllRuleNodes(t ParseTree, ruleIndex int) []ParseTree {

func TreesfindAllNodes(t ParseTree, index int, findTokens bool) []ParseTree {
nodes := make([]ParseTree, 0)
TreesFindAllNodes(t, index, findTokens, nodes)
treesFindAllNodes(t, index, findTokens, &nodes)
return nodes
}

func TreesFindAllNodes(t ParseTree, index int, findTokens bool, nodes []ParseTree) {
func treesFindAllNodes(t ParseTree, index int, findTokens bool, nodes *[]ParseTree) {
// check this node (the root) first

t2, ok := t.(TerminalNode)
t3, ok2 := t.(ParserRuleContext)

if findTokens && ok {
if t2.GetSymbol().GetTokenType() == index {
nodes = append(nodes, t2)
*nodes = append(*nodes, t2)
}
} else if !findTokens && ok2 {
if t3.GetRuleIndex() == index {
nodes = append(nodes, t3)
*nodes = append(*nodes, t3)
}
}
// check children
for i := 0; i < t.GetChildCount(); i++ {
TreesFindAllNodes(t.GetChild(i).(ParseTree), index, findTokens, nodes)
treesFindAllNodes(t.GetChild(i).(ParseTree), index, findTokens, nodes)
}
}

Expand Down