View | Details | Raw Unified | Return to bug 150074 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java (-19 / +54 lines)
Lines 124-143 Link Here
124
124
125
		// we need the variable to iterate the collection even if the 
125
		// we need the variable to iterate the collection even if the 
126
		// element variable is not used
126
		// element variable is not used
127
		if (!(this.action == null
127
		switch(this.kind) {
128
				|| this.action.isEmptyBlock()
128
			case ARRAY :
129
				|| ((this.action.bits & IsUsefulEmptyStatement) != 0))) {
129
				this.collectionVariable.useFlag = LocalVariableBinding.USED;
130
			switch(this.kind) {
130
				this.indexVariable.useFlag = LocalVariableBinding.USED;
131
				case ARRAY :
131
				this.maxVariable.useFlag = LocalVariableBinding.USED;
132
					this.collectionVariable.useFlag = LocalVariableBinding.USED;
132
				break;
133
					this.indexVariable.useFlag = LocalVariableBinding.USED;
133
			case RAW_ITERABLE :
134
					this.maxVariable.useFlag = LocalVariableBinding.USED;
134
			case GENERIC_ITERABLE :
135
					break;
135
				this.indexVariable.useFlag = LocalVariableBinding.USED;
136
				case RAW_ITERABLE :
136
				break;
137
				case GENERIC_ITERABLE :
138
					this.indexVariable.useFlag = LocalVariableBinding.USED;
139
					break;
140
			}
141
		}
137
		}
142
		//end of loop
138
		//end of loop
143
		loopingContext.complainOnDeferredNullChecks(currentScope, actionInfo);
139
		loopingContext.complainOnDeferredNullChecks(currentScope, actionInfo);
Lines 167-175 Link Here
167
			return;
163
			return;
168
		}
164
		}
169
		int pc = codeStream.position;
165
		int pc = codeStream.position;
166
167
		// label management
168
		BranchLabel actionLabel = new BranchLabel(codeStream);
169
		actionLabel.tagBits |= BranchLabel.USED;
170
		BranchLabel conditionLabel = new BranchLabel(codeStream);
171
		conditionLabel.tagBits |= BranchLabel.USED;
172
		breakLabel.initialize(codeStream);
173
170
		if (this.action == null
174
		if (this.action == null
171
				|| this.action.isEmptyBlock()
175
				|| this.action.isEmptyBlock()
172
				|| ((this.action.bits & IsUsefulEmptyStatement) != 0)) {
176
				|| ((this.action.bits & IsUsefulEmptyStatement) != 0)) {
177
178
			switch(this.kind) {
179
				case RAW_ITERABLE :
180
				case GENERIC_ITERABLE :
181
					collection.generateCode(scope, codeStream, true);
182
					// declaringClass.iterator();
183
					MethodBinding iteratorMethodBinding =
184
						new MethodBinding(
185
								ClassFileConstants.AccPublic,
186
								"iterator".toCharArray(),//$NON-NLS-1$
187
								scope.getJavaUtilIterator(),
188
								Binding.NO_PARAMETERS,
189
								Binding.NO_EXCEPTIONS,
190
								(ReferenceBinding) this.iteratorReceiverType.erasure());
191
					if (this.iteratorReceiverType.isInterface()) {
192
						codeStream.invokeinterface(iteratorMethodBinding);
193
					} else {
194
						codeStream.invokevirtual(iteratorMethodBinding);
195
					}
196
					codeStream.store(this.indexVariable, false);
197
					break;
198
			}
199
			// generate the loop action
200
			actionLabel.place();
201
			
202
			int conditionPC = codeStream.position;
203
			switch(this.kind) {
204
				case RAW_ITERABLE :
205
				case GENERIC_ITERABLE :
206
					codeStream.load(this.indexVariable);
207
					codeStream.invokeJavaUtilIteratorHasNext();
208
					codeStream.ifne(actionLabel);
209
					break;
210
			}
211
			codeStream.recordPositionsFrom(conditionPC, this.elementVariable.sourceStart);
212
			
173
			codeStream.exitUserScope(scope);
213
			codeStream.exitUserScope(scope);
174
			if (mergedInitStateIndex != -1) {
214
			if (mergedInitStateIndex != -1) {
175
				codeStream.removeNotDefinitelyAssignedVariables(currentScope, mergedInitStateIndex);
215
				codeStream.removeNotDefinitelyAssignedVariables(currentScope, mergedInitStateIndex);
Lines 211-221 Link Here
211
		}
251
		}
212
		
252
		
213
		// label management
253
		// label management
214
		BranchLabel actionLabel = new BranchLabel(codeStream);
215
		actionLabel.tagBits |= BranchLabel.USED;
216
		BranchLabel conditionLabel = new BranchLabel(codeStream);
217
		conditionLabel.tagBits |= BranchLabel.USED;
218
		breakLabel.initialize(codeStream);
219
		if (this.continueLabel != null) {
254
		if (this.continueLabel != null) {
220
			this.continueLabel.initialize(codeStream);
255
			this.continueLabel.initialize(codeStream);
221
			this.continueLabel.tagBits |= BranchLabel.USED;
256
			this.continueLabel.tagBits |= BranchLabel.USED;

Return to bug 150074