private string getSyncChannel(Template t, StateTransition st, SyncRule.Direction dir) { SyncRule r = (SyncRule)st.Rules.SingleOrDefault(x => x is SyncRule); if (r == null) { return(NULL); } if (r.Dir != dir) { return(NULL); } VarDecl vd; switch (r.Expr.Type) { case Expression.ExpType.Func: // might be array/range if (r.Expr.Func != Expression.Funcs.ArrayIndex) { throw new Exception("Only array dereferencing allowed on channels!"); } if (r.Expr.First.Type != Expression.ExpType.Var) { throw new Exception("Synchronization rule must be a channel!"); } int idx; if (!t.Declarations.getExprValue(r.Expr.Second, out idx)) { throw new Exception("Channel array index must be a constant!"); } vd = t.Declarations.getVar(r.Expr.First.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new Exception(String.Format("Could not find '{0}' in declarations for template '{1}' or globally!", r.Expr.First.Var, t.Name)); } return(String.Format("{0}_ARRAY[{1}]", getUniqueName(vd), idx - vd.ArrLow)); case Expression.ExpType.Var: vd = t.Declarations.getVar(r.Expr.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new Exception(String.Format("Could not find '{0}' in declarations for template '{1}' or globally!", r.Expr.Var, t.Name)); } return(String.Format("&{0}", getUniqueName(vd))); default: throw new Exception("Synchronization rule must be a channel"); } }
private string getSyncChannel(Template t, StateTransition st, SyncRule.Direction dir) { SyncRule r = (SyncRule)st.Rules.SingleOrDefault(x => x is SyncRule); if (r == null) { return(NULL); } if (r.Dir != dir) { return(NULL); } return(getSyncChannelCode(getUniqueName, t, r)); }
public IEnumerable <string> getDirOnlyChannels(SyncRule.Direction direction) { var result = new List <string>(); foreach (Template t in _model.Templates) { foreach (var r in t.Transitions .SelectMany(tr => tr.Rules) .Select(s => s as SyncRule) .Where(s => (s != null && s.Dir == direction))) { VarDecl vd; switch (r.Expr.Type) { case Expression.ExpType.Func: // might be array/range int idx; if (r.Expr.Func == Expression.Funcs.ArrayIndex && r.Expr.First.Type == Expression.ExpType.Var && t.Declarations.getExprValue(r.Expr.Second, out idx)) { vd = t.Declarations.getVar(r.Expr.First.Var); if (vd != null && vd.Type.Type == VarType.Channel) { for (int i = 0; i < vd.ArrLength; ++i) { result.Add(String.Format("{0}_{1}", _namer(vd), vd.ArrLow + i)); } } } break; case Expression.ExpType.Var: vd = t.Declarations.getVar(r.Expr.Var); if (vd != null && vd.Type.Type == VarType.Channel) { result.Add(_namer(vd)); } break; } } } return(result.Distinct().OrderBy(x => x)); }