示例#1
0
 def __innerexpand__secondfiltering__(self, names2x, lines2x, puthere):
     global alpha
     __resetalphabet__()
     cnt = 0
     for name in names2x:
         for line in lines2x:
             newline = line
             newline = newline.replace(__TAG_STATENAME_SMALL_CAMEL__,
                                       camel_case_small(name))
             newline = newline.replace(__TAG_STATENAME__, name)
             newline = newline.replace(__TAG_EVENTNAME_SMALL_CAMEL__,
                                       camel_case_small(name))
             newline = newline.replace(__TAG_EVENTNAME__, name)
             newline = newline.replace(__TAG_ACTIONNAME__, name)
             newline = newline.replace(__TAG_ACTIONNAME_SMALL_CAMEL__,
                                       camel_case_small(name))
             newline = newline.replace(__TAG_GUARDNAME__, name)
             newline = newline.replace(__TAG_GUARDNAME_SMALL_CAMEL__,
                                       camel_case_small(name))
             newline = newline.replace(__TAG_ABC__, chr(alpha))
             newline = newline.replace(__TAG_123__, str(cnt))
             tabcnt = newline.count('    ')
             newline = newline.replace(__TAG_EVENT_SIGNATURE__,
                                       self.__get_event_signature__(name))
             # __TAG_EVENT_MEMBERINST__ -> PTR
             if self.hasTag(newline, __TAG_EVENT_MEMBERINST__
                            ) and self.hasMemberName(newline):
                 line_member = self.extractMemberNameAndTag(newline)
                 newline = newline.replace(
                     line_member[0],
                     self.__instantiate_event_struct_member(
                         name, tabcnt, True, line_member[1]))
             else:
                 newline = newline.replace(
                     __TAG_EVENT_MEMBERINST__,
                     self.__instantiate_event_struct_member(
                         name, tabcnt, True))  # PTR
             # __TAG_LITE_EVENT_MEMBERINST__ -> NO PTR
             if self.hasTag(newline, __TAG_LITE_EVENT_MEMBERINST__
                            ) and self.hasMemberName(newline):
                 line_member = self.extractMemberNameAndTag(newline)
                 newline = newline.replace(
                     line_member[0],
                     self.__instantiate_event_struct_member(
                         name, tabcnt, False, line_member[1]))
             else:
                 newline = newline.replace(
                     __TAG_LITE_EVENT_MEMBERINST__,
                     self.__instantiate_event_struct_member(
                         name, tabcnt, False))  # NO PTR
             newline = newline.replace(
                 __TAG_EVENT_MEMBERDECL__,
                 self.__declare_event_struct_members(name, tabcnt))
             if newline == '\n' or newline == '' or newline == '\r\n' or newline.replace(
                     ' ', '') == "" or newline.replace(' ', '').replace(
                         '\n', '').replace('\r', '') == "":
                 continue
             puthere.append(newline)
         cnt = cnt + 1
         __getnextalphabet__()
示例#2
0
    def __set_transitions_per_state(self):
        for tableline in self.transition_table:
            transition = OrderedDict()
            if tableline[self.ACTION] != "" and tableline[
                    self.ACTION].lower() != "none":
                transition[__TAG_ACTIONNAME__] = tableline[self.ACTION]
                transition[__TAG_ACTIONNAME_SMALL_CAMEL__] = camel_case_small(
                    tableline[self.ACTION])
            if tableline[self.GUARD] != "" and tableline[
                    self.GUARD].lower() != "none":
                transition[__TAG_GUARDNAME__] = tableline[self.GUARD]
                transition[__TAG_GUARDNAME_SMALL_CAMEL__] = camel_case_small(
                    tableline[self.GUARD])
            if tableline[self.NEXT_STATE] != "" and tableline[
                    self.NEXT_STATE].lower() != "none":
                transition[__TAG_NEXTSTATENAME__] = tableline[self.NEXT_STATE]
                transition[
                    __TAG_NEXTSTATENAME_SMALL_CAMEL__] = camel_case_small(
                        tableline[self.NEXT_STATE])

            if tableline[self.START_STATE] != "" and tableline[
                    self.START_STATE].lower() != "none":
                if not tableline[self.START_STATE] in self.transitionsperstate:
                    self.transitionsperstate[tableline[
                        self.START_STATE]] = OrderedDict()

            if tableline[self.EVENT] != "" and tableline[
                    self.EVENT].lower() != "none":
                if not tableline[self.EVENT] in self.transitionsperstate[
                        tableline[self.START_STATE]]:
                    self.transitionsperstate[tableline[self.START_STATE]][
                        tableline[self.EVENT]] = []
                self.transitionsperstate[tableline[self.START_STATE]][
                    tableline[self.EVENT]].append(transition)
