Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2013 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation Stephan Herrmann - Contributions for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking /
 
 package org.eclipse.jdt.internal.compiler.ast;
 
 
 public class DoStatement extends Statement {
 
 	public Expression condition;
 	public Statement action;
 
 
 	// for local variables table attributes
 	int mergedInitStateIndex = -1;
 
 public DoStatement(Expression conditionStatement actionint sourceStartint sourceEnd) {
 
 	this. = sourceStart;
 	this. = sourceEnd;
 	this. = condition;
 	this. = action;
 	// remember useful empty statement
 	if (action instanceof EmptyStatementaction.bits |= .;
 }
 
 public FlowInfo analyseCode(BlockScope currentScopeFlowContext flowContextFlowInfo flowInfo) {
 	this. = new BranchLabel();
 	this. = new BranchLabel();
 	LoopingFlowContext loopingContext =
 			flowContext,
 			flowInfo,
 			this,
 			this.,
 			currentScope,
 			false);
 
 	Constant cst = this..;
 	boolean isConditionTrue = cst != . && cst.booleanValue() == true;
 	boolean isConditionOptimizedTrue = cst != . && cst.booleanValue() == true;
 	boolean isConditionOptimizedFalse = cst != . && cst.booleanValue() == false;
 
 	int previousMode = flowInfo.reachMode();
 
 	FlowInfo initsOnCondition = flowInfo;
 	// we need to collect the contribution to nulls of the coming paths through the
 	// loop, be they falling through normally or branched to break, continue labels
 	// or catch blocks
 	if ((this. != null) && !this..isEmptyBlock()) {
 		actionInfo = this..
 			analyseCode(currentScopeloopingContextactionInfo).
 
 		// code generation can be optimized when no need to continue in the loop
 		if ((actionInfo.tagBits &
 				loopingContext.initsOnContinue.tagBits &
 			this. = null;
 		}
 		if ((this.. & .) != 0) {
 			initsOnCondition = flowInfo.unconditionalInits().
 										actionInfo.mergedWith(loopingContext.initsOnContinue));
 		}
 	}
 	this..checkNPEbyUnboxing(currentScopeflowContextinitsOnCondition);
 	/* Reset reach mode, to address following scenario.
 	 *   final blank;
 	 *   do { if (true) break; else blank = 0; } while(false);
 	 *   blank = 1; // may be initialized already
 	 */
 	actionInfo.setReachMode(previousMode);
 
 	LoopingFlowContext condLoopContext;
 	FlowInfo condInfo =
 			currentScope,
 			(condLoopContext =
				new LoopingFlowContext(flowContext,	flowInfothisnull,
					nullcurrentScopetrue)),
			(this. == null
actionInfo
				: (actionInfo.mergedWith(loopingContext.initsOnContinue))).copy());
	/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023, we reach the condition at the bottom via two arcs, 
	   one by free fall and another by continuing... Merge initializations propagated through the two pathways,
	   cf, while and for loops.
	*/
	this. = currentScope.methodScope().recordInitializationStates(actionInfo.mergedWith(loopingContext.initsOnContinue));
	if (!isConditionOptimizedFalse && this. != null) {
		loopingContext.complainOnDeferredFinalChecks(currentScopecondInfo);
		condLoopContext.complainOnDeferredFinalChecks(currentScopecondInfo);
		loopingContext.complainOnDeferredNullChecks(currentScope,
		condLoopContext.complainOnDeferredNullChecks(currentScope,
	}
	if (loopingContext.hasEscapingExceptions()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321926
		FlowInfo loopbackFlowInfo = flowInfo.copy();
		loopbackFlowInfo.mergedWith(condInfo.initsWhenTrue().unconditionalCopy());
		loopingContext.simulateThrowAfterLoopBack(loopbackFlowInfo);
	}
	// end of loop
	FlowInfo mergedInfo = 
						(loopingContext.initsOnBreak.tagBits & .) != 0
loopingContext.initsOnBreak
flowInfo.unconditionalCopy().addInitializationsFrom(loopingContext.initsOnBreak),
								// recover upstream null info
						isConditionOptimizedTrue,
						(condInfo.tagBits & .) == 0
flowInfo.copy().addInitializationsFrom(condInfo.initsWhenFalse()) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927
condInfo,
							// recover null inits from before condition analysis
						false// never consider opt false case for DO loop, since break can always occur (47776)
						!isConditionTrue /*do{}while(true); unreachable(); */);
	this. = currentScope.methodScope().recordInitializationStates(mergedInfo);
	return mergedInfo;
Do statement code generation
public void generateCode(BlockScope currentScopeCodeStream codeStream) {
	if ((this. & .) == 0) {
		return;
	}
	int pc = codeStream.position;
	// labels management
	BranchLabel actionLabel = new BranchLabel(codeStream);
	if (this. != nullactionLabel.tagBits |= .;
	actionLabel.place();
	this..initialize(codeStream);
	boolean hasContinueLabel = this. != null;
	if (hasContinueLabel) {
		this..initialize(codeStream);
	}
	// generate action
	if (this. != null) {
		this..generateCode(currentScopecodeStream);
	}
	// continue label (135602)
	if (hasContinueLabel) {
		// May loose some local variable initializations : affecting the local variable attributes
		if (this. != -1) {
		}
		// generate condition
		boolean isConditionOptimizedFalse = cst != . && cst.booleanValue() == false;
		if (isConditionOptimizedFalse){
			this..generateCode(currentScopecodeStreamfalse);
else {
				currentScope,
				codeStream,
				actionLabel,
				null,
				true);
		}
	}
	// May loose some local variable initializations : affecting the local variable attributes
	if (this. != -1) {
	}
	if (this..forwardReferenceCount() > 0) {
	}
	codeStream.recordPositionsFrom(pcthis.);
public StringBuffer printStatement(int indentStringBuffer output) {
	printIndent(indentoutput).append("do"); //$NON-NLS-1$
	if (this. == null)
		output.append(" ;\n"); //$NON-NLS-1$
	else {
		output.append('\n');
		this..printStatement(indent + 1, output).append('\n');
	}
	output.append("while ("); //$NON-NLS-1$
	return this..printExpression(0, output).append(");"); //$NON-NLS-1$
public void resolve(BlockScope scope) {
	this..computeConversion(scopetypetype);
	if (this. != null)
		this..resolve(scope);
public void traverse(ASTVisitor visitorBlockScope scope) {
	if (visitor.visit(thisscope)) {
		if (this. != null) {
			this..traverse(visitorscope);
		}
		this..traverse(visitorscope);
	}
	visitor.endVisit(thisscope);
New to GrepCode? Check out our FAQ X