コード例 #1
0
ファイル: ProtoBase.py プロジェクト: icsa-caps/HieraGen
    def copy_trace_or_trans_list_rename_states(self,
                                               start_state: State,
                                               remote_trace: Union[Trace, List[Transition]],
                                               old_trans_to_new_trans_map: Dict[int, Transition],
                                               old_state_to_new_state_map: Dict[str, State],
                                               forbidden_guards: List[str]) \
            -> List[Transition]:

        remote_transitions = remote_trace
        if isinstance(remote_trace, Trace):
            remote_transitions = remote_trace.transitions

        remote_trace_trans_mod = []
        moving_start_state = start_state

        for ind in range(0, len(remote_transitions)):
            cur_transition = remote_transitions[ind]

            # Check if the current transition has been copied before
            cur_trans_hash = cur_transition.get_hash()
            if cur_trans_hash in old_trans_to_new_trans_map:
                remote_trace_trans_mod.append(
                    old_trans_to_new_trans_map[cur_trans_hash])
                moving_start_state = old_trans_to_new_trans_map[
                    cur_trans_hash].finalState
            else:
                if cur_transition.startState == cur_transition.finalState:
                    new_trans = self._CopyModifyTransition(
                        cur_transition, moving_start_state, moving_start_state)
                    start_state.addtransitions(new_trans)
                else:
                    final_state = None
                    if ind == len(remote_transitions) - 1:
                        final_state = cur_transition.finalState

                    moving_start_state, new_trans = self.copy_modify_state(
                        moving_start_state, remote_transitions[ind],
                        old_state_to_new_state_map, forbidden_guards,
                        final_state)

                remote_trace_trans_mod.append(new_trans)
                old_trans_to_new_trans_map[cur_trans_hash] = new_trans

        if remote_transitions[0].startState == remote_transitions[
                -1].finalState:
            remote_trace_trans_mod[-1].finalState = start_state

        remote_trace_trans_mod[0].startState = start_state

        return remote_trace_trans_mod
コード例 #2
0
    def _CopyState(self,
                   startstate: State,
                   guard,
                   stateset,
                   stablestates,
                   newstates,
                   dummy_state,
                   defer_operations: List[Tuple[Message,
                                                List[CommonTree]]] = None):
        newstate = State(
            self._CheckStateName(
                startstate.getstatename() + "__" + guard + "_" +
                stateset.getstablestate().getstatename(), stateset),
            self.access, self.evict)

        newstates.append(newstate)
        stateset.addendstate(newstate)

        #newstate.add_tail_list_defer_msg_operations(copy.copy(startstate.get_defer_msg_operation()))

        if defer_operations:
            newstate.add_tail_list_defer_msg_operations(defer_operations)

        for transition in startstate.getdataack():
            newtrans = copy.copy(transition)
            # Emit non deferred messages
            #newtrans.add_out_msg_list(copy.copy(transition.getoutmsg()))
            newtrans.setstartstate(newstate)

            if transition.getstartstate() == transition.getfinalstate():
                newtrans.setfinalstate(newstate)
            else:
                finalstate = [
                    finalstate for finalstate in stablestates
                    if finalstate == newtrans.getfinalstate().getstatename()
                ]
                if finalstate:
                    newtrans.setfinalstate(dummy_state)

                else:
                    finalstate = self._CopyState(newtrans.getfinalstate(),
                                                 guard, stateset, stablestates,
                                                 newstates, dummy_state,
                                                 defer_operations)

                    newtrans.setfinalstate(finalstate)
            newstate.addtransitions(newtrans)
        return newstate
コード例 #3
0
    def _CopyModifyState(self, startstate, transition):
        newstate = State(
            startstate.getstatename() + "_" + transition.getguard(),
            self.access, self.evict)
        for datatrans in startstate.getdataack():
            newtrans = copy.copy(datatrans)
            newtrans.setstartstate(newstate)
            newstate.addtransitions(newtrans)

        for startset in transition.getfinalstate().getstatesets():
            startset.addstartstate(newstate)

        for endset in startstate.getendstatesets():
            endset.addendstate(newstate)

        # Create vertice
        startstate.addtransitions(
            self._CopyModifyTransition(transition, startstate, newstate))

        return newstate
コード例 #4
0
    def _MergeGivenStates(self, mergestates, transitionmap, statesets):
        mergestates.sort(key=lambda x: len(x.getstatename()))
        # mergestates.sort(key=lambda x: len(x.getstatename()))

        # Make new state
        newstate = State(mergestates[0].getstatename(), self.access,
                         self.evict)

        for transition in transitionmap.values():
            newstate.addtransitions(transition[0])

        # Explore context
        startstatesets = []
        endstatesets = []

        for state in mergestates:
            startstatesets += state.getstartstatesets()
            endstatesets += state.getendstatesets()

        startstatesets = list(set(startstatesets))
        endstatesets = list(set(endstatesets))

        # Remove old states from all state sets
        for stateset in statesets.values():
            stateset.removestates(mergestates)

        # Now add new state to sets
        for stateset in startstatesets:
            stateset.addstartstate(newstate)

        for stateset in endstatesets:
            stateset.addendstate(newstate)

        # Update links
        for stateset in statesets.values():
            for state in stateset.getstates():
                for replacestate in mergestates:
                    state.replaceremotestate(replacestate, newstate)
コード例 #5
0
ファイル: ProtoBase.py プロジェクト: icsa-caps/HieraGen
    def copy_modify_state(self,
                          startstate: State,
                          transition: Transition,
                          old_state_to_new_state_map: Dict[str, State],
                          forbidden_guards: List[str],
                          final_state: [State, None] = None):
        # If a known final state exists, then
        if final_state:
            newstate = final_state
            if str(final_state) in old_state_to_new_state_map:
                newstate = old_state_to_new_state_map[str(final_state)]
        else:
            new_state_str = startstate.getstatename(
            ) + "_" + transition.getguard()
            if new_state_str in old_state_to_new_state_map:
                newstate = old_state_to_new_state_map[new_state_str]
            else:
                newstate = State(new_state_str, self.access, self.evict)
                old_state_to_new_state_map[new_state_str] = newstate

                # The new_state replaces the final state so it must possess all local access permissions
                for trans in transition.startState.setTrans:
                    if str(trans.inMsg) in forbidden_guards:
                        continue

                    if trans.startState == trans.finalState:
                        new_trans = self._CopyModifyTransition(
                            trans, newstate, newstate)
                        newstate.addtransitions(new_trans)

                for trans in transition.finalState.setTrans:
                    if str(trans.inMsg) in forbidden_guards:
                        continue

                    if trans.startState == trans.finalState:
                        new_trans = self._CopyModifyTransition(
                            trans, newstate, newstate)
                        newstate.addtransitions(new_trans)

                # The new_state replaces the final state so it must possess all local access permissions
                for trans in startstate.setTrans:
                    if str(trans.inMsg) in forbidden_guards:
                        continue

                    if trans.startState == trans.finalState:
                        new_trans = self._CopyModifyTransition(
                            trans, newstate, newstate)
                        newstate.addtransitions(new_trans)

                for startset in transition.getfinalstate().getstatesets():
                    startset.addstartstate(newstate)

                for endset in startstate.getendstatesets():
                    endset.addendstate(newstate)

        # Create vertice
        new_trans = self._CopyModifyTransition(transition, startstate,
                                               newstate)
        startstate.addtransitions(new_trans)

        return newstate, new_trans