Class KotlinSafeCallOperatorFilter

  • All Implemented Interfaces:
    IFilter

    final class KotlinSafeCallOperatorFilter
    extends java.lang.Object
    implements IFilter
    Filters bytecode that Kotlin compiler generates for chains of safe call operators (?.).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void filter​(org.objectweb.asm.tree.MethodNode methodNode, IFilterContext context, IFilterOutput output)
      This method is called for every method.
      private static java.util.Collection<java.util.ArrayList<org.objectweb.asm.tree.JumpInsnNode>> findChains​(org.objectweb.asm.tree.MethodNode methodNode)
      "optimized" chain:
      private static boolean isUnoptimizedSafeCallFollowedByElvis​(org.objectweb.asm.tree.JumpInsnNode jump, org.objectweb.asm.tree.AbstractInsnNode target, java.util.ArrayList<org.objectweb.asm.tree.JumpInsnNode> chain)  
      private static org.objectweb.asm.tree.AbstractInsnNode preceding​(org.objectweb.asm.tree.AbstractInsnNode i, int opcode)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KotlinSafeCallOperatorFilter

        KotlinSafeCallOperatorFilter()
    • Method Detail

      • filter

        public void filter​(org.objectweb.asm.tree.MethodNode methodNode,
                           IFilterContext context,
                           IFilterOutput output)
        Description copied from interface: IFilter
        This method is called for every method. The filter implementation is expected to inspect the provided method and report its result to the given IFilterOutput instance.
        Specified by:
        filter in interface IFilter
        Parameters:
        methodNode - method to inspect
        context - context information for the method
        output - callback to report filtering results to
      • findChains

        private static java.util.Collection<java.util.ArrayList<org.objectweb.asm.tree.JumpInsnNode>> findChains​(org.objectweb.asm.tree.MethodNode methodNode)
        "optimized" chain:
         DUP
         IFNULL label
         ... // call 0
        
         ...
        
         DUP
         IFNULL label
         ... // call N
        
         label:
         POP
         
        "unoptimized" chain:
         ALOAD v0
         IFNULL label
         ... // call 0
        
         ...
        
         ASTORE v1
         ALOAD v1
         IFNULL label
         ... // call N
        
         label:
         ACONST_NULL
         
        "unoptimized" safe call operator(s) followed by elvis operator:
         ALOAD v0
         IFNULL nullCase
         ... // call 0
        
         ASTORE v1
         ALOAD v1
         IFNULL nullCase
         ... // call 1
        
         ...
        
         ASTORE vN
         ALOAD vN
         IFNULL nullCase
         ALOAD vN
         GOTO nonNullCase
         nullCase:
         ... // right hand side of elvis operator
         nonNullCase:
         ...
         
      • isUnoptimizedSafeCallFollowedByElvis

        private static boolean isUnoptimizedSafeCallFollowedByElvis​(org.objectweb.asm.tree.JumpInsnNode jump,
                                                                    org.objectweb.asm.tree.AbstractInsnNode target,
                                                                    java.util.ArrayList<org.objectweb.asm.tree.JumpInsnNode> chain)
      • preceding

        private static org.objectweb.asm.tree.AbstractInsnNode preceding​(org.objectweb.asm.tree.AbstractInsnNode i,
                                                                         int opcode)
        Returns:
        non pseudo-instruction preceding given if it has given opcode, null otherwise