llcppsigfetch:Constant & Incomplete Array
This commit is contained in:
@@ -147,11 +147,20 @@ func (ct *Converter) ProcessType(t clang.Type) ast.Expr {
|
||||
expr = &ast.FuncType{Ret: ret}
|
||||
case clang.TypeTypedef:
|
||||
expr = ct.ProcessType(t.CanonicalType())
|
||||
case clang.TypeConstantArray, clang.TypeVariableArray, clang.TypeIncompleteArray, clang.TypeDependentSizedArray:
|
||||
expr = &ast.ArrayType{
|
||||
Elt: ct.ProcessType(t.ArrayElementType()),
|
||||
case clang.TypeConstantArray, clang.TypeIncompleteArray, clang.TypeVariableArray, clang.TypeDependentSizedArray:
|
||||
if t.Kind == clang.TypeConstantArray {
|
||||
valueStr := make([]c.Char, 20)
|
||||
c.Sprintf(unsafe.SliceData(valueStr), c.Str("%d"), t.ArraySize())
|
||||
expr = &ast.ArrayType{
|
||||
Elt: ct.ProcessType(t.ArrayElementType()),
|
||||
Len: &ast.BasicLit{Kind: ast.IntLit, Value: c.GoString(unsafe.SliceData(valueStr))},
|
||||
}
|
||||
} else if t.Kind == clang.TypeIncompleteArray {
|
||||
// incomplete array havent len expr
|
||||
expr = &ast.ArrayType{
|
||||
Elt: ct.ProcessType(t.ArrayElementType()),
|
||||
}
|
||||
}
|
||||
// todo(zzy):array length
|
||||
}
|
||||
return expr
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ func TestFuncDecl() {
|
||||
`void foo(char* str, double x);`,
|
||||
`float* foo(char* str, double x);`,
|
||||
`float* foo(char*** str, double x);`,
|
||||
|
||||
`float* foo(char str[], double x);`,
|
||||
`float* foo(int arr[3][4]);`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
|
||||
@@ -259,6 +259,107 @@ Test Case 6:
|
||||
}
|
||||
}
|
||||
|
||||
Test Case 7:
|
||||
{
|
||||
"temp.h": {
|
||||
"Path": "temp.h",
|
||||
"decls": [{
|
||||
"Loc": null,
|
||||
"Doc": null,
|
||||
"Parent": null,
|
||||
"Name": {
|
||||
"Name": "foo"
|
||||
},
|
||||
"Type": {
|
||||
"Params": {
|
||||
"List": [{
|
||||
"Type": {
|
||||
"Elt": {
|
||||
"Kind": 2,
|
||||
"Flags": 1
|
||||
},
|
||||
"Len": null
|
||||
},
|
||||
"Doc": null,
|
||||
"Comment": null,
|
||||
"Names": [{
|
||||
"Name": "str"
|
||||
}]
|
||||
}, {
|
||||
"Type": {
|
||||
"Kind": 8,
|
||||
"Flags": 16
|
||||
},
|
||||
"Doc": null,
|
||||
"Comment": null,
|
||||
"Names": [{
|
||||
"Name": "x"
|
||||
}]
|
||||
}]
|
||||
},
|
||||
"Ret": {
|
||||
"X": {
|
||||
"Kind": 8,
|
||||
"Flags": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}],
|
||||
"includes": [],
|
||||
"macros": []
|
||||
}
|
||||
}
|
||||
|
||||
Test Case 8:
|
||||
{
|
||||
"temp.h": {
|
||||
"Path": "temp.h",
|
||||
"decls": [{
|
||||
"Loc": null,
|
||||
"Doc": null,
|
||||
"Parent": null,
|
||||
"Name": {
|
||||
"Name": "foo"
|
||||
},
|
||||
"Type": {
|
||||
"Params": {
|
||||
"List": [{
|
||||
"Type": {
|
||||
"Elt": {
|
||||
"Elt": {
|
||||
"Kind": 6,
|
||||
"Flags": 0
|
||||
},
|
||||
"Len": {
|
||||
"Kind": 0,
|
||||
"Value": "4"
|
||||
}
|
||||
},
|
||||
"Len": {
|
||||
"Kind": 0,
|
||||
"Value": "3"
|
||||
}
|
||||
},
|
||||
"Doc": null,
|
||||
"Comment": null,
|
||||
"Names": [{
|
||||
"Name": "arr"
|
||||
}]
|
||||
}]
|
||||
},
|
||||
"Ret": {
|
||||
"X": {
|
||||
"Kind": 8,
|
||||
"Flags": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}],
|
||||
"includes": [],
|
||||
"macros": []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#stderr
|
||||
|
||||
|
||||
@@ -87,8 +87,14 @@ func (ct *Converter) TypeJSON(t ast.Expr) *cjson.JSON {
|
||||
root.SetItem(c.Str("Names"), names)
|
||||
case *ast.Ident:
|
||||
root.SetItem(c.Str("Name"), cjson.String(c.AllocaCStr(d.Name)))
|
||||
case *ast.BasicLit:
|
||||
root.SetItem(c.Str("Kind"), cjson.Number(float64(d.Kind)))
|
||||
root.SetItem(c.Str("Value"), cjson.String(c.AllocaCStr(d.Value)))
|
||||
case *ast.PointerType:
|
||||
root.SetItem(c.Str("X"), ct.TypeJSON(d.X))
|
||||
case *ast.ArrayType:
|
||||
root.SetItem(c.Str("Elt"), ct.TypeJSON(d.Elt))
|
||||
root.SetItem(c.Str("Len"), ct.TypeJSON(d.Len))
|
||||
case *ast.BuiltinType:
|
||||
root.SetItem(c.Str("Kind"), cjson.Number(float64(d.Kind)))
|
||||
root.SetItem(c.Str("Flags"), cjson.Number(float64(d.Flags)))
|
||||
|
||||
Reference in New Issue
Block a user