Repository: Konstantin8105/c4go
Pull request #335 (2019-03-18 13:16:00)

atomicOperation: unary + - for value

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

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

```diff
@@            Coverage Diff             @@
##           master     #335      +/-   ##
==========================================
- Coverage   86.31%   86.29%   -0.02%     
==========================================
  Files         184      184              
  Lines       10435    10435              
==========================================
- Hits         9007     9005       -2     
- Misses       1020     1021       +1     
- Partials      408      409       +1
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/335?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/335?src=pr&el=footer). Last update [613e34b...a7d9e00](https://codecov.io/gh/Konstantin8105/c4go/pull/335?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 68dc7ea..634abf5 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -507,7 +507,7 @@ func atomicOperation(n ast.Node, p *program.Program) (
 	switch v := n.(type) {
 	case *ast.UnaryOperator:
 		switch v.Operator {
-		case "&", "*", "!", "-", "~":
+		case "&", "*", "!", "-", "+", "~":
 			return
 		}
 		// UnaryOperator 0x252d798 <col:17, col:18> 'double' prefix '-'
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 00d8a88..c349e22 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -525,6 +525,11 @@ func transpileUnaryOperator(n *ast.UnaryOperator, p *program.Program) (
 		return transpileUnaryOperatorAmpersant(n, p)
 	}
 
+	// Example:
+	// UnaryOperator 'int' prefix '-'
+	// `-ImplicitCastExpr 'int' <LValueToRValue>
+	//   `-DeclRefExpr 'int' lvalue Var 0x3b42898 'c' 'int'
+
 	// Otherwise handle like a unary operator.
 	e, eType, newPre, newPost, err := transpileToExpr(n.Children()[0], p, false)
 	if err != nil {
@@ -537,7 +542,6 @@ func transpileUnaryOperator(n *ast.UnaryOperator, p *program.Program) (
 		Op: operator,
 		X:  e,
 	}, eType, preStmts, postStmts, nil
-
 }
 
 func transpileUnaryExprOrTypeTraitExpr(n *ast.UnaryExprOrTypeTraitExpr, p *program.Program) (


Test patch:
diff --git a/tests/operators.c b/tests/operators.c
index c2404cf..fff2aed 100644
--- a/tests/operators.c
+++ b/tests/operators.c
@@ -57,9 +57,14 @@ int reteg(int a)
     return *ptr = a + 1;
 }
 
+void view(int c)
+{
+	printf("%d\n",c);
+}
+
 int main()
 {
-    plan(115);
+    plan(116);
 
     int i = 10;
     signed char j = 1;
@@ -499,6 +504,13 @@ int main()
         flag &= ~(2 | 256 | 1024);
         is_eq(flag, 100);
     }
+	diag("unary + - ");
+	{
+		int c = 90;
+		view(+c);
+		view(-c);
+		is_eq(c,90);
+	}
 
     done_testing();
 }