use of org.mozilla.javascript.ast.Scope in project HL4A by HL4A.
the class IRFactory method transformForLoop.
private Node transformForLoop(ForLoop loop) {
decompiler.addToken(Token.FOR);
decompiler.addToken(Token.LP);
loop.setType(Token.LOOP);
// XXX: Can't use pushScope/popScope here since 'createFor' may split
// the scope
Scope savedScope = currentScope;
currentScope = loop;
try {
Node init = transform(loop.getInitializer());
decompiler.addToken(Token.SEMI);
Node test = transform(loop.getCondition());
decompiler.addToken(Token.SEMI);
Node incr = transform(loop.getIncrement());
decompiler.addToken(Token.RP);
decompiler.addEOL(Token.LC);
Node body = transform(loop.getBody());
decompiler.addEOL(Token.RC);
return createFor(loop, init, test, incr, body);
} finally {
currentScope = savedScope;
}
}
use of org.mozilla.javascript.ast.Scope in project HL4A by HL4A.
the class Parser method destructuringAssignmentHelper.
Node destructuringAssignmentHelper(int variableType, Node left, Node right, String tempName) {
Scope result = createScopeNode(Token.LETEXPR, left.getLineno());
result.addChildToFront(new Node(Token.LET, createName(Token.NAME, tempName, right)));
try {
pushScope(result);
defineSymbol(Token.LET, tempName, true);
} finally {
popScope();
}
Node comma = new Node(Token.COMMA);
result.addChildToBack(comma);
List<String> destructuringNames = new ArrayList<String>();
boolean empty = true;
switch(left.getType()) {
case Token.ARRAYLIT:
empty = destructuringArray((ArrayLiteral) left, variableType, tempName, comma, destructuringNames);
break;
case Token.OBJECTLIT:
empty = destructuringObject((ObjectLiteral) left, variableType, tempName, comma, destructuringNames);
break;
case Token.GETPROP:
case Token.GETELEM:
switch(variableType) {
case Token.CONST:
case Token.LET:
case Token.VAR:
reportError("msg.bad.assign.left");
}
comma.addChildToBack(simpleAssignment(left, createName(tempName)));
break;
default:
reportError("msg.bad.assign.left");
}
if (empty) {
// Don't want a COMMA node with no children. Just add a zero.
comma.addChildToBack(createNumber(0));
}
result.putProp(Node.DESTRUCTURING_NAMES, destructuringNames);
return result;
}
use of org.mozilla.javascript.ast.Scope in project HL4A by HL4A.
the class Parser method defineSymbol.
void defineSymbol(int declType, String name, boolean ignoreNotInBlock) {
if (name == null) {
if (compilerEnv.isIdeMode()) {
// be robust in IDE-mode
return;
} else {
codeBug();
}
}
Scope definingScope = currentScope.getDefiningScope(name);
Symbol symbol = definingScope != null ? definingScope.getSymbol(name) : null;
int symDeclType = symbol != null ? symbol.getDeclType() : -1;
if (symbol != null && (symDeclType == Token.CONST || declType == Token.CONST || (definingScope == currentScope && symDeclType == Token.LET))) {
addError(symDeclType == Token.CONST ? "msg.const.redecl" : symDeclType == Token.LET ? "msg.let.redecl" : symDeclType == Token.VAR ? "msg.var.redecl" : symDeclType == Token.FUNCTION ? "msg.fn.redecl" : "msg.parm.redecl", name);
return;
}
switch(declType) {
case Token.LET:
if (!ignoreNotInBlock && ((currentScope.getType() == Token.IF) || currentScope instanceof Loop)) {
addError("msg.let.decl.not.in.block");
return;
}
currentScope.putSymbol(new Symbol(declType, name));
return;
case Token.VAR:
case Token.CONST:
case Token.FUNCTION:
if (symbol != null) {
if (symDeclType == Token.VAR)
addStrictWarning("msg.var.redecl", name);
else if (symDeclType == Token.LP) {
addStrictWarning("msg.var.hides.arg", name);
}
} else {
currentScriptOrFn.putSymbol(new Symbol(declType, name));
}
return;
case Token.LP:
if (symbol != null) {
// must be duplicate parameter. Second parameter hides the
// first, so go ahead and add the second parameter
addWarning("msg.dup.parms", name);
}
currentScriptOrFn.putSymbol(new Symbol(declType, name));
return;
default:
throw codeBug();
}
}
use of org.mozilla.javascript.ast.Scope in project HL4A by HL4A.
the class Parser method pushScope.
void pushScope(Scope scope) {
Scope parent = scope.getParentScope();
// in which case we just need to set currentScope variable.
if (parent != null) {
if (parent != currentScope)
codeBug();
} else {
currentScope.addChildScope(scope);
}
currentScope = scope;
}
use of org.mozilla.javascript.ast.Scope in project HL4A by HL4A.
the class Parser method createScopeNode.
/**
* Create a node that can be used to hold lexically scoped variable
* definitions (via let declarations).
*
* @param token the token of the node to create
* @param lineno line number of source
* @return the created node
*/
protected Scope createScopeNode(int token, int lineno) {
Scope scope = new Scope();
scope.setType(token);
scope.setLineno(lineno);
return scope;
}
Aggregations