validateLabel(n);
}
private void validateBreakContinue(Node n) {
if (n.isBreak() || n.isContinue()) {
Node labelName = n.getFirstChild();
if (labelName != null) {
Node parent = n.getParent();
while (!parent.isLabel() || !labelsMatch(parent, labelName)) {
if (parent.isFunction() || parent.isScript()) {
// report missing label
errorReporter.error(
String.format(UNDEFINED_LABEL, labelName.getString()),
sourceName,
n.getLineno(), n.getCharno());
break;
}
parent = parent.getParent();
}
if (parent.isLabel() && labelsMatch(parent, labelName)) {
if (n.isContinue() && !isContinueTarget(parent.getLastChild())) {
// report invalid continue target
errorReporter.error(
UNEXPECTED_LABLED_CONTINUE,
sourceName,
n.getLineno(), n.getCharno());
}
}
} else {
if (n.isContinue()) {
Node parent = n.getParent();
while (!isContinueTarget(parent)) {
if (parent.isFunction() || parent.isScript()) {
// report invalid continue
errorReporter.error(
UNEXPECTED_CONTINUE,
sourceName,
n.getLineno(), n.getCharno());
break;
}
parent = parent.getParent();
}
} else {
Node parent = n.getParent();
while (!isBreakTarget(parent)) {
if (parent.isFunction() || parent.isScript()) {
// report invalid break
errorReporter.error(
UNLABELED_BREAK,
sourceName,
n.getLineno(), n.getCharno());
break;
}
parent = parent.getParent();
}
}
}
}
}