Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 0 additions & 261 deletions _xtool/internal/parser/dump.go

This file was deleted.

13 changes: 5 additions & 8 deletions _xtool/llclang/internal/parser/iparser.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package parser

import (
"encoding/json"
"fmt"
"strconv"
"unsafe"

"github.com/goplus/lib/c"
cparser "github.com/goplus/llcppg/_xtool/internal/parser"
"github.com/goplus/llcppg/parser"
"github.com/goplus/llpkg/cjson"
)

type Mode = parser.Mode
Expand Down Expand Up @@ -50,10 +48,9 @@ func parseIntermediateFile(filename string, mode Mode) error {
if err != nil {
return fmt.Errorf("parseIntermediateFile: %w", err)
}
json := cparser.MarshalASTFile(file)
str := json.Print()
defer cjson.FreeCStr(unsafe.Pointer(str))
defer json.Delete()
c.Printf(c.Str("%s"), str)
js := cparser.XMarshalASTFile(file)
str, _ := json.MarshalIndent(&js, "", " ")

fmt.Println(string(str))
return nil
}
26 changes: 12 additions & 14 deletions _xtool/llcppsigfetch/internal/parse/dump.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package parse

import (
"github.com/goplus/lib/c"
"github.com/goplus/llcppg/_xtool/internal/parser"
llcppg "github.com/goplus/llcppg/config"
"github.com/goplus/llpkg/cjson"
)

func MarshalPkg(pkg *llcppg.Pkg) *cjson.JSON {
root := cjson.Object()
root.SetItem(c.Str("File"), parser.MarshalASTFile(pkg.File))
root.SetItem(c.Str("FileMap"), MarshalFileMap(pkg.FileMap))
return root
func MarshalPkg(pkg *llcppg.Pkg) map[string]any {
return map[string]any{
"File": parser.XMarshalASTFile(pkg.File),
"FileMap": MarshalFileMap(pkg.FileMap),
}
}

func MarshalFileMap(fmap map[string]*llcppg.FileInfo) *cjson.JSON {
root := cjson.Object()
func MarshalFileMap(fmap map[string]*llcppg.FileInfo) map[string]any {
root := make(map[string]any)
for path, info := range fmap {
root.SetItem(c.AllocaCStr(path), MarshalFileInfo(info))
root[path] = MarshalFileInfo(info)
}
return root
}

func MarshalFileInfo(info *llcppg.FileInfo) *cjson.JSON {
root := cjson.Object()
root.SetItem(c.Str("FileType"), cjson.Number(float64(info.FileType)))
return root
func MarshalFileInfo(info *llcppg.FileInfo) map[string]any {
return map[string]any{
"FileType": float64(info.FileType),
}
}
14 changes: 5 additions & 9 deletions _xtool/llcppsigfetch/internal/parse/parse.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package parse

import (
"encoding/json"
"fmt"
"os"
"strings"
"unsafe"

"github.com/goplus/lib/c"
"github.com/goplus/llcppg/_xtool/internal/clangtool"
"github.com/goplus/llcppg/_xtool/internal/config"
"github.com/goplus/llcppg/_xtool/internal/parser"
llcppg "github.com/goplus/llcppg/config"
"github.com/goplus/llpkg/cjson"
)

type dbgFlags = int
Expand Down Expand Up @@ -157,23 +155,21 @@ func Do(conf *Config) error {

func OutputPkg(conf *Config, pkg *llcppg.Pkg) {
info := MarshalPkg(pkg)
str := info.Print()
defer cjson.FreeCStr(unsafe.Pointer(str))
defer info.Delete()
str, _ := json.MarshalIndent(&info, "", " ")
outputResult(str, conf.Out)
}

func outputResult(result *c.Char, outputToFile bool) {
func outputResult(result []byte, outputToFile bool) {
if outputToFile {
outputFile := llcppg.LLCPPG_SIGFETCH
err := os.WriteFile(outputFile, []byte(c.GoString(result)), 0644)
err := os.WriteFile(outputFile, result, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing to output file: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "Results saved to %s\n", outputFile)
} else {
c.Printf(c.Str("%s"), result)
fmt.Println(string(result))
}
}

Expand Down
Loading
Loading