use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method destructuringObject.
boolean destructuringObject(ObjectLiteral node, int variableType, String tempName, Node parent, List<String> destructuringNames) {
boolean empty = true;
int setOp = variableType == Token.CONST ? Token.SETCONST : Token.SETNAME;
for (ObjectProperty prop : node.getElements()) {
int lineno = 0;
// tokenStream isn't set. Deal with it.
if (ts != null) {
lineno = ts.lineno;
}
AstNode id = prop.getLeft();
Node rightElem = null;
if (id instanceof Name) {
Node s = Node.newString(((Name) id).getIdentifier());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof StringLiteral) {
Node s = Node.newString(((StringLiteral) id).getValue());
rightElem = new Node(Token.GETPROP, createName(tempName), s);
} else if (id instanceof NumberLiteral) {
Node s = createNumber((int) ((NumberLiteral) id).getNumber());
rightElem = new Node(Token.GETELEM, createName(tempName), s);
} else {
throw codeBug();
}
rightElem.setLineno(lineno);
AstNode value = prop.getRight();
if (value.getType() == Token.NAME) {
String name = ((Name) value).getIdentifier();
parent.addChildToBack(new Node(setOp, createName(Token.BINDNAME, name, null), rightElem));
if (variableType != -1) {
defineSymbol(variableType, name, true);
destructuringNames.add(name);
}
} else {
parent.addChildToBack(destructuringAssignmentHelper(variableType, value, rightElem, currentScriptOrFn.getNextTempName()));
}
empty = false;
}
return empty;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Node method toString.
private void toString(ObjToIntMap printIds, StringBuilder 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 Node method newString.
public static Node newString(int type, String str) {
Name name = new Name();
name.setIdentifier(str);
name.setType(type);
return name;
}
Aggregations