in compiler/src/main/java/org/apache/royale/abc/instructionlist/InstructionList.java [417:657]
public void addAll(InstructionList src_list)
{
checkValidity();
src_list.checkValidity();
// Inherit active labels from the other list, and
// adjust their positions relative to this list.
if (src_list.activeLabels != null)
{
if (!isEmpty())
{
for (Label l : src_list.activeLabels)
{
l.adjustOffset(size());
}
}
getActiveLabels().addAll(src_list.activeLabels);
}
if (!src_list.isEmpty())
{
// If the new instruction sequence contains any executable instructions,
// resolve this list's pending labels to the position of the first new
// executable instruction in the merged list.
int firstExecutableOffset = src_list.firstExecutableOffset();
if (firstExecutableOffset != NO_EXECUTABLE_INSTRUCTIONS)
resolvePendingLabels(size() + firstExecutableOffset);
// This state machine copies src_list's fixed or variable
// storage into this list with as few calls to getInstructions()
// as feasible, since getInstructions() always converts this
// list to relatively expensive variable-length storage.
StorageState this_state = getStorageState();
StorageState src_state = src_list.getStorageState();
switch (this_state)
{
case Empty:
{
switch (src_state)
{
case Empty:
{
break;
}
case Ins1:
case Ins2:
case Ins3:
{
insn1 = src_list.insn1;
insn2 = src_list.insn2;
insn3 = src_list.insn3;
break;
}
case Variable:
{
// Note: shared src_list objects will
// clone their leafInstructions list.
leafInstructions = src_list.leafInstructions;
break;
}
default:
{
assert false : "Unknown storage state " + src_state;
}
}
break;
}
case Ins1:
{
switch (src_state)
{
case Empty:
{
break;
}
case Ins1:
case Ins2:
{
insn2 = src_list.insn1;
insn3 = src_list.insn2;
break;
}
case Ins3:
{
getInstructions().add(src_list.insn1);
getInstructions().add(src_list.insn2);
getInstructions().add(src_list.insn3);
break;
}
case Variable:
{
getInstructions().addAll(src_list.getInstructions());
break;
}
default:
{
assert (false) : "Unknown storage state " + src_state;
}
}
break;
}
case Ins2:
{
switch (src_state)
{
case Empty:
{
break;
}
case Ins1:
{
insn3 = src_list.insn1;
break;
}
case Ins2:
{
getInstructions().add(src_list.insn1);
getInstructions().add(src_list.insn2);
break;
}
case Ins3:
{
getInstructions().add(src_list.insn1);
getInstructions().add(src_list.insn2);
getInstructions().add(src_list.insn3);
break;
}
case Variable:
{
getInstructions().addAll(src_list.getInstructions());
break;
}
default:
{
assert (false) : "Unknown storage state " + src_state;
}
}
break;
}
case Ins3:
{
switch (src_state)
{
case Empty:
{
break;
}
case Ins1:
{
getInstructions().add(src_list.insn1);
break;
}
case Ins2:
{
getInstructions().add(src_list.insn1);
getInstructions().add(src_list.insn2);
break;
}
case Ins3:
{
getInstructions().add(src_list.insn1);
getInstructions().add(src_list.insn2);
getInstructions().add(src_list.insn3);
break;
}
case Variable:
{
getInstructions().addAll(src_list.getInstructions());
break;
}
default:
{
assert (false) : "Unknown storage state " + src_state;
}
}
break;
}
case Variable:
{
switch (src_state)
{
case Empty:
{
break;
}
case Ins1:
{
leafInstructions.add(src_list.insn1);
break;
}
case Ins2:
{
leafInstructions.add(src_list.insn1);
leafInstructions.add(src_list.insn2);
break;
}
case Ins3:
{
leafInstructions.add(src_list.insn1);
leafInstructions.add(src_list.insn2);
leafInstructions.add(src_list.insn3);
break;
}
case Variable:
{
leafInstructions.addAll(src_list.getInstructions());
break;
}
default:
{
assert (false) : "Unknown storage state " + src_state;
}
}
break;
}
default:
{
assert false : "Unknown storage state " + this_state;
}
}
}
// Inherit any pending labels from the other list.
if (src_list.pendingLabels != null)
{
if (pendingLabels == null)
pendingLabels = new ArrayList<Label>();
pendingLabels.addAll(src_list.pendingLabels);
}
// Invalidate the source list.
src_list.isValid = false;
}