Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 itertools | 6 import itertools |
| 7 import json | 7 import json |
| 8 import os.path | 8 import os.path |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 raise ValueError('Did not process %s %s' % (child.cls, child)) | 311 raise ValueError('Did not process %s %s' % (child.cls, child)) |
| 312 enum.append(enum_value) | 312 enum.append(enum_value) |
| 313 elif node.cls == 'Comment': | 313 elif node.cls == 'Comment': |
| 314 self.description = ProcessComment(node.GetName())[0] | 314 self.description = ProcessComment(node.GetName())[0] |
| 315 else: | 315 else: |
| 316 sys.exit('Did not process %s %s' % (node.cls, node)) | 316 sys.exit('Did not process %s %s' % (node.cls, node)) |
| 317 result = {'id' : self.node.GetName(), | 317 result = {'id' : self.node.GetName(), |
| 318 'description': self.description, | 318 'description': self.description, |
| 319 'type': 'string', | 319 'type': 'string', |
| 320 'enum': enum} | 320 'enum': enum} |
| 321 for property_name in ( | 321 for property_name in ( |
|
not at google - send to devlin
2014/05/14 23:43:43
should fit on 1 line now
David Tseng
2014/05/15 01:12:37
Not anymore with the below change.
| |
| 322 'inline_doc', 'noinline_doc', 'nodoc', 'cpp_omit_enum_type',): | 322 'inline_doc', 'noinline_doc', 'nodoc',): |
| 323 if self.node.GetProperty(property_name): | 323 if self.node.GetProperty(property_name): |
| 324 result[property_name] = True | 324 result[property_name] = True |
|
not at google - send to devlin
2014/05/14 23:43:43
hm I wonder if the "default" value for IDL attribu
David Tseng
2014/05/15 01:12:37
Done (after verifying True gets returned for prope
| |
| 325 if self.node.GetProperty('cpp_enum_prefix_override'): | |
| 326 result['cpp_enum_prefix_override'] = self.node.GetProperty( | |
| 327 'cpp_enum_prefix_override') | |
| 325 if self.node.GetProperty('deprecated'): | 328 if self.node.GetProperty('deprecated'): |
| 326 result[deprecated] = self.node.GetProperty('deprecated') | 329 result[deprecated] = self.node.GetProperty('deprecated') |
| 327 return result | 330 return result |
| 328 | 331 |
| 329 | 332 |
| 330 class Namespace(object): | 333 class Namespace(object): |
| 331 ''' | 334 ''' |
| 332 Given an IDLNode representing an IDL namespace, converts into a Python | 335 Given an IDLNode representing an IDL namespace, converts into a Python |
| 333 dictionary that the JSON schema compiler expects to see. | 336 dictionary that the JSON schema compiler expects to see. |
| 334 ''' | 337 ''' |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 | 403 |
| 401 def __init__(self, idl): | 404 def __init__(self, idl): |
| 402 self.idl = idl | 405 self.idl = idl |
| 403 | 406 |
| 404 def process(self): | 407 def process(self): |
| 405 namespaces = [] | 408 namespaces = [] |
| 406 nodoc = False | 409 nodoc = False |
| 407 internal = False | 410 internal = False |
| 408 description = None | 411 description = None |
| 409 platforms = None | 412 platforms = None |
| 410 compiler_options = None | 413 compiler_options = {} |
| 411 deprecated = None | 414 deprecated = None |
| 412 for node in self.idl: | 415 for node in self.idl: |
| 413 if node.cls == 'Namespace': | 416 if node.cls == 'Namespace': |
| 414 if not description: | 417 if not description: |
| 415 # TODO(kalman): Go back to throwing an error here. | 418 # TODO(kalman): Go back to throwing an error here. |
| 416 print('%s must have a namespace-level comment. This will ' | 419 print('%s must have a namespace-level comment. This will ' |
| 417 'appear on the API summary page.' % node.GetName()) | 420 'appear on the API summary page.' % node.GetName()) |
| 418 description = '' | 421 description = '' |
| 419 namespace = Namespace(node, description, nodoc, internal, | 422 namespace = Namespace(node, description, nodoc, internal, |
| 420 platforms=platforms, | 423 platforms=platforms, |
| 421 compiler_options=compiler_options, | 424 compiler_options=compiler_options or None, |
| 422 deprecated=deprecated) | 425 deprecated=deprecated) |
| 423 namespaces.append(namespace.process()) | 426 namespaces.append(namespace.process()) |
| 424 nodoc = False | 427 nodoc = False |
| 425 internal = False | 428 internal = False |
| 426 platforms = None | 429 platforms = None |
| 427 compiler_options = None | 430 compiler_options = None |
| 428 elif node.cls == 'Copyright': | 431 elif node.cls == 'Copyright': |
| 429 continue | 432 continue |
| 430 elif node.cls == 'Comment': | 433 elif node.cls == 'Comment': |
| 431 description = node.GetName() | 434 description = node.GetName() |
| 432 elif node.cls == 'ExtAttribute': | 435 elif node.cls == 'ExtAttribute': |
| 433 if node.name == 'nodoc': | 436 if node.name == 'nodoc': |
| 434 nodoc = bool(node.value) | 437 nodoc = bool(node.value) |
| 435 elif node.name == 'internal': | 438 elif node.name == 'internal': |
| 436 internal = bool(node.value) | 439 internal = bool(node.value) |
| 437 elif node.name == 'platforms': | 440 elif node.name == 'platforms': |
| 438 platforms = list(node.value) | 441 platforms = list(node.value) |
| 439 elif node.name == 'implemented_in': | 442 elif node.name == 'implemented_in': |
| 440 compiler_options = {'implemented_in': node.value} | 443 compiler_options['implemented_in'] = node.value |
| 444 elif node.name == 'camel_case_enum_to_string': | |
| 445 compiler_options['camel_case_enum_to_string'] = node.value | |
| 441 elif node.name == 'deprecated': | 446 elif node.name == 'deprecated': |
| 442 deprecated = str(node.value) | 447 deprecated = str(node.value) |
| 443 else: | 448 else: |
| 444 continue | 449 continue |
| 445 else: | 450 else: |
| 446 sys.exit('Did not process %s %s' % (node.cls, node)) | 451 sys.exit('Did not process %s %s' % (node.cls, node)) |
| 447 return namespaces | 452 return namespaces |
| 448 | 453 |
| 449 | 454 |
| 450 def Load(filename): | 455 def Load(filename): |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 467 Dump a json serialization of parse result for the IDL files whose names | 472 Dump a json serialization of parse result for the IDL files whose names |
| 468 were passed in on the command line. | 473 were passed in on the command line. |
| 469 ''' | 474 ''' |
| 470 for filename in sys.argv[1:]: | 475 for filename in sys.argv[1:]: |
| 471 schema = Load(filename) | 476 schema = Load(filename) |
| 472 print json.dumps(schema, indent=2) | 477 print json.dumps(schema, indent=2) |
| 473 | 478 |
| 474 | 479 |
| 475 if __name__ == '__main__': | 480 if __name__ == '__main__': |
| 476 Main() | 481 Main() |
| OLD | NEW |