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,
Fields: fields, Type: &ast.RecordType{
Methods: methods, Tag: tag,
Fields: fields,
Methods: methods,
},
} }
return decl return decl

View File

@@ -553,36 +553,38 @@ TestScope Case 4:
"Parent": { "Parent": {
"Name": "a" "Name": "a"
}, },
"Tag": 3,
"Name": { "Name": {
"Name": "a" "Name": "a"
}, },
"Fields": { "Type": {
"List": [] "Tag": 3,
}, "Fields": {
"Methods": [{ "List": []
"Loc": { },
"File": "temp.h" "Methods": [{
}, "Loc": {
"Doc": { "File": "temp.h"
"List": [] },
}, "Doc": {
"Parent": {
"Name": "a"
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [] "List": []
}, },
"Ret": { "Parent": {
"Kind": 0, "Name": "a"
"Flags": 0 },
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": []
},
"Ret": {
"Kind": 0,
"Flags": 0
}
} }
} }]
}] }
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -608,41 +610,43 @@ TestScope Case 5:
"Name": "a" "Name": "a"
} }
}, },
"Tag": 3,
"Name": { "Name": {
"Name": "b" "Name": "b"
}, },
"Fields": { "Type": {
"List": [] "Tag": 3,
}, "Fields": {
"Methods": [{ "List": []
"Loc": { },
"File": "temp.h" "Methods": [{
}, "Loc": {
"Doc": { "File": "temp.h"
"List": []
},
"Parent": {
"X": {
"Name": "b"
}, },
"Parent": { "Doc": {
"Name": "a"
}
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [] "List": []
}, },
"Ret": { "Parent": {
"Kind": 0, "X": {
"Flags": 0 "Name": "b"
},
"Parent": {
"Name": "a"
}
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": []
},
"Ret": {
"Kind": 0,
"Flags": 0
}
} }
} }]
}] }
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -957,26 +961,28 @@ TestStructDecl Case 1:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 0,
"Name": null, "Name": null,
"Fields": { "Type": {
"List": [{ "Tag": 0,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}] "Name": "a"
}, }]
"Methods": [] }]
},
"Methods": []
}
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -995,42 +1001,44 @@ TestStructDecl Case 2:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 0,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 0,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": { }]
"Kind": 6, }, {
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "b" },
}] "Names": [{
}] "Name": "b"
}, }]
"Methods": [] }]
},
"Methods": []
}
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1049,42 +1057,44 @@ TestStructDecl Case 3:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 0,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 0,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": { }]
"Kind": 6, }, {
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "b" },
}] "Names": [{
}] "Name": "b"
}, }]
"Methods": [] }]
},
"Methods": []
}
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1103,90 +1113,92 @@ TestStructDecl Case 4:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 0,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 0,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}] }]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
}, },
"Ret": { "Doc": {
"Kind": 8, "List": []
"Flags": 0 },
"Parent": null,
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Ret": {
"Kind": 8,
"Flags": 0
}
} }
} }]
}] }
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1207,42 +1219,44 @@ TestClassDecl Case 1:
"Parent": { "Parent": {
"Name": "A" "Name": "A"
}, },
"Tag": 3,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 3,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": { }]
"Kind": 6, }, {
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "b" },
}] "Names": [{
}] "Name": "b"
}, }]
"Methods": [] }]
},
"Methods": []
}
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1263,92 +1277,94 @@ TestClassDecl Case 2:
"Parent": { "Parent": {
"Name": "A" "Name": "A"
}, },
"Tag": 3,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 3,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": {
"Name": "A"
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}] }]
}, {
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Methods": [{
"Loc": {
"File": "temp.h"
}, },
"Ret": { "Doc": {
"Kind": 8, "List": []
"Flags": 0 },
"Parent": {
"Name": "A"
},
"Name": {
"Name": "foo"
},
"Type": {
"Params": {
"List": [{
"Type": {
"Kind": 6,
"Flags": 0
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "a"
}]
}, {
"Type": {
"Kind": 8,
"Flags": 16
},
"Doc": {
"List": []
},
"Comment": {
"List": []
},
"Names": [{
"Name": "b"
}]
}]
},
"Ret": {
"Kind": 8,
"Flags": 0
}
} }
} }]
}] }
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1367,40 +1383,42 @@ TestUnionDecl Case 1:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 1,
"Name": null, "Name": null,
"Fields": { "Type": {
"List": [{ "Tag": 1,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": { }]
"Kind": 6, }, {
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "b" },
}] "Names": [{
}] "Name": "b"
}, }]
"Methods": [] }]
},
"Methods": []
}
}], }],
"includes": [], "includes": [],
"macros": [] "macros": []
@@ -1419,42 +1437,44 @@ TestUnionDecl Case 2:
"List": [] "List": []
}, },
"Parent": null, "Parent": null,
"Tag": 1,
"Name": { "Name": {
"Name": "A" "Name": "A"
}, },
"Fields": { "Type": {
"List": [{ "Tag": 1,
"Type": { "Fields": {
"Kind": 6, "List": [{
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "a" },
}] "Names": [{
}, { "Name": "a"
"Type": { }]
"Kind": 6, }, {
"Flags": 0 "Type": {
}, "Kind": 6,
"Doc": { "Flags": 0
"List": [] },
}, "Doc": {
"Comment": { "List": []
"List": [] },
}, "Comment": {
"Names": [{ "List": []
"Name": "b" },
}] "Names": [{
}] "Name": "b"
}, }]
"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"
}, },
"Fields": { "Type": {
"List": [] "Tag": 0,
}, "Fields": {
"Methods": [] "List": []
},
"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"
}, },
"Fields": { "Type": {
"List": [] "Tag": 1,
}, "Fields": {
"Methods": [] "List": []
},
"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"
}, },
"Fields": { "Type": {
"List": [] "Tag": 3,
}, "Fields": {
"Methods": [] "List": []
},
"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))