nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java
changeset 28690 78317797ab62
parent 28130 433d6755c5f8
child 29283 fb47e4d25a9f
equal deleted inserted replaced
28597:b2f9702efbe9 28690:78317797ab62
    60 import jdk.nashorn.internal.ir.IfNode;
    60 import jdk.nashorn.internal.ir.IfNode;
    61 import jdk.nashorn.internal.ir.IndexNode;
    61 import jdk.nashorn.internal.ir.IndexNode;
    62 import jdk.nashorn.internal.ir.JoinPredecessor;
    62 import jdk.nashorn.internal.ir.JoinPredecessor;
    63 import jdk.nashorn.internal.ir.JoinPredecessorExpression;
    63 import jdk.nashorn.internal.ir.JoinPredecessorExpression;
    64 import jdk.nashorn.internal.ir.JumpStatement;
    64 import jdk.nashorn.internal.ir.JumpStatement;
       
    65 import jdk.nashorn.internal.ir.JumpToInlinedFinally;
    65 import jdk.nashorn.internal.ir.LabelNode;
    66 import jdk.nashorn.internal.ir.LabelNode;
    66 import jdk.nashorn.internal.ir.LexicalContext;
    67 import jdk.nashorn.internal.ir.LexicalContext;
    67 import jdk.nashorn.internal.ir.LexicalContextNode;
    68 import jdk.nashorn.internal.ir.LexicalContextNode;
    68 import jdk.nashorn.internal.ir.LiteralNode;
    69 import jdk.nashorn.internal.ir.LiteralNode;
    69 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
    70 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
   527     private boolean enterJumpStatement(final JumpStatement jump) {
   528     private boolean enterJumpStatement(final JumpStatement jump) {
   528         if(!reachable) {
   529         if(!reachable) {
   529             return false;
   530             return false;
   530         }
   531         }
   531         assertTypeStackIsEmpty();
   532         assertTypeStackIsEmpty();
   532         final BreakableNode target = jump.getTarget(lc);
   533         jumpToLabel(jump, jump.getTargetLabel(lc), getBreakTargetTypes(jump.getPopScopeLimit(lc)));
   533         jumpToLabel(jump, jump.getTargetLabel(target), getBreakTargetTypes(target));
       
   534         doesNotContinueSequentially();
   534         doesNotContinueSequentially();
   535         return false;
   535         return false;
   536     }
   536     }
   537 
   537 
   538     @Override
   538     @Override
   782         }
   782         }
   783         return false;
   783         return false;
   784     }
   784     }
   785 
   785 
   786     @Override
   786     @Override
       
   787     public boolean enterJumpToInlinedFinally(final JumpToInlinedFinally jumpToInlinedFinally) {
       
   788         return enterJumpStatement(jumpToInlinedFinally);
       
   789     }
       
   790 
       
   791     @Override
   787     public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
   792     public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
   788         if (literalNode instanceof ArrayLiteralNode) {
   793         if (literalNode instanceof ArrayLiteralNode) {
   789             final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
   794             final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
   790             if (expressions != null) {
   795             if (expressions != null) {
   791                 visitExpressions(expressions);
   796                 visitExpressions(expressions);
  1039         if(reachable) {
  1044         if(reachable) {
  1040             jumpToLabel(body, endLabel);
  1045             jumpToLabel(body, endLabel);
  1041             canExit = true;
  1046             canExit = true;
  1042         }
  1047         }
  1043         doesNotContinueSequentially();
  1048         doesNotContinueSequentially();
       
  1049 
       
  1050         for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
       
  1051             final Block finallyBody = TryNode.getLabelledInlinedFinallyBlock(inlinedFinally);
       
  1052             joinOnLabel(finallyBody.getEntryLabel());
       
  1053             // NOTE: the jump to inlined finally can end up in dead code, so it is not necessarily reachable.
       
  1054             if (reachable) {
       
  1055                 finallyBody.accept(this);
       
  1056                 // All inlined finallies end with a jump or a return
       
  1057                 assert !reachable;
       
  1058             }
       
  1059         }
  1044 
  1060 
  1045         joinOnLabel(catchLabel);
  1061         joinOnLabel(catchLabel);
  1046         for(final CatchNode catchNode: tryNode.getCatches()) {
  1062         for(final CatchNode catchNode: tryNode.getCatches()) {
  1047             final IdentNode exception = catchNode.getException();
  1063             final IdentNode exception = catchNode.getException();
  1048             onAssignment(exception, LvarType.OBJECT);
  1064             onAssignment(exception, LvarType.OBJECT);
  1123             withNode.getBody().accept(this);
  1139             withNode.getBody().accept(this);
  1124         }
  1140         }
  1125         return false;
  1141         return false;
  1126     };
  1142     };
  1127 
  1143 
  1128     private Map<Symbol, LvarType> getBreakTargetTypes(final BreakableNode target) {
  1144     private Map<Symbol, LvarType> getBreakTargetTypes(final LexicalContextNode target) {
  1129         // Remove symbols defined in the the blocks that are being broken out of.
  1145         // Remove symbols defined in the the blocks that are being broken out of.
  1130         Map<Symbol, LvarType> types = localVariableTypes;
  1146         Map<Symbol, LvarType> types = localVariableTypes;
  1131         for(final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
  1147         for(final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
  1132             final LexicalContextNode node = it.next();
  1148             final LexicalContextNode node = it.next();
  1133             if(node instanceof Block) {
  1149             if(node instanceof Block) {
  1378             @Override
  1394             @Override
  1379             protected Node leaveDefault(final Node node) {
  1395             protected Node leaveDefault(final Node node) {
  1380                 if(node instanceof JoinPredecessor) {
  1396                 if(node instanceof JoinPredecessor) {
  1381                     final JoinPredecessor original = joinPredecessors.pop();
  1397                     final JoinPredecessor original = joinPredecessors.pop();
  1382                     assert original.getClass() == node.getClass() : original.getClass().getName() + "!=" + node.getClass().getName();
  1398                     assert original.getClass() == node.getClass() : original.getClass().getName() + "!=" + node.getClass().getName();
  1383                     return (Node)setLocalVariableConversion(original, (JoinPredecessor)node);
  1399                     final JoinPredecessor newNode = setLocalVariableConversion(original, (JoinPredecessor)node);
       
  1400                     if (newNode instanceof LexicalContextNode) {
       
  1401                         lc.replace((LexicalContextNode)node, (LexicalContextNode)newNode);
       
  1402                     }
       
  1403                     return (Node)newNode;
  1384                 }
  1404                 }
  1385                 return node;
  1405                 return node;
  1386             }
  1406             }
  1387 
  1407 
  1388             @Override
  1408             @Override