Пример #1
0
	    public override void VisitBlockStatement (BlockStatement node)
		{
			ProcessBlock (node);

			foreach (var statement in node.Statements)
				Visit (statement);
		}
		public ForStatement (Statement initializer, Expression condition, Statement increment, BlockStatement body)
		{
			this.initializer = initializer;
			this.condition = condition;
			this.increment = increment;
			this.body = body;
		}
		public void Run (MethodBody body)
		{
			this.context = new DecompilationContext (body, ControlFlowGraph.Create (body.Method));
			var block = new BlockStatement ();

			foreach (var step in steps)
				block = step.Process (context, block);

			body_block = block;
		}
		public BlockStatement Process (DecompilationContext context, BlockStatement block)
		{
			for (int i = 0; i < context.Variables.Count; i++) {
				block.Statements.Insert (
					i,
					new ExpressionStatement (
						new VariableDeclarationExpression (context.Variables [i])));
			}

			return block;
		}
		void ProcessBlock (BlockStatement node)
		{
			var matcher = new ForMatcher ();
			matcher.Visit (node);

			if (!matcher.Match)
				return;

			var index = node.Statements.IndexOf (matcher.Initializer);
			node.Statements.RemoveAt (index); // initializer
			node.Statements.RemoveAt (index); // while
			node.Statements.Insert (index, matcher.For);
		}
Пример #6
0
		void ProcessBlock (BlockStatement node)
		{
			for (int i = 0; i < node.Statements.ToList ().Count - 1; i++) {
				var matcher = new ForeachMatcher (node.Statements [i], node.Statements [i + 1]);
				if (!matcher.Match ())
					continue;
				context.RemoveVariable (matcher.Enumerator);
				node.Statements.RemoveAt (i); // enumerator declaration/assignment
				node.Statements.RemoveAt (i); // try
				node.Statements.Insert (i, matcher.Foreach);
				ProcessBlock (matcher.Foreach.Body);
			}
		}
		public BlockStatement Process (DecompilationContext context, BlockStatement block)
		{
			var index = block.Statements.Count - 1;
			var ret = block.Statements [index] as ReturnStatement;
			if (ret == null)
				return block;

			if (ret.Expression != null)
				return block;

			block.Statements.RemoveAt (index);

			return block;
		}
		public BlockStatement Process (DecompilationContext context, BlockStatement body)
		{
			this.cfg = context.ControlFlowGraph;
			this.annotations = AnnotationStore.CreateStore (cfg, optimization);
			this.body = context.Body;
			this.variables = context.Variables;

			this.expression_decompiler = new ExpressionDecompiler (context.Method, annotations);
			this.statements = new List<Statement> [cfg.Blocks.Length];
			this.processed = new HashSet<InstructionBlock> ();
			this.assignments = new Dictionary<VariableReference, Expression> ();

			Run ();

			PopulateBodyBlock (body);

			return body;
		}
Пример #9
0
		void ProcessBlock (BlockStatement node)
		{
			var matcher = new ForMatcher ();
			matcher.Visit (node);

			if (!matcher.Match)
				return;

			var index = node.Statements.IndexOf (matcher.Initializer);
            if (index == -1)
            {
                System.Diagnostics.Debug.WriteLine("in BuildForStatements.ProcessBlock: index == -1 (so aborting function)");
                return;
            }
            
			node.Statements.RemoveAt (index); // initializer
			node.Statements.RemoveAt (index); // while
			node.Statements.Insert (index, matcher.For);
		}
Пример #10
0
			void CreateForStatement (BlockStatement body)
			{
				@for = new ForStatement (
					initializer,
					condition,
					increment,
					new BlockStatement ());

				for (int i = 0; i < body.Statements.Count - 1; i++)
					@for.Body.Statements.Add (body.Statements [i]);
			}
Пример #11
0
		public override void OnSwitch (Instruction instruction)
		{
			//AddOptimizedSwitch (instruction);
			
			var @switch = new SwitchStatement (Pop ());

			var targets = (Instruction []) instruction.Operand;

			for (int i = 0; i < targets.Length; i++) {
				var target = targets [i];

				var body = new BlockStatement ();

				var condition = new ConditionCase (new LiteralExpression (i), body);

				body.Statements.Add (
					new GotoStatement (GetLabelName (target)));

				@switch.Cases.Add (condition);
			}

			Add (@switch);
		}
