Esempio n. 1
0
		public ContractExtractor (ContractNodes contractNodes, AssemblyNode assembly, bool verbose)
		{
			this.visited_methods = new Dictionary<Method, Method> ();
			this.contract_nodes = contractNodes;
			this.assembly = assembly;
			this.verbose = verbose;
		}
Esempio n. 2
0
		public override AssemblyNode VisitAssembly (AssemblyNode node)
		{
			if (node == null)
				return null;
			if (this.verbose)
				Console.WriteLine ("Extracting from '{0}'", this.assembly.FullName);

			return base.VisitAssembly (node);
		}
Esempio n. 3
0
        private void InitializeLazyTypes()
        {
            this.typeVoid       = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(void))));
            this.typeSByte      = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(SByte))));
            this.typeByte       = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Byte))));
            this.typeInt16      = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Int16))));
            this.typeInt32      = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Int32))));
            this.typeInt64      = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Int64))));
            this.typeUInt16     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(UInt16))));
            this.typeUInt32     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(UInt32))));
            this.typeUInt64     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(UInt64))));
            this.typeSingle     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Single))));
            this.typeDouble     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Double))));
            this.typeBoolean    = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Boolean))));
            this.typeObject     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(object))));
            this.typeString     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(string))));
            this.typeArray      = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Array))));
            this.typeIntPtr     = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(IntPtr))));
            this.typeUIntPtr    = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(UIntPtr))));
            this.typeChar       = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(char))));
            this.typeSystemType = new Lazy <TypeNode> (() => TypeNode.Create(this.Module.Import(typeof(Type))));

            this.systemAssembly = new Lazy <AssemblyNode> (() => AssemblyNode.GetSystemAssembly());
        }
Esempio n. 4
0
		public ContractExtractor (ContractNodes contractNodes, AssemblyNode assembly)
			: this (contractNodes, assembly, DebugOptions.Debug)
		{
		}
Esempio n. 5
0
		private ContractNodes (AssemblyNode assembly, Action<string> errorHandler)
		{
			CoreSystemTypes.ModuleDefinition = assembly.Modules.First ().Definition;
			if (errorHandler != null)
				ErrorFound += errorHandler;
			this.ContractClass = assembly.GetType (ContractNamespace, ContractClassName) as Class;
			if (this.ContractClass == null)
				return;


			IEnumerable<Method> methods = this.ContractClass.GetMethods (RequiresName, CoreSystemTypes.Instance.TypeBoolean);
			foreach (Method method in methods) {
				if (method.GenericParameters == null || method.GenericParameters.Count == 0)
					this.RequiresMethod = method;
			}

			if (this.RequiresMethod == null) {
				this.ContractClass = null;
				return;
			}

			methods = this.ContractClass.GetMethods (RequiresName, CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString);
			foreach (Method method in methods) {
				if (method.GenericParameters == null || method.GenericParameters.Count == 0)
					this.RequiresWithMessageMethod = method;
			}
			this.EnsuresMethod = this.ContractClass.GetMethod (EnsuresName, CoreSystemTypes.Instance.TypeBoolean);
			this.EnsuresWithMessageMethod = this.ContractClass.GetMethod (EnsuresName,
			                                                              CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString);

			this.AssertMethod = this.ContractClass.GetMethod (AssertName, CoreSystemTypes.Instance.TypeBoolean);
			this.AssertWithMessageMethod = this.ContractClass.GetMethod (AssertName,
			                                                             CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString);

			this.AssumeMethod = this.ContractClass.GetMethod (AssumeName, CoreSystemTypes.Instance.TypeBoolean);
			this.AssumeWithMessageMethod = this.ContractClass.GetMethod (AssumeName,
			                                                             CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString);

			this.EndContractBlock = this.ContractClass.GetMethod (EndContractBlockName);

			foreach (FieldInfo fieldInfo in typeof (ContractNodes).GetFields ()) {
				if (fieldInfo.GetValue (this) != null)
					continue;

				string runtimeName = null;
				bool isRequired = false;
				object[] attributes = fieldInfo.GetCustomAttributes (typeof (RepresentationForAttribute), false);
				foreach (object attribute in attributes) {
					var representationForAttribute = attribute as RepresentationForAttribute;
					if (representationForAttribute != null) {
						runtimeName = representationForAttribute.RuntimeName;
						isRequired = representationForAttribute.IsRequired;
						break;
					}
				}
				if (isRequired) {
					string message = string.Format ("Could not find contract node for '{0}'", fieldInfo.Name);
					if (runtimeName != null)
						message = string.Format ("Could not find the method/type '{0}'", runtimeName);

					FireErrorFound (message);
					ClearFields ();
				}
			}
		}
Esempio n. 6
0
		public static ContractNodes GetContractNodes (AssemblyNode assembly, Action<string> errorHandler)
		{
			var contractNodes = new ContractNodes (assembly, errorHandler);
			if (contractNodes.ContractClass != null)
				return contractNodes;
			return null;
		}