From 8b9bed3a05361a0fd886dd821aab54f86eb0a573 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 18 Apr 2005 19:13:02 +0000 Subject: [PATCH] Improved error "Unreachable code" for if statements --- .../phpdt/internal/compiler/parser/Parser.java | 26 +++++++++---------- 1 files changed, 12 insertions(+), 14 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 4777170..01897dd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -464,18 +464,14 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI private Block statementList() { boolean branchStatement = false; Statement statement; - int sourceStart; - int sourceEnd; int blockStart = scanner.getCurrentTokenStartPosition(); ArrayList blockStatements = new ArrayList(); do { try { - sourceStart = scanner.getCurrentTokenStartPosition(); statement = statement(); blockStatements.add(statement); - if (branchStatement) { - sourceEnd = scanner.getCurrentTokenEndPosition(); - reportSyntaxError("Unreachable code", sourceStart, sourceEnd); + if (branchStatement && statement!=null) { + reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd); } if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse) || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor) @@ -484,7 +480,6 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI return createBlock(blockStart, blockStatements); } branchStatement = checkUnreachableStatements(statement); -// return createBlock(blockStart, blockStatements); } catch (SyntaxError sytaxErr1) { // if an error occured, // try to find keywords @@ -528,13 +523,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI * @return */ private boolean checkUnreachableStatements(Statement statement) { - boolean branchStatement = false; if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) { - branchStatement = true; + return true; } else if (statement instanceof IfStatement && ((IfStatement)statement).checkUnreachable) { - branchStatement = true; + return true; } - return branchStatement; + return false; } /** @@ -1949,12 +1943,16 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI int off = b.statements.length - 1; if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement) && !(b.statements[off] instanceof BreakStatement)) { - iState.checkUnreachable = false; - } + if (!(b.statements[off] instanceof IfStatement) || !((IfStatement)b.statements[off]).checkUnreachable) { + iState.checkUnreachable = false; + } + } } } else { if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) { - iState.checkUnreachable = false; + if (!(s instanceof IfStatement) || !((IfStatement)s).checkUnreachable) { + iState.checkUnreachable = false; + } } } } -- 1.7.1