/// <summary> /// Summarizes the state-machines in the project. /// </summary> /// <param name="machines">StateMachines</param> private void SummarizeStateMachines(ISet <StateMachine> machines) { // Iterate the syntax trees for each project file. foreach (var tree in base.AnalysisContext.Compilation.SyntaxTrees) { // Get the tree's semantic model. var model = base.AnalysisContext.Compilation.GetSemanticModel(tree); // Get the tree's root node compilation unit. var root = (CompilationUnitSyntax)tree.GetRoot(); // Iterate the class declerations only if they are machines. foreach (var classDecl in root.DescendantNodes().OfType <ClassDeclarationSyntax>()) { if (Querying.IsMachine(base.AnalysisContext.Compilation, classDecl)) { StateMachine stateMachine = new StateMachine(classDecl, base.AnalysisContext); if (this.Configuration.AnalyzeDataFlow) { stateMachine.Summarize(); } machines.Add(stateMachine); } } } }
/// <summary> /// Finds all P# machines in the project. /// </summary> private static void FindAllMachines() { // Iterate the syntax trees for each project file. foreach (var tree in AnalysisContext.Compilation.SyntaxTrees) { if (!AnalysisContext.IsProgramSyntaxTree(tree)) { continue; } // Get the tree's semantic model. var model = AnalysisContext.Compilation.GetSemanticModel(tree); // Get the tree's root node compilation unit. var root = (CompilationUnitSyntax)tree.GetRoot(); // Iterate the class declerations only if they are machines. foreach (var classDecl in root.DescendantNodes().OfType <ClassDeclarationSyntax>()) { if (Querying.IsMachine(AnalysisContext.Compilation, classDecl)) { AnalysisContext.Machines.Add(classDecl); } } } }
/// <summary> /// Returns true if the given class declaration is a machine. /// </summary> protected override bool IsMachine(CodeAnalysis.Compilation compilation, ClassDeclarationSyntax classDecl) => Querying.IsMachine(compilation, classDecl);