Exemple #1
0
		public ExprBinaryOp (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
			: base (methodInfo)
		{
			this.Left = left;
			this.Right = right;
			this.Signage = signage;
		}
Exemple #2
0
		public virtual Expr Visit (Expr e)
		{
			switch (e.ExprType) {
			case ExprType.Block:
				return this.VisitBlock ((ExprBlock) e);
			case ExprType.Nop:
				return this.VisitNop ((ExprNop) e);
			case ExprType.Call:
				return this.VisitCall ((ExprCall) e);
			case ExprType.CompareEqual:
				return this.VisitCompareEqual ((ExprCompareEqual) e);
			case ExprType.CompareLessThan:
				return this.VisitCompareLessThan ((ExprCompareLessThan) e);
			case ExprType.CompareGreaterThan:
				return this.VisitCompareGreaterThan ((ExprCompareGreaterThan) e);
			case ExprType.Add:
				return this.VisitAdd ((ExprAdd) e);
			case ExprType.Sub:
				return this.VisitSub ((ExprSub) e);
			case ExprType.LoadArg:
				return this.VisitLoadArg ((ExprLoadArg) e);
			case ExprType.LoadConstant:
				return this.VisitLoadConstant ((ExprLoadConstant) e);
			case ExprType.Return:
				return this.VisitReturn ((ExprReturn) e);
			case ExprType.Box:
				return this.VisitBox ((ExprBox) e);
			case ExprType.Conv:
				return this.VisitConv ((ExprConv) e);
			default:
				throw new NotSupportedException ("Cannot handle: " + e.ExprType);
			}
		}
		public override Expr Visit (Expr e)
		{
			Instruction inst;
			if (this.instructionLookup.TryGetValue (e, out inst)) {
				this.instructions.Add (inst);
			}
			return base.Visit (e);
		}
Exemple #4
0
		private void Emit (Expr originalExpr, Instruction inst)
		{
			Instruction originalInst;
			if (this.instructionLookup != null) {
				// TODO: Doesn't handle inherited contracts - need to check what to do in this case.
				//if (this.instructionLookup.TryGetValue (originalExpr, out originalInst)) {
				//	inst.SequencePoint = originalInst.SequencePoint;
				//}
			}
			this.fnEmit (inst);
		}
Exemple #5
0
		protected virtual Expr VisitCollection (IEnumerable<Expr> collection, Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew)
		{
			int index = 0;
			List<Expr> exprs = null;
			foreach (var expr in collection) {
				Expr exprVisited = this.Visit (expr);
				if (exprs != null || exprVisited != expr) {
					if (exprs == null) {
						exprs = new List<Expr> (collection.Take (index));
					}
					exprs.Add (exprVisited);
				}
				index++;
			}
			if (exprs == null) {
				return e;
			} else {
				return fnCreateNew(exprs);
			}
		}
		public ContractRequiresInfo (Expr originalExpr, Expr rewrittenExpr)
		{
			this.OriginalExpr = originalExpr;
			this.RewrittenExpr = rewrittenExpr;
		}
Exemple #7
0
		public ExprCompareGreaterThan CompareGreaterThan (Expr left, Expr right, Sn signage)
		{
			return new ExprCompareGreaterThan (this.methodInfo, left, right, signage);
		}
Exemple #8
0
		public ExprCompareEqual (MethodInfo methodInfo, Expr left, Expr right)
			: base (methodInfo, left, right, Sn.None)
		{
		}
Exemple #9
0
		public ExprBox Box (Expr exprToBox)
		{
			return new ExprBox (this.methodInfo, exprToBox);
		}
Exemple #10
0
		public ExprCompareEqual CompareEqual (Expr left, Expr right)
		{
			return new ExprCompareEqual (this.methodInfo, left, right);
		}
Exemple #11
0
		public ExprConv Conv (Expr exprToConvert, TypeCode convToType)
		{
			return new ExprConv (this.methodInfo, exprToConvert, convToType);
		}
Exemple #12
0
		public ExprSub Sub (Expr left, Expr right, Sn signage, bool overflow)
		{
			return new ExprSub (this.methodInfo, left, right, signage, overflow);
		}
		public ExprBinaryOpArithmetic (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)
			: base (methodInfo, left, right, signage)
		{
			this.Overflow = overflow;
		}
Exemple #14
0
		private void RewriteIL (MethodBody body, Dictionary<Expr,Instruction> instructionLookup, Expr remove, Expr insert)
		{
			var il = body.CilWorker;
			Instruction instInsertBefore;
			if (remove != null) {
				var vInstExtent = new InstructionExtentVisitor (instructionLookup);
				vInstExtent.Visit (remove);
				instInsertBefore = vInstExtent.Instructions.Last ().Next;
				foreach (var instRemove in vInstExtent.Instructions) {
					il.Remove (instRemove);
				}
			} else {
				instInsertBefore = body.Instructions [0];
			}
			if (insert != null) {
				var compiler = new CompileVisitor (il, instructionLookup, inst => il.InsertBefore (instInsertBefore, inst));
				compiler.Visit (insert);
			}
		}
		public ExprBinaryOpComparison (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
			: base (methodInfo, left, right, signage)
		{
		}
Exemple #16
0
		private void Emit (Expr originalExpr, Func<IEnumerable<Instruction>> fnCreateInstruction)
		{
			throw new NotImplementedException ();
		}
Exemple #17
0
		public ExprBox (MethodInfo methodInfo, Expr exprToBox)
			: base (methodInfo)
		{
			this.ExprToBox = exprToBox;
		}
Exemple #18
0
		public ExprSub (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)
			: base (methodInfo, left, right, signage, overflow)
		{
		}
		private string GetConditionString (Expr e)
		{
			var vSource = new SourcePositionVisitor (this.instructionLookup);
			vSource.Visit (e);
			var extractor = new ConditionTextExtractor (vSource.SourceCodeFileName, vSource.StartPosition, vSource.EndPosition);
			return extractor.GetConditionText ();
		}
		public override Expr Visit (Expr e)
		{
			Instruction inst;
			if (this.instructionLookup.TryGetValue (e, out inst)) {
				var seq = inst.SequencePoint;
				if (seq != null) {
					this.SourceCodeFileName = seq.Document.Url;
					var instStart = new CodePosition(seq.StartLine, seq.StartColumn);
					if (this.StartPosition.IsEmpty || instStart < this.StartPosition) {
						this.StartPosition = instStart;
					}
					var instEnd = new CodePosition (seq.EndLine, seq.EndColumn);
					if (this.EndPosition.IsEmpty || instEnd > this.EndPosition) {
						this.EndPosition = instEnd;
					}
				}
			}
			return base.Visit (e);
		}
Exemple #21
0
		private Expr ProcessCall (MethodReference method)
		{
			int paramCount = method.Parameters.Count;
			Expr [] parameterExprs = new Expr [paramCount];
			for (int i = 0; i < paramCount; i++) {
				Expr parameter = this.exprs.Pop ();
				parameterExprs [paramCount - i - 1] = parameter;
			}
			return this.gen.Call(method, parameterExprs);
		}
Exemple #22
0
		private void Emit (Expr originalExpr, Func<Instruction> fnCreateInstruction)
		{
			Instruction inst = fnCreateInstruction();
			this.Emit (originalExpr, inst);
		}
Exemple #23
0
		protected Expr VisitCollection (Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew, params Expr [] collection)
		{
			return this.VisitCollection (collection, e, fnCreateNew);
		}
		public ExprCompareGreaterThan (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
			: base (methodInfo, left, right, signage)
		{
		}
Exemple #25
0
		public ExprConv (MethodInfo methodInfo, Expr exprToConvert, TypeCode convToType)
			: base (methodInfo)
		{
			this.ExprToConvert = exprToConvert;
			this.ConvToType = convToType;
		}