示例#1
0
        /// <summary>
        /// Resolves and type checks the given Boogie program.  Any errors are reported to the
        /// console.  Returns:
        ///  - Done if no errors occurred, and command line specified no resolution or no type checking.
        ///  - ResolutionError if a resolution error occurred
        ///  - TypeCheckingError if a type checking error occurred
        ///  - ResolvedAndTypeChecked if both resolution and type checking succeeded
        /// </summary>
        public static PipelineOutcome ResolveAndTypecheck(Program program, string bplFileName, out LinearTypeChecker linearTypeChecker, out CivlTypeChecker civlTypeChecker)
        {
            Contract.Requires(program != null);
              Contract.Requires(bplFileName != null);

              linearTypeChecker = null;
              civlTypeChecker = null;

              // ---------- Resolve ------------------------------------------------------------

              if (CommandLineOptions.Clo.NoResolve)
              {
            return PipelineOutcome.Done;
              }

              int errorCount = program.Resolve();
              if (errorCount != 0)
              {
            Console.WriteLine("{0} name resolution errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.ResolutionError;
              }

              // ---------- Type check ------------------------------------------------------------

              if (CommandLineOptions.Clo.NoTypecheck)
              {
            return PipelineOutcome.Done;
              }

              errorCount = program.Typecheck();
              if (errorCount != 0)
              {
            Console.WriteLine("{0} type checking errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.TypeCheckingError;
              }

              if (PolymorphismChecker.IsMonomorphic(program))
              {
              CommandLineOptions.Clo.TypeEncodingMethod = CommandLineOptions.TypeEncoding.Monomorphic;
              }

              CollectModSets(program);

              civlTypeChecker = new CivlTypeChecker(program);
              civlTypeChecker.TypeCheck();
              if (civlTypeChecker.errorCount != 0)
              {
              Console.WriteLine("{0} type checking errors detected in {1}", civlTypeChecker.errorCount, GetFileNameForConsole(bplFileName));
              return PipelineOutcome.TypeCheckingError;
              }

              linearTypeChecker = new LinearTypeChecker(program);
              linearTypeChecker.TypeCheck();
              if (linearTypeChecker.errorCount == 0)
              {
            linearTypeChecker.Transform();
              }
              else
              {
            Console.WriteLine("{0} type checking errors detected in {1}", linearTypeChecker.errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.TypeCheckingError;
              }

              if (CommandLineOptions.Clo.PrintFile != null && CommandLineOptions.Clo.PrintDesugarings)
              {
            // if PrintDesugaring option is engaged, print the file here, after resolution and type checking
            PrintBplFile(CommandLineOptions.Clo.PrintFile, program, true, true, CommandLineOptions.Clo.PrettyPrint);
              }

              return PipelineOutcome.ResolvedAndTypeChecked;
        }