protected static void GatherDiagnostics( SyntaxElement root, List <Diagnostic> diagnostics, DiagnosticsInclude include, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); bool includeSyntax = (include & DiagnosticsInclude.Syntactic) != 0; bool includeSemantic = (include & DiagnosticsInclude.Semantic) != 0; bool includeExpansion = (include & DiagnosticsInclude.Expansion) != 0; var fnDescend = (include == DiagnosticsInclude.Syntactic) ? (Func <SyntaxElement, bool>)((SyntaxElement e) => e.ContainsSyntaxDiagnostics) : null; SyntaxElement.Walk(root, fnBefore: element => { if (element.HasSyntaxDiagnostics && includeSyntax) { // each syntax diagnostic is located at the element that carries it. diagnostics.AddRange(element.SyntaxDiagnostics.Select(d => d.HasLocation ? d : SetLocation(d, element))); } if (includeSemantic && element is SyntaxNode node && node.SemanticDiagnostics.Count > 0) { diagnostics.AddRange(node.SemanticDiagnostics); } },
internal void InitializeTriviaStarts() { SyntaxElement.Walk( this.Root, fnBefore: element => { System.Diagnostics.Debug.Assert(element.Parent == null || element.Parent._triviaStart >= 0); element._triviaStart = (element.Parent?._triviaStart ?? 0) + element.OffsetInParent; }); }
/// <summary> /// Walks the entire syntax tree and evaluates the maximum depth of all the nodes. /// </summary> private static int ComputeMaxDepth(SyntaxElement root) { var maxDepth = 0; var depth = 0; SyntaxElement.Walk( root, fnBefore: e => { depth++; if (depth > maxDepth) { maxDepth = depth; } }, fnAfter: e => depth--); return(maxDepth); }