llcppsigfetch:null processing

This commit is contained in:
luoliwoshang
2024-09-02 15:47:05 +08:00
parent da6706cb93
commit 86b50b0a93
11 changed files with 278 additions and 633 deletions

View File

@@ -129,17 +129,20 @@ func (ct *Converter) CreateDeclBase(cursor clang.Cursor) ast.DeclBase {
rawComment := cursor.RawCommentText()
defer rawComment.Dispose()
res := ast.DeclBase{
Loc: &ct.curLoc,
Parent: buildScopingExpr(cursor.SemanticParent()),
}
commentGroup := &ast.CommentGroup{}
if rawComment.CStr() != nil {
commentGroup = ct.ParseComment(c.GoString(rawComment.CStr()))
if len(commentGroup.List) > 0 {
res.Doc = commentGroup
}
}
loc := ct.curLoc
return ast.DeclBase{
Loc: &loc,
Parent: buildScopingExpr(cursor.SemanticParent()),
Doc: commentGroup,
}
return res
}
func (ct *Converter) ParseComment(rawComment string) *ast.CommentGroup {
@@ -248,7 +251,7 @@ func (ct *Converter) ProcessFunctionType(t clang.Type) *ast.FuncType {
// This would return CursorNoDeclFound
ret := ct.ProcessType(t.ResultType())
params := &ast.FieldList{List: make([]*ast.Field, 0)}
params := &ast.FieldList{}
numArgs := t.NumArgTypes()
for i := 0; i < int(numArgs); i++ {
argType := t.ArgType(c.Uint(i))
@@ -256,7 +259,6 @@ func (ct *Converter) ProcessFunctionType(t clang.Type) *ast.FuncType {
Type: ct.ProcessType(argType),
})
}
if t.IsFunctionTypeVariadic() != 0 {
params.List = append(params.List, &ast.Field{
Type: &ast.Variadic{},
@@ -452,10 +454,12 @@ func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan
// int a, b;
// };
field := &ast.Field{
Doc: &ast.CommentGroup{},
Comment: &ast.CommentGroup{},
Type: ctx.converter.ProcessType(cursor.Type()),
Names: []*ast.Ident{{Name: c.GoString(paramName.CStr())}},
// todo(zzy):comment & doc
Type: ctx.converter.ProcessType(cursor.Type()),
}
if paramName.CStr() != nil {
field.Names = []*ast.Ident{{Name: c.GoString(paramName.CStr())}}
}
if cursor.Kind == clang.CursorFieldDecl {
@@ -470,14 +474,15 @@ func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan
fieldname := cursor.String()
defer fieldname.Dispose()
//todo(zzy): comment & doc
ctx.params.List = append(ctx.params.List, &ast.Field{
Doc: &ast.CommentGroup{},
Comment: &ast.CommentGroup{},
field := &ast.Field{
Type: ctx.converter.ProcessType(cursor.Type()),
Access: ast.AccessSpecifier(cursor.CXXAccessSpecifier()),
IsStatic: true,
Names: []*ast.Ident{{Name: c.GoString(fieldname.CStr())}},
})
}
if fieldname.CStr() != nil && c.GoString(fieldname.CStr()) != "" {
field.Names = []*ast.Ident{{Name: c.GoString(fieldname.CStr())}}
}
ctx.params.List = append(ctx.params.List, field)
}
}
@@ -486,7 +491,7 @@ func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan
// For Record Type(struct,union ...) & Func 's FieldList
func (ct *Converter) ProcessFieldList(cursor clang.Cursor) *ast.FieldList {
params := &ast.FieldList{List: []*ast.Field{}}
params := &ast.FieldList{}
ctx := &visitFieldContext{
params: params,
converter: ct,

View File

@@ -9,10 +9,7 @@ TestClassDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -30,14 +27,8 @@ TestClassDecl Case 1:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -51,14 +42,8 @@ TestClassDecl Case 1:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -85,10 +70,7 @@ TestClassDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -106,14 +88,8 @@ TestClassDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": true,
"Access": 1,
"Names": [{
@@ -127,14 +103,8 @@ TestClassDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -149,10 +119,7 @@ TestClassDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -172,14 +139,8 @@ TestClassDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -193,14 +154,8 @@ TestClassDecl Case 2:
"Kind": 8,
"Flags": 16
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -241,10 +196,7 @@ TestClassDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -255,7 +207,7 @@ TestClassDecl Case 3:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": [{
"_Type": "FuncDecl",
@@ -263,10 +215,7 @@ TestClassDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -279,7 +228,7 @@ TestClassDecl Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -301,10 +250,7 @@ TestClassDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -317,7 +263,7 @@ TestClassDecl Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -339,10 +285,7 @@ TestClassDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -355,7 +298,7 @@ TestClassDecl Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -377,10 +320,7 @@ TestClassDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -393,7 +333,7 @@ TestClassDecl Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -427,10 +367,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -441,7 +378,7 @@ TestClassDecl Case 4:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": [{
"_Type": "FuncDecl",
@@ -449,10 +386,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Base"
@@ -465,7 +399,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -487,10 +421,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Base"
@@ -503,7 +434,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -525,10 +456,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Base"
@@ -541,7 +469,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -565,10 +493,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -579,7 +504,7 @@ TestClassDecl Case 4:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": [{
"_Type": "FuncDecl",
@@ -587,10 +512,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Derived"
@@ -603,7 +525,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -625,10 +547,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Derived"
@@ -641,7 +560,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -663,10 +582,7 @@ TestClassDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "Derived"
@@ -679,7 +595,7 @@ TestClassDecl Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -713,10 +629,7 @@ TestClassDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -730,7 +643,7 @@ TestClassDecl Case 5:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": []
}
@@ -740,10 +653,7 @@ TestClassDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "ScopingExpr",
"X": {
@@ -763,7 +673,7 @@ TestClassDecl Case 5:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",

View File

@@ -9,10 +9,7 @@ TestDoc Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -22,7 +19,7 @@ TestDoc Case 1:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -54,10 +51,7 @@ TestDoc Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -67,7 +61,7 @@ TestDoc Case 2:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -115,7 +109,7 @@ TestDoc Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -163,7 +157,7 @@ TestDoc Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -211,7 +205,7 @@ TestDoc Case 5:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -262,7 +256,7 @@ TestDoc Case 6:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -313,7 +307,7 @@ TestDoc Case 7:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -364,7 +358,7 @@ TestDoc Case 8:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -421,7 +415,7 @@ TestDoc Case 9:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",

View File

@@ -9,10 +9,7 @@ TestEnumDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -71,10 +68,7 @@ TestEnumDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -133,10 +127,7 @@ TestEnumDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",

View File

@@ -9,10 +9,7 @@ TestFuncDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -22,7 +19,7 @@ TestFuncDecl Case 1:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -54,10 +51,7 @@ TestFuncDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -74,14 +68,8 @@ TestFuncDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -120,10 +108,7 @@ TestFuncDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -142,7 +127,7 @@ TestFuncDecl Case 3:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -150,14 +135,8 @@ TestFuncDecl Case 3:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -196,10 +175,7 @@ TestFuncDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -216,14 +192,8 @@ TestFuncDecl Case 4:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -237,14 +207,8 @@ TestFuncDecl Case 4:
"Kind": 8,
"Flags": 16
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -286,10 +250,7 @@ TestFuncDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -306,14 +267,8 @@ TestFuncDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{
@@ -327,14 +282,8 @@ TestFuncDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": [{

View File

@@ -9,10 +9,7 @@ TestScope Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -22,7 +19,7 @@ TestScope Case 1:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -54,10 +51,7 @@ TestScope Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "a"
@@ -70,7 +64,7 @@ TestScope Case 2:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -102,10 +96,7 @@ TestScope Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "ScopingExpr",
"X": {
@@ -125,7 +116,7 @@ TestScope Case 3:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -157,10 +148,7 @@ TestScope Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -171,7 +159,7 @@ TestScope Case 4:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": [{
"_Type": "FuncDecl",
@@ -179,10 +167,7 @@ TestScope Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "a"
@@ -195,7 +180,7 @@ TestScope Case 4:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",
@@ -229,10 +214,7 @@ TestScope Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "a"
@@ -246,7 +228,7 @@ TestScope Case 5:
"Tag": 3,
"Fields": {
"_Type": "FieldList",
"List": []
"List": null
},
"Methods": [{
"_Type": "FuncDecl",
@@ -254,10 +236,7 @@ TestScope Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "ScopingExpr",
"X": {
@@ -277,7 +256,7 @@ TestScope Case 5:
"_Type": "FuncType",
"Params": {
"_Type": "FieldList",
"List": []
"List": null
},
"Ret": {
"_Type": "BuiltinType",

View File

@@ -9,10 +9,7 @@ TestStructDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
@@ -27,14 +24,8 @@ TestStructDecl Case 1:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -61,10 +52,7 @@ TestStructDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -82,14 +70,8 @@ TestStructDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -103,14 +85,8 @@ TestStructDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -137,10 +113,7 @@ TestStructDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -158,14 +131,8 @@ TestStructDecl Case 3:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -179,14 +146,8 @@ TestStructDecl Case 3:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -213,10 +174,7 @@ TestStructDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -234,14 +192,8 @@ TestStructDecl Case 4:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -267,7 +219,7 @@ TestStructDecl Case 4:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -279,7 +231,7 @@ TestStructDecl Case 4:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}]
},
"Ret": {
@@ -289,14 +241,8 @@ TestStructDecl Case 4:
}
}
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -323,10 +269,7 @@ TestStructDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -344,14 +287,8 @@ TestStructDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -372,14 +309,8 @@ TestStructDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -393,14 +324,8 @@ TestStructDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -414,14 +339,8 @@ TestStructDecl Case 5:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -432,14 +351,8 @@ TestStructDecl Case 5:
},
"Methods": []
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{

View File

@@ -9,10 +9,7 @@ TestTypeDefDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -39,10 +36,7 @@ TestTypeDefDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -59,10 +53,7 @@ TestTypeDefDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -88,10 +79,7 @@ TestTypeDefDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -108,10 +96,7 @@ TestTypeDefDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -131,10 +116,7 @@ TestTypeDefDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -165,10 +147,7 @@ TestTypeDefDecl Case 4:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -191,7 +170,7 @@ TestTypeDefDecl Case 4:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -203,7 +182,7 @@ TestTypeDefDecl Case 4:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -213,7 +192,7 @@ TestTypeDefDecl Case 4:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}]
},
"Ret": {
@@ -239,10 +218,7 @@ TestTypeDefDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -265,7 +241,7 @@ TestTypeDefDecl Case 5:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -277,7 +253,7 @@ TestTypeDefDecl Case 5:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}]
},
"Ret": {
@@ -293,10 +269,7 @@ TestTypeDefDecl Case 5:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -322,7 +295,7 @@ TestTypeDefDecl Case 5:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -337,7 +310,7 @@ TestTypeDefDecl Case 5:
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}]
},
"Ret": {
@@ -363,10 +336,7 @@ TestTypeDefDecl Case 6:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -387,14 +357,8 @@ TestTypeDefDecl Case 6:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 3,
"Names": [{
@@ -411,10 +375,7 @@ TestTypeDefDecl Case 6:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -444,10 +405,7 @@ TestTypeDefDecl Case 6:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"
@@ -480,10 +438,7 @@ TestTypeDefDecl Case 6:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": {
"_Type": "Ident",
"Name": "A"

View File

@@ -9,10 +9,7 @@ TestUnionDecl Case 1:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": null,
"Type": {
@@ -27,14 +24,8 @@ TestUnionDecl Case 1:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -48,14 +39,8 @@ TestUnionDecl Case 1:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -82,10 +67,7 @@ TestUnionDecl Case 2:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -103,14 +85,8 @@ TestUnionDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -124,14 +100,8 @@ TestUnionDecl Case 2:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -158,10 +128,7 @@ TestUnionDecl Case 3:
"_Type": "Location",
"File": "temp.h"
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Parent": null,
"Name": {
"_Type": "Ident",
@@ -179,14 +146,8 @@ TestUnionDecl Case 3:
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -200,14 +161,8 @@ TestUnionDecl Case 3:
"Kind": 8,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -228,14 +183,8 @@ TestUnionDecl Case 3:
"Kind": 2,
"Flags": 1
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -249,14 +198,8 @@ TestUnionDecl Case 3:
"Kind": 6,
"Flags": 32
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -267,14 +210,8 @@ TestUnionDecl Case 3:
},
"Methods": []
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{

View File

@@ -141,14 +141,8 @@ Type: struct (unnamed struct at temp.h:1:1):
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -186,14 +180,8 @@ Type: union (unnamed union at temp.h:1:1):
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 1,
"Names": [{
@@ -261,14 +249,8 @@ Type: class (unnamed class at temp.h:1:1):
"Kind": 6,
"Flags": 0
},
"Doc": {
"_Type": "CommentGroup",
"List": []
},
"Comment": {
"_Type": "CommentGroup",
"List": []
},
"Doc": null,
"Comment": null,
"IsStatic": false,
"Access": 3,
"Names": [{
@@ -339,7 +321,7 @@ Type: int (*)(int, char):
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}, {
"_Type": "Field",
"Type": {
@@ -351,7 +333,7 @@ Type: int (*)(int, char):
"Comment": null,
"IsStatic": false,
"Access": 0,
"Names": []
"Names": null
}]
},
"Ret": {

View File

@@ -14,47 +14,89 @@ func MarshalASTFiles(files map[string]*ast.File) *cjson.JSON {
return root
}
func MarshalASTFile(file *ast.File) *cjson.JSON {
root := cjson.Object()
decls := cjson.Array()
for _, decl := range file.Decls {
decls.AddItem(MarshalASTDecl(decl))
func MarshalDeclList(list []ast.Decl) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root.SetItem(c.Str("_Type"), stringField("File"))
root.SetItem(c.Str("decls"), decls)
// json:includes,omitempty
if file.Includes != nil {
includes := cjson.Array()
for _, i := range file.Includes {
include := cjson.Object()
include.SetItem(c.Str("_Type"), stringField("Include"))
include.SetItem(c.Str("Path"), stringField(i.Path))
includes.AddItem(include)
}
root.SetItem(c.Str("includes"), includes)
}
// json:macros,omitempty
if file.Macros != nil {
macros := cjson.Array()
for _, m := range file.Macros {
marco := cjson.Object()
marco.SetItem(c.Str("_Type"), stringField("Macro"))
marco.SetItem(c.Str("Name"), stringField(m.Name))
tokens := cjson.Array()
for _, tok := range m.Tokens {
tokens.AddItem(Token(tok))
}
marco.SetItem(c.Str("Tokens"), tokens)
macros.AddItem(marco)
}
root.SetItem(c.Str("macros"), macros)
root := cjson.Array()
for _, item := range list {
root.AddItem(MarshalASTDecl(item))
}
return root
}
func Token(tok *ast.Token) *cjson.JSON {
func MarshalFieldList(list []*ast.Field) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array()
for _, item := range list {
root.AddItem(MarshalASTExpr(item))
}
return root
}
func MarshalIncludeList(list []*ast.Include) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array()
for _, item := range list {
include := cjson.Object()
include.SetItem(c.Str("_Type"), stringField("Include"))
include.SetItem(c.Str("Path"), stringField(item.Path))
root.AddItem(include)
}
return root
}
func MarshalMacroList(list []*ast.Macro) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array()
for _, item := range list {
macro := cjson.Object()
macro.SetItem(c.Str("_Type"), stringField("Macro"))
macro.SetItem(c.Str("Name"), stringField(item.Name))
macro.SetItem(c.Str("Tokens"), MarshalTokenList(item.Tokens))
root.AddItem(macro)
}
return root
}
func MarshalTokenList(list []*ast.Token) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array()
for _, item := range list {
root.AddItem(MarshalToken(item))
}
return root
}
func MarshalIdentList(list []*ast.Ident) *cjson.JSON {
if list == nil {
return cjson.Null()
}
root := cjson.Array()
for _, item := range list {
root.AddItem(MarshalASTExpr(item))
}
return root
}
func MarshalASTFile(file *ast.File) *cjson.JSON {
root := cjson.Object()
root.SetItem(c.Str("_Type"), stringField("File"))
root.SetItem(c.Str("decls"), MarshalDeclList(file.Decls))
root.SetItem(c.Str("includes"), MarshalIncludeList(file.Includes))
root.SetItem(c.Str("macros"), MarshalMacroList(file.Macros))
return root
}
func MarshalToken(tok *ast.Token) *cjson.JSON {
root := cjson.Object()
root.SetItem(c.Str("_Type"), stringField("Token"))
root.SetItem(c.Str("Token"), numberField(uint(tok.Token)))
@@ -105,7 +147,6 @@ func MarshalASTDeclBase(decl ast.DeclBase, root *cjson.JSON) {
loc.SetItem(c.Str("_Type"), stringField("Location"))
loc.SetItem(c.Str("File"), stringField(decl.Loc.File))
root.SetItem(c.Str("Loc"), loc)
root.SetItem(c.Str("Doc"), MarshalASTExpr(decl.Doc))
root.SetItem(c.Str("Parent"), MarshalASTExpr(decl.Parent))
}
@@ -144,14 +185,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
root.SetItem(c.Str("Ret"), MarshalASTExpr(d.Ret))
case *ast.FieldList:
root.SetItem(c.Str("_Type"), stringField("FieldList"))
if d == nil {
return cjson.Null()
}
list := cjson.Array()
for _, f := range d.List {
list.AddItem(MarshalASTExpr(f))
}
root.SetItem(c.Str("List"), list)
root.SetItem(c.Str("List"), MarshalFieldList(d.List))
case *ast.Field:
root.SetItem(c.Str("_Type"), stringField("Field"))
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
@@ -159,11 +193,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
root.SetItem(c.Str("Comment"), MarshalASTExpr(d.Comment))
root.SetItem(c.Str("IsStatic"), boolField(d.IsStatic))
root.SetItem(c.Str("Access"), numberField(uint(d.Access)))
names := cjson.Array()
for _, n := range d.Names {
names.AddItem(MarshalASTExpr(n))
}
root.SetItem(c.Str("Names"), names)
root.SetItem(c.Str("Names"), MarshalIdentList(d.Names))
case *ast.Variadic:
root.SetItem(c.Str("_Type"), stringField("Variadic"))
case *ast.Ident: