Skip to content

Commit

Permalink
ParmVarDecl could not match regexp. Fixes #280 (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
yulvil authored and Elliot Chance committed Oct 29, 2017
1 parent 92b71d5 commit a24a0df
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 73 deletions.
35 changes: 19 additions & 16 deletions ast/parm_var_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import (
)

type ParmVarDecl struct {
Addr Address
Pos Position
Position2 string
Name string
Type string
Type2 string
IsUsed bool
ChildNodes []Node
Addr Address
Pos Position
Position2 string
Name string
Type string
Type2 string
IsUsed bool
IsReferenced bool
ChildNodes []Node
}

func parseParmVarDecl(line string) *ParmVarDecl {
groups := groupsFromRegex(
`<(?P<position>.*)>
(?P<position2> [^ ]+:[\d:]+)?
(?P<used> used)?
(?P<referenced> referenced)?
(?P<name> \w+)?
'(?P<type>.*?)'
(?P<type2>:'.*?')?`,
Expand All @@ -37,14 +39,15 @@ func parseParmVarDecl(line string) *ParmVarDecl {
}

return &ParmVarDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
Type: groups["type"],
Type2: type2,
IsUsed: len(groups["used"]) > 0,
ChildNodes: []Node{},
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
Type: groups["type"],
Type2: type2,
IsUsed: len(groups["used"]) > 0,
IsReferenced: len(groups["referenced"]) > 0,
ChildNodes: []Node{},
}
}

Expand Down
130 changes: 74 additions & 56 deletions ast/parm_var_decl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,92 @@ import (
func TestParmVarDecl(t *testing.T) {
nodes := map[string]Node{
`0x7f973380f000 <col:14> col:17 'int'`: &ParmVarDecl{
Addr: 0x7f973380f000,
Pos: NewPositionFromString("col:14"),
Position2: "col:17",
Type: "int",
Name: "",
Type2: "",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f973380f000,
Pos: NewPositionFromString("col:14"),
Position2: "col:17",
Type: "int",
Name: "",
Type2: "",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f973380f070 <col:19, col:30> col:31 'const char *'`: &ParmVarDecl{
Addr: 0x7f973380f070,
Pos: NewPositionFromString("col:19, col:30"),
Position2: "col:31",
Type: "const char *",
Name: "",
Type2: "",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f973380f070,
Pos: NewPositionFromString("col:19, col:30"),
Position2: "col:31",
Type: "const char *",
Name: "",
Type2: "",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f9733816e50 <col:13, col:37> col:37 __filename 'const char *__restrict'`: &ParmVarDecl{
Addr: 0x7f9733816e50,
Pos: NewPositionFromString("col:13, col:37"),
Position2: "col:37",
Type: "const char *__restrict",
Name: "__filename",
Type2: "",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f9733816e50,
Pos: NewPositionFromString("col:13, col:37"),
Position2: "col:37",
Type: "const char *__restrict",
Name: "__filename",
Type2: "",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f9733817418 <<invalid sloc>> <invalid sloc> 'FILE *'`: &ParmVarDecl{
Addr: 0x7f9733817418,
Pos: NewPositionFromString("<invalid sloc>"),
Position2: "<invalid sloc>",
Type: "FILE *",
Name: "",
Type2: "",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f9733817418,
Pos: NewPositionFromString("<invalid sloc>"),
Position2: "<invalid sloc>",
Type: "FILE *",
Name: "",
Type2: "",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f9733817c30 <col:40, col:47> col:47 __size 'size_t':'unsigned long'`: &ParmVarDecl{
Addr: 0x7f9733817c30,
Pos: NewPositionFromString("col:40, col:47"),
Position2: "col:47",
Type: "size_t",
Name: "__size",
Type2: "unsigned long",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f9733817c30,
Pos: NewPositionFromString("col:40, col:47"),
Position2: "col:47",
Type: "size_t",
Name: "__size",
Type2: "unsigned long",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f973382fa10 <line:476:18, col:25> col:34 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &ParmVarDecl{
Addr: 0x7f973382fa10,
Pos: NewPositionFromString("line:476:18, col:25"),
Position2: "col:34",
Type: "int (* _Nullable)(void *, char *, int)",
Name: "",
Type2: "int (*)(void *, char *, int)",
IsUsed: false,
ChildNodes: []Node{},
Addr: 0x7f973382fa10,
Pos: NewPositionFromString("line:476:18, col:25"),
Position2: "col:34",
Type: "int (* _Nullable)(void *, char *, int)",
Name: "",
Type2: "int (*)(void *, char *, int)",
IsUsed: false,
IsReferenced: false,
ChildNodes: []Node{},
},
`0x7f97338355b8 <col:10, col:14> col:14 used argc 'int'`: &ParmVarDecl{
Addr: 0x7f97338355b8,
Pos: NewPositionFromString("col:10, col:14"),
Position2: "col:14",
Type: "int",
Name: "argc",
Type2: "",
IsUsed: true,
ChildNodes: []Node{},
Addr: 0x7f97338355b8,
Pos: NewPositionFromString("col:10, col:14"),
Position2: "col:14",
Type: "int",
Name: "argc",
Type2: "",
IsUsed: true,
IsReferenced: false,
ChildNodes: []Node{},
},
`ParmVarDecl 0x1d82850 <col:11, col:22> col:16 referenced foo 'char *':'char *'`: &ParmVarDecl{
Addr: 0x1d82850,
Pos: NewPositionFromString("col:11, col:22"),
Position2: "col:16",
Type: "char *",
Name: "foo",
Type2: "char *",
IsUsed: false,
IsReferenced: true,
ChildNodes: []Node{},
},
}

Expand Down
14 changes: 13 additions & 1 deletion tests/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,20 @@ void test_exprarr()
is_eq(a[3], 3);
}

long dummy(char foo[42])
{
return sizeof(foo);
}

void test_argarr()
{
char abc[1];
is_eq(8, dummy(abc));
}

int main()
{
plan(21);
plan(22);

START_TEST(intarr);
START_TEST(doublearr);
Expand All @@ -81,6 +92,7 @@ int main()
START_TEST(chararr_init);
START_TEST(chararr_init2);
START_TEST(exprarr);
START_TEST(argarr);

done_testing();
}

0 comments on commit a24a0df

Please sign in to comment.