/src/main/java/com/alibaba/fastjson/asm/MethodVisitor.java

https://github.com/alibaba/fastjson · Java · 153 lines · 15 code · 17 blank · 121 comment · 0 complexity · 6824931a5cda64c09f158badd94fccab MD5 · raw file

  1. /***
  2. * ASM: a very small and fast Java bytecode manipulation framework
  3. * Copyright (c) 2000-2007 INRIA, France Telecom
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  28. * THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. package com.alibaba.fastjson.asm;
  31. /**
  32. *
  33. * @author Eric Bruneton
  34. */
  35. public interface MethodVisitor {
  36. // -------------------------------------------------------------------------
  37. // Annotations and non standard attributes
  38. // -------------------------------------------------------------------------
  39. // -------------------------------------------------------------------------
  40. // Normal instructions
  41. // -------------------------------------------------------------------------
  42. /**
  43. * Visits a zero operand instruction.
  44. *
  45. * @param opcode the opcode of the instruction to be visited. This opcode is either NOP, ACONST_NULL, ICONST_M1,
  46. * ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2,
  47. * DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
  48. * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD,
  49. * LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM,
  50. * INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D,
  51. * L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
  52. * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.
  53. */
  54. void visitInsn(int opcode);
  55. void visitIntInsn(int opcode, int operand);
  56. /**
  57. * Visits a local variable instruction. A local variable instruction is an instruction that loads or stores the
  58. * value of a local variable.
  59. *
  60. * @param opcode the opcode of the local variable instruction to be visited. This opcode is either ILOAD, LLOAD,
  61. * FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
  62. * @param var the operand of the instruction to be visited. This operand is the index of a local variable.
  63. */
  64. void visitVarInsn(int opcode, int var);
  65. /**
  66. * Visits a type instruction. A type instruction is an instruction that takes the internal name of a class as
  67. * parameter.
  68. *
  69. * @param opcode the opcode of the type instruction to be visited. This opcode is either NEW, ANEWARRAY, CHECKCAST
  70. * or INSTANCEOF.
  71. * @param type the operand of the instruction to be visited. This operand must be the internal name of an object or
  72. * array class (see {@link Type#getInternalName() getInternalName}).
  73. */
  74. void visitTypeInsn(int opcode, String type);
  75. /**
  76. * Visits a field instruction. A field instruction is an instruction that loads or stores the value of a field of an
  77. * object.
  78. *
  79. * @param opcode the opcode of the type instruction to be visited. This opcode is either GETSTATIC, PUTSTATIC,
  80. * GETFIELD or PUTFIELD.
  81. * @param owner the internal name of the field's owner class (see {@link Type#getInternalName() getInternalName}).
  82. * @param name the field's name.
  83. * @param desc the field's descriptor (see {@link Type Type}).
  84. */
  85. void visitFieldInsn(int opcode, String owner, String name, String desc);
  86. void visitMethodInsn(int opcode, String owner, String name, String desc);
  87. /**
  88. * Visits a jump instruction. A jump instruction is an instruction that may jump to another instruction.
  89. *
  90. * @param opcode the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE,
  91. * IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR,
  92. * IFNULL or IFNONNULL.
  93. * @param label the operand of the instruction to be visited. This operand is a label that designates the
  94. * instruction to which the jump instruction may jump.
  95. */
  96. void visitJumpInsn(int opcode, Label label);
  97. /**
  98. * Visits a label. A label designates the instruction that will be visited just after it.
  99. *
  100. * @param label a {@link Label Label} object.
  101. */
  102. void visitLabel(Label label);
  103. // -------------------------------------------------------------------------
  104. // Special instructions
  105. // -------------------------------------------------------------------------
  106. /**
  107. * Visits a LDC instruction.
  108. *
  109. * @param cst the constant to be loaded on the stack. This parameter must be a non null {@link Integer}, a
  110. * {@link Float}, a {@link Long}, a {@link Double} a {@link String} (or a {@link Type} for <tt>.class</tt>
  111. * constants, for classes whose version is 49.0 or more).
  112. */
  113. void visitLdcInsn(Object cst);
  114. /**
  115. * Visits an IINC instruction.
  116. *
  117. * @param var index of the local variable to be incremented.
  118. * @param increment amount to increment the local variable by.
  119. */
  120. void visitIincInsn(int var, int increment);
  121. // -------------------------------------------------------------------------
  122. // Exceptions table entries, debug information, max stack and max locals
  123. // -------------------------------------------------------------------------
  124. /**
  125. * Visits the maximum stack size and the maximum number of local variables of the method.
  126. *
  127. * @param maxStack maximum stack size of the method.
  128. * @param maxLocals maximum number of local variables for the method.
  129. */
  130. void visitMaxs(int maxStack, int maxLocals);
  131. /**
  132. * Visits the end of the method. This method, which is the last one to be called, is used to inform the visitor that
  133. * all the annotations and attributes of the method have been visited.
  134. */
  135. void visitEnd();
  136. }