c/clang/symg:multiple header file
This commit is contained in:
@@ -17,7 +17,7 @@ type Context struct {
|
|||||||
namespaceName string
|
namespaceName string
|
||||||
className string
|
className string
|
||||||
astInfo []common.ASTInformation
|
astInfo []common.ASTInformation
|
||||||
filename *c.Char
|
currentFile *c.Char
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContext() *Context {
|
func newContext() *Context {
|
||||||
@@ -34,8 +34,8 @@ func (c *Context) setClassName(name string) {
|
|||||||
c.className = name
|
c.className = name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) setFilename(filename *c.Char) {
|
func (c *Context) setCurrentFile(filename *c.Char) {
|
||||||
c.filename = filename
|
c.currentFile = filename
|
||||||
}
|
}
|
||||||
|
|
||||||
var context = newContext()
|
var context = newContext()
|
||||||
@@ -109,7 +109,7 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
|||||||
loc.SpellingLocation(&file, &line, &column, nil)
|
loc.SpellingLocation(&file, &line, &column, nil)
|
||||||
filename := file.FileName()
|
filename := file.FileName()
|
||||||
|
|
||||||
if c.Strcmp(filename.CStr(), context.filename) == 0 {
|
if c.Strcmp(filename.CStr(), context.currentFile) == 0 {
|
||||||
info := collectFuncInfo(cursor)
|
info := collectFuncInfo(cursor)
|
||||||
info.Location = c.GoString(filename.CStr()) + ":" + strconv.Itoa(int(line)) + ":" + strconv.Itoa(int(column))
|
info.Location = c.GoString(filename.CStr()) + ":" + strconv.Itoa(int(line)) + ":" + strconv.Itoa(int(column))
|
||||||
context.astInfo = append(context.astInfo, info)
|
context.astInfo = append(context.astInfo, info)
|
||||||
@@ -122,13 +122,14 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
|||||||
return clang.ChildVisit_Continue
|
return clang.ChildVisit_Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(filename *c.Char) []common.ASTInformation {
|
func parse(filenames []*c.Char) []common.ASTInformation {
|
||||||
index := clang.CreateIndex(0, 0)
|
index := clang.CreateIndex(0, 0)
|
||||||
args := make([]*c.Char, 3)
|
args := make([]*c.Char, 3)
|
||||||
args[0] = c.Str("-x")
|
args[0] = c.Str("-x")
|
||||||
args[1] = c.Str("c++")
|
args[1] = c.Str("c++")
|
||||||
args[1] = c.Str("c++")
|
|
||||||
args[2] = c.Str("-std=c++11")
|
args[2] = c.Str("-std=c++11")
|
||||||
|
|
||||||
|
for _, filename := range filenames {
|
||||||
unit := index.ParseTranslationUnit(
|
unit := index.ParseTranslationUnit(
|
||||||
filename,
|
filename,
|
||||||
unsafe.SliceData(args), 3,
|
unsafe.SliceData(args), 3,
|
||||||
@@ -137,16 +138,18 @@ func parse(filename *c.Char) []common.ASTInformation {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if unit == nil {
|
if unit == nil {
|
||||||
println("Unable to parse translation unit. Quitting.")
|
fmt.Printf("Unable to parse translation unit for file: %s. Skipping.\n", c.GoString(filename))
|
||||||
c.Exit(1)
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor := unit.Cursor()
|
cursor := unit.Cursor()
|
||||||
context.setFilename(filename)
|
context.setCurrentFile(filename)
|
||||||
|
|
||||||
clang.VisitChildren(cursor, visit, nil)
|
clang.VisitChildren(cursor, visit, nil)
|
||||||
|
|
||||||
unit.Dispose()
|
unit.Dispose()
|
||||||
|
}
|
||||||
|
|
||||||
index.Dispose()
|
index.Dispose()
|
||||||
|
|
||||||
return context.astInfo
|
return context.astInfo
|
||||||
@@ -176,13 +179,15 @@ func printJson(infos []common.ASTInformation) {
|
|||||||
}
|
}
|
||||||
c.Printf(c.Str("%s\n"), root.Print())
|
c.Printf(c.Str("%s\n"), root.Print())
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if c.Argc < 2 {
|
if c.Argc < 2 {
|
||||||
fmt.Fprintln(os.Stderr, "Usage: <C++ header file>\n")
|
fmt.Fprintln(os.Stderr, "Usage: <C++ header file1> [<C++ header file2> ...]\n")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
// todo(zzy): receive files
|
filenames := make([]*c.Char, c.Argc-1)
|
||||||
printJson(parse(c.Index(c.Argv, 1)))
|
for i := 1; i < int(c.Argc); i++ {
|
||||||
|
filenames[i-1] = c.Index(c.Argv, c.Int(i))
|
||||||
|
}
|
||||||
|
printJson(parse(filenames))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user