Repository: Konstantin8105/c4go
Pull request #429 (2019-04-25 08:51:31)

example: redis


Patch:
diff --git a/noarch/math.go b/noarch/math.go
index 8f447b7..fea0a05 100644
--- a/noarch/math.go
+++ b/noarch/math.go
@@ -147,3 +147,19 @@ func Erff(x float32) float32 {
 func Erfcf(x float32) float32 {
 	return float32(math.Erfc(float64(x)))
 }
+
+func LRound(x float32) int32 {
+	return LRoundl(float64(x))
+}
+
+func LRoundl(x float64) int32 {
+	return int32(math.Round(x))
+}
+
+func LLRound(x float32) int64 {
+	return LLRoundl(float64(x))
+}
+
+func LLRoundl(x float64) int64 {
+	return int64(math.Round(x))
+}
diff --git a/program/definition_function.go b/program/definition_function.go
index 193467b..21a4730 100644
--- a/program/definition_function.go
+++ b/program/definition_function.go
@@ -205,6 +205,14 @@ var builtInFunctionDefinitions = map[string][]string{
 		"double hypot(double, double) -> math.Hypot",
 		"float hypotf(float) -> noarch.Hypotf",
 		"long double hypotl(long double, long double) -> math.Hypot",
+
+		"long int lround(double ) -> noarch.LRound",
+		"long int lroundf(float ) -> noarch.LRound",
+		"long int lroundl(long double ) -> noarch.LRoundl",
+
+		"long long int llround(double ) -> noarch.LLRound",
+		"long long int llroundf(float ) -> noarch.LLRound",
+		"long long int llroundl(long double ) -> noarch.LLRoundl",
 	},
 	"stdio.h": {
 
diff --git a/scripts/redis.sh b/scripts/redis.sh
index 307178f..b4aad5a 100755
--- a/scripts/redis.sh
+++ b/scripts/redis.sh
@@ -40,41 +40,60 @@ if [ "$1" == "-a" ]; then
 fi
 
 # transpilation of all projects
-	echo "Transpile to $GO_FILE"
+	echo "Transpile to Go"
 	$C4GO transpile                                          \
 		-s                                                   \
 		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/hiredis"   \
 		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/jemalloc"  \
 		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/linenoise" \
 		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/lua"       \
-		-o="$GO_FILE"                       \
+		-o="$TEMP_FOLDER/redis_cli.go"                       \
 		$TEMP_FOLDER/$VERSION/src/redis-cli.c
 
-# show warnings comments in Go source
-	echo "Calculate warnings in file: $GO_FILE"
-	WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l`
-	echo "		After transpiling : $WARNINGS warnings."
-
-# show other warnings
-	# show amount error from `go build`:
-		echo "Build to $GO_APP file"
-		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
-		echo "		Go build : $WARNINGS_GO warnings"
-	# amount unsafe
-		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
-		echo "		Unsafe   : $UNSAFE"
+	$C4GO transpile                                          \
+		-s                                                   \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/hiredis"   \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/jemalloc"  \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/linenoise" \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/lua"       \
+		-o="$TEMP_FOLDER/dict.go"                            \
+		$TEMP_FOLDER/$VERSION/src/dict.c
 
+	$C4GO transpile                                          \
+		-s                                                   \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/hiredis"   \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/jemalloc"  \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/linenoise" \
+		-clang-flag="-I$TEMP_FOLDER/$VERSION/deps/lua"       \
+		-o="$TEMP_FOLDER/sds.go"                             \
+		$TEMP_FOLDER/$VERSION/src/sds.c
 
 # Arguments menu
 echo "    -s for show detail of Go build errors"
-if [ "$1" == "-s" ]; then
-	# show go build warnings	
-		# 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
-fi
-
-
 
+# transpilation each file
+	for f in $TEMP_FOLDER/*.go; do
+			# iteration by C projects
+				echo "***** transpilation folder : $f"
+			# show warnings comments in Go source
+				export FILE="$f"
+				echo "Calculate warnings : $FILE"
+				WARNINGS=`cat $FILE | grep "^// Warning" | sort | uniq | wc -l`
+				echo "		After transpiling : $WARNINGS warnings."
+			# show amount error from `go build`:
+				echo "Build to $GO_APP file"
+				WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $f 2>&1 | wc -l`
+				echo "		Go build : $WARNINGS_GO warnings"
+			# amount unsafe
+				UNSAFE=`cat $FILE | grep "unsafe\." | wc -l`
+				echo "		Unsafe   : $UNSAFE"
+
+			if [ "$1" == "-s" ]; then
+				# show go build warnings	
+					# c4go warnings
+						cat $f | grep "^// Warning" | sort | uniq
+					# show amount error from `go build`:
+						go build -o $GO_APP -gcflags="-e" $f 2>&1 && echo "OK" || echo "NOK"
+			fi
+	done
 
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index fe33ee4..838d73e 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -54,10 +54,18 @@ Calculate warnings in file: ./testdata/neatroff/neatroff.go
 		Go build : 8 warnings
 		Unsafe   : 248
 
-Calculate warnings in file: ./testdata/redis/redis.go
+Calculate warnings : ./testdata/redis/dict.go
 		After transpiling : 0 warnings.
-		Go build : 4 warnings
+		Go build : 40 warnings
+		Unsafe   : 73
+Calculate warnings : ./testdata/redis/redis_cli.go
+		After transpiling : 0 warnings.
+		Go build : 50 warnings
 		Unsafe   : 262
+Calculate warnings : ./testdata/redis/sds.go
+		After transpiling : 0 warnings.
+		Go build : 43 warnings
+		Unsafe   : 118
 
 Calculate warnings in file: ./testdata/neatvi/neatvi.go
 		After transpiling : 0 warnings.


Test patch:
diff --git a/tests/math.c b/tests/math.c
index aede270..cdf2061 100644
--- a/tests/math.c
+++ b/tests/math.c
@@ -12,7 +12,7 @@ unsigned long long ullmax = 18446744073709551615ull;
 
 int main()
 {
-    plan(488);
+    plan(496);
 
 	{
 		diag("modf");
@@ -787,5 +787,18 @@ int main()
         is_eq(n, 4);
     }
 
+	diag("round");
+	{
+	   is_eq(lround(2.3), 2);
+	   is_eq(lround(3.8), 4);
+	   is_eq(lround(-2.3), -2);
+	   is_eq(lround(-3.8), -4);
+
+	   is_eq(llround(2.3), 2);
+	   is_eq(llround(3.8), 4);
+	   is_eq(llround(-2.3), -2);
+	   is_eq(llround(-3.8), -4);
+	}
+
     done_testing();
 }