Skip to content

Commit

Permalink
ast: support forward declarations of enums (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsmith authored Apr 16, 2020
1 parent 6854d8f commit b603e1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ast/enum_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// EnumDecl is node represents a enum declaration.
type EnumDecl struct {
Addr Address
Prev Address
Pos Position
Position2 string
Name string
Expand All @@ -15,12 +16,13 @@ type EnumDecl struct {

func parseEnumDecl(line string) *EnumDecl {
groups := groupsFromRegex(
`<(?P<position>.*)>(?P<position2> .+:\d+)?(?P<name>.*)`,
`(?:prev (?P<prev>0x[0-9a-f]+) )?<(?P<position>.*)>(?P<position2> .+:\d+)?(?P<name>.*)`,
line,
)

return &EnumDecl{
Addr: ParseAddress(groups["address"]),
Prev: ParseAddress(groups["prev"]),
Pos: NewPositionFromString(groups["position"]),
Position2: groups["position2"],
Name: strings.TrimSpace(groups["name"]),
Expand Down
8 changes: 8 additions & 0 deletions ast/enum_decl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func TestEnumDecl(t *testing.T) {
Name: "week",
ChildNodes: []Node{},
},
`0x5570ff477388 prev 0x5570ff445c40 <line:1030:1, line:1034:1> line:1030:6 cb_assign_type`: &EnumDecl{
Addr: 0x5570ff477388,
Prev: 0x5570ff445c40,
Pos: NewPositionFromString("line:1030:1, line:1034:1"),
Position2: " line:1030:6",
Name: "cb_assign_type",
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
Expand Down

0 comments on commit b603e1d

Please sign in to comment.