Repository: Konstantin8105/c4go
Pull request #382 (2019-04-02 14:31:39)

specific va_list

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

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

```diff
@@            Coverage Diff             @@
##           master     #382      +/-   ##
==========================================
- Coverage   85.97%   85.94%   -0.04%     
==========================================
  Files         188      188              
  Lines       10946    10950       +4     
==========================================
  Hits         9411     9411              
- Misses       1097     1099       +2     
- Partials      438      440       +2
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/382?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [types/resolve.go](https://codecov.io/gh/Konstantin8105/c4go/pull/382/diff?src=pr&el=tree#diff-dHlwZXMvcmVzb2x2ZS5nbw==) | `75.29% <0%> (-1.22%)` | :arrow_down: |
| [types/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/382/diff?src=pr&el=tree#diff-dHlwZXMvY2FzdC5nbw==) | `70.63% <100%> (ø)` | :arrow_up: |

------

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


Patch:
diff --git a/program/definition_type.go b/program/definition_type.go
index 665a98d..4a85250 100644
--- a/program/definition_type.go
+++ b/program/definition_type.go
@@ -54,27 +54,11 @@ var DefinitionType = map[string]string{
 	// when using the NULL macro.
 	"null": "null",
 
-	// Non platform-specific types.
-	"uint32":     "uint32",
-	"uint64":     "uint64",
-	"__uint16_t": "uint16",
-	"__uint32_t": "uint32",
-	"__uint64_t": "uint64",
-
 	// sys/stat.h
 	"mode_t":   "uint16",
 	"__mode_t": "uint16",
 
-	// These are special cases that almost certainly don't work. I've put
-	// them here because for whatever reason there is no suitable type or we
-	// don't need these platform specific things to be implemented yet.
-	"__builtin_va_list": "int64",
-	"unsigned __int128": "uint64",
-	"__int128":          "int64",
-	"__mbstate_t":       "int64",
-	"__sbuf":            "int64",
-	"__sFILEX":          "interface{}",
-	"FILE":              "github.com/Konstantin8105/c4go/noarch.File",
+	"FILE": "github.com/Konstantin8105/c4go/noarch.File",
 
 	// termios.h
 	"tcflag_t": "uint32",
diff --git a/transpiler/transpiler.go b/transpiler/transpiler.go
index 0117f20..9d1787c 100644
--- a/transpiler/transpiler.go
+++ b/transpiler/transpiler.go
@@ -159,7 +159,7 @@ func TranspileAST(fileName, packageName string, withOutsideStructs bool,
 	}
 
 	// only for "stdarg.h"
-	if p.IncludeHeaderIsExists("stdarg.h") && p.IsHaveVaList {
+	if (p.IncludeHeaderIsExists("stdarg.h") && p.IsHaveVaList) || strings.Contains(source, "va_list") {
 		source += getVaListStruct()
 	}
 
diff --git a/types/cast.go b/types/cast.go
index 1187ad2..e4e3503 100644
--- a/types/cast.go
+++ b/types/cast.go
@@ -133,7 +133,7 @@ func CastExpr(p *program.Program, expr goast.Expr, cFromType, cToType string) (
 	}
 
 	// Exceptions for va_list
-	if fromType == "va_list" && toType == "struct __va_list_tag *" {
+	if fromType == "va_list" {
 		return expr, nil
 	}
 
@@ -335,9 +335,6 @@ func CastExpr(p *program.Program, expr goast.Expr, cFromType, cToType string) (
 		// Floating-point types.
 		"float32", "float64",
 
-		// Known aliases
-		"__uint16_t", "size_t",
-
 		"noarch.SsizeT",
 	}
 	for _, v := range types {
diff --git a/types/resolve.go b/types/resolve.go
index 9b1020f..550b8f2 100644
--- a/types/resolve.go
+++ b/types/resolve.go
@@ -162,6 +162,12 @@ func ResolveType(p *program.Program, s string) (resolveResult string, err error)
 	if strings.Contains(s, "struct __va_list_tag") {
 		return "* va_list", nil
 	}
+	if strings.Contains(s, "va_list") {
+		return "* va_list", nil
+	}
+	if strings.Contains(s, "__builtin_va_list") {
+		return "* va_list", nil
+	}
 
 	// The simple resolve types are the types that we know there is an exact Go
 	// equivalent. For example float, int, etc.


Test patch:
diff --git a/types/cast_test.go b/types/cast_test.go
index 35765fb..ca426e0 100644
--- a/types/cast_test.go
+++ b/types/cast_test.go
@@ -37,7 +37,6 @@ func TestCast(t *testing.T) {
 		// Casting between numeric types.
 		{args{util.NewIntLit(1), "int", "float"}, util.NewCallExpr("float32", util.NewIntLit(1))},
 		{args{util.NewIntLit(1), "int", "double"}, util.NewCallExpr("float64", util.NewIntLit(1))},
-		{args{util.NewIntLit(1), "int", "__uint16_t"}, util.NewCallExpr("uint16", util.NewIntLit(1))},
 
 		// Casting to bool
 		{args{util.NewIntLit(1), "int", "bool"}, util.NewBinaryExpr(util.NewIntLit(1), token.NEQ, util.NewIntLit(0), "bool", false)},
diff --git a/types/resolve_test.go b/types/resolve_test.go
index f4aa409..dc49055 100644
--- a/types/resolve_test.go
+++ b/types/resolve_test.go
@@ -17,7 +17,6 @@ type resolveTestCase struct {
 var resolveTestCases = []resolveTestCase{
 	{"int", "int32"},
 	{"char *[13]", "[][]byte"},
-	{"__uint16_t", "uint16"},
 	{"void *", "interface{}"},
 	{"unsigned short int", "uint16"},
 	{"div_t", "noarch.DivT"},