コード例 #1
0
        /// <summary>
        /// Analyzes the given P# project.
        /// </summary>
        /// <param name="project">Project</param>
        private void AnalyzeProject(Project project)
        {
            // Starts profiling the analysis.
            if (this.CompilationContext.Configuration.EnableProfiling)
            {
                this.Profiler.StartMeasuringExecutionTime();
            }

            // Create a state-machine static analysis context.
            var context = AnalysisContext.Create(project);

            this.PerformErrorChecking(context);

            this.RegisterImmutableTypes(context);
            this.RegisterGivesUpOwnershipOperations(context);

            // Creates and runs an analysis pass that computes the
            // summaries for every P# machine.
            ISet <StateMachine> machines = new HashSet <StateMachine>();

            try
            {
                // Creates summaries for each machine, which can be used for subsequent
                // analyses. Optionally performs data-flow analysis.
                MachineSummarizationPass.Create(context, this.CompilationContext.Configuration).
                Run(machines);

                // Creates and runs an analysis pass that detects if a machine contains
                // states that are declared as generic. This is not allowed by P#.
                NoGenericStatesAnalysisPass.Create(context, this.CompilationContext.Configuration).
                Run(machines);

                // Creates and runs an analysis pass that finds if a machine exposes
                // any fields or methods to other machines.
                DirectAccessAnalysisPass.Create(context, this.CompilationContext.Configuration).
                Run(machines);

                if (this.CompilationContext.Configuration.AnalyzeDataRaces)
                {
                    // Creates and runs an analysis pass that detects if any method
                    // in each machine is erroneously giving up ownership.
                    GivesUpOwnershipAnalysisPass.Create(context, this.CompilationContext.Configuration).
                    Run(machines);

                    // Creates and runs an analysis pass that detects if all methods
                    // in each machine respect given up ownerships.
                    RespectsOwnershipAnalysisPass.Create(context, this.CompilationContext.Configuration).
                    Run(machines);
                }
            }
            catch (Exception ex)
            {
                if (this.CompilationContext.Configuration.ThrowInternalExceptions)
                {
                    throw ex;
                }

                IO.PrintLine($"... Failed to analyze project '{project.Name}'");
                IO.Debug(ex.ToString());
            }

            // Stops profiling the analysis.
            if (this.CompilationContext.Configuration.EnableProfiling)
            {
                this.Profiler.StopMeasuringExecutionTime();
                IO.PrintLine("... Total static analysis runtime: '" +
                             this.Profiler.Results() + "' seconds.");
            }
        }