Examples of JMultiExpression


Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

       * must be computed twice, we have to replace any left-hand side
       * expressions that could have side effects with temporaries, so that they
       * are only run once.
       */
      ReplaceSideEffectsInLvalue replacer =
          new ReplaceSideEffectsInLvalue(new JMultiExpression(x.getSourceInfo()));
      JExpression newLhs = replacer.accept(x.getLhs());

      JExpression operation =
          new JBinaryOperation(x.getSourceInfo(), newLhs.getType(), op.getNonAssignmentOf(),
              newLhs, x.getRhs());
      operation = modifyResultOperation((JBinaryOperation) operation);

      // newLhs is cloned below because it was used in operation
      JBinaryOperation asg =
          new JBinaryOperation(x.getSourceInfo(), newLhs.getType(), JBinaryOperator.ASG, cloner
              .cloneExpression(newLhs), operation);

      JMultiExpression multiExpr = replacer.getMultiExpr();
      if (multiExpr.isEmpty()) {
        // just use the split assignment expression
        ctx.replaceMe(asg);
      } else {
        // add the assignment as the last item in the multi
        multiExpr.addExpressions(asg);
        ctx.replaceMe(multiExpr);
      }
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

      // Convert into a comma operation, such as:
      // (t = x, x += 1, t)

      // First, replace the arg with a non-side-effect causing one.
      JMultiExpression multi = new JMultiExpression(x.getSourceInfo());
      ReplaceSideEffectsInLvalue replacer = new ReplaceSideEffectsInLvalue(multi);
      JExpression newArg = replacer.accept(x.getArg());

      JExpression expressionReturn = expressionToReturn(newArg);

      // Now generate the appropriate expressions.
      JLocal tempLocal = createTempLocal(x.getSourceInfo(), expressionReturn.getType());

      // t = x
      JLocalRef tempRef = new JLocalRef(x.getSourceInfo(), tempLocal);
      JBinaryOperation asg =
          new JBinaryOperation(x.getSourceInfo(), x.getType(), JBinaryOperator.ASG, tempRef,
              expressionReturn);
      multi.addExpressions(asg);

      // x += 1
      asg = createAsgOpFromUnary(newArg, op);
      // Break the resulting asg op before adding to multi.
      multi.addExpressions(accept(asg));

      // t
      tempRef = new JLocalRef(x.getSourceInfo(), tempLocal);
      multi.addExpressions(tempRef);

      ctx.replaceMe(multi);
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

        assert (JProgram.isClinit(clinit));
        return new JMethodCall(sourceInfo, null, clinit);
      }

      private JMultiExpression createMultiExpressionForInstanceAndClinit(JExpression x) {
        JMultiExpression multi = new JMultiExpression(x.getSourceInfo());

        JMethodCall clinit = null;
        if (x instanceof JMethodCall) {
          JExpression instance = ((JMethodCall) x).getInstance();

          // Any instance expression goes first (this can happen even with statics).
          if (instance != null) {

            multi.addExpressions(instance);
            JLocal var = JProgram.createLocal(instance.getSourceInfo(), "$t", instance.getType(),
                false, body);

            JLocalRef localRef = new JLocalRef(var.getSourceInfo(), var);
            instance = new JBinaryOperation(instance.getSourceInfo(), localRef.getType(),
                JBinaryOperator.ASG, localRef, instance);
          }
          clinit = createClinitCall(x.getSourceInfo(),
              ((JMethodCall) x).getTarget().getEnclosingType());
        } else if (x instanceof JFieldRef) {
          clinit = createClinitCall(x.getSourceInfo(), ((JFieldRef) x).getEnclosingType());
        }
        // If we need a clinit call, add it first
        if (clinit != null) {
          multi.addExpressions(clinit);
        }
        multi.addExpressions(x);
        return multi;
      }

      @Override
      public void endVisit(JMethodCall x, Context ctx) {
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

    }
    String snippet = Joiner.on(";\n").join(expressionSnippets) + ";\n";
    final JProgram program = compileSnippet(returnType, snippet);
    JMethod method = findMethod(program, MAIN_METHOD_NAME);
    JMethodBody body = (JMethodBody) method.getBody();
    JMultiExpression multi = new JMultiExpression(body.getSourceInfo());

    // Transform statement sequence into a JMultiExpression
    for (JStatement stmt : body.getStatements()) {

      if (stmt instanceof JExpressionStatement) {
        JExpressionStatement exprStmt = (JExpressionStatement) stmt;
        JExpression expr = exprStmt.getExpr();
        multi.addExpressions(expr);
      } else if (stmt instanceof JReturnStatement) {
        JReturnStatement returnStatement = (JReturnStatement) stmt;
        JExpression expr = returnStatement.getExpr();
        if (expr != null) {
            multi.addExpressions(expr);
        }
      } else {
        assert false : "Not a valid multiexpression";
      }
    }

    // Take care of the return type
    JStatement multiStm;
    if (!returnType.equals("void")) {
      multiStm = new JReturnStatement(multi.getSourceInfo(), multi);
    } else {
      multiStm = multi.makeStatement();
    }

    // Replace the method body
    JMethodBody newBody = new JMethodBody(method.getBody().getSourceInfo());
    newBody.getBlock().addStmt(multiStm);
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

      JType type, JExpression condExpr, JExpression thenExpr,
      JExpression elseExpr) {
    if (condExpr instanceof JMultiExpression) {
      // (a,b,c)?d:e -> a,b,(c?d:e)
      // TODO(spoon): do this outward multi movement for all AST nodes
      JMultiExpression condMulti = (JMultiExpression) condExpr;
      JMultiExpression newMulti = new JMultiExpression(program, sourceInfo);
      newMulti.exprs.addAll(allButLast(condMulti.exprs));
      newMulti.exprs.add(conditional(null, sourceInfo, type,
          last(condMulti.exprs), thenExpr, elseExpr));
      // TODO(spoon): immediately simplify the resulting multi
      return newMulti;
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

  public JStatement ifStatement(JIfStatement original, SourceInfo sourceInfo,
      JExpression condExpr, JStatement thenStmt, JStatement elseStmt) {
    if (condExpr instanceof JMultiExpression) {
      // if(a,b,c) d else e -> {a; b; if(c) d else e; }
      JMultiExpression condMulti = (JMultiExpression) condExpr;
      JBlock newBlock = new JBlock(program, sourceInfo);
      for (JExpression expr : allButLast(condMulti.exprs)) {
        newBlock.statements.add(expr.makeStatement());
      }
      newBlock.statements.add(ifStatement(null, sourceInfo,
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

  public JExpression not(JPrefixOperation original, SourceInfo sourceInfo,
      JExpression arg) {
    if (arg instanceof JMultiExpression) {
      // !(a,b,c) -> (a,b,!c)
      JMultiExpression argMulti = (JMultiExpression) arg;
      JMultiExpression newMulti = new JMultiExpression(program, sourceInfo);
      newMulti.exprs.addAll(allButLast(argMulti.exprs));
      newMulti.exprs.add(not(null, sourceInfo, last(argMulti.exprs)));
      // TODO(spoon): immediately simplify the newMulti
      return newMulti;
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

          JExpressionStatement stmtExpr = (JExpressionStatement) stmt;
          if (stmtExpr.getExpr() instanceof JMultiExpression) {
            // Promote a multi's expressions to the current block
            x.statements.remove(i);
            int start = i;
            JMultiExpression multi = ((JMultiExpression) stmtExpr.getExpr());
            for (JExpression expr : multi.exprs) {
              x.statements.add(i++, expr.makeStatement());
            }
            i = start - 1;
            continue;
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

       * irrelevant. We can inline the constant, if any, but we might also need
       * to evaluate an instance and run a clinit.
       */
      // We can inline the constant, but we might also need to evaluate an
      // instance and run a clinit.
      JMultiExpression multi = new JMultiExpression(program, x.getSourceInfo());

      JExpression instance = x.getInstance();
      if (instance != null) {
        multi.exprs.add(instance);
      }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.js.JMultiExpression

        }

        ArrayList<JExpression> args = x.getArgs();
        ArrayList<JParameter> originalParams = methodToOriginalParamsMap.get(method);

        JMultiExpression currentMulti = null;
        for (int i = 0, c = args.size(); i < c; ++i) {
          JExpression arg = args.get(i);
          JParameter param = null;
          if (i < originalParams.size()) {
            param = originalParams.get(i);
          }

          if (param != null && referencedNonTypes.contains(param)) {
            // If there is an existing multi, terminate it.
            if (currentMulti != null) {
              currentMulti.exprs.add(arg);
              newCall.getArgs().add(currentMulti);
              currentMulti = null;
            } else {
              newCall.getArgs().add(arg);
            }
          } else if (arg.hasSideEffects()) {
            // The argument is only needed for side effects, add it to a multi.
            if (currentMulti == null) {
              currentMulti = new JMultiExpression(program, x.getSourceInfo());
            }
            currentMulti.exprs.add(arg);
          }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.