Repository: Konstantin8105/c4go
Pull request #316 (2019-03-14 06:51:18)

 README: clarify main approach of project 

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

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

```diff
@@            Coverage Diff             @@
##           master     #316      +/-   ##
==========================================
+ Coverage   86.49%   86.72%   +0.22%     
==========================================
  Files         184      184              
  Lines       10457    10457              
==========================================
+ Hits         9045     9069      +24     
+ Misses        994      970      -24     
  Partials      418      418
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/316?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/316/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYXN0Lmdv) | `93.1% <0%> (+16.55%)` | :arrow_up: |

------

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


Patch:
diff --git a/README.md b/README.md
index 293e4ee..3d820b2 100644
--- a/README.md
+++ b/README.md
@@ -118,12 +118,7 @@ func main() {
 
 # Example with binding function
 
-Run:
-
-```
-c4go transpile 
-```
-
+C:
 
 ```c
 #include <stdio.h>
@@ -180,58 +175,92 @@ func frexp(arg0 float64, arg1 []int32) float64 {
 ```c
 #include <stdio.h>
 
+// input argument - C-pointer
 void a(int *v1) { printf("a: %d\n",*v1); }
 
+// input argument - C-array
 void b(int v1[], int size) {
 	for (size-- ; size >= 0 ; size-- ) { printf("b: %d %d\n", size,  v1[size]); }
 }
 
 int main() {
-	int i1 = 42;
-	a(&i1);
-	b(&i1, 1);
+	// value
+	int i1 = 42; a(&i1); b(&i1, 1);
+
+	// C-array
+	int i2[] = {11,22} ; a(i2); b(i2,2);
+
+	// C-pointer from value
+	int *i3 = &i1      ; a(i3); b(i3,1);
+
+	// C-pointer from array
+	int *i4 = i2       ; a(i4); b(i4,2);
+
+	// C-pointer from array
+	int *i5 = i2[1]    ; a(i5); b(i5,1);
 
-	int i2[] = {11,22};
-	a(i2);
-	b(i2,2);
+	// pointer arithmetic
+	int *i6 = i5 + 1   ; a(i6); b(i6,1);
+	
+	// pointer arithmetic
+	int *i7 = 1 + 0+ i5; a(i7); b(i7,1);
 
 	return 0;
 }
 ```
 
 ```go
-//
-//	Package - transpiled by c4go
-//
-//	If you have found any issues, please raise an issue at:
-//	https://github.com/Konstantin8105/c4go/
-//
-
 package main
 
 import "unsafe"
 import "github.com/Konstantin8105/c4go/noarch"
 
-// a - transpiled function from  C4GO/examples/ap.c:3
+// a - transpiled function from  C4GO/examples/ap.c:4
 func a(v1 []int32) {
+	// input argument - C-pointer
 	noarch.Printf([]byte("a: %d\n\x00"), v1[0])
 }
 
-// b - transpiled function from  C4GO/examples/ap.c:5
+// b - transpiled function from  C4GO/examples/ap.c:7
 func b(v1 []int32, size int32) {
-	for size -= 1; size >= 0; size-- {
-		noarch.Printf([]byte("b: %d %d\n\x00"), size, v1[size])
+	{
+		// input argument - C-array
+		for size -= 1; size >= 0; size-- {
+			noarch.Printf([]byte("b: %d %d\n\x00"), size, v1[size])
+		}
 	}
 }
 
-// main - transpiled function from  C4GO/examples/ap.c:9
+// main - transpiled function from  C4GO/examples/ap.c:11
 func main() {
 	var i1 int32 = 42
+	// value
 	a((*[100000000]int32)(unsafe.Pointer(&i1))[:])
 	b((*[100000000]int32)(unsafe.Pointer(&i1))[:], 1)
 	var i2 []int32 = []int32{11, 22}
+	// C-array
 	a(i2)
 	b(i2, 2)
+	var i3 []int32 = (*[100000000]int32)(unsafe.Pointer(&i1))[:]
+	// C-pointer from value
+	a(i3)
+	b(i3, 1)
+	var i4 []int32 = i2
+	// C-pointer from array
+	a(i4)
+	b(i4, 2)
+	var i5 []int32 = *((*[]int32)(unsafe.Pointer(uintptr(i2[1]))))
+	// C-pointer from array
+	a(i5)
+	b(i5, 1)
+	var i6 []int32 = i5[1:]
+	// pointer arithmetic
+	a(i6)
+	b(i6, 1)
+	var i7 []int32 = (*(*[1000000000]int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&i5[0])) + (uintptr)(1+0)*unsafe.Sizeof(i5[0]))))[:]
+	// pointer arithmetic
+	a(i7)
+	b(i7, 1)
 	return
 }
 ```
diff --git a/examples/ap.c b/examples/ap.c
index 3c75e2b..5db35df 100644
--- a/examples/ap.c
+++ b/examples/ap.c
@@ -1,19 +1,34 @@
 #include <stdio.h>
 
+// input argument - C-pointer
 void a(int *v1) { printf("a: %d\n",*v1); }
 
+// input argument - C-array
 void b(int v1[], int size) {
 	for (size-- ; size >= 0 ; size-- ) { printf("b: %d %d\n", size,  v1[size]); }
 }
 
 int main() {
-	int i1 = 42;
-	a(&i1);
-	b(&i1, 1);
+	// value
+	int i1 = 42; a(&i1); b(&i1, 1);
 
-	int i2[] = {11,22};
-	a(i2);
-	b(i2,2);
+	// C-array
+	int i2[] = {11,22} ; a(i2); b(i2,2);
+
+	// C-pointer from value
+	int *i3 = &i1      ; a(i3); b(i3,1);
+
+	// C-pointer from array
+	int *i4 = i2       ; a(i4); b(i4,2);
+
+	// C-pointer from array
+	int *i5 = i2[1]    ; a(i5); b(i5,1);
+
+	// pointer arithmetic
+	int *i6 = i5 + 1   ; a(i6); b(i6,1);
+	
+	// pointer arithmetic
+	int *i7 = 1 + 0+ i5; a(i7); b(i7,1);
 
 	return 0;
 }


Test patch:
diff --git a/main_test.go b/main_test.go
index d388074..db3c391 100644
--- a/main_test.go
+++ b/main_test.go
@@ -866,28 +866,31 @@ func TestExamples(t *testing.T) {
 				t.Errorf(err.Error())
 			}
 
-			var file *os.File
-			file, err = os.Open(args.outputFile)
-			if err != nil {
-				t.Fatal(err)
-			}
-			defer file.Close()
+			filenames := append(args.inputFiles, args.outputFile)
+			for _, filename := range filenames {
+				var file *os.File
+				file, err = os.Open(filename)
+				if err != nil {
+					t.Fatal(err)
+				}
+				defer file.Close()
 
-			readme, err := ioutil.ReadFile("./README.md")
-			if err != nil {
-				t.Fatal(err)
-			}
+				readme, err := ioutil.ReadFile("./README.md")
+				if err != nil {
+					t.Fatal(err)
+				}
 
-			scanner := bufio.NewScanner(file)
-			for scanner.Scan() {
-				line := scanner.Text()
-				if !bytes.Contains(readme, []byte(line)) {
-					t.Errorf("Cannot found line : %s", line)
+				scanner := bufio.NewScanner(file)
+				for scanner.Scan() {
+					line := scanner.Text()
+					if !bytes.Contains(readme, []byte(line)) {
+						t.Errorf("Cannot found line : %s", line)
+					}
 				}
-			}
 
-			if err := scanner.Err(); err != nil {
-				t.Fatal(err)
+				if err := scanner.Err(); err != nil {
+					t.Fatal(err)
+				}
 			}
 		})
 	}
