public void Anon_11(Event currentMachine_dequeuedEvent) { Door currentMachine = this; PrtBool TMP_tmp0_10 = ((PrtBool)false); PEvent TMP_tmp1_9 = null; PrtBool TMP_tmp2_4 = ((PrtBool)false); PEvent TMP_tmp3_3 = null; TMP_tmp0_10 = (PrtBool)(((PrtBool)currentMachine.TryRandomBool())); if (TMP_tmp0_10) { TMP_tmp1_9 = (PEvent)(new eUnit(null)); currentMachine.TryRaiseEvent((Event)TMP_tmp1_9); return; } else { TMP_tmp2_4 = (PrtBool)(((PrtBool)currentMachine.TryRandomBool())); if (TMP_tmp2_4) { TMP_tmp3_3 = (PEvent)(new eObjectEncountered(null)); currentMachine.TryRaiseEvent((Event)TMP_tmp3_3); return; } } }
public PEvent(PEvent other) : this(PapillonPINVOKE.new_PEvent__SWIG_1(PEvent.getCPtr(other)), true) { if (PapillonPINVOKE.SWIGPendingException.Pending) { throw PapillonPINVOKE.SWIGPendingException.Retrieve(); } }
// Each event class implements the IEvent interface and overrides the handle function. // The handle function calls the correspondning event handler of the current state. private void WriteEventClass(StringWriter output, PEvent pEvent) { string eventClassName = Context.Names.GetUnqualifiedEventClassName(pEvent); string eventInterfaceName = Context.Names.GetEventInterfaceName(); string stateInterfaceName = Context.Names.GetStateInterfaceName(); string stateClassName = Context.Names.GetStateBaseClassName(); Context.WriteLine(output, $"static class {eventClassName} implements {eventInterfaceName} {{"); // Override handle function string handleFunctionName = Context.Names.GetEventHandleFunctionName(); string payloadType = Context.Names.GetDefaultPayloadTypeName(); string maybePayloadName = Context.Names.GetMaybePayloadArgumentName(); string throwsClause = Tools.GetThrowsClause(); string stateVariable = Context.Names.GetStateVariableName(); Context.WriteLine(output, "@Override"); Context.WriteLine(output, $"public void {handleFunctionName}({stateInterfaceName} {stateVariable}, Optional<{payloadType}> {maybePayloadName}) {throwsClause} {{"); string payloadName = ""; if (!Tools.isNullType(pEvent.PayloadType)) { string actualPayloadType = Context.Names.GetJavaTypeName(pEvent.PayloadType); payloadName = Context.Names.GetPayloadArgumentName(); Tools.InlineEventHandlerArguments(output, actualPayloadType, payloadName); } string handlerName = Context.Names.GetStateEventHandlerName(pEvent); Context.WriteLine(output, $"(({stateClassName}){stateVariable}).{handlerName}({payloadName});"); Context.WriteLine(output, "}"); Context.WriteLine(output, "}"); }
public void Anon() { var currentMachine = this; PMachineValue TMP_tmp0 = null; PMachineValue TMP_tmp1 = null; PEvent TMP_tmp2 = null; PMachineValue TMP_tmp3 = null; PEvent TMP_tmp4 = null; PMachineValue TMP_tmp5 = null; PEvent TMP_tmp6 = null; PMachineValue TMP_tmp7 = null; PEvent TMP_tmp8 = null; TMP_tmp0 = currentMachine.CreateInterface <I_Receiver>(currentMachine); m = TMP_tmp0; TMP_tmp1 = (PMachineValue)((IPrtValue)m)?.Clone(); TMP_tmp2 = new e1(null); currentMachine.SendEvent(TMP_tmp1, TMP_tmp2); TMP_tmp3 = (PMachineValue)((IPrtValue)m)?.Clone(); TMP_tmp4 = new e2(null); currentMachine.SendEvent(TMP_tmp3, TMP_tmp4); TMP_tmp5 = (PMachineValue)((IPrtValue)m)?.Clone(); TMP_tmp6 = new e3(null); currentMachine.SendEvent(TMP_tmp5, TMP_tmp6); TMP_tmp7 = (PMachineValue)((IPrtValue)m)?.Clone(); TMP_tmp8 = new e4(null); currentMachine.SendEvent(TMP_tmp7, TMP_tmp8); }
public PEvent Put(string name, PParser.EventDeclContext tree) { PEvent @event = new PEvent(name, tree); CheckConflicts(@event, Namespace(events), Namespace(enumElems)); events.Add(name, @event); return(@event); }
public EventGotoState(ParserRuleContext sourceLocation, PEvent trigger, State target, Function transitionFunction) { SourceLocation = sourceLocation; Trigger = trigger; Target = target; TransitionFunction = transitionFunction; }
public Exception IllegalInterfaceCoerce(ParserRuleContext context, PLanguageType oldType, PLanguageType newType) { PEvent outlierEvent = newType.AllowedPermissions.Value.First(x => !oldType.AllowedPermissions.Value.Contains(x)); return(IssueError(context, $"illegal Coerce, {oldType.OriginalRepresentation} permissions is not a superset of {newType.OriginalRepresentation} (e.g., event {outlierEvent.Name})")); }
public override object VisitEventDecl(PParser.EventDeclContext context) { string symbolName = context.name.GetText(); PEvent decl = CurrentScope.Put(symbolName, context); nodesToDeclarations.Put(context, decl); UniversalEventSet.Instance.AddEvent(decl); // TODO: do we actually want to do this? return(null); }
public override object VisitEventDecl(PParser.EventDeclContext context) { string symbolName = context.name.GetText(); PEvent decl = CurrentScope.Put(symbolName, context); nodesToDeclarations.Put(context, decl); CurrentScope.UniversalEventSet.AddEvent(decl); return(null); }
public void Anon_16(Event currentMachine_dequeuedEvent) { Timer currentMachine = this; PMachineValue TMP_tmp0_14 = null; PEvent TMP_tmp1_13 = null; TMP_tmp0_14 = (PMachineValue)(((PMachineValue)((IPrtValue)creator)?.Clone())); TMP_tmp1_13 = (PEvent)(new eTimerFired(null)); currentMachine.TrySendEvent(TMP_tmp0_14, (Event)TMP_tmp1_13); }
// Writes the state event handler internal void WriteTemplateEventHandler(StringWriter output, PEvent pEvent, EventHandlerBodyDelegate writeBody) { string throwsClause = GetThrowsClause(); string handlerName = Context.Names.GetStateEventHandlerName(pEvent); WriteEventHandlerSignature(output, pEvent); Context.WriteLine(output, $" {{"); writeBody(output); Context.WriteLine(output, "}"); }
public void Anon_6(Event currentMachine_dequeuedEvent) { Elevator currentMachine = this; PMachineValue TMP_tmp0_6 = null; PEvent TMP_tmp1_6 = null; TMP_tmp0_6 = (PMachineValue)(((PMachineValue)((IPrtValue)DoorV)?.Clone())); TMP_tmp1_6 = (PEvent)(new eSendCommandToStopDoor(null)); currentMachine.TrySendEvent(TMP_tmp0_6, (Event)TMP_tmp1_6); }
public Transition Anon() { Main currentMachine = this; PMachineValue TMP_tmp0 = null; PEvent TMP_tmp1 = null; TMP_tmp0 = currentMachine.CreateInterface <I_PONG>(currentMachine); pongId = TMP_tmp0; TMP_tmp1 = new Success(null); return(currentMachine.TryRaiseEvent(TMP_tmp1)); }
private static void ValidateTransitions(ITranslationErrorHandler handler, Machine machine) { foreach (State state in machine.AllStates()) { foreach (KeyValuePair <PEvent, AST.IStateAction> pair in state.AllEventHandlers) { PEvent handledEvent = pair.Key; switch (pair.Value) { case EventDoAction eventDoAction: if (eventDoAction.Target != null) { ValidateEventPayloadToTransitionTarget(handler, eventDoAction.SourceLocation, handledEvent.PayloadType, eventDoAction.Target); } break; case EventGotoState eventGotoState: if (eventGotoState.Target.Entry != null) { ValidateEventPayloadToTransitionTarget(handler, eventGotoState.SourceLocation, handledEvent.PayloadType, eventGotoState.Target.Entry); } if (eventGotoState.TransitionFunction != null) { ValidateEventPayloadToTransitionTarget(handler, eventGotoState.SourceLocation, handledEvent.PayloadType, eventGotoState.TransitionFunction); } break; case EventPushState eventPushState: if (eventPushState.Target.Entry != null) { ValidateEventPayloadToTransitionTarget(handler, eventPushState.SourceLocation, handledEvent.PayloadType, eventPushState.Target.Entry); } break; } } if (state.Exit?.Signature.Parameters.Count > 0) { throw handler.IncorrectArgumentCount(state.SourceLocation, state.Exit.Signature.Parameters.Count, 0); } } }
public void Anon() { Main currentMachine = this; PMachineValue TMP_tmp0 = null; PEvent TMP_tmp1 = null; TMP_tmp0 = currentMachine.CreateInterface <I_PONG>(currentMachine); pongId = TMP_tmp0; TMP_tmp1 = new Success(null); currentMachine.RaiseEvent(TMP_tmp1); throw new PUnreachableCodeException(); }
public void Anon_1() { Timer currentMachine = this; PMachineValue TMP_tmp0_3 = null; PEvent TMP_tmp1_2 = null; PMachineValue TMP_tmp2_1 = null; TMP_tmp0_3 = (PMachineValue)(((PMachineValue)((IPrtValue)client)?.Clone())); TMP_tmp1_2 = (PEvent)(new TIMEOUT(null)); TMP_tmp2_1 = (PMachineValue)(currentMachine.self); currentMachine.SendEvent(TMP_tmp0_3, (Event)TMP_tmp1_2, TMP_tmp2_1); }
public void Anon_12(Event currentMachine_dequeuedEvent) { Door currentMachine = this; PMachineValue TMP_tmp0_11 = null; PEvent TMP_tmp1_10 = null; TMP_tmp0_11 = (PMachineValue)(((PMachineValue)((IPrtValue)ElevatorV_1)?.Clone())); TMP_tmp1_10 = (PEvent)(new eObjectDetected(null)); currentMachine.TrySendEvent(TMP_tmp0_11, (Event)TMP_tmp1_10); currentMachine.TryGotoState <Door.Init_2>(); return; }
public void Anon_14(Event currentMachine_dequeuedEvent) { Door currentMachine = this; PMachineValue TMP_tmp0_13 = null; PEvent TMP_tmp1_12 = null; TMP_tmp0_13 = (PMachineValue)(((PMachineValue)((IPrtValue)ElevatorV_1)?.Clone())); TMP_tmp1_12 = (PEvent)(new eDoorStopped(null)); currentMachine.TrySendEvent(TMP_tmp0_13, (Event)TMP_tmp1_12); currentMachine.TryGotoState <Door.OpenDoor>(); return; }
private static void ValidateTransitions(ITranslationErrorHandler handler, Machine machine) { foreach (State state in machine.AllStates()) { foreach (KeyValuePair <PEvent, AST.IStateAction> pair in state.AllEventHandlers) { PEvent handledEvent = pair.Key; switch (pair.Value) { case EventDoAction eventDoAction: if (eventDoAction.Target != null) { ValidateEventPayloadToTransitionTarget(handler: handler, sourceLocation: eventDoAction.SourceLocation, eventPayloadType: handledEvent.PayloadType, targetFunction: eventDoAction.Target); } break; case EventGotoState eventGotoState: if (eventGotoState.Target.Entry != null) { ValidateEventPayloadToTransitionTarget(handler: handler, sourceLocation: eventGotoState.SourceLocation, eventPayloadType: handledEvent.PayloadType, targetFunction: eventGotoState.Target.Entry); } if (eventGotoState.TransitionFunction != null) { ValidateEventPayloadToTransitionTarget(handler: handler, sourceLocation: eventGotoState.SourceLocation, eventPayloadType: handledEvent.PayloadType, targetFunction: eventGotoState.TransitionFunction); } break; case EventPushState eventPushState: if (eventPushState.Target.Entry != null) { ValidateEventPayloadToTransitionTarget(handler: handler, sourceLocation: eventPushState.SourceLocation, eventPayloadType: handledEvent.PayloadType, targetFunction: eventPushState.Target.Entry); } break; case EventDefer _: case EventIgnore _: { break; } } } } }
internal void WriteEventHandlerSignature(StringWriter output, PEvent pEvent) { string throwsClause = GetThrowsClause(); string handlerName = Context.Names.GetStateEventHandlerName(pEvent); Context.Write(output, $"public void {handlerName}("); if (!isNullType(pEvent.PayloadType)) { string payloadType = Context.Names.GetJavaTypeName(pEvent.PayloadType); string payloadName = Context.Names.GetPayloadArgumentName(); Context.Write(output, $"{payloadType} {payloadName}"); } Context.Write(output, $") {throwsClause}"); }
public void Anon_4(Event currentMachine_dequeuedEvent) { Elevator currentMachine = this; PrtBool TMP_tmp0_4 = ((PrtBool)false); PEvent TMP_tmp1_4 = null; TMP_tmp0_4 = (PrtBool)(((PrtBool)currentMachine.TryRandomBool())); if (TMP_tmp0_4) { TMP_tmp1_4 = (PEvent)(new eCloseDoor(null)); currentMachine.TryRaiseEvent((Event)TMP_tmp1_4); return; } }
public void Anon_10(Event currentMachine_dequeuedEvent) { Door currentMachine = this; PMachineValue TMP_tmp0_9 = null; PEvent TMP_tmp1_8 = null; PEvent TMP_tmp2_3 = null; TMP_tmp0_9 = (PMachineValue)(((PMachineValue)((IPrtValue)ElevatorV_1)?.Clone())); TMP_tmp1_8 = (PEvent)(new eDoorOpened(null)); currentMachine.TrySendEvent(TMP_tmp0_9, (Event)TMP_tmp1_8); TMP_tmp2_3 = (PEvent)(new eUnit(null)); currentMachine.TryRaiseEvent((Event)TMP_tmp2_3); return; }
public Transition Anon_1() { Main currentMachine = this; PMachineValue TMP_tmp0_1 = null; PEvent TMP_tmp1_1 = null; PMachineValue TMP_tmp2 = null; PEvent TMP_tmp3 = null; TMP_tmp0_1 = ((PMachineValue)((IPrtValue)pongId)?.Clone()); TMP_tmp1_1 = new Ping(null); TMP_tmp2 = currentMachine.self; currentMachine.TrySendEvent(TMP_tmp0_1, TMP_tmp1_1, TMP_tmp2); TMP_tmp3 = new Success(null); return(currentMachine.TryRaiseEvent(TMP_tmp3)); }
public void Anon_3(Event currentMachine_dequeuedEvent) { Elevator currentMachine = this; PMachineValue TMP_tmp0_3 = null; PEvent TMP_tmp1_3 = null; PMachineValue TMP_tmp2_1 = null; PEvent TMP_tmp3_1 = null; TMP_tmp0_3 = (PMachineValue)(((PMachineValue)((IPrtValue)DoorV)?.Clone())); TMP_tmp1_3 = (PEvent)(new eSendCommandToResetDoor(null)); currentMachine.TrySendEvent(TMP_tmp0_3, (Event)TMP_tmp1_3); TMP_tmp2_1 = (PMachineValue)(((PMachineValue)((IPrtValue)TimerV)?.Clone())); TMP_tmp3_1 = (PEvent)(new eStartTimer(null)); currentMachine.TrySendEvent(TMP_tmp2_1, (Event)TMP_tmp3_1); }
public Transition Anon_3(Event currentMachine_dequeuedEvent) { PONG currentMachine = this; PMachineValue payload = (PMachineValue)(gotoPayload ?? ((PEvent)currentMachine_dequeuedEvent).Payload); gotoPayload = null; PMachineValue TMP_tmp0_2 = null; PEvent TMP_tmp1_2 = null; PEvent TMP_tmp2_1 = null; TMP_tmp0_2 = ((PMachineValue)((IPrtValue)payload)?.Clone()); TMP_tmp1_2 = new Pong(null); currentMachine.TrySendEvent(TMP_tmp0_2, TMP_tmp1_2); TMP_tmp2_1 = new Success(null); return(currentMachine.TryRaiseEvent(TMP_tmp2_1)); }
public void Anon_1() { Main currentMachine = this; PMachineValue TMP_tmp0_1 = null; PEvent TMP_tmp1_1 = null; PMachineValue TMP_tmp2 = null; PEvent TMP_tmp3 = null; TMP_tmp0_1 = ((PMachineValue)((IPrtValue)pongId)?.Clone()); TMP_tmp1_1 = new Ping(null); TMP_tmp2 = currentMachine.self; currentMachine.SendEvent(TMP_tmp0_1, TMP_tmp1_1, TMP_tmp2); TMP_tmp3 = new Success(null); currentMachine.RaiseEvent(TMP_tmp3); throw new PUnreachableCodeException(); }
public bool Lookup(string name, out PEvent tree) { Scope current = this; while (current != null) { if (current.Get(name, out tree)) { return(true); } current = current.Parent; } tree = null; return(false); }
public int GetDeclNumber(PEvent ev) { if (ev.IsNullEvent) { return(0); } if (ev.IsHaltEvent) { return(1); } // There are two built-in events, which have predetermined numbers. // User-defined events have a minimum id of 2, but GetOrAddNumber // assigns sequentially from 0. return(2 + GetOrAddNumber(userEventNumbering, ev)); }
public void Anon_3() { PONG currentMachine = this; PMachineValue payload = (PMachineValue)(gotoPayload ?? ((PEvent)currentMachine.ReceivedEvent).Payload); gotoPayload = null; PMachineValue TMP_tmp0_2 = null; PEvent TMP_tmp1_2 = null; PEvent TMP_tmp2_1 = null; TMP_tmp0_2 = ((PMachineValue)((IPrtValue)payload)?.Clone()); TMP_tmp1_2 = new Pong(null); currentMachine.SendEvent(TMP_tmp0_2, TMP_tmp1_2); TMP_tmp2_1 = new Success(null); currentMachine.RaiseEvent(TMP_tmp2_1); throw new PUnreachableCodeException(); }
private static void ValidateHandlers(ITranslationErrorHandler handler, Machine machine) { foreach (var state in machine.AllStates()) { if (state.Entry?.Signature.Parameters.Count > 1) { throw handler.MoreThanOneParameterForHandlers(state.SourceLocation, state.Entry.Signature.Parameters.Count); } if (state.Exit?.Signature.Parameters.Count > 0) { throw handler.ExitFunctionCannotTakeParameters(state.SourceLocation, state.Exit.Signature.Parameters.Count); } foreach (KeyValuePair <PEvent, AST.IStateAction> pair in state.AllEventHandlers) { PEvent handledEvent = pair.Key; switch (pair.Value) { case EventDoAction eventDoAction: if (eventDoAction.Target != null && eventDoAction.Target.Signature.ParameterTypes.Count() > 1) { throw handler.MoreThanOneParameterForHandlers(eventDoAction.SourceLocation, eventDoAction.Target.Signature.ParameterTypes.Count()); } break; case EventGotoState eventGotoState: if (eventGotoState.TransitionFunction != null && eventGotoState.TransitionFunction.Signature.ParameterTypes.Count() > 1) { throw handler.MoreThanOneParameterForHandlers(eventGotoState.SourceLocation, eventGotoState.TransitionFunction.Signature.ParameterTypes.Count()); } break; case EventPushState _: case EventDefer _: case EventIgnore _: { break; } } } } }