3 from __future__ import print_function
4 from optparse import OptionParser
7 parser = OptionParser ()
8 parser.add_option ("--switch", action = "store_true", dest = "switch")
9 parser.add_option ("--one-method-if", action = "store_true", dest = "one_method_if")
11 (options, args) = parser.parse_args ()
13 def print_file (file_name):
14 f = open (file_name, "r")
16 sys.stdout.write (line + " ")
20 print_file ("descriptor-tests-prefix.cs")
22 print ("public struct NoRef1 { int x; }")
23 for i in range (1, 17):
24 print ("public struct NoRef{0} {{ NoRef{1} a, b; }}".format (1 << i, 1 << (i-1)))
33 for offset in range (0, max_offset, 19):
34 for bitmap in range (0, max_bitmap):
35 name = "Bitmap{0}Skip{1}".format (bitmap, offset)
37 print ("public struct {0} : Filler {{".format (name))
38 for i in range (0, 16):
41 print (" NoRef{0} skip{1};".format (bit, bit))
42 for i in range (0, 9):
45 print (" object ref{0};".format (i))
47 print (" int bit{0};".format (i))
48 print (" public void Fill (object[] refs) {")
49 for i in range (0, 9):
52 print (" ref{0} = refs [{1}];".format (i, i))
55 print ("public class {0}Wrapper : Filler {{".format (name))
56 print (" {0}[] a;".format (name))
57 print (" public {0}Wrapper () {{".format (name))
58 print (" a = new {0} [1];".format (name))
60 print (" public void Fill (object[] refs) {")
61 print (" a [0].Fill (refs);")
65 def search_method_name (left, right):
66 return "MakeAndFillL{0}R{1}".format (left, right)
71 print (" b = new {0}Wrapper ();".format (name))
73 print (" b = new {0} ();".format (name))
74 print ("b.Fill (refs); return b;")
76 def gen_binary_search_body (left, right, one_method):
78 gen_new (names [left])
80 mid = (left + right) // 2
81 print ("if (which < {0}) {{".format (mid))
83 gen_binary_search_body (left, mid, one_method)
85 print ("return {0} (which, refs, wrap);".format (search_method_name (left, mid)))
88 gen_binary_search_body (mid, right, one_method)
90 print ("return {0} (which, refs, wrap);".format (search_method_name (mid, right)))
93 def gen_binary_search (left, right, one_method):
94 name = search_method_name (left, right)
95 print ("public static Filler {0} (int which, object[] refs, bool wrap) {{".format (name))
96 gen_binary_search_body (left, right, one_method)
98 if not one_method and left + 1 < right:
99 mid = (left + right) // 2
100 gen_binary_search (left, mid, one_method)
101 gen_binary_search (mid, right, one_method)
104 print ("public class Bitmaps {")
106 print (" public static Filler MakeAndFill (int which, object[] refs, bool wrap) {")
107 print (" switch (which) {")
108 for i in range (0, len (names)):
109 print (" case {0}: {{".format (i))
112 print (" default: return null;")
116 method_name = gen_binary_search (0, len (names), options.one_method_if)
117 print (" public static Filler MakeAndFill (int which, object[] refs, bool wrap) {")
118 print (" if (which >= {0}) return null;".format (len (names)))
119 print (" return {0} (which, refs, wrap);".format (method_name))
121 print (" public const int NumWhich = {0};".format (len (names)))
126 print_file ("descriptor-tests-driver.cs")