llcppsigfetch:handle unexpect tag

This commit is contained in:
luoliwoshang
2024-09-21 01:52:19 +08:00
parent 2c3d46bb80
commit c8a064af3e
2 changed files with 15 additions and 20 deletions

View File

@@ -181,11 +181,7 @@ func (ct *Converter) GetCurFile() *ast.File {
return ct.Files[i].Doc return ct.Files[i].Doc
} }
} }
newDoc := &ast.File{ newDoc := &ast.File{}
Decls: make([]ast.Decl, 0),
Includes: make([]*ast.Include, 0),
Macros: make([]*ast.Macro, 0),
}
ct.Files = append(ct.Files, &FileEntry{Path: ct.curLoc.File, Doc: newDoc}) ct.Files = append(ct.Files, &FileEntry{Path: ct.curLoc.File, Doc: newDoc})
return 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 { 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{ return &ast.RecordType{
Tag: tagMap[cursor.Kind], Tag: toTag(cursor.Kind),
Fields: ct.ProcessFieldList(cursor), Fields: ct.ProcessFieldList(cursor),
Methods: ct.ProcessMethods(cursor), Methods: ct.ProcessMethods(cursor),
} }
@@ -896,6 +887,19 @@ func IsExplicitUnsigned(t clang.Type) bool {
t.Kind == clang.TypeUInt128 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 { func toToken(tok clang.Token) token.Token {
if tok.Kind() < clang.Punctuation || tok.Kind() > clang.Comment { if tok.Kind() < clang.Punctuation || tok.Kind() > clang.Comment {
return token.ILLEGAL return token.ILLEGAL

View File

@@ -27,9 +27,6 @@ func MarshalASTFiles(files []*FileEntry) *cjson.JSON {
} }
func MarshalDeclList(list []ast.Decl) *cjson.JSON { func MarshalDeclList(list []ast.Decl) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array() root := cjson.Array()
for _, item := range list { for _, item := range list {
root.AddItem(MarshalASTDecl(item)) root.AddItem(MarshalASTDecl(item))
@@ -49,9 +46,6 @@ func MarshalFieldList(list []*ast.Field) *cjson.JSON {
} }
func MarshalIncludeList(list []*ast.Include) *cjson.JSON { func MarshalIncludeList(list []*ast.Include) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array() root := cjson.Array()
for _, item := range list { for _, item := range list {
include := cjson.Object() include := cjson.Object()
@@ -63,9 +57,6 @@ func MarshalIncludeList(list []*ast.Include) *cjson.JSON {
} }
func MarshalMacroList(list []*ast.Macro) *cjson.JSON { func MarshalMacroList(list []*ast.Macro) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array() root := cjson.Array()
for _, item := range list { for _, item := range list {
macro := cjson.Object() macro := cjson.Object()