llcppsigfetch:union

This commit is contained in:
luoliwoshang
2024-08-20 10:43:01 +08:00
parent bf8aa502f9
commit 43bcf1051d
3 changed files with 69 additions and 0 deletions

View File

@@ -194,6 +194,8 @@ func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVi
ct.PopScope()
case clang.CursorStructDecl:
ct.ProcessStruct(cursor)
case clang.CursorUnionDecl:
ct.ProcessUnion(cursor)
case clang.CursorFunctionDecl:
ct.curFile.Decls = append(ct.curFile.Decls, ct.ProcessFunc(cursor))
case clang.CursorNamespace:
@@ -435,6 +437,11 @@ func (ct *Converter) ProcessStruct(cursor clang.Cursor) {
ct.curFile.Decls = append(ct.curFile.Decls, structDecl)
}
func (ct *Converter) ProcessUnion(cursor clang.Cursor) {
structDecl := ct.ProcessStructOrClass(cursor, ast.Union)
ct.curFile.Decls = append(ct.curFile.Decls, structDecl)
}
func (ct *Converter) ProcessClass(cursor clang.Cursor) {
classDecl := ct.ProcessStructOrClass(cursor, ast.Class)
// other logic for class

View File

@@ -10,6 +10,7 @@ func main() {
TestComment()
TestStructDecl()
TestClassDecl()
TestUnionDecl()
TestEnumDecl()
}
@@ -100,6 +101,16 @@ func TestStructDecl() {
test.RunTest("TestStructDecl", testCases)
}
func TestUnionDecl() {
testCases := []string{
`union A {
int a;
int b;
};`,
}
test.RunTest("TestUnionDecl", testCases)
}
func TestClassDecl() {
testCases := []string{
`class A {

View File

@@ -1296,6 +1296,57 @@ TestClassDecl Case 2:
}
}
TestUnionDecl Case 1:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Tag": 1,
"Fields": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": []
}],
"includes": [],
"macros": []
}
}
TestEnumDecl Case 1:
{
"temp.h": {