1414
1515import dotty .tools .backend .jvm .attributes .InstructionTypeArguments ;
1616import dotty .tools .backend .jvm .attributes .InvokeReturnType ;
17+ import dotty .tools .backend .jvm .attributes .ExtraBoxUnbox ;
1718import java .util .Map ;
1819
1920import dotty .tools .backend .jvm .attributes .TypeHints ;
@@ -43,12 +44,16 @@ public class MethodNode1 extends MethodNode {
4344
4445 public Map <AbstractInsnNode , List <TypeHints .TypeA >> instructionTypeArgTypeAs = new LinkedHashMap <>();
4546
47+ public Map <AbstractInsnNode , Boolean > extraBoxUnboxMap = new LinkedHashMap <>();
48+
4649 private Map <AbstractInsnNode , Integer > offsetMap = new LinkedHashMap <>();
4750
4851 private InvokeReturnType invokeReturnTypeAttribute ;
4952
5053 private InstructionTypeArguments instructionTypeArgumentsAttribute ;
5154
55+ private ExtraBoxUnbox extraBoxUnboxAttribute ;
56+
5257 public MethodNode1 (int api , int access , String name , String descriptor , String signature , String [] exceptions ) {
5358 super (api , access , name , descriptor , signature , exceptions );
5459 }
@@ -393,6 +398,7 @@ public void setAttribtues(){
393398 if (!hasTypeHints ()) return ;
394399 genOffsetMap ();
395400 if (DEBUG ) printOffsetMap ();
401+ // create InvokeReturnType attribute
396402 List <TypeHints .TypeBHint > typeBHintList = new ArrayList <>();
397403 for (Map .Entry <AbstractInsnNode , TypeHints .TypeB > entry : invokeReturnTypeBs .entrySet ()){
398404 AbstractInsnNode insn = entry .getKey ();
@@ -411,6 +417,7 @@ public void setAttribtues(){
411417 if (DEBUG ) System .out .println ("invokeReturnTypeAttribute: " + invokeReturnTypeAttribute );
412418 visitAttribute (invokeReturnTypeAttribute );
413419 }
420+ // create InstructionTypeArguments attribute
414421 List <TypeHints .TypeAHint > typeAHintList = new ArrayList <>();
415422 for (Map .Entry <AbstractInsnNode , List <TypeHints .TypeA >> entry : instructionTypeArgTypeAs .entrySet ()){
416423 AbstractInsnNode insn = entry .getKey ();
@@ -428,6 +435,25 @@ public void setAttribtues(){
428435 if (DEBUG ) System .out .println ("instructionTypeArgumentsAttribute: " + instructionTypeArgumentsAttribute );
429436 visitAttribute (instructionTypeArgumentsAttribute );
430437 }
438+ // create ExtraBoxUnbox attribute
439+ List <Integer > extraBoxUnboxOffsets = new ArrayList <>();
440+ for (Map .Entry <AbstractInsnNode , Boolean > entry : extraBoxUnboxMap .entrySet ()){
441+ AbstractInsnNode insn = entry .getKey ();
442+ Boolean hasExtraBoxUnbox = entry .getValue ();
443+ if (!hasExtraBoxUnbox ) continue ;
444+ Integer bcOffset = offsetMap .getOrDefault (insn , -1 );
445+ if (bcOffset != -1 ){
446+ extraBoxUnboxOffsets .add (bcOffset );
447+ } else {
448+ throw new IllegalArgumentException ();
449+ }
450+ }
451+ if (extraBoxUnboxOffsets .size () != 0 ){
452+ int [] offsetsArray = extraBoxUnboxOffsets .stream ().mapToInt (i -> i ).toArray ();
453+ this .extraBoxUnboxAttribute = new ExtraBoxUnbox (offsetsArray );
454+ if (DEBUG ) System .out .println ("extraBoxUnboxAttribute: " + extraBoxUnboxAttribute );
455+ visitAttribute (extraBoxUnboxAttribute );
456+ }
431457
432458 }
433459
0 commit comments