Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 83 |
| 84 def patch_full_qualified_refs(): | 84 def patch_full_qualified_refs(): |
| 85 def patch_full_qualified_refs_in_domain(json, domain_name): | 85 def patch_full_qualified_refs_in_domain(json, domain_name): |
| 86 if isinstance(json, list): | 86 if isinstance(json, list): |
| 87 for item in json: | 87 for item in json: |
| 88 patch_full_qualified_refs_in_domain(item, domain_name) | 88 patch_full_qualified_refs_in_domain(item, domain_name) |
| 89 | 89 |
| 90 if not isinstance(json, dict): | 90 if not isinstance(json, dict): |
| 91 return | 91 return |
| 92 for key in json: | 92 for key in json: |
| 93 if key == "type" and json[key] == "string": | |
| 94 json[key] = domain_name + ".string" | |
| 93 if key != "$ref": | 95 if key != "$ref": |
| 94 patch_full_qualified_refs_in_domain(json[key], domain_name) | 96 patch_full_qualified_refs_in_domain(json[key], domain_name) |
| 95 continue | 97 continue |
| 96 if json["$ref"].find(".") == -1: | 98 if json["$ref"].find(".") == -1: |
| 97 json["$ref"] = domain_name + "." + json["$ref"] | 99 json["$ref"] = domain_name + "." + json["$ref"] |
| 98 | 100 |
| 99 for domain in json_api["domains"]: | 101 for domain in json_api["domains"]: |
| 100 patch_full_qualified_refs_in_domain(domain, domain["domain"]) | 102 patch_full_qualified_refs_in_domain(domain, domain["domain"]) |
| 101 | 103 |
| 102 | 104 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 132 "pass_type": "PassOwnPtr<protocol::Value>", | 134 "pass_type": "PassOwnPtr<protocol::Value>", |
| 133 "to_raw_type": "%s.get()", | 135 "to_raw_type": "%s.get()", |
| 134 "to_pass_type": "%s.release()", | 136 "to_pass_type": "%s.release()", |
| 135 "type": "OwnPtr<protocol::Value>", | 137 "type": "OwnPtr<protocol::Value>", |
| 136 "raw_type": "protocol::Value", | 138 "raw_type": "protocol::Value", |
| 137 "raw_pass_type": "protocol::Value*", | 139 "raw_pass_type": "protocol::Value*", |
| 138 "raw_return_type": "protocol::Value*", | 140 "raw_return_type": "protocol::Value*", |
| 139 } | 141 } |
| 140 | 142 |
| 141 | 143 |
| 144 def create_string_type_definition(domain): | |
| 145 if domain in ["Runtime", "Debugger", "Profiler", "HeapProfiler"]: | |
|
dgozman
2016/03/08 01:35:12
Mark them in protocol.json.
pfeldman
2016/03/08 02:24:59
We'll split them.
| |
| 146 return { | |
| 147 "return_type": "String16", | |
| 148 "pass_type": "const String16&", | |
| 149 "to_pass_type": "%s", | |
| 150 "to_raw_type": "%s", | |
| 151 "type": "String16", | |
| 152 "raw_type": "String16", | |
| 153 "raw_pass_type": "const String16&", | |
| 154 "raw_return_type": "String16", | |
| 155 } | |
| 156 return { | |
| 157 "return_type": "String", | |
| 158 "pass_type": "const String&", | |
| 159 "to_pass_type": "%s", | |
| 160 "to_raw_type": "%s", | |
| 161 "type": "String", | |
| 162 "raw_type": "String", | |
| 163 "raw_pass_type": "const String&", | |
| 164 "raw_return_type": "String", | |
| 165 } | |
| 166 | |
| 167 | |
| 142 def create_primitive_type_definition(type): | 168 def create_primitive_type_definition(type): |
| 143 if type == "string": | |
| 144 return { | |
| 145 "return_type": "String", | |
| 146 "pass_type": "const String&", | |
| 147 "to_pass_type": "%s", | |
| 148 "to_raw_type": "%s", | |
| 149 "type": "String", | |
| 150 "raw_type": "String", | |
| 151 "raw_pass_type": "const String&", | |
| 152 "raw_return_type": "String", | |
| 153 } | |
| 154 | |
| 155 typedefs = { | 169 typedefs = { |
| 156 "number": "double", | 170 "number": "double", |
| 157 "integer": "int", | 171 "integer": "int", |
| 158 "boolean": "bool" | 172 "boolean": "bool" |
| 159 } | 173 } |
| 160 jsontypes = { | 174 jsontypes = { |
| 161 "number": "TypeNumber", | 175 "number": "TypeNumber", |
| 162 "integer": "TypeNumber", | 176 "integer": "TypeNumber", |
| 163 "boolean": "TypeBoolean", | 177 "boolean": "TypeBoolean", |
| 164 } | 178 } |
| 165 return { | 179 return { |
| 166 "return_type": typedefs[type], | 180 "return_type": typedefs[type], |
| 167 "pass_type": typedefs[type], | 181 "pass_type": typedefs[type], |
| 168 "to_pass_type": "%s", | 182 "to_pass_type": "%s", |
| 169 "to_raw_type": "%s", | 183 "to_raw_type": "%s", |
| 170 "type": typedefs[type], | 184 "type": typedefs[type], |
| 171 "raw_type": typedefs[type], | 185 "raw_type": typedefs[type], |
| 172 "raw_pass_type": typedefs[type], | 186 "raw_pass_type": typedefs[type], |
| 173 "raw_return_type": typedefs[type], | 187 "raw_return_type": typedefs[type], |
| 174 } | 188 } |
| 175 | 189 |
| 176 type_definitions = {} | 190 type_definitions = {} |
| 177 type_definitions["string"] = create_primitive_type_definition("string") | |
| 178 type_definitions["number"] = create_primitive_type_definition("number") | 191 type_definitions["number"] = create_primitive_type_definition("number") |
| 179 type_definitions["integer"] = create_primitive_type_definition("integer") | 192 type_definitions["integer"] = create_primitive_type_definition("integer") |
| 180 type_definitions["boolean"] = create_primitive_type_definition("boolean") | 193 type_definitions["boolean"] = create_primitive_type_definition("boolean") |
| 181 type_definitions["object"] = create_object_type_definition() | 194 type_definitions["object"] = create_object_type_definition() |
| 182 type_definitions["any"] = create_any_type_definition() | 195 type_definitions["any"] = create_any_type_definition() |
| 183 | 196 |
| 184 | |
| 185 def wrap_array_definition(type): | 197 def wrap_array_definition(type): |
| 186 return { | 198 return { |
| 187 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], | 199 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 188 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], | 200 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 189 "to_raw_type": "%s.get()", | 201 "to_raw_type": "%s.get()", |
| 190 "to_pass_type": "%s.release()", | 202 "to_pass_type": "%s.release()", |
| 191 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], | 203 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], |
| 192 "raw_type": "protocol::Array<%s>" % type["raw_type"], | 204 "raw_type": "protocol::Array<%s>" % type["raw_type"], |
| 193 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], | 205 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], |
| 194 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], | 206 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], |
| 195 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"], | 207 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"], |
| 196 "out_type": "protocol::Array<%s>&" % type["raw_type"], | 208 "out_type": "protocol::Array<%s>&" % type["raw_type"], |
| 197 } | 209 } |
| 198 | 210 |
| 199 | 211 |
| 200 def create_type_definitions(): | 212 def create_type_definitions(): |
| 201 for domain in json_api["domains"]: | 213 for domain in json_api["domains"]: |
| 214 type_definitions[domain["domain"] + ".string"] = create_string_type_defi nition(domain["domain"]) | |
| 202 if not ("types" in domain): | 215 if not ("types" in domain): |
| 203 continue | 216 continue |
| 204 for type in domain["types"]: | 217 for type in domain["types"]: |
| 205 if type["type"] == "object": | 218 if type["type"] == "object": |
| 206 type_definitions[domain["domain"] + "." + type["id"]] = create_u ser_type_definition(domain["domain"], type) | 219 type_definitions[domain["domain"] + "." + type["id"]] = create_u ser_type_definition(domain["domain"], type) |
| 207 elif type["type"] == "array": | 220 elif type["type"] == "array": |
| 208 items_type = type["items"]["type"] | 221 items_type = type["items"]["type"] |
| 209 type_definitions[domain["domain"] + "." + type["id"]] = wrap_arr ay_definition(type_definitions[items_type]) | 222 type_definitions[domain["domain"] + "." + type["id"]] = wrap_arr ay_definition(type_definitions[items_type]) |
| 223 elif type["type"] == domain["domain"] + ".string": | |
| 224 type_definitions[domain["domain"] + "." + type["id"]] = create_s tring_type_definition(domain["domain"]) | |
| 210 else: | 225 else: |
| 211 type_definitions[domain["domain"] + "." + type["id"]] = create_p rimitive_type_definition(type["type"]) | 226 type_definitions[domain["domain"] + "." + type["id"]] = create_p rimitive_type_definition(type["type"]) |
| 212 | 227 |
| 213 patch_full_qualified_refs() | 228 patch_full_qualified_refs() |
| 214 create_type_definitions() | 229 create_type_definitions() |
| 215 | 230 |
| 216 | 231 |
| 217 def type_definition(name): | 232 def type_definition(name): |
| 218 return type_definitions[name] | 233 return type_definitions[name] |
| 219 | 234 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 249 h_file.write(h_template.render(template_context)) | 264 h_file.write(h_template.render(template_context)) |
| 250 cpp_file.write(cpp_template.render(template_context)) | 265 cpp_file.write(cpp_template.render(template_context)) |
| 251 h_file.close() | 266 h_file.close() |
| 252 cpp_file.close() | 267 cpp_file.close() |
| 253 | 268 |
| 254 | 269 |
| 255 jinja_env = initialize_jinja_env(output_dirname) | 270 jinja_env = initialize_jinja_env(output_dirname) |
| 256 generate("Dispatcher") | 271 generate("Dispatcher") |
| 257 generate("Frontend") | 272 generate("Frontend") |
| 258 generate("TypeBuilder") | 273 generate("TypeBuilder") |
| OLD | NEW |