original_docstring: 
      Walks through a method, evaluating instructions and using the callback
      for side-effects.
  
      The method is assumed to not have any conditionals, and to only return
      at the very end.
      
docstring: Walks through a method, evaluating instructions and using the callback
  for side-effects.
  
  The method is assumed to not have any conditionals, and to only return
  at the very end.
docstring_tokens: Walks through a method evaluating instructions and using the callback for side - effects . The method is assumed to not have any conditionals and to only return at the very end .
code: def walk_method(cf, method, callback, verbose, input_args=None):
      """
      Walks through a method, evaluating instructions and using the callback
      for side-effects.
  
      The method is assumed to not have any conditionals, and to only return
      at the very end.
      """
      assert isinstance(callback, WalkerCallback)
  
      stack = []
      locals = {}
      cur_index = 0
  
      if not method.access_flags.acc_static:
          # TODO: allow specifying this
          locals[cur_index] = object()
          cur_index += 1
  
      if input_args != None:
          assert len(input_args) == len(method.args)
          for arg in input_args:
              locals[cur_index] = arg
              cur_index += 1
      else:
          for arg in method.args:
              locals[cur_index] = object()
              cur_index += 1
  
      ins_list = list(method.code.disassemble())
      for ins in ins_list[:-1]:
          if ins in ("bipush", "sipush"):
              stack.append(ins.operands[0].value)
          elif ins.mnemonic.startswith("fconst") or ins.mnemonic.startswith("dconst"):
              stack.append(float(ins.mnemonic[-1]))
          elif ins == "aconst_null":
              stack.append(None)
          elif ins in ("ldc", "ldc_w", "ldc2_w"):
              const = ins.operands[0]
  
              if isinstance(const, ConstantClass):
                  stack.append("%s.class" % const.name.value)
              elif isinstance(const, String):
                  stack.append(const.string.value)
              else:
                  stack.append(const.value)
          elif ins == "new":
              const = ins.operands[0]
  
              try:
                  stack.append(callback.on_new(ins, const))
              except StopIteration:
                  break
          elif ins in ("getfield", "getstatic"):
              const = ins.operands[0]
              if ins.mnemonic != "getstatic":
                  obj = stack.pop()
              else:
                  obj = None
  
              try:
                  stack.append(callback.on_get_field(ins, const, obj))
              except StopIteration:
                  break
          elif ins in ("putfield", "putstatic"):
              const = ins.operands[0]
              value = stack.pop()
              if ins.mnemonic != "putstatic":
                  obj = stack.pop()
              else:
                  obj = None
  
              try:
                  callback.on_put_field(ins, const, obj, value)
              except StopIteration:
                  break
          elif ins in ("invokevirtual", "invokespecial", "invokeinterface", "invokestatic"):
              const = ins.operands[0]
              method_desc = const.name_and_type.descriptor.value
              desc = method_descriptor(method_desc)
              num_args = len(desc.args)
  
              args = []
  
              for i in six.moves.range(num_args):
                  args.insert(0, stack.pop())
              if ins.mnemonic != "invokestatic":
                  obj = stack.pop()
              else:
                  obj = None
  
              try:
                  ret = callback.on_invoke(ins, const, obj, args)
              except StopIteration:
                  break
              if desc.returns.name != "void":
                  stack.append(ret)
          elif ins in ("astore", "istore", "lstore", "fstore", "dstore"):
              locals[ins.operands[0].value] = stack.pop()
          elif ins in ("aload", "iload", "lload", "fload", "dload"):
              stack.append(locals[ins.operands[0].value])
          elif ins == "dup":
              stack.append(stack[-1])
          elif ins == "pop":
              stack.pop()
          elif ins == "anewarray":
              stack.append([None] * stack.pop())
          elif ins == "newarray":
              stack.append([0] * stack.pop())
          elif ins in ("aastore", "bastore", "castore", "sastore", "iastore", "lastore", "fastore", "dastore"):
              value = stack.pop()
              index = stack.pop()
              array = stack.pop()
              if isinstance(array, list) and isinstance(index, int):
                  array[index] = value
              elif verbose:
                  print("Failed to execute %s: array %s index %s value %s" % (ins, array, index, value))
          elif ins in ("aaload", "baload", "caload", "saload", "iaload", "laload", "faload", "daload"):
              index = stack.pop()
              array = stack.pop()
              if isinstance(array, list) and isinstance(index, int):
                  stack.push(array[index])
              elif verbose:
                  print("Failed to execute %s: array %s index %s" % (ins, array, index))
          elif ins == "invokedynamic":
              const = ins.operands[0]
              method_desc = const.name_and_type.descriptor.value
              desc = method_descriptor(method_desc)
              num_args = len(desc.args)
  
              args = []
  
              for i in six.moves.range(num_args):
                  args.insert(0, stack.pop())
  
              stack.append(callback.on_invokedynamic(ins, ins.operands[0], args))
          elif ins == "checkcast":
              pass
          elif verbose:
              print("Unknown instruction %s: stack is %s" % (ins, stack))
  
      last_ins = ins_list[-1]
      if last_ins.mnemonic in ("ireturn", "lreturn", "freturn", "dreturn", "areturn"):
          # Non-void method returning
          return stack.pop()
      elif last_ins.mnemonic == "return":
          # Void method returning
          pass
      elif verbose:
          print("Unexpected final instruction %s: stack is %s" % (ins, stack))
