00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 #ifndef __JHL_ITERATOR_H 00003 #define __JHL_ITERATOR_H 00004 00005 /* 00006 * $Id: jhl_iterator.h,v 1.2 2000/07/24 00:33:30 brm Exp $ 00007 * 00008 * Iterator classes 00009 * 00010 */ 00011 00012 extern SuifEnv* get_suif_env(); 00013 00014 /* 00015 * Abstract baseclass for all iterators. 00016 */ 00017 class jhl_AbstractIterator 00018 #ifdef BDW_GC 00019 : public gc 00020 #endif 00021 { 00022 public: 00023 jhl_AbstractIterator() { } 00024 virtual ~jhl_AbstractIterator() { } 00025 00026 virtual void iterate() =0; 00027 }; 00028 00029 00030 /* 00031 * Iterator that goes throught the bytecode array of a particual 00032 * Java method. For every bytecode the correspondig method in the 00033 * code visitor jhl_CodeVisitor is called. 00034 * 00035 * The field _curr_index can be accesed from the visitor to find out 00036 * the current index of the bytecode the visitor has been invoked for. 00037 * (This value is identical to the first parameter 'ci' for every 00038 * visitor!) 00039 */ 00040 class jhl_ByteCodeIterator : public jhl_AbstractIterator { 00041 private: 00042 jhl_Code* _code; 00043 jhl_CodeVisitor* _v; 00044 00045 jhl_u4 _start_index; 00046 jhl_u4 _curr_index; 00047 jhl_u4 _end_index; 00048 public: 00049 00050 // Java bytecode enum 00051 #include "jhl_bytecode_enum" 00052 00053 // iterate through all bytecodes 00054 jhl_ByteCodeIterator(jhl_Code* c, jhl_CodeVisitor* v); 00055 00056 // iterate through interval [start_index..end_index) of the 00057 // bytecode array 00058 jhl_ByteCodeIterator(jhl_Code* c, 00059 jhl_u4 start_index, 00060 jhl_u4 end_index, 00061 jhl_CodeVisitor* v); 00062 00063 // accessors 00064 jhl_Code* code() const { return _code; } 00065 jhl_CodeVisitor* codeVisitor() const { return _v; } 00066 jhl_u4 start_index() const { return _start_index; } 00067 jhl_u4 curr_index() const { return _curr_index; } 00068 jhl_u4 end_index() const { return _end_index; } 00069 00070 void iterate(); 00071 00072 }; 00073 00074 #endif