Skip to content

Commit 83744f7

Browse files
committed
refactor(compiler): simplify cond expr branch helper
Collapse the WithFailure variant into compileCondExprBranch by making the false continuation explicit at each call site.
1 parent 0c9d51b commit 83744f7

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

compiler/cond.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func (c *Compiler) compileCondExprValueInFrame(expr ast.Expression, baseCond llv
535535
}
536536

537537
cond, temps := c.extractCondExprs(expr, baseCond, nil)
538-
c.compileCondExprBranch(cond, temps, onTrue)
538+
c.compileCondExprBranch(cond, temps, onTrue, func() {})
539539
}
540540

541541
// compileOperandCondExprValue extracts conditional expressions from expr's
@@ -555,14 +555,10 @@ func (c *Compiler) compileOperandCondExprValue(expr ast.Expression, baseCond llv
555555
for _, child := range ast.ExprChildren(expr) {
556556
cond, temps = c.extractCondExprs(child, cond, temps)
557557
}
558-
c.compileCondExprBranch(cond, temps, onTrue)
558+
c.compileCondExprBranch(cond, temps, onTrue, func() {})
559559
}
560560

561-
func (c *Compiler) compileCondExprBranch(cond llvm.Value, temps []condTemp, onTrue func()) {
562-
c.compileCondExprBranchWithFailure(cond, temps, onTrue, func() {})
563-
}
564-
565-
func (c *Compiler) compileCondExprBranchWithFailure(cond llvm.Value, temps []condTemp, onTrue func(), onFalse func()) {
561+
func (c *Compiler) compileCondExprBranch(cond llvm.Value, temps []condTemp, onTrue func(), onFalse func()) {
566562
if cond.IsNil() {
567563
onTrue()
568564
return
@@ -584,7 +580,7 @@ func (c *Compiler) compileCondExprBranchWithFailure(cond llvm.Value, temps []con
584580

585581
func (c *Compiler) compileCondExprChildrenInFrame(children []ast.Expression, baseCond llvm.Value, onTrue func(), onFalse func()) {
586582
if len(children) == 0 {
587-
c.compileCondExprBranchWithFailure(baseCond, nil, onTrue, onFalse)
583+
c.compileCondExprBranch(baseCond, nil, onTrue, onFalse)
588584
return
589585
}
590586

@@ -608,7 +604,7 @@ func (c *Compiler) compileCondExprWithFailure(expr ast.Expression, baseCond llvm
608604

609605
if !c.hasLogicalOrCondExprInTree(expr) {
610606
cond, temps := c.extractCondExprs(expr, baseCond, nil)
611-
c.compileCondExprBranchWithFailure(cond, temps, onTrue, onFalse)
607+
c.compileCondExprBranch(cond, temps, onTrue, onFalse)
612608
return
613609
}
614610

@@ -617,7 +613,7 @@ func (c *Compiler) compileCondExprWithFailure(expr ast.Expression, baseCond llvm
617613
info := c.ExprCache[key(c.FuncNameMangled, infix)]
618614
if info != nil && info.HasCondScalar() && len(c.pendingLoopRanges(info.Ranges)) == 0 {
619615
cond, temps := c.extractCondExprSelf(infix, info, llvm.Value{}, nil)
620-
c.compileCondExprBranchWithFailure(cond, temps, onTrue, onFalse)
616+
c.compileCondExprBranch(cond, temps, onTrue, onFalse)
621617
return
622618
}
623619
}
@@ -636,7 +632,7 @@ func (c *Compiler) withCondLHS(expr ast.Expression, syms []*Symbol, body func())
636632

637633
func (c *Compiler) compileLogicalOrCondExprWithFailure(expr *ast.InfixExpression, baseCond llvm.Value, onTrue func(), onFalse func()) {
638634
if !baseCond.IsNil() {
639-
c.compileCondExprBranchWithFailure(baseCond, nil, func() {
635+
c.compileCondExprBranch(baseCond, nil, func() {
640636
c.compileLogicalOrCondExprWithFailure(expr, llvm.Value{}, onTrue, onFalse)
641637
}, onFalse)
642638
return

0 commit comments

Comments
 (0)