示例#3
0
 def __innerexpand_sml__(self, smmodel, sml_entry_exit, puthere):
     tt_out = "                // " + even_space(
         "Start", smmodel.maxlenSTART_STATE + 8) + even_space(
             "+Event", smmodel.maxlenEVENT + 10) + even_space(
                 "[ Guard ]", smmodel.maxlenGUARD + 6) + even_space(
                     "/ Action", smmodel.maxlenACTION + 4) + even_space(
                         " = Next", 0) + '\n'
     startStateHasEntryExit = {}
     for i, ttline in enumerate(smmodel.transition_table):
         if i == 0:  # initial state
             tt_out += "                 *"
         else:
             tt_out += "                , "
         tt_out += even_space(
             'state<' + self.__transitiontable_replace_NONE__(
                 ttline[smmodel.START_STATE]) + '>',
             smmodel.maxlenSTART_STATE + 9) + '+'
         tt_out += even_space(
             'event<' +
             self.__transitiontable_replace_NONE__(ttline[smmodel.EVENT]) +
             '>', smmodel.maxlenEVENT + 9) + ' '
         tt_out += even_space(
             '[' + self.__transitiontableLITE_guard_replace_NONE__(
                 camel_case_small(ttline[smmodel.GUARD])) + ']',
             smmodel.maxlenGUARD + 4) + ' / '
         tt_out += even_space(
             self.__transitiontableLITE_action_replace_NONE__(
                 camel_case_small(ttline[smmodel.ACTION])),
             smmodel.maxlenACTION + 2)
         if ttline[smmodel.NEXT_STATE].lower(
         ) != 'none':  # to not get transitions into/outof state on actions that dont change the state...
             tt_out += ' = ' + even_space(
                 'state<' +
                 self.__transitiontableLITE_nextstate_replace_NONE__(
                     ttline[smmodel.NEXT_STATE],
                     ttline[smmodel.START_STATE]) + '>', 0)
         tt_out += '\n'
         puthere.append(tt_out)
         tt_out = ""
         # State entry/exit, once only
         if not (ttline[smmodel.START_STATE]
                 in startStateHasEntryExit) and sml_entry_exit:
             startStateHasEntryExit[ttline[smmodel.START_STATE]] = True
             tt_out += "                , state<" + ttline[
                 smmodel.
                 START_STATE] + "> + boost::sml::on_entry<_> / " + camel_case_small(
                     ttline[smmodel.START_STATE]) + 'OnEntry\n'
             tt_out += "                , state<" + ttline[
                 smmodel.
                 START_STATE] + "> + boost::sml::on_exit<_> / " + camel_case_small(
                     ttline[smmodel.START_STATE]) + 'OnExit'
             tt_out += '\n'
             puthere.append(tt_out)
             tt_out = ""
