-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLoopLabels.java
More file actions
114 lines (101 loc) · 4.11 KB
/
LoopLabels.java
File metadata and controls
114 lines (101 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package org.perlonjava.codegen;
import org.objectweb.asm.Label;
/**
* Represents control flow labels for loop constructs in bytecode generation.
* Manages the next, redo, and last labels commonly used in loop structures,
* along with their context and stack state information.
*/
public class LoopLabels {
/**
* The name of the loop label as it appears in the source code
*/
public String labelName;
/**
* The ASM Label for the 'next' statement (continues to next iteration)
*/
public Label nextLabel;
/**
* The ASM Label for the 'redo' statement (restarts current iteration)
*/
public Label redoLabel;
/**
* The ASM Label for the 'last' statement (exits the loop)
*/
public Label lastLabel;
/**
* The ASM Label for the control flow handler (processes marked RuntimeList)
* This handler checks the control flow type and label, then either handles
* it or propagates to parent loop handler
*/
public Label controlFlowHandler;
/**
* The context type in which this loop operates
*/
public int context;
/**
* Whether this is a "true" loop (for/while/until) vs a pseudo-loop (do-while/bare block).
* True loops allow last/next/redo. Pseudo-loops cause compile errors.
*/
public boolean isTrueLoop;
/**
* Whether unlabeled next/last/redo should target this loop/block.
*
* Perl semantics:
* - Unlabeled next/last/redo target the nearest enclosing true loop.
* - Labeled next/last/redo can target labeled blocks (e.g. next SKIP in SKIP: { ... }).
*
* We keep block loops on the stack so labeled control flow can find them,
* but prevent them from being selected as the target for unlabeled control flow.
*/
public boolean isUnlabeledControlFlowTarget;
/**
* Creates a new LoopLabels instance with all necessary label information.
*
* @param labelName The name of the loop label in source code
* @param nextLabel The ASM Label for 'next' operations
* @param redoLabel The ASM Label for 'redo' operations
* @param lastLabel The ASM Label for 'last' operations
* @param context The context type for this loop
*/
public LoopLabels(String labelName, Label nextLabel, Label redoLabel, Label lastLabel, int context) {
this(labelName, nextLabel, redoLabel, lastLabel, context, true, true);
}
/**
* Creates a new LoopLabels instance with all necessary label information.
*
* @param labelName The name of the loop label in source code
* @param nextLabel The ASM Label for 'next' operations
* @param redoLabel The ASM Label for 'redo' operations
* @param lastLabel The ASM Label for 'last' operations
* @param context The context type for this loop
* @param isTrueLoop Whether this is a true loop (for/while/until) or pseudo-loop (do-while/bare)
*/
public LoopLabels(String labelName, Label nextLabel, Label redoLabel, Label lastLabel, int context, boolean isTrueLoop) {
this(labelName, nextLabel, redoLabel, lastLabel, context, isTrueLoop, true);
}
public LoopLabels(String labelName, Label nextLabel, Label redoLabel, Label lastLabel, int context, boolean isTrueLoop, boolean isUnlabeledControlFlowTarget) {
this.labelName = labelName;
this.nextLabel = nextLabel;
this.redoLabel = redoLabel;
this.lastLabel = lastLabel;
this.context = context;
this.isTrueLoop = isTrueLoop;
this.isUnlabeledControlFlowTarget = isUnlabeledControlFlowTarget;
}
/**
* Returns a string representation of the LoopLabels object.
* Useful for debugging and logging purposes.
*
* @return A string containing all fields of this object
*/
@Override
public String toString() {
return "LoopLabels{" +
"labelName='" + labelName + '\'' +
", nextLabel=" + nextLabel +
", redoLabel=" + redoLabel +
", lastLabel=" + lastLabel +
", context=" + context +
'}';
}
}