import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
+import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.EmptyStatement;
+import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
+import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
return compilationUnit;
}
- private boolean isVariable() {
- return token == TokenNameVariable; // || token == TokenNamethis;
- }
+// private boolean isVariable() {
+// return token == TokenNameVariable; // || token == TokenNamethis;
+// }
private void statementList() {
+ boolean branchStatement = false;
+ Statement statement;
+ int sourceStart;
+ int sourceEnd;
do {
try {
- statement(TokenNameEOF);
+ sourceStart = scanner.getCurrentTokenStartPosition();
+ statement = statement(TokenNameEOF);
+ if (branchStatement) {
+ sourceEnd = scanner.getCurrentTokenEndPosition();
+ reportSyntaxError("Unreachable code", sourceStart, sourceEnd);
+ }
if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
|| (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
|| (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
|| (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
return;
}
+ branchStatement = false;
+ if (statement instanceof ReturnStatement ||statement instanceof ContinueStatement || statement instanceof BreakStatement) {
+ branchStatement = true;
+ }
} catch (SyntaxError sytaxErr1) {
// if an error occured,
// try to find keywords
Statement statement = null;
Expression expression;
int sourceStart = scanner.getCurrentTokenStartPosition();
+ int sourceEnd;
if (token == TokenNameif) {
getNextToken();
if (token == TokenNameLPAREN) {
}
foreachStatement();
return statement;
- } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
+ } else if (token == TokenNamebreak) {
+ expression = null;
getNextToken();
if (token != TokenNameSEMICOLON) {
- expr();
+ expression = expr();
}
if (token == TokenNameSEMICOLON) {
+ sourceEnd = scanner.getCurrentTokenEndPosition();
getNextToken();
} else {
if (token != TokenNameINLINE_HTML) {
- throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
+ throwSyntaxError("';' expected after 'break'.");
}
+ sourceEnd = scanner.getCurrentTokenEndPosition();
getNextToken();
}
- return statement;
+ return new BreakStatement(null,sourceStart, sourceEnd);
+ } else if (token == TokenNamecontinue) {
+ expression = null;
+ getNextToken();
+ if (token != TokenNameSEMICOLON) {
+ expression = expr();
+ }
+ if (token == TokenNameSEMICOLON) {
+ sourceEnd = scanner.getCurrentTokenEndPosition();
+ getNextToken();
+ } else {
+ if (token != TokenNameINLINE_HTML) {
+ throwSyntaxError("';' expected after 'continue'.");
+ }
+ sourceEnd = scanner.getCurrentTokenEndPosition();
+ getNextToken();
+ }
+ return new ContinueStatement(null,sourceStart, sourceEnd);
+ } else if (token == TokenNamereturn) {
+ expression = null;
+ getNextToken();
+ if (token != TokenNameSEMICOLON) {
+ expression = expr();
+ }
+ if (token == TokenNameSEMICOLON) {
+ sourceEnd = scanner.getCurrentTokenEndPosition();
+ getNextToken();
+ } else {
+ if (token != TokenNameINLINE_HTML) {
+ throwSyntaxError("';' expected after 'return'.");
+ }
+ sourceEnd = scanner.getCurrentTokenEndPosition();
+ getNextToken();
+ }
+ return new ReturnStatement(expression,sourceStart, sourceEnd);
} else if (token == TokenNameecho) {
getNextToken();
expressionList();
getNextToken();
functionDefinition(methodDecl);
} finally {
- int sourceEnd = scanner.getCurrentTokenStartPosition();
+ sourceEnd = scanner.getCurrentTokenStartPosition();
if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
sourceEnd = methodDecl.declarationSourceStart + 1;
}