Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: lib/dom/scripts/generator.py

Issue 10116025: Introduce CompositeIDLTypeInfo and clean up the code that deals with sequences. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import re 9 import re
10 10
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 native_type=None, ref_counted=True, 428 native_type=None, ref_counted=True,
429 has_dart_wrapper=True, conversion_template=None, 429 has_dart_wrapper=True, conversion_template=None,
430 custom_to_dart=False, conversion_includes=[]): 430 custom_to_dart=False, conversion_includes=[]):
431 self._idl_type = idl_type 431 self._idl_type = idl_type
432 self._dart_type = dart_type 432 self._dart_type = dart_type
433 self._native_type = native_type 433 self._native_type = native_type
434 self._ref_counted = ref_counted 434 self._ref_counted = ref_counted
435 self._has_dart_wrapper = has_dart_wrapper 435 self._has_dart_wrapper = has_dart_wrapper
436 self._conversion_template = conversion_template 436 self._conversion_template = conversion_template
437 self._custom_to_dart = custom_to_dart 437 self._custom_to_dart = custom_to_dart
438 self._conversion_includes = conversion_includes 438 self._conversion_includes = conversion_includes + [idl_type]
439 439
440 def idl_type(self): 440 def idl_type(self):
441 return self._idl_type 441 return self._idl_type
442 442
443 def dart_type(self): 443 def dart_type(self):
444 if self._dart_type: 444 return self._dart_type or self._idl_type
445 return self._dart_type
446
447 match = re.match(r'sequence<(\w*)>$', self._idl_type)
448 if match:
449 return 'List<%s>' % DartType(match.group(1))
450
451 return self._idl_type
452 445
453 def native_type(self): 446 def native_type(self):
454 if self._native_type: 447 return self._native_type or self._idl_type
455 return self._native_type
456 return self._idl_type
457 448
458 def parameter_adapter_info(self): 449 def parameter_adapter_info(self):
459 native_type = self.native_type() 450 native_type = self.native_type()
460 if self._ref_counted: 451 if self._ref_counted:
461 native_type = 'RefPtr< %s >' % native_type 452 native_type = 'RefPtr< %s >' % native_type
462 if self._has_dart_wrapper: 453 if self._has_dart_wrapper:
463 wrapper_type = 'Dart%s' % self.idl_type() 454 wrapper_type = 'Dart%s' % self.idl_type()
464 adapter_type = 'ParameterAdapter<%s, %s>' % (native_type, wrapper_type) 455 adapter_type = 'ParameterAdapter<%s, %s>' % (native_type, wrapper_type)
465 return (adapter_type, '"%s.h"' % wrapper_type) 456 return (adapter_type, '"%s.h"' % wrapper_type)
466 return ('ParameterAdapter< %s >' % native_type, '"%s.h"' % self._idl_type) 457 return ('ParameterAdapter< %s >' % native_type, '"%s.h"' % self._idl_type)
(...skipping 27 matching lines...) Expand all
494 if self._idl_type.startswith('SVGPathSeg'): 485 if self._idl_type.startswith('SVGPathSeg'):
495 include = self._idl_type.replace('Abs', '').replace('Rel', '') 486 include = self._idl_type.replace('Abs', '').replace('Rel', '')
496 else: 487 else:
497 include = self._idl_type 488 include = self._idl_type
498 return ['"%s.h"' % include] + _svg_supplemental_includes 489 return ['"%s.h"' % include] + _svg_supplemental_includes
499 490
500 def receiver(self): 491 def receiver(self):
501 return 'receiver->' 492 return 'receiver->'
502 493
503 def conversion_includes(self): 494 def conversion_includes(self):
504 def NeededDartTypes(type_name): 495 return ['"Dart%s.h"' % include for include in self._conversion_includes]
505 if re.match(r'Dynamic(\/.*)?$', type_name): return []
506 match = re.match(r'List<(\w*)>$', type_name)
507 if match:
508 return NeededDartTypes(match.group(1))
509 return [type_name]
510
511 return ['"Dart%s.h"' % include
512 for include in
513 NeededDartTypes(self.dart_type()) + self._conversion_includes]
514 496
515 def conversion_cast(self, expression): 497 def conversion_cast(self, expression):
516 if self._conversion_template: 498 if self._conversion_template:
517 return self._conversion_template % expression 499 return self._conversion_template % expression
518 return expression 500 return expression
519 501
520 def custom_to_dart(self): 502 def custom_to_dart(self):
521 return self._custom_to_dart 503 return self._custom_to_dart
522 504
505
506 class SequenceIDLTypeInfo(IDLTypeInfo):
507 def __init__(self, idl_type, item_info):
508 super(SequenceIDLTypeInfo, self).__init__(idl_type)
509 self._item_info = item_info
510
511 def dart_type(self):
512 return 'List<%s>' % self._item_info.dart_type()
513
514 def conversion_includes(self):
515 return self._item_info.conversion_includes()
516
517
523 class PrimitiveIDLTypeInfo(IDLTypeInfo): 518 class PrimitiveIDLTypeInfo(IDLTypeInfo):
524 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, 519 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False,
525 conversion_template=None, conversion_includes=[], 520 conversion_template=None,
526 webcore_getter_name='getAttribute', 521 webcore_getter_name='getAttribute',
527 webcore_setter_name='setAttribute'): 522 webcore_setter_name='setAttribute'):
528 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 523 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
529 native_type=native_type, ref_counted=ref_counted, 524 native_type=native_type, ref_counted=ref_counted,
530 conversion_template=conversion_template, 525 conversion_template=conversion_template)
531 conversion_includes=conversion_includes)
532 self._webcore_getter_name = webcore_getter_name 526 self._webcore_getter_name = webcore_getter_name
533 self._webcore_setter_name = webcore_setter_name 527 self._webcore_setter_name = webcore_setter_name
534 528
535 def parameter_adapter_info(self): 529 def parameter_adapter_info(self):
536 native_type = self.native_type() 530 native_type = self.native_type()
537 if self._ref_counted: 531 if self._ref_counted:
538 native_type = 'RefPtr< %s >' % native_type 532 native_type = 'RefPtr< %s >' % native_type
539 return ('ParameterAdapter< %s >' % native_type, None) 533 return ('ParameterAdapter< %s >' % native_type, None)
540 534
541 def parameter_type(self): 535 def parameter_type(self):
542 if self.native_type() == 'String': 536 if self.native_type() == 'String':
543 return 'const String&' 537 return 'const String&'
544 return self.native_type() 538 return self.native_type()
545 539
546 def conversion_includes(self): 540 def conversion_includes(self):
547 return ['"Dart%s.h"' % include for include in self._conversion_includes] 541 return []
548 542
549 def webcore_getter_name(self): 543 def webcore_getter_name(self):
550 return self._webcore_getter_name 544 return self._webcore_getter_name
551 545
552 def webcore_setter_name(self): 546 def webcore_setter_name(self):
553 return self._webcore_setter_name 547 return self._webcore_setter_name
554 548
555 class SVGTearOffIDLTypeInfo(IDLTypeInfo): 549 class SVGTearOffIDLTypeInfo(IDLTypeInfo):
556 def __init__(self, idl_type, native_type='', ref_counted=True): 550 def __init__(self, idl_type, native_type='', ref_counted=True):
557 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, 551 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'), 607 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'),
614 # TODO(sra): Come up with some meaningful name so that where this appears in 608 # TODO(sra): Come up with some meaningful name so that where this appears in
615 # the documentation, the user is made aware that only a limited subset of 609 # the documentation, the user is made aware that only a limited subset of
616 # serializable types are actually permitted. 610 # serializable types are actually permitted.
617 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), 611 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True),
618 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 612 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
619 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 613 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
620 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), 614 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'),
621 615
622 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'), 616 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'),
623 'DOMStringMap': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<String, String>',
624 conversion_includes=['DOMStringMap']),
625 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), 617 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'),
626 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), 618 'void': PrimitiveIDLTypeInfo('void', dart_type='void'),
627 619
628 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), 620 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']),
629 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), 621 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'),
622 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') ,
630 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), 623 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True),
631 'Element': IDLTypeInfo('Element', custom_to_dart=True), 624 'Element': IDLTypeInfo('Element', custom_to_dart=True),
632 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), 625 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False),
633 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), 626 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False),
634 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), 627 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True),
635 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', 628 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', has_dart_wrapper=False) ,
636 native_type='IDBAny', 629 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', has_dart_wrapper=False) ,
637 has_dart_wrapper=False,
638 conversion_includes=['IDBAny']),
639 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic',
640 native_type='IDBKey',
641 has_dart_wrapper=False,
642 conversion_includes=['IDBKey']),
643 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra pper=False), 630 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra pper=False),
644 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), 631 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False),
645 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]), 632 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]),
646 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), 633 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True),
647 634
648 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), 635 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'),
649 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), 636 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'),
650 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False), 637 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False),
651 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), 638 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'),
652 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'), 639 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'),
(...skipping 11 matching lines...) Expand all
664 _svg_supplemental_includes = [ 651 _svg_supplemental_includes = [
665 '"SVGAnimatedPropertyTearOff.h"', 652 '"SVGAnimatedPropertyTearOff.h"',
666 '"SVGAnimatedListPropertyTearOff.h"', 653 '"SVGAnimatedListPropertyTearOff.h"',
667 '"SVGStaticListPropertyTearOff.h"', 654 '"SVGStaticListPropertyTearOff.h"',
668 '"SVGAnimatedListPropertyTearOff.h"', 655 '"SVGAnimatedListPropertyTearOff.h"',
669 '"SVGTransformListPropertyTearOff.h"', 656 '"SVGTransformListPropertyTearOff.h"',
670 '"SVGPathSegListPropertyTearOff.h"', 657 '"SVGPathSegListPropertyTearOff.h"',
671 ] 658 ]
672 659
673 def GetIDLTypeInfo(idl_type_name): 660 def GetIDLTypeInfo(idl_type_name):
661 match = re.match(r'sequence<(\w+)>$', idl_type_name)
662 if match:
663 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
674 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 664 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698