Skip to content
Draft
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
24 changes: 21 additions & 3 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
gotoken "go/token"
"go/types"
"log"
"os"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -210,6 +211,7 @@ type Config struct {
type nodeInterp struct {
fset *token.FileSet
files map[string]*ast.File
codes map[string][]byte
relBaseDir string
}

Expand All @@ -232,9 +234,17 @@ func (p *nodeInterp) LoadExpr(node ast.Node) string {
return ""
}
pos := p.fset.Position(start)
f := p.files[pos.Filename]
n := int(node.End() - start)
return string(f.Code[pos.Offset : pos.Offset+n])
code := p.codes[pos.Filename]
if code == nil {
src, err := os.ReadFile(pos.Filename)
if err != nil {
return ""
}
code = src
p.codes[pos.Filename] = code
}
return string(code[pos.Offset : pos.Offset+n])
}

func (p *nodeInterp) ProjFile() *ast.File {
Expand Down Expand Up @@ -360,6 +370,7 @@ type pkgCtx struct {

goxMainClass string
goxMain int32 // normal gox files with main func
outline bool
}

type pkgImp struct {
Expand Down Expand Up @@ -577,7 +588,13 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gogen.Packag
fset := conf.Fset
files := pkg.Files
interp := &nodeInterp{
fset: fset, files: files, relBaseDir: relBaseDir,
fset: fset,
files: files,
codes: make(map[string][]byte, len(pkg.Files)),
relBaseDir: relBaseDir,
}
for filename, f := range files {
interp.codes[filename] = f.Code
}
ctx := &pkgCtx{
fset: fset,
Expand All @@ -587,6 +604,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gogen.Packag
overpos: make(map[string]token.Pos),
syms: make(map[string]loader),
generics: make(map[string]bool),
outline: conf.Outline,
}
confGox := &gogen.Config{
Types: conf.Types,
Expand Down
12 changes: 11 additions & 1 deletion cl/func_type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,17 @@ func instantiate(ctx *blockCtx, exprX ast.Expr, indices ...ast.Expr) types.Type
for i, index := range indices {
idx[i] = toType(ctx, index)
}
typ := ctx.pkg.Instantiate(x, idx, exprX)
var typ types.Type
if ctx.outline {
var err error
typ, err = types.Instantiate(nil, x, idx, false)
if err != nil {
ctx.handleErrorf(exprX.Pos(), exprX.End(), "%v", err)
return types.Typ[types.Invalid]
}
} else {
typ = ctx.pkg.Instantiate(x, idx, exprX)
}
if rec := ctx.recorder(); rec != nil {
rec.instantiate(exprX, x, typ)
}
Expand Down
Loading