private Statement CloneStatement(bool copyInstructions) { List <KeyValuePair <Expression, BlockStatement> > conditionBlocksClone = new List <KeyValuePair <Expression, BlockStatement> >(); foreach (KeyValuePair <Expression, BlockStatement> pair in conditionBlocks) { Expression conditionClone = copyInstructions ? pair.Key.Clone() : pair.Key.CloneExpressionOnly(); BlockStatement blockClone = copyInstructions ? (BlockStatement)pair.Value.Clone() : (BlockStatement)pair.Value.CloneStatementOnly(); conditionBlocksClone.Add(new KeyValuePair <Expression, BlockStatement>(conditionClone, blockClone)); } BlockStatement elseClone = null; if (@else != null) { elseClone = copyInstructions ? (BlockStatement)[email protected]() : (BlockStatement)[email protected](); } IfElseIfStatement result = new IfElseIfStatement(conditionBlocksClone, elseClone); CopyParentAndLabel(result); return(result); }
public override void VisitIfElseIfStatement(IfElseIfStatement node) { for (int i = 0; i < node.ConditionBlocks.Count; i++) { if (i == 0) { WriteKeyword(KeyWordWriter.If); } else { WriteLine(); WriteKeyword(KeyWordWriter.ElseIf); } WriteSpace(); WriteBetweenParenthesis(node.ConditionBlocks[i].Key); if (KeyWordWriter.Then != null) { WriteSpace(); WriteKeyword(KeyWordWriter.Then); } WriteLine(); Visit(node.ConditionBlocks[i].Value); } if (node.Else != null) { WriteLine(); WriteKeyword(KeyWordWriter.Else); WriteLine(); Visit(node.Else); } WriteSpecialEndBlock(KeyWordWriter.If); }
private Statement CloneStatement(bool copyInstructions) { List<KeyValuePair<Expression, BlockStatement>> conditionBlocksClone = new List<KeyValuePair<Expression, BlockStatement>>(); foreach (KeyValuePair<Expression, BlockStatement> pair in conditionBlocks) { Expression conditionClone = copyInstructions ? pair.Key.Clone() : pair.Key.CloneExpressionOnly(); BlockStatement blockClone = copyInstructions ? (BlockStatement)pair.Value.Clone() : (BlockStatement)pair.Value.CloneStatementOnly(); conditionBlocksClone.Add(new KeyValuePair<Expression, BlockStatement>(conditionClone, blockClone)); } BlockStatement elseClone = null; if (@else != null) { elseClone = copyInstructions ? (BlockStatement)[email protected]() : (BlockStatement)[email protected](); } IfElseIfStatement result = new IfElseIfStatement(conditionBlocksClone, elseClone); CopyParentAndLabel(result); return result; }
public virtual void VisitIfElseIfStatement(IfElseIfStatement node) { for (int i = 0; i < node.ConditionBlocks.Count; i++) { KeyValuePair<Expression, BlockStatement> pair = node.ConditionBlocks[i]; Visit(pair.Key); Visit(pair.Value); } Visit(node.Else); }
private IfElseIfStatement BuildIfElseIfStatement(IfStatement theIf) { // at this point we are sure, that the statement is either IfStatement or IfElseIfStatement Statement elseStatement = theIf.Else.Statements[0]; if (elseStatement.CodeNodeType == CodeNodeType.IfStatement) { IfStatement innerIf = (IfStatement)elseStatement; List<KeyValuePair<Expression, BlockStatement>> ifChain = new List<KeyValuePair<Expression, BlockStatement>>(); KeyValuePair<Expression, BlockStatement> theFirstPair = new KeyValuePair<Expression, BlockStatement>(theIf.Condition, theIf.Then); KeyValuePair<Expression, BlockStatement> theSecondPair = new KeyValuePair<Expression, BlockStatement>(innerIf.Condition, innerIf.Then); ifChain.Add(theFirstPair); ifChain.Add(theSecondPair); IfElseIfStatement result = new IfElseIfStatement(ifChain, innerIf.Else); return result; } else { IfElseIfStatement innerIfElseIf = (IfElseIfStatement)elseStatement; List<KeyValuePair<Expression, BlockStatement>> ifChain = innerIfElseIf.ConditionBlocks; KeyValuePair<Expression, BlockStatement> outerPair = new KeyValuePair<Expression, BlockStatement>(theIf.Condition, theIf.Then); ifChain.Insert(0, outerPair); theIf.Then.Parent = innerIfElseIf; return innerIfElseIf; } }