Package com.dragome.compiler.ast

Examples of com.dragome.compiler.ast.CatchClause


  {
    println("try {");
    visit_(tryStmt.getTryBlock());
    indent("} ");
    Block clauses= tryStmt.getCatchStatements();
    CatchClause clause= (CatchClause) clauses.getFirstChild();

    String ex= null;
    if (clause != null)
    {
      ex= clause.getException().getName();
    }

    //  if (clauses.getChildCount() == 1)
    //  {
    //      print("catch(" + ex + ") ");
    //      clause.visit(this);
    //  }
    if (clauses.getChildCount() > 0)
    {
      println("catch(" + ex + ") {");
      depth++;
      indent();
      while (clause != null)
      {
        if (clause.getException().getType() != null)
          print("if (dragomeJs.isInstanceof(" + ex + ", " + normalizeExpression(Utils.getSignature(clause.getException().getType())) + ")) ");
        else
          print("if (true)");

        clause.visit(this);
        clause= (CatchClause) clause.getNextSibling();
        if (clause == null)
          break;
        print(" else ");
      }
View Full Code Here


    {
      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);
      cc= (CatchClause) cc.getNextSibling();
    }
  }
View Full Code Here

    loopFound= false;
  }

  private CatchClause createCatchClause(TryStatement tryStmt, ExceptionHandler handle)
  {
    CatchClause cStmt= new CatchClause(handle.getHandlerPC());
    VariableDeclaration decl= new VariableDeclaration(VariableDeclaration.LOCAL_PARAMETER);
    decl.setName("_EX_");
    decl.setType(handle.getCatchType(constantPool));
    cStmt.setException(decl);
    tryStmt.addCatchStatement(cStmt);
    return cStmt;
  }
View Full Code Here

    Node tryNode= graph.getOrCreateNode(stmt.getBeginIndex());
    tryNode.stack= new ASTNodeStack();
    header.setTryBody(tryNode);

    CatchClause clause= (CatchClause) stmt.getCatchStatements().getFirstChild();
    while (clause != null)
    {
      // Push implicit exception.
      Node catchNode= graph.createNode(clause.getBeginIndex());
      // catchNode.type = NodeType.CATCH;
      catchNode.stack= new ASTNodeStack(new VariableBinding(clause.getException()));
      header.addCatchNode(catchNode);

      clause= (CatchClause) clause.getNextSibling();
    }
  }
View Full Code Here

      // 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

Related Classes of com.dragome.compiler.ast.CatchClause

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.