Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java175
1 files changed, 7 insertions, 168 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index bd748e5713..727853be81 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -7299,7 +7299,7 @@ protected void consumeRule(int act) {
consumeStatementBreak() ;
break;
- case 422 : if (DEBUG) { System.out.println("BreakStatement ::= break Expression SEMICOLON"); } //$NON-NLS-1$
+ case 422 : if (DEBUG) { System.out.println("BreakStatement ::= break Identifier SEMICOLON"); } //$NON-NLS-1$
consumeStatementBreakWithLabel() ;
break;
@@ -9099,21 +9099,12 @@ protected void consumeStatementBreakWithLabel() {
// BreakStatement ::= 'break' Identifier ';'
// break pushs a position on this.intStack in case there is no label
- // add the compliance check
- if (this.expressionLengthStack[this.expressionLengthPtr--] != 0) {
- Expression expr = this.expressionStack[this.expressionPtr--];
- char[] labelOrExpr = expr instanceof Literal ?
- ((Literal) expr).source() : expr instanceof SingleNameReference ? ((SingleNameReference) expr).token : null;
- BreakStatement breakStatement = new BreakStatement(
- labelOrExpr,
- this.intStack[this.intPtr--],
- this.endStatementPosition);
- pushOnAstStack(breakStatement);
- breakStatement.expression = expr; // need to figure out later whether this is a label or an expression.
- if (expr instanceof SingleNameReference) {
- ((SingleNameReference) expr).isLabel = true;
- }
- }
+ pushOnAstStack(
+ new BreakStatement(
+ this.identifierStack[this.identifierPtr--],
+ this.intStack[this.intPtr--],
+ this.endStatementPosition));
+ this.identifierLengthPtr--;
}
protected void consumeStatementYield() {
// YieldStatement ::= RestrictedIdentifierYield Expression ';'
@@ -9582,158 +9573,6 @@ protected void consumeDefaultLabelExpr() {
}
defaultStatement.isExpr = true;
}
-/* package */ void collectResultExpressions(SwitchExpression s) {
- if (s.resultExpressions != null)
- return; // already calculated.
-
- class ResultExpressionsCollector extends ASTVisitor {
- Stack<SwitchExpression> targetSwitchExpressions;
- public ResultExpressionsCollector(SwitchExpression se) {
- if (this.targetSwitchExpressions == null)
- this.targetSwitchExpressions = new Stack<>();
- this.targetSwitchExpressions.push(se);
- }
- @Override
- public boolean visit(SwitchExpression switchExpression, BlockScope blockScope) {
- if (switchExpression.resultExpressions == null)
- switchExpression.resultExpressions = new ArrayList<>(0);
- this.targetSwitchExpressions.push(switchExpression);
- return false;
- }
- @Override
- public void endVisit(SwitchExpression switchExpression, BlockScope blockScope) {
- this.targetSwitchExpressions.pop();
- }
- @Override
- public boolean visit(BreakStatement breakStatement, BlockScope blockScope) {
- SwitchExpression targetSwitchExpression = this.targetSwitchExpressions.peek();
- if (breakStatement.expression != null) {
- targetSwitchExpression.resultExpressions.add(breakStatement.expression);
- breakStatement.switchExpression = this.targetSwitchExpressions.peek();
- breakStatement.label = null; // not a label, but an expression
- if (breakStatement.expression instanceof SingleNameReference) {
- ((SingleNameReference) breakStatement.expression).isLabel = false;
- }
- } else {
- // flag an error while resolving
- breakStatement.switchExpression = targetSwitchExpression;
- }
- return true;
- }
- @Override
- public boolean visit(DoStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(ForStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(ForeachStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(SwitchStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(WhileStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(CaseStatement caseStatement, BlockScope blockScope) {
- return true; // do nothing by default, keep traversing
- }
- }
- s.resultExpressions = new ArrayList<>(0); // indicates processed
- int l = s.statements == null ? 0 : s.statements.length;
- for (int i = 0; i < l; ++i) {
- Statement stmt = s.statements[i];
- if (stmt instanceof CaseStatement) {
- CaseStatement caseStatement = (CaseStatement) stmt;
- if (!caseStatement.isExpr) continue;
- stmt = s.statements[++i];
- if (stmt instanceof Expression && ((Expression) stmt).isTrulyExpression()) {
- s.resultExpressions.add((Expression) stmt);
- continue;
- } else if (stmt instanceof ThrowStatement) {
- // TODO: Throw Expression Processing. Anything to be done here for resolve?
- continue;
- }
- }
- // break statement and block statement of SwitchLabelRule or block statement of ':'
- ResultExpressionsCollector reCollector = new ResultExpressionsCollector(s);
- stmt.traverse(reCollector, null);
- }
-}
-/* package */ void flagBreak(SwitchExpression s) {
- if (s.resultExpressions != null)
- return; // already calculated.
-
- class BreakFlagVisitor extends ASTVisitor {
- Stack<SwitchExpression> targetSwitchExpressions;
- public BreakFlagVisitor(SwitchExpression se) {
- if (this.targetSwitchExpressions == null)
- this.targetSwitchExpressions = new Stack<>();
- this.targetSwitchExpressions.push(se);
- }
- @Override
- public boolean visit(SwitchExpression switchExpression, BlockScope blockScope) {
- if (switchExpression.resultExpressions == null)
- switchExpression.resultExpressions = new ArrayList<>(0);
- this.targetSwitchExpressions.push(switchExpression);
- return false;
- }
- @Override
- public void endVisit(SwitchExpression switchExpression, BlockScope blockScope) {
- this.targetSwitchExpressions.pop();
- }
- @Override
- public boolean visit(BreakStatement breakStatement, BlockScope blockScope) {
- // flag an error while resolving
- breakStatement.switchExpression = this.targetSwitchExpressions.peek();
- return true;
- }
- @Override
- public boolean visit(DoStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(ForStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(ForeachStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(SwitchStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(WhileStatement stmt, BlockScope blockScope) {
- return false;
- }
- @Override
- public boolean visit(CaseStatement caseStatement, BlockScope blockScope) {
- return true; // do nothing by default, keep traversing
- }
- }
- int l = s.statements == null ? 0 : s.statements.length;
- for (int i = 0; i < l; ++i) {
- Statement stmt = s.statements[i];
- BreakFlagVisitor reCollector = new BreakFlagVisitor(s);
- stmt.traverse(reCollector, null);
- }
-}
/* package */ void collectResultExpressionsYield(SwitchExpression s) {
if (s.resultExpressions != null)
return; // already calculated.

Back to the top