Beispiel #1
0
            public static MethodContract /*?*/ ExtractContracts(IContractAwareHost contractAwareHost, PdbReader /*?*/ pdbReader, ContractExtractor extractor, ISourceMethodBody methodBody)
            {
                var definingUnit = TypeHelper.GetDefiningUnit(methodBody.MethodDefinition.ContainingType.ResolvedType);
                var methodIsInReferenceAssembly = ContractHelper.IsContractReferenceAssembly(contractAwareHost, definingUnit);
                var oldAndResultExtractor       = new OldAndResultExtractor(contractAwareHost, methodBody, extractor.IsContractMethod);
                var localsInitializedWithFields = FindLocals.FindSetOfLocals(methodBody);

                var har = new HermansAlwaysRight(contractAwareHost, extractor, methodBody, methodIsInReferenceAssembly, oldAndResultExtractor, pdbReader);

                har.Rewrite(methodBody);

                if (har.extractor.currentMethodContract == null)
                {
                    return(null);
                }

                // The decompiler will have introduced locals if there were any anonymous delegates in the contracts
                // Such locals are initialized with the fields of the iterator class.
                // The contract that comes back from here will have those fields replaced with whatever the iterator captured
                // (parameters, locals). So the locals in the contract need to be replaced with the iterator fields so that
                // next replacement will see the right thing (i.e., the fields) and replace them! Phew!
                var localReplacer = new LocalReplacer(contractAwareHost, localsInitializedWithFields);

                localReplacer.Rewrite(har.extractor.currentMethodContract);
                // also need to rewrite the remainder of the body
                localReplacer.Rewrite(methodBody);

                return(har.extractor.currentMethodContract);
            }
Beispiel #2
0
 private HermansAlwaysRight(IContractAwareHost contractAwareHost, ContractExtractor extractor, ISourceMethodBody sourceMethodBody, bool methodIsInReferenceAssembly, OldAndResultExtractor oldAndResultExtractor, PdbReader /*?*/ pdbReader)
     : base(contractAwareHost)
 {
     this.contractAwareHost           = contractAwareHost;
     this.extractor                   = extractor;
     this.sourceMethodBody            = sourceMethodBody;
     this.methodIsInReferenceAssembly = methodIsInReferenceAssembly;
     this.oldAndResultExtractor       = oldAndResultExtractor;
     this.pdbReader                   = pdbReader;
 }
Beispiel #3
0
      public static MethodContract/*?*/ ExtractContracts(IContractAwareHost contractAwareHost, PdbReader/*?*/ pdbReader, ContractExtractor extractor, ISourceMethodBody methodBody) {
        var definingUnit = TypeHelper.GetDefiningUnit(methodBody.MethodDefinition.ContainingType.ResolvedType);
        var methodIsInReferenceAssembly = ContractHelper.IsContractReferenceAssembly(contractAwareHost, definingUnit);
        var oldAndResultExtractor = new OldAndResultExtractor(contractAwareHost, methodBody, extractor.IsContractMethod);
        var localsInitializedWithFields = FindLocals.FindSetOfLocals(methodBody);

        var har = new HermansAlwaysRight(contractAwareHost, extractor, methodBody, methodIsInReferenceAssembly, oldAndResultExtractor, pdbReader);
        har.Rewrite(methodBody);

        if (har.extractor.currentMethodContract == null) return null;

        // The decompiler will have introduced locals if there were any anonymous delegates in the contracts
        // Such locals are initialized with the fields of the iterator class.
        // The contract that comes back from here will have those fields replaced with whatever the iterator captured
        // (parameters, locals). So the locals in the contract need to be replaced with the iterator fields so that
        // next replacement will see the right thing (i.e., the fields) and replace them! Phew!
        var localReplacer = new LocalReplacer(contractAwareHost, localsInitializedWithFields);
        localReplacer.Rewrite(har.extractor.currentMethodContract);
        // also need to rewrite the remainder of the body
        localReplacer.Rewrite(methodBody);

        return har.extractor.currentMethodContract;
      }
Beispiel #4
0
 private HermansAlwaysRight(IContractAwareHost contractAwareHost, ContractExtractor extractor, ISourceMethodBody sourceMethodBody, bool methodIsInReferenceAssembly, OldAndResultExtractor oldAndResultExtractor, PdbReader/*?*/ pdbReader)
   : base(contractAwareHost)
 {
   this.contractAwareHost = contractAwareHost;
   this.extractor = extractor;
   this.sourceMethodBody = sourceMethodBody;
   this.methodIsInReferenceAssembly = methodIsInReferenceAssembly;
   this.oldAndResultExtractor = oldAndResultExtractor;
   this.pdbReader = pdbReader;
 }