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

Add support for NoDebugAttr #827

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func Parse(fullline string) Node {
return parseModeAttr(line)
case "NoAliasAttr":
return parseNoAliasAttr(line)
case "NoDebugAttr":
return parseNoDebugAttr(line)
case "NoInlineAttr":
return parseNoInlineAttr(line)
case "NoThrowAttr":
Expand Down
2 changes: 1 addition & 1 deletion ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPrint(t *testing.T) {
}

var lines = []string{
// c2go ast sqlite3.c | head -5000 | sed 's/^[ |`-]*//' | sed 's/<<<NULL>>>/NullStmt/g' | gawk 'length > 0 {print "`" $0 "`,"}'
// c2go ast sqlite3.c | head -5000 | sed 's/^[ |`-]*//' | sed 's/<<<NULL>>>/NullStmt/g' | gawk 'length > 0 {print "`" $0 "`,"}'
}

func BenchmarkParse(b *testing.B) {
Expand Down
45 changes: 45 additions & 0 deletions ast/no_debug_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ast

// NoDebugAttr is a type of attribute that is optionally attached to a variable
// or struct field definition.
type NoDebugAttr struct {
Addr Address
Pos Position
ChildNodes []Node
}

func parseNoDebugAttr(line string) *NoDebugAttr {
groups := groupsFromRegex(
`<(?P<position>.*)>`,
line,
)

return &NoDebugAttr{
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 *NoDebugAttr) 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 *NoDebugAttr) 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 *NoDebugAttr) Children() []Node {
return n.ChildNodes
}

// Position returns the position in the original source code.
func (n *NoDebugAttr) Position() Position {
return n.Pos
}
17 changes: 17 additions & 0 deletions ast/no_debug_attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ast

import (
"testing"
)

func TestNoDebugAttr(t *testing.T) {
nodes := map[string]Node{
`0x33b8788 <col:59>`: &NoDebugAttr{
Addr: 0x33b8788,
Pos: NewPositionFromString("col:59"),
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 @@ -337,6 +337,8 @@ func setPosition(node Node, position Position) {
n.Pos = position
case *NoAliasAttr:
n.Pos = position
case *NoDebugAttr:
n.Pos = position
case *NoInlineAttr:
n.Pos = position
case *NoThrowAttr:
Expand Down