Search in sources :

Example 1 with Label

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;
}
Also used : Label(org.mozilla.javascript.ast.Label)

Example 2 with Label

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;
}
Also used : LabeledStatement(org.mozilla.javascript.ast.LabeledStatement) Label(org.mozilla.javascript.ast.Label)

Example 3 with Label

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;
}
Also used : ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) Label(org.mozilla.javascript.ast.Label)

Example 4 with Label

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;
}
Also used : LabeledStatement(org.mozilla.javascript.ast.LabeledStatement) ExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement) Label(org.mozilla.javascript.ast.Label) AstNode(org.mozilla.javascript.ast.AstNode)

Example 5 with Label

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();
}
Also used : Label(org.mozilla.javascript.ast.Label)

Aggregations

Label (org.mozilla.javascript.ast.Label)7 LabeledStatement (org.mozilla.javascript.ast.LabeledStatement)3 AstNode (org.mozilla.javascript.ast.AstNode)2 XmlString (org.mozilla.javascript.ast.XmlString)2 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)1 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 LetNode (org.mozilla.javascript.ast.LetNode)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1