Exemplo n.º 1
0
        public static void ValidateNoStaticHandlers(ITranslationErrorHandler handler, Machine machine)
        {
            foreach (State state in machine.AllStates())
            {
                bool illegalUsage = state.Entry != null && IsStaticOrForeign(state.Entry);
                if (illegalUsage)
                {
                    throw handler.StaticFunctionNotAllowedAsHandler(state.SourceLocation,
                                                                    state.Entry.Name);
                }

                illegalUsage = state.Exit != null && IsStaticOrForeign(state.Exit);
                if (illegalUsage)
                {
                    throw handler.StaticFunctionNotAllowedAsHandler(state.SourceLocation,
                                                                    state.Exit.Name);
                }

                foreach (KeyValuePair <PEvent, AST.IStateAction> pair in state.AllEventHandlers)
                {
                    switch (pair.Value)
                    {
                    case EventDoAction eventDoAction:
                        if (eventDoAction.Target != null && IsStaticOrForeign(eventDoAction.Target))
                        {
                            throw handler.StaticFunctionNotAllowedAsHandler(eventDoAction.SourceLocation,
                                                                            eventDoAction.Target.Name);
                        }

                        break;

                    case EventGotoState eventGotoState:
                        if (eventGotoState.TransitionFunction != null &&
                            IsStaticOrForeign(eventGotoState.TransitionFunction))
                        {
                            throw handler.StaticFunctionNotAllowedAsHandler(eventGotoState.SourceLocation,
                                                                            eventGotoState.TransitionFunction.Name);
                        }

                        break;

                    case EventDefer _:
                    case EventIgnore _:
                    case EventPushState _:
                        break;

                    default:
                        throw handler.InternalError(pair.Value.SourceLocation,
                                                    new System.Exception("Unknown transition type parsed, report to the P team"));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void ValidateNoStaticHandlers(ITranslationErrorHandler handler, Machine machine)
        {
            foreach (var state in machine.AllStates())
            {
                var illegalUsage = state.Entry != null && IsStaticOrForeign(state.Entry);
                if (illegalUsage)
                {
                    throw handler.StaticFunctionNotAllowedAsHandler(state.SourceLocation,
                                                                    state.Entry.Name);
                }

                illegalUsage = state.Exit != null && IsStaticOrForeign(state.Exit);
                if (illegalUsage)
                {
                    throw handler.StaticFunctionNotAllowedAsHandler(state.SourceLocation,
                                                                    state.Exit.Name);
                }

                foreach (var pair in state.AllEventHandlers)
                {
                    switch (pair.Value)
                    {
                    case EventDoAction eventDoAction:
                        if (eventDoAction.Target != null && IsStaticOrForeign(eventDoAction.Target))
                        {
                            throw handler.StaticFunctionNotAllowedAsHandler(eventDoAction.SourceLocation,
                                                                            eventDoAction.Target.Name);
                        }

                        break;

                    case EventGotoState eventGotoState:
                        if (eventGotoState.TransitionFunction != null &&
                            IsStaticOrForeign(eventGotoState.TransitionFunction))
                        {
                            throw handler.StaticFunctionNotAllowedAsHandler(eventGotoState.SourceLocation,
                                                                            eventGotoState.TransitionFunction.Name);
                        }

                        break;
                    }
                }
            }
        }