Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | MAX_ARGS = 15 |
michael@0 | 5 | |
michael@0 | 6 | boilerplate = "/* This Source Code Form is subject to the terms of the Mozilla Public\n\ |
michael@0 | 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this\n\ |
michael@0 | 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n" |
michael@0 | 9 | |
michael@0 | 10 | def gen_args_type(args, member): |
michael@0 | 11 | if member: |
michael@0 | 12 | ret = ["C o"] |
michael@0 | 13 | else: |
michael@0 | 14 | ret = [] |
michael@0 | 15 | ret.append("M m") |
michael@0 | 16 | for arg in range(0, args): |
michael@0 | 17 | ret.append("A%d a%d"%(arg, arg)) |
michael@0 | 18 | return ", ".join(ret) |
michael@0 | 19 | |
michael@0 | 20 | def gen_args(args, member): |
michael@0 | 21 | if member: |
michael@0 | 22 | ret = ["o"] |
michael@0 | 23 | else: |
michael@0 | 24 | ret = [] |
michael@0 | 25 | ret.append("m") |
michael@0 | 26 | for arg in range(0, args): |
michael@0 | 27 | ret.append("a%d"%(arg)) |
michael@0 | 28 | return ", ".join(ret) |
michael@0 | 29 | |
michael@0 | 30 | def gen_args_(args): |
michael@0 | 31 | ret = [] |
michael@0 | 32 | for arg in range(0, args): |
michael@0 | 33 | ret.append("a%d_"%(arg)) |
michael@0 | 34 | return ", ".join(ret) |
michael@0 | 35 | |
michael@0 | 36 | def gen_init(args, r = False, member = False): |
michael@0 | 37 | if member: |
michael@0 | 38 | ret = ["o_(o)"] |
michael@0 | 39 | else: |
michael@0 | 40 | ret = [] |
michael@0 | 41 | ret.append("m_(m)") |
michael@0 | 42 | |
michael@0 | 43 | if r: |
michael@0 | 44 | ret.append("r_(r)") |
michael@0 | 45 | |
michael@0 | 46 | for arg in range(0, args): |
michael@0 | 47 | ret.append("a%d_(a%d)"%(arg, arg)) |
michael@0 | 48 | return ", ".join(ret) |
michael@0 | 49 | |
michael@0 | 50 | def gen_typenames(args, member): |
michael@0 | 51 | if member: |
michael@0 | 52 | ret = ["typename C"] |
michael@0 | 53 | else: |
michael@0 | 54 | ret = [] |
michael@0 | 55 | ret.append("typename M") |
michael@0 | 56 | |
michael@0 | 57 | for arg in range(0, args): |
michael@0 | 58 | ret.append("typename A%d"%(arg)) |
michael@0 | 59 | return ", ".join(ret) |
michael@0 | 60 | |
michael@0 | 61 | def gen_types(args, member): |
michael@0 | 62 | if member: |
michael@0 | 63 | ret = ["C"] |
michael@0 | 64 | else: |
michael@0 | 65 | ret = [] |
michael@0 | 66 | ret.append("M") |
michael@0 | 67 | for arg in range(0, args): |
michael@0 | 68 | ret.append("A%d"%(arg)) |
michael@0 | 69 | return ", ".join(ret) |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | def generate_class_template(args, ret = False, member = True): |
michael@0 | 73 | print "// %d arguments --"%args |
michael@0 | 74 | if member: |
michael@0 | 75 | nm = "m" |
michael@0 | 76 | else: |
michael@0 | 77 | nm = "nm" |
michael@0 | 78 | |
michael@0 | 79 | if not ret: |
michael@0 | 80 | print "template<"+ gen_typenames(args, member) + "> class runnable_args_%s_%d : public runnable_args_base {"%(nm, args) |
michael@0 | 81 | else: |
michael@0 | 82 | print "template<"+ gen_typenames(args, member) + ", typename R> class runnable_args_%s_%d_ret : public runnable_args_base {"%(nm, args) |
michael@0 | 83 | |
michael@0 | 84 | print " public:" |
michael@0 | 85 | |
michael@0 | 86 | if not ret: |
michael@0 | 87 | print " runnable_args_%s_%d("%(nm, args) + gen_args_type(args, member) + ") :" |
michael@0 | 88 | print " " + gen_init(args, False, member) + " {}" |
michael@0 | 89 | else: |
michael@0 | 90 | print " runnable_args_%s_%d_ret("%(nm, args) + gen_args_type(args, member) + ", R *r) :" |
michael@0 | 91 | print " " + gen_init(args, True, member) + " {}" |
michael@0 | 92 | print " virtual bool returns_value() const { return true; }" |
michael@0 | 93 | |
michael@0 | 94 | print " NS_IMETHOD Run() {" |
michael@0 | 95 | if ret: |
michael@0 | 96 | print " *r_ =", |
michael@0 | 97 | else: |
michael@0 | 98 | print " ", |
michael@0 | 99 | if member: |
michael@0 | 100 | print "((*o_).*m_)(" + gen_args_(args) + ");" |
michael@0 | 101 | else: |
michael@0 | 102 | print "m_(" + gen_args_(args) + ");" |
michael@0 | 103 | |
michael@0 | 104 | print " return NS_OK;" |
michael@0 | 105 | print " }" |
michael@0 | 106 | |
michael@0 | 107 | print " private:" |
michael@0 | 108 | if member: |
michael@0 | 109 | print " C o_;" |
michael@0 | 110 | print " M m_;" |
michael@0 | 111 | if ret: |
michael@0 | 112 | print " R* r_;" |
michael@0 | 113 | for arg in range(0, args): |
michael@0 | 114 | print " A%d a%d_;"%(arg, arg) |
michael@0 | 115 | print "};" |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | |
michael@0 | 120 | def generate_function_template(args, member): |
michael@0 | 121 | if member: |
michael@0 | 122 | nm = "m" |
michael@0 | 123 | NM = ""; |
michael@0 | 124 | else: |
michael@0 | 125 | nm = "nm" |
michael@0 | 126 | NM = "NM"; |
michael@0 | 127 | |
michael@0 | 128 | print "// %d arguments --"%args |
michael@0 | 129 | print "template<" + gen_typenames(args, member) + ">" |
michael@0 | 130 | print "runnable_args_%s_%d<"%(nm, args) + gen_types(args, member) + ">* WrapRunnable%s("%NM + gen_args_type(args, member) + ") {" |
michael@0 | 131 | print " return new runnable_args_%s_%d<"%(nm, args) + gen_types(args, member) + ">" |
michael@0 | 132 | print " (" + gen_args(args, member) + ");" |
michael@0 | 133 | print "}" |
michael@0 | 134 | |
michael@0 | 135 | |
michael@0 | 136 | def generate_function_template_ret(args, member): |
michael@0 | 137 | if member: |
michael@0 | 138 | nm = "m" |
michael@0 | 139 | NM = ""; |
michael@0 | 140 | else: |
michael@0 | 141 | nm = "nm" |
michael@0 | 142 | NM = "NM"; |
michael@0 | 143 | print "// %d arguments --"%args |
michael@0 | 144 | print "template<" + gen_typenames(args, member) + ", typename R>" |
michael@0 | 145 | print "runnable_args_%s_%d_ret<"%(nm, args) + gen_types(args, member) + ", R>* WrapRunnable%sRet("%NM + gen_args_type(args, member) + ", R* r) {" |
michael@0 | 146 | print " return new runnable_args_%s_%d_ret<"%(nm, args) + gen_types(args, member) + ", R>" |
michael@0 | 147 | print " (" + gen_args(args, member) + ", r);" |
michael@0 | 148 | print "}" |
michael@0 | 149 | |
michael@0 | 150 | |
michael@0 | 151 | |
michael@0 | 152 | print boilerplate |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | for num_args in range (0, MAX_ARGS): |
michael@0 | 156 | generate_class_template(num_args, False, False) |
michael@0 | 157 | generate_class_template(num_args, True, False) |
michael@0 | 158 | generate_class_template(num_args, False, True) |
michael@0 | 159 | generate_class_template(num_args, True, True) |
michael@0 | 160 | |
michael@0 | 161 | |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | |
michael@0 | 166 | for num_args in range(0, MAX_ARGS): |
michael@0 | 167 | generate_function_template(num_args, False) |
michael@0 | 168 | generate_function_template_ret(num_args, False) |
michael@0 | 169 | generate_function_template(num_args, True) |
michael@0 | 170 | generate_function_template_ret(num_args, True) |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 |