View | Details | Raw Unified | Return to bug 185567
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java (-7 / +4 lines)
Lines 172-179 Link Here
172
	/**
172
	/**
173
	 * Boolean operator code generation Optimized operations are: &&
173
	 * Boolean operator code generation Optimized operations are: &&
174
	 */
174
	 */
175
	public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream,
175
	public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
176
			BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
177
176
178
		if (constant != Constant.NotAConstant) {
177
		if (constant != Constant.NotAConstant) {
179
			super.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel,
178
			super.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel,
Lines 206-213 Link Here
206
				if (trueLabel != null) {
205
				if (trueLabel != null) {
207
					// implicit falling through the FALSE case
206
					// implicit falling through the FALSE case
208
					BranchLabel internalFalseLabel = new BranchLabel(codeStream);
207
					BranchLabel internalFalseLabel = new BranchLabel(codeStream);
209
					left.generateOptimizedBoolean(currentScope, codeStream, null,
208
					left.generateOptimizedBoolean(currentScope, codeStream, null, internalFalseLabel, !leftIsConst); 
210
							internalFalseLabel, !leftIsConst); 
211
					// need value, e.g. if (a == 1 && ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a!=1
209
					// need value, e.g. if (a == 1 && ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a!=1
212
					if (leftIsConst && !leftIsTrue) {
210
					if (leftIsConst && !leftIsTrue) {
213
						internalFalseLabel.place();
211
						internalFalseLabel.place();
Lines 231-237 Link Here
231
					left.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, !leftIsConst); 
229
					left.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, !leftIsConst); 
232
					// need value, e.g. if (a == 1 && ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a!=1
230
					// need value, e.g. if (a == 1 && ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a!=1
233
					if (leftIsConst && !leftIsTrue) {
231
					if (leftIsConst && !leftIsTrue) {
234
						codeStream.goto_(falseLabel);
232
						if (valueRequired) codeStream.goto_(falseLabel);
235
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
233
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
236
						break generateOperands; // no need to generate right operand
234
						break generateOperands; // no need to generate right operand
237
					}
235
					}
Lines 239-246 Link Here
239
						codeStream
237
						codeStream
240
								.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
238
								.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
241
					}
239
					}
242
					right.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel,
240
					right.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, valueRequired && !rightIsConst);
243
							valueRequired && !rightIsConst);
244
					if (valueRequired && rightIsConst && !rightIsTrue) {
241
					if (valueRequired && rightIsConst && !rightIsTrue) {
245
						codeStream.goto_(falseLabel);
242
						codeStream.goto_(falseLabel);
246
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
243
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java (-13 / +8 lines)
Lines 73-79 Link Here
73
	 * Code generation for a binary operation
73
	 * Code generation for a binary operation
74
	 */
74
	 */
75
	public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
75
	public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
76
77
		int pc = codeStream.position;
76
		int pc = codeStream.position;
78
		if (constant != Constant.NotAConstant) {
77
		if (constant != Constant.NotAConstant) {
79
			// inlined value
78
			// inlined value
Lines 176-182 Link Here
176
	 * Boolean operator code generation Optimized operations are: ||
175
	 * Boolean operator code generation Optimized operations are: ||
177
	 */
176
	 */
178
	public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
177
	public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
179
180
		if (constant != Constant.NotAConstant) {
178
		if (constant != Constant.NotAConstant) {
181
			super.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel, valueRequired);
179
			super.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel, valueRequired);
182
			return;
180
			return;
Lines 209-225 Link Here
209
					// implicit falling through the FALSE case
207
					// implicit falling through the FALSE case
210
					left.generateOptimizedBoolean(currentScope, codeStream, trueLabel, null, !leftIsConst); 
208
					left.generateOptimizedBoolean(currentScope, codeStream, trueLabel, null, !leftIsConst); 
211
					// need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
209
					// need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
212
					if (leftIsConst && leftIsTrue) {
210
					if (leftIsTrue) {
213
						codeStream.goto_(trueLabel);
211
						if (valueRequired) codeStream.goto_(trueLabel);
214
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
212
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
215
						break generateOperands; // no need to generate right operand
213
						break generateOperands; // no need to generate right operand
216
					}
214
					}
217
					if (rightInitStateIndex != -1) {
215
					if (rightInitStateIndex != -1) {
218
						codeStream
216
						codeStream.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
219
								.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
220
					}
217
					}
221
					right.generateOptimizedBoolean(currentScope, codeStream, trueLabel, null, valueRequired && !rightIsConst);
218
					right.generateOptimizedBoolean(currentScope, codeStream, trueLabel, null, valueRequired && !rightIsConst);
222
					if (valueRequired && rightIsConst && rightIsTrue) {
219
					if (valueRequired && rightIsTrue) {
223
						codeStream.goto_(trueLabel);
220
						codeStream.goto_(trueLabel);
224
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
221
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
225
					}
222
					}
Lines 230-236 Link Here
230
					BranchLabel internalTrueLabel = new BranchLabel(codeStream);
227
					BranchLabel internalTrueLabel = new BranchLabel(codeStream);
231
					left.generateOptimizedBoolean(currentScope, codeStream, internalTrueLabel, null, !leftIsConst); 
228
					left.generateOptimizedBoolean(currentScope, codeStream, internalTrueLabel, null, !leftIsConst); 
232
					// need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
229
					// need value, e.g. if (a == 1 || ((b = 2) > 0)) {} -> shouldn't initialize 'b' if a==1
233
					if (leftIsConst && leftIsTrue) {
230
					if (leftIsTrue) {
234
						internalTrueLabel.place();
231
						internalTrueLabel.place();
235
						break generateOperands; // no need to generate right operand
232
						break generateOperands; // no need to generate right operand
236
					}
233
					}
Lines 239-249 Link Here
239
								.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
236
								.addDefinitelyAssignedVariables(currentScope, rightInitStateIndex);
240
					}
237
					}
241
					right.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, valueRequired && !rightIsConst);
238
					right.generateOptimizedBoolean(currentScope, codeStream, null, falseLabel, valueRequired && !rightIsConst);
242
					if (valueRequired && rightIsConst) {
239
					if (valueRequired && rightIsConst && !rightIsTrue) {
243
						if (!rightIsTrue) {
240
						codeStream.goto_(falseLabel);
244
							codeStream.goto_(falseLabel);
241
						codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
245
							codeStream.updateLastRecordedEndPC(currentScope, codeStream.position);
246
						}
247
					}
242
					}
248
					internalTrueLabel.place();
243
					internalTrueLabel.place();
249
				} else {
244
				} else {

Return to bug 185567