public ForStatement (Statement initializer, Expression condition, Statement increment, BlockStatement body)
		{
			this.initializer = initializer;
			this.condition = condition;
			this.increment = increment;
			this.body = body;
		}
Exemplo n.º 2
0
 public TypedAssignExpression(Expression target, Expression expression)
     : base(target, expression)
 {
     this.ElementType = TypedTransformer.GetElementType(target);
     //TODO: do we need to check the assigning type? if so how can we do it without the actual type handles?
     //Helper.AreEqual(this.ElementType, TypedTransformer.GetElementType(expression), "'expression' argument must have the same element type as 'target' argument.");
 }
        private void WriteExpression(Cecil.Decompiler.Ast.Expression expr)
        {
            Cecil.Decompiler.Languages.ILanguage csharpLang = Cecil.Decompiler.Languages.CSharp.GetLanguage(
                Cecil.Decompiler.Languages.CSharpVersion.V1);

            var writer = csharpLang.GetWriter(new Cecil.Decompiler.Languages.ColoredConsoleFormatter());

            writer.Write(expr);
        }
Exemplo n.º 4
0
		ICodeNode BuildUnaryExpression (UnaryOperator @operator, Expression expression)
		{
			return new UnaryExpression (@operator, (Expression) Visit (expression));
		}
		public MethodReferenceExpression (Expression target, MethodReference method)
		{
			this.target = target;
			this.method = method;
		}
		public ExpressionStatement (Expression expression)
		{
			this.expression = expression;
		}
		public override void Write (Expression expression)
		{
			Visit (expression);
		}
Exemplo n.º 8
0
 public TypedBinaryExpression(BinaryOperator @operator, Expression left, Expression right)
     : base(@operator, left, right)
 {
     this.ElementType = TypedTransformer.GetElementType(left);
     Helper.AreEqual(this.ElementType, TypedTransformer.GetElementType(right), "left and right expressions do not have the same ElementType");
 }
		public AddressOfExpression (Expression expression)
		{
			this.expression = expression;
		}
Exemplo n.º 10
0
			bool VisitMethodInvocationExpression (Expression node)
			{
				var invocation_expression = node as MethodInvocationExpression;
				if (invocation_expression == null)
					return false;

				var method_reference_expression = invocation_expression.Method as MethodReferenceExpression;
				if (method_reference_expression == null)
					return false;

				// todo : use a resolver for method calls
				switch (state) {
					case State.Begin:
						if (method_reference_expression.Method.Name != "GetEnumerator")
							return false;
						this.source = method_reference_expression.Target;
						break;

					case State.WhileCondition:
						if (!IsCallOnEnumerator (method_reference_expression, "MoveNext"))
							return false;
						break;

					case State.WhileBody:
						if (!IsCallOnEnumerator (method_reference_expression, "get_Current"))
							return false;
						break;

					case State.IfBody:
						if (!IsCallOnEnumerator (method_reference_expression, "Dispose"))
							return false;
						break;
				}

				return true;
			}
Exemplo n.º 11
0
			bool VisitAssignExpression (Expression node)
			{
				var assign_expression = node as AssignExpression;
				if (assign_expression == null)
					return false;

				if (!VisitVariableReferenceExpression (assign_expression.Target))
					return false;

				if (!VisitMethodInvocationExpression (assign_expression.Expression))
					return false;

				return true;
			}
		public AssignExpression (Expression target, Expression expression)
		{
			this.target = target;
			this.expression = expression;
		}
		public ConditionExpression (Expression condition, Expression then, Expression @else)
		{
			this.condition = condition;
			this.then = then;
			this.@else = @else;
		}
Exemplo n.º 14
0
		ICodeNode BuildBinaryExpression (BinaryOperator binary_operator, Expression left, Expression right)
		{
			base.Visit (left);
			base.Visit (right);
			return new BinaryExpression (binary_operator, left, right);
		}
Exemplo n.º 15
0
		ICodeNode BuildUnaryExpression (UnaryOperator unary_operator, Expression expression)
		{
			base.Visit (expression);
			return new UnaryExpression (unary_operator, expression);
		}
Exemplo n.º 16
0
			public override void VisitWhileStatement (WhileStatement node)
			{
				switch (state) {
				case State.Initializer:
					if (!VariableMatcher.FindVariableInExpression (variable, node.Condition))
						break;

					state = State.Condition;
					condition = node.Condition;

					var body = node.Body;

					if (body.Statements.Count == 0)
						break;

					Visit (body.Statements [body.Statements.Count - 1]);

					if (!Match)
						break;

					CreateForStatement (body);
					break;
				}

				Continue = false;
			}
Exemplo n.º 17
0
			bool VisitVariableReferenceExpression (Expression node)
			{
				var variable_reference_expression = node as VariableReferenceExpression;
				if (variable_reference_expression == null)
					return false;

				switch (state) {
					case State.Begin:
						this.enumerator = variable_reference_expression.Variable;
						break;

					case State.WhileBody:
						this.variable = variable_reference_expression.Variable as VariableDefinition;
						break;
				}

				return true;
			}
Exemplo n.º 18
0
		public MethodInvocationExpression (Expression method)
		{
			this.method = method;
		}
Exemplo n.º 19
0
			bool IsEnumerator (Expression node)
			{
				var variable_reference = node as VariableReferenceExpression;
				if (variable_reference == null || variable_reference.Variable != this.enumerator)
					return false;
				return true;
			}
		public FieldReferenceExpression (Expression target, FieldReference field)
		{
			this.target = target;
			this.field = field;
		}
		public ConditionCase (Expression condition, BlockStatement body) : base (body)
		{
			this.condition = condition;
		}
		void Push (Expression expression)
		{
			expression_decompiler.Push (expression);
		}
		public UnaryExpression (UnaryOperator @operator, Expression operand)
		{
			this.@operator = @operator;
			this.operand = operand;
		}
		void WriteBetweenParenthesis (Expression expression)
		{
			WriteToken ("(");
			Visit (expression);
			WriteToken (")");
		}
		public CastExpression (Expression expression, TypeReference targetType)
		{
			this.expression = expression;
			this.targetType = targetType;
		}
		public abstract void Write (Expression expression);
		public IfStatement (Expression condition, BlockStatement then, BlockStatement @else)
		{
			this.condition = condition;
			this.then = then;
			this.@else = @else;
		}
		public static bool FindVariableInExpression (VariableReference variable, Expression expression)
		{
			var matcher = new VariableMatcher (variable);
			matcher.Visit (expression);
			return matcher.Match;
		}
		public PropertyReferenceExpression (Expression target, PropertyReference property)
		{
			this.target = target;
			this.property = property;
		}
Exemplo n.º 30
0
		ICodeNode BuildBinaryExpression (BinaryOperator @operator, Expression left, Expression right)
		{
			return new BinaryExpression (@operator,
				(Expression) Visit (left),
				(Expression) Visit (right));
		}
		public SwitchStatement (Expression expression)
		{
			this.expression = expression;
		}