private void recordLabel(Label label, LabeledStatement bundle) throws IOException { // current token should be colon that primaryExpr left untouched if (peekToken() != Token.COLON) codeBug(); consumeToken(); String name = label.getName(); if (labelSet == null) { labelSet = new HashMap<String,LabeledStatement>(); } else { LabeledStatement ls = labelSet.get(name); if (ls != null) { if (compilerEnv.isIdeMode()) { Label dup = ls.getLabelByName(name); reportError("msg.dup.label", dup.getAbsolutePosition(), dup.getLength()); } reportError("msg.dup.label", label.getPosition(), label.getLength()); } } bundle.addLabel(label); labelSet.put(name, bundle); }
private AstNode name(int ttFlagged, int tt) throws IOException { String nameString = ts.getString(); int namePos = ts.tokenBeg, nameLineno = ts.lineno; if (0 != (ttFlagged & TI_CHECK_LABEL) && peekToken() == Token.COLON) { // Do not consume colon. It is used as an unwind indicator // to return to statementHelper. Label label = new Label(namePos, ts.tokenEnd - namePos); label.setName(nameString); label.setLineno(ts.lineno); return label; } // Not a label. Unfortunately peeking the next token to check for // a colon has biffed ts.tokenBeg, ts.tokenEnd. We store the name's // bounds in instance vars and createNameNode uses them. saveNameTokenData(namePos, nameString, nameLineno); if (compilerEnv.isXmlAvailable()) { return propertyName(-1, nameString, 0); } else { return createNameNode(true, Token.NAME); } }
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; }
private void print(LabeledStatement node) throws IOException { for (Label label : node.getLabels()) { writer.append(label.getName()).append(':').ws(); } print(node.getStatement()); }