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()); }
private static DirectiveStack ApplyDirectivesToTrivia(GreenNode triviaList, DirectiveStack stack) { if (triviaList != null && triviaList.ContainsDirectives) { return(ApplyDirectivesToListOrNode(triviaList, stack)); } return(stack); }
internal override DirectiveStack ApplyDirectives(DirectiveStack stack) { if (this.ContainsDirectives) { stack = ApplyDirectivesToTrivia(this.GetLeadingTrivia(), stack); stack = ApplyDirectivesToTrivia(this.GetTrailingTrivia(), stack); } return(stack); }
internal virtual DirectiveStack ApplyDirectives(DirectiveStack stack) { if (ContainsDirectives) { foreach (var childNode in ChildNodes) { if (childNode != null) { stack = ((SyntaxNode)childNode).ApplyDirectives(stack); } } } return(stack); }
private bool IsPreprocessorSymbolDefined(DirectiveStack directives, string symbolName) { switch (directives.IsDefined(symbolName)) { case DefineState.Defined: return(true); case DefineState.Undefined: return(false); default: return(((LanguageParseOptions)this.Options).PreprocessorSymbols.Contains(symbolName)); } }
internal static DirectiveStack ApplyDirectives(GreenNode node, DirectiveStack stack) { if (node.ContainsDirectives) { for (int i = 0, n = node.SlotCount; i < n; i++) { var child = node.GetSlot(i); if (child != null) { stack = ApplyDirectivesToListOrNode(child, stack); } } } return(stack); }
internal override DirectiveStack ApplyDirectives(DirectiveStack stack) { if (ContainsDirectives) { foreach (var trivia in LeadingTrivia.Where(x => x.ContainsDirectives)) { stack = trivia.ApplyDirectives(stack); } foreach (var trivia in TrailingTrivia.Where(x => x.ContainsDirectives)) { stack = trivia.ApplyDirectives(stack); } } return(stack); }
internal ParsedSyntaxTree(SourceText textOpt, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm, string path, MetaParseOptions options, MetaSyntaxNode root, DirectiveStack directives, bool cloneRoot = true) { Debug.Assert(root != null); Debug.Assert(options != null); Debug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm); _lazyText = textOpt; _encodingOpt = encodingOpt ?? textOpt?.Encoding; _checksumAlgorithm = checksumAlgorithm; _options = options; _path = path ?? string.Empty; _root = cloneRoot ? this.CloneNodeAsRoot(root) : root; _hasCompilationUnitRoot = root.Kind == MetaSyntaxKind.Main; this.SetDirectiveStack(directives); }
internal override DirectiveStack ApplyDirectives(DirectiveStack stack) { return(stack.Add(new Directive(this))); }
internal ParsedSyntaxTree(SourceText textOpt, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm, string path, SoalParseOptions options, SoalSyntaxNode root, DirectiveStack directives, bool cloneRoot = true) { Debug.Assert(root != null); Debug.Assert(options != null); Debug.Assert(path != null); Debug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm); _lazyText = textOpt; _encodingOpt = encodingOpt ?? textOpt?.Encoding; _checksumAlgorithm = checksumAlgorithm; _options = options; _path = path; _root = cloneRoot ? new MainSyntax((InternalSyntaxNode)root.Green, this, 0) : root; _hasCompilationUnitRoot = root.Kind == SoalSyntaxKind.Main; this.SetDirectiveStack(directives); }
protected void SetDirectiveStack(DirectiveStack directives) { _directives = directives; _hasDirectives = true; }
internal static DirectiveStack ApplyDirectivesToListOrNode(GreenNode listOrNode, DirectiveStack stack) { // If we have a list of trivia, then that node is not actually a CSharpSyntaxNode. // Just defer to our standard ApplyDirectives helper as it will do the appropriate // walking of this list to ApplyDirectives to the children. if (listOrNode.RawKind == GreenNode.ListKind) { return(ApplyDirectives(listOrNode, stack)); } else { // Otherwise, we must have an actual piece of C# trivia. Just apply the stack // to that node directly. return(((InternalSyntaxNode)listOrNode).ApplyDirectives(stack)); } }
internal virtual DirectiveStack ApplyDirectives(DirectiveStack stack) { return(ApplyDirectives(this, stack)); }
internal static DirectiveStack ApplyDirectives(this SyntaxNodeOrToken nodeOrToken, DirectiveStack stack) { if (nodeOrToken.IsToken) { return(nodeOrToken.AsToken().ApplyDirectives(stack)); } if (nodeOrToken.IsNode) { return(nodeOrToken.AsNode().ApplyDirectives(stack)); } return(stack); }
internal static DirectiveStack ApplyDirectives(this SyntaxToken token, DirectiveStack stack) { return(((Syntax.InternalSyntax.InternalSyntaxNode)token.Node).ApplyDirectives(stack)); }
internal static DirectiveStack ApplyDirectives(this SyntaxNode node, DirectiveStack stack) { return(((Syntax.InternalSyntax.InternalSyntaxNode)node.Green).ApplyDirectives(stack)); }