Repository: Konstantin8105/c4go
Pull request #357 (2019-03-25 09:25:51)

script: neatpost: fix problems

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

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

```diff
@@            Coverage Diff            @@
##           master    #357      +/-   ##
=========================================
+ Coverage   86.25%   86.3%   +0.04%     
=========================================
  Files         186     186              
  Lines       10698   10730      +32     
=========================================
+ Hits         9228    9260      +32     
  Misses       1051    1051              
  Partials      419     419
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/357?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [noarch/stdlib.go](https://codecov.io/gh/Konstantin8105/c4go/pull/357/diff?src=pr&el=tree#diff-bm9hcmNoL3N0ZGxpYi5nbw==) | `90.96% <100%> (ø)` | :arrow_up: |
| [util/goast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/357/diff?src=pr&el=tree#diff-dXRpbC9nb2FzdC5nbw==) | `90.39% <100%> (+1.05%)` | :arrow_up: |
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/357/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `80.14% <100%> (+0.05%)` | :arrow_up: |

------

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


Patch:
diff --git a/noarch/stdlib.go b/noarch/stdlib.go
index 40ba333..e41eca5 100644
--- a/noarch/stdlib.go
+++ b/noarch/stdlib.go
@@ -15,8 +15,8 @@ import (
 
 // DivT is the representation of "div_t". It is used by div().
 type DivT struct {
-	Quot int // quotient
-	Rem  int // remainder
+	Quot int32 // quotient
+	Rem  int32 // remainder
 }
 
 // LdivT is the representation of "ldiv_t". It is used by ldiv().
@@ -36,7 +36,7 @@ type LldivT struct {
 // In C++, this function is also overloaded in header <cmath> for floating-point
 // types (see cmath abs), in header <complex> for complex numbers (see complex
 // abs), and in header <valarray> for valarrays (see valarray abs).
-func Abs(n int) int {
+func Abs(n int32) int32 {
 	if n < 0 {
 		return -n
 	}
@@ -177,7 +177,7 @@ func atoll(str []byte, radix int) (int64, int) {
 // Div returns the integral quotient and remainder of the division of numer by
 // denom ( numer/denom ) as a structure of type div_t, ldiv_t or lldiv_t, which
 // has two members: quot and rem.
-func Div(numer, denom int) DivT {
+func Div(numer, denom int32) DivT {
 	return DivT{
 		Quot: numer / denom,
 		Rem:  numer % denom,
@@ -354,7 +354,7 @@ func Strtoull(str []byte, endptr [][]byte, radix int) uint64 {
 // System executes the given external command with parameters. Unlike system(3)
 // in C, System (and the underlying golang exec) do not invoke the system
 // command processor.
-func System(str []byte) int {
+func System(str []byte) int32 {
 	input := string(str)
 	if input[len(input)-1] == '\x00' {
 		input = input[:len(input)-1]
@@ -389,7 +389,7 @@ func System(str []byte) int {
 	if err != nil {
 		if strings.HasPrefix(err.Error(), "exit status ") {
 			result, _ := strconv.Atoi(strings.Split(err.Error(), " ")[2])
-			return result
+			return int32(result)
 		} else {
 			return 1
 		}
diff --git a/scripts/ed.sh b/scripts/ed.sh
index ac46f61..7158054 100755
--- a/scripts/ed.sh
+++ b/scripts/ed.sh
@@ -55,6 +55,6 @@ if [ "$1" == "-s" ]; then
 			# c4go warnings
 				cat $f | grep "^// Warning" | sort | uniq
 			# show amount error from `go build`:
-				go build -o $f.app -gcflags="-e" $f 2>&1 | sort 
+				go build -o $f.app -gcflags="-e" $f 2>&1
 		done
 fi
diff --git a/scripts/neateqn.sh b/scripts/neateqn.sh
index 6a9a52d..ff4f467 100755
--- a/scripts/neateqn.sh
+++ b/scripts/neateqn.sh
@@ -57,6 +57,6 @@ if [ "$1" == "-s" ]; then
 		# c4go warnings
 			cat $GO_FILE | grep "^// Warning" | sort | uniq
 		# show amount error from `go build`:
-			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
 fi
 
diff --git a/scripts/neatmkfn.sh b/scripts/neatmkfn.sh
index 0f5482c..e2e4f1f 100755
--- a/scripts/neatmkfn.sh
+++ b/scripts/neatmkfn.sh
@@ -57,5 +57,5 @@ if [ "$1" == "-s" ]; then
 		# c4go warnings
 			cat $GO_FILE | grep "^// Warning" | sort | uniq
 		# show amount error from `go build`:
-			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
 fi
diff --git a/scripts/neatpost.sh b/scripts/neatpost.sh
index 1189cdc..9b08fc7 100755
--- a/scripts/neatpost.sh
+++ b/scripts/neatpost.sh
@@ -60,5 +60,5 @@ if [ "$1" == "-s" ]; then
 		# c4go warnings
 			cat $GO_FILE | grep "^// Warning" | sort | uniq
 		# show amount error from `go build`:
-			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
 fi
diff --git a/scripts/neatroff.sh b/scripts/neatroff.sh
index 727353c..88d8ac6 100755
--- a/scripts/neatroff.sh
+++ b/scripts/neatroff.sh
@@ -58,6 +58,6 @@ if [ "$1" == "-s" ]; then
 		# c4go warnings
 			cat $GO_FILE | grep "^// Warning" | sort | uniq
 		# show amount error from `go build`:
-			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
 fi
 
diff --git a/scripts/neatvi.sh b/scripts/neatvi.sh
index 23e64c5..80737a6 100755
--- a/scripts/neatvi.sh
+++ b/scripts/neatvi.sh
@@ -60,6 +60,6 @@ if [ "$1" == "-s" ]; then
 		# c4go warnings
 			cat $GO_FILE | grep "^// Warning" | sort | uniq
 		# show amount error from `go build`:
-			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
 fi
 
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index 9c60e5b..cd826bf 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -16,31 +16,31 @@ Calculate warnings in file: ./testdata/neateqn/neateqn.go
 
 Calculate warnings in file: ./testdata/neatmkfn/neatmkfn.go
 		After transpiling : 557 warnings.
-		Go build : 86 warnings
-		Unsafe   : 16
+		Go build : 75 warnings
+		Unsafe   : 19
 
 Calculate warnings in file: ./testdata/neatpost/neatpost.go
 		After transpiling : 2 warnings.
-		Go build : 63 warnings
-		Unsafe   : 27
+		Go build : 51 warnings
+		Unsafe   : 28
 
 Calculate warnings in file: ./testdata/neatrefer/neatrefer.go
 		After transpiling : 2 warnings.
-		Go build : 3 warnings
-		Unsafe   : 11
+		Go build : 2 warnings
+		Unsafe   : 12
 
 Calculate warnings in file: ./testdata/neatroff/neatroff.go
 		After transpiling : 4 warnings.
-		Go build : 52 warnings
-		Unsafe   : 168
+		Go build : 48 warnings
+		Unsafe   : 170
 
 Calculate warnings in file: ./testdata/neatvi/neatvi.go
 		After transpiling : 31 warnings.
 		Go build : 3 warnings
-		Unsafe   : 77
+		Unsafe   : 79
 
 Calculate warnings in file: testdata/vorbis/vorbis.go
 After transpiling : 5 warnings.
-		Go build : 186 warnings
+		Go build : 180 warnings
 		Unsafe   : 69
 
diff --git a/transpiler/operators.go b/transpiler/operators.go
index beeec01..3a4c840 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -294,7 +294,11 @@ func pointerArithmetic(p *program.Program,
 		_ = printer.Fprint(&buf, token.NewFileSet(), right)
 		s.Condition = buf.String()
 	}
-	s.Type = resolvedLeftType[2:]
+
+	s.Type = resolvedLeftType
+	if resolvedLeftType != "interface{}" {
+		s.Type = resolvedLeftType[2:]
+	}
 
 	s.Operator = "+"
 	if operator == token.SUB {
diff --git a/util/goast.go b/util/goast.go
index 83819b5..e074c4e 100644
--- a/util/goast.go
+++ b/util/goast.go
@@ -375,21 +375,60 @@ func GetUintptr(expr goast.Expr) goast.Expr {
 func GetUintptrForSlice(expr goast.Expr, sizeof int) (goast.Expr, string) {
 	returnType := "long long"
 
+	if sl, ok := expr.(*goast.SliceExpr); ok {
+		expr = &goast.IndexExpr{
+			X:     sl.X,
+			Index: sl.Low,
+		}
+	}
+
+	if _, ok := expr.(*goast.CallExpr); ok {
+		name := "c4go_temp_name"
+		expr = NewAnonymousFunction(
+			// body
+			[]goast.Stmt{
+				&goast.ExprStmt{
+					X: &goast.BinaryExpr{
+						X:  goast.NewIdent(name),
+						Op: token.DEFINE,
+						Y:  expr,
+					},
+				},
+			},
+			// defer
+			nil,
+			// returnValue
+			NewCallExpr("int64", NewCallExpr("uintptr", NewCallExpr("unsafe.Pointer",
+				&goast.StarExpr{
+					Star: 1,
+					X: &goast.CallExpr{
+						Fun:    goast.NewIdent("(**byte)"),
+						Lparen: 1,
+						Args: []goast.Expr{&goast.CallExpr{
+							Fun:    goast.NewIdent("unsafe.Pointer"),
+							Lparen: 1,
+							Args: []goast.Expr{
+								&goast.UnaryExpr{
+									Op: token.AND,
+									X:  goast.NewIdent(name),
+								},
+							},
+						}},
+					},
+				},
+			))),
+			// returnType
+			"int64",
+		)
+		return expr, returnType
+	}
+
 	return &goast.BinaryExpr{
 		X: NewCallExpr("int64", NewCallExpr("uintptr", NewCallExpr("unsafe.Pointer",
 			&goast.StarExpr{
 				Star: 1,
 				X: &goast.CallExpr{
-					Fun: &goast.ParenExpr{
-						Lparen: 1,
-						X: &goast.StarExpr{
-							Star: 1,
-							X: &goast.StarExpr{
-								Star: 1,
-								X:    goast.NewIdent("byte"),
-							},
-						},
-					},
+					Fun:    goast.NewIdent("(**byte)"),
 					Lparen: 1,
 					Args: []goast.Expr{&goast.CallExpr{
 						Fun:    goast.NewIdent("unsafe.Pointer"),


Test patch:
diff --git a/tests/ctype.c b/tests/ctype.c
index 2d4ce26..6f823a6 100644
--- a/tests/ctype.c
+++ b/tests/ctype.c
@@ -24,9 +24,22 @@
 char* strnul = "this string has a \0 NUL";
 char arrnul[] = "this string has a \0 NUL";
 
+static int clrcomp(char *s, int len)
+{
+	static char *digs = "0123456789abcdef";
+	int i;
+	for (i = 0; i < len; i++) { 
+		if (strchr(digs, tolower(s[i]))) {
+			printf("%d\n", (int)(*strchr(digs, tolower(s[i]))));
+			return (strchr(digs, tolower(s[i])) - digs);
+		}
+	}
+	return -1;
+}
+
 int main()
 {
-    plan(112);
+    plan(114);
 
     //              . Lower alpha (a)
     //              |  . Upper alpha (B)
@@ -70,5 +83,13 @@ int main()
     is_eq(toupper('\n'), '\n');
     is_eq(toupper('z'), 'Z');
 
+	diag("clrcomp");
+	{
+		char *word1 = "12";
+		is_eq(clrcomp(word1,2),1);
+		char *word2 = "qwe12";
+		is_eq(clrcomp(word2,5),14);
+	}
+
     done_testing();
 }
diff --git a/tests/stdlib.c b/tests/stdlib.c
index c32c763..297ade5 100644
--- a/tests/stdlib.c
+++ b/tests/stdlib.c
@@ -543,6 +543,12 @@ int main()
     test_strtol("123abc", 16, 1194684, "");
     test_strtol("123abc", 8, 83, "abc");
 
+	diag("abs int");
+	{
+		int h = -1000;
+		printf("%d %d\n", abs(h)/100, abs(h) %100);
+	}
+
     test_system();
 
     q_sort();