llcppsigfetch:variadic param

This commit is contained in:
luoliwoshang
2024-08-27 16:18:29 +08:00
parent e57ee17532
commit 0ac48369fe
6 changed files with 115 additions and 34 deletions

View File

@@ -255,6 +255,12 @@ func (ct *Converter) ProcessFunctionType(t clang.Type) *ast.FuncType {
})
}
if t.IsFunctionTypeVariadic() != 0 {
params.List = append(params.List, &ast.Field{
Type: &ast.Variadic{},
})
}
return &ast.FuncType{
Ret: ret,
Params: params,
@@ -296,38 +302,7 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl {
}
if isMethod(cursor) {
if parent := cursor.SemanticParent(); parent.Equal(cursor.LexicalParent()) != 1 {
fn.DeclBase.Parent = buildScopingExpr(cursor.SemanticParent())
}
if cursor.Kind == clang.CursorDestructor {
fn.IsDestructor = true
}
if cursor.Kind == clang.CursorConstructor {
fn.IsConstructor = true
if cursor.IsExplicit() != 0 {
fn.IsExplicit = true
}
}
if cursor.IsStatic() != 0 {
fn.IsStatic = true
}
// virtual & pure virtual
if cursor.IsVirtual() != 0 || cursor.IsPureVirtual() != 0 {
fn.IsVirtual = true
}
if cursor.IsConst() != 0 {
fn.IsConst = true
}
var numOverridden c.Uint
var overridden *clang.Cursor
cursor.OverriddenCursors(&overridden, &numOverridden)
if numOverridden > 0 {
fn.IsOverride = true
}
overridden.DisposeOverriddenCursors()
ct.ProcessMethodAttributes(cursor, fn)
} else {
if cursor.StorageClass() == clang.SCStatic {
fn.IsStatic = true
@@ -337,6 +312,41 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl {
return fn
}
// get Methods Attributes
func (ct *Converter) ProcessMethodAttributes(cursor clang.Cursor, fn *ast.FuncDecl) {
if parent := cursor.SemanticParent(); parent.Equal(cursor.LexicalParent()) != 1 {
fn.DeclBase.Parent = buildScopingExpr(cursor.SemanticParent())
}
switch cursor.Kind {
case clang.CursorDestructor:
fn.IsDestructor = true
case clang.CursorConstructor:
fn.IsConstructor = true
if cursor.IsExplicit() != 0 {
fn.IsExplicit = true
}
}
if cursor.IsStatic() != 0 {
fn.IsStatic = true
}
if cursor.IsVirtual() != 0 || cursor.IsPureVirtual() != 0 {
fn.IsVirtual = true
}
if cursor.IsConst() != 0 {
fn.IsConst = true
}
var numOverridden c.Uint
var overridden *clang.Cursor
cursor.OverriddenCursors(&overridden, &numOverridden)
if numOverridden > 0 {
fn.IsOverride = true
}
overridden.DisposeOverriddenCursors()
}
type visitEnumContext struct {
enum *[]*ast.EnumItem
converter *Converter
@@ -449,12 +459,18 @@ func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan
return clang.ChildVisit_Continue
}
// For Record Type(struct,union ...) & Func 's FieldList
func (ct *Converter) ProcessFieldList(cursor clang.Cursor) *ast.FieldList {
params := &ast.FieldList{List: []*ast.Field{}}
ctx := &visitFieldContext{
params: params,
converter: ct,
}
if (cursor.Kind == clang.CursorFunctionDecl || isMethod(cursor)) && cursor.IsVariadic() != 0 {
params.List = append(params.List, &ast.Field{
Type: &ast.Variadic{},
})
}
clang.VisitChildren(cursor, visitFieldList, c.Pointer(ctx))
return params
}

View File

@@ -10,6 +10,7 @@ func TestFuncDecl() {
testCases := []string{
`void foo();`,
`void foo(int a);`,
`void foo(int a,...);`,
`float* foo(int a,double b);`,
`static inline int add(int a, int b);`,
}

View File

@@ -88,6 +88,63 @@ TestFuncDecl Case 2:
}
TestFuncDecl Case 3:
{
"temp.h": {
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
},
"Doc": null,
"Comment": null,
"Names": []
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}]
},
"Ret": {
"Kind": 0,
"Flags": 0
}
},
"IsInline": false,
"IsStatic": false,
"IsConst": false,
"IsExplicit": false,
"IsConstructor": false,
"IsDestructor": false,
"IsVirtual": false,
"IsOverride": false
}],
"includes": [],
"macros": []
}
}
TestFuncDecl Case 4:
{
"temp.h": {
"decls": [{
@@ -154,7 +211,7 @@ TestFuncDecl Case 3:
}
}
TestFuncDecl Case 4:
TestFuncDecl Case 5:
{
"temp.h": {
"decls": [{

View File

@@ -94,6 +94,12 @@ TestTypeDefDecl Case 3:
"Doc": null,
"Comment": null,
"Names": []
}, {
"Type": {
},
"Doc": null,
"Comment": null,
"Names": []
}]
},
"Ret": {

View File

@@ -13,7 +13,7 @@ func TestTypeDefDecl() {
`typedef int INT;
typedef INT STANDARD_INT;`,
`typedef int (*Foo)(int, int);`,
`typedef int (*Foo)(int, int, ...);`,
}
test.RunTest("TestTypeDefDecl", testCases)
}

View File

@@ -148,6 +148,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
names.AddItem(MarshalASTExpr(n))
}
root.SetItem(c.Str("Names"), names)
case *ast.Variadic:
case *ast.Ident:
if d == nil {
return cjson.Null()