/// <summary> /// Performs custom rewriting. /// </summary> private void PerformCustomRewriting() { Queue <Type> rewritingPasses = new Queue <Type>(); Dictionary <Type, List <Type> > passDependencies = new Dictionary <Type, List <Type> >(); HashSet <Queue <Type> > snapshot = new HashSet <Queue <Type> >(); foreach (var assembly in base.Project.CompilationContext.CustomCompilerPassAssemblies) { foreach (var pass in this.FindCustomRewritingPasses(assembly, typeof(CustomCSharpRewritingPass))) { rewritingPasses.Enqueue(pass); passDependencies.Add(pass, this.FindDependenciesOfPass(pass)); } } while (rewritingPasses.Count > 0) { Type nextPass = rewritingPasses.Dequeue(); bool allDependenciesDone = true; foreach (var dependency in passDependencies[nextPass]) { if (rewritingPasses.Contains(dependency)) { allDependenciesDone = false; break; } } if (!allDependenciesDone) { rewritingPasses.Enqueue(nextPass); if (snapshot.Any(item => item.SequenceEqual(rewritingPasses))) { Error.ReportAndExit("Possible cycle in the rewriting " + "pass dependencies, or dependency missing."); } snapshot.Add(rewritingPasses); continue; } CSharpRewriter rewriter = null; try { rewriter = Activator.CreateInstance(nextPass, this) as CSharpRewriter; } catch (MissingMethodException) { Error.ReportAndExit($"Public constructor of {nextPass} not found."); } rewriter.Rewrite(); } }
public async Task <ImmutableArray <Diagnostic> > EvaluateAsync(Document target) { var rewriter = new CSharpRewriter( fixIssues: false, comparer: _sortSystemFirst ? UsingsAndExternAliasesDirectiveComparer.SystemFirstInstance : UsingsAndExternAliasesDirectiveComparer.NormalInstance); rewriter.Visit(await target.GetSyntaxRootAsync()); return(rewriter.Diagnostics); }