Anonymous avatar Anonymous committed cd54727

changed iterables to no longer use pgen options

Comments (0)

Files changed (3)

codegen/iterables.py

 
 from pygen.cgen import *
-from arithgen import ArithGen
-
+from arithgen import ArithGen, IntegerGen, gen_max_int_gen
 from utils import eval_branches, FunctionGenerator
 
 import pgen
         self.stats = stats
 
     def get_iterable(self, literals):
-        opts = self.opts["iter_gen"]
-
-        types = list(opts["type"]) # iterables that dont require size
+        types = [(1.0, "xrange"), (1.0, "range")] # iterables that dont require size
         if self.stats.prog_size > 0:
-            types = types + opts["children"]
+            types = types + [(1.0, "list_comp_gen"), (1.0, "list_comp_list"), (1.0, "yield_func")]
 
         branch = eval_branches(self.rng, types)
 
             self.stats.prog_size -= 1
 
             gen = ListComprehensionGenerator(self.module, self.stats, self.opts, self.rng)
-            return [gen.get_generator(self.opts["list_comp_small_int"], literals)]
+            return [gen.get_generator(literals)]
 
         if branch == "list_comp_list":
             self.stats.prog_size -= 1
 
             gen = ListComprehensionGenerator(self.module, self.stats, self.opts, self.rng)
-            return [gen.get_list(self.opts["list_comp_small_int"], literals)]
+            return [gen.get_list(literals)]
 
         if branch == "yield_func":
             self.stats.prog_size -= 1
     def generate(self, args_num, pliterals):
         '''Returns a CallStatement'''
 
-        opts = self.opts["yieldfunction"]
-
         args = self.generate_arguments(args_num)
         f = self.create_function(args)
         self.module.content.insert(0, f)
 
-        literals = list(args) + [n.set_rng(self.rng) for n in opts["numbers"]]
+        literals = list(args) + [n.set_rng(self.rng) for n in [gen_max_int_gen(), IntegerGen(-1000, 1000)]]
 
         if self.stats.prog_size > 0:
             self.generate_child(f, literals)
         self.rng = rng
         self.stats = stats
 
-    def get_expression(self, opts, literals):
-        literals = list(literals) + [n.set_rng(self.rng) for n in opts["numbers"]]
-        branch = eval_branches(self.rng, opts["type"])
+    def get_expression(self, literals):
+        literals = list(literals) + [n.set_rng(self.rng) for n in [IntegerGen(-10, 10)]]
+        branch = eval_branches(self.rng, [(1.0, "thin"), (1.0, "fat")])
 
         iterable = IterableGenerator(self.module, self.stats, self.opts, self.rng).get_iterable(literals)
 
             exp = ArithGen(1, self.rng).generate(literals)
         return ["%s for i in " % (exp, ), iterable]
 
-    def get_generator(self, opts, literals):
-        return ["(", self.get_expression(opts, literals), ")"]
-    def get_list(self, opts, literals):
-        return ["[", self.get_expression(opts, literals), "]"]
+    def get_generator(self, literals):
+        return ["(", self.get_expression(literals), ")"]
+    def get_list(self, literals):
+        return ["[", self.get_expression(literals), "]"]
 
 
 class Stats(object):
     arg_number = 0
-    prog_size = 100
+    prog_size = 0
 
 class TestClassesGenerator(unittest.TestCase):
 
         return '\n'.join(result)
 
     def setUp(self):
-        self.opts = {'iter_gen' : {'type' : [(1.0, "xrange")], 'children' : []}}
+        self.opts = {}
         self.module = {}
         self.stats = Stats()
 
                 "numbers" : [IntegerGen(-10, 10)],
                 "if" : 0.10,
                },
-    "list_comp_small_int" : {
-                "numbers" : [IntegerGen(-10, 10)],
-                "type" : [(1.0, "thin"), (1.0, "fat")],
-               },
-    "iter_gen" : {
-                "type" : [(1.0, "xrange"), (1.0, "range")],
-                "children" : [(1.0, "list_comp_gen"), (1.0, "list_comp_list"), (1.0, "yield_func")],
-               },
-    "yieldfunction" : {
-                "numbers" : [gen_max_int_gen(), IntegerGen(-1000, 1000)],
-               },
     "change_global" : {
                 "numbers" : [IntegerGen(-10, 10)],
                },
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.