From a24a0dff64fac88cef6a4523c47ab83926d12d4d Mon Sep 17 00:00:00 2001 From: yulvil Date: Sun, 29 Oct 2017 15:40:28 -0700 Subject: [PATCH] ParmVarDecl could not match regexp. Fixes #280 (#284) --- ast/parm_var_decl.go | 35 +++++----- ast/parm_var_decl_test.go | 130 ++++++++++++++++++++++---------------- tests/array.c | 14 +++- 3 files changed, 106 insertions(+), 73 deletions(-) diff --git a/ast/parm_var_decl.go b/ast/parm_var_decl.go index 132a1f047..2095b49f0 100644 --- a/ast/parm_var_decl.go +++ b/ast/parm_var_decl.go @@ -5,14 +5,15 @@ 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 { @@ -20,6 +21,7 @@ func parseParmVarDecl(line string) *ParmVarDecl { `<(?P.*)> (?P [^ ]+:[\d:]+)? (?P used)? + (?P referenced)? (?P \w+)? '(?P.*?)' (?P:'.*?')?`, @@ -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{}, } } diff --git a/ast/parm_var_decl_test.go b/ast/parm_var_decl_test.go index 107e96e91..dc56ac895 100644 --- a/ast/parm_var_decl_test.go +++ b/ast/parm_var_decl_test.go @@ -7,74 +7,92 @@ import ( func TestParmVarDecl(t *testing.T) { nodes := map[string]Node{ `0x7f973380f000 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: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: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 <> 'FILE *'`: &ParmVarDecl{ - Addr: 0x7f9733817418, - Pos: NewPositionFromString(""), - Position2: "", - Type: "FILE *", - Name: "", - Type2: "", - IsUsed: false, - ChildNodes: []Node{}, + Addr: 0x7f9733817418, + Pos: NewPositionFromString(""), + Position2: "", + Type: "FILE *", + Name: "", + Type2: "", + IsUsed: false, + IsReferenced: false, + ChildNodes: []Node{}, }, `0x7f9733817c30 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 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: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: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{}, }, } diff --git a/tests/array.c b/tests/array.c index 149c5adb6..ac96d5b6c 100644 --- a/tests/array.c +++ b/tests/array.c @@ -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); @@ -81,6 +92,7 @@ int main() START_TEST(chararr_init); START_TEST(chararr_init2); START_TEST(exprarr); + START_TEST(argarr); done_testing(); }