Repository: Konstantin8105/c4go
Pull request #281 (2019-02-24 21:10:46)

operation += for char**

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=h1) Report
> Merging [#281](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/b7f41f02dcdce592b75da587e214227195b56670?src=pr&el=desc) will **increase** coverage by `0.05%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/281/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #281      +/-   ##
==========================================
+ Coverage   86.89%   86.94%   +0.05%     
==========================================
  Files         180      180              
  Lines        9840     9850      +10     
==========================================
+ Hits         8550     8564      +14     
+ Misses        891      887       -4     
  Partials      399      399
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/281/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `79.84% <100%> (+0.32%)` | :arrow_up: |
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/281/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `78.63% <0%> (+1.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=footer). Last update [b7f41f0...6936427](https://codecov.io/gh/Konstantin8105/c4go/pull/281?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/transpiler/operators.go b/transpiler/operators.go
index 58c3ec8..ee33d52 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -355,7 +355,8 @@ func transpileCompoundAssignOperator(
 	if types.IsPointer(n.Type) &&
 		(operator == token.ADD_ASSIGN || operator == token.SUB_ASSIGN) {
 		operator = convertToWithoutAssign(operator)
-		v, vType, newPre, newPost, err := pointerArithmetic(p, left, leftType, right, rightType, operator)
+		v, vType, newPre, newPost, err := pointerArithmetic(
+			p, left, leftType, right, rightType, operator)
 		if err != nil {
 			return nil, "", nil, nil, err
 		}
@@ -368,10 +369,23 @@ func transpileCompoundAssignOperator(
 		if err != nil {
 			return nil, "", nil, nil, err
 		}
-		v = &goast.BinaryExpr{
-			X:  goast.NewIdent(name),
-			Op: token.ASSIGN,
-			Y:  v,
+		found := false
+		if sl, ok := v.(*goast.SliceExpr); ok {
+			if ind, ok := sl.X.(*goast.IndexExpr); ok {
+				v = &goast.BinaryExpr{
+					X:  ind,
+					Op: token.ASSIGN,
+					Y:  v,
+				}
+				found = true
+			}
+		}
+		if !found {
+			v = &goast.BinaryExpr{
+				X:  goast.NewIdent(name),
+				Op: token.ASSIGN,
+				Y:  v,
+			}
 		}
 		return v, vType, preStmts, postStmts, nil
 	}
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 57aa4b1..9d24103 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -30,9 +30,9 @@ func transpileUnaryOperatorInc(n *ast.UnaryOperator, p *program.Program, operato
 
 	if types.IsPointer(n.Type) {
 		switch operator {
-		case token.INC:
+		case token.INC: // ++
 			operator = token.ADD
-		case token.DEC:
+		case token.DEC: // --
 			operator = token.SUB
 		}
 		// remove paren - ()
@@ -77,10 +77,24 @@ func transpileUnaryOperatorInc(n *ast.UnaryOperator, p *program.Program, operato
 		if err != nil {
 			return
 		}
-		expr = &goast.BinaryExpr{
-			X:  goast.NewIdent(name),
-			Op: token.ASSIGN,
-			Y:  expr,
+
+		found := false
+		if sl, ok := expr.(*goast.SliceExpr); ok {
+			if ind, ok := sl.X.(*goast.IndexExpr); ok {
+				expr = &goast.BinaryExpr{
+					X:  ind,
+					Op: token.ASSIGN,
+					Y:  expr,
+				}
+				found = true
+			}
+		}
+		if !found {
+			expr = &goast.BinaryExpr{
+				X:  goast.NewIdent(name),
+				Op: token.ASSIGN,
+				Y:  expr,
+			}
 		}
 		return
 	}


Test patch:
diff --git a/tests/array.c b/tests/array.c
index 9374a77..6f61f3a 100644
--- a/tests/array.c
+++ b/tests/array.c
@@ -401,7 +401,7 @@ void test_parg_struct()
 
 int main()
 {
-    plan(167);
+    plan(169);
 
     test_parg_struct();
     START_TEST(struct_init);
@@ -883,6 +883,22 @@ int main()
         is_not_null(t.w);
         (void)(t);
     }
+	{
+		diag("[][]char += 1");
+		char w1[]= "hello";
+		char w2[]= "world";
+		char w3[]= "people";
+		char *p1 = w1;
+		char *p2 = w2;
+		char *p3 = w3;
+		char *pa[3] = {p1,p2,p3};
+		char **pnt = pa;
+		char **pnt2 = pa;
+		*pnt += 1;
+		is_streq(*pnt, "ello");
+		(*pnt2)++;
+		is_streq(*pnt2,"llo");
+	}
 
     done_testing();
 }
diff --git a/tests/tests.h b/tests/tests.h
index 655ba85..a6e5cf2 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -187,8 +187,10 @@ static int last_test_was_ok = 1;
     }                                                              \
     else                                                           \
     {                                                              \
-        fail("%s (%d b) == %s (%d b) # got \"%s\"", #actual,       \
-            strlen(#actual), #expected, strlen(#expected), actual) \
+        fail("%s (%d b) == %s (%d b) # got \"%s\"",                \
+		#actual, strlen(#actual),                                  \
+        #expected, strlen(#expected),                              \
+		actual)                                                    \
     }
 
 // Compare two C wchars