14
14
const (
15
15
TRANS_CONTINUE TransCtrl = iota
16
16
TRANS_SKIP
17
- TRANS_BREAK
18
17
TRANS_EXIT
19
18
)
20
19
@@ -101,7 +100,7 @@ const (
101
100
TRANS_IMPORT_PATH
102
101
TRANS_CONST_TYPE
103
102
TRANS_CONST_VALUE
104
- TRANS_VAR_NAME // XXX stringer
103
+ TRANS_VAR_NAME
105
104
TRANS_VAR_TYPE
106
105
TRANS_VAR_VALUE
107
106
TRANS_TYPE_TYPE
@@ -113,8 +112,6 @@ const (
113
112
// - TRANS_SKIP to break out of the
114
113
// ENTER,CHILDS1,[BLOCK,CHILDS2]?,LEAVE sequence for that node,
115
114
// 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.
118
115
// - TRANS_EXIT to stop traversing altogether.
119
116
//
120
117
// Do not mutate ns.
@@ -168,9 +165,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
168
165
}
169
166
for idx := range cnn .Args {
170
167
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 ) {
174
169
return
175
170
}
176
171
}
@@ -248,16 +243,12 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
248
243
k , v := kvx .Key , kvx .Value
249
244
if k != nil {
250
245
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 ) {
254
247
return
255
248
}
256
249
}
257
250
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 ) {
261
252
return
262
253
}
263
254
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
269
260
}
270
261
for idx := range cnn .HeapCaptures {
271
262
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 ) {
275
264
return
276
265
}
277
266
}
@@ -285,9 +274,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
285
274
// iterate over Body; its length can change if a statement is decomposed.
286
275
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
287
276
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 ) {
291
278
return
292
279
}
293
280
}
@@ -321,9 +308,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
321
308
case * InterfaceTypeExpr :
322
309
for idx := range cnn .Methods {
323
310
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 ) {
327
312
return
328
313
}
329
314
}
@@ -341,9 +326,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
341
326
}
342
327
for idx := range cnn .Results {
343
328
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 ) {
347
330
return
348
331
}
349
332
}
@@ -359,9 +342,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
359
342
case * StructTypeExpr :
360
343
for idx := range cnn .Fields {
361
344
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 ) {
365
346
return
366
347
}
367
348
}
@@ -373,17 +354,13 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
373
354
case * AssignStmt :
374
355
for idx := range cnn .Lhs {
375
356
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 ) {
379
358
return
380
359
}
381
360
}
382
361
for idx := range cnn .Rhs {
383
362
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 ) {
387
364
return
388
365
}
389
366
}
@@ -398,9 +375,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
398
375
// iterate over Body; its length can change if a statement is decomposed.
399
376
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
400
377
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 ) {
404
379
return
405
380
}
406
381
}
@@ -409,9 +384,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
409
384
// iterate over Body; its length can change if a statement is decomposed.
410
385
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
411
386
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 ) {
415
388
return
416
389
}
417
390
}
@@ -455,9 +428,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
455
428
// iterate over Body; its length can change if a statement is decomposed.
456
429
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
457
430
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 ) {
461
432
return
462
433
}
463
434
}
@@ -506,9 +477,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
506
477
// iterate over Body; its length can change if a statement is decomposed.
507
478
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
508
479
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 ) {
512
481
return
513
482
}
514
483
}
@@ -544,18 +513,14 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
544
513
// iterate over Body; its length can change if a statement is decomposed.
545
514
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
546
515
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 ) {
550
517
return
551
518
}
552
519
}
553
520
case * ReturnStmt :
554
521
for idx := range cnn .Results {
555
522
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 ) {
559
524
return
560
525
}
561
526
}
@@ -564,9 +529,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
564
529
case * SelectStmt :
565
530
for idx := range cnn .Cases {
566
531
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 ) {
570
533
return
571
534
}
572
535
}
@@ -585,9 +548,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
585
548
// iterate over Body; its length can change if a statement is decomposed.
586
549
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
587
550
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 ) {
591
552
return
592
553
}
593
554
}
@@ -632,9 +593,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
632
593
}
633
594
for idx := range cnn .Clauses {
634
595
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 ) {
638
597
return
639
598
}
640
599
}
@@ -652,18 +611,14 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
652
611
}
653
612
for idx := range cnn .Cases {
654
613
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 ) {
658
615
return
659
616
}
660
617
}
661
618
// iterate over Body; its length can change if a statement is decomposed.
662
619
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
663
620
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 ) {
667
622
return
668
623
}
669
624
}
@@ -688,9 +643,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
688
643
// iterate over Body; its length can change if a statement is decomposed.
689
644
for idx := 0 ; idx < len (cnn .Body ); idx ++ {
690
645
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 ) {
694
647
return
695
648
}
696
649
}
@@ -709,9 +662,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
709
662
}
710
663
for idx := range cnn .Values {
711
664
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 ) {
715
666
return
716
667
}
717
668
}
@@ -730,9 +681,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc
730
681
}
731
682
for idx := range cnn .Decls {
732
683
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 ) {
736
685
return
737
686
}
738
687
}
@@ -768,12 +717,3 @@ func isStopOrSkip(oldnc *TransCtrl, nc TransCtrl) (stop bool) {
768
717
panic ("should not happen" )
769
718
}
770
719
}
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