Пример #12
0
 public SwitchCase(BlockStatement body)
 {
     this.body = body;
 }
		void MoveStatementsToBlock (BlockRange range, BlockStatement block)
		{
			MoveStatementsToBlock (range.Start, range.End, block);
		}
		void AddBasicCondition (Instruction instruction, Instruction target)
		{
			var then = new BlockStatement ();

			var condition = new IfStatement (Pop (), then, null);

			then.Statements.Add (new GotoStatement (annotations.GetData<string> (instruction)));

			Add (condition);
		}
		void AddRangeToBlock (BlockStatement block, IEnumerable<Statement> range)
		{
			foreach (var statement in range)
				block.Statements.Add (statement);
		}
		public ConditionCase (Expression condition, BlockStatement body) : base (body)
		{
			this.condition = condition;
		}
Пример #17
0
			bool VisitWhileStatement (Statement node)
			{
				var while_statement = node as WhileStatement;
				if (while_statement == null || while_statement.Body.Statements.Count < 1)
					return false;

				state = State.WhileCondition;

				if (!VisitMethodInvocationExpression (while_statement.Condition))
					return false;

				state = State.WhileBody;

				if (!VisitExpressionStatement (while_statement.Body.Statements [0]))
					return false;

				this.while_body = new BlockStatement ();
				for (int i = 1; i < while_statement.Body.Statements.Count; i++) {
					this.while_body.Statements.Add (while_statement.Body.Statements [i]);
				}

				return true;
			}
Пример #18
0
 public virtual ICodeNode VisitBlockStatement(BlockStatement node)
 {
     node.Statements = (StatementCollection)Visit(node.Statements);
     return(node);
 }
Пример #19
0
 public virtual void VisitBlockStatement(BlockStatement node)
 {
     Visit(node.Statements);
 }
Пример #20
0
		public BlockStatement Process (DecompilationContext context, BlockStatement body)
		{
			Visit (body);
			return body;
		}
		public BlockStatement Process (DecompilationContext context, BlockStatement block)
		{
			this.context = context;
			PopulateNotAssigned ();
			return (BlockStatement) VisitBlockStatement (block);
		}
Пример #22
0
		public virtual void VisitBlockStatement (BlockStatement node)
		{
			Visit (node.Statements);
		}
		public WhileStatement (Expression condition, BlockStatement body)
		{
			this.condition = condition;
			this.body = body;
		}
		public IfStatement (Expression condition, BlockStatement then, BlockStatement @else)
		{
			this.condition = condition;
			this.then = then;
			this.@else = @else;
		}
		void AddLoop (Instruction instruction, Statement loop, BlockStatement body)
		{
			var data = annotations.GetData<LoopData> (instruction);

			MoveStatementsToBlock (data.Body, body);

			Add (loop);
		}
		void PopulateBodyBlock (BlockStatement block)
		{
			AddRangeToBlock (block, GetStatements ());
		}
		void MoveStatementsToBlock (InstructionBlock start, InstructionBlock limit, BlockStatement block)
		{
			for (int i = start.Index; i < limit.Index; i++) {
				ProcessBlock (cfg.Blocks [i]);

				var block_statements = this.statements [i];
				if (block_statements == null)
					continue;

				AddRangeToBlock (block, block_statements);

				block_statements.Clear ();
			}
		}
Пример #28
0
 public void EmitBlockStatement(BlockStatement node, int si)
 {
     Emit(node.Statements, si);
 }
Пример #29
0
 public ForEachStatement(VariableDeclarationExpression variable, Expression expression, BlockStatement body)
 {
     this.variable   = variable;
     this.expression = expression;
     this.body       = body;
 }
		public ForEachStatement (VariableDeclarationExpression variable, Expression expression, BlockStatement body)
		{
			this.variable = variable;
			this.expression = expression;
			this.body = body;
		}
		public override void VisitBlockStatement (BlockStatement node)
		{
			WriteBlock (() => Visit (node.Statements));
		}
		public TryStatement (BlockStatement @try, BlockStatement fault, BlockStatement @finally)
		{
			this.@try = @try;
			this.fault = fault;
			this.@finally = @finally;
		}
Пример #33
0
		public BlockStatement Process (DecompilationContext context, BlockStatement body)
		{
			return (BlockStatement) VisitBlockStatement (body);
		}
		public CatchClause (BlockStatement body, TypeReference type, VariableDeclarationExpression variable)
		{
			this.body = body;
			this.type = type;
			this.variable = variable;
		}