Repository: Konstantin8105/c4go
Pull request #261 (2019-02-09 13:08:47)

transpileUnaryExprOrTypeTraitExpr: add type unare operator

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

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

```diff
@@            Coverage Diff            @@
##           master    #261      +/-   ##
=========================================
+ Coverage   86.81%   86.9%   +0.08%     
=========================================
  Files         177     176       -1     
  Lines        9656    9657       +1     
=========================================
+ Hits         8383    8392       +9     
+ Misses        881     875       -6     
+ Partials      392     390       -2
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/261?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/261/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `73.8% <100%> (+0.12%)` | :arrow_up: |
| [main.go](https://codecov.io/gh/Konstantin8105/c4go/pull/261/diff?src=pr&el=tree#diff-bWFpbi5nbw==) | | |
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/261/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `77.2% <0%> (+0.56%)` | :arrow_up: |
| [types/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/261/diff?src=pr&el=tree#diff-dHlwZXMvY2FzdC5nbw==) | `69.51% <0%> (+1.11%)` | :arrow_up: |
| [transpiler/branch.go](https://codecov.io/gh/Konstantin8105/c4go/pull/261/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9icmFuY2guZ28=) | `79.37% <0%> (+1.16%)` | :arrow_up: |

------

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


Patch:
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 3e8b8f3..133c924 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -600,6 +600,8 @@ func transpileUnaryExprOrTypeTraitExpr(n *ast.UnaryExprOrTypeTraitExpr, p *progr
 			realFirstChild = c.Children()[0]
 		case *ast.DeclRefExpr:
 			t = c.Type
+		case *ast.UnaryOperator:
+			t = c.Type
 		case *ast.MemberExpr:
 			t = c.Type
 		case *ast.ArraySubscriptExpr:


Test patch:
diff --git a/tests/unary.c b/tests/unary.c
index c265081..74e6862 100644
--- a/tests/unary.c
+++ b/tests/unary.c
@@ -39,12 +39,35 @@ void test_notptr()
     }
 }
 
+int conv(int i)
+{
+	return i;
+}
+
+void test_sizeoftest()
+{
+	// example :
+	// while ((n = fread(buf, sizeof *buf, sizeof buf, fin)) > 0)
+// UnaryExprOrTypeTraitExpr 'unsigned long' sizeof
+// `-UnaryOperator 0x2e1a880 'char' lvalue prefix '*'
+//   `-ImplicitCastExpr 0x2e1a868 'char *' <ArrayToPointerDecay>
+//     `-DeclRefExpr 0x2e1a840 'char [1024]' lvalue Var 0x2e19d78 'buf' 'char [1024]'
+	char *buf = NULL;
+	if (conv(sizeof *buf) > 0) {
+		pass("ok");
+	} else {
+		fail("fail");
+	}
+	(void)(buf);
+}
+
 int main()
 {
-    plan(4);
+    plan(5);
 
     START_TEST(notint)
     START_TEST(notptr)
+	START_TEST(sizeoftest)
 
     done_testing();
 }