Java 类org.mozilla.javascript.ast.UnaryExpression 实例源码

项目:HL4A    文件:IRFactory.java   
private Node transformUnary(UnaryExpression node) {
    int type = node.getType();
    if (type == Token.DEFAULTNAMESPACE) {
        return transformDefaultXmlNamepace(node);
    }
    if (node.isPrefix()) {
        decompiler.addToken(type);
    }
    Node child = transform(node.getOperand());
    if (node.isPostfix()) {
        decompiler.addToken(type);
    }
    if (type == Token.INC || type == Token.DEC) {
        return createIncDec(type, node.isPostfix(), child);
    }
    return createUnary(type, child);
}
项目:LoboEvolution    文件:IRFactory.java   
private Node transformUnary(UnaryExpression node) {
    int type = node.getType();
    if (type == Token.DEFAULTNAMESPACE) {
        return transformDefaultXmlNamepace(node);
    }
    if (node.isPrefix()) {
        decompiler.addToken(type);
    }
    Node child = transform(node.getOperand());
    if (node.isPostfix()) {
        decompiler.addToken(type);
    }
    if (type == Token.INC || type == Token.DEC) {
        return createIncDec(type, node.isPostfix(), child);
    }
    return createUnary(type, child);
}
项目:HL4A    文件:IRFactory.java   
private Node transformDefaultXmlNamepace(UnaryExpression node) {
    decompiler.addToken(Token.DEFAULT);
    decompiler.addName(" xml");
    decompiler.addName(" namespace");
    decompiler.addToken(Token.ASSIGN);
    Node child = transform(node.getOperand());
    return createUnary(Token.DEFAULTNAMESPACE, child);
}
项目:HL4A    文件:Parser.java   
private AstNode defaultXmlNamespace()
    throws IOException
{
    if (currentToken != Token.DEFAULT) codeBug();
    consumeToken();
    mustHaveXML();
    setRequiresActivation();
    int lineno = ts.lineno, pos = ts.tokenBeg;

    if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!matchToken(Token.ASSIGN)) {
        reportError("msg.bad.namespace");
    }

    AstNode e = expr();
    UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
    dxmln.setOperator(Token.DEFAULTNAMESPACE);
    dxmln.setOperand(e);
    dxmln.setLineno(lineno);

    ExpressionStatement es = new ExpressionStatement(dxmln, true);
    return es;
}
项目:HL4A    文件:Parser.java   
private void checkBadIncDec(UnaryExpression expr) {
    AstNode op = removeParens(expr.getOperand());
    int tt = op.getType();
    if (!(tt == Token.NAME
          || tt == Token.GETPROP
          || tt == Token.GETELEM
          || tt == Token.GET_REF
          || tt == Token.CALL))
        reportError(expr.getType() == Token.INC
                    ? "msg.bad.incr"
                    : "msg.bad.decr");
}
项目:SJS    文件:TypeErrorMessage.java   
public static TypeErrorMessage unaryOperatorMisuse(UnaryExpression node, Type inType, Type outType) {
    TypeErrorMessage msg = genericTypeError("misuse of unary operator " + AstNode.operatorToString(node.getOperator()) + " in " + shortSrc(node),
            locationOf(node));
    if (!unconstrained(inType)) {
        msg = msg.withNote("input has type " + describeType(inType));
    }
    if (!unconstrained(outType)) {
        msg = msg.withNote("result type is " + describeType(outType));
    }
    return msg;
}
项目:LoboEvolution    文件:IRFactory.java   
private Node transformDefaultXmlNamepace(UnaryExpression node) {
    decompiler.addToken(Token.DEFAULT);
    decompiler.addName(" xml");
    decompiler.addName(" namespace");
    decompiler.addToken(Token.ASSIGN);
    Node child = transform(node.getOperand());
    return createUnary(Token.DEFAULTNAMESPACE, child);
}
项目:LoboEvolution    文件:Parser.java   
private AstNode defaultXmlNamespace()
    throws IOException
{
    if (currentToken != Token.DEFAULT) codeBug();
    consumeToken();
    mustHaveXML();
    setRequiresActivation();
    int lineno = ts.lineno, pos = ts.tokenBeg;

    if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!matchToken(Token.ASSIGN)) {
        reportError("msg.bad.namespace");
    }

    AstNode e = expr();
    UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
    dxmln.setOperator(Token.DEFAULTNAMESPACE);
    dxmln.setOperand(e);
    dxmln.setLineno(lineno);

    ExpressionStatement es = new ExpressionStatement(dxmln, true);
    return es;
}
项目:LoboEvolution    文件:Parser.java   
private void checkBadIncDec(UnaryExpression expr) {
    AstNode op = removeParens(expr.getOperand());
    int tt = op.getType();
    if (!(tt == Token.NAME
          || tt == Token.GETPROP
          || tt == Token.GETELEM
          || tt == Token.GET_REF
          || tt == Token.CALL))
        reportError(expr.getType() == Token.INC
                    ? "msg.bad.incr"
                    : "msg.bad.decr");
}
项目:teavm    文件:AstWriter.java   
private void printUnary(UnaryExpression node, int precedence) throws IOException {
    int innerPrecedence = node.isPostfix() ? PRECEDENCE_POSTFIX : PRECEDENCE_PREFIX;

    if (innerPrecedence > precedence) {
        writer.append('(');
    }

    if (!node.isPostfix()) {
        String op = AstNode.operatorToString(node.getType());
        if (op.startsWith("-")) {
            writer.append(' ');
        }
        writer.append(op);
        if (requiresWhitespaces(node.getType())) {
            writer.append(' ');
        }
    }

    print(node.getOperand(), innerPrecedence);

    if (node.isPostfix()) {
        writer.append(AstNode.operatorToString(node.getType()));
    }

    if (innerPrecedence > precedence) {
        writer.append(')');
    }
}
项目:SJS    文件:ConstraintGenUtil.java   
public static boolean isNullUndefinedLitOrVoidOp(ITypeTerm term) {
    AstNode node = term.getNode();
    return isNullConstant(node)
            || (node instanceof Name && ((Name)node).getIdentifier().equals("undefined"))
            || (node instanceof UnaryExpression && ((UnaryExpression)node).getOperator() == Token.VOID);
}
项目:SJS    文件:ConstraintVisitor.java   
/**
 * This method generates constraints for all relevant AstNodes. It delegates its work to various
 * processXXX() methods that handle AstNodes of type XXX.
 */
