Search in sources :

Example 1 with Name

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;
}
Also used : Name(org.mozilla.javascript.ast.Name)

Example 2 with Name

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;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral) XmlString(org.mozilla.javascript.ast.XmlString) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral) Name(org.mozilla.javascript.ast.Name)

Example 3 with Name

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;
}
Also used : ObjectProperty(org.mozilla.javascript.ast.ObjectProperty) FunctionNode(org.mozilla.javascript.ast.FunctionNode) Name(org.mozilla.javascript.ast.Name)

Example 4 with Name

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;
}
Also used : BreakStatement(org.mozilla.javascript.ast.BreakStatement) LabeledStatement(org.mozilla.javascript.ast.LabeledStatement) Jump(org.mozilla.javascript.ast.Jump) Name(org.mozilla.javascript.ast.Name)

Example 5 with Name

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;
}
Also used : Comment(org.mozilla.javascript.ast.Comment) TryStatement(org.mozilla.javascript.ast.TryStatement) ArrayList(java.util.ArrayList) Block(org.mozilla.javascript.ast.Block) CatchClause(org.mozilla.javascript.ast.CatchClause) XmlString(org.mozilla.javascript.ast.XmlString) AstNode(org.mozilla.javascript.ast.AstNode) Name(org.mozilla.javascript.ast.Name)

Aggregations

Name (org.mozilla.javascript.ast.Name)23 AstNode (org.mozilla.javascript.ast.AstNode)11 XmlString (org.mozilla.javascript.ast.XmlString)11 FunctionNode (org.mozilla.javascript.ast.FunctionNode)10 ScriptNode (org.mozilla.javascript.ast.ScriptNode)7 LetNode (org.mozilla.javascript.ast.LetNode)5 Comment (org.mozilla.javascript.ast.Comment)3 ErrorNode (org.mozilla.javascript.ast.ErrorNode)3 Jump (org.mozilla.javascript.ast.Jump)3 ObjectProperty (org.mozilla.javascript.ast.ObjectProperty)3 Iterator (java.util.Iterator)2 InfixExpression (org.mozilla.javascript.ast.InfixExpression)2 LabeledStatement (org.mozilla.javascript.ast.LabeledStatement)2 NumberLiteral (org.mozilla.javascript.ast.NumberLiteral)2 PropertyGet (org.mozilla.javascript.ast.PropertyGet)2 Scope (org.mozilla.javascript.ast.Scope)2 StringLiteral (org.mozilla.javascript.ast.StringLiteral)2 XmlPropRef (org.mozilla.javascript.ast.XmlPropRef)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1