llcppsigfetch/chore:rename

This commit is contained in:
luoliwoshang
2024-08-22 21:24:25 +08:00
parent 14b335a51e
commit e57ea9b501
3 changed files with 58 additions and 58 deletions

View File

@@ -19,7 +19,7 @@ type Converter struct {
curLoc ast.Location curLoc ast.Location
index *clang.Index index *clang.Index
unit *clang.TranslationUnit unit *clang.TranslationUnit
scopeStack []ast.Expr //namespace & class scopeContext []ast.Expr //namespace & class
} }
type Config struct { type Config struct {
@@ -97,26 +97,26 @@ func (ct *Converter) PushScope(cursor clang.Cursor) {
defer name.Dispose() defer name.Dispose()
ident := &ast.Ident{Name: c.GoString(name.CStr())} ident := &ast.Ident{Name: c.GoString(name.CStr())}
if len(ct.scopeStack) == 0 { if len(ct.scopeContext) == 0 {
ct.scopeStack = append(ct.scopeStack, ident) ct.scopeContext = append(ct.scopeContext, ident)
} else { } else {
parent := ct.scopeStack[len(ct.scopeStack)-1] parent := ct.scopeContext[len(ct.scopeContext)-1]
newContext := &ast.ScopingExpr{Parent: parent, X: ident} newContext := &ast.ScopingExpr{Parent: parent, X: ident}
ct.scopeStack = append(ct.scopeStack, newContext) ct.scopeContext = append(ct.scopeContext, newContext)
} }
} }
func (ct *Converter) PopScope() { func (ct *Converter) PopScope() {
if len(ct.scopeStack) > 0 { if len(ct.scopeContext) > 0 {
ct.scopeStack = ct.scopeStack[:len(ct.scopeStack)-1] ct.scopeContext = ct.scopeContext[:len(ct.scopeContext)-1]
} }
} }
func (ct *Converter) GetCurScope() ast.Expr { func (ct *Converter) GetCurScope() ast.Expr {
if len(ct.scopeStack) == 0 { if len(ct.scopeContext) == 0 {
return nil return nil
} }
return ct.scopeStack[len(ct.scopeStack)-1] return ct.scopeContext[len(ct.scopeContext)-1]
} }
func (ct *Converter) UpdateLoc(cursor clang.Cursor) { func (ct *Converter) UpdateLoc(cursor clang.Cursor) {
@@ -179,8 +179,8 @@ func (ct *Converter) ParseComment(rawComment string) *ast.CommentGroup {
return commentGroup return commentGroup
} }
// visit top decls (struct,class,function,enum & marco,include) // visit top decls (struct,class,function,enum & macro,include)
func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult { func visitTop(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult {
ct := (*Converter)(clientData) ct := (*Converter)(clientData)
ct.UpdateLoc(cursor) ct.UpdateLoc(cursor)
@@ -194,8 +194,8 @@ func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVi
include := ct.ProcessInclude(cursor) include := ct.ProcessInclude(cursor)
curFile.Includes = append(curFile.Includes, include) curFile.Includes = append(curFile.Includes, include)
case clang.CursorMacroDefinition: case clang.CursorMacroDefinition:
marco := ct.ProcessMarco(cursor) macro := ct.ProcessMacro(cursor)
curFile.Macros = append(curFile.Macros, marco) curFile.Macros = append(curFile.Macros, macro)
case clang.CursorEnumDecl: case clang.CursorEnumDecl:
enum := ct.ProcessEnumDecl(cursor) enum := ct.ProcessEnumDecl(cursor)
curFile.Decls = append(curFile.Decls, enum) curFile.Decls = append(curFile.Decls, enum)
@@ -214,7 +214,7 @@ func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVi
curFile.Decls = append(curFile.Decls, ct.ProcessTypeDefDecl(cursor)) curFile.Decls = append(curFile.Decls, ct.ProcessTypeDefDecl(cursor))
case clang.CursorNamespace: case clang.CursorNamespace:
ct.PushScope(cursor) ct.PushScope(cursor)
clang.VisitChildren(cursor, visit, c.Pointer(ct)) clang.VisitChildren(cursor, visitTop, c.Pointer(ct))
ct.PopScope() ct.PopScope()
} }
return clang.ChildVisit_Continue return clang.ChildVisit_Continue
@@ -222,8 +222,8 @@ func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVi
func (ct *Converter) Convert() (map[string]*ast.File, error) { func (ct *Converter) Convert() (map[string]*ast.File, error) {
cursor := ct.unit.Cursor() cursor := ct.unit.Cursor()
// visit top decls (struct,class,function & marco,include) // visit top decls (struct,class,function & macro,include)
clang.VisitChildren(cursor, visit, c.Pointer(ct)) clang.VisitChildren(cursor, visitTop, c.Pointer(ct))
return ct.Files, nil return ct.Files, nil
} }
@@ -338,8 +338,8 @@ func (ct *Converter) ProcessEnumDecl(cursor clang.Cursor) *ast.EnumTypeDecl {
} }
} }
// current only collect marco which defined in file // current only collect macro which defined in file
func (ct *Converter) ProcessMarco(cursor clang.Cursor) *ast.Macro { func (ct *Converter) ProcessMacro(cursor clang.Cursor) *ast.Macro {
name := cursor.String() name := cursor.String()
defer name.Dispose() defer name.Dispose()

View File

@@ -3,35 +3,35 @@ package main
import test "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse/cvt_test" import test "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse/cvt_test"
func main() { func main() {
TestComment() TestDoc()
} }
func TestComment() { func TestDoc() {
testCases := []string{ testCases := []string{
`// not read comment 1 `// not read doc 1
void foo();`, void foo();`,
`/* not read comment 2 */ `/* not read doc 2 */
void foo();`, void foo();`,
`/// comment `/// doc
void foo();`, void foo();`,
`/** comment */ `/** doc */
void foo();`, void foo();`,
`/*! comment */ `/*! doc */
void foo();`, void foo();`,
`/// comment 1 `/// doc 1
/// comment 2 /// doc 2
void foo();`, void foo();`,
`/*! comment 1 */ `/*! doc 1 */
/*! comment 2 */ /*! doc 2 */
void foo();`, void foo();`,
`/** comment 1 */ `/** doc 1 */
/** comment 1 */ /** doc 1 */
void foo();`, void foo();`,
`/** `/**
* comment 1 * doc 1
* comment 2 * doc 2
*/ */
void foo();`, void foo();`,
} }
test.RunTest("TestComment", testCases) test.RunTest("TestDoc", testCases)
} }

View File

@@ -1,5 +1,5 @@
#stdout #stdout
TestComment Case 1: TestDoc Case 1:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -28,7 +28,7 @@ TestComment Case 1:
} }
} }
TestComment Case 2: TestDoc Case 2:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -57,7 +57,7 @@ TestComment Case 2:
} }
} }
TestComment Case 3: TestDoc Case 3:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -66,7 +66,7 @@ TestComment Case 3:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/// comment" "Text": "/// doc"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -88,7 +88,7 @@ TestComment Case 3:
} }
} }
TestComment Case 4: TestDoc Case 4:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -97,7 +97,7 @@ TestComment Case 4:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/** comment */" "Text": "/** doc */"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -119,7 +119,7 @@ TestComment Case 4:
} }
} }
TestComment Case 5: TestDoc Case 5:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -128,7 +128,7 @@ TestComment Case 5:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/*! comment */" "Text": "/*! doc */"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -150,7 +150,7 @@ TestComment Case 5:
} }
} }
TestComment Case 6: TestDoc Case 6:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -159,9 +159,9 @@ TestComment Case 6:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/// comment 1" "Text": "/// doc 1"
}, { }, {
"Text": "/// comment 2" "Text": "/// doc 2"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -183,7 +183,7 @@ TestComment Case 6:
} }
} }
TestComment Case 7: TestDoc Case 7:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -192,9 +192,9 @@ TestComment Case 7:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/*! comment 1 */" "Text": "/*! doc 1 */"
}, { }, {
"Text": "/*! comment 2 */" "Text": "/*! doc 2 */"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -216,7 +216,7 @@ TestComment Case 7:
} }
} }
TestComment Case 8: TestDoc Case 8:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -225,9 +225,9 @@ TestComment Case 8:
}, },
"Doc": { "Doc": {
"List": [{ "List": [{
"Text": "/** comment 1 */" "Text": "/** doc 1 */"
}, { }, {
"Text": "/** comment 1 */" "Text": "/** doc 1 */"
}] }]
}, },
"Parent": null, "Parent": null,
@@ -249,7 +249,7 @@ TestComment Case 8:
} }
} }
TestComment Case 9: TestDoc Case 9:
{ {
"temp.h": { "temp.h": {
"decls": [{ "decls": [{
@@ -260,9 +260,9 @@ TestComment Case 9:
"List": [{ "List": [{
"Text": "/**" "Text": "/**"
}, { }, {
"Text": " * comment 1" "Text": " * doc 1"
}, { }, {
"Text": " * comment 2" "Text": " * doc 2"
}, { }, {
"Text": " */" "Text": " */"
}] }]