/// <summary> /// Checks the methods of each machine and report warnings if /// any method is directly accessed by anything else than the /// P# runtime. /// </summary> private static void CheckMethods() { foreach (var classDecl in AnalysisContext.Machines) { SanityCheckingAnalysis.CheckForExternalAsynchronyUseInMachine(classDecl); foreach (var nestedClass in classDecl.ChildNodes().OfType <ClassDeclarationSyntax>()) { if (nestedClass.BaseList == null || !nestedClass.BaseList.Types.Any(t => t.ToString().Equals("MachineState"))) { ErrorReporter.ReportAndExit("Class '{0}' is not a state of the machine '{1}' " + "and, thus, is not allowed to be declared inside the machine body.", nestedClass.Identifier.ValueText, classDecl.Identifier.ValueText); } foreach (var method in nestedClass.ChildNodes().OfType <MethodDeclarationSyntax>()) { if (method.Modifiers.Any(SyntaxKind.AbstractKeyword)) { continue; } foreach (var stmt in method.Body.Statements) { SanityCheckingAnalysis.CheckStatement(stmt, method, classDecl, nestedClass); } } } foreach (var method in classDecl.ChildNodes().OfType <MethodDeclarationSyntax>()) { if (method.Modifiers.Any(SyntaxKind.AbstractKeyword)) { continue; } foreach (var stmt in method.Body.Statements) { SanityCheckingAnalysis.CheckStatement(stmt, method, classDecl); } } } }
/// <summary> /// Checks the fields of each machine and report warnings if /// any field is not private or protected. /// </summary> private void CheckFields() { foreach (var classDecl in AnalysisContext.Machines) { foreach (var field in classDecl.ChildNodes().OfType <FieldDeclarationSyntax>()) { if (field.Modifiers.Any(SyntaxKind.PublicKeyword)) { ErrorReporter.ReportAndExit("Field '{0}' of machine '{1}' is declared as " + "'public'.", field.Declaration.ToString(), classDecl.Identifier.ValueText); } else if (field.Modifiers.Any(SyntaxKind.InternalKeyword)) { ErrorReporter.ReportAndExit("Field '{0}' of machine '{1}' is declared as " + "'internal'.", field.Declaration.ToString(), classDecl.Identifier.ValueText); } } } }
/// <summary> /// Checks the methods of each machine and report warnings if /// any method is directly accessed by anything else than the /// P# runtime. /// </summary> private void CheckMethods() { foreach (var classDecl in AnalysisContext.Machines) { foreach (var method in classDecl.ChildNodes().OfType <MethodDeclarationSyntax>()) { if (method.Modifiers.Any(SyntaxKind.PublicKeyword)) { ErrorReporter.ReportAndExit("Method '{0}' of machine '{1}' is " + "declared as 'public'.", method.Identifier.ValueText, classDecl.Identifier.ValueText); } else if (method.Modifiers.Any(SyntaxKind.InternalKeyword)) { ErrorReporter.ReportAndExit("Method '{0}' of machine '{1}' is " + "declared as 'internal'.", method.Identifier.ValueText, classDecl.Identifier.ValueText); } } } }