Repository: Konstantin8105/c4go
Pull request #276 (2019-02-22 08:43:24)

atomicOperation for ternary and call function

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/276?src=pr&el=h1) Report
> Merging [#276](https://codecov.io/gh/Konstantin8105/c4go/pull/276?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/320587d9548f80c878ed4c5249fcb54ecafca1d6?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `78.57%`.

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

```diff
@@            Coverage Diff             @@
##           master     #276      +/-   ##
==========================================
- Coverage   86.82%   86.81%   -0.02%     
==========================================
  Files         180      180              
  Lines        9772     9781       +9     
==========================================
+ Hits         8485     8491       +6     
- Misses        890      892       +2     
- Partials      397      398       +1
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/276?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/276/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `75.98% <100%> (ø)` | :arrow_up: |
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/276/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `77.53% <100%> (+0.12%)` | :arrow_up: |
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/276/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `79.2% <70%> (-0.25%)` | :arrow_down: |
| [transpiler/declarations.go](https://codecov.io/gh/Konstantin8105/c4go/pull/276/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9kZWNsYXJhdGlvbnMuZ28=) | `73.72% <0%> (-0.47%)` | :arrow_down: |
| [types/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/276/diff?src=pr&el=tree#diff-dHlwZXMvY2FzdC5nbw==) | `72.49% <0%> (+0.74%)` | :arrow_up: |

------

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


Patch:
diff --git a/transpiler/call.go b/transpiler/call.go
index 4c9c3c8..dff585e 100644
--- a/transpiler/call.go
+++ b/transpiler/call.go
@@ -416,6 +416,7 @@ func transpileCallExpr(n *ast.CallExpr, p *program.Program) (
 			// to:
 			// call(val = 43,val);
 			var b ast.BinaryOperator
+			b.Type = bin.Type
 			b.Operator = ","
 			b.AddChild(arg)
 			b.AddChild(bin.Children()[0])
@@ -428,12 +429,13 @@ func transpileCallExpr(n *ast.CallExpr, p *program.Program) (
 			// to:
 			// call(val += 43,val);
 			var b ast.BinaryOperator
+			b.Type = cmp.Type
 			b.Operator = ","
 			b.AddChild(arg)
 			b.AddChild(cmp.Children()[0])
 			arg = &b
 		}
-		e, eType, newPre, newPost, err := transpileToExpr(arg, p, false)
+		e, eType, newPre, newPost, err := atomicOperation(arg, p)
 		if err != nil {
 			err = fmt.Errorf("argument position is %d. %v", i, err)
 			p.AddMessage(p.GenerateWarningMessage(err, arg))
diff --git a/transpiler/operators.go b/transpiler/operators.go
index ff1c92d..58c3ec8 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -42,7 +42,7 @@ func transpileConditionalOperator(n *ast.ConditionalOperator, p *program.Program
 	}()
 
 	// a - condition
-	a, aType, newPre, newPost, err := transpileToExpr(n.Children()[0], p, false)
+	a, aType, newPre, newPost, err := atomicOperation(n.Children()[0], p)
 	if err != nil {
 		return
 	}
@@ -200,7 +200,11 @@ func transpileParenExpr(n *ast.ParenExpr, p *program.Program) (
 		exprType = n.Type
 	}
 
-	r = &goast.ParenExpr{X: expr}
+	var ok bool
+	r, ok = expr.(*goast.ParenExpr)
+	if !ok {
+		r = &goast.ParenExpr{X: expr}
+	}
 
 	return
 }
@@ -777,7 +781,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 
 	case *ast.ParenExpr:
 		// ParenExpr 0x3c42468 <col:18, col:40> 'int'
-		return atomicOperation(v.Children()[0], p)
+		return
 
 	case *ast.ImplicitCastExpr:
 		if _, ok := v.Children()[0].(*ast.MemberExpr); ok {
@@ -875,6 +879,11 @@ func atomicOperation(n ast.Node, p *program.Program) (
 		return
 
 	case *ast.BinaryOperator:
+		defer func() {
+			if err != nil {
+				err = fmt.Errorf("binary operator : `%v`. %v", v.Operator, err)
+			}
+		}()
 		switch v.Operator {
 		case ",":
 			// BinaryOperator 0x35b95e8 <col:29, col:51> 'int' ','
@@ -930,6 +939,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 			var exprResolveType string
 			exprResolveType, err = types.ResolveType(p, v.Type)
 			if err != nil {
+				err = fmt.Errorf("exprResolveType error for type `%v`: %v", v.Type, err)
 				return
 			}
 
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 8bd0013..57aa4b1 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -130,7 +130,7 @@ func transpileUnaryOperatorInc(n *ast.UnaryOperator, p *program.Program, operato
 
 func transpileUnaryOperatorNot(n *ast.UnaryOperator, p *program.Program) (
 	goast.Expr, string, []goast.Stmt, []goast.Stmt, error) {
-	e, eType, preStmts, postStmts, err := transpileToExpr(n.Children()[0], p, false)
+	e, eType, preStmts, postStmts, err := atomicOperation(n.Children()[0], p)
 	if err != nil {
 		return nil, "", nil, nil, err
 	}


Test patch:
diff --git a/tests/code_quality/for.expected.c b/tests/code_quality/for.expected.c
index 47341e5..b83c99e 100644
--- a/tests/code_quality/for.expected.c
+++ b/tests/code_quality/for.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
diff --git a/tests/code_quality/if.expected.c b/tests/code_quality/if.expected.c
index d2ab8b7..04e2b6b 100644
--- a/tests/code_quality/if.expected.c
+++ b/tests/code_quality/if.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
@@ -52,7 +52,7 @@ func if_1() {
 		return 5
 	}()
 	r = func() int {
-		if map[bool]int{false: 0, true: 1}[w > 1]+map[bool]int{false: 0, true: 1}[r == 4] != 0 {
+		if map[bool]int{false: 0, true: 1}[(w > 1)]+map[bool]int{false: 0, true: 1}[(r == 4)] != 0 {
 			return -1
 		}
 		return 5
diff --git a/tests/code_quality/operators.expected.c b/tests/code_quality/operators.expected.c
index 9f524a5..7f372db 100644
--- a/tests/code_quality/operators.expected.c
+++ b/tests/code_quality/operators.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
@@ -42,23 +42,23 @@ func operators_equals() {
 	var v1 float64
 	var v2 float32
 	var x1 int
-	var x2 uint32
-	var x3 int32
-	var x4 int64
-	var x5 int16
-	var z1 float64
-	var z2 float32
+	var x2 uint32 = uint32((0))
+	var x3 int32 = int32((0))
+	var x4 int64 = int64((0))
+	var x5 int16 = int16((0))
+	var z1 float64 = float64((0))
+	var z2 float32 = float32((0))
 	var t1 float64
-	var t2 float32
+	var t2 float32 = float32((0))
 	var r1 []int
 	var r2 [][]int
 	var r3 [][][]int
 	var r4 [][][][]int
 	var r5 [][][][][]int
 	var r6 [][][][][][]int
-	f(42)
 	// zero value
 	// function
+	f(42)
 	var arr []float32 = make([]float32, 500)
 }
 
diff --git a/tests/code_quality/paren.expected.c b/tests/code_quality/paren.expected.c
index b8ee9a0..d548d7a 100644
--- a/tests/code_quality/paren.expected.c
+++ b/tests/code_quality/paren.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
@@ -12,7 +12,7 @@ func function() {
 	var t int
 	t = (0)
 	var a int
-	a = t
+	a = (t)
 	_ = (t)
 	_ = (a)
 	(function())
diff --git a/tests/code_quality/return.expected.c b/tests/code_quality/return.expected.c
index 464b244..2ef2fcf 100644
--- a/tests/code_quality/return.expected.c
+++ b/tests/code_quality/return.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
diff --git a/tests/code_quality/stdio.expected.c b/tests/code_quality/stdio.expected.c
index d03a094..fd7d72d 100644
--- a/tests/code_quality/stdio.expected.c
+++ b/tests/code_quality/stdio.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
diff --git a/tests/code_quality/switch.expected.c b/tests/code_quality/switch.expected.c
index 4afb03c..1ebab9a 100644
--- a/tests/code_quality/switch.expected.c
+++ b/tests/code_quality/switch.expected.c
@@ -1,5 +1,5 @@
 //
-//	Package main - transpiled by c4go
+//	Package - transpiled by c4go
 //
 //	If you have found any issues, please raise an issue at:
 //	https://github.com/Konstantin8105/c4go/
diff --git a/tests/operators.c b/tests/operators.c
index aa0210a..824fd7e 100644
--- a/tests/operators.c
+++ b/tests/operators.c
@@ -59,7 +59,7 @@ int reteg(int a)
 
 int main()
 {
-    plan(111);
+    plan(113);
 
     int i = 10;
     signed char j = 1;
@@ -469,6 +469,22 @@ int main()
 		a = reteg(a);
 		is_eq(a,43);
 	}
+	diag("equal in function");
+	{
+		int a[2];
+		a[0] = -1;
+		a[1] = 42;
+		int b = a[0];
+		b += reteg((*a)++);
+		is_eq(a[1],42);
+	}
+	diag("operation Not in if");
+	{
+		int addr = 0;
+		if (!addr++){
+			is_eq(addr,1);
+		}
+	}
 
     done_testing();
 }
diff --git a/tests/ternary.c b/tests/ternary.c
index 36937c8..5e110a9 100644
--- a/tests/ternary.c
+++ b/tests/ternary.c
@@ -31,7 +31,7 @@ void test_return_ternary()
 
 int main()
 {
-    plan(11);
+    plan(13);
 
     int a = 'a' == 65 ? 10 : 100;
     float b = 10 == 10 ? 1.0 : 2.0;
@@ -76,6 +76,14 @@ int main()
         0 ? f_empty() : f_empty();
     }
     pass("Ok - ToVoid");
+	{
+		diag("oper ++");
+		int b = 42;
+		int addr = 0;
+		b = addr++? 1:2;
+		is_eq(addr, 1);
+		is_eq(b, 2);
+	}
 
     test_return_ternary();