org.oklab.compiler.nametable
クラス CodeBufferManager

java.lang.Object
  上位を拡張 org.oklab.compiler.nametable.CodeBufferManager
すべての実装されたインタフェース:
IntermediateLangManager

public class CodeBufferManager
extends java.lang.Object
implements IntermediateLangManager

コードを保持するクラス. コードとは、メソッド内に書かれた文(Statement)や式の事.変数や関数などはその文字列を コンテントプールに保持して、保持する場所のindex情報をFieldManagerやMethodManagerが管理する. 実際の実行されるコード部分である{}内の情報はこのクラスが管理する.またバイトコードを そのたびに出力するのではなく、このクラスのバッファで保持して、最後に一気にファイル出力をする.

導入されたバージョン:
1.0
バージョン:
1.01
作成者:
Satoshi Okita satoshiokita@gmail.com
関連項目:
VM Spec ClassFile

フィールドの概要
private  int attributeNameIndex
          クラスファイル内のCodeと示された文字列が実際の実行コードのindexとなる.
private static int BYTECODE_BUFFER_SIZE
           
private  int bytecodeByteSize
          バイトコードのバイト数.
private  byte[] bytecodes
          実際のバイトコードを保持する.
private static CodeBufferManager instance
           
private  int maxLocalVariable
          ローカル変数の最大数.
private  int maxOperandStack
          オペランドスタックの最大数.
 
コンストラクタの概要
private CodeBufferManager()
          バイトコードを保持するために初期化.
 
メソッドの概要
 int appendEmpty(int size)
          空領域を確保して、確保する前のバイトコードのバイト数を返す.このコードバッファマネージャ のバイトコード数は引数の数値分増加する.
 void emitCode(java.io.DataOutputStream classfile)
          クラスファイルに書き出し.
 int getBytecodeByteSize()
          バッファに書き込まれたバイトコードのバイト数.保存される領域の最大値ではない.
static CodeBufferManager getInstance()
           
 void init()
           
 void insertEmpty(int offset, int size)
          空領域を途中に挿入する.
 void patchByte(int bytecodeByteSize, int code)
           
 void patchInt(int bytecodeByteSize, int code)
           
 void patchShort(int bytecodeByteSize, int code)
           
 void patchUnsignedByte(int bytecodeByteSize, int code)
           
 void patchUnsignedShort(int bytecodeByteSize, int code)
           
private  void requireToExtendCode(int currentBytecodeSize)
          もしコード領域が足りない場合は、確認して拡張する.
 void setMaxLocalVariable(int localVariable)
           
 void setMaxOperandStack(int stackPointer)
           
 void writeByte(int code)
           
 void writeInt(int code)
           
(package private)  void writeReturnBytecode()
           
 void writeShort(int code)
           
 void writeUnsignedByte(int code)
           
 void writeUnsignedShort(int code)
           
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

BYTECODE_BUFFER_SIZE

private static int BYTECODE_BUFFER_SIZE

attributeNameIndex

private int attributeNameIndex
クラスファイル内のCodeと示された文字列が実際の実行コードのindexとなる.


bytecodes

private byte[] bytecodes
実際のバイトコードを保持する.


maxOperandStack

private int maxOperandStack
オペランドスタックの最大数.(=スタックポインタ)


maxLocalVariable

private int maxLocalVariable
ローカル変数の最大数.


bytecodeByteSize

private int bytecodeByteSize
バイトコードのバイト数.


instance

private static CodeBufferManager instance
コンストラクタの詳細

CodeBufferManager

private CodeBufferManager()
                   throws CompileError
バイトコードを保持するために初期化.

例外:
CompileError
メソッドの詳細

getInstance

public static CodeBufferManager getInstance()
                                     throws CompileError
例外:
CompileError

setMaxOperandStack

public void setMaxOperandStack(int stackPointer)
                        throws CompileError
例外:
CompileError

setMaxLocalVariable

public void setMaxLocalVariable(int localVariable)
                         throws CompileError
例外:
CompileError

emitCode

public void emitCode(java.io.DataOutputStream classfile)
              throws CompileError
クラスファイルに書き出し.

例外:
CompileError
関連項目:
VM Spec - ClassFile

getBytecodeByteSize

public int getBytecodeByteSize()
バッファに書き込まれたバイトコードのバイト数.保存される領域の最大値ではない.

戻り値:
バイト数.

patchByte

public void patchByte(int bytecodeByteSize,
                      int code)
               throws CompileError
例外:
CompileError

patchUnsignedByte

public void patchUnsignedByte(int bytecodeByteSize,
                              int code)
                       throws CompileError
例外:
CompileError

patchShort

public void patchShort(int bytecodeByteSize,
                       int code)
                throws CompileError
例外:
CompileError

patchUnsignedShort

public void patchUnsignedShort(int bytecodeByteSize,
                               int code)
                        throws CompileError
例外:
CompileError

patchInt

public void patchInt(int bytecodeByteSize,
                     int code)
              throws CompileError
例外:
CompileError

writeByte

public void writeByte(int code)
               throws CompileError
例外:
CompileError

writeUnsignedByte

public void writeUnsignedByte(int code)
                       throws CompileError
例外:
CompileError

writeShort

public void writeShort(int code)
                throws CompileError
例外:
CompileError

writeUnsignedShort

public void writeUnsignedShort(int code)
                        throws CompileError
例外:
CompileError

writeInt

public void writeInt(int code)
              throws CompileError
例外:
CompileError

insertEmpty

public void insertEmpty(int offset,
                        int size)
空領域を途中に挿入する.

パラメータ:
offset - 空領域を作り始める場所.
size - 空領域のバイト数.

appendEmpty

public int appendEmpty(int size)
空領域を確保して、確保する前のバイトコードのバイト数を返す.このコードバッファマネージャ のバイトコード数は引数の数値分増加する. 確保した後のバイトコードのバイト数を返さないのは、あらかじめ領域を確保してから、 バイトコードを書き込みたい場合があるためである.

パラメータ:
size - 空領域のバイト数.
戻り値:
確保する前のバイトコードのバイト数を返す.

requireToExtendCode

private void requireToExtendCode(int currentBytecodeSize)
もしコード領域が足りない場合は、確認して拡張する.


writeReturnBytecode

void writeReturnBytecode()
                   throws CompileError
例外:
CompileError

init

public void init()
定義:
インタフェース IntermediateLangManager 内の init