Merge pull request #116 from luoliwoshang/llcppsigfetch/enum_anony
llcppsigfetch:anonymous enumdecl
This commit is contained in:
@@ -611,13 +611,22 @@ func (ct *Converter) ProcessEnumType(cursor clang.Cursor) *ast.EnumType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ct *Converter) ProcessEnumDecl(cursor clang.Cursor) *ast.EnumTypeDecl {
|
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{
|
decl := &ast.EnumTypeDecl{
|
||||||
DeclBase: ct.CreateDeclBase(cursor),
|
DeclBase: ct.CreateDeclBase(cursor),
|
||||||
Name: &ast.Ident{Name: name},
|
|
||||||
Type: ct.ProcessEnumType(cursor),
|
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)
|
ct.SetTypeDecl(cursor, decl)
|
||||||
return decl
|
return decl
|
||||||
}
|
}
|
||||||
@@ -738,22 +747,20 @@ func (ct *Converter) ProcessRecordDecl(cursor clang.Cursor) *ast.TypeDecl {
|
|||||||
cursorName, cursorKind := getCursorDesc(cursor)
|
cursorName, cursorKind := getCursorDesc(cursor)
|
||||||
ct.logln("ProcessRecordDecl: CursorName:", cursorName, "CursorKind:", cursorKind)
|
ct.logln("ProcessRecordDecl: CursorName:", cursorName, "CursorKind:", cursorKind)
|
||||||
|
|
||||||
|
decl := &ast.TypeDecl{
|
||||||
|
DeclBase: ct.CreateDeclBase(cursor),
|
||||||
|
Type: ct.ProcessRecordType(cursor),
|
||||||
|
}
|
||||||
|
|
||||||
anony := cursor.IsAnonymousRecordDecl()
|
anony := cursor.IsAnonymousRecordDecl()
|
||||||
var name *ast.Ident
|
|
||||||
if anony == 0 {
|
if anony == 0 {
|
||||||
name = &ast.Ident{Name: cursorName}
|
decl.Name = &ast.Ident{Name: cursorName}
|
||||||
ct.logln("ProcessRecordDecl: has name", cursorName)
|
ct.logln("ProcessRecordDecl: has name", cursorName)
|
||||||
} else {
|
} else {
|
||||||
ct.logln("ProcessRecordDecl: is anonymous")
|
ct.logln("ProcessRecordDecl: is anonymous")
|
||||||
}
|
}
|
||||||
|
|
||||||
decl := &ast.TypeDecl{
|
|
||||||
DeclBase: ct.CreateDeclBase(cursor),
|
|
||||||
Name: name,
|
|
||||||
Type: ct.ProcessRecordType(cursor),
|
|
||||||
}
|
|
||||||
ct.SetTypeDecl(cursor, decl)
|
ct.SetTypeDecl(cursor, decl)
|
||||||
|
|
||||||
return decl
|
return decl
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,7 +782,7 @@ func (ct *Converter) ProcessClassDecl(cursor clang.Cursor) *ast.TypeDecl {
|
|||||||
|
|
||||||
decl := &ast.TypeDecl{
|
decl := &ast.TypeDecl{
|
||||||
DeclBase: base,
|
DeclBase: base,
|
||||||
Name: &ast.Ident{Name: c.GoString(cursor.String().CStr())},
|
Name: &ast.Ident{Name: cursorName},
|
||||||
Type: typ,
|
Type: typ,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ func main() {
|
|||||||
|
|
||||||
func TestEnumDecl() {
|
func TestEnumDecl() {
|
||||||
testCases := []string{
|
testCases := []string{
|
||||||
|
`enum {
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
};`,
|
||||||
`enum Foo {
|
`enum Foo {
|
||||||
a,
|
a,
|
||||||
b,
|
b,
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ TestEnumDecl Case 1:
|
|||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": null,
|
||||||
"Parent": null,
|
"Parent": null,
|
||||||
"Name": {
|
"Name": null,
|
||||||
"_Type": "Ident",
|
|
||||||
"Name": "Foo"
|
|
||||||
},
|
|
||||||
"Type": {
|
"Type": {
|
||||||
"_Type": "EnumType",
|
"_Type": "EnumType",
|
||||||
"Items": [{
|
"Items": [{
|
||||||
@@ -59,6 +56,65 @@ TestEnumDecl Case 1:
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestEnumDecl Case 2:
|
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": {
|
"temp.h": {
|
||||||
"_Type": "File",
|
"_Type": "File",
|
||||||
@@ -117,7 +173,7 @@ TestEnumDecl Case 2:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TestEnumDecl Case 3:
|
TestEnumDecl Case 4:
|
||||||
{
|
{
|
||||||
"temp.h": {
|
"temp.h": {
|
||||||
"_Type": "File",
|
"_Type": "File",
|
||||||
|
|||||||
Reference in New Issue
Block a user