llcppsigfetch:Decl Comment

This commit is contained in:
luoliwoshang
2024-08-15 16:08:50 +08:00
parent 2c8a9d1160
commit 762ed994c1
3 changed files with 394 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"unsafe"
"github.com/goplus/llgo/c"
@@ -126,12 +127,30 @@ func (ct *Converter) UpdateCurFile(cursor clang.Cursor) {
}
func (ct *Converter) CreateDeclBase(cursor clang.Cursor) ast.DeclBase {
rawComment := cursor.RawCommentText()
defer rawComment.Dispose()
commentGroup := &ast.CommentGroup{}
if rawComment.CStr() != nil {
commentGroup = ct.ParseComment(c.GoString(rawComment.CStr()))
}
return ast.DeclBase{
Loc: &ct.curLoc,
Parent: ct.GetCurScope(),
Doc: commentGroup,
}
}
func (ct *Converter) ParseComment(rawComment string) *ast.CommentGroup {
lines := strings.Split(rawComment, "\n")
commentGroup := &ast.CommentGroup{}
for _, line := range lines {
commentGroup.List = append(commentGroup.List, &ast.Comment{Text: line})
}
return commentGroup
}
// visit top decls (struct,class,function,enum & marco,include)
func visit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult {
ct := (*Converter)(clientData)