coins.casttohir
Class SideEffectBuffer

java.lang.Object
  extended bycoins.casttohir.SideEffectBuffer

public class SideEffectBuffer
extends java.lang.Object

SideEffectBuffer Hold side effect statements and process them (move, insert, etc.).
Side effect statement: statement that leave side effect (assign statement, call statement, etc.).
Sequence point: program point where side effect should be completed at the latest.
Swept out statement: statement moved forward or backward to perform side effect at proper point as defined by the grammar.
Sweep out backward: move a side effect statement in front of the current statement.
Sweep out forward: move a side effect statement to some position succeeding the current statement.


Constructor Summary
(package private) SideEffectBuffer(ToHir tohir)
          SideEffectBuffer Constructor.
 
Method Summary
(package private)  void add(SideEffectBuffer child)
          add Connect the statement lists of the child with the statement lists of this SideEffectBuffer, and clear the statement lists of the child.
(package private)  SideEffectBuffer addNext(HIR s)
          addNext Add statement to the list of statements to be swept forward.
(package private)  void addNext(SideEffectBuffer child)
          addNext Connect the statement lists of the child with the nextList of this SideEffectBuffer, and clear the statement lists of the child.
(package private)  SideEffectBuffer addPrev(HIR s)
          addPrev Add statement to the list of statements to be swept backward.
(package private)  void addPrev(SideEffectBuffer child)
          addPrev Connect the statement lists of the child with the prevList of this SideEffectBuffer, and clear the statement lists of the child.
(package private)  void addToBlockFirst(Stmt s, boolean reserve)
          addToBlockLast Add swept forward statements (in nextList) as the last statement of the block which is either parameter s or a block generated to surround s.
(package private)  void addToBlockLast(Stmt s, boolean reserve)
          addToBlockLast Add swept backward statements (in prevList) as the last statement of the block which is either parameter s or a block generated to surround s.
(package private)  void addToStmtNext(Stmt s, boolean reserve)
          addToStmtNext Insert the statements swept forward (nextList elements) at the position next to the statement s.
(package private)  void addToStmtPrev(Stmt s, boolean reserve)
          addToStmtPrev Insert the statements swept backward (prevList elements) in front of the statement s.
(package private)  BlockStmt getBlockStmt(Stmt s)
          getBlockStmt From parameter s, make a block statement in which swept out statements can be inserted.
(package private)  boolean isEmpty()
          isEmpty
(package private)  boolean isEmptyNext()
          isEmptyNext
(package private)  boolean isEmptyPrev()
          isEmptyPrev
(package private)  void moveNextToPrev()
          moveNextToPrev Move the swept forward statements to the list of swept backward statements by moving statements in nextList to prevList.
(package private)  Exp toExp(Exp e)
          toExp Change the list of swept backward expressions to an expression by successively changing expressions in prevList to comma expression and appending parameter e as value expression of the comma expression.
(package private)  Stmt toStmt()
          toStmt Change the swept out statement list to a statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SideEffectBuffer

SideEffectBuffer(ToHir tohir)
SideEffectBuffer Constructor.

Parameters:
tohir - Offers cooperation with the object of other packages.
Method Detail

isEmpty

boolean isEmpty()
isEmpty

Returns:
True if there is no statements swept out.

isEmptyPrev

boolean isEmptyPrev()
isEmptyPrev

Returns:
True if there is no statement swept backward.

isEmptyNext

boolean isEmptyNext()
isEmptyNext

Returns:
True if there is no statement swept forward.

addPrev

SideEffectBuffer addPrev(HIR s)
addPrev Add statement to the list of statements to be swept backward.

Parameters:
s - Added statement.
Returns:
This SideEffectBuffer.

addNext

SideEffectBuffer addNext(HIR s)
addNext Add statement to the list of statements to be swept forward.

Parameters:
s - Added statement.
Returns:
This SideEffectBuffer.

add

void add(SideEffectBuffer child)
add Connect the statement lists of the child with the statement lists of this SideEffectBuffer, and clear the statement lists of the child.

Parameters:
child - The child SideEffectBuffer.

addPrev

void addPrev(SideEffectBuffer child)
addPrev Connect the statement lists of the child with the prevList of this SideEffectBuffer, and clear the statement lists of the child.

Parameters:
child - The child SideEffectBuffer.

addNext

void addNext(SideEffectBuffer child)
addNext Connect the statement lists of the child with the nextList of this SideEffectBuffer, and clear the statement lists of the child.

Parameters:
child - The child SideEffectBuffer.

moveNextToPrev

void moveNextToPrev()
moveNextToPrev Move the swept forward statements to the list of swept backward statements by moving statements in nextList to prevList.


toStmt

Stmt toStmt()
toStmt Change the swept out statement list to a statement. If there is only one statement swept out, then return it. If there are multiple statements, the make a block statement where statements in prevList are arranged first and then statements in nextList are arranged next.

Returns:
The resultant statement.

toExp

Exp toExp(Exp e)
toExp Change the list of swept backward expressions to an expression by successively changing expressions in prevList to comma expression and appending parameter e as value expression of the comma expression.

Parameters:
e - The second operand of the most outside comma expression.
Returns:
The resultant expression.

addToStmtPrev

final void addToStmtPrev(Stmt s,
                         boolean reserve)
addToStmtPrev Insert the statements swept backward (prevList elements) in front of the statement s. If a prevList element is an expression, then change it to ExpStmt and insert it.

Parameters:
s - Statement showing the position of insertion.
reserve - True if the inserted statements are to be left.

addToStmtNext

final void addToStmtNext(Stmt s,
                         boolean reserve)
addToStmtNext Insert the statements swept forward (nextList elements) at the position next to the statement s. If a nextList element is an expression, then change it to ExpStmt and insert it.

Parameters:
s - Statement showing the position of insertion.
reserve - True if the inserted statements are to be left.

addToBlockLast

final void addToBlockLast(Stmt s,
                          boolean reserve)
addToBlockLast Add swept backward statements (in prevList) as the last statement of the block which is either parameter s or a block generated to surround s.

Parameters:
s - Statement showing the candidate of insertion.
reserve - True if the inserted statements are to be left.

addToBlockFirst

final void addToBlockFirst(Stmt s,
                           boolean reserve)
addToBlockLast Add swept forward statements (in nextList) as the last statement of the block which is either parameter s or a block generated to surround s.

Parameters:
s - Statement showing the candidate of insertion.
reserve - True if the inserted statements are to be left.

getBlockStmt

BlockStmt getBlockStmt(Stmt s)
getBlockStmt From parameter s, make a block statement in which swept out statements can be inserted.
 0)  (BlockStmt )      =>  (BlockStmt )  --> return

 1)  (LabeledStmt          (LabeledStmt
       (BlockStmt      =>    (BlockStmt  --> return

 2)  (LabeledStmt          (LabeledStmt
       (xxxStmt ))     =>    (BlockStmt  --> return
                               (xxxStmt )))

 3)  (xxxStmt )        =>  (BlockStmt  --> return
                             (xxxStmt ))
 

Parameters:
s - Statement showing the candidate of insertion point.
Returns:
Resultant block statement.