diff --git a/tests/code_quality/ap.c b/tests/code_quality/ap.c
new file mode 100644
index 0000000..5db35df
--- /dev/null
+++ b/tests/code_quality/ap.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+// input argument - C-pointer
+void a(int *v1) { printf("a: %d\n",*v1); }
+
+// input argument - C-array
+void b(int v1[], int size) {
+	for (size-- ; size >= 0 ; size-- ) { printf("b: %d %d\n", size,  v1[size]); }
+}
+
+int main() {
+	// value
+	int i1 = 42; a(&i1); b(&i1, 1);
+
+	// C-array
+	int i2[] = {11,22} ; a(i2); b(i2,2);
+
+	// C-pointer from value
+	int *i3 = &i1      ; a(i3); b(i3,1);
+
+	// C-pointer from array
+	int *i4 = i2       ; a(i4); b(i4,2);
+
+	// C-pointer from array
+	int *i5 = i2[1]    ; a(i5); b(i5,1);
+
+	// pointer arithmetic
+	int *i6 = i5 + 1   ; a(i6); b(i6,1);
+	
+	// pointer arithmetic
+	int *i7 = 1 + 0+ i5; a(i7); b(i7,1);
+
+	return 0;
+}
diff --git a/tests/code_quality/ap.expected.c b/tests/code_quality/ap.expected.c
new file mode 100644
index 0000000..9f7fb45
--- /dev/null
+++ b/tests/code_quality/ap.expected.c
@@ -0,0 +1,60 @@
+//
+//	Package - transpiled by c4go
+//
+//	If you have found any issues, please raise an issue at:
+//	https://github.com/Konstantin8105/c4go/
+//
+
+package code_quality
+
+import "unsafe"
+import "github.com/Konstantin8105/c4go/noarch"
+
+// a - transpiled function from  C4GO/tests/code_quality/ap.c:4
+func a(v1 []int32) {
+	// input argument - C-pointer
+	noarch.Printf([]byte("a: %d\n\x00"), v1[0])
+}
+
+// b - transpiled function from  C4GO/tests/code_quality/ap.c:7
+func b(v1 []int32, size int32) {
+	{
+		// input argument - C-array
+		for size -= 1; size >= 0; size-- {
+			noarch.Printf([]byte("b: %d %d\n\x00"), size, v1[size])
+		}
+	}
+}
+
+// main - transpiled function from  C4GO/tests/code_quality/ap.c:11
+func main() {
+	var i1 int32 = 42
+	// value
+	a((*[100000000]int32)(unsafe.Pointer(&i1))[:])
+	b((*[100000000]int32)(unsafe.Pointer(&i1))[:], 1)
+	var i2 []int32 = []int32{11, 22}
+	// C-array
+	a(i2)
+	b(i2, 2)
+	var i3 []int32 = (*[100000000]int32)(unsafe.Pointer(&i1))[:]
+	// C-pointer from value
+	a(i3)
+	b(i3, 1)
+	var i4 []int32 = i2
+	// C-pointer from array
+	a(i4)
+	b(i4, 2)
+	var i5 []int32 = *((*[]int32)(unsafe.Pointer(uintptr(i2[1]))))
+	// C-pointer from array
+	a(i5)
+	b(i5, 1)
+	var i6 []int32 = i5[1:]
+	// pointer arithmetic
+	a(i6)
+	b(i6, 1)
+	var i7 []int32 = (*(*[1000000000]int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&i5[0])) + (uintptr)(1+0)*unsafe.Sizeof(i5[0]))))[:]
+	// pointer arithmetic
+	a(i7)
+	b(i7, 1)
+	return
+}
diff --git a/tests/code_quality/for.expected.c b/tests/code_quality/for.expected.c
index 60daf86..3e08d5a 100644
--- a/tests/code_quality/for.expected.c
+++ b/tests/code_quality/for.expected.c
@@ -7,21 +7,21 @@
 
 package code_quality
 
