gogensig:unsigned & signed char
This commit is contained in:
@@ -180,8 +180,8 @@ TestUnionDecl Case 3:
|
||||
"_Type": "Field",
|
||||
"Type": {
|
||||
"_Type": "BuiltinType",
|
||||
"Kind": 2,
|
||||
"Flags": 1
|
||||
"Kind": 6,
|
||||
"Flags": 0
|
||||
},
|
||||
"Doc": null,
|
||||
"Comment": null,
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestUnionDecl() {
|
||||
int i;
|
||||
float f;
|
||||
union {
|
||||
char c;
|
||||
int c;
|
||||
short s;
|
||||
} inner;
|
||||
};`,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user