public void AddCase(KirinStatement statement) { if (this.Complete) { throw new FiMException("Expected end of switch statement"); } this.Complete = true; this.DefaultCase = statement; }
public void AddCase(KirinStatement statement, string rawIndex) { if (this.Complete) { throw new FiMException("Expected end of switch statement"); } if (this.Cases.ContainsKey(rawIndex)) { throw new FiMException("Case " + rawIndex + " already exists"); } this.Cases[rawIndex] = statement; }
public override object Execute(FiMClass reportClass) { if (!this.Complete) { throw new FiMException("Executing an incomplete switch statement"); } var variable = reportClass.GetVariable(this.RawVariable); if (variable == null) { throw new FiMException("Varible " + this.RawVariable + " does not exist"); } if (FiMHelper.IsTypeArray(variable)) { throw new FiMException("Cannot use array on a switch"); } Dictionary <object, string> CasesLookup = new Dictionary <object, string>(); foreach (var key in Cases.Keys) { if (!KirinSwitchCase.IsValidPlace(key, reportClass, out object value)) { throw new FiMException("Invalid case " + key); } if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, value))) { throw new FiMException("Duplicate case value " + key); } CasesLookup.Add(value, key); } KirinStatement s = DefaultCase; if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, variable.Value))) { s = Cases[CasesLookup.First(l => KirinValue.IsEqual(l.Key, variable.Value)).Value]; } if (s != null) { return(s.Execute(reportClass)); } return(null); }
public void AddCondition(string condition, KirinStatement statement) { if (this.Complete) { throw new FiMException("Expected end of if statement"); } if (condition == string.Empty) { condition = "correct is correct"; this.Complete = true; } if (!KirinConditional.IsConditional(condition, out var result)) { throw new FiMException("Expression is not a conditional"); } Conditions.Add(new KirinConditionStatement() { Condition = result, Statement = statement }); }