1466 void genCatch(JCCatch tree, |
1468 void genCatch(JCCatch tree, |
1467 Env<GenContext> env, |
1469 Env<GenContext> env, |
1468 int startpc, int endpc, |
1470 int startpc, int endpc, |
1469 List<Integer> gaps) { |
1471 List<Integer> gaps) { |
1470 if (startpc != endpc) { |
1472 if (startpc != endpc) { |
1471 List<JCExpression> subClauses = TreeInfo.isMultiCatch(tree) ? |
1473 List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypeExprs |
1472 ((JCTypeUnion)tree.param.vartype).alternatives : |
1474 = catchTypesWithAnnotations(tree); |
1473 List.of(tree.param.vartype); |
|
1474 while (gaps.nonEmpty()) { |
1475 while (gaps.nonEmpty()) { |
1475 for (JCExpression subCatch : subClauses) { |
1476 for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) { |
|
1477 JCExpression subCatch = subCatch1.snd; |
1476 int catchType = makeRef(tree.pos(), subCatch.type); |
1478 int catchType = makeRef(tree.pos(), subCatch.type); |
1477 int end = gaps.head.intValue(); |
1479 int end = gaps.head.intValue(); |
1478 registerCatch(tree.pos(), |
1480 registerCatch(tree.pos(), |
1479 startpc, end, code.curCP(), |
1481 startpc, end, code.curCP(), |
1480 catchType); |
1482 catchType); |
1481 if (subCatch.type.isAnnotated()) { |
1483 for (Attribute.TypeCompound tc : subCatch1.fst) { |
1482 for (Attribute.TypeCompound tc : |
|
1483 subCatch.type.getAnnotationMirrors()) { |
|
1484 tc.position.setCatchInfo(catchType, startpc); |
1484 tc.position.setCatchInfo(catchType, startpc); |
1485 } |
|
1486 } |
1485 } |
1487 } |
1486 } |
1488 gaps = gaps.tail; |
1487 gaps = gaps.tail; |
1489 startpc = gaps.head.intValue(); |
1488 startpc = gaps.head.intValue(); |
1490 gaps = gaps.tail; |
1489 gaps = gaps.tail; |
1491 } |
1490 } |
1492 if (startpc < endpc) { |
1491 if (startpc < endpc) { |
1493 for (JCExpression subCatch : subClauses) { |
1492 for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) { |
|
1493 JCExpression subCatch = subCatch1.snd; |
1494 int catchType = makeRef(tree.pos(), subCatch.type); |
1494 int catchType = makeRef(tree.pos(), subCatch.type); |
1495 registerCatch(tree.pos(), |
1495 registerCatch(tree.pos(), |
1496 startpc, endpc, code.curCP(), |
1496 startpc, endpc, code.curCP(), |
1497 catchType); |
1497 catchType); |
1498 if (subCatch.type.isAnnotated()) { |
1498 for (Attribute.TypeCompound tc : subCatch1.fst) { |
1499 for (Attribute.TypeCompound tc : |
1499 tc.position.setCatchInfo(catchType, startpc); |
1500 subCatch.type.getAnnotationMirrors()) { |
|
1501 tc.position.setCatchInfo(catchType, startpc); |
|
1502 } |
|
1503 } |
1500 } |
1504 } |
1501 } |
1505 } |
1502 } |
1506 VarSymbol exparam = tree.param.sym; |
1503 VarSymbol exparam = tree.param.sym; |
1507 code.statBegin(tree.pos); |
1504 code.statBegin(tree.pos); |
1508 code.markStatBegin(); |
1505 code.markStatBegin(); |
1509 int limit = code.nextreg; |
1506 int limit = code.nextreg; |
1510 int exlocal = code.newLocal(exparam); |
1507 code.newLocal(exparam); |
1511 items.makeLocalItem(exparam).store(); |
1508 items.makeLocalItem(exparam).store(); |
1512 code.statBegin(TreeInfo.firstStatPos(tree.body)); |
1509 code.statBegin(TreeInfo.firstStatPos(tree.body)); |
1513 genStat(tree.body, env, CRT_BLOCK); |
1510 genStat(tree.body, env, CRT_BLOCK); |
1514 code.endScopes(limit); |
1511 code.endScopes(limit); |
1515 code.statBegin(TreeInfo.endPos(tree.body)); |
1512 code.statBegin(TreeInfo.endPos(tree.body)); |
1516 } |
1513 } |
|
1514 } |
|
1515 // where |
|
1516 List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotations(JCCatch tree) { |
|
1517 return TreeInfo.isMultiCatch(tree) ? |
|
1518 catchTypesWithAnnotationsFromMulticatch((JCTypeUnion)tree.param.vartype, tree.param.sym.getRawTypeAttributes()) : |
|
1519 List.of(new Pair<>(tree.param.sym.getRawTypeAttributes(), tree.param.vartype)); |
|
1520 } |
|
1521 // where |
|
1522 List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotationsFromMulticatch(JCTypeUnion tree, List<TypeCompound> first) { |
|
1523 List<JCExpression> alts = tree.alternatives; |
|
1524 List<Pair<List<TypeCompound>, JCExpression>> res = List.of(new Pair<>(first, alts.head)); |
|
1525 alts = alts.tail; |
|
1526 |
|
1527 while(alts != null && alts.head != null) { |
|
1528 JCExpression alt = alts.head; |
|
1529 if (alt instanceof JCAnnotatedType) { |
|
1530 JCAnnotatedType a = (JCAnnotatedType)alt; |
|
1531 res = res.prepend(new Pair<>(annotate.fromAnnotations(a.annotations), alt)); |
|
1532 } else { |
|
1533 res = res.prepend(new Pair<>(List.nil(), alt)); |
|
1534 } |
|
1535 alts = alts.tail; |
|
1536 } |
|
1537 return res.reverse(); |
1517 } |
1538 } |
1518 |
1539 |
1519 /** Register a catch clause in the "Exceptions" code-attribute. |
1540 /** Register a catch clause in the "Exceptions" code-attribute. |
1520 */ |
1541 */ |
1521 void registerCatch(DiagnosticPosition pos, |
1542 void registerCatch(DiagnosticPosition pos, |