int compareByChannelPriority(StateTransition x, StateTransition y)
        {
            SyncRule xr = (SyncRule)x.Rules.SingleOrDefault(r => r is SyncRule);
            SyncRule yr = (SyncRule)y.Rules.SingleOrDefault(r => r is SyncRule);

            // no sync rules are last
            if (xr == null && yr == null)
            {
                return(x.Name.CompareTo(y.Name));
            }
            if (xr == null)
            {
                return(-1);
            }
            if (yr == null)
            {
                return(1);
            }

            // both have sync rules
            int xp = _decls.getChannelPriority(xr.Expr);
            int yp = _decls.getChannelPriority(yr.Expr);

            return(xp.CompareTo(yp));
        }
示例#2
0
        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");
            }
        }