@Override
public boolean visit(AstNode node) {
    if (node instanceof VariableInitializer){
        processVariableInitializer(node);
    } else if (node instanceof ReturnStatement){
        processReturnStatement((ReturnStatement)node);
    } else if (node instanceof ExpressionStatement){
        processExpressionStatement((ExpressionStatement)node);
    } else if (node instanceof ForLoop){
        processForLoop((ForLoop)node);
    } else if (node instanceof ForInLoop){
        processForInLoop((ForInLoop)node);
    }else if (node instanceof WhileLoop){
        processWhileLoop((WhileLoop)node);
    } else if (node instanceof DoLoop){
        processDoLoop((DoLoop)node);
    } else if (node instanceof NewExpression){
        processNewExpression((NewExpression)node);
    } else if (node instanceof FunctionCall){
        processFunctionCall((FunctionCall)node);
    } else if (node instanceof ElementGet){
        processElementGet((ElementGet)node);
    } else if (node instanceof FunctionNode){
        processFunctionNode((FunctionNode)node);
    } else if (node instanceof IfStatement){
        processIfStatement((IfStatement)node);
    } else if (node instanceof KeywordLiteral){
        processKeywordLiteral((KeywordLiteral)node);
    } else if (node instanceof SwitchStatement){
        processSwitchStatement((SwitchStatement)node);
    } else if (node instanceof SwitchCase){
        processSwitchCase((SwitchCase)node);
    } else if ((node instanceof AstRoot) || //AstRoot: no constraints need to be generated
        (node instanceof BreakStatement) || //BreakStatement: no constraints need to be generated
        (node instanceof VariableDeclaration) || //VariableDeclaration: we generate constraints for its constituent VariableInitializer nodes
        (node instanceof Name) || //Name: generate constraints for complex expressions that refer to names
        (node instanceof NumberLiteral) || //NumberLiteral: generate constraints for complex expressions that refer to names
        (node instanceof StringLiteral) || //StringLiteral: generate constraints for complex expressions that refer to names
        (node instanceof Assignment) || // Assignment is a special case of InfixExpression
        (node instanceof ArrayLiteral) ||
        (node instanceof UnaryExpression) ||
        (node instanceof InfixExpression) ||
        (node instanceof ConditionalExpression) ||
        (node instanceof ParenthesizedExpression) ||
        (node instanceof EmptyExpression) ||
        (node instanceof ObjectLiteral) ||
        (node instanceof EmptyStatement) ||
        (node instanceof ContinueStatement) ||
        (node instanceof Scope) ||
        (node instanceof Block)){ // // occurs in programs with for loops -- nothing to be done here?
        /* nothing */
    } else {
        error("unsupported node " + node.toSource().trim() + " of type: " + node.getClass().getName(), node);
    }
    return true;
}
项目:SJS    文件:ConstraintVisitor.java   
/**
 * Creates constraints for the subtree rooted at a designated expression node,
 * and returns a constraint variable corresponding to the root of the tree.
 */
private ITypeTerm processExpression(AstNode n){

    ITypeTerm cached = theMap.get(n);
    if (cached != null) return cached;

    if (n instanceof Name){
        return processVariableReference((Name)n);
    } else if (n instanceof NumberLiteral){
        return processNumericConstant((NumberLiteral)n);
    } else if (n instanceof StringLiteral){
        return processStringLiteral((StringLiteral)n);
    } else if (ConstraintGenUtil.isBooleanConstant(n)){
        return processBooleanConstant(n);
    } else if (n instanceof UnaryExpression){
        return processUnaryExpression((UnaryExpression)n);
    } else if (n instanceof InfixExpression){
        return processInfixExpression((InfixExpression)n);
    } else if (n instanceof FunctionCall){
        return processFunctionCallExpression((FunctionCall)n);
    } else if (n instanceof ArrayLiteral){
        return processArrayLiteral((ArrayLiteral)n);
    } else if (n instanceof ElementGet){
        return processElementGet((ElementGet)n);
    } else if (n instanceof ParenthesizedExpression) {
        return processParenthesizedExpression((ParenthesizedExpression)n);
    } else if (n instanceof ConditionalExpression) {
        return processConditionalExpression((ConditionalExpression)n);
    } else if (n instanceof ObjectLiteral) {
        return processObjectLiteral((ObjectLiteral)n);
    } else if (n instanceof KeywordLiteral){
        return processKeywordLiteral((KeywordLiteral)n);
    } else if (n instanceof FunctionNode){
        return processFunctionNode((FunctionNode)n);
    } else if (n instanceof EmptyExpression){
        return processEmptyExpression((EmptyExpression)n);
    } else {
        System.err.println(n.toSource());
        return expError("unimplemented case in findOrCreateExpressionVariable: " + n.getClass().getName(), n);
    }
}