Thanks to visit codestin.com
Credit goes to github.com

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
7 changes: 3 additions & 4 deletions cl/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,17 @@ func getStringConst(spx *gox.PkgRef, name string) string {
return ""
}

func getFields(f *ast.File) (specs []ast.Spec) {
func getFields(f *ast.File) []ast.Spec {
for _, decl := range f.Decls {
if g, ok := decl.(*ast.GenDecl); ok {
if g.Tok == token.VAR {
specs, g.Specs = g.Specs, nil
return
return g.Specs
}
continue
}
break
}
return
return nil
}

func setBodyHandler(ctx *blockCtx) {
Expand Down
41 changes: 31 additions & 10 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,21 +758,34 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
tags = append(tags, "")
}
}
rec := ctx.recorder()
for _, v := range specs {
spec := v.(*ast.ValueSpec)
var embed bool
if spec.Names == nil {
embed = true
v := parseTypeEmbedName(spec.Type)
spec.Names = []*ast.Ident{v}
}
typ := toType(ctx, spec.Type)
for _, name := range spec.Names {
if chk.chkRedecl(ctx, name.Name, name.Pos()) {
tag := toFieldTag(spec.Tag)
if len(spec.Names) == 0 {
name := parseTypeEmbedName(spec.Type)
if chk.chkRedecl(ctx, name.Name, spec.Type.Pos()) {
continue
}
flds = append(flds, types.NewField(name.Pos(), pkg, name.Name, typ, embed))
tags = append(tags, toFieldTag(spec.Tag))
fld := types.NewField(spec.Type.Pos(), pkg, name.Name, typ, true)
if rec != nil {
rec.Def(name, fld)
}
flds = append(flds, fld)
tags = append(tags, tag)
} else {
for _, name := range spec.Names {
if chk.chkRedecl(ctx, name.Name, name.Pos()) {
continue
}
fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
if rec != nil {
rec.Def(name, fld)
}
flds = append(flds, fld)
tags = append(tags, tag)
}
}
}
decl.InitType(p, types.NewStruct(flds, tags))
Expand Down Expand Up @@ -834,6 +847,10 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
goFile := genGoFile(file, gopFile)
old, _ := p.SetCurFile(goFile, true)
defer p.RestoreCurFile(old)
var skipClassFields bool
if f.IsClass {
skipClassFields = true
}
for _, decl := range f.Decls {
switch d := decl.(type) {
case *ast.FuncDecl:
Expand Down Expand Up @@ -970,6 +987,10 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
})
}
case token.VAR:
if skipClassFields {
skipClassFields = false
continue
}
for _, spec := range d.Specs {
vSpec := spec.(*ast.ValueSpec)
if debugLoad {
Expand Down
41 changes: 21 additions & 20 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ func onCloned() {

import "github.com/goplus/gop/cl/internal/spx"

type Game struct {
*spx.MyGame
Kai Kai
}
type Kai struct {
spx.Sprite
*Game
a int
}
type Game struct {
*spx.MyGame
Kai Kai
}

func (this *Game) onInit() {
spx.Gopt_Sprite_Clone__0(this.Kai)
Expand Down Expand Up @@ -345,17 +345,18 @@ import (
"github.com/goplus/gop/cl/internal/spx"
)

type Kai struct {
spx.Sprite
*index
}

var x float64 = spx.Rand__1(1.2)

type index struct {
*spx.MyGame
Kai Kai
t spx.Sound
}
type Kai struct {
spx.Sprite
*index
}

func (this *index) MainEntry() {
spx.Gopt_MyGame_Run(this, "hzip://open.qiniu.us/weather/res.zip")
Expand Down Expand Up @@ -493,14 +494,14 @@ var (

import "github.com/goplus/gop/cl/internal/spx2"

type Game struct {
spx2.Game
Kai Kai
}
type Kai struct {
spx2.Sprite
*Game
}
type Game struct {
spx2.Game
Kai Kai
}

func (this *Game) MainEntry() {
}
Expand Down Expand Up @@ -529,14 +530,14 @@ import (
"github.com/goplus/gop/cl/internal/spx2"
)

type Game struct {
spx2.Game
Kai Kai
}
type Kai struct {
spx2.Sprite
*Game
}
type Game struct {
spx2.Game
Kai Kai
}

func (this *Game) MainEntry() {
fmt.Println("Hi")
Expand Down Expand Up @@ -630,15 +631,15 @@ type info struct {
x int
y int
}
type Game struct {
*spx.MyGame
Kai Kai
}
type Kai struct {
spx.Sprite
*Game
a int
}
type Game struct {
*spx.MyGame
Kai Kai
}

func (this *Game) onInit() {
spx.Gopt_Sprite_Clone__0(this.Kai)
Expand Down