예제 #1
0
    def _prepare(self):
        JFileUtils.rmdir(self._source_dir)

        mix_dirs = []
        for i in range(random.randint(1, 21)):
            d = os.path.join(self._source_dir, JOcHelper.var(self._mix_dirs))
            JFileUtils.mkdir(d)
            mix_dirs.append(d)
        self._mix_dirs = mix_dirs

        refs_dir = os.path.join(self._source_dir, JOcHelper.var())
        JFileUtils.mkdir(refs_dir)
        self._refs_dir = refs_dir
예제 #2
0
 def setIncludes(self, classes):
     self._include_classes = classes
     # 添加引用类的导入
     for cls in classes:
         self.imports.append(cls.className + '.h')
     # 添加私有变量
     if (random.random() < 0.3):
         for cls in classes:
             n = JOcHelper.var(self.variables.keys())
             self.variables[n] = (cls.className + '*', None)
예제 #3
0
 def addVarialbe(self, type=None):
     var_list = []
     var_list.extend(self.variables.keys())
     if (self.argNames is not None):
         var_list.extend(self.argNames)
     v = JOcHelper.var(var_list)
     if (type is None):
         type = random.choice(OC_BASE)
     d = JOcHelper.randValue(type)
     self.variables[v] = [type, d]
     return v
예제 #4
0
 def _map_method(self, name, statement, argTypes=None, argNames=None):
     notice = JOcHelper.var(self._api_map.values())
     self._api_map[name] = notice
     method = JOcMethod(self)
     method.scope = '+'
     method.ret = 'void'
     method.messages.append(notice)
     if argTypes is not None:
         method.argTypes = [argTypes]
     if argNames is not None:
         method.argNames = [argNames]
     if statement is not None:
         method.lineTree = self._gen_line(method, statement)
     self.methods.append(method)
예제 #5
0
 def __make__declare(self):
     var_list = self.variables.keys()
     # 生成指令表
     msgNums = 1 + JRand.rand_nearest(4)  # [1, 5]
     for i in range(msgNums):
         while (True):
             n = JOcHelper.var(self.messages)
             if (n not in var_list):
                 self.messages.append(n)
                 break
     # 生成参数表
     argNums = msgNums if (msgNums != 1) else (0 if (
         random.random() < 0.5) else 1)
     if (argNums > 0):
         self.argTypes = []
         self.argNames = []
         for i in range(argNums):
             self.argTypes.append(JRand.chose_nearest(OC_BASE))
             while (True):
                 n = JOcHelper.var(self.argNames)
                 if (n not in var_list):
                     self.argNames.append(n)
                     break