Package com.google.gwt.dev.jjs.ast

Examples of com.google.gwt.dev.jjs.ast.JModVisitor


          return false;
        }

        final JExpression oldCondition = node.getCondition();
        final JExpression newCondition = JBooleanLiteral.get(conditionValue);
        JModVisitor visitor = new JModVisitor() {
          @Override
          public boolean visit(JExpression x, Context ctx) {
            if (x == oldCondition) {
              ctx.replaceMe(newCondition);
              return false;
            }
            return true;
          }
        };
        JNode startNode = node.getJNode();
        visitor.accept(startNode);
        Preconditions.checkState(visitor.didChange(),
            "Couldn't replace %s with %s in %s",
            oldCondition, newCondition, startNode);

        return visitor.didChange();
      }
    };
  }
View Full Code Here


  }

  @Override
  public boolean transform(CfgNode<?> node, Cfg cfgGraph) {
    Preconditions.checkArgument(nodeToFold == node);
    JModVisitor visitor = new JModVisitor() {
      @Override
      public boolean visit(JVariableRef x, Context ctx) {
        JNode newNode = transform(x);
        if (newNode != null) {
          ctx.replaceMe(newNode);
          return false;
        }
        return true;
      }
    };

    CfgNode<?> parentNode = nodeToFold.getParent();
    JNode jnode = parentNode.getJNode();
    Preconditions.checkNotNull(jnode);
    visitor.accept(jnode);
    Preconditions.checkState(visitor.didChange());
    return true;
  }
View Full Code Here

    // The actual clinit() calls might be inserted as a result of optimizations: e,g,
    // DeadCodeElimination inserts clinit calls when it removes (some) field accesses or method
    // calls.
    final JMethodBody body = (JMethodBody) method.getBody();

    new JModVisitor() {

      private JMethodCall createClinitCall(SourceInfo sourceInfo, JDeclaredType targetType) {
        JMethod clinit = targetType.getClinitTarget().getClinitMethod();
        assert (JProgram.isClinit(clinit));
        return new JMethodCall(sourceInfo, null, clinit);
View Full Code Here

    @Override
    public CfgTransformer getGraphTransformer() {
      return new CfgTransformer() {
        @Override
        public boolean transform(final CfgNode<?> node, Cfg cfgGraph) {
          JModVisitor visitor = new JModVisitor() {
            @Override
            public void endVisit(JNode x, Context ctx) {
              if (x == node.getJNode()) {
                ctx.replaceMe(createRef(x.getSourceInfo(), original));
              }
            }
          };
          CfgNode<?> parentNode = node.getParent();
          JNode parentJNode = parentNode.getJNode();
          visitor.accept(parentJNode);
          Preconditions.checkState(visitor.didChange());
          return true;
        }
      };
    }
View Full Code Here

  @Override
  public CfgTransformer getGraphTransformer() {
    return new CfgTransformer() {
      @Override
      public boolean transform(CfgNode<?> node, Cfg cfgGraph) {
        JModVisitor visitor = new JModVisitor() {
          @Override
          public void endVisit(JBinaryOperation x, Context ctx) {
            if (!shouldKill(x)) {
              return;
            }

            ctx.replaceMe(x.getRhs());
          }

          @Override
          public void endVisit(JDeclarationStatement x, Context ctx) {
            if (writeToKill.getValue() != x.getInitializer() ||
                x != writeToKill.getJNode()) {
              return;
            }

            if (x.getInitializer().hasSideEffects()) {
              ctx.insertBefore(x.getInitializer().makeStatement());
            }

            x.initializer = null;
            madeChanges();
          }

          @Override
          public boolean visit(JExpressionStatement x, Context ctx) {
            JExpression expr = x.getExpr();
            if (expr instanceof JBinaryOperation) {
              JBinaryOperation binop = (JBinaryOperation) expr;
              if (shouldKill(binop) &&
                  !binop.getRhs().hasSideEffects()) {
                ctx.removeMe();
                return false;
              }
            }
            return true;
          }

          private boolean shouldKill(JBinaryOperation x) {
            return writeToKill.getJNode() == x;
          }
        };

        CfgNode<?> parentNode = CfgUtil.findParentOfContainingStatement(node);
        Preconditions.checkNotNull(parentNode,
            "Can't find parent of stmt of %s", node);
        JNode parentJNode = parentNode.getJNode();
        visitor.accept(parentJNode);
        Preconditions.checkState(visitor.didChange(),
            "Can't remove write in %s", node.getJNode());
        return visitor.didChange();
      }
    };
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JModVisitor

Copyright © 2018 www.massapicom. 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.