public override void ExitIfStatement([NotNull] SBP.IfStatementContext context) { var stack = m_expressionData.PopStackLevel(); var condition = stack.Pop(); var subStatements = m_scopeStack.Peek().GetSubExpressions(); var attributes = m_scopeStack.Peek().GetAttributes(); condition = this.ResolveForGetOperation(condition); Expression trueStatement; if (subStatements[0].Type == ProcedureParsingScope.ScopeType.Block) { trueStatement = subStatements[0].GetBlockCode(); // TODO: Add some logging and stuff } else { trueStatement = subStatements[0].GetOnlyStatementCode(); } Expression falseStatement = null; if (subStatements.Count == 2) { if (subStatements[1].Type == ProcedureParsingScope.ScopeType.Block) { falseStatement = subStatements[1].GetBlockCode(); // TODO: Add some logging and stuff } else { falseStatement = subStatements[1].GetOnlyStatementCode(); } } if (condition.IsValueType && condition.DataType.Type == typeof(bool)) { switch (subStatements.Count) { case 1: // Without 'else' m_scopeStack.Peek().AddStatementCode(Expression.IfThen(condition.ExpressionCode, trueStatement)); break; case 2: // With 'else' m_scopeStack.Peek().AddStatementCode(Expression.IfThenElse(condition.ExpressionCode, trueStatement, falseStatement)); break; default: throw new NotImplementedException("This should never happen !!!"); } } else { throw new NotImplementedException("Something wrong with the condition expression."); } }
public override void EnterIfStatement([NotNull] SBP.IfStatementContext context) { this.AddEnterStatement(context); m_expressionData.PushStackLevel("IfStatement"); }