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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 'to_raw_type': '*%s', | 185 'to_raw_type': '*%s', |
186 'to_raw_return_type': '%s.get()', | 186 'to_raw_return_type': '%s.get()', |
187 'to_pass_type': 'std::move(%s)', | 187 'to_pass_type': 'std::move(%s)', |
188 'type': 'std::unique_ptr<base::Value>', | 188 'type': 'std::unique_ptr<base::Value>', |
189 'raw_type': 'base::Value', | 189 'raw_type': 'base::Value', |
190 'raw_pass_type': 'base::Value*', | 190 'raw_pass_type': 'base::Value*', |
191 'raw_return_type': 'const base::Value*', | 191 'raw_return_type': 'const base::Value*', |
192 } | 192 } |
193 | 193 |
194 | 194 |
195 def CreateStringTypeDefinition(domain): | 195 def CreateStringTypeDefinition(): |
196 return { | 196 return { |
197 'return_type': 'std::string', | 197 'return_type': 'std::string', |
198 'pass_type': 'const std::string&', | 198 'pass_type': 'const std::string&', |
199 'to_pass_type': '%s', | 199 'to_pass_type': '%s', |
200 'to_raw_type': '%s', | 200 'to_raw_type': '%s', |
201 'to_raw_return_type': '%s', | 201 'to_raw_return_type': '%s', |
202 'type': 'std::string', | 202 'type': 'std::string', |
203 'raw_type': 'std::string', | 203 'raw_type': 'std::string', |
204 'raw_pass_type': 'const std::string&', | 204 'raw_pass_type': 'const std::string&', |
205 'raw_return_type': 'std::string', | 205 'raw_return_type': 'std::string', |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 def CreatePrimitiveTypeDefinition(type): | 209 def CreatePrimitiveTypeDefinition(type): |
210 typedefs = { | 210 typedefs = { |
211 'number': 'double', | 211 'number': 'double', |
212 'integer': 'int', | 212 'integer': 'int', |
213 'boolean': 'bool', | 213 'boolean': 'bool', |
214 'string': 'std::string', | |
215 } | 214 } |
216 return { | 215 return { |
217 'return_type': typedefs[type], | 216 'return_type': typedefs[type], |
218 'pass_type': typedefs[type], | 217 'pass_type': typedefs[type], |
219 'to_pass_type': '%s', | 218 'to_pass_type': '%s', |
220 'to_raw_type': '%s', | 219 'to_raw_type': '%s', |
221 'to_raw_return_type': '%s', | 220 'to_raw_return_type': '%s', |
222 'type': typedefs[type], | 221 'type': typedefs[type], |
223 'raw_type': typedefs[type], | 222 'raw_type': typedefs[type], |
224 'raw_pass_type': typedefs[type], | 223 'raw_pass_type': typedefs[type], |
225 'raw_return_type': typedefs[type], | 224 'raw_return_type': typedefs[type], |
226 } | 225 } |
227 | 226 |
228 | 227 |
229 type_definitions = {} | 228 type_definitions = {} |
230 type_definitions['number'] = CreatePrimitiveTypeDefinition('number') | 229 type_definitions['number'] = CreatePrimitiveTypeDefinition('number') |
231 type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer') | 230 type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer') |
232 type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean') | 231 type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean') |
233 type_definitions['string'] = CreatePrimitiveTypeDefinition('string') | 232 type_definitions['string'] = CreateStringTypeDefinition() |
234 type_definitions['object'] = CreateObjectTypeDefinition() | 233 type_definitions['object'] = CreateObjectTypeDefinition() |
235 type_definitions['any'] = CreateAnyTypeDefinition() | 234 type_definitions['any'] = CreateAnyTypeDefinition() |
236 | 235 |
237 | 236 |
238 def WrapArrayDefinition(type): | 237 def WrapArrayDefinition(type): |
239 return { | 238 return { |
240 'return_type': 'std::vector<%s>' % type['type'], | 239 'return_type': 'std::vector<%s>' % type['type'], |
241 'pass_type': 'std::vector<%s>' % type['type'], | 240 'pass_type': 'std::vector<%s>' % type['type'], |
242 'to_raw_type': '%s', | 241 'to_raw_type': '%s', |
243 'to_raw_return_type': '&%s', | 242 'to_raw_return_type': '&%s', |
(...skipping 21 matching lines...) Expand all Loading... |
265 items_type = type['items']['type'] | 264 items_type = type['items']['type'] |
266 type_definitions[domain['domain'] + '.' + type['id']] = ( | 265 type_definitions[domain['domain'] + '.' + type['id']] = ( |
267 WrapArrayDefinition(type_definitions[items_type])) | 266 WrapArrayDefinition(type_definitions[items_type])) |
268 elif 'enum' in type: | 267 elif 'enum' in type: |
269 type_definitions[domain['domain'] + '.' + type['id']] = ( | 268 type_definitions[domain['domain'] + '.' + type['id']] = ( |
270 CreateEnumTypeDefinition(domain['domain'], type)) | 269 CreateEnumTypeDefinition(domain['domain'], type)) |
271 type['$ref'] = domain['domain'] + '.' + type['id'] | 270 type['$ref'] = domain['domain'] + '.' + type['id'] |
272 elif type['type'] == 'any': | 271 elif type['type'] == 'any': |
273 type_definitions[domain['domain'] + '.' + type['id']] = ( | 272 type_definitions[domain['domain'] + '.' + type['id']] = ( |
274 CreateAnyTypeDefinition()) | 273 CreateAnyTypeDefinition()) |
| 274 elif type['type'] == 'string': |
| 275 type_definitions[domain['domain'] + '.' + type['id']] = ( |
| 276 CreateStringTypeDefinition()) |
275 else: | 277 else: |
276 type_definitions[domain['domain'] + '.' + type['id']] = ( | 278 type_definitions[domain['domain'] + '.' + type['id']] = ( |
277 CreatePrimitiveTypeDefinition(type['type'])) | 279 CreatePrimitiveTypeDefinition(type['type'])) |
278 | 280 |
279 | 281 |
280 def TypeDefinition(name): | 282 def TypeDefinition(name): |
281 return type_definitions[name] | 283 return type_definitions[name] |
282 | 284 |
283 | 285 |
284 def ResolveType(property): | 286 def ResolveType(property): |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 InitializeDomainDependencies(json_api) | 499 InitializeDomainDependencies(json_api) |
498 PatchExperimentalCommandsAndEvents(json_api) | 500 PatchExperimentalCommandsAndEvents(json_api) |
499 EnsureCommandsHaveParametersAndReturnTypes(json_api) | 501 EnsureCommandsHaveParametersAndReturnTypes(json_api) |
500 SynthesizeCommandTypes(json_api) | 502 SynthesizeCommandTypes(json_api) |
501 SynthesizeEventTypes(json_api) | 503 SynthesizeEventTypes(json_api) |
502 PatchFullQualifiedRefs(json_api) | 504 PatchFullQualifiedRefs(json_api) |
503 CreateTypeDefinitions(json_api) | 505 CreateTypeDefinitions(json_api) |
504 GenerateDomains(jinja_env, output_dirname, json_api) | 506 GenerateDomains(jinja_env, output_dirname, json_api) |
505 GenerateTypes(jinja_env, output_dirname, json_api) | 507 GenerateTypes(jinja_env, output_dirname, json_api) |
506 GenerateTypeConversions(jinja_env, output_dirname, json_api) | 508 GenerateTypeConversions(jinja_env, output_dirname, json_api) |
OLD | NEW |