/// <summary>
/// The main RegexCode generator. It does a depth-first walk
/// through the tree and calls EmitFragment to emits code before
/// and after each child of an interior node, and at each leaf.
/// </summary>
private void EmitFragment(int nodetype, RegexNode node, int curIndex)
{
int bits = 0;
if (nodetype <= RegexNode.Ref)
{
if (node.UseOptionR())
{
bits |= RegexCode.Rtl;
}
if ((node.Options & RegexOptions.IgnoreCase) != 0)
{
bits |= RegexCode.Ci;
}
}
switch (nodetype)
{
case RegexNode.Concatenate | BeforeChild:
case RegexNode.Concatenate | AfterChild:
case RegexNode.Empty:
break;
case RegexNode.Alternate | BeforeChild:
if (curIndex < node.Children !.Count - 1)
{
_intStack.Append(_emitted.Length);
Emit(RegexCode.Lazybranch, 0);
}
break;
case RegexNode.Alternate | AfterChild:
{
if (curIndex < node.Children !.Count - 1)
{
int LBPos = _intStack.Pop();
_intStack.Append(_emitted.Length);
Emit(RegexCode.Goto, 0);
PatchJump(LBPos, _emitted.Length);
}