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{ decl := &ast.TypeDecl{
DeclBase: ct.CreateDeclBase(cursor), DeclBase: ct.CreateDeclBase(cursor),
Tag: tag,
Name: name, Name: name,
Type: &ast.RecordType{
Tag: tag,
Fields: fields, Fields: fields,
Methods: methods, Methods: methods,
},
} }
return decl return decl

View File

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

View File

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