Skip to content

Commit 07e3c49

Browse files
authored
refactor(gnovm): remove TRANS_BREAK from transcriber (#3626)
was unused until now, and it looks redundant if we have TRANS_SKIP anyway.
1 parent 31fcf6a commit 07e3c49

File tree

2 files changed

+28
-89
lines changed

2 files changed

+28
-89
lines changed

gnovm/pkg/gnolang/string_methods.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gnovm/pkg/gnolang/transcribe.go

Lines changed: 25 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type (
1414
const (
1515
TRANS_CONTINUE TransCtrl = iota
1616
TRANS_SKIP
17-
TRANS_BREAK
1817
TRANS_EXIT
1918
)
2019

@@ -101,7 +100,7 @@ const (
101100
TRANS_IMPORT_PATH
102101
TRANS_CONST_TYPE
103102
TRANS_CONST_VALUE
104-
TRANS_VAR_NAME // XXX stringer
103+
TRANS_VAR_NAME
105104
TRANS_VAR_TYPE
106105
TRANS_VAR_VALUE
107106
TRANS_TYPE_TYPE
@@ -113,8 +112,6 @@ const (
113112
// - TRANS_SKIP to break out of the
114113
// ENTER,CHILDS1,[BLOCK,CHILDS2]?,LEAVE sequence for that node,
115114
// i.e. skipping (the rest of) it;
116-
// - TRANS_BREAK to break out of looping in CHILDS1 or CHILDS2,
117-
// but still perform TRANS_LEAVE.
118115
// - TRANS_EXIT to stop traversing altogether.
119116
//
120117
// Do not mutate ns.
@@ -168,9 +165,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
168165
}
169166
for idx := range cnn.Args {
170167
cnn.Args[idx] = transcribe(t, nns, TRANS_CALL_ARG, idx, cnn.Args[idx], &c).(Expr)
171-
if isBreak(c) {
172-
break
173-
} else if isStopOrSkip(nc, c) {
168+
if isStopOrSkip(nc, c) {
174169
return
175170
}
176171
}
@@ -248,16 +243,12 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
248243
k, v := kvx.Key, kvx.Value
249244
if k != nil {
250245
k = transcribe(t, nns, TRANS_COMPOSITE_KEY, idx, k, &c).(Expr)
251-
if isBreak(c) {
252-
break
253-
} else if isStopOrSkip(nc, c) {
246+
if isStopOrSkip(nc, c) {
254247
return
255248
}
256249
}
257250
v = transcribe(t, nns, TRANS_COMPOSITE_VALUE, idx, v, &c).(Expr)
258-
if isBreak(c) {
259-
break
260-
} else if isStopOrSkip(nc, c) {
251+
if isStopOrSkip(nc, c) {
261252
return
262253
}
263254
cnn.Elts[idx] = KeyValueExpr{Key: k, Value: v}
@@ -269,9 +260,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
269260
}
270261
for idx := range cnn.HeapCaptures {
271262
cnn.HeapCaptures[idx] = *(transcribe(t, nns, TRANS_FUNCLIT_HEAP_CAPTURE, idx, &cnn.HeapCaptures[idx], &c).(*NameExpr))
272-
if isBreak(c) {
273-
break
274-
} else if isStopOrSkip(nc, c) {
263+
if isStopOrSkip(nc, c) {
275264
return
276265
}
277266
}
@@ -285,9 +274,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
285274
// iterate over Body; its length can change if a statement is decomposed.
286275
for idx := 0; idx < len(cnn.Body); idx++ {
287276
cnn.Body[idx] = transcribe(t, nns, TRANS_FUNCLIT_BODY, idx, cnn.Body[idx], &c).(Stmt)
288-
if isBreak(c) {
289-
break
290-
} else if isStopOrSkip(nc, c) {
277+
if isStopOrSkip(nc, c) {
291278
return
292279
}
293280
}
@@ -321,9 +308,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
321308
case *InterfaceTypeExpr:
322309
for idx := range cnn.Methods {
323310
cnn.Methods[idx] = *transcribe(t, nns, TRANS_INTERFACETYPE_METHOD, idx, &cnn.Methods[idx], &c).(*FieldTypeExpr)
324-
if isBreak(c) {
325-
break
326-
} else if isStopOrSkip(nc, c) {
311+
if isStopOrSkip(nc, c) {
327312
return
328313
}
329314
}
@@ -341,9 +326,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
341326
}
342327
for idx := range cnn.Results {
343328
cnn.Results[idx] = *transcribe(t, nns, TRANS_FUNCTYPE_RESULT, idx, &cnn.Results[idx], &c).(*FieldTypeExpr)
344-
if isBreak(c) {
345-
break
346-
} else if isStopOrSkip(nc, c) {
329+
if isStopOrSkip(nc, c) {
347330
return
348331
}
349332
}
@@ -359,9 +342,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
359342
case *StructTypeExpr:
360343
for idx := range cnn.Fields {
361344
cnn.Fields[idx] = *transcribe(t, nns, TRANS_STRUCTTYPE_FIELD, idx, &cnn.Fields[idx], &c).(*FieldTypeExpr)
362-
if isBreak(c) {
363-
break
364-
} else if isStopOrSkip(nc, c) {
345+
if isStopOrSkip(nc, c) {
365346
return
366347
}
367348
}
@@ -373,17 +354,13 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
373354
case *AssignStmt:
374355
for idx := range cnn.Lhs {
375356
cnn.Lhs[idx] = transcribe(t, nns, TRANS_ASSIGN_LHS, idx, cnn.Lhs[idx], &c).(Expr)
376-
if isBreak(c) {
377-
break
378-
} else if isStopOrSkip(nc, c) {
357+
if isStopOrSkip(nc, c) {
379358
return
380359
}
381360
}
382361
for idx := range cnn.Rhs {
383362
cnn.Rhs[idx] = transcribe(t, nns, TRANS_ASSIGN_RHS, idx, cnn.Rhs[idx], &c).(Expr)
384-
if isBreak(c) {
385-
break
386-
} else if isStopOrSkip(nc, c) {
363+
if isStopOrSkip(nc, c) {
387364
return
388365
}
389366
}
@@ -398,9 +375,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
398375
// iterate over Body; its length can change if a statement is decomposed.
399376
for idx := 0; idx < len(cnn.Body); idx++ {
400377
cnn.Body[idx] = transcribe(t, nns, TRANS_BLOCK_BODY, idx, cnn.Body[idx], &c).(Stmt)
401-
if isBreak(c) {
402-
break
403-
} else if isStopOrSkip(nc, c) {
378+
if isStopOrSkip(nc, c) {
404379
return
405380
}
406381
}
@@ -409,9 +384,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
409384
// iterate over Body; its length can change if a statement is decomposed.
410385
for idx := 0; idx < len(cnn.Body); idx++ {
411386
cnn.Body[idx] = transcribe(t, nns, TRANS_DECL_BODY, idx, cnn.Body[idx], &c).(SimpleDeclStmt)
412-
if isBreak(c) {
413-
break
414-
} else if isStopOrSkip(nc, c) {
387+
if isStopOrSkip(nc, c) {
415388
return
416389
}
417390
}
@@ -455,9 +428,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
455428
// iterate over Body; its length can change if a statement is decomposed.
456429
for idx := 0; idx < len(cnn.Body); idx++ {
457430
cnn.Body[idx] = transcribe(t, nns, TRANS_FOR_BODY, idx, cnn.Body[idx], &c).(Stmt)
458-
if isBreak(c) {
459-
break
460-
} else if isStopOrSkip(nc, c) {
431+
if isStopOrSkip(nc, c) {
461432
return
462433
}
463434
}
@@ -506,9 +477,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
506477
// iterate over Body; its length can change if a statement is decomposed.
507478
for idx := 0; idx < len(cnn.Body); idx++ {
508479
cnn.Body[idx] = transcribe(t, nns, TRANS_IF_CASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
509-
if isBreak(c) {
510-
break
511-
} else if isStopOrSkip(nc, c) {
480+
if isStopOrSkip(nc, c) {
512481
return
513482
}
514483
}
@@ -544,18 +513,14 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
544513
// iterate over Body; its length can change if a statement is decomposed.
545514
for idx := 0; idx < len(cnn.Body); idx++ {
546515
cnn.Body[idx] = transcribe(t, nns, TRANS_RANGE_BODY, idx, cnn.Body[idx], &c).(Stmt)
547-
if isBreak(c) {
548-
break
549-
} else if isStopOrSkip(nc, c) {
516+
if isStopOrSkip(nc, c) {
550517
return
551518
}
552519
}
553520
case *ReturnStmt:
554521
for idx := range cnn.Results {
555522
cnn.Results[idx] = transcribe(t, nns, TRANS_RETURN_RESULT, idx, cnn.Results[idx], &c).(Expr)
556-
if isBreak(c) {
557-
break
558-
} else if isStopOrSkip(nc, c) {
523+
if isStopOrSkip(nc, c) {
559524
return
560525
}
561526
}
@@ -564,9 +529,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
564529
case *SelectStmt:
565530
for idx := range cnn.Cases {
566531
cnn.Cases[idx] = *transcribe(t, nns, TRANS_SELECT_CASE, idx, &cnn.Cases[idx], &c).(*SelectCaseStmt)
567-
if isBreak(c) {
568-
break
569-
} else if isStopOrSkip(nc, c) {
532+
if isStopOrSkip(nc, c) {
570533
return
571534
}
572535
}
@@ -585,9 +548,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
585548
// iterate over Body; its length can change if a statement is decomposed.
586549
for idx := 0; idx < len(cnn.Body); idx++ {
587550
cnn.Body[idx] = transcribe(t, nns, TRANS_SELECTCASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
588-
if isBreak(c) {
589-
break
590-
} else if isStopOrSkip(nc, c) {
551+
if isStopOrSkip(nc, c) {
591552
return
592553
}
593554
}
@@ -632,9 +593,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
632593
}
633594
for idx := range cnn.Clauses {
634595
cnn.Clauses[idx] = *transcribe(t, nns, TRANS_SWITCH_CASE, idx, &cnn.Clauses[idx], &c).(*SwitchClauseStmt)
635-
if isBreak(c) {
636-
break
637-
} else if isStopOrSkip(nc, c) {
596+
if isStopOrSkip(nc, c) {
638597
return
639598
}
640599
}
@@ -652,18 +611,14 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
652611
}
653612
for idx := range cnn.Cases {
654613
cnn.Cases[idx] = transcribe(t, nns, TRANS_SWITCHCASE_CASE, idx, cnn.Cases[idx], &c).(Expr)
655-
if isBreak(c) {
656-
break
657-
} else if isStopOrSkip(nc, c) {
614+
if isStopOrSkip(nc, c) {
658615
return
659616
}
660617
}
661618
// iterate over Body; its length can change if a statement is decomposed.
662619
for idx := 0; idx < len(cnn.Body); idx++ {
663620
cnn.Body[idx] = transcribe(t, nns, TRANS_SWITCHCASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
664-
if isBreak(c) {
665-
break
666-
} else if isStopOrSkip(nc, c) {
621+
if isStopOrSkip(nc, c) {
667622
return
668623
}
669624
}
@@ -688,9 +643,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
688643
// iterate over Body; its length can change if a statement is decomposed.
689644
for idx := 0; idx < len(cnn.Body); idx++ {
690645
cnn.Body[idx] = transcribe(t, nns, TRANS_FUNC_BODY, idx, cnn.Body[idx], &c).(Stmt)
691-
if isBreak(c) {
692-
break
693-
} else if isStopOrSkip(nc, c) {
646+
if isStopOrSkip(nc, c) {
694647
return
695648
}
696649
}
@@ -709,9 +662,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
709662
}
710663
for idx := range cnn.Values {
711664
cnn.Values[idx] = transcribe(t, nns, TRANS_VAR_VALUE, idx, cnn.Values[idx], &c).(Expr)
712-
if isBreak(c) {
713-
break
714-
} else if isStopOrSkip(nc, c) {
665+
if isStopOrSkip(nc, c) {
715666
return
716667
}
717668
}
@@ -730,9 +681,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
730681
}
731682
for idx := range cnn.Decls {
732683
cnn.Decls[idx] = transcribe(t, nns, TRANS_FILE_BODY, idx, cnn.Decls[idx], &c).(Decl)
733-
if isBreak(c) {
734-
break
735-
} else if isStopOrSkip(nc, c) {
684+
if isStopOrSkip(nc, c) {
736685
return
737686
}
738687
}
@@ -768,12 +717,3 @@ func isStopOrSkip(oldnc *TransCtrl, nc TransCtrl) (stop bool) {
768717
panic("should not happen")
769718
}
770719
}
771-
772-
// returns true if transcribe() should break (a loop).
773-
func isBreak(nc TransCtrl) (brek bool) {
774-
if nc == TRANS_BREAK {
775-
return true
776-
} else {
777-
return false
778-
}
779-
}

0 commit comments

Comments
 (0)