-
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.
ast,transpile: add support for ConstantExpr (#850)
- Loading branch information
Showing
6 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ast | ||
|
||
// ConstantExpr is a constant expression | ||
type ConstantExpr struct { | ||
Addr Address | ||
Pos Position | ||
Type string | ||
ChildNodes []Node | ||
} | ||
|
||
func parseConstantExpr(line string) *ConstantExpr { | ||
groups := groupsFromRegex( | ||
"<(?P<position>.*)> '(?P<type>.*?)'", | ||
line, | ||
) | ||
|
||
return &ConstantExpr{ | ||
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 *ConstantExpr) 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 *ConstantExpr) 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 *ConstantExpr) Children() []Node { | ||
return n.ChildNodes | ||
} | ||
|
||
// Position returns the position in the original source code. | ||
func (n *ConstantExpr) 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 TestConstantExpr(t *testing.T) { | ||
nodes := map[string]Node{ | ||
`0x5558ffde68f0 <col:34, col:55> 'unsigned long'`: &ConstantExpr{ | ||
Addr: 0x5558ffde68f0, | ||
Pos: NewPositionFromString("col:34, col:55"), | ||
Type: "unsigned long", | ||
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