llcppsymg:refine classname fetch
This commit is contained in:
@@ -16,8 +16,6 @@ type SymbolInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
namespaceName string
|
|
||||||
className string
|
|
||||||
prefixes []string
|
prefixes []string
|
||||||
symbolMap map[string]*SymbolInfo
|
symbolMap map[string]*SymbolInfo
|
||||||
currentFile string
|
currentFile string
|
||||||
@@ -32,14 +30,6 @@ func newContext(prefixes []string) *Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) setNamespaceName(name string) {
|
|
||||||
c.namespaceName = name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) setClassName(name string) {
|
|
||||||
c.className = name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) setCurrentFile(filename string) {
|
func (c *Context) setCurrentFile(filename string) {
|
||||||
c.currentFile = filename
|
c.currentFile = filename
|
||||||
}
|
}
|
||||||
@@ -79,18 +69,19 @@ func (c *Context) toGoName(name string) string {
|
|||||||
return toCamel(name)
|
return toCamel(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) genGoName(name string) string {
|
func (p *Context) genGoName(cursor clang.Cursor) string {
|
||||||
class := c.toGoName(c.className)
|
funcName := cursor.String()
|
||||||
name = c.toGoName(name)
|
defer funcName.Dispose()
|
||||||
|
|
||||||
var baseName string
|
name := p.toGoName(c.GoString(funcName.CStr()))
|
||||||
if class == "" {
|
if parent := cursor.SemanticParent(); parent.Kind == clang.CursorClassDecl {
|
||||||
baseName = name
|
parentName := parent.String()
|
||||||
} else {
|
defer parentName.Dispose()
|
||||||
baseName = c.genMethodName(class, name)
|
class := p.toGoName(c.GoString(parentName.CStr()))
|
||||||
|
return p.addSuffix(p.genMethodName(class, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.addSuffix(baseName)
|
return p.addSuffix(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) genMethodName(class, name string) string {
|
func (c *Context) genMethodName(class, name string) string {
|
||||||
@@ -132,19 +123,16 @@ func (c *Context) addSuffix(name string) string {
|
|||||||
var context = newContext([]string{})
|
var context = newContext([]string{})
|
||||||
|
|
||||||
func collectFuncInfo(cursor clang.Cursor) {
|
func collectFuncInfo(cursor clang.Cursor) {
|
||||||
cursorStr := cursor.String()
|
|
||||||
symbol := cursor.Mangling()
|
symbol := cursor.Mangling()
|
||||||
|
|
||||||
name := c.GoString(cursorStr.CStr())
|
|
||||||
symbolName := c.GoString(symbol.CStr())
|
symbolName := c.GoString(symbol.CStr())
|
||||||
if len(symbolName) >= 1 && symbolName[0] == '_' {
|
if len(symbolName) >= 1 && symbolName[0] == '_' {
|
||||||
symbolName = symbolName[1:]
|
symbolName = symbolName[1:]
|
||||||
}
|
}
|
||||||
defer symbol.Dispose()
|
defer symbol.Dispose()
|
||||||
defer cursorStr.Dispose()
|
|
||||||
|
|
||||||
context.symbolMap[symbolName] = &SymbolInfo{
|
context.symbolMap[symbolName] = &SymbolInfo{
|
||||||
GoName: context.genGoName(name),
|
GoName: context.genGoName(cursor),
|
||||||
ProtoName: context.genProtoName(cursor),
|
ProtoName: context.genProtoName(cursor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,30 +140,11 @@ func collectFuncInfo(cursor clang.Cursor) {
|
|||||||
func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitResult {
|
func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitResult {
|
||||||
switch cursor.Kind {
|
switch cursor.Kind {
|
||||||
case clang.CursorNamespace, clang.CursorClassDecl:
|
case clang.CursorNamespace, clang.CursorClassDecl:
|
||||||
nameStr := cursor.String()
|
|
||||||
defer nameStr.Dispose()
|
|
||||||
|
|
||||||
name := c.GoString(nameStr.CStr())
|
|
||||||
if cursor.Kind == clang.CursorNamespace {
|
|
||||||
context.setNamespaceName(name)
|
|
||||||
} else {
|
|
||||||
context.setClassName(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
clang.VisitChildren(cursor, visit, nil)
|
clang.VisitChildren(cursor, visit, nil)
|
||||||
|
|
||||||
if cursor.Kind == clang.CursorNamespace {
|
|
||||||
context.setNamespaceName("")
|
|
||||||
} else {
|
|
||||||
context.setClassName("")
|
|
||||||
}
|
|
||||||
|
|
||||||
case clang.CursorCXXMethod, clang.CursorFunctionDecl, clang.CursorConstructor, clang.CursorDestructor:
|
case clang.CursorCXXMethod, clang.CursorFunctionDecl, clang.CursorConstructor, clang.CursorDestructor:
|
||||||
loc := cursor.Location()
|
loc := cursor.Location()
|
||||||
var file clang.File
|
var file clang.File
|
||||||
var line, column c.Uint
|
loc.SpellingLocation(&file, nil, nil, nil)
|
||||||
|
|
||||||
loc.SpellingLocation(&file, &line, &column, nil)
|
|
||||||
filename := file.FileName()
|
filename := file.FileName()
|
||||||
defer filename.Dispose()
|
defer filename.Dispose()
|
||||||
|
|
||||||
@@ -186,7 +155,6 @@ func visit(cursor, parent clang.Cursor, clientData c.Pointer) clang.ChildVisitRe
|
|||||||
collectFuncInfo(cursor)
|
collectFuncInfo(cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return clang.ChildVisit_Continue
|
return clang.ChildVisit_Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user