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
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
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
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
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
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
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
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
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
def _mod_state_func(node, transaction: Transaction): transaction.addoperation(node) return transaction
def _SetFunctions(node, transaction: Transaction): transaction.addoperation(node) return transaction
def _HandleEndif(node=0, transaction: Transaction = 0): transaction.endif() return transaction
def _HandleCond(node, transaction: Transaction): transaction.getcurtransition().addoperation(node) transaction.getcurtransition().addcond(''.join(toStringList(node))) return transaction
def _NewIfElseFork(self, node, transaction: Transaction): transaction.newifelse() self._CreateProc(node, transaction) return transaction
def _CreateIfElse(self, node, transaction: Transaction): transaction.newifconstr() self._CreateProc(node, transaction) return transaction