示例#1
0
        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;
                    }
                    }
                }
            }
        }