Ejemplo n.º 1
0
        private void BuildPreprocessorStateChangeMap()
        {
            DirectiveStack currentState = DirectiveStack.Empty;
            var            positions    = ArrayBuilder <int> .GetInstance();

            var states = ArrayBuilder <DirectiveStack> .GetInstance();

            foreach (IDirectiveTriviaSyntax directive in this.GetRootNode().
                     GetDirectives(d =>
            {
                switch (((IDirectiveTriviaSyntax)d).Directive.Kind)
                {
                case DirectiveKind.If:
                case DirectiveKind.Elif:
                case DirectiveKind.Else:
                case DirectiveKind.EndIf:
                case DirectiveKind.Define:
                case DirectiveKind.Undef:
                    return(true);

                default:
                    return(false);
                }
            }))
            {
                currentState = currentState.Add(directive.Directive);
                int position = ((SyntaxNode)directive).SpanStart;
                switch (directive.Directive.Kind)
                {
                case DirectiveKind.If:
                    // #if directive doesn't affect the set of defined/undefined symbols
                    break;

                case DirectiveKind.Elif:
                case DirectiveKind.Else:
                case DirectiveKind.EndIf:
                case DirectiveKind.Define:
                case DirectiveKind.Undef:
                    states.Add(currentState);
                    positions.Add(position);
                    break;

                default:
                    throw ExceptionUtilities.UnexpectedValue(directive.Directive.Kind);
                }
            }

#if DEBUG
            int currentPos = -1;
            foreach (int pos in positions)
            {
                Debug.Assert(currentPos < pos);
                currentPos = pos;
            }
#endif

            ImmutableInterlocked.InterlockedInitialize(ref _preprocessorStates, states.ToImmutableAndFree());
            ImmutableInterlocked.InterlockedInitialize(ref _preprocessorStateChangePositions, positions.ToImmutableAndFree());
        }
Ejemplo n.º 2
0
 internal override DirectiveStack ApplyDirectives(DirectiveStack stack)
 {
     return(stack.Add(new Directive(this)));
 }