use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method continueStatement.
private ContinueStatement continueStatement() throws IOException {
if (currentToken != Token.CONTINUE)
codeBug();
consumeToken();
int lineno = ts.lineno, pos = ts.tokenBeg, end = ts.tokenEnd;
Name label = null;
if (peekTokenOrEOL() == Token.NAME) {
label = createNameNode();
end = getNodeEnd(label);
}
// matchJumpLabelName only matches if there is one
LabeledStatement labels = matchJumpLabelName();
Loop target = null;
if (labels == null && label == null) {
if (loopSet == null || loopSet.size() == 0) {
reportError("msg.continue.outside");
} else {
target = loopSet.get(loopSet.size() - 1);
}
} else {
if (labels == null || !(labels.getStatement() instanceof Loop)) {
reportError("msg.continue.nonloop", pos, end - pos);
}
target = labels == null ? null : (Loop) labels.getStatement();
}
ContinueStatement pn = new ContinueStatement(pos, end - pos);
if (// can be null in error-recovery mode
target != null)
pn.setTarget(target);
pn.setLabel(label);
pn.setLineno(lineno);
return pn;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method parseFunctionParams.
private void parseFunctionParams(FunctionNode fnNode) throws IOException {
if (matchToken(Token.RP)) {
fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
return;
}
// Would prefer not to call createDestructuringAssignment until codegen,
// but the symbol definitions have to happen now, before body is parsed.
Map<String, Node> destructuring = null;
Set<String> paramNames = new HashSet<String>();
do {
int tt = peekToken();
if (tt == Token.LB || tt == Token.LC) {
AstNode expr = destructuringPrimaryExpr();
markDestructuring(expr);
fnNode.addParam(expr);
// variables from the destructuring assignment
if (destructuring == null) {
destructuring = new HashMap<String, Node>();
}
String pname = currentScriptOrFn.getNextTempName();
defineSymbol(Token.LP, pname, false);
destructuring.put(pname, expr);
} else {
if (mustMatchToken(Token.NAME, "msg.no.parm")) {
Name paramNameNode = createNameNode();
Comment jsdocNodeForName = getAndResetJsDoc();
if (jsdocNodeForName != null) {
paramNameNode.setJsDocNode(jsdocNodeForName);
}
fnNode.addParam(paramNameNode);
String paramName = ts.getString();
defineSymbol(Token.LP, paramName);
if (this.inUseStrictDirective) {
if ("eval".equals(paramName) || "arguments".equals(paramName)) {
reportError("msg.bad.id.strict", paramName);
}
if (paramNames.contains(paramName))
addError("msg.dup.param.strict", paramName);
paramNames.add(paramName);
}
} else {
fnNode.addParam(makeErrorNode());
}
}
} while (matchToken(Token.COMMA));
if (destructuring != null) {
Node destructuringNode = new Node(Token.COMMA);
// Add assignment helper for each destructuring parameter
for (Map.Entry<String, Node> param : destructuring.entrySet()) {
Node assign = createDestructuringAssignment(Token.VAR, param.getValue(), createName(param.getKey()));
destructuringNode.addChildToBack(assign);
}
fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode);
}
if (mustMatchToken(Token.RP, "msg.no.paren.after.parms")) {
fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
}
}
use of org.mozilla.javascript.ast.Name in project hackpad by dropbox.
the class Node method newString.
public static Node newString(int type, String str) {
Name name = new Name();
name.setIdentifier(str);
name.setType(type);
return name;
}
use of org.mozilla.javascript.ast.Name in project hackpad by dropbox.
the class Node method toString.
private void toString(ObjToIntMap printIds, StringBuffer sb) {
if (Token.printTrees) {
sb.append(Token.name(type));
if (this instanceof Name) {
sb.append(' ');
sb.append(getString());
Scope scope = getScope();
if (scope != null) {
sb.append("[scope: ");
appendPrintId(scope, printIds, sb);
sb.append("]");
}
} else if (this instanceof Scope) {
if (this instanceof ScriptNode) {
ScriptNode sof = (ScriptNode) this;
if (this instanceof FunctionNode) {
FunctionNode fn = (FunctionNode) this;
sb.append(' ');
sb.append(fn.getName());
}
sb.append(" [source name: ");
sb.append(sof.getSourceName());
sb.append("] [encoded source length: ");
sb.append(sof.getEncodedSourceEnd() - sof.getEncodedSourceStart());
sb.append("] [base line: ");
sb.append(sof.getBaseLineno());
sb.append("] [end line: ");
sb.append(sof.getEndLineno());
sb.append(']');
}
if (((Scope) this).getSymbolTable() != null) {
sb.append(" [scope ");
appendPrintId(this, printIds, sb);
sb.append(": ");
Iterator<String> iter = ((Scope) this).getSymbolTable().keySet().iterator();
while (iter.hasNext()) {
sb.append(iter.next());
sb.append(" ");
}
sb.append("]");
}
} else if (this instanceof Jump) {
Jump jump = (Jump) this;
if (type == Token.BREAK || type == Token.CONTINUE) {
sb.append(" [label: ");
appendPrintId(jump.getJumpStatement(), printIds, sb);
sb.append(']');
} else if (type == Token.TRY) {
Node catchNode = jump.target;
Node finallyTarget = jump.getFinally();
if (catchNode != null) {
sb.append(" [catch: ");
appendPrintId(catchNode, printIds, sb);
sb.append(']');
}
if (finallyTarget != null) {
sb.append(" [finally: ");
appendPrintId(finallyTarget, printIds, sb);
sb.append(']');
}
} else if (type == Token.LABEL || type == Token.LOOP || type == Token.SWITCH) {
sb.append(" [break: ");
appendPrintId(jump.target, printIds, sb);
sb.append(']');
if (type == Token.LOOP) {
sb.append(" [continue: ");
appendPrintId(jump.getContinue(), printIds, sb);
sb.append(']');
}
} else {
sb.append(" [target: ");
appendPrintId(jump.target, printIds, sb);
sb.append(']');
}
} else if (type == Token.NUMBER) {
sb.append(' ');
sb.append(getDouble());
} else if (type == Token.TARGET) {
sb.append(' ');
appendPrintId(this, printIds, sb);
}
if (lineno != -1) {
sb.append(' ');
sb.append(lineno);
}
for (PropListItem x = propListHead; x != null; x = x.next) {
int type = x.type;
sb.append(" [");
sb.append(propToString(type));
sb.append(": ");
String value;
switch(type) {
case // can't add this as it recurses
TARGETBLOCK_PROP:
value = "target block property";
break;
case // can't add this as it is dull
LOCAL_BLOCK_PROP:
value = "last local block";
break;
case ISNUMBER_PROP:
switch(x.intValue) {
case BOTH:
value = "both";
break;
case RIGHT:
value = "right";
break;
case LEFT:
value = "left";
break;
default:
throw Kit.codeBug();
}
break;
case SPECIALCALL_PROP:
switch(x.intValue) {
case SPECIALCALL_EVAL:
value = "eval";
break;
case SPECIALCALL_WITH:
value = "with";
break;
default:
// NON_SPECIALCALL should not be stored
throw Kit.codeBug();
}
break;
case OBJECT_IDS_PROP:
{
Object[] a = (Object[]) x.objectValue;
value = "[";
for (int i = 0; i < a.length; i++) {
value += a[i].toString();
if (i + 1 < a.length)
value += ", ";
}
value += "]";
break;
}
default:
Object obj = x.objectValue;
if (obj != null) {
value = obj.toString();
} else {
value = String.valueOf(x.intValue);
}
break;
}
sb.append(value);
sb.append(']');
}
}
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class IRFactory method transformXmlRef.
private Node transformXmlRef(Node pn, XmlRef node, int memberTypeFlags) {
if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0)
decompiler.addToken(Token.XMLATTR);
Name namespace = node.getNamespace();
String ns = namespace != null ? namespace.getIdentifier() : null;
if (ns != null) {
decompiler.addName(ns);
decompiler.addToken(Token.COLONCOLON);
}
if (node instanceof XmlPropRef) {
String name = ((XmlPropRef) node).getPropName().getIdentifier();
decompiler.addName(name);
return createPropertyGet(pn, ns, name, memberTypeFlags);
} else {
decompiler.addToken(Token.LB);
Node expr = transform(((XmlElemRef) node).getExpression());
decompiler.addToken(Token.RB);
return createElementGet(pn, ns, expr, memberTypeFlags);
}
}
Aggregations