Skip to content

Commit

Permalink
Merge pull request #388 from visualfc/commcase
Browse files Browse the repository at this point in the history
commCase: update scope
  • Loading branch information
xushiwei authored Feb 20, 2024
2 parents 4ebf0a5 + 4ea9c28 commit 92a75e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,10 +977,10 @@ func TestSelect(t *testing.T) {
pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
NewVar(tyXchg, "xchg").
/**/ Select().
/****/ DefineVarStart(0, "x").Val(ctxRef(pkg, "xchg")).UnaryOp(token.ARROW).EndInit(1).CommCase(1).
/****/ CommCase(1).DefineVarStart(0, "x").Val(ctxRef(pkg, "xchg")).UnaryOp(token.ARROW).EndInit(1).
/******/ NewVarStart(types.Typ[types.Int], "t").Val(ctxRef(pkg, "x")).EndInit(1).
/****/ End().
/****/ Val(ctxRef(pkg, "xchg")).Val(1).Send().CommCase(1).
/****/ CommCase(1).Val(ctxRef(pkg, "xchg")).Val(1).Send().
/******/ DefineVarStart(0, "x").Val(1).EndInit(1).
/****/ End().
/****/ CommCase(0).
Expand Down
17 changes: 9 additions & 8 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,7 @@ type selectStmt struct {
}

func (p *selectStmt) CommCase(cb *CodeBuilder, n int, src ...ast.Node) {
var comm ast.Stmt
if n == 1 {
comm = cb.popStmt()
}
stmt := &commCase{comm: comm}
stmt := &commCase{n: n}
cb.startBlockStmt(stmt, src, "comm case statement", &stmt.old)
}

Expand All @@ -241,14 +237,19 @@ func (p *selectStmt) End(cb *CodeBuilder, src ast.Node) {
}

type commCase struct {
comm ast.Stmt
old codeBlockCtx
n int
old codeBlockCtx
}

func (p *commCase) End(cb *CodeBuilder, src ast.Node) {
var comm ast.Stmt
if p.n == 1 {
comm = cb.current.stmts[0]
cb.current.stmts = cb.current.stmts[1:]
}
body, flows := cb.endBlockStmt(&p.old)
cb.current.flows |= flows
cb.emitStmt(&ast.CommClause{Comm: p.comm, Body: body})
cb.emitStmt(&ast.CommClause{Comm: comm, Body: body})
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 92a75e9

Please sign in to comment.