c/clang/symg:get constructor & destructor
This commit is contained in:
@@ -2,11 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goplus/llgo/chore/_xtool/llcppsymg/common"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/chore/_xtool/llcppsymg/common"
|
||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
"github.com/goplus/llgo/c/cjson"
|
"github.com/goplus/llgo/c/cjson"
|
||||||
"github.com/goplus/llgo/c/clang"
|
"github.com/goplus/llgo/c/clang"
|
||||||
@@ -74,13 +75,9 @@ func collectFuncInfo(cursor clang.Cursor) common.ASTInformation {
|
|||||||
info.Class = context.className
|
info.Class = context.className
|
||||||
}
|
}
|
||||||
|
|
||||||
if cursor.Kind == clang.CXXMethod || cursor.Kind == clang.FunctionDecl {
|
|
||||||
// c.Printf(c.Str("symbol:%s\n"), symbol.CStr())
|
|
||||||
|
|
||||||
typeStr := cursor.ResultType().String()
|
typeStr := cursor.ResultType().String()
|
||||||
defer typeStr.Dispose()
|
defer typeStr.Dispose()
|
||||||
info.ReturnType = c.GoString(typeStr.CStr())
|
info.ReturnType = c.GoString(typeStr.CStr())
|
||||||
// c.Printf(c.Str("Parameters(%d): ( "), cursor.NumArguments())
|
|
||||||
|
|
||||||
info.Parameters = make([]common.Parameter, cursor.NumArguments())
|
info.Parameters = make([]common.Parameter, cursor.NumArguments())
|
||||||
for i := 0; i < int(cursor.NumArguments()); i++ {
|
for i := 0; i < int(cursor.NumArguments()); i++ {
|
||||||
@@ -96,27 +93,6 @@ func collectFuncInfo(cursor clang.Cursor) common.ASTInformation {
|
|||||||
argName.Dispose()
|
argName.Dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println("location", info.Location)
|
|
||||||
// fmt.Println("symbol:", info.Symbol)
|
|
||||||
// fmt.Println("name:", info.Name)
|
|
||||||
// if info.Namespace != "" {
|
|
||||||
// fmt.Println("namespace:", info.Namespace)
|
|
||||||
// }
|
|
||||||
// if info.Class != "" {
|
|
||||||
// fmt.Println("class:", info.Class)
|
|
||||||
// }
|
|
||||||
// fmt.Println("return type:", info.ReturnType)
|
|
||||||
|
|
||||||
// if len(info.Parameters) != 0 {
|
|
||||||
// fmt.Println("Parameters:(")
|
|
||||||
// for _, param := range info.Parameters {
|
|
||||||
// fmt.Println(" ", param.Name, ":", param.Type)
|
|
||||||
// }
|
|
||||||
// fmt.Println(")")
|
|
||||||
// }
|
|
||||||
// println("--------------------------------")
|
|
||||||
}
|
|
||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +107,7 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
|||||||
context.setClassName(c.GoString(nameStr.CStr()))
|
context.setClassName(c.GoString(nameStr.CStr()))
|
||||||
clang.VisitChildren(cursor, visit, nil)
|
clang.VisitChildren(cursor, visit, nil)
|
||||||
context.setClassName("")
|
context.setClassName("")
|
||||||
} else if cursor.Kind == clang.CXXMethod || cursor.Kind == clang.FunctionDecl {
|
} else if cursor.Kind == clang.CXXMethod || cursor.Kind == clang.FunctionDecl || cursor.Kind == clang.Constructor || cursor.Kind == clang.Destructor {
|
||||||
info := collectFuncInfo(cursor)
|
info := collectFuncInfo(cursor)
|
||||||
context.astInfo = append(context.astInfo, info)
|
context.astInfo = append(context.astInfo, info)
|
||||||
}
|
}
|
||||||
@@ -193,20 +169,11 @@ func printJson(infos []common.ASTInformation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// for i := c.Int(0); i < c.Argc; i++ {
|
if c.Argc < 2 {
|
||||||
// c.Printf(c.Str("%s\n"), c.Index(c.Argv, i))
|
|
||||||
// }
|
|
||||||
// c.Printf(c.Str("c.Index %s\n"), c.Index(c.Argv, 1))
|
|
||||||
// c.Printf(c.Str("c.Index %s\n"), *c.Advance(c.Argv, 1))
|
|
||||||
|
|
||||||
if c.Argc != 2 {
|
|
||||||
fmt.Fprintln(os.Stderr, "Usage: <C++ header file>\n")
|
fmt.Fprintln(os.Stderr, "Usage: <C++ header file>\n")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
// todo(zzy): receive files
|
||||||
// sourceFile := *c.Advance(c.Argv, 1)
|
|
||||||
printJson(parse(c.Index(c.Argv, 1)))
|
printJson(parse(c.Index(c.Argv, 1)))
|
||||||
// fmt.Println("Json end")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfgFile := "/Users/lixianyu/go/src/llgo/chore/_xtool/llcppsymg/llcppg.cfg"
|
cfgFile := "llcppg.cfg"
|
||||||
//if len(os.Args) > 1 {
|
//if len(os.Args) > 1 {
|
||||||
// cfgFile = os.Args[1]
|
// cfgFile = os.Args[1]
|
||||||
//}
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user