private void CalcBranchOffsets(ArrayList actionRecord)
{
if (actionRecord.Count<1) return;
ArrayList jumpList = new ArrayList();
Hashtable labelPos = new Hashtable();
int pos = 0;
for (int i=0; i<actionRecord.Count; i++) {
BaseAction action = (BaseAction) actionRecord[i];
ActionLabel label = action as ActionLabel;
IJump jump = action as IJump;
if (label!=null) {
labelPos[label.LabelId] = pos;
}
if (jump!=null) {
jumpList.Add(new JumpPos(pos,jump));
}
// recursively step through function blocks
ActionDefineFunction f = actionRecord[i] as ActionDefineFunction;
if (f!=null) CalcBranchOffsets(f.ActionRecord);
ActionDefineFunction2 f2 = actionRecord[i] as ActionDefineFunction2;
if (f2!=null) CalcBranchOffsets(f2.ActionRecord);
pos+=action.ByteCount;
}
for (int i=0; i<jumpList.Count; i++) {
JumpPos j = (JumpPos) jumpList[i];
int offset = (int)labelPos[j.Jump.LabelId]-j.Position-5;
j.Jump.Offset = offset;
}
}