-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dc4d7f
commit a7d1140
Showing
8 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ast | ||
|
||
type StmtExpr struct { | ||
Addr Address | ||
Pos Position | ||
Type string | ||
ChildNodes []Node | ||
} | ||
|
||
func parseStmtExpr(line string) *StmtExpr { | ||
groups := groupsFromRegex( | ||
"<(?P<position>.*)> '(?P<type>.*)'", | ||
line, | ||
) | ||
|
||
return &StmtExpr{ | ||
Addr: ParseAddress(groups["address"]), | ||
Pos: NewPositionFromString(groups["position"]), | ||
Type: groups["type"], | ||
ChildNodes: []Node{}, | ||
} | ||
} | ||
|
||
// AddChild adds a new child node. Child nodes can then be accessed with the | ||
// Children attribute. | ||
func (n *StmtExpr) 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 *StmtExpr) 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 *StmtExpr) Children() []Node { | ||
return n.ChildNodes | ||
} | ||
|
||
// Position returns the position in the original source code. | ||
func (n *StmtExpr) Position() Position { | ||
return n.Pos | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ast | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestStmtExpr(t *testing.T) { | ||
nodes := map[string]Node{ | ||
`0x7ff4f9100d28 <col:11, col:18> 'int'`: &StmtExpr{ | ||
Addr: 0x7ff4f9100d28, | ||
Pos: NewPositionFromString("col:11, col:18"), | ||
Type: "int", | ||
ChildNodes: []Node{}, | ||
}, | ||
} | ||
|
||
runNodeTests(t, nodes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters