private void ExtractInitialize() { foreach (var state in d_states) { if ((d_randStateSet != null && d_randStateSet.Contains(state.Object)) || state is DelayedState) { continue; } if ((state.Type & Cdn.RawC.State.Flags.Derivative) != 0) { continue; } if ((state.Type & Cdn.RawC.State.Flags.EventNode) != 0) { continue; } if ((state.Type & Cdn.RawC.State.Flags.EventSet) != 0) { continue; } if (state == Time || state == TimeStep) { continue; } if (state.Object != null) { var v = state.Object as Variable; Instruction[] instrs; Cdn.EdgeAction[] actions = null; if (v == null || !v.HasFlag(VariableFlags.Integrated) || state.Actions.Length == 0) { instrs = state.Instructions; actions = state.Actions; } else { instrs = v.Expression.Instructions; } State s; EventActionState evstate = state as EventActionState; if (evstate != null) { s = new EventActionState(evstate.Action, evstate.Variable); d_eventStateToGroup[(EventActionState)s] = d_eventStateToGroup[evstate]; } else { s = new State(state.Object, instrs, state.Type | RawC.State.Flags.Initialization, actions); } AddInitialize(s); } } }
private List <State> ExtractEventActionStates(Cdn.Variable v) { var ret = new List <State>(); Cdn.EdgeAction[] actions; if (!d_actionedVariables.TryGetValue(v, out actions)) { return(ret); } foreach (Cdn.EdgeAction action in actions) { var ph = action.Phases; string[] eph; if (action.Edge != null) { eph = action.Edge.Phases; } else { eph = new string[] {}; } if (ph.Length != 0 || eph.Length != 0) { var node = FindStateNode(action.Edge.Input as Cdn.Node); HashSet <string> hs; if (ph.Length != 0) { hs = new HashSet <string>(ph); if (eph.Length != 0) { hs.IntersectWith(eph); } } else { hs = new HashSet <string>(eph); } if (node == null) { return(ret); } foreach (var h in hs) { EventStateContainerAdd(AddEventStateContainer(node), node, h); } var nm = UniqueVariableName(action.Edge, String.Format("__action_{0}", action.Target)); var nv = new Cdn.Variable(nm, action.Equation.Copy(), Cdn.VariableFlags.None); action.Edge.AddVariable(nv); d_eventActionProperties[action] = nv; var evst = new EventActionState(action, nv); ret.Add(evst); List <int> indices = new List <int>(); foreach (var st in hs) { var evstdid = EventStateId(node, st); EventState revst; if (d_eventStateIdMap.TryGetValue(evstdid, out revst)) { indices.Add(revst.Index); revst.ActiveActions.Add(action); } } if (indices.Count != 0) { indices.Sort(); string key = String.Join(",", indices.ConvertAll(a => a.ToString())); EventStateGroup grp; if (!d_eventStateGroups.TryGetValue(key, out grp)) { grp = new EventStateGroup { Node = node, Actions = new List <Cdn.EdgeAction>(), States = new List <State>(), Indices = indices, ActiveIn = hs }; d_eventStateGroups[key] = grp; } grp.Actions.Add(action); grp.States.Add(evst); d_eventStateToGroup[evst] = grp; } } } return(ret); }