An object that associates contracts, such as preconditions and postconditions, with methods, types and loops.
Inheritance: IContractProvider
示例#1
0
 public NonNullInjector(
     IMetadataHost host,
     Microsoft.Cci.MutableContracts.ContractProvider contractProvider)
 {
     this.host             = host;
     this.contractProvider = contractProvider;
 }
 public NonNullInjector(
   ICcsHost host,
   ContractProvider contractProvider)
 {
     this.host = host;
     this.contractProvider = contractProvider;
 }
 public MemoryVisitor(CodeContractAwareHostEnvironment host, PdbReader pdbReader, ContractProvider contractProvider, MemoryContractsInformation memoryContractsInformation, PointsToInformation pointsToInformation)
 {
     _host = host;
     _pdbReader = pdbReader;
     _contractProvider = contractProvider;
     _memoryContractsInformation = memoryContractsInformation;
     _errorReportItems = new List<ErrorReportItem>();
     _pointsToInformation = pointsToInformation;
 }
示例#4
0
        /// <summary>
        /// The constructor for creating an aggregating extractor.
        /// </summary>
        /// <param name="host">This is the host that loaded the unit for which the <paramref name="primaryExtractor"/> is
        /// the extractor for.
        /// </param>
        /// <param name="primaryExtractor">
        /// The extractor that will be used to define the types/members of things referred to in contracts.
        /// </param>
        /// <param name="oobExtractorsAndHosts">
        /// These are optional. If non-null, then it must be a finite sequence of pairs: each pair is a contract extractor
        /// and the host that loaded the unit for which it is a extractor.
        /// </param>
        public AggregatingContractExtractor(IMetadataHost host, IContractExtractor primaryExtractor, IEnumerable<KeyValuePair<IContractProvider, IMetadataHost>>/*?*/ oobExtractorsAndHosts)
        {
            var primaryUnit = primaryExtractor.Unit;
              this.unit = primaryUnit;
              this.primaryExtractor = primaryExtractor;

              this.underlyingContractProvider = new ContractProvider(primaryExtractor.ContractMethods, primaryUnit);
              this.host = host;

              if (oobExtractorsAndHosts != null) {
            this.oobExtractors = new List<IContractProvider>();
            foreach (var oobProviderAndHost in oobExtractorsAndHosts) {
              var oobProvider = oobProviderAndHost.Key;
              var oobHost = oobProviderAndHost.Value;
              this.oobExtractors.Add(oobProvider);
              IUnit oobUnit = oobProvider.Unit;
              this.mapperForOobToPrimary.Add(oobProvider, new MappingMutator(host, primaryUnit, oobUnit));
              this.mapperForPrimaryToOob.Add(oobProvider, new MappingMutator(oobHost, oobUnit, primaryUnit));
            }
              }
        }
示例#5
0
        private IUnit unit; // the module this is a lazy provider for

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Allocates an object that can be used to query for contracts by asking questions about specific methods/types, etc.
        /// </summary>
        /// <param name="host">The host that loaded the unit for which this is to be a contract provider.</param>
        /// <param name="unit">The unit to retrieve the contracts from.</param>
        /// <param name="contractMethods">A collection of methods that can be called in a way that provides tools with information about contracts.</param>
        /// <param name="usePdb">Whether to use the PDB file (and possibly the source files if available) during extraction.</param>
        public LazyContractExtractor(IContractAwareHost host, IUnit unit, IContractMethods contractMethods, bool usePdb)
        {
            this.host = host;
              this.underlyingContractProvider = new ContractProvider(contractMethods, unit);
              if (usePdb) {
            string pdbFile = Path.ChangeExtension(unit.Location, "pdb");
            if (File.Exists(pdbFile)) {
              using (var pdbStream = File.OpenRead(pdbFile)) {
            this.pdbReader = new PdbReader(pdbStream, host);
              }
            }
              }
              this.unit = unit;
        }
示例#6
0
 /// <summary>
 /// Creates a contract provider which is aware of how abstract methods have their contracts encoded.
 /// </summary>
 /// <param name="host">
 /// The host that was used to load the unit for which the <paramref name="underlyingContractProvider"/>
 /// is a provider for.
 /// </param>
 /// <param name="underlyingContractProvider">
 /// The (non-aware) provider that was used to extract the contracts from the IL.
 /// </param>
 public CodeContractsContractExtractor(IMetadataHost host, IContractExtractor underlyingContractProvider)
 {
     this.host = host;
       this.underlyingContractProvider = underlyingContractProvider;
       this.contractProviderCache = new ContractProvider(underlyingContractProvider.ContractMethods, underlyingContractProvider.Unit);
 }
示例#7
0
        public void LoadMutatedAssembly(string assemblyFullPath)
        {
            Contract.Requires(!String.IsNullOrEmpty(assemblyFullPath));

            var assembly = this.LoadAssemblyFrom(assemblyFullPath, out this._mutatedPdbReader);
            // Extract contracts (side effect: removes them from the method bodies)
            var contractProvider = Microsoft.Cci.MutableContracts.ContractHelper.ExtractContracts(this, assembly, this._mutatedPdbReader, this._mutatedPdbReader);

            this.MutatedAssembly = assembly;
            this.MutatedContracts = contractProvider;
        }
示例#8
0
 internal SeparateContractsFromCode(IContractAwareHost host, PdbReader/*?*/ pdbReader, ILocalScopeProvider/*?*/ localScopeProvider, ContractProvider contractProvider) {
   this.contractAwareHost = host;
   this.pdbReader = pdbReader;
   this.localScopeProvider = localScopeProvider;
   this.contractProvider = contractProvider;
   this.TraverseIntoMethodBodies = true;
 }
示例#9
0
 public ContractCallInjector(IMetadataHost host, ContractProvider contractProvider, ISourceLocationProvider sourceLocationProvider)
   : base(host, contractProvider) {
   this.systemVoid = host.PlatformType.SystemVoid;
   this.sourceLocationProvider = sourceLocationProvider;
 }
示例#10
0
 /// <summary>
 /// Mutates the given <paramref name="module"/> by injecting calls to contract methods at the
 /// beginnning of any method in the <paramref name="module"/> that has a corresponding contract
 /// in the <paramref name="contractProvider"/>. It also creates a contract invariant method
 /// for each type in <paramref name="module"/> that has a type contract in the
 /// <paramref name="contractProvider"/>.
 /// </summary>
 public static void InjectContractCalls(IMetadataHost host, Module module, ContractProvider contractProvider, ISourceLocationProvider sourceLocationProvider) {
   var cci = new ContractCallInjector(host, contractProvider, sourceLocationProvider);
   cci.Rewrite(module);
 }