llcppsigfetch:basic class & struct 's process
This commit is contained in:
@@ -168,9 +168,9 @@ func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVi
|
|||||||
ct.ProcessClass(cursor)
|
ct.ProcessClass(cursor)
|
||||||
ct.PopScope()
|
ct.PopScope()
|
||||||
case clang.CursorStructDecl:
|
case clang.CursorStructDecl:
|
||||||
// todo(zzy)
|
ct.ProcessStruct(cursor)
|
||||||
case clang.CursorFunctionDecl:
|
case clang.CursorFunctionDecl:
|
||||||
ct.ProcessFunc(cursor)
|
ct.curFile.Decls = append(ct.curFile.Decls, ct.ProcessFunc(cursor))
|
||||||
case clang.CursorNamespace:
|
case clang.CursorNamespace:
|
||||||
ct.PushScope(cursor)
|
ct.PushScope(cursor)
|
||||||
clang.VisitChildren(cursor, visit, c.Pointer(ct))
|
clang.VisitChildren(cursor, visit, c.Pointer(ct))
|
||||||
@@ -218,45 +218,51 @@ func (ct *Converter) ProcessType(t clang.Type) ast.Expr {
|
|||||||
return expr
|
return expr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *Converter) ProcessFunc(cursor clang.Cursor) {
|
func (ct *Converter) ProcessFunc(cursor clang.Cursor) *ast.FuncDecl {
|
||||||
name := cursor.String()
|
name := cursor.String()
|
||||||
defer name.Dispose()
|
defer name.Dispose()
|
||||||
|
|
||||||
// function type will only collect return type
|
// function type will only collect return type
|
||||||
// ProcessType can't get the field names,will collect in follows
|
// ProcessType can't get the field names,will collect in follows
|
||||||
funcType, ok := ct.ProcessType(cursor.Type()).(*ast.FuncType)
|
funcType, ok := ct.ProcessType(cursor.Type()).(*ast.FuncType)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("failed to process function type")
|
fmt.Println("failed to process function type")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
params := ct.ProcessFuncParams(cursor)
|
params := ct.ProcessFieldList(cursor)
|
||||||
funcType.Params = params
|
funcType.Params = params
|
||||||
fn := &ast.FuncDecl{
|
fn := &ast.FuncDecl{
|
||||||
DeclBase: ct.CreateDeclBase(cursor),
|
DeclBase: ct.CreateDeclBase(cursor),
|
||||||
Name: &ast.Ident{Name: c.GoString(name.CStr())},
|
Name: &ast.Ident{Name: c.GoString(name.CStr())},
|
||||||
Type: funcType,
|
Type: funcType,
|
||||||
}
|
}
|
||||||
ct.curFile.Decls = append(ct.curFile.Decls, fn)
|
return fn
|
||||||
}
|
}
|
||||||
|
|
||||||
type visitParamContext struct {
|
type visitFieldContext struct {
|
||||||
params *ast.FieldList
|
params *ast.FieldList
|
||||||
converter *Converter
|
converter *Converter
|
||||||
}
|
}
|
||||||
|
|
||||||
// visit top decls (struct,class,function,enum & marco,include)
|
func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult {
|
||||||
func visitParamDecl(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult {
|
ctx := (*visitFieldContext)(clientData)
|
||||||
ctx := (*visitParamContext)(clientData)
|
if cursor.Kind == clang.CursorParmDecl || cursor.Kind == clang.CursorFieldDecl {
|
||||||
if cursor.Kind == clang.CursorParmDecl {
|
|
||||||
paramName := cursor.String()
|
paramName := cursor.String()
|
||||||
defer paramName.Dispose()
|
defer paramName.Dispose()
|
||||||
argType := ctx.converter.ProcessType(cursor.Type())
|
argType := ctx.converter.ProcessType(cursor.Type())
|
||||||
|
|
||||||
// In C language, parameter lists do not have similar parameter grouping in Go.
|
// In C language, parameter lists do not have similar parameter grouping in Go.
|
||||||
// func foo(a, b int)
|
// func foo(a, b int)
|
||||||
|
|
||||||
|
// For follows struct, it will also parse to two FieldDecl
|
||||||
|
// struct A {
|
||||||
|
// int a, b;
|
||||||
|
// };
|
||||||
ctx.params.List = append(ctx.params.List,
|
ctx.params.List = append(ctx.params.List,
|
||||||
&ast.Field{
|
&ast.Field{
|
||||||
Type: argType,
|
//todo(zzy): comment & doc
|
||||||
|
Doc: &ast.CommentGroup{},
|
||||||
|
Comment: &ast.CommentGroup{},
|
||||||
|
Type: argType,
|
||||||
Names: []*ast.Ident{
|
Names: []*ast.Ident{
|
||||||
{Name: c.GoString(paramName.CStr())},
|
{Name: c.GoString(paramName.CStr())},
|
||||||
},
|
},
|
||||||
@@ -265,18 +271,68 @@ func visitParamDecl(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan
|
|||||||
return clang.ChildVisit_Continue
|
return clang.ChildVisit_Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *Converter) ProcessFuncParams(cursor clang.Cursor) *ast.FieldList {
|
func (ct *Converter) ProcessFieldList(cursor clang.Cursor) *ast.FieldList {
|
||||||
params := &ast.FieldList{List: []*ast.Field{}}
|
params := &ast.FieldList{List: []*ast.Field{}}
|
||||||
ctx := &visitParamContext{
|
ctx := &visitFieldContext{
|
||||||
params: params,
|
params: params,
|
||||||
converter: ct,
|
converter: ct,
|
||||||
}
|
}
|
||||||
clang.VisitChildren(cursor, visitParamDecl, c.Pointer(ctx))
|
clang.VisitChildren(cursor, visitFieldList, c.Pointer(ctx))
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type visitMethodsContext struct {
|
||||||
|
methods *[]*ast.FuncDecl
|
||||||
|
converter *Converter
|
||||||
|
}
|
||||||
|
|
||||||
|
func visitMethods(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult {
|
||||||
|
ctx := (*visitMethodsContext)(clientData)
|
||||||
|
if cursor.Kind == clang.CursorCXXMethod {
|
||||||
|
method := ctx.converter.ProcessFunc(cursor)
|
||||||
|
if method != nil {
|
||||||
|
*ctx.methods = append(*ctx.methods, method)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clang.ChildVisit_Continue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Converter) ProcessMethods(cursor clang.Cursor) []*ast.FuncDecl {
|
||||||
|
methods := make([]*ast.FuncDecl, 0)
|
||||||
|
ctx := &visitMethodsContext{
|
||||||
|
methods: &methods,
|
||||||
|
converter: ct,
|
||||||
|
}
|
||||||
|
clang.VisitChildren(cursor, visitMethods, c.Pointer(ctx))
|
||||||
|
return methods
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Converter) ProcessStructOrClass(cursor clang.Cursor, tag ast.Tag) *ast.TypeDecl {
|
||||||
|
name := cursor.String()
|
||||||
|
defer name.Dispose()
|
||||||
|
|
||||||
|
fields := ct.ProcessFieldList(cursor)
|
||||||
|
methods := ct.ProcessMethods(cursor)
|
||||||
|
|
||||||
|
decl := &ast.TypeDecl{
|
||||||
|
DeclBase: ct.CreateDeclBase(cursor),
|
||||||
|
Tag: tag,
|
||||||
|
Fields: fields,
|
||||||
|
Methods: methods,
|
||||||
|
}
|
||||||
|
|
||||||
|
return decl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Converter) ProcessStruct(cursor clang.Cursor) {
|
||||||
|
structDecl := ct.ProcessStructOrClass(cursor, ast.Struct)
|
||||||
|
ct.curFile.Decls = append(ct.curFile.Decls, structDecl)
|
||||||
|
}
|
||||||
|
|
||||||
func (ct *Converter) ProcessClass(cursor clang.Cursor) {
|
func (ct *Converter) ProcessClass(cursor clang.Cursor) {
|
||||||
println("todo: Process class")
|
classDecl := ct.ProcessStructOrClass(cursor, ast.Class)
|
||||||
|
// other logic for class
|
||||||
|
ct.curFile.Decls = append(ct.curFile.Decls, classDecl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *Converter) ProcessBuiltinType(t clang.Type) *ast.BuiltinType {
|
func (ct *Converter) ProcessBuiltinType(t clang.Type) *ast.BuiltinType {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ func main() {
|
|||||||
TestFuncDecl()
|
TestFuncDecl()
|
||||||
TestScope()
|
TestScope()
|
||||||
TestComment()
|
TestComment()
|
||||||
|
TestStructDecl()
|
||||||
|
TestClassDecl()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFuncDecl() {
|
func TestFuncDecl() {
|
||||||
@@ -54,6 +56,14 @@ func TestScope() {
|
|||||||
void foo();
|
void foo();
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
`class a {
|
||||||
|
void foo();
|
||||||
|
};`,
|
||||||
|
`namespace a {
|
||||||
|
class b {
|
||||||
|
void foo();
|
||||||
|
};
|
||||||
|
}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, content := range testCases {
|
for i, content := range testCases {
|
||||||
@@ -73,6 +83,7 @@ func TestScope() {
|
|||||||
converter.Dispose()
|
converter.Dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestComment() {
|
func TestComment() {
|
||||||
testCases := []string{
|
testCases := []string{
|
||||||
`// not read comment 1
|
`// not read comment 1
|
||||||
@@ -118,3 +129,68 @@ void foo();`,
|
|||||||
converter.Dispose()
|
converter.Dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructDecl() {
|
||||||
|
testCases := []string{
|
||||||
|
`struct A {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};`,
|
||||||
|
`struct A {
|
||||||
|
int a, b;
|
||||||
|
};`,
|
||||||
|
`struct A {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
float foo(int a,double b);;
|
||||||
|
};`,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, content := range testCases {
|
||||||
|
converter, err := parse.NewConverter(content, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = converter.Convert()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
json := converter.GetFilesJSON()
|
||||||
|
c.Printf(c.Str("TestStructDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||||
|
|
||||||
|
converter.Dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClassDecl() {
|
||||||
|
testCases := []string{
|
||||||
|
`class A {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};`,
|
||||||
|
`class A {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
float foo(int a,double b);;
|
||||||
|
};`,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, content := range testCases {
|
||||||
|
converter, err := parse.NewConverter(content, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = converter.Convert()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
json := converter.GetFilesJSON()
|
||||||
|
c.Printf(c.Str("TestClassDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||||
|
|
||||||
|
converter.Dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,8 +51,12 @@ TestFuncDecl Case 2:
|
|||||||
"Kind": 6,
|
"Kind": 6,
|
||||||
"Flags": 0
|
"Flags": 0
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "a"
|
"Name": "a"
|
||||||
}]
|
}]
|
||||||
@@ -91,8 +95,12 @@ TestFuncDecl Case 3:
|
|||||||
"Kind": 6,
|
"Kind": 6,
|
||||||
"Flags": 0
|
"Flags": 0
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "a"
|
"Name": "a"
|
||||||
}]
|
}]
|
||||||
@@ -101,8 +109,12 @@ TestFuncDecl Case 3:
|
|||||||
"Kind": 8,
|
"Kind": 8,
|
||||||
"Flags": 16
|
"Flags": 16
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "b"
|
"Name": "b"
|
||||||
}]
|
}]
|
||||||
@@ -143,8 +155,12 @@ TestFuncDecl Case 4:
|
|||||||
"Flags": 1
|
"Flags": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "str"
|
"Name": "str"
|
||||||
}]
|
}]
|
||||||
@@ -153,8 +169,12 @@ TestFuncDecl Case 4:
|
|||||||
"Kind": 8,
|
"Kind": 8,
|
||||||
"Flags": 16
|
"Flags": 16
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "x"
|
"Name": "x"
|
||||||
}]
|
}]
|
||||||
@@ -195,8 +215,12 @@ TestFuncDecl Case 5:
|
|||||||
"Flags": 1
|
"Flags": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "str"
|
"Name": "str"
|
||||||
}]
|
}]
|
||||||
@@ -205,8 +229,12 @@ TestFuncDecl Case 5:
|
|||||||
"Kind": 8,
|
"Kind": 8,
|
||||||
"Flags": 16
|
"Flags": 16
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "x"
|
"Name": "x"
|
||||||
}]
|
}]
|
||||||
@@ -253,8 +281,12 @@ TestFuncDecl Case 6:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "str"
|
"Name": "str"
|
||||||
}]
|
}]
|
||||||
@@ -263,8 +295,12 @@ TestFuncDecl Case 6:
|
|||||||
"Kind": 8,
|
"Kind": 8,
|
||||||
"Flags": 16
|
"Flags": 16
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "x"
|
"Name": "x"
|
||||||
}]
|
}]
|
||||||
@@ -308,8 +344,12 @@ TestFuncDecl Case 7:
|
|||||||
},
|
},
|
||||||
"Len": null
|
"Len": null
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "str"
|
"Name": "str"
|
||||||
}]
|
}]
|
||||||
@@ -318,8 +358,12 @@ TestFuncDecl Case 7:
|
|||||||
"Kind": 8,
|
"Kind": 8,
|
||||||
"Flags": 16
|
"Flags": 16
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "x"
|
"Name": "x"
|
||||||
}]
|
}]
|
||||||
@@ -372,8 +416,12 @@ TestFuncDecl Case 8:
|
|||||||
"Value": "3"
|
"Value": "3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Doc": null,
|
"Doc": {
|
||||||
"Comment": null,
|
"List": []
|
||||||
|
},
|
||||||
|
"Comment": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
"Names": [{
|
"Names": [{
|
||||||
"Name": "arr"
|
"Name": "arr"
|
||||||
}]
|
}]
|
||||||
@@ -491,6 +539,110 @@ TestScope Case 3:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestScope Case 4:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "a"
|
||||||
|
},
|
||||||
|
"Tag": 3,
|
||||||
|
"Fields": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Methods": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "a"
|
||||||
|
},
|
||||||
|
"Name": {
|
||||||
|
"Name": "foo"
|
||||||
|
},
|
||||||
|
"Type": {
|
||||||
|
"Params": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Ret": {
|
||||||
|
"Kind": 0,
|
||||||
|
"Flags": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"includes": [],
|
||||||
|
"macros": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestScope Case 5:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"X": {
|
||||||
|
"Name": "b"
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Tag": 3,
|
||||||
|
"Fields": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Methods": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"X": {
|
||||||
|
"Name": "b"
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Name": {
|
||||||
|
"Name": "foo"
|
||||||
|
},
|
||||||
|
"Type": {
|
||||||
|
"Params": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Ret": {
|
||||||
|
"Kind": 0,
|
||||||
|
"Flags": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"includes": [],
|
||||||
|
"macros": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TestComment Case 1:
|
TestComment Case 1:
|
||||||
{
|
{
|
||||||
"temp.h": {
|
"temp.h": {
|
||||||
@@ -787,6 +939,363 @@ TestComment Case 9:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestStructDecl Case 1:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": null,
|
||||||
|
"Tag": 0,
|
||||||
|
"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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestStructDecl Case 2:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": null,
|
||||||
|
"Tag": 0,
|
||||||
|
"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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestStructDecl Case 3:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": null,
|
||||||
|
"Tag": 0,
|
||||||
|
"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": [{
|
||||||
|
"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"
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"Ret": {
|
||||||
|
"Kind": 8,
|
||||||
|
"Flags": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"includes": [],
|
||||||
|
"macros": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestClassDecl Case 1:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "A"
|
||||||
|
},
|
||||||
|
"Tag": 3,
|
||||||
|
"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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestClassDecl Case 2:
|
||||||
|
{
|
||||||
|
"temp.h": {
|
||||||
|
"path": "temp.h",
|
||||||
|
"decls": [{
|
||||||
|
"Loc": {
|
||||||
|
"File": "temp.h"
|
||||||
|
},
|
||||||
|
"Doc": {
|
||||||
|
"List": []
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"Name": "A"
|
||||||
|
},
|
||||||
|
"Tag": 3,
|
||||||
|
"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": [{
|
||||||
|
"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"
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"Ret": {
|
||||||
|
"Kind": 8,
|
||||||
|
"Flags": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"includes": [],
|
||||||
|
"macros": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#stderr
|
#stderr
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,15 @@ func (ct *Converter) DeclJSON(decl ast.Decl) *cjson.JSON {
|
|||||||
ct.DeclBaseJSON(d.DeclBase, root)
|
ct.DeclBaseJSON(d.DeclBase, root)
|
||||||
root.SetItem(c.Str("Name"), ct.TypeJSON(d.Name))
|
root.SetItem(c.Str("Name"), ct.TypeJSON(d.Name))
|
||||||
root.SetItem(c.Str("Type"), ct.TypeJSON(d.Type))
|
root.SetItem(c.Str("Type"), ct.TypeJSON(d.Type))
|
||||||
|
case *ast.TypeDecl:
|
||||||
|
ct.DeclBaseJSON(d.DeclBase, root)
|
||||||
|
root.SetItem(c.Str("Tag"), cjson.Number(float64(d.Tag)))
|
||||||
|
root.SetItem(c.Str("Fields"), ct.TypeJSON(d.Fields))
|
||||||
|
methods := cjson.Array()
|
||||||
|
for _, m := range d.Methods {
|
||||||
|
methods.AddItem(ct.DeclJSON(m))
|
||||||
|
}
|
||||||
|
root.SetItem(c.Str("Methods"), methods)
|
||||||
}
|
}
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user