// ControlFlowGraph/ControlFlowRegion private static void AppendProperty(this HierarchicalStringBuilder builder, string name, ControlFlowRegion region) { using (builder.AppendSection("{0}: Kind={1}", name, region.Kind)) { builder.AppendLine("Capture ids: {0}", region.CaptureIds.Join()); builder.AppendLine("Locals: {0}", region.Locals.Join()); builder.AppendLine("Local functions: {0}", region.LocalFunctions.Join()); foreach (var nestedRegion in region.NestedRegions) { builder.AppendProperty("Nested region", nestedRegion); } } }
private static void AppendObject(this HierarchicalStringBuilder builder, Diagnostic[] diagnostics) { foreach (var diagnostic in diagnostics) { if (diagnostic.Location.IsInSource) { var location = diagnostic.Location; builder.AppendLine("Diagnostic: {0}, {1} ({2} {3})", diagnostic.Id, diagnostic.GetMessage(), location.SourceTree.FilePath, location.SourceSpan); } else { builder.AppendLine("Diagnostic: {0}, {1}", diagnostic.Id, diagnostic.GetMessage()); } } }
// ControlFlowAnalysis public static string GetDisplayString(BlockSyntax syntax, ControlFlowAnalysis analysis) { var builder = new HierarchicalStringBuilder(); using (builder.AppendTitle("Control flow analysis: {0}", syntax.Parent !.Kind())) { builder.AppendLine("Start point is reachable: {0}", analysis.StartPointIsReachable); builder.AppendLine("End point is reachable: {0}", analysis.EndPointIsReachable); builder.AppendLine("Entry points: {0}", analysis.EntryPoints.Join()); builder.AppendLine("Exit points: {0}", analysis.ExitPoints.Join()); builder.AppendLine("Return statements: {0}", analysis.ReturnStatements.Join()); } return(builder.ToString()); }
private static void AppendObject(this HierarchicalStringBuilder builder, GeneratedSourceResult[] sources) { foreach (var source in sources) { builder.AppendLine("Source: {0}", source.HintName).AppendText(source.SourceText); } }
private static void AppendObject(this HierarchicalStringBuilder builder, Exception?exception) { if (exception != null) { builder.AppendLine("Exception: {0}", exception); } }
private static void AppendObject(this HierarchicalStringBuilder builder, DiagnosticAnalyzer[] analyzers) { foreach (var analyzer in analyzers) { builder.AppendLine("Analyzer: {0}", analyzer.GetType().Name); } }
// ControlFlowGraph/Operation private static void AppendProperty(this HierarchicalStringBuilder builder, string name, IOperation?operation) { if (operation == null) { return; } builder.AppendLine("{0}: Kind={1}", name, operation.Kind).AppendText(operation.Syntax); }
// ControlFlowGraph/ControlFlowBranch private static void AppendProperty(this HierarchicalStringBuilder builder, string name, ControlFlowBranch?branch) { if (branch == null) { return; } builder.AppendLine("{0}: Semantics={1}, Destination={2}", name, branch.Semantics, branch.Destination?.Ordinal); }
// Generation public static string GetMessage(ISourceGenerator generator, Compilation compilation, GeneratedSourceResult[] sources, Diagnostic[] diagnostics, Exception?exception) { var builder = new HierarchicalStringBuilder(); using (builder.AppendTitle("Generation result:")) { builder.AppendLine("Generator: {0}", generator.GetType().Name); builder.AppendObject(compilation); builder.AppendObject(diagnostics); builder.AppendObject(exception); builder.AppendObject(sources); } return(builder.ToString()); }
// Helpers/AppendObject private static void AppendObject(this HierarchicalStringBuilder builder, Compilation compilation) { builder.AppendLine("Compilation: {0} ({1})", compilation.AssemblyName, compilation.SyntaxTrees.Join(i => Path.GetFileName(i.FilePath))); }
// DataFlowAnalysis public static string GetDisplayString(BlockSyntax syntax, DataFlowAnalysis analysis) { var builder = new HierarchicalStringBuilder(); using (builder.AppendTitle("Data flow analysis: {0}", syntax.Parent !.Kind())) { builder.AppendLine("Definitely assigned (On entry): {0}", analysis.DefinitelyAssignedOnEntry.Join()); builder.AppendLine("Definitely assigned (On exit): {0}", analysis.DefinitelyAssignedOnExit.Join()); builder.AppendLine("Declared (Inside): {0}", analysis.VariablesDeclared.Join()); builder.AppendLine("Always assigned (Inside): {0}", analysis.AlwaysAssigned.Join()); builder.AppendLine("Written (Outside): {0}", analysis.WrittenOutside.Join()); builder.AppendLine("Read (Outside): {0}", analysis.ReadOutside.Join()); builder.AppendLine("Written (Inside): {0}", analysis.WrittenInside.Join()); builder.AppendLine("Read (Inside): {0}", analysis.ReadInside.Join()); builder.AppendLine("Data flows (In): {0}", analysis.DataFlowsIn.Join()); builder.AppendLine("Data flows (Out): {0}", analysis.DataFlowsOut.Join()); builder.AppendLine("Captured: {0}", analysis.Captured.Join()); builder.AppendLine("Captured (Inside): {0}", analysis.CapturedInside.Join()); builder.AppendLine("Captured (Outside): {0}", analysis.CapturedOutside.Join()); builder.AppendLine("Unsafe address taken: {0}", analysis.UnsafeAddressTaken.Join()); builder.AppendLine("Used local functions: {0}", analysis.UsedLocalFunctions.Join()); } return(builder.ToString()); }