code_tokens: def walk_method ( cf , method , callback , verbose , input_args = None ) : assert isinstance ( callback , WalkerCallback ) stack = [ ] locals = { } cur_index = 0 if not method . access_flags . acc_static : locals [ cur_index ] = object ( ) cur_index += 1 if input_args != None : assert len ( input_args ) == len ( method . args ) for arg in input_args : locals [ cur_index ] = arg cur_index += 1 else : for arg in method . args : locals [ cur_index ] = object ( ) cur_index += 1 ins_list = list ( method . code . disassemble ( ) ) for ins in ins_list [ : - 1 ] : if ins in ( "bipush" , "sipush" ) : stack . append ( ins . operands [ 0 ] . value ) elif ins . mnemonic . startswith ( "fconst" ) or ins . mnemonic . startswith ( "dconst" ) : stack . append ( float ( ins . mnemonic [ - 1 ] ) ) elif ins == "aconst_null" : stack . append ( None ) elif ins in ( "ldc" , "ldc_w" , "ldc2_w" ) : const = ins . operands [ 0 ] if isinstance ( const , ConstantClass ) : stack . append ( "%s.class" % const . name . value ) elif isinstance ( const , String ) : stack . append ( const . string . value ) else : stack . append ( const . value ) elif ins == "new" : const = ins . operands [ 0 ] try : stack . append ( callback . on_new ( ins , const ) ) except StopIteration : break elif ins in ( "getfield" , "getstatic" ) : const = ins . operands [ 0 ] if ins . mnemonic != "getstatic" : obj = stack . pop ( ) else : obj = None try : stack . append ( callback . on_get_field ( ins , const , obj ) ) except StopIteration : break elif ins in ( "putfield" , "putstatic" ) : const = ins . operands [ 0 ] value = stack . pop ( ) if ins . mnemonic != "putstatic" : obj = stack . pop ( ) else : obj = None try : callback . on_put_field ( ins , const , obj , value ) except StopIteration : break elif ins in ( "invokevirtual" , "invokespecial" , "invokeinterface" , "invokestatic" ) : const = ins . operands [ 0 ] method_desc = const . name_and_type . descriptor . value desc = method_descriptor ( method_desc ) num_args = len ( desc . args ) args = [ ] for i in six . moves . range ( num_args ) : args . insert ( 0 , stack . pop ( ) ) if ins . mnemonic != "invokestatic" : obj = stack . pop ( ) else : obj = None try : ret = callback . on_invoke ( ins , const , obj , args ) except StopIteration : break if desc . returns . name != "void" : stack . append ( ret ) elif ins in ( "astore" , "istore" , "lstore" , "fstore" , "dstore" ) : locals [ ins . operands [ 0 ] . value ] = stack . pop ( ) elif ins in ( "aload" , "iload" , "lload" , "fload" , "dload" ) : stack . append ( locals [ ins . operands [ 0 ] . value ] ) elif ins == "dup" : stack . append ( stack [ - 1 ] ) elif ins == "pop" : stack . pop ( ) elif ins == "anewarray" : stack . append ( [ None ] * stack . pop ( ) ) elif ins == "newarray" : stack . append ( [ 0 ] * stack . pop ( ) ) elif ins in ( "aastore" , "bastore" , "castore" , "sastore" , "iastore" , "lastore" , "fastore" , "dastore" ) : value = stack . pop ( ) index = stack . pop ( ) array = stack . pop ( ) if isinstance ( array , list ) and isinstance ( index , int ) : array [ index ] = value elif verbose : print ( "Failed to execute %s: array %s index %s value %s" % ( ins , array , index , value ) ) elif ins in ( "aaload" , "baload" , "caload" , "saload" , "iaload" , "laload" , "faload" , "daload" ) : index = stack . pop ( ) array = stack . pop ( ) if isinstance ( array , list ) and isinstance ( index , int ) : stack . push ( array [ index ] ) elif verbose : print ( "Failed to execute %s: array %s index %s" % ( ins , array , index ) ) elif ins == "invokedynamic" : const = ins . operands [ 0 ] method_desc = const . name_and_type . descriptor . value desc = method_descriptor ( method_desc ) num_args = len ( desc . args ) args = [ ] for i in six . moves . range ( num_args ) : args . insert ( 0 , stack . pop ( ) ) stack . append ( callback . on_invokedynamic ( ins , ins . operands [ 0 ] , args ) ) elif ins == "checkcast" : pass elif verbose : print ( "Unknown instruction %s: stack is %s" % ( ins , stack ) ) last_ins = ins_list [ - 1 ] if last_ins . mnemonic in ( "ireturn" , "lreturn" , "freturn" , "dreturn" , "areturn" ) : return stack . pop ( ) elif last_ins . mnemonic == "return" : pass elif verbose : print ( "Unexpected final instruction %s: stack is %s" % ( ins , stack ) )
short_docstring: Walks through a method, evaluating instructions and using the callback
  for side-effects.
short_docstring_tokens: Walks through a method evaluating instructions and using the callback for side - effects .
comment: """
      Walks through a method, evaluating instructions and using the callback
      for side-effects.
  
      The method is assumed to not have any conditionals, and to only return
      at the very end.
      """$SEP$# TODO: allow specifying this$SEP$# Non-void method returning$SEP$# Void method returning