Skip to content

Commit b4c9fb1

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

File tree

7 files changed

+64
-19
lines changed

7 files changed

+64
-19
lines changed

_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/llcppsigfetch/dbg/debug.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ type dbgFlags = int
55
var flags dbgFlags
66

77
const (
8-
DbgParse dbgFlags = 1 << iota
9-
DbgFlagAll = DbgParse
8+
DbgParse dbgFlags = 1 << iota
9+
DbgVisitTop
10+
DbgFlagAll = DbgParse
1011
)
1112

1213
func SetDebugParse() {
@@ -20,3 +21,11 @@ func GetDebugParse() bool {
2021
func SetDebugAll() {
2122
flags = DbgFlagAll
2223
}
24+
25+
func SetDebugVisitTop() {
26+
flags |= DbgVisitTop
27+
}
28+
29+
func GetDebugVisitTop() bool {
30+
return flags&DbgVisitTop != 0
31+
}

_xtool/llcppsigfetch/parse/cvt.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ func (ct *Converter) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResul
229229
inFile := ct.InFile(cursor)
230230

231231
name := toStr(cursor.String())
232-
ct.logf("visitTop: Cursor: %s\n", name)
232+
if dbg.GetDebugVisitTop() {
233+
ct.logf("visitTop: Cursor: %s\n", name)
234+
}
233235

234236
if !inFile {
235237
return clang.ChildVisit_Continue
@@ -243,17 +245,23 @@ func (ct *Converter) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResul
243245
return clang.ChildVisit_Continue
244246
}
245247
ct.Pkg.File.Includes = append(ct.Pkg.File.Includes, include)
246-
ct.logln("visitTop: ProcessInclude END ", include.Path)
248+
if dbg.GetDebugVisitTop() {
249+
ct.logln("visitTop: ProcessInclude END ", include.Path)
250+
}
247251
case clang.CursorMacroDefinition:
248252
macro := ct.ProcessMacro(cursor)
249253
if cursor.IsMacroBuiltin() == 0 {
250254
ct.Pkg.File.Macros = append(ct.Pkg.File.Macros, macro)
251255
}
252-
ct.logln("visitTop: ProcessMacro END ", macro.Name, "Tokens Length:", len(macro.Tokens))
256+
if dbg.GetDebugVisitTop() {
257+
ct.logln("visitTop: ProcessMacro END ", macro.Name, "Tokens Length:", len(macro.Tokens))
258+
}
253259
case clang.CursorEnumDecl:
254260
enum := ct.ProcessEnumDecl(cursor)
255261
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, enum)
256-
ct.logf("visitTop: ProcessEnumDecl END")
262+
if dbg.GetDebugVisitTop() {
263+
ct.logf("visitTop: ProcessEnumDecl END")
264+
}
257265
if enum.Name != nil {
258266
ct.logln(enum.Name.Name)
259267
} else {
@@ -264,11 +272,15 @@ func (ct *Converter) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResul
264272
classDecl := ct.ProcessClassDecl(cursor)
265273
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, classDecl)
266274
// class havent anonymous situation
267-
ct.logln("visitTop: ProcessClassDecl END", classDecl.Name.Name)
275+
if dbg.GetDebugVisitTop() {
276+
ct.logln("visitTop: ProcessClassDecl END", classDecl.Name.Name)
277+
}
268278
case clang.CursorStructDecl:
269279
structDecl := ct.ProcessStructDecl(cursor)
270280
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, structDecl)
271-
ct.logf("visitTop: ProcessStructDecl END")
281+
if dbg.GetDebugVisitTop() {
282+
ct.logf("visitTop: ProcessStructDecl END")
283+
}
272284
if structDecl.Name != nil {
273285
ct.logln(structDecl.Name.Name)
274286
} else {
@@ -277,7 +289,9 @@ func (ct *Converter) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResul
277289
case clang.CursorUnionDecl:
278290
unionDecl := ct.ProcessUnionDecl(cursor)
279291
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, unionDecl)
280-
ct.logf("visitTop: ProcessUnionDecl END")
292+
if dbg.GetDebugVisitTop() {
293+
ct.logf("visitTop: ProcessUnionDecl END")
294+
}
281295
if unionDecl.Name != nil {
282296
ct.logln(unionDecl.Name.Name)
283297
} else {
@@ -288,14 +302,18 @@ func (ct *Converter) visitTop(cursor, parent clang.Cursor) clang.ChildVisitResul
288302
// Example: void MyClass::myMethod() { ... } out-of-class method
289303
funcDecl := ct.ProcessFuncDecl(cursor)
290304
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, funcDecl)
291-
ct.logln("visitTop: ProcessFuncDecl END", funcDecl.Name.Name, funcDecl.MangledName, "isStatic:", funcDecl.IsStatic, "isInline:", funcDecl.IsInline)
305+
if dbg.GetDebugVisitTop() {
306+
ct.logln("visitTop: ProcessFuncDecl END", funcDecl.Name.Name, funcDecl.MangledName, "isStatic:", funcDecl.IsStatic, "isInline:", funcDecl.IsInline)
307+
}
292308
case clang.CursorTypedefDecl:
293309
typedefDecl := ct.ProcessTypeDefDecl(cursor)
294310
if typedefDecl == nil {
295311
return clang.ChildVisit_Continue
296312
}
297313
ct.Pkg.File.Decls = append(ct.Pkg.File.Decls, typedefDecl)
298-
ct.logln("visitTop: ProcessTypeDefDecl END", typedefDecl.Name.Name)
314+
if dbg.GetDebugVisitTop() {
315+
ct.logln("visitTop: ProcessTypeDefDecl END", typedefDecl.Name.Name)
316+
}
299317
case clang.CursorNamespace:
300318
clangutils.VisitChildren(cursor, ct.visitTop)
301319
}

_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)