private void RewriteMethod(ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)
        {
            if (this.rewrittenMethods.ContainsKey(method))
            {
                return;
            }
            var overridden = this.GetOverriddenMethod(method);

            if (overridden != null)
            {
                this.RewriteMethod(module, overridden, contractsRuntime);
            }
            bool anyRewrites = false;
            var  baseMethod  = this.GetBaseOverriddenMethod(method);

            if (baseMethod != method)
            {
                // Contract inheritance must be used
                var vOverriddenTransform = this.rewrittenMethods [baseMethod];
                // Can be null if overriding an abstract method
                if (vOverriddenTransform != null)
                {
                    if (this.options.Level >= 2)
                    {
                        // Only insert re-written contracts if level >= 2
                        foreach (var inheritedRequires in vOverriddenTransform.ContractRequiresInfo)
                        {
                            this.RewriteIL(method.Body, null, null, inheritedRequires.RewrittenExpr);
                            anyRewrites = true;
                        }
                    }
                }
            }

            TransformContractsVisitor vTransform = null;

            if (method.HasBody)
            {
                vTransform = this.TransformContracts(module, method, contractsRuntime);
                if (vTransform.ContractRequiresInfo.Any())
                {
                    anyRewrites = true;
                }
            }
            this.rewrittenMethods.Add(method, vTransform);

            if (anyRewrites)
            {
                Console.WriteLine(method);
            }
        }
        private TransformContractsVisitor TransformContracts(ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)
        {
            var       body      = method.Body;
            Decompile decompile = new Decompile(module, method);
            var       decomp    = decompile.Go();

            TransformContractsVisitor vTransform = new TransformContractsVisitor(module, method, decompile.Instructions, contractsRuntime);

            vTransform.Visit(decomp);

            foreach (var replacement in vTransform.ContractRequiresInfo)
            {
                // Only insert re-written contracts if level >= 2
                Expr rewritten = this.options.Level >= 2 ? replacement.RewrittenExpr : null;
                this.RewriteIL(body, decompile.Instructions, replacement.OriginalExpr, rewritten);
            }

            return(vTransform);
        }
예제 #3
0
		private TransformContractsVisitor TransformContracts (ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)
		{
			var body = method.Body;
			Decompile decompile = new Decompile (module, method);
			var decomp = decompile.Go ();

			TransformContractsVisitor vTransform = new TransformContractsVisitor (module, method, decompile.Instructions, contractsRuntime);
			vTransform.Visit (decomp);

			foreach (var replacement in vTransform.ContractRequiresInfo) {
				// Only insert re-written contracts if level >= 2
				Expr rewritten = this.options.Level >= 2 ? replacement.RewrittenExpr : null;
				this.RewriteIL (body, decompile.Instructions, replacement.OriginalExpr, rewritten);
			}

			return vTransform;
		}