llcppsigfetch:record type

This commit is contained in:
luoliwoshang
2024-08-22 09:51:14 +08:00
parent e09c5fcb3c
commit d4fa379f11
3 changed files with 449 additions and 419 deletions

View File

@@ -463,10 +463,12 @@ func (ct *Converter) ProcessRecord(cursor clang.Cursor, tag ast.Tag) *ast.TypeDe
decl := &ast.TypeDecl{
DeclBase: ct.CreateDeclBase(cursor),
Tag: tag,
Name: name,
Type: &ast.RecordType{
Tag: tag,
Fields: fields,
Methods: methods,
},
}
return decl

View File

@@ -553,10 +553,11 @@ TestScope Case 4:
"Parent": {
"Name": "a"
},
"Tag": 3,
"Name": {
"Name": "a"
},
"Type": {
"Tag": 3,
"Fields": {
"List": []
},
@@ -583,6 +584,7 @@ TestScope Case 4:
}
}
}]
}
}],
"includes": [],
"macros": []
@@ -608,10 +610,11 @@ TestScope Case 5:
"Name": "a"
}
},
"Tag": 3,
"Name": {
"Name": "b"
},
"Type": {
"Tag": 3,
"Fields": {
"List": []
},
@@ -643,6 +646,7 @@ TestScope Case 5:
}
}
}]
}
}],
"includes": [],
"macros": []
@@ -957,8 +961,9 @@ TestStructDecl Case 1:
"List": []
},
"Parent": null,
"Tag": 0,
"Name": null,
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
@@ -977,6 +982,7 @@ TestStructDecl Case 1:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -995,10 +1001,11 @@ TestStructDecl Case 2:
"List": []
},
"Parent": null,
"Tag": 0,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
@@ -1031,6 +1038,7 @@ TestStructDecl Case 2:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -1049,10 +1057,11 @@ TestStructDecl Case 3:
"List": []
},
"Parent": null,
"Tag": 0,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
@@ -1085,6 +1094,7 @@ TestStructDecl Case 3:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -1103,10 +1113,11 @@ TestStructDecl Case 4:
"List": []
},
"Parent": null,
"Tag": 0,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 0,
"Fields": {
"List": [{
"Type": {
@@ -1187,6 +1198,7 @@ TestStructDecl Case 4:
}
}
}]
}
}],
"includes": [],
"macros": []
@@ -1207,10 +1219,11 @@ TestClassDecl Case 1:
"Parent": {
"Name": "A"
},
"Tag": 3,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 3,
"Fields": {
"List": [{
"Type": {
@@ -1243,6 +1256,7 @@ TestClassDecl Case 1:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -1263,10 +1277,11 @@ TestClassDecl Case 2:
"Parent": {
"Name": "A"
},
"Tag": 3,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 3,
"Fields": {
"List": [{
"Type": {
@@ -1349,6 +1364,7 @@ TestClassDecl Case 2:
}
}
}]
}
}],
"includes": [],
"macros": []
@@ -1367,8 +1383,9 @@ TestUnionDecl Case 1:
"List": []
},
"Parent": null,
"Tag": 1,
"Name": null,
"Type": {
"Tag": 1,
"Fields": {
"List": [{
"Type": {
@@ -1401,6 +1418,7 @@ TestUnionDecl Case 1:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -1419,10 +1437,11 @@ TestUnionDecl Case 2:
"List": []
},
"Parent": null,
"Tag": 1,
"Name": {
"Name": "A"
},
"Type": {
"Tag": 1,
"Fields": {
"List": [{
"Type": {
@@ -1455,6 +1474,7 @@ TestUnionDecl Case 2:
}]
},
"Methods": []
}
}],
"includes": [],
"macros": []
@@ -1675,14 +1695,16 @@ TestTypeDefDecl Case 3:
"List": []
},
"Parent": null,
"Tag": 0,
"Name": {
"Name": "StructFoo"
},
"Type": {
"Tag": 0,
"Fields": {
"List": []
},
"Methods": []
}
}, {
"Loc": {
"File": "temp.h"
@@ -1691,14 +1713,16 @@ TestTypeDefDecl Case 3:
"List": []
},
"Parent": null,
"Tag": 1,
"Name": {
"Name": "UnionFoo"
},
"Type": {
"Tag": 1,
"Fields": {
"List": []
},
"Methods": []
}
}, {
"Loc": {
"File": "temp.h"
@@ -1709,14 +1733,16 @@ TestTypeDefDecl Case 3:
"Parent": {
"Name": "ClassFoo"
},
"Tag": 3,
"Name": {
"Name": "ClassFoo"
},
"Type": {
"Tag": 3,
"Fields": {
"List": []
},
"Methods": []
}
}, {
"Loc": {
"File": "temp.h"

View File

@@ -84,14 +84,8 @@ func MarshalASTDecl(decl ast.Decl) *cjson.JSON {
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
case *ast.TypeDecl:
MarshalASTDeclBase(d.DeclBase, root)
root.SetItem(c.Str("Tag"), cjson.Number(float64(d.Tag)))
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
root.SetItem(c.Str("Fields"), MarshalASTExpr(d.Fields))
methods := cjson.Array()
for _, m := range d.Methods {
methods.AddItem(MarshalASTDecl(m))
}
root.SetItem(c.Str("Methods"), methods)
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
}
return root
}
@@ -113,6 +107,14 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
root := cjson.Object()
switch d := t.(type) {
case *ast.RecordType:
root.SetItem(c.Str("Tag"), cjson.Number(float64(d.Tag)))
root.SetItem(c.Str("Fields"), MarshalASTExpr(d.Fields))
methods := cjson.Array()
for _, m := range d.Methods {
methods.AddItem(MarshalASTDecl(m))
}
root.SetItem(c.Str("Methods"), methods)
case *ast.FuncType:
root.SetItem(c.Str("Params"), MarshalASTExpr(d.Params))
root.SetItem(c.Str("Ret"), MarshalASTExpr(d.Ret))