Repository: elliotchance/c2go (go)

Issue:
can't convert open62541.c
Hello, 
I am trying to transpile [open62541.c](https://github.com/open62541/open62541/releases/download/0.3-rc2/open62541.c) on MacOs.

I am geting following exceptions

Any chance todo it or it is too difficult for now?
Thank You

c2go transpile open62541.c
panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) (?:prev (?P<prev>0x[0-9a-f]+) )?(?:parent (?P<parent>0x[0-9a-f]+) )?<(?P<position>.*)>(?P<position2> .+:\d+)?(?P<used> used)?(?P<referenced> referenced)?(?P<name> \w+)? '(?P<type>.+?)'(?P<type2>:'.*?')?(?P<extern> extern)?(?P<static> static)?(?P<cinit> cinit)?(?P<register> register)?[\s]*$
0x7feb6d06b2e8 <col:5, col:21> col:21 used result 'UA_BrowseResult':'UA_BrowseResult' nrvo


goroutine 23 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc00739d900, 0x13b, 0xc005f61300, 0x5a, 0xc005f612ca)
	/Users/ee/go/src/github.com/elliotchance/c2go/ast/ast.go:286 +0x379
github.com/elliotchance/c2go/ast.parseVarDecl(0xc005f61300, 0x5a, 0x1295a6b)
	/Users/ee/go/src/github.com/elliotchance/c2go/ast/var_decl.go:26 +0x65
github.com/elliotchance/c2go/ast.Parse(0xc005f612f8, 0x62, 0x1294a14, 0x5)
	/Users/ee/go/src/github.com/elliotchance/c2go/ast/ast.go:252 +0x46c
main.convertLinesToNodes(0xc001507b60, 0x392c, 0x15708, 0x0, 0x0, 0x0)
	/Users/ee/go/src/github.com/elliotchance/c2go/main.go:89 +0x1cf
main.convertLinesToNodesParallel.func1.1(0xc0007f60c0, 0xc00000c008, 0xc001507b60, 0x392c, 0x15708, 0x0)
	/Users/ee/go/src/github.com/elliotchance/c2go/main.go:113 +0x59
created by main.convertLinesToNodesParallel.func1
	/Users/ee/go/src/github.com/elliotchance/c2go/main.go:111 +0x112

Pull request:
Support NRVO in VarDecl regex
Fixes #802

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/elliotchance/c2go/872)
<!-- Reviewable:end -->


Patch:
diff --git a/ast/var_decl.go b/ast/var_decl.go
index 29ec13b..9414521 100644
--- a/ast/var_decl.go
+++ b/ast/var_decl.go
@@ -15,6 +15,7 @@ type VarDecl struct {
 	Type2        string
 	IsExtern     bool
 	IsUsed       bool
+	IsNRVO       bool
 	IsCInit      bool
 	IsReferenced bool
 	IsStatic     bool
@@ -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)?
 		`,
@@ -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,


Test patch:
diff --git a/ast/var_decl_test.go b/ast/var_decl_test.go
index 8d81114..a8e43ad 100644
--- a/ast/var_decl_test.go
+++ b/ast/var_decl_test.go
@@ -15,6 +15,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       false,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -31,6 +32,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     true,
 			IsUsed:       false,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -47,6 +49,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "unsigned long",
 			IsExtern:     false,
 			IsUsed:       false,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -63,6 +66,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -79,6 +83,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      true,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -95,6 +100,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       false,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: true,
 			IsStatic:     false,
@@ -111,6 +117,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      true,
 			IsReferenced: false,
 			IsStatic:     true,
@@ -127,6 +134,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "",
 			IsExtern:     false,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -143,6 +151,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "extCoord",
 			IsExtern:     false,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      true,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -159,6 +168,7 @@ func TestVarDecl(t *testing.T) {
 			Type2:        "struct cmark_mem",
 			IsExtern:     true,
 			IsUsed:       true,
+			IsNRVO:       false,
 			IsCInit:      false,
 			IsReferenced: false,
 			IsStatic:     false,
@@ -166,6 +176,22 @@ func TestVarDecl(t *testing.T) {
 			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)