| 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 argparse | 5 import argparse |
| 6 import collections | 6 import collections |
| 7 import os.path | 7 import os.path |
| 8 import re | 8 import re |
| 9 import sys | 9 import sys |
| 10 try: | 10 try: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if not '.' in json['$ref']: | 113 if not '.' in json['$ref']: |
| 114 json['$ref'] = domain_name + '.' + json['$ref'] | 114 json['$ref'] = domain_name + '.' + json['$ref'] |
| 115 | 115 |
| 116 for domain in json_api['domains']: | 116 for domain in json_api['domains']: |
| 117 PatchFullQualifiedRefsInDomain(domain, domain['domain']) | 117 PatchFullQualifiedRefsInDomain(domain, domain['domain']) |
| 118 | 118 |
| 119 | 119 |
| 120 def CreateUserTypeDefinition(domain, type): | 120 def CreateUserTypeDefinition(domain, type): |
| 121 namespace = CamelCaseToHackerStyle(domain['domain']) | 121 namespace = CamelCaseToHackerStyle(domain['domain']) |
| 122 return { | 122 return { |
| 123 'js_type': '!chromium.DevTools.%s.%s' % (domain['domain'], type['id']), |
| 123 'return_type': 'std::unique_ptr<headless::%s::%s>' % ( | 124 'return_type': 'std::unique_ptr<headless::%s::%s>' % ( |
| 124 namespace, type['id']), | 125 namespace, type['id']), |
| 125 'pass_type': 'std::unique_ptr<headless::%s::%s>' % ( | 126 'pass_type': 'std::unique_ptr<headless::%s::%s>' % ( |
| 126 namespace, type['id']), | 127 namespace, type['id']), |
| 127 'to_raw_type': '*%s', | 128 'to_raw_type': '*%s', |
| 128 'to_raw_return_type': '%s.get()', | 129 'to_raw_return_type': '%s.get()', |
| 129 'to_pass_type': 'std::move(%s)', | 130 'to_pass_type': 'std::move(%s)', |
| 130 'type': 'std::unique_ptr<headless::%s::%s>' % (namespace, type['id']), | 131 'type': 'std::unique_ptr<headless::%s::%s>' % (namespace, type['id']), |
| 131 'raw_type': 'headless::%s::%s' % (namespace, type['id']), | 132 'raw_type': 'headless::%s::%s' % (namespace, type['id']), |
| 132 'raw_pass_type': 'headless::%s::%s*' % (namespace, type['id']), | 133 'raw_pass_type': 'headless::%s::%s*' % (namespace, type['id']), |
| 133 'raw_return_type': 'const headless::%s::%s*' % (namespace, type['id']), | 134 'raw_return_type': 'const headless::%s::%s*' % (namespace, type['id']), |
| 134 } | 135 } |
| 135 | 136 |
| 136 | 137 |
| 137 def CreateEnumTypeDefinition(domain_name, type): | 138 def CreateEnumTypeDefinition(domain_name, type): |
| 138 namespace = CamelCaseToHackerStyle(domain_name) | 139 namespace = CamelCaseToHackerStyle(domain_name) |
| 139 return { | 140 return { |
| 141 'js_type': '!chromium.DevTools.%s.%s' % (domain_name, type['id']), |
| 140 'return_type': 'headless::%s::%s' % (namespace, type['id']), | 142 'return_type': 'headless::%s::%s' % (namespace, type['id']), |
| 141 'pass_type': 'headless::%s::%s' % (namespace, type['id']), | 143 'pass_type': 'headless::%s::%s' % (namespace, type['id']), |
| 142 'to_raw_type': '%s', | 144 'to_raw_type': '%s', |
| 143 'to_raw_return_type': '%s', | 145 'to_raw_return_type': '%s', |
| 144 'to_pass_type': '%s', | 146 'to_pass_type': '%s', |
| 145 'type': 'headless::%s::%s' % (namespace, type['id']), | 147 'type': 'headless::%s::%s' % (namespace, type['id']), |
| 146 'raw_type': 'headless::%s::%s' % (namespace, type['id']), | 148 'raw_type': 'headless::%s::%s' % (namespace, type['id']), |
| 147 'raw_pass_type': 'headless::%s::%s' % (namespace, type['id']), | 149 'raw_pass_type': 'headless::%s::%s' % (namespace, type['id']), |
| 148 'raw_return_type': 'headless::%s::%s' % (namespace, type['id']), | 150 'raw_return_type': 'headless::%s::%s' % (namespace, type['id']), |
| 149 } | 151 } |
| 150 | 152 |
| 151 | 153 |
| 152 def CreateObjectTypeDefinition(): | 154 def CreateObjectTypeDefinition(): |
| 153 return { | 155 return { |
| 156 'js_type': '%s', |
| 154 'return_type': 'std::unique_ptr<base::DictionaryValue>', | 157 'return_type': 'std::unique_ptr<base::DictionaryValue>', |
| 155 'pass_type': 'std::unique_ptr<base::DictionaryValue>', | 158 'pass_type': 'std::unique_ptr<base::DictionaryValue>', |
| 156 'to_raw_type': '*%s', | 159 'to_raw_type': '*%s', |
| 157 'to_raw_return_type': '%s.get()', | 160 'to_raw_return_type': '%s.get()', |
| 158 'to_pass_type': 'std::move(%s)', | 161 'to_pass_type': 'std::move(%s)', |
| 159 'type': 'std::unique_ptr<base::DictionaryValue>', | 162 'type': 'std::unique_ptr<base::DictionaryValue>', |
| 160 'raw_type': 'base::DictionaryValue', | 163 'raw_type': 'base::DictionaryValue', |
| 161 'raw_pass_type': 'base::DictionaryValue*', | 164 'raw_pass_type': 'base::DictionaryValue*', |
| 162 'raw_return_type': 'const base::DictionaryValue*', | 165 'raw_return_type': 'const base::DictionaryValue*', |
| 163 } | 166 } |
| 164 | 167 |
| 165 | 168 |
| 166 def WrapObjectTypeDefinition(type): | 169 def WrapObjectTypeDefinition(type): |
| 167 id = type.get('id', 'base::Value') | 170 id = type.get('id', 'base::Value') |
| 168 return { | 171 return { |
| 172 'js_type': '!Object', |
| 169 'return_type': 'std::unique_ptr<%s>' % id, | 173 'return_type': 'std::unique_ptr<%s>' % id, |
| 170 'pass_type': 'std::unique_ptr<%s>' % id, | 174 'pass_type': 'std::unique_ptr<%s>' % id, |
| 171 'to_raw_type': '*%s', | 175 'to_raw_type': '*%s', |
| 172 'to_raw_return_type': '%s.get()', | 176 'to_raw_return_type': '%s.get()', |
| 173 'to_pass_type': 'std::move(%s)', | 177 'to_pass_type': 'std::move(%s)', |
| 174 'type': 'std::unique_ptr<%s>' % id, | 178 'type': 'std::unique_ptr<%s>' % id, |
| 175 'raw_type': id, | 179 'raw_type': id, |
| 176 'raw_pass_type': '%s*' % id, | 180 'raw_pass_type': '%s*' % id, |
| 177 'raw_return_type': 'const %s*' % id, | 181 'raw_return_type': 'const %s*' % id, |
| 178 } | 182 } |
| 179 | 183 |
| 180 | 184 |
| 181 def CreateAnyTypeDefinition(): | 185 def CreateAnyTypeDefinition(): |
| 182 return { | 186 return { |
| 187 'js_type': '*', |
| 183 'return_type': 'std::unique_ptr<base::Value>', | 188 'return_type': 'std::unique_ptr<base::Value>', |
| 184 'pass_type': 'std::unique_ptr<base::Value>', | 189 'pass_type': 'std::unique_ptr<base::Value>', |
| 185 'to_raw_type': '*%s', | 190 'to_raw_type': '*%s', |
| 186 'to_raw_return_type': '%s.get()', | 191 'to_raw_return_type': '%s.get()', |
| 187 'to_pass_type': 'std::move(%s)', | 192 'to_pass_type': 'std::move(%s)', |
| 188 'type': 'std::unique_ptr<base::Value>', | 193 'type': 'std::unique_ptr<base::Value>', |
| 189 'raw_type': 'base::Value', | 194 'raw_type': 'base::Value', |
| 190 'raw_pass_type': 'base::Value*', | 195 'raw_pass_type': 'base::Value*', |
| 191 'raw_return_type': 'const base::Value*', | 196 'raw_return_type': 'const base::Value*', |
| 192 } | 197 } |
| 193 | 198 |
| 194 | 199 |
| 195 def CreateStringTypeDefinition(): | 200 def CreateStringTypeDefinition(): |
| 196 return { | 201 return { |
| 202 'js_type': 'string', |
| 197 'return_type': 'std::string', | 203 'return_type': 'std::string', |
| 198 'pass_type': 'const std::string&', | 204 'pass_type': 'const std::string&', |
| 199 'to_pass_type': '%s', | 205 'to_pass_type': '%s', |
| 200 'to_raw_type': '%s', | 206 'to_raw_type': '%s', |
| 201 'to_raw_return_type': '%s', | 207 'to_raw_return_type': '%s', |
| 202 'type': 'std::string', | 208 'type': 'std::string', |
| 203 'raw_type': 'std::string', | 209 'raw_type': 'std::string', |
| 204 'raw_pass_type': 'const std::string&', | 210 'raw_pass_type': 'const std::string&', |
| 205 'raw_return_type': 'std::string', | 211 'raw_return_type': 'std::string', |
| 206 } | 212 } |
| 207 | 213 |
| 208 | 214 |
| 209 def CreatePrimitiveTypeDefinition(type): | 215 def CreatePrimitiveTypeDefinition(type): |
| 210 typedefs = { | 216 typedefs = { |
| 211 'number': 'double', | 217 'number': 'double', |
| 212 'integer': 'int', | 218 'integer': 'int', |
| 213 'boolean': 'bool', | 219 'boolean': 'bool', |
| 214 } | 220 } |
| 221 js_typedefs = { |
| 222 'number': 'number', |
| 223 'integer': 'number', |
| 224 'boolean': 'boolean', |
| 225 } |
| 215 return { | 226 return { |
| 227 'js_type': js_typedefs[type], |
| 216 'return_type': typedefs[type], | 228 'return_type': typedefs[type], |
| 217 'pass_type': typedefs[type], | 229 'pass_type': typedefs[type], |
| 218 'to_pass_type': '%s', | 230 'to_pass_type': '%s', |
| 219 'to_raw_type': '%s', | 231 'to_raw_type': '%s', |
| 220 'to_raw_return_type': '%s', | 232 'to_raw_return_type': '%s', |
| 221 'type': typedefs[type], | 233 'type': typedefs[type], |
| 222 'raw_type': typedefs[type], | 234 'raw_type': typedefs[type], |
| 223 'raw_pass_type': typedefs[type], | 235 'raw_pass_type': typedefs[type], |
| 224 'raw_return_type': typedefs[type], | 236 'raw_return_type': typedefs[type], |
| 225 } | 237 } |
| 226 | 238 |
| 227 | 239 |
| 228 type_definitions = {} | 240 type_definitions = {} |
| 229 type_definitions['number'] = CreatePrimitiveTypeDefinition('number') | 241 type_definitions['number'] = CreatePrimitiveTypeDefinition('number') |
| 230 type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer') | 242 type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer') |
| 231 type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean') | 243 type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean') |
| 232 type_definitions['string'] = CreateStringTypeDefinition() | 244 type_definitions['string'] = CreateStringTypeDefinition() |
| 233 type_definitions['object'] = CreateObjectTypeDefinition() | 245 type_definitions['object'] = CreateObjectTypeDefinition() |
| 234 type_definitions['any'] = CreateAnyTypeDefinition() | 246 type_definitions['any'] = CreateAnyTypeDefinition() |
| 235 | 247 |
| 236 | 248 |
| 237 def WrapArrayDefinition(type): | 249 def WrapArrayDefinition(type): |
| 238 return { | 250 return { |
| 251 'js_type': '!Array.<%s>' % type['js_type'], |
| 239 'return_type': 'std::vector<%s>' % type['type'], | 252 'return_type': 'std::vector<%s>' % type['type'], |
| 240 'pass_type': 'std::vector<%s>' % type['type'], | 253 'pass_type': 'std::vector<%s>' % type['type'], |
| 241 'to_raw_type': '%s', | 254 'to_raw_type': '%s', |
| 242 'to_raw_return_type': '&%s', | 255 'to_raw_return_type': '&%s', |
| 243 'to_pass_type': 'std::move(%s)', | 256 'to_pass_type': 'std::move(%s)', |
| 244 'type': 'std::vector<%s>' % type['type'], | 257 'type': 'std::vector<%s>' % type['type'], |
| 245 'raw_type': 'std::vector<%s>' % type['type'], | 258 'raw_type': 'std::vector<%s>' % type['type'], |
| 246 'raw_pass_type': 'std::vector<%s>*' % type['type'], | 259 'raw_pass_type': 'std::vector<%s>*' % type['type'], |
| 247 'raw_return_type': 'const std::vector<%s>*' % type['type'], | 260 'raw_return_type': 'const std::vector<%s>*' % type['type'], |
| 248 } | 261 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 file_type) | 476 file_type) |
| 464 with open(output_file, 'w') as f: | 477 with open(output_file, 'w') as f: |
| 465 f.write(template.render(template_context)) | 478 f.write(template.render(template_context)) |
| 466 | 479 |
| 467 | 480 |
| 468 def GenerateDomains(jinja_env, output_dirname, json_api): | 481 def GenerateDomains(jinja_env, output_dirname, json_api): |
| 469 GeneratePerDomain( | 482 GeneratePerDomain( |
| 470 jinja_env, os.path.join(output_dirname, 'devtools', 'domains'), json_api, | 483 jinja_env, os.path.join(output_dirname, 'devtools', 'domains'), json_api, |
| 471 'domain', ['cc', 'h'], | 484 'domain', ['cc', 'h'], |
| 472 lambda domain_name: domain_name) | 485 lambda domain_name: domain_name) |
| 486 GeneratePerDomain( |
| 487 jinja_env, os.path.join(output_dirname, 'devtools_js'), json_api, |
| 488 'domain', ['js'], |
| 489 lambda domain_name: domain_name) |
| 473 | 490 |
| 474 | 491 |
| 475 def GenerateTypes(jinja_env, output_dirname, json_api): | 492 def GenerateTypes(jinja_env, output_dirname, json_api): |
| 476 # Generate forward declarations for types. | 493 # Generate forward declarations for types. |
| 477 GeneratePerDomain( | 494 GeneratePerDomain( |
| 478 jinja_env, os.path.join(output_dirname, 'devtools', 'internal'), | 495 jinja_env, os.path.join(output_dirname, 'devtools', 'internal'), |
| 479 json_api, 'domain_types_forward_declarations', ['h'], | 496 json_api, 'domain_types_forward_declarations', ['h'], |
| 480 lambda domain_name: 'types_forward_declarations_%s' % (domain_name, )) | 497 lambda domain_name: 'types_forward_declarations_%s' % (domain_name, )) |
| 481 # Generate types on per-domain basis. | 498 # Generate types on per-domain basis. |
| 482 GeneratePerDomain( | 499 GeneratePerDomain( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 499 InitializeDomainDependencies(json_api) | 516 InitializeDomainDependencies(json_api) |
| 500 PatchExperimentalCommandsAndEvents(json_api) | 517 PatchExperimentalCommandsAndEvents(json_api) |
| 501 EnsureCommandsHaveParametersAndReturnTypes(json_api) | 518 EnsureCommandsHaveParametersAndReturnTypes(json_api) |
| 502 SynthesizeCommandTypes(json_api) | 519 SynthesizeCommandTypes(json_api) |
| 503 SynthesizeEventTypes(json_api) | 520 SynthesizeEventTypes(json_api) |
| 504 PatchFullQualifiedRefs(json_api) | 521 PatchFullQualifiedRefs(json_api) |
| 505 CreateTypeDefinitions(json_api) | 522 CreateTypeDefinitions(json_api) |
| 506 GenerateDomains(jinja_env, output_dirname, json_api) | 523 GenerateDomains(jinja_env, output_dirname, json_api) |
| 507 GenerateTypes(jinja_env, output_dirname, json_api) | 524 GenerateTypes(jinja_env, output_dirname, json_api) |
| 508 GenerateTypeConversions(jinja_env, output_dirname, json_api) | 525 GenerateTypeConversions(jinja_env, output_dirname, json_api) |
| OLD | NEW |