From a30bdcbb50d305f2da7e00e3d34b33350fb6de8f Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 9 Oct 2024 19:55:13 +0800 Subject: [PATCH] gogensig:unsigned & signed char --- .../cvt_test/decl_test/union_test/llgo.expect | 4 +- .../cvt_test/decl_test/union_test/union.go | 2 +- .../parse/cvt_test/type_test/llgo.expect | 37 +++++++++--------- .../parse/cvt_test/type_test/type.go | 38 ++++++++++++++++--- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/llgo.expect index 7be1d152..7263896d 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/llgo.expect @@ -180,8 +180,8 @@ TestUnionDecl Case 3: "_Type": "Field", "Type": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 }, "Doc": null, "Comment": null, diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/union.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/union.go index 5e8c18b5..c963feb8 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/union.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/union_test/union.go @@ -20,7 +20,7 @@ func TestUnionDecl() { int i; float f; union { - char c; + int c; short s; } inner; };`, diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/llgo.expect index d7e93459..cad17f83 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/llgo.expect @@ -1,4 +1,5 @@ #stdout +Char's flags is signed or unsigned Void:flags:0 kind:0 Bool:flags:0 kind:1 Char_S:flags:1 kind:2 @@ -26,16 +27,16 @@ Complex:flags:0 kind:11 Complex:flags:16 kind:11 Complex:flags:20 kind:11 Unknown:flags:0 kind:0 -Type: char *: +Type: int *: { "_Type": "PointerType", "X": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 } } -Type: char ***: +Type: int ***: { "_Type": "PointerType", "X": { @@ -44,29 +45,29 @@ Type: char ***: "_Type": "PointerType", "X": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 } } } } -Type: char[]: +Type: int[]: { "_Type": "ArrayType", "Elt": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 }, "Len": null } -Type: char[10]: +Type: int[10]: { "_Type": "ArrayType", "Elt": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 }, "Len": { "_Type": "BasicLit", @@ -74,15 +75,15 @@ Type: char[10]: "Value": "10" } } -Type: char[3][4]: +Type: int[3][4]: { "_Type": "ArrayType", "Elt": { "_Type": "ArrayType", "Elt": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 }, "Len": { "_Type": "BasicLit", @@ -303,7 +304,7 @@ Type: class a::b::c: }, "Tag": 3 } -Type: int (*)(int, char): +Type: int (*)(int, int): { "_Type": "PointerType", "X": { @@ -326,8 +327,8 @@ Type: int (*)(int, char): "_Type": "Field", "Type": { "_Type": "BuiltinType", - "Kind": 2, - "Flags": 1 + "Kind": 6, + "Flags": 0 }, "Doc": null, "Comment": null, diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/type.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/type.go index 03a5771f..76fef62f 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/type.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/type_test/type.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "github.com/goplus/llgo/c" "github.com/goplus/llgo/c/cjson" @@ -12,6 +13,7 @@ import ( ) func main() { + TestChar() TestBuiltinType() TestNonBuiltinTypes() } @@ -64,14 +66,38 @@ func TestBuiltinType() { } } +// Char's Default Type in macos is signed char & in linux is unsigned char +// So we only confirm the char's kind is char & flags is unsigned or signed +func TestChar() { + typ, index, transunit := test.GetType(&test.GetTypeOptions{ + TypeCode: "char", + IsCpp: false, + }) + converter := &parse.Converter{} + expr := converter.ProcessType(typ) + if btType, ok := expr.(*ast.BuiltinType); ok { + if btType.Kind == ast.Char { + if btType.Flags == ast.Signed || btType.Flags == ast.Unsigned { + fmt.Println("Char's flags is signed or unsigned") + } else { + fmt.Fprintf(os.Stderr, "Char's flags is not signed or unsigned") + } + } + } else { + fmt.Fprintf(os.Stderr, "Char's expr is not a builtin type") + } + index.Dispose() + transunit.Dispose() +} + func TestNonBuiltinTypes() { tests := []string{ - "char*", - "char***", + "int*", + "int***", - "char[]", - "char[10]", - "char[3][4]", + "int[]", + "int[10]", + "int[3][4]", "int&", "int&&", @@ -122,7 +148,7 @@ func TestNonBuiltinTypes() { } class a::b::c`, - `int (*p)(int, char);`, + `int (*p)(int, int);`, } for _, t := range tests {