Search in sources :

Example 1 with XmlPropRef

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

the class IRFactory method transformXmlRef.

private Node transformXmlRef(Node pn, XmlRef node, int memberTypeFlags) {
    if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0)
        decompiler.addToken(Token.XMLATTR);
    Name namespace = node.getNamespace();
    String ns = namespace != null ? namespace.getIdentifier() : null;
    if (ns != null) {
        decompiler.addName(ns);
        decompiler.addToken(Token.COLONCOLON);
    }
    if (node instanceof XmlPropRef) {
        String name = ((XmlPropRef) node).getPropName().getIdentifier();
        decompiler.addName(name);
        return createPropertyGet(pn, ns, name, memberTypeFlags);
    } else {
        decompiler.addToken(Token.LB);
        Node expr = transform(((XmlElemRef) node).getExpression());
        decompiler.addToken(Token.RB);
        return createElementGet(pn, ns, expr, memberTypeFlags);
    }
}
Also used : XmlPropRef(org.mozilla.javascript.ast.XmlPropRef) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) XmlString(org.mozilla.javascript.ast.XmlString) Name(org.mozilla.javascript.ast.Name)

Example 2 with XmlPropRef

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

the class Parser method propertyName.

/**
 * Check if :: follows name in which case it becomes a qualified name.
 *
 * @param atPos a natural number if we just read an '@' token, else -1
 *
 * @param s the name or string that was matched (an identifier, "throw" or
 * "*").
 *
 * @param memberTypeFlags flags tracking whether we're a '.' or '..' child
 *
 * @return an XmlRef node if it's an attribute access, a child of a
 * '..' operator, or the name is followed by ::.  For a plain name,
 * returns a Name node.  Returns an ErrorNode for malformed XML
 * expressions.  (For now - might change to return a partial XmlRef.)
 */
private AstNode propertyName(int atPos, String s, int memberTypeFlags) throws IOException {
    int pos = atPos != -1 ? atPos : ts.tokenBeg, lineno = ts.lineno;
    int colonPos = -1;
    Name name = createNameNode(true, currentToken);
    Name ns = null;
    if (matchToken(Token.COLONCOLON)) {
        ns = name;
        colonPos = ts.tokenBeg;
        switch(nextToken()) {
            // handles name::name
            case Token.NAME:
                name = createNameNode();
                break;
            // handles name::*
            case Token.MUL:
                saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
                name = createNameNode(false, -1);
                break;
            // handles name::[expr] or *::[expr]
            case Token.LB:
                return xmlElemRef(atPos, ns, colonPos);
            default:
                reportError("msg.no.name.after.coloncolon");
                return makeErrorNode();
        }
    }
    if (ns == null && memberTypeFlags == 0 && atPos == -1) {
        return name;
    }
    XmlPropRef ref = new XmlPropRef(pos, getNodeEnd(name) - pos);
    ref.setAtPos(atPos);
    ref.setNamespace(ns);
    ref.setColonPos(colonPos);
    ref.setPropName(name);
    ref.setLineno(lineno);
    return ref;
}
Also used : XmlPropRef(org.mozilla.javascript.ast.XmlPropRef) Name(org.mozilla.javascript.ast.Name)

Aggregations

Name (org.mozilla.javascript.ast.Name)2 XmlPropRef (org.mozilla.javascript.ast.XmlPropRef)2 AstNode (org.mozilla.javascript.ast.AstNode)1 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 LetNode (org.mozilla.javascript.ast.LetNode)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1 XmlString (org.mozilla.javascript.ast.XmlString)1