public void AddSetRule(AST.SimplificationMode mode, Rule rule) { if (!this.HasSetRule(mode)) { setRule.Add(mode, rule); } }
public bool CanRunSet(AST.SimplificationMode mode, RPN.Node node) { if (debug) { if (canExecuteTracker == null) { canExecuteTracker = new Dictionary <AST.SimplificationMode, Stopwatch>(); } if (!canExecuteTracker.ContainsKey(mode)) { Stopwatch temp = new Stopwatch(); temp.Reset(); canExecuteTracker.Add(mode, temp); } } bool result = false; Stopwatch sw = null; if (debug) { sw = canExecuteTracker[mode]; sw.Start(); } result = ContainsSet(mode) && (!HasSetRule(mode) || GetSetRule(mode).CanExecute(node)); if (debug) { sw.Stop(); } return(result); }
public void Add(AST.SimplificationMode mode, Rule rule) { //If the rule already exists we should not //add it! if (contains.Contains(rule)) { return; } contains.Add(rule); rule.Logger += Write; //When the key already exists we just add onto the existing list if (ruleSet.ContainsKey(mode)) { List <Rule> rules = ruleSet[mode]; rules.Add(rule); ruleSet[mode] = rules; return; } //When the key does not exist we should create a list and add the rule onto it ruleSet.Add(mode, new List <Rule> { rule }); hits.Add(mode, 0); if (debug) { Stopwatch sw = new Stopwatch(); sw.Reset(); ruleSetTracker.Add(mode, sw); Stopwatch sw2 = new Stopwatch(); sw2.Reset(); canExecuteTracker.Add(mode, sw2); } }
public bool HasSetRule(AST.SimplificationMode mode) { return(setRule.ContainsKey(mode)); }
public bool ContainsSet(AST.SimplificationMode mode) { return(ruleSet.ContainsKey(mode)); }
/// <summary> /// This executes any possible simplification in the appropriate /// set. /// </summary> /// <param name="mode">The set to look in</param> /// <param name="node">The node to apply over</param> /// <returns>A new node that is the result of the application of the rule or null /// when no rule could be run</returns> public RPN.Node Execute(AST.SimplificationMode mode, RPN.Node node) { if (!ruleSet.ContainsKey(mode)) { throw new KeyNotFoundException("The optimization set was not found"); } List <Rule> rules = ruleSet[mode]; Stopwatch sw = null; if (debug) { if (ruleSetTracker == null) { ruleSetTracker = new Dictionary <AST.SimplificationMode, Stopwatch>(); } if (ruleSetTracker.ContainsKey(mode)) { sw = ruleSetTracker[mode]; } else { sw = new Stopwatch(); ruleSetTracker.Add(mode, sw); } sw.Start(); } if (!hits.ContainsKey(mode)) { hits.Add(mode, 0); } for (int i = 0; i < rules.Count; i++) { Rule rule = rules[i]; if (rule.CanExecute(node)) { RPN.Node temp = rule.Execute(node); if (debug) { sw.Stop(); } if (rule.DebugMode()) { Write("The output of : " + temp.ToInfix()); } hits[mode] = hits[mode] + 1; return(temp); } } if (debug) { sw.Stop(); } return(null); }
public Rule GetSetRule(AST.SimplificationMode mode) { return(setRule[mode]); }
public List <Rule> Get(AST.SimplificationMode mode) { return(ruleSet[mode]); }