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

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

View File

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

View File

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