-// f1 - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/for.c:1
+// f1 - transpiled function from  C4GO/tests/code_quality/for.c:1
 func f1() {
 	var i int32
 	for i = 0; i < 10; i++ {
 	}
 }
 
-// f2 - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/for.c:7
+// f2 - transpiled function from  C4GO/tests/code_quality/for.c:7
 func f2() {
 	var i int32
 	for i = 10; i > 0; i-- {
 	}
 }
 
-// f3 - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/for.c:13
+// f3 - transpiled function from  C4GO/tests/code_quality/for.c:13
 func f3() {
 	{
 		var i int32
diff --git a/tests/code_quality/if.expected.c b/tests/code_quality/if.expected.c
index c042c07..5a9d16c 100644
--- a/tests/code_quality/if.expected.c
+++ b/tests/code_quality/if.expected.c
@@ -7,7 +7,7 @@
 
 package code_quality
 
-// if_1 - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/if.c:1
+// if_1 - transpiled function from  C4GO/tests/code_quality/if.c:1
 func if_1() {
 	var a int32 = 5
 	var b int32 = 2
diff --git a/tests/code_quality/operators.expected.c b/tests/code_quality/operators.expected.c
index 868c0d1..a6e3dc9 100644
--- a/tests/code_quality/operators.expected.c
+++ b/tests/code_quality/operators.expected.c
@@ -7,12 +7,12 @@
 
 package code_quality
 
-// f - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/operators.c:1
+// f - transpiled function from  C4GO/tests/code_quality/operators.c:1
 func f(d uint32) {
 	_ = (d)
 }
 
-// operators_equals - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/operators.c:7
+// operators_equals - transpiled function from  C4GO/tests/code_quality/operators.c:7
 func operators_equals() {
 	var a int32
 	var b int32
diff --git a/tests/code_quality/paren.expected.c b/tests/code_quality/paren.expected.c
index df4828f..f4d0a7f 100644
--- a/tests/code_quality/paren.expected.c
+++ b/tests/code_quality/paren.expected.c
@@ -7,7 +7,7 @@
 
 package code_quality
 
-// function - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/paren.c:1
+// function - transpiled function from  C4GO/tests/code_quality/paren.c:1
 func function() {
 	var t int32
 	t = (0)
diff --git a/tests/code_quality/return.expected.c b/tests/code_quality/return.expected.c
index 4022a0a..91d06ea 100644
--- a/tests/code_quality/return.expected.c
+++ b/tests/code_quality/return.expected.c
@@ -7,21 +7,21 @@
 
 package code_quality
 
-// a - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/return.c:1
+// a - transpiled function from  C4GO/tests/code_quality/return.c:1
 func a() {
 }
 
-// r - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/return.c:5
+// r - transpiled function from  C4GO/tests/code_quality/return.c:5
 func r(y int32) {
 	_ = (y)
 }
 
-// b - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/return.c:10
+// b - transpiled function from  C4GO/tests/code_quality/return.c:10
 func b() int32 {
 	return 0
 }
 
-// c - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/return.c:14
+// c - transpiled function from  C4GO/tests/code_quality/return.c:14
 func c() float32 {
 	return 0
 }
diff --git a/tests/code_quality/stdio.expected.c b/tests/code_quality/stdio.expected.c
index fd7d72d..e892e80 100644
--- a/tests/code_quality/stdio.expected.c
+++ b/tests/code_quality/stdio.expected.c
@@ -10,7 +10,7 @@ package code_quality
 import "github.com/Konstantin8105/c4go/noarch"
 import "fmt"
 
-// print - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/stdio.c:3
+// print - transpiled function from  C4GO/tests/code_quality/stdio.c:3
 func print() {
 	fmt.Printf("Hello")
 	noarch.Printf([]byte("Hello, %d\x00"), 42)
diff --git a/tests/code_quality/switch.expected.c b/tests/code_quality/switch.expected.c
index 821062f..fd5b3c1 100644
--- a/tests/code_quality/switch.expected.c
+++ b/tests/code_quality/switch.expected.c
@@ -7,7 +7,7 @@
 
 package code_quality
 
-// switch_function - transpiled function from  $GOPATH/src/github.com/Konstantin8105/c4go/tests/code_quality/switch.c:1
+// switch_function - transpiled function from  C4GO/tests/code_quality/switch.c:1
 func switch_function() {
 	var i int32 = 34
 	switch i {