c/clang/symg:filter unuse file
This commit is contained in:
@@ -17,6 +17,7 @@ type Context struct {
|
|||||||
namespaceName string
|
namespaceName string
|
||||||
className string
|
className string
|
||||||
astInfo []common.ASTInformation
|
astInfo []common.ASTInformation
|
||||||
|
filename *c.Char
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContext() *Context {
|
func newContext() *Context {
|
||||||
@@ -33,25 +34,19 @@ func (c *Context) setClassName(name string) {
|
|||||||
c.className = name
|
c.className = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) setFilename(filename *c.Char) {
|
||||||
|
c.filename = filename
|
||||||
|
}
|
||||||
|
|
||||||
var context = newContext()
|
var context = newContext()
|
||||||
|
|
||||||
func collectFuncInfo(cursor clang.Cursor) common.ASTInformation {
|
func collectFuncInfo(cursor clang.Cursor) common.ASTInformation {
|
||||||
|
|
||||||
info := common.ASTInformation{
|
info := common.ASTInformation{
|
||||||
Namespace: context.namespaceName,
|
Namespace: context.namespaceName,
|
||||||
Class: context.className,
|
Class: context.className,
|
||||||
}
|
}
|
||||||
|
|
||||||
loc := cursor.Location()
|
|
||||||
var file clang.File
|
|
||||||
var line, column c.Uint
|
|
||||||
|
|
||||||
loc.SpellingLocation(&file, &line, &column, nil)
|
|
||||||
filename := file.FileName()
|
|
||||||
|
|
||||||
info.Location = c.GoString(filename.CStr()) + ":" + strconv.Itoa(int(line)) + ":" + strconv.Itoa(int(column))
|
|
||||||
|
|
||||||
// c.Printf(c.Str("%s:%d:%d\n"), filename.CStr(), line, column)
|
|
||||||
|
|
||||||
cursorStr := cursor.String()
|
cursorStr := cursor.String()
|
||||||
symbol := cursor.Mangling()
|
symbol := cursor.Mangling()
|
||||||
|
|
||||||
@@ -66,7 +61,6 @@ func collectFuncInfo(cursor clang.Cursor) common.ASTInformation {
|
|||||||
|
|
||||||
defer symbol.Dispose()
|
defer symbol.Dispose()
|
||||||
defer cursorStr.Dispose()
|
defer cursorStr.Dispose()
|
||||||
defer filename.Dispose()
|
|
||||||
|
|
||||||
if context.namespaceName != "" {
|
if context.namespaceName != "" {
|
||||||
info.Namespace = context.namespaceName
|
info.Namespace = context.namespaceName
|
||||||
@@ -108,10 +102,23 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
|||||||
clang.VisitChildren(cursor, visit, nil)
|
clang.VisitChildren(cursor, visit, nil)
|
||||||
context.setClassName("")
|
context.setClassName("")
|
||||||
} else if cursor.Kind == clang.CXXMethod || cursor.Kind == clang.FunctionDecl || cursor.Kind == clang.Constructor || cursor.Kind == clang.Destructor {
|
} else if cursor.Kind == clang.CXXMethod || cursor.Kind == clang.FunctionDecl || cursor.Kind == clang.Constructor || cursor.Kind == clang.Destructor {
|
||||||
|
loc := cursor.Location()
|
||||||
|
var file clang.File
|
||||||
|
var line, column c.Uint
|
||||||
|
|
||||||
|
loc.SpellingLocation(&file, &line, &column, nil)
|
||||||
|
filename := file.FileName()
|
||||||
|
|
||||||
|
if c.Strcmp(filename.CStr(), context.filename) == 0 {
|
||||||
info := collectFuncInfo(cursor)
|
info := collectFuncInfo(cursor)
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer filename.Dispose()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return clang.ChildVisit_Continue
|
return clang.ChildVisit_Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +127,7 @@ func parse(filename *c.Char) []common.ASTInformation {
|
|||||||
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")
|
||||||
unit := index.ParseTranslationUnit(
|
unit := index.ParseTranslationUnit(
|
||||||
filename,
|
filename,
|
||||||
@@ -134,6 +142,7 @@ func parse(filename *c.Char) []common.ASTInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cursor := unit.Cursor()
|
cursor := unit.Cursor()
|
||||||
|
context.setFilename(filename)
|
||||||
|
|
||||||
clang.VisitChildren(cursor, visit, nil)
|
clang.VisitChildren(cursor, visit, nil)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user