示例#4
0
    def __loadtemplates_firstfiltering__(self, smmodel):
        """
        See baseclass implementation. This just prepares the dictionary of things to replace
        for this type of codegeneration.

        @param smmodel:
        @return: cgen.CCodeModel, a dictionary -> {filename,[lines]}
        """

        dict_to_replace_lines = {}
        dict_to_replace_lines[__TAG_SM_NAME_UPPER__] = caps(
            smmodel.statemachinename)
        dict_to_replace_lines[__TAG_SM_NAME_SMALL_CAMEL__] = camel_case_small(
            smmodel.statemachinename)
        dict_to_replace_lines[__TAG_SM_NAME__] = smmodel.statemachinename
        dict_to_replace_lines[__TAG_CLASS_NAME__] = smmodel.statemachinename
        dict_to_replace_lines[
            __TAG_PyIFGen_NAME__] = smmodel.pythoninterfacegeneratorfilename.replace(
                '.py', '')  # hack : for tcpgen simple templates,
        if not dict_to_replace_lines[__TAG_PyIFGen_NAME__]:
            dict_to_replace_lines[__TAG_PyIFGen_NAME__] = self.vpp_filename
        dict_to_replace_lines[__TAG_NAMESPACE__] = smmodel.namespacename
        dict_to_replace_lines[__TAG_AUTHOR__] = self.author
        dict_to_replace_lines[__TAG_GROUP__] = self.group
        dict_to_replace_lines[__TAG_BRIEF__] = self.brief
        dict_to_replace_lines[
            __TAG_DECLSPEC_DLL_EXPORT__] = smmodel.declspecdllexport

        dict_to_replace_filenames = {}
        dict_to_replace_filenames["TEMPLATE_"] = smmodel.statemachinename

        return CBASEGenerator.__loadtemplates_firstfiltering__(
            self, dict_to_replace_lines, dict_to_replace_filenames)
示例#5
0
 def __innerexpand_transitionsperguard(self, eventName, transitionList,
                                       lines2x, puthere):
     ex_transition = False
     snipped_to_expand = []
     for line in lines2x:
         begin = line.find(__TAG_PGT_BEGIN__) > -1
         ex_transition = begin or ex_transition
         if ex_transition and line.find(__TAG_PGT_END__) > -1:
             # Should now have all the guard/action/next repeats.
             #----
             for transitionDict in transitionList:
                 for l in snipped_to_expand:
                     for k, v in transitionDict.items():
                         # for those that are present but who have alternate text when not present.
                         if self.hasTag(l, k):
                             l = self.removeTag(l)
                         l = l.replace(k, v)
                     l = l.replace(__TAG_EVENTNAME__, eventName).replace(
                         __TAG_EVENTNAME_SMALL_CAMEL__,
                         camel_case_small(eventName))
                     # If there is no guard, or next state (transitions are not mandated to have either), just remove it (or replace it with the alternative text). Leave no hanging code.
                     if self.hasTag(l, __TAG_GUARDNAME__) or self.hasTag(
                             l, __TAG_NEXTSTATENAME__):
                         line_member = self.extractMemberNameAndTag(l)
                         if line_member[
                                 1]:  # alternative text is embedded in the tag.
                             whitespace = len(l) - len(l.lstrip())
                             puthere.append(whitespace * ' ' +
                                            line_member[1] + '\n')
                     elif l.find(__TAG_GUARDNAME__) == -1 and l.find(
                             __TAG_NEXTSTATENAME__) == -1:
                         puthere.append(l)
             #----
             ex_transition = False
         if ex_transition:
             if not begin:
                 snipped_to_expand.append(line)
         else:
             if line.find(__TAG_PGT_END__) == -1:
                 puthere.append(
                     line.replace(__TAG_EVENTNAME__, eventName).replace(
                         __TAG_EVENTNAME_SMALL_CAMEL__,
                         camel_case_small(eventName)))
示例#6
0
 def __innerexpand_actionsignatures__(self, states2x, lines2x, puthere):
     global alpha
     __resetalphabet__()
     cnt = 0
     for key, (actionname, eventname) in states2x.items():
         if eventname == "" or eventname.lower() == 'none':
             eventname = "NONE"
         elif eventname.lower() == 'any':
             eventname = "ANY"
         for line in lines2x:
             puthere.append(
                 line.replace(__TAG_ACTIONNAME_SMALL_CAMEL__,
                              camel_case_small(actionname)).replace(
                                  __TAG_ACTIONNAME__, actionname).replace(
                                      __TAG_EVENTNAME_SMALL_CAMEL__,
                                      camel_case_small(eventname)).replace(
                                          __TAG_EVENTNAME__,
                                          eventname).replace(
                                              __TAG_ABC__,
                                              chr(alpha)).replace(
                                                  __TAG_123__, str(cnt)))
         cnt = cnt + 1
         __getnextalphabet__()