Skip to content

Commit 878ecc7

Browse files
committed
symMap field of llcppg.cfg support -
1 parent eb0c906 commit 878ecc7

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

_demo/cjsondemo/demo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"github.com/goplus/llgo/c"
5-
cjson "github.com/goplus/llpkg/cjson"
5+
"github.com/goplus/llpkg/cjson"
66
)
77

88
func main() {

_xtool/llcppsymg/_cmptest/symg_test/cjson/llcppg.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"cplusplus": false,
99
"symMap": {
1010
"cJSON_AddArrayToObject":".AddArrayToObj",
11-
"cJSON_AddBoolToObject":"AddBoolToObj"
11+
"cJSON_AddBoolToObject":"AddBoolToObj",
12+
"cJSON_AddNumberToObject":"-"
1213
}
1314
}

_xtool/llcppsymg/_cmptest/symg_test/symg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestParseHeaderFile() {
5555
"cJSON_Delete",
5656
"cJSON_AddArrayToObject",
5757
"cJSON_AddBoolToObject",
58+
"cJSON_AddNumberToObject",
5859
},
5960
},
6061
{

_xtool/llcppsymg/dbg/debug.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88
DbgSymbol dbgFlags = 1 << iota
99
DbgParseIsMethod //print parse.go isMethod debug log info
1010
DbgEditSymMap //print user edit sym map info
11+
DbgVisitTop //print visitTop
1112
DbgFlagAll = DbgSymbol | DbgParseIsMethod
1213
)
1314

@@ -34,3 +35,11 @@ func SetDebugEditSymMap() {
3435
func GetDebugEditSymMap() bool {
3536
return flags&DbgEditSymMap != 0
3637
}
38+
39+
func SetDebugVisitTop() {
40+
flags |= DbgVisitTop
41+
}
42+
43+
func GetDebugVisitTop() bool {
44+
return flags&DbgVisitTop != 0
45+
}

_xtool/llcppsymg/parse/parse.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (p *SymbolProcessor) userEditGoName(manglingName string) (goName string, is
207207
func (p *SymbolProcessor) genGoName(cursor clang.Cursor, mangleName string) string {
208208

209209
edittedGoName, isEdittedGoName, isEdittedMethodName := p.userEditGoName(mangleName)
210+
210211
if dbg.GetDebugEditSymMap() && isEdittedGoName {
211212
fmt.Println("edittedGoName:", edittedGoName)
212213
fmt.Println("isEdittedGoName", isEdittedGoName)
@@ -295,16 +296,22 @@ func (p *SymbolProcessor) collectFuncInfo(cursor clang.Cursor) {
295296
return
296297
}
297298

299+
// ignore
300+
goName := p.genGoName(cursor, manglingName)
301+
if goName == "-" || len(goName) == 0 {
302+
return
303+
}
304+
298305
p.SymbolMap[manglingName] = &SymbolInfo{
299-
GoName: p.genGoName(cursor, manglingName),
306+
GoName: goName,
300307
ProtoName: p.genProtoName(cursor),
301308
}
302309
}
303310

304311
func (p *SymbolProcessor) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResult {
305312
filename := clang.GoString(cursor.Location().File().FileName())
306313
if _, ok := p.processedFiles[filename]; ok {
307-
if dbg.GetDebugSymbol() {
314+
if dbg.GetDebugVisitTop() && p.isSelfFile(filename) {
308315
fmt.Printf("visitTop: %s has been processed: \n", filename)
309316
}
310317
return clang.ChildVisit_Continue
@@ -313,7 +320,7 @@ func (p *SymbolProcessor) visitTop(cursor, parent clang.Cursor) clang.ChildVisit
313320
return clang.ChildVisit_Continue
314321
}
315322
p.processingFiles[filename] = struct{}{}
316-
if dbg.GetDebugSymbol() && filename != "" {
323+
if dbg.GetDebugVisitTop() && p.isSelfFile(filename) {
317324
fmt.Printf("visitTop: %s\n", filename)
318325
}
319326
switch cursor.Kind {
@@ -334,20 +341,20 @@ func (p *SymbolProcessor) collect(cfg *clangutils.Config) error {
334341
filename = clangutils.TEMP_FILE
335342
}
336343
if _, ok := p.processedFiles[filename]; ok {
337-
if dbg.GetDebugSymbol() {
344+
if dbg.GetDebugSymbol() && p.isSelfFile(filename) {
338345
fmt.Printf("%s has been processed: \n", filename)
339346
}
340347
return nil
341348
}
342-
if dbg.GetDebugSymbol() {
349+
if dbg.GetDebugSymbol() && p.isSelfFile(filename) {
343350
fmt.Printf("create translation unit: \nfile:%s\nIsCpp:%v\nTemp:%v\nArgs:%v\n", filename, cfg.IsCpp, cfg.Temp, cfg.Args)
344351
}
345352
_, unit, err := clangutils.CreateTranslationUnit(cfg)
346353
if err != nil {
347354
return errors.New("Unable to parse translation unit for file " + filename)
348355
}
349356
cursor := unit.Cursor()
350-
if dbg.GetDebugSymbol() {
357+
if dbg.GetDebugVisitTop() && p.isSelfFile(filename) {
351358
fmt.Printf("%s start collect \n", filename)
352359
}
353360
clangutils.VisitChildren(cursor, p.visitTop)

0 commit comments

Comments
 (0)