Search in sources :

Example 1 with XmlRef

use of org.mozilla.javascript.ast.XmlRef in project HL4A by HL4A.

the class IRFactory method transformXmlMemberGet.

private Node transformXmlMemberGet(XmlMemberGet node) {
    XmlRef ref = node.getMemberRef();
    Node pn = transform(node.getLeft());
    int flags = ref.isAttributeAccess() ? Node.ATTRIBUTE_FLAG : 0;
    if (node.getType() == Token.DOTDOT) {
        flags |= Node.DESCENDANTS_FLAG;
        decompiler.addToken(Token.DOTDOT);
    } else {
        decompiler.addToken(Token.DOT);
    }
    return transformXmlRef(pn, ref, flags);
}
Also used : XmlRef(org.mozilla.javascript.ast.XmlRef) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode)

Example 2 with XmlRef

use of org.mozilla.javascript.ast.XmlRef in project HL4A by HL4A.

the class Parser method propertyAccess.

/**
 * Handles any construct following a "." or ".." operator.
 * @param pn the left-hand side (target) of the operator.  Never null.
 * @return a PropertyGet, XmlMemberGet, or ErrorNode
 */
private AstNode propertyAccess(int tt, AstNode pn) throws IOException {
    if (pn == null)
        codeBug();
    int memberTypeFlags = 0, lineno = ts.lineno, dotPos = ts.tokenBeg;
    consumeToken();
    if (tt == Token.DOTDOT) {
        mustHaveXML();
        memberTypeFlags = Node.DESCENDANTS_FLAG;
    }
    if (!compilerEnv.isXmlAvailable()) {
        int maybeName = nextToken();
        if (maybeName != Token.NAME && !(compilerEnv.isReservedKeywordAsIdentifier() && TokenStream.isKeyword(ts.getString(), compilerEnv.getLanguageVersion(), inUseStrictDirective))) {
            reportError("msg.no.name.after.dot");
        }
        Name name = createNameNode(true, Token.GETPROP);
        PropertyGet pg = new PropertyGet(pn, name, dotPos);
        pg.setLineno(lineno);
        return pg;
    }
    // right side of . or .. operator
    AstNode ref = null;
    int token = nextToken();
    switch(token) {
        case Token.THROW:
            // needed for generator.throw();
            saveNameTokenData(ts.tokenBeg, "throw", ts.lineno);
            ref = propertyName(-1, "throw", memberTypeFlags);
            break;
        case Token.NAME:
            // handles: name, ns::name, ns::*, ns::[expr]
            ref = propertyName(-1, ts.getString(), memberTypeFlags);
            break;
        case Token.MUL:
            // handles: *, *::name, *::*, *::[expr]
            saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
            ref = propertyName(-1, "*", memberTypeFlags);
            break;
        case Token.XMLATTR:
            // handles: '@attr', '@ns::attr', '@ns::*', '@ns::*',
            // '@::attr', '@::*', '@*', '@*::attr', '@*::*'
            ref = attributeAccess();
            break;
        case Token.RESERVED:
            {
                String name = ts.getString();
                saveNameTokenData(ts.tokenBeg, name, ts.lineno);
                ref = propertyName(-1, name, memberTypeFlags);
                break;
            }
        default:
            if (compilerEnv.isReservedKeywordAsIdentifier()) {
                // allow keywords as property names, e.g. ({if: 1})
                String name = Token.keywordToName(token);
                if (name != null) {
                    saveNameTokenData(ts.tokenBeg, name, ts.lineno);
                    ref = propertyName(-1, name, memberTypeFlags);
                    break;
                }
            }
            reportError("msg.no.name.after.dot");
            return makeErrorNode();
    }
    boolean xml = ref instanceof XmlRef;
    InfixExpression result = xml ? new XmlMemberGet() : new PropertyGet();
    if (xml && tt == Token.DOT)
        result.setType(Token.DOT);
    int pos = pn.getPosition();
    result.setPosition(pos);
    result.setLength(getNodeEnd(ref) - pos);
    result.setOperatorPosition(dotPos - pos);
    result.setLineno(pn.getLineno());
    // do this after setting position
    result.setLeft(pn);
    result.setRight(ref);
    return result;
}
Also used : XmlRef(org.mozilla.javascript.ast.XmlRef) PropertyGet(org.mozilla.javascript.ast.PropertyGet) InfixExpression(org.mozilla.javascript.ast.InfixExpression) XmlMemberGet(org.mozilla.javascript.ast.XmlMemberGet) XmlString(org.mozilla.javascript.ast.XmlString) AstNode(org.mozilla.javascript.ast.AstNode) Name(org.mozilla.javascript.ast.Name)

Aggregations

AstNode (org.mozilla.javascript.ast.AstNode)2 XmlRef (org.mozilla.javascript.ast.XmlRef)2 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 InfixExpression (org.mozilla.javascript.ast.InfixExpression)1 LetNode (org.mozilla.javascript.ast.LetNode)1 Name (org.mozilla.javascript.ast.Name)1 PropertyGet (org.mozilla.javascript.ast.PropertyGet)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1 XmlMemberGet (org.mozilla.javascript.ast.XmlMemberGet)1 XmlString (org.mozilla.javascript.ast.XmlString)1