3 from optparse import OptionParser
5 parser = OptionParser ()
6 parser.add_option ("--switch", action = "store_true", dest = "switch")
7 parser.add_option ("--one-method-if", action = "store_true", dest = "one_method_if")
9 (options, args) = parser.parse_args ()
11 def print_file (file_name):
12 f = open (file_name, "r")
17 print_file ("descriptor-tests-prefix.cs")
19 print ("public struct NoRef1 { int x; }")
20 for i in range (1, 17):
21 print ("public struct NoRef%d { NoRef%d a, b; }" % (1 << i, 1 << (i-1)))
30 for offset in range (0, max_offset, 19):
31 for bitmap in range (0, max_bitmap):
32 name = "Bitmap%dSkip%d" % (bitmap, offset)
34 print ("public struct %s : Filler {" % name)
35 for i in range (0, 16):
38 print (" NoRef%d skip%d;" % (bit, bit))
39 for i in range (0, 9):
42 print (" object ref%d;" % i)
44 print (" int bit%d;" % i)
45 print (" public void Fill (object[] refs) {")
46 for i in range (0, 9):
49 print (" ref%d = refs [%d];" % (i, i))
52 print ("public class %sWrapper : Filler {" % name)
53 print (" %s[] a;" % name)
54 print (" public %sWrapper () {" % name)
55 print (" a = new %s [1];" % name)
57 print (" public void Fill (object[] refs) {")
58 print (" a [0].Fill (refs);")
62 def search_method_name (left, right):
63 return "MakeAndFillL%dR%d" % (left, right)
68 print (" b = new %sWrapper ();" % name)
70 print (" b = new %s ();" % name)
71 print ("b.Fill (refs); return b;")
73 def gen_binary_search_body (left, right, one_method):
75 gen_new (names [left])
77 mid = (left + right) // 2
78 print ("if (which < %d) {" % mid)
80 gen_binary_search_body (left, mid, one_method)
82 print ("return %s (which, refs, wrap);" % search_method_name (left, mid))
85 gen_binary_search_body (mid, right, one_method)
87 print ("return %s (which, refs, wrap);" % search_method_name (mid, right))
90 def gen_binary_search (left, right, one_method):
91 name = search_method_name (left, right)
92 print ("public static Filler %s (int which, object[] refs, bool wrap) {" % name)
93 gen_binary_search_body (left, right, one_method)
95 if not one_method and left + 1 < right:
96 mid = (left + right) // 2
97 gen_binary_search (left, mid, one_method)
98 gen_binary_search (mid, right, one_method)
101 print ("public class Bitmaps {")
103 print (" public static Filler MakeAndFill (int which, object[] refs, bool wrap) {")
104 print (" switch (which) {")
105 for i in range (0, len (names)):
106 print (" case %d: {" % i)
109 print (" default: return null;")
113 method_name = gen_binary_search (0, len (names), options.one_method_if)
114 print (" public static Filler MakeAndFill (int which, object[] refs, bool wrap) {")
115 print (" if (which >= %d) return null;" % len (names))
116 print (" return %s (which, refs, wrap);" % method_name)
118 print (" public const int NumWhich = %d;" % len (names))
123 print_file ("descriptor-tests-driver.cs")