llcppsigfetch:order output

This commit is contained in:
luoliwoshang
2024-09-19 16:49:05 +08:00
parent e0cb6d4531
commit 2c3d46bb80
3 changed files with 39 additions and 33 deletions

View File

@@ -4,17 +4,16 @@ import (
"errors"
"github.com/goplus/llgo/c/cjson"
"github.com/goplus/llgo/chore/llcppg/ast"
)
type Context struct {
Files map[string]*ast.File
Files []*FileEntry
IsCpp bool
}
func NewContext(isCpp bool) *Context {
return &Context{
Files: make(map[string]*ast.File),
Files: make([]*FileEntry, 0),
IsCpp: isCpp,
}
}
@@ -35,23 +34,21 @@ func (p *Context) ProcessFiles(files []string) error {
// parse file and add it to the context,avoid duplicate parsing
func (p *Context) processFile(path string) error {
if _, exists := p.Files[path]; exists {
return nil
for _, entry := range p.Files {
if entry.Path == path {
return nil
}
}
parsedfiles, err := p.parseFile(path)
parsedFiles, err := p.parseFile(path)
if err != nil {
return errors.New("failed to parse file: " + path)
}
for path, file := range parsedfiles {
if _, exist := p.Files[path]; !exist {
p.Files[path] = file
}
}
p.Files = append(p.Files, parsedFiles...)
return nil
}
func (p *Context) parseFile(path string) (map[string]*ast.File, error) {
func (p *Context) parseFile(path string) ([]*FileEntry, error) {
converter, err := NewConverter(&Config{
File: path,
Temp: false,