llcppsigfetch:dump node type for unmarshal
This commit is contained in:
@@ -21,7 +21,7 @@ func MarshalASTFile(file *ast.File) *cjson.JSON {
|
||||
for _, decl := range file.Decls {
|
||||
decls.AddItem(MarshalASTDecl(decl))
|
||||
}
|
||||
|
||||
root.SetItem(c.Str("_Type"), stringField("File"))
|
||||
root.SetItem(c.Str("decls"), decls)
|
||||
|
||||
// json:includes,omitempty
|
||||
@@ -29,6 +29,7 @@ func MarshalASTFile(file *ast.File) *cjson.JSON {
|
||||
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)
|
||||
}
|
||||
@@ -40,6 +41,7 @@ func MarshalASTFile(file *ast.File) *cjson.JSON {
|
||||
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 {
|
||||
@@ -54,6 +56,7 @@ func MarshalASTFile(file *ast.File) *cjson.JSON {
|
||||
}
|
||||
func Token(tok *ast.Token) *cjson.JSON {
|
||||
root := cjson.Object()
|
||||
root.SetItem(c.Str("_Type"), stringField("Token"))
|
||||
root.SetItem(c.Str("Token"), numberField(uint(tok.Token)))
|
||||
root.SetItem(c.Str("Lit"), stringField(tok.Lit))
|
||||
return root
|
||||
@@ -66,14 +69,17 @@ func MarshalASTDecl(decl ast.Decl) *cjson.JSON {
|
||||
root := cjson.Object()
|
||||
switch d := decl.(type) {
|
||||
case *ast.EnumTypeDecl:
|
||||
root.SetItem(c.Str("_Type"), stringField("EnumTypeDecl"))
|
||||
MarshalASTDeclBase(d.DeclBase, root)
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
|
||||
case *ast.TypedefDecl:
|
||||
root.SetItem(c.Str("_Type"), stringField("TypedefDecl"))
|
||||
MarshalASTDeclBase(d.DeclBase, root)
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
|
||||
case *ast.FuncDecl:
|
||||
root.SetItem(c.Str("_Type"), stringField("FuncDecl"))
|
||||
MarshalASTDeclBase(d.DeclBase, root)
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
|
||||
@@ -86,6 +92,7 @@ func MarshalASTDecl(decl ast.Decl) *cjson.JSON {
|
||||
root.SetItem(c.Str("IsVirtual"), boolField(d.IsVirtual))
|
||||
root.SetItem(c.Str("IsOverride"), boolField(d.IsOverride))
|
||||
case *ast.TypeDecl:
|
||||
root.SetItem(c.Str("_Type"), stringField("TypeDecl"))
|
||||
MarshalASTDeclBase(d.DeclBase, root)
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
|
||||
@@ -95,6 +102,7 @@ func MarshalASTDecl(decl ast.Decl) *cjson.JSON {
|
||||
|
||||
func MarshalASTDeclBase(decl ast.DeclBase, root *cjson.JSON) {
|
||||
loc := cjson.Object()
|
||||
loc.SetItem(c.Str("_Type"), stringField("Location"))
|
||||
loc.SetItem(c.Str("File"), stringField(decl.Loc.File))
|
||||
root.SetItem(c.Str("Loc"), loc)
|
||||
|
||||
@@ -111,15 +119,18 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
|
||||
|
||||
switch d := t.(type) {
|
||||
case *ast.EnumType:
|
||||
root.SetItem(c.Str("_Type"), stringField("EnumType"))
|
||||
items := cjson.Array()
|
||||
for _, e := range d.Items {
|
||||
items.AddItem(MarshalASTExpr(e))
|
||||
}
|
||||
root.SetItem(c.Str("Items"), items)
|
||||
case *ast.EnumItem:
|
||||
root.SetItem(c.Str("_Type"), stringField("EnumItem"))
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Value"), MarshalASTExpr(d.Value))
|
||||
case *ast.RecordType:
|
||||
root.SetItem(c.Str("_Type"), stringField("RecordType"))
|
||||
root.SetItem(c.Str("Tag"), numberField(uint(d.Tag)))
|
||||
root.SetItem(c.Str("Fields"), MarshalASTExpr(d.Fields))
|
||||
methods := cjson.Array()
|
||||
@@ -128,9 +139,11 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
|
||||
}
|
||||
root.SetItem(c.Str("Methods"), methods)
|
||||
case *ast.FuncType:
|
||||
root.SetItem(c.Str("_Type"), stringField("FuncType"))
|
||||
root.SetItem(c.Str("Params"), MarshalASTExpr(d.Params))
|
||||
root.SetItem(c.Str("Ret"), MarshalASTExpr(d.Ret))
|
||||
case *ast.FieldList:
|
||||
root.SetItem(c.Str("_Type"), stringField("FieldList"))
|
||||
if d == nil {
|
||||
return cjson.Null()
|
||||
}
|
||||
@@ -140,6 +153,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
|
||||
}
|
||||
root.SetItem(c.Str("List"), list)
|
||||
case *ast.Field:
|
||||
root.SetItem(c.Str("_Type"), stringField("Field"))
|
||||
root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type))
|
||||
root.SetItem(c.Str("Doc"), MarshalASTExpr(d.Doc))
|
||||
root.SetItem(c.Str("Comment"), MarshalASTExpr(d.Comment))
|
||||
@@ -151,35 +165,46 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
|
||||
}
|
||||
root.SetItem(c.Str("Names"), names)
|
||||
case *ast.Variadic:
|
||||
root.SetItem(c.Str("_Type"), stringField("Variadic"))
|
||||
case *ast.Ident:
|
||||
root.SetItem(c.Str("_Type"), stringField("Ident"))
|
||||
if d == nil {
|
||||
return cjson.Null()
|
||||
}
|
||||
root.SetItem(c.Str("Name"), stringField(d.Name))
|
||||
case *ast.TagExpr:
|
||||
root.SetItem(c.Str("_Type"), stringField("TagExpr"))
|
||||
root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name))
|
||||
root.SetItem(c.Str("Tag"), numberField(uint(d.Tag)))
|
||||
case *ast.BasicLit:
|
||||
root.SetItem(c.Str("_Type"), stringField("BasicLit"))
|
||||
root.SetItem(c.Str("Kind"), numberField(uint(d.Kind)))
|
||||
root.SetItem(c.Str("Value"), stringField(d.Value))
|
||||
case *ast.LvalueRefType:
|
||||
root.SetItem(c.Str("_Type"), stringField("LvalueRefType"))
|
||||
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
|
||||
case *ast.RvalueRefType:
|
||||
root.SetItem(c.Str("_Type"), stringField("RvalueRefType"))
|
||||
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
|
||||
case *ast.PointerType:
|
||||
root.SetItem(c.Str("_Type"), stringField("PointerType"))
|
||||
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
|
||||
case *ast.ArrayType:
|
||||
root.SetItem(c.Str("_Type"), stringField("ArrayType"))
|
||||
root.SetItem(c.Str("Elt"), MarshalASTExpr(d.Elt))
|
||||
root.SetItem(c.Str("Len"), MarshalASTExpr(d.Len))
|
||||
case *ast.BuiltinType:
|
||||
root.SetItem(c.Str("_Type"), stringField("BuiltinType"))
|
||||
root.SetItem(c.Str("Kind"), numberField(uint(d.Kind)))
|
||||
root.SetItem(c.Str("Flags"), numberField(uint(d.Flags)))
|
||||
case *ast.Comment:
|
||||
root.SetItem(c.Str("_Type"), stringField("Comment"))
|
||||
if d == nil {
|
||||
return cjson.Null()
|
||||
}
|
||||
root.SetItem(c.Str("Text"), stringField(d.Text))
|
||||
case *ast.CommentGroup:
|
||||
root.SetItem(c.Str("_Type"), stringField("CommentGroup"))
|
||||
if d == nil {
|
||||
return cjson.Null()
|
||||
}
|
||||
@@ -189,6 +214,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON {
|
||||
}
|
||||
root.SetItem(c.Str("List"), list)
|
||||
case *ast.ScopingExpr:
|
||||
root.SetItem(c.Str("_Type"), stringField("ScopingExpr"))
|
||||
root.SetItem(c.Str("X"), MarshalASTExpr(d.X))
|
||||
root.SetItem(c.Str("Parent"), MarshalASTExpr(d.Parent))
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user