Exemple #1
0
 private void Init(){
   ErrorNodeList tempErrors = new ErrorNodeList();
   ErrorHandler tempErrorHandler = new ErrorHandler(tempErrors);
   tempTypeSystem = new TypeSystem(tempErrorHandler);
   // Here we ignore the errors generated by this temporary checker on purpose!
   tempChecker = new Checker(tempErrorHandler, tempTypeSystem, null, null, null);
   if (errorHandler == null) {
     errors = new ErrorNodeList();
     errorHandler = new ErrorHandler(errors);
   }
 }
      private static void KaelsArchitecture(AssemblyNode assemblyNode) {

    // Finish decompiling expressions where CCI left off.
        new Abnormalizer().Visit(assemblyNode);
        

    // Check and extract all inline foxtrot contracts and place them in the object model.
        Checker checker = new Checker(new ContractNodes(assemblyNode));
        bool errorFound = false;
        checker.ErrorFound += delegate(System.CodeDom.Compiler.CompilerError error) {
          if (!error.IsWarning || warningLevel > 0) {
            Console.WriteLine(error.ToString());
          }
          errorFound |= !error.IsWarning;
        };
        checker.Visit(assemblyNode);
        if (errorFound)
          return;
        

        if (verify) {
          throw new NotImplementedException("Static verification is not yet implemented.");
        }

    // Write out the assembly, possibly injecting the runtime checks
        if (rewrite || passthrough) {
          // Reload the assembly to flush out the abnormalized contracts since the rewriter can't handle them yet.
          assemblyNode = LoadAssembly();

          if (!passthrough) {
            // Rewrite the assembly in memory.
            Rewriter rewriter = new Rewriter(new ContractNodes(assemblyNode));
            rewriter.InlinePreconditions = false;
            rewriter.InlinePostconditions = false;
            rewriter.InlineInvariant = false;
            rewriter.Verbose = verbose;
            rewriter.Decompile = decompile;
            rewriter.Visit(assemblyNode);
          }

          if (output == "same") {
            // Save the rewritten assembly to a temporary location.
            output = Path.Combine(Path.GetTempPath(), Path.GetFileName(assembly));

            // Re-attach external file resources to the new output assembly.
            MoveModuleResources(assemblyNode, output);

            // Save the rewritten assembly.
            assemblyNode.WriteModule(output, debug);

            // Make a copy of the original assembly and PDB.
            File.Delete(assembly + ".original");
            File.Delete(Path.ChangeExtension(assembly, ".pdb") + ".original");
            File.Move(assembly, assembly + ".original");
            File.Move(Path.ChangeExtension(assembly, ".pdb"), Path.ChangeExtension(assembly, ".pdb") + ".original");

            // Move the rewritten assembly and PDB to the original location.
            File.Move(output, assembly);
            File.Move(Path.ChangeExtension(output, ".pdb"), Path.ChangeExtension(assembly, ".pdb"));
          } else {
            // Re-attach external file resources to the new output assembly.
            MoveModuleResources(assemblyNode, output);

            // Save the rewritten assembly.
            assemblyNode.WriteModule(output, debug);
          }
        }
      }
 public AdmissibilityChecker(System.Compiler.Checker callingChecker)
   : base(callingChecker) {
   this.ErrorHandler = (ErrorHandler)callingChecker.ErrorHandler;
   this.checker = callingChecker;
 }