jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Burt Wagner" <burt.wag...@alignmentsoftware.com>
Subject RE: Method start & termination points
Date Wed, 21 Aug 2002 15:50:31 GMT
Ian Hunter wrote:

Are there convenient ways within BCel to identify points in methods
where 
users can safely insert code. My thoughts are that given a method, can I

identify things like all return statements, exception exits from the
method 
and possibly System.exit(). I also realise that in the case of <init>
there 
is some code which must be first (the new and the call to super()).
There may be other examples which I haven't come across.

Burt Wagner, Senior Software Engineer
Alignment Software, Inc. www.alignmentsoftware.com
(Formerly NPULSE Software, Inc. www.npulse.com)
100 Superior Plaza Way, Suite 200
Superior, Colorado 80027
Work: (303) 642-4457 WFax: (303) 642-4002
Cell: (303) 589-3095

Responds:

The following code snip might give you some ideas.

public static final String PATTERNS =
   "`RETURN'|`ARETURN'|`DRETURN'|`FRETURN'|`IRETURN'|`LRETURN'";

InstructionHandle instructionHandle = instructionList.getStart();
FindPattern findPattern = new FindPattern(instructionList);

do {

   instructionHandle = findPattern.search(PATTERNS, instructionHandle);

   if (instructionHandle != null) {

      Instruction instruction = instructionHandle.getInstruction();
      switch (instruction.getOpcode()) {

      case Constants.IRETURN: // 172
         break;

      case Constants.LRETURN: // 173
         break;

      case Constants.FRETURN: // 174
         break;

      case Constants.DRETURN: // 175
         break;

      case Constants.ARETURN: // 176
         break;

      case Constants.RETURN: // 177
         break;

      default: throw new RuntimeException("Bad case in opcode switch");
      }

} while (instructionHandle!=null);
 

--
To unsubscribe, e-mail:   <mailto:bcel-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:bcel-user-help@jakarta.apache.org>


Mime
View raw message