Implemented structs

This commit is contained in:
2025-02-04 18:16:31 +01:00
parent 4609a814df
commit 03a3bd8f02
32 changed files with 267 additions and 63 deletions

View File

@ -1,20 +1,25 @@
package scanner
import (
"path/filepath"
"git.akyoto.dev/cli/q/src/config"
"git.akyoto.dev/cli/q/src/core"
"git.akyoto.dev/cli/q/src/fs"
"git.akyoto.dev/cli/q/src/types"
)
// Scan scans the list of files.
func Scan(files []string) (<-chan *fs.File, <-chan *core.Function, <-chan *types.Type, <-chan error) {
func Scan(files []string) (<-chan *fs.File, <-chan *core.Function, <-chan types.Type, <-chan error) {
scanner := Scanner{
files: make(chan *fs.File),
functions: make(chan *core.Function),
types: make(chan *types.Type),
types: make(chan types.Type),
errors: make(chan error),
}
scanner.queueDirectory(filepath.Join(config.Library, "mem"), "mem")
go func() {
scanner.queue(files...)
scanner.group.Wait()

View File

@ -12,7 +12,7 @@ import (
type Scanner struct {
files chan *fs.File
functions chan *core.Function
types chan *types.Type
types chan types.Type
errors chan error
queued sync.Map
group sync.WaitGroup

View File

@ -17,7 +17,7 @@ func (s *Scanner) scanStruct(file *fs.File, tokens token.List, i int) (int, erro
structName := tokens[i].Text(file.Bytes)
typ := &types.Type{
structure := &types.Struct{
Name: structName,
}
@ -39,14 +39,14 @@ func (s *Scanner) scanStruct(file *fs.File, tokens token.List, i int) (int, erro
fieldType := types.Parse(fieldTypeName)
i++
typ.Fields = append(typ.Fields, &types.Field{
structure.Fields = append(structure.Fields, &types.Field{
Type: fieldType,
Name: fieldName,
Position: token.Position(fieldPosition),
Offset: typ.Size,
Offset: structure.Size,
})
typ.Size += fieldType.Size
structure.Size += fieldType.TotalSize()
}
if tokens[i].Kind == token.BlockEnd {
@ -61,6 +61,6 @@ func (s *Scanner) scanStruct(file *fs.File, tokens token.List, i int) (int, erro
return i, errors.New(errors.MissingBlockEnd, file, tokens[i].Position)
}
s.types <- typ
s.types <- structure
return i, nil
}