| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os.path | 5 import os.path |
| 6 import sys | 6 import sys |
| 7 import string | 7 import string |
| 8 import optparse | 8 import optparse |
| 9 import re | 9 import re |
| 10 try: | 10 try: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 | 102 |
| 103 def create_user_type_definition(domain_name, type): | 103 def create_user_type_definition(domain_name, type): |
| 104 return { | 104 return { |
| 105 "return_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]
), | 105 "return_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]
), |
| 106 "pass_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), | 106 "pass_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), |
| 107 "to_pass_type": "%s.release()", | 107 "to_pass_type": "%s.release()", |
| 108 "type": "OwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), | 108 "type": "OwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), |
| 109 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), | 109 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), |
| 110 "create_type": "adoptPtr(new protocol::%s::%s())" % (domain_name, type["
id"]), | 110 "create_type": "adoptPtr(new protocol::%s::%s())" % (domain_name, type["
id"]), |
| 111 "optional_type": "OwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), | |
| 112 "optional_pass_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, typ
e["id"]), | |
| 113 "from_optional_out": "%s.release()", | |
| 114 "json_getter": "FromValue<protocol::%s::%s>::convert(getObject(%%s))" %
(domain_name, type["id"]), | 111 "json_getter": "FromValue<protocol::%s::%s>::convert(getObject(%%s))" %
(domain_name, type["id"]), |
| 115 "json_type": "TypeObject", | 112 "json_type": "TypeObject", |
| 116 "nullable": True, | |
| 117 } | 113 } |
| 118 | 114 |
| 119 | 115 |
| 120 def create_object_type_definition(): | 116 def create_object_type_definition(): |
| 121 return { | 117 return { |
| 122 "return_type": "PassRefPtr<JSONObject>", | 118 "return_type": "PassRefPtr<JSONObject>", |
| 123 "pass_type": "PassRefPtr<JSONObject>", | 119 "pass_type": "PassRefPtr<JSONObject>", |
| 124 "to_pass_type": "%s.release()", | 120 "to_pass_type": "%s.release()", |
| 125 "type": "RefPtr<JSONObject>", | 121 "type": "RefPtr<JSONObject>", |
| 126 "raw_type": "RefPtr<JSONObject>", | 122 "raw_type": "RefPtr<JSONObject>", |
| 127 "optional_type": "RefPtr<JSONObject>", | |
| 128 "optional_pass_type": "PassRefPtr<JSONObject>", | |
| 129 "from_optional_out": "%s.release()", | |
| 130 "json_getter": "getObject(%s)", | 123 "json_getter": "getObject(%s)", |
| 131 "json_type": "TypeObject", | 124 "json_type": "TypeObject", |
| 132 "nullable": True, | |
| 133 } | 125 } |
| 134 | 126 |
| 135 | 127 |
| 136 def create_any_type_definition(): | 128 def create_any_type_definition(): |
| 137 return { | 129 return { |
| 138 "return_type": "PassRefPtr<JSONValue>", | 130 "return_type": "PassRefPtr<JSONValue>", |
| 139 "pass_type": "PassRefPtr<JSONValue>", | 131 "pass_type": "PassRefPtr<JSONValue>", |
| 140 "to_pass_type": "%s.release()", | 132 "to_pass_type": "%s.release()", |
| 141 "type": "RefPtr<JSONValue>", | 133 "type": "RefPtr<JSONValue>", |
| 142 "raw_type": "RefPtr<JSONValue>", | 134 "raw_type": "RefPtr<JSONValue>", |
| 143 "optional_type": "RefPtr<JSONValue>", | |
| 144 "optional_pass_type": "PassRefPtr<JSONValue>", | |
| 145 "from_optional_out": "%s.release()", | |
| 146 "json_getter": "getValue(%s)", | 135 "json_getter": "getValue(%s)", |
| 147 "nullable": True, | |
| 148 } | 136 } |
| 149 | 137 |
| 150 | 138 |
| 151 def create_primitive_type_definition(type): | 139 def create_primitive_type_definition(type): |
| 152 if type == "string": | 140 if type == "string": |
| 153 return { | 141 return { |
| 154 "return_type": "String", | 142 "return_type": "String", |
| 155 "pass_type": "const String&", | 143 "pass_type": "const String&", |
| 156 "to_pass_type": "%s", | 144 "to_pass_type": "%s", |
| 157 "type": "String", | 145 "type": "String", |
| 158 "raw_type": "String", | 146 "raw_type": "String", |
| 159 "optional_type": "protocol::OptionalValue<String>", | |
| 160 "optional_pass_type": "const protocol::OptionalValue<String>&", | |
| 161 "from_optional_out": "%s.get()", | |
| 162 "json_getter": "getString(%s)", | 147 "json_getter": "getString(%s)", |
| 163 "json_type": "TypeString", | 148 "json_type": "TypeString", |
| 164 "nullable": False, | |
| 165 } | 149 } |
| 166 | 150 |
| 167 typedefs = { | 151 typedefs = { |
| 168 "number": "double", | 152 "number": "double", |
| 169 "integer": "int", | 153 "integer": "int", |
| 170 "boolean": "bool" | 154 "boolean": "bool" |
| 171 } | 155 } |
| 172 jsontypes = { | 156 jsontypes = { |
| 173 "number": "TypeNumber", | 157 "number": "TypeNumber", |
| 174 "integer": "TypeNumber", | 158 "integer": "TypeNumber", |
| 175 "boolean": "TypeBoolean", | 159 "boolean": "TypeBoolean", |
| 176 } | 160 } |
| 177 return { | 161 return { |
| 178 "return_type": typedefs[type], | 162 "return_type": typedefs[type], |
| 179 "pass_type": typedefs[type], | 163 "pass_type": typedefs[type], |
| 180 "to_pass_type": "%s", | 164 "to_pass_type": "%s", |
| 181 "type": typedefs[type], | 165 "type": typedefs[type], |
| 182 "raw_type": typedefs[type], | 166 "raw_type": typedefs[type], |
| 183 "optional_type": "protocol::OptionalValue<" + typedefs[type] + ">", | |
| 184 "optional_pass_type": "const protocol::OptionalValue<" + typedefs[type]
+ ">&", | |
| 185 "from_optional_out": "%s.get()", | |
| 186 "json_getter": "get" + to_title_case(type) + "(%s)", | 167 "json_getter": "get" + to_title_case(type) + "(%s)", |
| 187 "json_type": jsontypes[type], | 168 "json_type": jsontypes[type], |
| 188 "nullable": False, | |
| 189 } | 169 } |
| 190 | 170 |
| 191 type_definitions = {} | 171 type_definitions = {} |
| 192 type_definitions["string"] = create_primitive_type_definition("string") | 172 type_definitions["string"] = create_primitive_type_definition("string") |
| 193 type_definitions["number"] = create_primitive_type_definition("number") | 173 type_definitions["number"] = create_primitive_type_definition("number") |
| 194 type_definitions["integer"] = create_primitive_type_definition("integer") | 174 type_definitions["integer"] = create_primitive_type_definition("integer") |
| 195 type_definitions["boolean"] = create_primitive_type_definition("boolean") | 175 type_definitions["boolean"] = create_primitive_type_definition("boolean") |
| 196 type_definitions["object"] = create_object_type_definition() | 176 type_definitions["object"] = create_object_type_definition() |
| 197 type_definitions["any"] = create_any_type_definition() | 177 type_definitions["any"] = create_any_type_definition() |
| 198 | 178 |
| 199 | 179 |
| 200 def wrap_array_definition(type): | 180 def wrap_array_definition(type): |
| 201 return { | 181 return { |
| 202 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], | 182 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 203 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], | 183 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 204 "to_pass_type": "%s.release()", | 184 "to_pass_type": "%s.release()", |
| 205 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], | 185 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 206 "raw_type": "protocol::Array<%s>" % type["raw_type"], | 186 "raw_type": "protocol::Array<%s>" % type["raw_type"], |
| 207 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"], | 187 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"], |
| 208 "out_type": "protocol::Array<%s>&" % type["raw_type"], | 188 "out_type": "protocol::Array<%s>&" % type["raw_type"], |
| 209 "optional_type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], | |
| 210 "optional_pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type
"], | |
| 211 "from_optional_out": "%s.release()", | |
| 212 "json_getter": "protocol::Array<%s>::runtimeCast(getArray(%%s))" % type[
"raw_type"], | 189 "json_getter": "protocol::Array<%s>::runtimeCast(getArray(%%s))" % type[
"raw_type"], |
| 213 "json_type": "TypeArray", | 190 "json_type": "TypeArray", |
| 214 "nullable": True, | |
| 215 } | 191 } |
| 216 | 192 |
| 217 | 193 |
| 218 def create_type_definitions(): | 194 def create_type_definitions(): |
| 219 for domain in json_api["domains"]: | 195 for domain in json_api["domains"]: |
| 220 if not ("types" in domain): | 196 if not ("types" in domain): |
| 221 continue | 197 continue |
| 222 for type in domain["types"]: | 198 for type in domain["types"]: |
| 223 if type["type"] == "object": | 199 if type["type"] == "object": |
| 224 type_definitions[domain["domain"] + "." + type["id"]] = create_u
ser_type_definition(domain["domain"], type) | 200 type_definitions[domain["domain"] + "." + type["id"]] = create_u
ser_type_definition(domain["domain"], type) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 h_file.write(h_template.render(template_context)) | 243 h_file.write(h_template.render(template_context)) |
| 268 cpp_file.write(cpp_template.render(template_context)) | 244 cpp_file.write(cpp_template.render(template_context)) |
| 269 h_file.close() | 245 h_file.close() |
| 270 cpp_file.close() | 246 cpp_file.close() |
| 271 | 247 |
| 272 | 248 |
| 273 jinja_env = initialize_jinja_env(output_dirname) | 249 jinja_env = initialize_jinja_env(output_dirname) |
| 274 generate("Dispatcher") | 250 generate("Dispatcher") |
| 275 generate("Frontend") | 251 generate("Frontend") |
| 276 generate("TypeBuilder") | 252 generate("TypeBuilder") |
| OLD | NEW |