Examples of TryStatement


Examples of anvil.script.statements.TryStatement

      Statement stmt = flowPeek();
      switch(stmt.typeOf()) {
      case Statement.ST_BLOCK:
      case Statement.ST_IMPLICIT_BLOCK:
        {
          TryStatement trystmt;
          BlockStatement block = (BlockStatement)stmt;
          stmt = block.getTail();
          if (stmt != null && stmt.typeOf() == Statement.ST_TRY) {
            trystmt = (TryStatement)stmt;
            if (trystmt.hasFinally()) {
              trystmt = block.replaceWithTry();
            }
          } else {
            trystmt = block.replaceWithTry();
          }
          return trystmt;
        }

      default:
        {
          TryStatement trystmt = new TryStatement(stmt, stmt.getLocation());
          stmt.setChildStatement(trystmt);
          return trystmt;
        }
      }
    }
View Full Code Here

Examples of anvil.script.statements.TryStatement

  }

  final public void TryStatement() throws ParseException {
  Token t;
    t = jj_consume_token(TRY);
      TryStatement trystmt = new TryStatement(flowPeek(), toLocation(t));
      flowPushChild(trystmt);
    Statement();
    label_18:
    while (true) {
      if (jj_2_8(2147483647)) {
View Full Code Here

Examples of com.bacoder.parser.java.api.TryStatement

    return throwStatement;
  }

  protected TryStatement processTryStatement(StatementContext context) {
    TryStatement tryStatement = createNode(context, TryStatement.class);

    ResourceSpecificationContext resourceSpecificationContext =
        getChild(context, ResourceSpecificationContext.class);
    if (resourceSpecificationContext != null) {
      ResourcesContext resourcesContext =
          getChild(resourceSpecificationContext, ResourcesContext.class);
      if (resourcesContext != null) {
        tryStatement.setResources(transform(resourcesContext, ResourceContext.class,
            new Function<ResourceContext, Resource>() {
              @Override
              public Resource apply(ResourceContext context) {
                Resource resource = createNode(context, Resource.class);

                setModifiers(context, resource);

                ClassOrInterfaceTypeContext classOrInterfaceTypeContext =
                    getChild(context, ClassOrInterfaceTypeContext.class);
                if (classOrInterfaceTypeContext != null) {
                  resource.setType(
                      getAdapter(ClassOrInterfaceTypeAdapter.class).adapt(
                          classOrInterfaceTypeContext));
                }

                VariableDeclaratorIdContext variableDeclaratorIdContext =
                    getChild(context, VariableDeclaratorIdContext.class);
                if (variableDeclaratorIdContext != null) {
                  TerminalNode identifierNode =
                      getTerminalNode(variableDeclaratorIdContext, JavaParser.Identifier);
                  if (identifierNode != null) {
                    resource.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
                  }

                  resource.setDimensions(
                      getAdapter(ArrayDimensionsAdapter.class).adapt(variableDeclaratorIdContext));
                }

                ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
                if (expressionContext != null) {
                  resource.setInitializer(
                      getAdapter(ExpressionAdapter.class).adapt(expressionContext));
                }

                return resource;
              }
            }));
      }
    }

    BlockContext blockContext = getChild(context, BlockContext.class);
    if (blockContext != null) {
      tryStatement.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
    }

    tryStatement.setCatchClauses(transform(context, CatchClauseContext.class,
        new Function<CatchClauseContext, CatchClause>() {
          @Override
          public CatchClause apply(CatchClauseContext context) {
            CatchClause catchClause = createNode(context, CatchClause.class);

            setModifiers(context, catchClause);

            CatchTypeContext catchTypeContext = getChild(context, CatchTypeContext.class);
            if (catchTypeContext != null) {
              catchClause.setExceptions(transform(catchTypeContext, QualifiedNameContext.class,
                  new Function<QualifiedNameContext, QualifiedName>() {
                    @Override
                    public QualifiedName apply(QualifiedNameContext context) {
                      return getAdapter(QualifiedNameAdapter.class).adapt(context);
                    }
                  }));
            }

            TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
            if (identifierNode != null) {
              catchClause.setVariable(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
            }

            BlockContext blockContext = getChild(context, BlockContext.class);
            if (blockContext != null) {
              catchClause.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
            }

            return catchClause;
          }
        }));

    FinallyBlockContext finallyBlockContext = getChild(context, FinallyBlockContext.class);
    if (finallyBlockContext != null) {
      BlockContext finallyBodyContext = getChild(finallyBlockContext, BlockContext.class);
      if (finallyBodyContext != null) {
        tryStatement.setFinallyBlock(getAdapter(BlockAdapter.class).adapt(finallyBodyContext));
      }
    }

    return tryStatement;
  }
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  private TryStatement selectTryStatement(Node node)
  {
    int pc= node.getInitialPc();
    for (int i= 0; i < tryStatements.size(); i++)
    {
      TryStatement tryStmt= (TryStatement) tryStatements.get(i);
      Block block= tryStmt.getTryBlock();
      if (pc >= block.getBeginIndex() && pc <= block.getEndIndex())
        return tryStmt;
    }
    return null;
  }
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  private void processTrys()
  {
    for (int i= 0; i < tryStatements.size(); i++)
    {
      TryStatement stmt= (TryStatement) tryStatements.get(i);
      TryHeaderNode header= stmt.header;
      Node tryNode= header.getTryBody();

      if (tryNode == sourceNode)
      {
        //    if (tryNode.getInEdges().size() > 1)
        //    {
        //        problemCounter++;
        //        throw new WhileTryProblemException();
        //    }
        //    else
        sourceNode= header;
      }

      for (Edge edge : new ArrayList<Edge>(tryNode.getInEdges()))
      {
        int pc= edge.source.getInitialPc();
        if (pc >= stmt.getBeginIndex() && pc <= stmt.getEndIndex())
          continue;
        if (edge.source == header)
          continue;
        edge.redirect(header);
      }
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  private void processTrys2()
  {
    for (Node node : nodesByPc.values())
    {
      TryStatement sourceTry= selectTryStatement(node);
      if (sourceTry == null)
        continue;

      for (Edge edge : node.getOutEdges())
      {
        if (edge.target.getInEdges().size() != 1)
        {
          continue;
        }
        TryStatement targetTry= selectTryStatement(edge.target);
        if (targetTry == null || targetTry != sourceTry)
        {
          edge.reroot(sourceTry.header);
        }
      }
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  private void processTrys1()
  {
    for (int i= 0; i < tryStatements.size(); i++)
    {
      TryStatement stmt= (TryStatement) tryStatements.get(i);
      TryHeaderNode header= stmt.header;
      Node finallyNode= header.getFinallyNode();
      if (finallyNode == null)
        continue;
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  void rollOut_(Block block)
  {
    TryHeaderNode head= (TryHeaderNode) header;

    TryStatement stmt= head.getTryStatement();
    block.appendChild(stmt);

    graph.rollOut(tryBodyNode, stmt.getTryBlock());

    if (finallyNode != null)
    {
      stmt.setFinallyBlock(new Block());
      graph.rollOut(finallyNode, stmt.getFinallyBlock());
    }

    CatchClause cc= (CatchClause) stmt.getCatchStatements().getFirstChild();
    Iterator iter= catchNodes.iterator();
    while (iter.hasNext())
    {
      Node catchNode= (Node) iter.next();
      graph.rollOut(catchNode, cc);
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

  private void makeTryFrames()
  {
    for (int i= 0; i < tryStatements.size(); i++)
    {
      TryStatement tryStmt= tryStatements.get(i);
      makeTryFrame(tryStmt);
    }
  }
View Full Code Here

Examples of com.dragome.compiler.ast.TryStatement

    {
      boolean hasFinally= false;
      int start= handle.getStartPC();
      int end= handle.getEndPC();

      TryStatement tryStmt= new TryStatement();
      tryStmt.header= (TryHeaderNode) graph.createNode(TryHeaderNode.class);
      tryStmt.header.tryStmt= tryStmt;

      Block tryBlock= new Block(start, end);
      tryStmt.setTryBlock(tryBlock);

      // tryStmt.setBeginIndex(start);

      tryStatements.add(tryStmt);

      CatchClause cStmt= null;

      // Collect all non-default handlers. The range of each handler is
      // from the 'store'-instruction to the beginning of the next
      // handler.
      while (handle != null && !handle.isDefault() && handle.getStartPC() == start && handle.getEndPC() == end)
      {
        if (cStmt != null)
        {
          cStmt.setEndIndex(handle.getHandlerPC() - 1);
        }
        cStmt= createCatchClause(tryStmt, handle);
        handle= handleIterator.hasNext() ? handleIterator.next() : null;
      }

      int foo= -1;
      if (handle != null && handle.isDefault() && handle.getStartPC() == start)
      {
        // Collect first default handler.
        hasFinally= true;
        if (cStmt != null)
        {
          cStmt.setEndIndex(handle.getHandlerPC() - 1);
          tryStmt.setEndIndex(handle.getHandlerPC() - 1);
          // Warning: We only set a lower bound for the end index. The
          // correct index is set later
          // when the finally statement is analysed.
        }
        cStmt= createCatchClause(tryStmt, handle);
        foo= handle.getHandlerPC();
        handle= handleIterator.hasNext() ? handleIterator.next() : null;
      }

      // Last catch stmt has no endIndex, yet!

      while (handle != null && handle.isDefault() && (handle.getHandlerPC() == foo))
      {
        // Skip all remaining default handlers.
        throw new RuntimeException("remaining default handlers");
        // handle = handleIterator.hasNext()?handleIterator.next():null;
      }

      Block catches= tryStmt.getCatchStatements();
      if (catches.getChildCount() == 0)
      {
        throw new ParseException("A try clause must have at least one (possibly default) catch clause", tryStmt);
      }
      cStmt= (CatchClause) catches.getChildAt(0);
      tryBlock.setEndIndex(cStmt.getBeginIndex() - 1);
      cStmt= (CatchClause) catches.getLastChild();
      if (cStmt.getEndIndex() == Integer.MIN_VALUE)
      {
        cStmt.setEndIndex(cStmt.getBeginIndex() + 1);
      }
      tryStmt.setEndIndex(cStmt.getEndIndex());

      if (hasFinally)
      {
        // Can't say yet where finally block is located.
      }
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.