use of org.mozilla.javascript.ast.Name in project st-js by st-js.
the class RhinoJavaScriptBuilder method name.
/**
* {@inheritDoc}
*/
@Override
public AstNode name(CharSequence name) {
Name n = new Name();
n.setIdentifier(name.toString());
return n;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class IRFactory method getPropKey.
private Object getPropKey(Node id) {
Object key;
if (id instanceof Name) {
String s = ((Name) id).getIdentifier();
decompiler.addName(s);
key = ScriptRuntime.getIndexObject(s);
} else if (id instanceof StringLiteral) {
String s = ((StringLiteral) id).getValue();
decompiler.addString(s);
key = ScriptRuntime.getIndexObject(s);
} else if (id instanceof NumberLiteral) {
double n = ((NumberLiteral) id).getNumber();
decompiler.addNumber(n);
key = ScriptRuntime.getIndexObject(n);
} else {
throw Kit.codeBug();
}
return key;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method methodDefinition.
private ObjectProperty methodDefinition(int pos, AstNode propName, int entryKind) throws IOException {
FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION);
// We've already parsed the function name, so fn should be anonymous.
Name name = fn.getFunctionName();
if (name != null && name.length() != 0) {
reportError("msg.bad.prop");
}
ObjectProperty pn = new ObjectProperty(pos);
switch(entryKind) {
case GET_ENTRY:
pn.setIsGetterMethod();
fn.setFunctionIsGetterMethod();
break;
case SET_ENTRY:
pn.setIsSetterMethod();
fn.setFunctionIsSetterMethod();
break;
case METHOD_ENTRY:
pn.setIsNormalMethod();
fn.setFunctionIsNormalMethod();
break;
}
int end = getNodeEnd(fn);
pn.setLeft(propName);
pn.setRight(fn);
pn.setLength(end - pos);
return pn;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method breakStatement.
private BreakStatement breakStatement() throws IOException {
if (currentToken != Token.BREAK)
codeBug();
consumeToken();
int lineno = ts.lineno, pos = ts.tokenBeg, end = ts.tokenEnd;
Name breakLabel = null;
if (peekTokenOrEOL() == Token.NAME) {
breakLabel = createNameNode();
end = getNodeEnd(breakLabel);
}
// matchJumpLabelName only matches if there is one
LabeledStatement labels = matchJumpLabelName();
// always use first label as target
Jump breakTarget = labels == null ? null : labels.getFirstLabel();
if (breakTarget == null && breakLabel == null) {
if (loopAndSwitchSet == null || loopAndSwitchSet.size() == 0) {
if (breakLabel == null) {
reportError("msg.bad.break", pos, end - pos);
}
} else {
breakTarget = loopAndSwitchSet.get(loopAndSwitchSet.size() - 1);
}
}
BreakStatement pn = new BreakStatement(pos, end - pos);
pn.setBreakLabel(breakLabel);
// can be null if it's a bad break in error-recovery mode
if (breakTarget != null)
pn.setBreakTarget(breakTarget);
pn.setLineno(lineno);
return pn;
}
use of org.mozilla.javascript.ast.Name in project HL4A by HL4A.
the class Parser method tryStatement.
private TryStatement tryStatement() throws IOException {
if (currentToken != Token.TRY)
codeBug();
consumeToken();
// Pull out JSDoc info and reset it before recursing.
Comment jsdocNode = getAndResetJsDoc();
int tryPos = ts.tokenBeg, lineno = ts.lineno, finallyPos = -1;
if (peekToken() != Token.LC) {
reportError("msg.no.brace.try");
}
AstNode tryBlock = statement();
int tryEnd = getNodeEnd(tryBlock);
List<CatchClause> clauses = null;
boolean sawDefaultCatch = false;
int peek = peekToken();
if (peek == Token.CATCH) {
while (matchToken(Token.CATCH)) {
int catchLineNum = ts.lineno;
if (sawDefaultCatch) {
reportError("msg.catch.unreachable");
}
int catchPos = ts.tokenBeg, lp = -1, rp = -1, guardPos = -1;
if (mustMatchToken(Token.LP, "msg.no.paren.catch"))
lp = ts.tokenBeg;
mustMatchToken(Token.NAME, "msg.bad.catchcond");
Name varName = createNameNode();
Comment jsdocNodeForName = getAndResetJsDoc();
if (jsdocNodeForName != null) {
varName.setJsDocNode(jsdocNodeForName);
}
String varNameString = varName.getIdentifier();
if (inUseStrictDirective) {
if ("eval".equals(varNameString) || "arguments".equals(varNameString)) {
reportError("msg.bad.id.strict", varNameString);
}
}
AstNode catchCond = null;
if (matchToken(Token.IF)) {
guardPos = ts.tokenBeg;
catchCond = expr();
} else {
sawDefaultCatch = true;
}
if (mustMatchToken(Token.RP, "msg.bad.catchcond"))
rp = ts.tokenBeg;
mustMatchToken(Token.LC, "msg.no.brace.catchblock");
Block catchBlock = (Block) statements();
tryEnd = getNodeEnd(catchBlock);
CatchClause catchNode = new CatchClause(catchPos);
catchNode.setVarName(varName);
catchNode.setCatchCondition(catchCond);
catchNode.setBody(catchBlock);
if (guardPos != -1) {
catchNode.setIfPosition(guardPos - catchPos);
}
catchNode.setParens(lp, rp);
catchNode.setLineno(catchLineNum);
if (mustMatchToken(Token.RC, "msg.no.brace.after.body"))
tryEnd = ts.tokenEnd;
catchNode.setLength(tryEnd - catchPos);
if (clauses == null)
clauses = new ArrayList<CatchClause>();
clauses.add(catchNode);
}
} else if (peek != Token.FINALLY) {
mustMatchToken(Token.FINALLY, "msg.try.no.catchfinally");
}
AstNode finallyBlock = null;
if (matchToken(Token.FINALLY)) {
finallyPos = ts.tokenBeg;
finallyBlock = statement();
tryEnd = getNodeEnd(finallyBlock);
}
TryStatement pn = new TryStatement(tryPos, tryEnd - tryPos);
pn.setTryBlock(tryBlock);
pn.setCatchClauses(clauses);
pn.setFinallyBlock(finallyBlock);
if (finallyPos != -1) {
pn.setFinallyPosition(finallyPos - tryPos);
}
pn.setLineno(lineno);
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
return pn;
}
Aggregations