private void GetConditions(RuleAction ruleAction) { foreach (var condition in ruleAction.Conditions) { var conditionParse = condition.Expression.Parse(ActionSet); Element value1; EnumMember compareOperator; Element value2; if (conditionParse is V_Compare) { value1 = (Element)((Element)conditionParse).ParameterValues[0]; compareOperator = (EnumMember)((Element)conditionParse).ParameterValues[1]; value2 = (Element)((Element)conditionParse).ParameterValues[2]; } else { value1 = (Element)conditionParse; compareOperator = EnumData.GetEnumValue(Operators.Equal); value2 = new V_True(); } Conditions.Add(new Condition(value1, compareOperator, value2)); } }
public override void Translate(ActionSet actionSet) { if (DefinedVariable != null) { // Add the defined variable to the index assigner. actionSet.IndexAssigner.Add(actionSet.VarCollection, DefinedVariable, actionSet.IsGlobal, null); // Set the initial variable. if (actionSet.IndexAssigner[DefinedVariable] is IndexReference && DefinedVariable.InitialValue != null) { actionSet.AddAction(((IndexReference)actionSet.IndexAssigner[DefinedVariable]).SetVariable( (Element)DefinedVariable.InitialValue.Parse(actionSet) )); } } else if (InitialVarSet != null) { InitialVarSet.Translate(actionSet); } // Get the condition. Element condition; if (Condition != null) { condition = (Element)Condition.Parse(actionSet); // User-define condition } else { condition = new V_True(); // No condition, just use true. } actionSet.AddAction(Element.Part <A_While>(condition)); Block.Translate(actionSet.Indent()); // Resolve continues. ResolveContinues(actionSet); if (SetVariableAction != null) { SetVariableAction.Translate(actionSet.Indent()); } actionSet.AddAction(new A_End()); // Resolve breaks. ResolveBreaks(actionSet); }
public Condition(Element value1, Operators compareOperator = Operators.Equal, Element value2 = null) { if (value2 == null) { value2 = new V_True(); } if (value1.ElementData.ElementType != ElementType.Value) { throw new IncorrectElementTypeException(nameof(value1), true); } if (value2.ElementData.ElementType != ElementType.Value) { throw new IncorrectElementTypeException(nameof(value2), true); } Value1 = value1; CompareOperator = compareOperator; Value2 = value2; }