private void TryMergeExpressions(ConditionStatement node)
		{
			if (!(node.Condition is UnaryExpression))
			{
				return;
			}

			UnaryExpression unaryExpression = (UnaryExpression)node.Condition;

			if (unaryExpression.Operator != UnaryOperator.LogicalNot)
			{
				return;
			}

			if (unaryExpression.Operand is MethodInvocationExpression || unaryExpression.Operand is PropertyReferenceExpression)
			{
				return;
			}

			if (!IsConditionExpression(unaryExpression.Operand))
			{
				return;
			}

			node.Condition = Negator.Negate(unaryExpression.Operand, typeSystem);
		}
コード例 #2
0
		private void SetVariablesExpressionStatements(ConditionStatement node)
		{
			for (int i = variables.Count - 1; i >= 0; i--)
			{
				var keyValuePair = variables[i];

				if (keyValuePair.VariableState == VariableState.Other)
					continue;

				for (int j = keyValuePair.StatementExpressions.Count - 1; j >= 0; j--)
				{
					var statementExpression = keyValuePair.StatementExpressions[j];
					if (statementExpression.Statement == null)
					{
						if (node == statementExpression.ParentWhileStatement)
						{
							statementExpression.ParentWhileStatement = GetParentWhileStatementAtLevel(1);
						}
						statementExpression.Statement = node;
					}
				}
			}
		}
コード例 #3
0
		private void TryProcessConditionStatement(ConditionStatement node)
		{
			if (processStep == ProcessStep.Replace)
			{
				Expression expression;
				if (TryGetVariableExpression(node.Condition, out expression))
				{
					node.Condition = expression;
				}
			}
			if (processStep == ProcessStep.Search)
			{
				if (!(node is WhileStatement) && !(node is DoWhileStatement))
				{
					SetVariablesExpressionStatements(node);
				}
			}
		}
コード例 #4
0
        /// <summary>
        /// Extracts the condition of the condition statement into new variable. Replaces the condition of the statement with the new variable and inserts 
        /// the assignment statement right before the condition statement.
        /// </summary>
        /// <param name="conditionVar">The variable which should be assigned the condition.</param>
        /// <param name="gotoStatement">The conditional goto.</param>
        /// <param name="containingBlock">The block that contains the conditional goto.</param>
        private void ExtractConditionIntoVariable(VariableReferenceExpression conditionVar, ConditionStatement statement, BlockStatement containingBlock)
        {
            /// Create the statement conditionVariable = originalCondition;
            BinaryExpression conditionAssignment = new BinaryExpression(BinaryOperator.Assign, conditionVar, statement.Condition, typeSystem, null);
            ExpressionStatement assignStatement = new ExpressionStatement(conditionAssignment);

            /// Insert the statement before the original goto statement.
            int gotoIndex = containingBlock.Statements.IndexOf(statement);
            containingBlock.AddStatementAt(gotoIndex, assignStatement);

            /// Update the condition of the goto statement.
            statement.Condition = conditionVar.CloneExpressionOnly();
        }