コード例 #1
0
 def _EndTransaction(self, node=0, transaction: Transaction = 0):
     # Check if the final state has changed from default
     # If not return to start state
     curtrans = transaction.getcurtransition()
     if curtrans.getfinalstate().getstatename() == transaction.getinterfinalstate():
         curtrans.setfinalstate(transaction.getstartstate())
     return transaction
コード例 #2
0
    def _CreateMsg(self, message, transaction: Transaction):
        # msg: format
        # [object, type, src, dest, payload..]

        varname = self._AssignVarName(message.getParent())

        msg = message.getChildren()
        msgobj = msg[0].getText()

        if not list(filter(lambda x: msgobj in x.getname(), self.msgNode)):
            self.perror("Object related to constructor undefined")

        if msg[1].getChildren():
            self.perror("Expected message identifier")

        msgtype = msg[1].getText()
        msgsrc = ''.join(toStringList(msg[2]))
        msgdest = ''.join(toStringList(msg[3]))

        payload = []
        for ind in range(4, len(msg)):
            payload.append(''.join(toStringList(msg[ind])))

        msgconstr = Message(msgtype, msgobj, msgsrc, msgdest, payload, msgobj)
        transaction.addmessage(varname, msgconstr)

        if not list(filter(lambda x: msgtype == x, self.msgTypes)):
            self.msgTypes.append(msgtype)

        return transaction
コード例 #3
0
    def _SendMsg(self, message, transaction: Transaction):
        transaction.addoperation(message)

        send = toStringList(message)
        msg = transaction.getmessage(send[2])
        msg.setvc(send[1])
        transaction.addoutmsg(msg)

        return transaction
コード例 #4
0
    def _TransactionFork(self, node, transaction: Transaction = 0):
        transaction.endifconstr()
        curtrans = transaction.getcurtransition()
        if curtrans.getfinalstate().getstatename() == transaction.getinterfinalstate():
            # Generate new intermediate state name
            finalstate = curtrans.getstartstate().getstatename() + "_" + curtrans.getguard()
            curtrans.getfinalstate().setstatename(finalstate)
            self.pdebug(transaction.getcurtransition().pbase())

        self._CreateProc(node, transaction)
        return transaction
コード例 #5
0
    def _SetTransGuard(self, node, transaction: Transaction = 0):
        guardtype = node.getChild(0).toString()
        guardmsg = Message(guardtype)

        if not list(filter(lambda x: guardtype == x, self.msgTypes)):
            self.msgTypes.append(guardtype)

        # Append new transition to tree (When is always succeded by a guard
        prenode = transaction.getcurtransitionode()
        startstate = transaction.getcurtransition().getfinalstate()
        finalstate = StateNode(transaction.getinterfinalstate(), self.Accesses)
        transaction.newwhen(startstate, finalstate, guardmsg, prenode)

        return transaction
コード例 #6
0
    def _EndTransition(self, node=0, transaction: Transaction = 0):
        endnodes = transaction.endifconstr()

        # Check if the final state has changed from default
        # If not loop in intermediate state
        if not endnodes:
            transition = [transaction.getcurtransition()]
        else:
            transition = []
            for entry in endnodes:
                transition.append(entry.getdata())

        for curtrans in transition:
            if curtrans.getfinalstate().getstatename() == transaction.getinterfinalstate():
                curtrans.getfinalstate().setstatename(curtrans.getstartstate().getstatename())

        # return to preceeding tree node
        assert not transaction.getcurtransitionode() == transaction.endwhen(), "Unexpected behaviour"

        return transaction
コード例 #7
0
    def _CreateAssign(self, assign, transaction: Transaction):

        transaction.addoperation(assign)

        # Assign new variable name
        # [left op assign]
        assigndef = assign.getChildren()

        # Check for object initialization
        for comp in assigndef:
            if comp.getChildren():
                if not list(filter(lambda x: comp.getText() == x, self.msgTypes)):
                    try:
                        method_fct = self.AssignObj[comp.getText()]
                    except KeyError:
                        method_fct = 0

                    if method_fct:
                        method = getattr(self, method_fct, lambda: '__UnknownNode__')
                        transaction = method(comp, transaction)

        # Set state name
        if assigndef[0].toString() == transaction.getinterfinalstate():
            transaction.setfinalstate(assigndef[2].toString())
            self.pdebug(transaction.getcurtransition().pbase())

        return transaction
コード例 #8
0
    def _EndProcess(self, comp=0, transaction: Transaction = 0):
        nrinit = transaction.getnrtransitions()
        endnodes = transaction.endifconstr()
        if endnodes:
            for node in endnodes:
                curtrans = node.getdata()
                if curtrans.getfinalstate().getstatename() == transaction.getinterfinalstate():
                    curtrans.getfinalstate().setstatename(curtrans.getstartstate().getstatename())
        else:
            curtrans = transaction.getcurtransition()
            if curtrans.getfinalstate().getstatename() == transaction.getinterfinalstate() \
                    and curtrans.getfinalstate().getstatename() == self.State:
                    curtrans.getfinalstate().setstatename(curtrans.getstartstate().getstatename())

        transaction.pushtransition()
        self.pdebug("New transitions due to fork: " + str(transaction.getnrtransitions() - nrinit))

        return transaction
コード例 #9
0
    def _CreateTrans(self, trans, transaction):
        if not isinstance(transaction, int):
            perror("Nested transactions are not permited")

        transsetup = toStringList(trans)

        # Static format
        startstate = StateNode(transsetup[1], self.Accesses)

        if len(transsetup) > 3:
            finalstate = StateNode(transsetup[3], self.Accesses)
        else:
            finalstate = StateNode(self.State, self.Accesses)

        transaction = Transaction(startstate, transsetup[2], finalstate)

        return transaction
コード例 #10
0
 def _mod_state_func(node, transaction: Transaction):
     transaction.addoperation(node)
     return transaction
コード例 #11
0
 def _SetFunctions(node, transaction: Transaction):
     transaction.addoperation(node)
     return transaction
コード例 #12
0
 def _HandleEndif(node=0, transaction: Transaction = 0):
     transaction.endif()
     return transaction
コード例 #13
0
 def _HandleCond(node, transaction: Transaction):
     transaction.getcurtransition().addoperation(node)
     transaction.getcurtransition().addcond(''.join(toStringList(node)))
     return transaction
コード例 #14
0
 def _NewIfElseFork(self, node, transaction: Transaction):
     transaction.newifelse()
     self._CreateProc(node, transaction)
     return transaction
コード例 #15
0
 def _CreateIfElse(self, node, transaction: Transaction):
     transaction.newifconstr()
     self._CreateProc(node, transaction)
     return transaction