@@ -50,7 +50,7 @@ public final class SFunction extends AStatement {
50
50
public final String name ;
51
51
private final List <String > paramTypeStrs ;
52
52
private final List <String > paramNameStrs ;
53
- private final List < AStatement > statements ;
53
+ private final SBlock block ;
54
54
public final boolean synthetic ;
55
55
56
56
private CompilerSettings settings ;
@@ -65,35 +65,31 @@ public final class SFunction extends AStatement {
65
65
private Variable loop = null ;
66
66
67
67
public SFunction (Location location , String rtnType , String name ,
68
- List <String > paramTypes , List <String > paramNames , List < AStatement > statements ,
68
+ List <String > paramTypes , List <String > paramNames , SBlock block ,
69
69
boolean synthetic ) {
70
70
super (location );
71
71
72
72
this .rtnTypeStr = Objects .requireNonNull (rtnType );
73
73
this .name = Objects .requireNonNull (name );
74
74
this .paramTypeStrs = Collections .unmodifiableList (paramTypes );
75
75
this .paramNameStrs = Collections .unmodifiableList (paramNames );
76
- this .statements = Collections . unmodifiableList ( statements );
76
+ this .block = Objects . requireNonNull ( block );
77
77
this .synthetic = synthetic ;
78
78
}
79
79
80
80
@ Override
81
81
void storeSettings (CompilerSettings settings ) {
82
- for (AStatement statement : statements ) {
83
- statement .storeSettings (settings );
84
- }
82
+ block .storeSettings (settings );
85
83
86
84
this .settings = settings ;
87
85
}
88
86
89
87
@ Override
90
88
void extractVariables (Set <String > variables ) {
91
- for (AStatement statement : statements ) {
92
- // we reset the list for function scope
93
- // note this is not stored for this node
94
- // but still required for lambdas
95
- statement .extractVariables (new HashSet <>());
96
- }
89
+ // we reset the list for function scope
90
+ // note this is not stored for this node
91
+ // but still required for lambdas
92
+ block .extractVariables (new HashSet <>());
97
93
}
98
94
99
95
void generateSignature (PainlessLookup painlessLookup ) {
@@ -131,28 +127,14 @@ void generateSignature(PainlessLookup painlessLookup) {
131
127
132
128
@ Override
133
129
void analyze (Locals locals ) {
134
- if (statements == null || statements .isEmpty ()) {
130
+ if (block . statements .isEmpty ()) {
135
131
throw createError (new IllegalArgumentException ("Cannot generate an empty function [" + name + "]." ));
136
132
}
137
133
138
134
locals = Locals .newLocalScope (locals );
139
-
140
- AStatement last = statements .get (statements .size () - 1 );
141
-
142
- for (AStatement statement : statements ) {
143
- // Note that we do not need to check after the last statement because
144
- // there is no statement that can be unreachable after the last.
145
- if (allEscape ) {
146
- throw createError (new IllegalArgumentException ("Unreachable statement." ));
147
- }
148
-
149
- statement .lastSource = statement == last ;
150
-
151
- statement .analyze (locals );
152
-
153
- methodEscape = statement .methodEscape ;
154
- allEscape = statement .allEscape ;
155
- }
135
+ block .lastSource = true ;
136
+ block .analyze (locals );
137
+ methodEscape = block .methodEscape ;
156
138
157
139
if (!methodEscape && returnType != void .class ) {
158
140
throw createError (new IllegalArgumentException ("Not all paths provide a return value for method [" + name + "]." ));
@@ -184,9 +166,7 @@ void write(MethodWriter function, Globals globals) {
184
166
function .visitVarInsn (Opcodes .ISTORE , loop .getSlot ());
185
167
}
186
168
187
- for (AStatement statement : statements ) {
188
- statement .write (function , globals );
189
- }
169
+ block .write (function , globals );
190
170
191
171
if (!methodEscape ) {
192
172
if (returnType == void .class ) {
@@ -205,6 +185,6 @@ public String toString() {
205
185
if (false == (paramTypeStrs .isEmpty () && paramNameStrs .isEmpty ())) {
206
186
description .add (joinWithName ("Args" , pairwiseToString (paramTypeStrs , paramNameStrs ), emptyList ()));
207
187
}
208
- return multilineToString (description , statements );
188
+ return multilineToString (description , block . statements );
209
189
}
210
190
}
0 commit comments