Skip to content

Commit 0027823

Browse files
author
Troy Melhase
committed
Updates AST break and continue visitors to warn about labeled constructs.
1 parent 431b568 commit 0027823

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

doc/features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ Java `return` statements are translated to equivalent Python `return` statements
136136
Java `throw` statements are translated to equivalent Python `throw` statements.
137137

138138
##### break
139-
Java `break` statements are translated to equivalent Python `break` statements. However, a Java `break` statement with an identifier (e.g., `break FOO`) is not supported. If the compiler detects such a statement, a waring will be printed and the translated source will not
139+
Java `break` statements are translated to equivalent Python `break` statements. However, a Java `break` statement with an identifier (e.g., `break FOO`) is not supported. If the compiler detects such a statement, a warning will be printed and the translated source will not
140140
contain the original label.
141141

142142
###### continue
143-
Java `continue` statements are translated to equivalent Python `continue` statements. However, a Java `continue` statement with an identifier (e.g., `continue FOO`) is not supported. If the compiler detects such a statement, a waring will be printed and the translated source will not
143+
Java `continue` statements are translated to equivalent Python `continue` statements. However, a Java `continue` statement with an identifier (e.g., `continue FOO`) is not supported. If the compiler detects such a statement, a warning will be printed and the translated source will not
144144
contain the original label.
145145

146146

java2python/compiler/visitor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from functools import reduce, partial
1616
from itertools import ifilter, ifilterfalse, izip, tee
17-
from logging import debug
17+
from logging import debug, warn
1818
from re import compile as recompile, sub as resub
1919

2020
from java2python.lang import tokens
@@ -370,6 +370,8 @@ def acceptBreak(self, node, memo):
370370
if parent.type in ok_types:
371371
break
372372
if insert:
373+
if len(node.children):
374+
warn('Detected unhandled break statement with label; generated code incorrect.')
373375
breakStat = self.factory.statement('break', parent=self)
374376

375377
def acceptCatch(self, node, memo):
@@ -390,6 +392,8 @@ def acceptCatch(self, node, memo):
390392
def acceptContinue(self, node, memo):
391393
""" Accept and process a continue statement. """
392394
contStat = self.factory.statement('continue', fs=FS.lsr, parent=self)
395+
if len(node.children):
396+
warn('Detected unhandled continue statement with label; generated code incorrect.')
393397

394398
def acceptDo(self, node, memo):
395399
""" Accept and process a do-while block. """

0 commit comments

Comments
 (0)