private static ConsList<Directive> CompleteIf(ConsList<Directive> stack, out bool include)
{
// if we get to the top, the default rule is to include anything that follows
if (!stack.Any())
{
include = true;
return stack;
}
// if we reach the #if directive, then we stop unwinding and start
// rebuilding the stack w/o the #if/#elif/#else/#endif directives
// only including content from sections that are considered included
if (stack.Head.Kind.IsIfLikeDirective())
{
include = stack.Head.BranchTaken;
return stack.Tail;
}
var newStack = CompleteIf(stack.Tail, out include);
switch (stack.Head.Kind)
{
case SyntaxKind.ElifDirectiveTrivia:
case SyntaxKind.ElseDirectiveTrivia:
include = stack.Head.BranchTaken;
break;
default:
if (include)
{
newStack = new ConsList<Directive>(stack.Head, newStack);
}
break;
}
return newStack;
}