Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import sys | 6 import sys |
| 7 import string | 7 import string |
| 8 import json | 8 import json |
| 9 | 9 |
| 10 input_json_path = sys.argv[1] | 10 blink_protocol_path = sys.argv[1] |
| 11 output_cc_path = sys.argv[2] | 11 browser_protocol_path = sys.argv[2] |
| 12 output_h_path = sys.argv[3] | 12 output_cc_path = sys.argv[3] |
| 13 output_h_path = sys.argv[4] | |
| 13 | 14 |
| 14 header = """\ | 15 header = """\ |
| 15 // Copyright 2014 The Chromium Authors. All rights reserved. | 16 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 16 // Use of this source code is governed by a BSD-style license that can be | 17 // Use of this source code is governed by a BSD-style license that can be |
| 17 // found in the LICENSE file. | 18 // found in the LICENSE file. |
| 18 | 19 |
| 19 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. | 20 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. |
| 20 // Generated by | 21 // Generated by |
| 21 // content/public/browser/devtools_protocol_handler_generator.py from | 22 // content/public/browser/devtools_protocol_handler_generator.py from |
| 22 // third_party/WebKit/Source/devtools/protocol.json | 23 // third_party/WebKit/Source/devtools/protocol.json |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 """) | 413 """) |
| 413 | 414 |
| 414 tmpl_wrap_dict = string.Template("""\ | 415 tmpl_wrap_dict = string.Template("""\ |
| 415 ${dict_var}->Set("${proto_param}", | 416 ${dict_var}->Set("${proto_param}", |
| 416 ${param_type}::ToValue(${var_name}.Pass()).release()); | 417 ${param_type}::ToValue(${var_name}.Pass()).release()); |
| 417 """) | 418 """) |
| 418 | 419 |
| 419 tmpl_wrap_list = tmpl_wrap_dict; | 420 tmpl_wrap_list = tmpl_wrap_dict; |
| 420 | 421 |
| 421 tmpl_wrap_obj = string.Template("""\ | 422 tmpl_wrap_obj = string.Template("""\ |
| 422 ${dict_var}->Set("${proto_param}", ${var_name}); | 423 ${dict_var}->Set("${proto_param}", ${var_name}.release()); |
|
dgozman
2014/10/17 13:11:28
Should this go to previous patch?
vkuzkokov
2014/10/17 15:53:17
Done.
| |
| 423 """) | 424 """) |
| 424 | 425 |
| 425 tmpl_typename = string.Template("devtools::${domain}::${declared_name}") | 426 tmpl_typename = string.Template("devtools::${domain}::${declared_name}") |
| 426 | 427 |
| 427 def Capitalize(s): | 428 def Capitalize(s): |
| 428 return s[:1].upper() + s[1:] | 429 return s[:1].upper() + s[1:] |
| 429 | 430 |
| 430 def Decapitalize(s): | 431 def Decapitalize(s): |
| 431 return s.lower() | 432 return s.lower() |
| 432 | 433 |
| 433 def Uncamelcase(s): | 434 def Uncamelcase(s): |
| 434 result = "" | 435 result = "" |
| 435 for i, c in enumerate(s): | 436 for i, c in enumerate(s): |
| 436 if c.isupper(): | 437 if c.isupper(): |
| 437 if (i > 0) and ((i < len(s)-1) and s[i+1].islower() or s[i-1].islower()): | 438 if (i > 0) and ((i < len(s)-1) and s[i+1].islower() or s[i-1].islower()): |
| 438 result += "_" | 439 result += "_" |
| 439 result += c.lower() | 440 result += c.lower() |
| 440 else: | 441 else: |
| 441 result += c | 442 result += c |
| 442 return result | 443 return result |
| 443 | 444 |
| 444 types = {} | 445 types = {} |
| 445 json_api = json.loads(open(input_json_path, "r").read()) | 446 blink_protocol = json.loads(open(blink_protocol_path, "r").read()) |
| 447 browser_protocol = json.loads(open(browser_protocol_path, "r").read()) | |
| 446 type_decls = [] | 448 type_decls = [] |
| 447 type_impls = [] | 449 type_impls = [] |
| 448 handler_methods = [] | 450 handler_methods = [] |
| 449 handler_method_impls = [] | 451 handler_method_impls = [] |
| 450 | 452 |
| 451 for json_domain in json_api["domains"]: | 453 all_domains = blink_protocol["domains"] + browser_protocol["domains"] |
| 454 | |
| 455 for json_domain in all_domains: | |
| 452 if "types" in json_domain: | 456 if "types" in json_domain: |
| 453 for json_type in json_domain["types"]: | 457 for json_type in json_domain["types"]: |
| 454 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type | 458 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type |
| 455 | 459 |
| 456 def DeclareStruct(json_properties, mapping): | 460 def DeclareStruct(json_properties, mapping): |
| 457 methods = [] | 461 methods = [] |
| 458 fields = [] | 462 fields = [] |
| 459 fields_init = [] | 463 fields_init = [] |
| 460 method_impls = [] | 464 method_impls = [] |
| 461 dchecks = [] | 465 dchecks = [] |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 489 dot_pos = json["$ref"].find(".") | 493 dot_pos = json["$ref"].find(".") |
| 490 if dot_pos == -1: | 494 if dot_pos == -1: |
| 491 domain_name = mapping["Domain"] | 495 domain_name = mapping["Domain"] |
| 492 type_name = json["$ref"] | 496 type_name = json["$ref"] |
| 493 else: | 497 else: |
| 494 domain_name = json["$ref"][:dot_pos] | 498 domain_name = json["$ref"][:dot_pos] |
| 495 type_name = json["$ref"][dot_pos + 1:] | 499 type_name = json["$ref"][dot_pos + 1:] |
| 496 json_type = types["%s.%s" % (domain_name, type_name)] | 500 json_type = types["%s.%s" % (domain_name, type_name)] |
| 497 mapping["declared_name"] = Capitalize(type_name) | 501 mapping["declared_name"] = Capitalize(type_name) |
| 498 mapping["Domain"] = domain_name | 502 mapping["Domain"] = domain_name |
| 499 mapping["domain"] = Decapitalize(domain_name) | 503 mapping["domain"] = Uncamelcase(domain_name) |
|
dgozman
2014/10/17 13:11:28
ditto
vkuzkokov
2014/10/17 15:53:17
Done.
| |
| 500 mapping["param_type"] = tmpl_typename.substitute(mapping) | 504 mapping["param_type"] = tmpl_typename.substitute(mapping) |
| 501 if json_type.get("enum"): | 505 if json_type.get("enum"): |
| 502 # TODO(vkuzkokov) Implement. Approximate template: | 506 # TODO(vkuzkokov) Implement. Approximate template: |
| 503 # namespace ${domain} { const char k${declared_name}${Value}; } | 507 # namespace ${domain} { const char k${declared_name}${Value}; } |
| 504 raise Exception("Named enumerations are not implemented") | 508 raise Exception("Named enumerations are not implemented") |
| 505 ResolveType(json_type, mapping) | 509 ResolveType(json_type, mapping) |
| 506 if not "___struct_declared" in json_type: | 510 if not "___struct_declared" in json_type: |
| 507 json_type["___struct_declared"] = True; | 511 json_type["___struct_declared"] = True; |
| 508 if (json_type.get("type") == "object") and ("properties" in json_type): | 512 if (json_type.get("type") == "object") and ("properties" in json_type): |
| 509 DeclareStruct(json_type["properties"], mapping) | 513 DeclareStruct(json_type["properties"], mapping) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 else: | 605 else: |
| 602 raise Exception("Unknown type at %s.%s %s" % | 606 raise Exception("Unknown type at %s.%s %s" % |
| 603 (mapping["Domain"], mapping["command"], mapping["proto_param"])) | 607 (mapping["Domain"], mapping["command"], mapping["proto_param"])) |
| 604 | 608 |
| 605 setters = [] | 609 setters = [] |
| 606 fields = [] | 610 fields = [] |
| 607 | 611 |
| 608 includes = [] | 612 includes = [] |
| 609 fields_init = [] | 613 fields_init = [] |
| 610 | 614 |
| 611 for json_domain in json_api["domains"]: | 615 for json_domain in all_domains: |
| 612 domain_map = {} | 616 domain_map = {} |
| 613 domain_map["Domain"] = json_domain["domain"] | 617 domain_map["Domain"] = json_domain["domain"] |
| 614 domain_map["domain"] = Decapitalize(json_domain["domain"]) | 618 domain_map["domain"] = Uncamelcase(json_domain["domain"]) |
|
dgozman
2014/10/17 13:11:28
ditto
vkuzkokov
2014/10/17 15:53:17
Done.
| |
| 615 | 619 |
| 616 initializations = [] | 620 initializations = [] |
| 617 client_methods = [] | 621 client_methods = [] |
| 618 client_method_impls = [] | 622 client_method_impls = [] |
| 619 domain_empty = True | 623 domain_empty = True |
| 620 domain_needs_client = False | 624 domain_needs_client = False |
| 621 | 625 |
| 622 if "commands" in json_domain: | 626 if "commands" in json_domain: |
| 623 for json_command in json_domain["commands"]: | 627 for json_command in json_domain["commands"]: |
| 624 if (not ("handlers" in json_command) or | 628 if (not ("handlers" in json_command) or |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 methods = "".join(handler_methods), | 755 methods = "".join(handler_methods), |
| 752 fields = "".join(fields))) | 756 fields = "".join(fields))) |
| 753 output_h_file.close() | 757 output_h_file.close() |
| 754 | 758 |
| 755 output_cc_file.write(template_cc.substitute({}, | 759 output_cc_file.write(template_cc.substitute({}, |
| 756 includes = "".join(sorted(includes)), | 760 includes = "".join(sorted(includes)), |
| 757 fields_init = ",\n ".join(fields_init), | 761 fields_init = ",\n ".join(fields_init), |
| 758 methods = "\n".join(handler_method_impls), | 762 methods = "\n".join(handler_method_impls), |
| 759 types = "\n".join(type_impls))) | 763 types = "\n".join(type_impls))) |
| 760 output_cc_file.close() | 764 output_cc_file.close() |
| OLD | NEW |