use of org.mozilla.javascript.ast.Label in project st-js by st-js.
the class RhinoJavaScriptBuilder method label.
/**
* {@inheritDoc}
*/
@Override
public AstNode label(CharSequence name) {
Label n = new Label();
n.setName(name.toString());
return n;
}
use of org.mozilla.javascript.ast.Label in project st-js by st-js.
the class RhinoJavaScriptBuilder method labeledStatement.
/**
* {@inheritDoc}
*/
@Override
public AstNode labeledStatement(AstNode label, AstNode statement) {
LabeledStatement s = new LabeledStatement();
s.addLabel(cast(label, Label.class));
s.setStatement(statement);
return s;
}
use of org.mozilla.javascript.ast.Label in project HL4A by HL4A.
the class IRFactory method transformLabeledStatement.
private Node transformLabeledStatement(LabeledStatement ls) {
Label label = ls.getFirstLabel();
List<Label> labels = ls.getLabels();
decompiler.addName(label.getName());
if (labels.size() > 1) {
// more than one label
for (Label lb : labels.subList(1, labels.size())) {
decompiler.addEOL(Token.COLON);
decompiler.addName(lb.getName());
}
}
if (ls.getStatement().getType() == Token.BLOCK) {
// reuse OBJECTLIT for ':' workaround, cf. transformObjectLiteral()
decompiler.addToken(Token.OBJECTLIT);
decompiler.addEOL(Token.LC);
} else {
decompiler.addEOL(Token.COLON);
}
Node statement = transform(ls.getStatement());
if (ls.getStatement().getType() == Token.BLOCK) {
decompiler.addEOL(Token.RC);
}
// Make a target and put it _after_ the statement node. Add in the
// LABEL node, so breaks get the right target.
Node breakTarget = Node.newTarget();
Node block = new Node(Token.BLOCK, label, statement, breakTarget);
label.target = breakTarget;
return block;
}
use of org.mozilla.javascript.ast.Label in project HL4A by HL4A.
the class Parser method nameOrLabel.
/**
* Found a name in a statement context. If it's a label, we gather
* up any following labels and the next non-label statement into a
* {@link LabeledStatement} "bundle" and return that. Otherwise we parse
* an expression and return it wrapped in an {@link ExpressionStatement}.
*/
private AstNode nameOrLabel() throws IOException {
if (currentToken != Token.NAME)
throw codeBug();
int pos = ts.tokenBeg;
// set check for label and call down to primaryExpr
currentFlaggedToken |= TI_CHECK_LABEL;
AstNode expr = expr();
if (expr.getType() != Token.LABEL) {
AstNode n = new ExpressionStatement(expr, !insideFunction());
n.lineno = expr.lineno;
return n;
}
LabeledStatement bundle = new LabeledStatement(pos);
recordLabel((Label) expr, bundle);
bundle.setLineno(ts.lineno);
// look for more labels
AstNode stmt = null;
while (peekToken() == Token.NAME) {
currentFlaggedToken |= TI_CHECK_LABEL;
expr = expr();
if (expr.getType() != Token.LABEL) {
stmt = new ExpressionStatement(expr, !insideFunction());
autoInsertSemicolon(stmt);
break;
}
recordLabel((Label) expr, bundle);
}
// no more labels; now parse the labeled statement
try {
currentLabel = bundle;
if (stmt == null) {
stmt = statementHelper();
}
} finally {
currentLabel = null;
// remove the labels for this statement from the global set
for (Label lb : bundle.getLabels()) {
labelSet.remove(lb.getName());
}
}
// If stmt has parent assigned its position already is relative
// (See bug #710225)
bundle.setLength(stmt.getParent() == null ? getNodeEnd(stmt) - pos : getNodeEnd(stmt));
bundle.setStatement(stmt);
return bundle;
}
use of org.mozilla.javascript.ast.Label in project st-js by st-js.
the class RhinoJavaScriptWriter method visitLabeledStatement.
/**
* {@inheritDoc}
*/
@Override
public void visitLabeledStatement(LabeledStatement labelStatement, Boolean param) {
for (Label label : labelStatement.getLabels()) {
// prints newline
visitorSupport.accept(label, this, param);
}
indent();
visitorSupport.accept(labelStatement.getStatement(), this, param);
unindent();
}
Aggregations