gogensig:unsigned & signed char

This commit is contained in:
luoliwoshang
2024-10-09 19:55:13 +08:00
parent 82275d49a6
commit a30bdcbb50
4 changed files with 54 additions and 27 deletions

View File

@@ -180,8 +180,8 @@ TestUnionDecl Case 3:
"_Type": "Field", "_Type": "Field",
"Type": { "Type": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
}, },
"Doc": null, "Doc": null,
"Comment": null, "Comment": null,

View File

@@ -20,7 +20,7 @@ func TestUnionDecl() {
int i; int i;
float f; float f;
union { union {
char c; int c;
short s; short s;
} inner; } inner;
};`, };`,

View File

@@ -1,4 +1,5 @@
#stdout #stdout
Char's flags is signed or unsigned
Void:flags:0 kind:0 Void:flags:0 kind:0
Bool:flags:0 kind:1 Bool:flags:0 kind:1
Char_S:flags:1 kind:2 Char_S:flags:1 kind:2
@@ -26,16 +27,16 @@ Complex:flags:0 kind:11
Complex:flags:16 kind:11 Complex:flags:16 kind:11
Complex:flags:20 kind:11 Complex:flags:20 kind:11
Unknown:flags:0 kind:0 Unknown:flags:0 kind:0
Type: char *: Type: int *:
{ {
"_Type": "PointerType", "_Type": "PointerType",
"X": { "X": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
} }
} }
Type: char ***: Type: int ***:
{ {
"_Type": "PointerType", "_Type": "PointerType",
"X": { "X": {
@@ -44,29 +45,29 @@ Type: char ***:
"_Type": "PointerType", "_Type": "PointerType",
"X": { "X": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
} }
} }
} }
} }
Type: char[]: Type: int[]:
{ {
"_Type": "ArrayType", "_Type": "ArrayType",
"Elt": { "Elt": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
}, },
"Len": null "Len": null
} }
Type: char[10]: Type: int[10]:
{ {
"_Type": "ArrayType", "_Type": "ArrayType",
"Elt": { "Elt": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
}, },
"Len": { "Len": {
"_Type": "BasicLit", "_Type": "BasicLit",
@@ -74,15 +75,15 @@ Type: char[10]:
"Value": "10" "Value": "10"
} }
} }
Type: char[3][4]: Type: int[3][4]:
{ {
"_Type": "ArrayType", "_Type": "ArrayType",
"Elt": { "Elt": {
"_Type": "ArrayType", "_Type": "ArrayType",
"Elt": { "Elt": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
}, },
"Len": { "Len": {
"_Type": "BasicLit", "_Type": "BasicLit",
@@ -303,7 +304,7 @@ Type: class a::b::c:
}, },
"Tag": 3 "Tag": 3
} }
Type: int (*)(int, char): Type: int (*)(int, int):
{ {
"_Type": "PointerType", "_Type": "PointerType",
"X": { "X": {
@@ -326,8 +327,8 @@ Type: int (*)(int, char):
"_Type": "Field", "_Type": "Field",
"Type": { "Type": {
"_Type": "BuiltinType", "_Type": "BuiltinType",
"Kind": 2, "Kind": 6,
"Flags": 1 "Flags": 0
}, },
"Doc": null, "Doc": null,
"Comment": null, "Comment": null,

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson" "github.com/goplus/llgo/c/cjson"
@@ -12,6 +13,7 @@ import (
) )
func main() { func main() {
TestChar()
TestBuiltinType() TestBuiltinType()
TestNonBuiltinTypes() 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() { func TestNonBuiltinTypes() {
tests := []string{ tests := []string{
"char*", "int*",
"char***", "int***",
"char[]", "int[]",
"char[10]", "int[10]",
"char[3][4]", "int[3][4]",
"int&", "int&",
"int&&", "int&&",
@@ -122,7 +148,7 @@ func TestNonBuiltinTypes() {
} }
class a::b::c`, class a::b::c`,
`int (*p)(int, char);`, `int (*p)(int, int);`,
} }
for _, t := range tests { for _, t := range tests {