-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f7700c8
commit 89c9ff2
Showing
4 changed files
with
64 additions
and
1 deletion.
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,43 @@ | ||
package ast | ||
|
||
// AttributedType is an attribute type | ||
type AttributedType struct { | ||
Addr Address | ||
Type string | ||
Sugar bool | ||
ChildNodes []Node | ||
} | ||
|
||
func parseAttributedType(line string) *AttributedType { | ||
groups := groupsFromRegex(`'(?P<type>.*?)' sugar`, line) | ||
|
||
return &AttributedType{ | ||
Addr: ParseAddress(groups["address"]), | ||
Type: groups["type"], | ||
Sugar: true, | ||
ChildNodes: []Node{}, | ||
} | ||
} | ||
|
||
// AddChild adds a new child node. Child nodes can then be accessed with the | ||
// Children attribute. | ||
func (n *AttributedType) 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 *AttributedType) 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 *AttributedType) Children() []Node { | ||
return n.ChildNodes | ||
} | ||
|
||
// Position returns the position in the original source code. | ||
func (n *AttributedType) Position() Position { | ||
return Position{} | ||
} |
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 TestAttributedType(t *testing.T) { | ||
nodes := map[string]Node{ | ||
`0x2b6c359e30 'int (void) __attribute__((cdecl))' sugar`: &AttributedType{ | ||
Addr: 0x2b6c359e30, | ||
Type: "int (void) __attribute__((cdecl))", | ||
Sugar: true, | ||
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