Repository: Konstantin8105/c4go
Pull request #362 (2019-03-27 20:31:23)

post increment for selector expression

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

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

```diff
@@           Coverage Diff           @@
##           master     #362   +/-   ##
=======================================
  Coverage   85.85%   85.85%           
=======================================
  Files         186      186           
  Lines       10908    10908           
=======================================
  Hits         9365     9365           
  Misses       1104     1104           
  Partials      439      439
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/362?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/362/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `80.8% <100%> (ø)` | :arrow_up: |
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/362/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `74.59% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/362?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/362?src=pr&el=footer). Last update [d3fe450...a3e66f7](https://codecov.io/gh/Konstantin8105/c4go/pull/362?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

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

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

```diff
@@           Coverage Diff           @@
##           master     #362   +/-   ##
=======================================
  Coverage   85.85%   85.85%           
=======================================
  Files         186      186           
  Lines       10908    10908           
=======================================
  Hits         9365     9365           
  Misses       1104     1104           
  Partials      439      439
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/362?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/362/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `80.8% <100%> (ø)` | :arrow_up: |
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/362/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `74.59% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/362?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/362?src=pr&el=footer). Last update [d3fe450...a3e66f7](https://codecov.io/gh/Konstantin8105/c4go/pull/362?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 620ac51..3018044 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -463,7 +463,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 			return
 		}
 
-		if types.IsCPointer(v.Type, p) || types.IsCArray(v.Type, p) {
+		if types.IsPointer(v.Type, p) {
 			switch e := expr.(type) {
 			case *goast.IndexExpr:
 				if v.Operator == "++" {
@@ -507,7 +507,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 					return
 				}
 
-			case *goast.Ident:
+			case *goast.Ident, *goast.SelectorExpr:
 				if v.Operator == "++" {
 					// expr = 'p'
 					// example of snippet:
@@ -550,6 +550,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 				}
 
 			default:
+				// TODO add here
 				p.AddMessage(p.GenerateWarningMessage(
 					fmt.Errorf("transpilation pointer is not support: %T", e), v))
 			}
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 0b7d5c7..d1e0125 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -30,7 +30,7 @@ func transpileUnaryOperatorInc(n *ast.UnaryOperator, p *program.Program, operato
 
 	// for values
 	if v, ok := n.Children()[0].(*ast.DeclRefExpr); ok &&
-		!types.IsCArray(v.Type, p) && !types.IsCPointer(v.Type, p) {
+		!types.IsPointer(v.Type, p) {
 		switch n.Operator {
 		case "++":
 			return &goast.BinaryExpr{
@@ -58,7 +58,7 @@ func transpileUnaryOperatorInc(n *ast.UnaryOperator, p *program.Program, operato
 		return
 	}
 
-	if !types.IsCPointer(n.Type, p) && !types.IsCArray(n.Type, p) {
+	if !types.IsPointer(n.Type, p) {
 
 		binaryOperator := "+="
 		if operator == token.DEC {


Test patch:
diff --git a/tests/array.c b/tests/array.c
index 7e0bddb..a75e16c 100644
--- a/tests/array.c
+++ b/tests/array.c
@@ -714,9 +714,28 @@ void test_matrix_init()
 	}
 }
 
+struct someR{
+	unsigned long * ul;
+};
+
+void test_post_pointer()
+{
+	struct someR R;
+	unsigned long ull[6] = {2,4,8,10,12,34};
+	R.ul = ull;
+	struct someR * pR = &R;
+	for (int i=0;i <5;i++) {
+		printf("%d\n",(int)(*pR->ul));
+		is_eq(ull[i], *pR->ul);
+		if (i < 4) {
+			pR->ul++;
+		}
+	}
+}
+
 int main()
 {
-    plan(194);
+    plan(199);
 
     test_parg_struct();
     START_TEST(struct_init);
@@ -1255,6 +1274,7 @@ int main()
 	START_TEST(func_byte);
 	START_TEST(negative_index);
 	START_TEST(matrix_init);
+	START_TEST(post_pointer);
 
     done_testing();
 }