diff --git a/chore/_xtool/llcppsigfetch/parse/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt.go index 26c66fab..310adc6c 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt.go @@ -181,11 +181,7 @@ func (ct *Converter) GetCurFile() *ast.File { return ct.Files[i].Doc } } - newDoc := &ast.File{ - Decls: make([]ast.Decl, 0), - Includes: make([]*ast.Include, 0), - Macros: make([]*ast.Macro, 0), - } + newDoc := &ast.File{} ct.Files = append(ct.Files, &FileEntry{Path: ct.curLoc.File, Doc: newDoc}) return newDoc } @@ -734,13 +730,8 @@ func (ct *Converter) ProcessClassDecl(cursor clang.Cursor) *ast.TypeDecl { } func (ct *Converter) ProcessRecordType(cursor clang.Cursor) *ast.RecordType { - tagMap := map[clang.CursorKind]ast.Tag{ - clang.CursorStructDecl: ast.Struct, - clang.CursorUnionDecl: ast.Union, - clang.CursorClassDecl: ast.Class, - } return &ast.RecordType{ - Tag: tagMap[cursor.Kind], + Tag: toTag(cursor.Kind), Fields: ct.ProcessFieldList(cursor), Methods: ct.ProcessMethods(cursor), } @@ -896,6 +887,19 @@ func IsExplicitUnsigned(t clang.Type) bool { t.Kind == clang.TypeUInt128 } +func toTag(kind clang.CursorKind) ast.Tag { + switch kind { + case clang.CursorStructDecl: + return ast.Struct + case clang.CursorUnionDecl: + return ast.Union + case clang.CursorClassDecl: + return ast.Class + default: + panic(fmt.Sprintf("Unexpected cursor kind in toTag: %v", kind)) + } +} + func toToken(tok clang.Token) token.Token { if tok.Kind() < clang.Punctuation || tok.Kind() > clang.Comment { return token.ILLEGAL diff --git a/chore/_xtool/llcppsigfetch/parse/dump.go b/chore/_xtool/llcppsigfetch/parse/dump.go index bb58a02c..2606edbe 100644 --- a/chore/_xtool/llcppsigfetch/parse/dump.go +++ b/chore/_xtool/llcppsigfetch/parse/dump.go @@ -27,9 +27,6 @@ func MarshalASTFiles(files []*FileEntry) *cjson.JSON { } func MarshalDeclList(list []ast.Decl) *cjson.JSON { - if list == nil { - return cjson.Null() - } root := cjson.Array() for _, item := range list { root.AddItem(MarshalASTDecl(item)) @@ -49,9 +46,6 @@ func MarshalFieldList(list []*ast.Field) *cjson.JSON { } func MarshalIncludeList(list []*ast.Include) *cjson.JSON { - if list == nil { - return cjson.Null() - } root := cjson.Array() for _, item := range list { include := cjson.Object() @@ -63,9 +57,6 @@ func MarshalIncludeList(list []*ast.Include) *cjson.JSON { } func MarshalMacroList(list []*ast.Macro) *cjson.JSON { - if list == nil { - return cjson.Null() - } root := cjson.Array() for _, item := range list { macro := cjson.Object()