Skip to content

Commit

Permalink
Support NRVO in VarDecl regex (#872)
Browse files Browse the repository at this point in the history
Fixes #802
  • Loading branch information
kroppt authored Jul 28, 2020
1 parent 72b29fc commit a1651b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ast/var_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type VarDecl struct {
Type2 string
IsExtern bool
IsUsed bool
IsNRVO bool
IsCInit bool
IsReferenced bool
IsStatic bool
Expand All @@ -34,6 +35,7 @@ func parseVarDecl(line string) *VarDecl {
(?P<type2>:'.*?')?
(?P<extern> extern)?
(?P<static> static)?
(?P<nrvo> nrvo)?
(?P<cinit> cinit)?
(?P<register> register)?
`,
Expand All @@ -55,6 +57,7 @@ func parseVarDecl(line string) *VarDecl {
Type2: type2,
IsExtern: len(groups["extern"]) > 0,
IsUsed: len(groups["used"]) > 0,
IsNRVO: len(groups["nrvo"]) > 0,
IsCInit: len(groups["cinit"]) > 0,
IsReferenced: len(groups["referenced"]) > 0,
IsStatic: len(groups["static"]) > 0,
Expand Down
26 changes: 26 additions & 0 deletions ast/var_decl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: false,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
Expand All @@ -31,6 +32,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: true,
IsUsed: false,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
Expand All @@ -47,6 +49,7 @@ func TestVarDecl(t *testing.T) {
Type2: "unsigned long",
IsExtern: false,
IsUsed: false,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
Expand All @@ -63,6 +66,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: true,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
Expand All @@ -79,6 +83,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: true,
IsNRVO: false,
IsCInit: true,
IsReferenced: false,
IsStatic: false,
Expand All @@ -95,6 +100,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: false,
IsNRVO: false,
IsCInit: false,
IsReferenced: true,
IsStatic: false,
Expand All @@ -111,6 +117,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: true,
IsNRVO: false,
IsCInit: true,
IsReferenced: false,
IsStatic: true,
Expand All @@ -127,6 +134,7 @@ func TestVarDecl(t *testing.T) {
Type2: "",
IsExtern: false,
IsUsed: true,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
Expand All @@ -143,6 +151,7 @@ func TestVarDecl(t *testing.T) {
Type2: "extCoord",
IsExtern: false,
IsUsed: true,
IsNRVO: false,
IsCInit: true,
IsReferenced: false,
IsStatic: false,
Expand All @@ -159,13 +168,30 @@ func TestVarDecl(t *testing.T) {
Type2: "struct cmark_mem",
IsExtern: true,
IsUsed: true,
IsNRVO: false,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
IsRegister: false,
Parent: 0x7f985e0246d0,
ChildNodes: []Node{},
},
`0x55d681e87428 <col:5, col:23> col:23 used variable 'union programming':'union programming' nrvo`: &VarDecl{
Addr: 0x55d681e87428,
Pos: NewPositionFromString("col:5, col:23"),
Position2: "col:23",
Name: "variable",
Type: "union programming",
Type2: "union programming",
IsExtern: false,
IsUsed: true,
IsNRVO: true,
IsCInit: false,
IsReferenced: false,
IsStatic: false,
IsRegister: false,
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
Expand Down

0 comments on commit a1651b9

Please sign in to comment.