From 05777019c8d9f13285b854f6ff7bb48ebf7dc781 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Thu, 24 Oct 2024 17:46:33 +0800 Subject: [PATCH] llcppsigfetch:anony enum --- chore/_xtool/llcppsigfetch/parse/cvt.go | 29 ++++---- .../cvt_test/decl_test/enum_test/enum.go | 5 ++ .../cvt_test/decl_test/enum_test/llgo.expect | 66 +++++++++++++++++-- 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/parse/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt.go index 8ad9b658..1c26389f 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt.go @@ -611,13 +611,22 @@ func (ct *Converter) ProcessEnumType(cursor clang.Cursor) *ast.EnumType { } func (ct *Converter) ProcessEnumDecl(cursor clang.Cursor) *ast.EnumTypeDecl { - name := toStr(cursor.String()) + cursorName, cursorKind := getCursorDesc(cursor) + ct.logln("ProcessEnumDecl: CursorName:", cursorName, "CursorKind:", cursorKind) decl := &ast.EnumTypeDecl{ DeclBase: ct.CreateDeclBase(cursor), - Name: &ast.Ident{Name: name}, Type: ct.ProcessEnumType(cursor), } + + anony := cursor.IsAnonymous() + if anony == 0 { + decl.Name = &ast.Ident{Name: cursorName} + ct.logln("ProcessEnumDecl: has name", cursorName) + } else { + ct.logln("ProcessRecordDecl: is anonymous") + } + ct.SetTypeDecl(cursor, decl) return decl } @@ -738,22 +747,20 @@ func (ct *Converter) ProcessRecordDecl(cursor clang.Cursor) *ast.TypeDecl { cursorName, cursorKind := getCursorDesc(cursor) ct.logln("ProcessRecordDecl: CursorName:", cursorName, "CursorKind:", cursorKind) + decl := &ast.TypeDecl{ + DeclBase: ct.CreateDeclBase(cursor), + Type: ct.ProcessRecordType(cursor), + } + anony := cursor.IsAnonymousRecordDecl() - var name *ast.Ident if anony == 0 { - name = &ast.Ident{Name: cursorName} + decl.Name = &ast.Ident{Name: cursorName} ct.logln("ProcessRecordDecl: has name", cursorName) } else { ct.logln("ProcessRecordDecl: is anonymous") } - decl := &ast.TypeDecl{ - DeclBase: ct.CreateDeclBase(cursor), - Name: name, - Type: ct.ProcessRecordType(cursor), - } ct.SetTypeDecl(cursor, decl) - return decl } @@ -775,7 +782,7 @@ func (ct *Converter) ProcessClassDecl(cursor clang.Cursor) *ast.TypeDecl { decl := &ast.TypeDecl{ DeclBase: base, - Name: &ast.Ident{Name: c.GoString(cursor.String().CStr())}, + Name: &ast.Ident{Name: cursorName}, Type: typ, } diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/enum.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/enum.go index 8ed4cba7..31e3be96 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/enum.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/enum.go @@ -8,6 +8,11 @@ func main() { func TestEnumDecl() { testCases := []string{ + `enum { + a, + b, + c, + };`, `enum Foo { a, b, diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/llgo.expect index b82d9957..23f9c577 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/enum_test/llgo.expect @@ -11,10 +11,7 @@ TestEnumDecl Case 1: }, "Doc": null, "Parent": null, - "Name": { - "_Type": "Ident", - "Name": "Foo" - }, + "Name": null, "Type": { "_Type": "EnumType", "Items": [{ @@ -59,6 +56,65 @@ TestEnumDecl Case 1: } TestEnumDecl Case 2: +{ + "temp.h": { + "_Type": "File", + "decls": [{ + "_Type": "EnumTypeDecl", + "Loc": { + "_Type": "Location", + "File": "temp.h" + }, + "Doc": null, + "Parent": null, + "Name": { + "_Type": "Ident", + "Name": "Foo" + }, + "Type": { + "_Type": "EnumType", + "Items": [{ + "_Type": "EnumItem", + "Name": { + "_Type": "Ident", + "Name": "a" + }, + "Value": { + "_Type": "BasicLit", + "Kind": 0, + "Value": "0" + } + }, { + "_Type": "EnumItem", + "Name": { + "_Type": "Ident", + "Name": "b" + }, + "Value": { + "_Type": "BasicLit", + "Kind": 0, + "Value": "1" + } + }, { + "_Type": "EnumItem", + "Name": { + "_Type": "Ident", + "Name": "c" + }, + "Value": { + "_Type": "BasicLit", + "Kind": 0, + "Value": "2" + } + }] + } + }], + "includes": [], + "macros": [] + } +} + +TestEnumDecl Case 3: { "temp.h": { "_Type": "File", @@ -117,7 +173,7 @@ TestEnumDecl Case 2: } } -TestEnumDecl Case 3: +TestEnumDecl Case 4: { "temp.h": { "_Type": "File",