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

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: . 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 if self._dart_type:
Anton Muhin 2012/04/18 14:25:53 return self._dart_type or self._idl_type or it's t
podivilov 2012/04/18 14:56:26 Done.
445 return self._dart_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 446 return self._idl_type
452 447
453 def native_type(self): 448 def native_type(self):
454 if self._native_type: 449 if self._native_type:
455 return self._native_type 450 return self._native_type
456 return self._idl_type 451 return self._idl_type
457 452
458 def parameter_adapter_info(self): 453 def parameter_adapter_info(self):
459 native_type = self.native_type() 454 native_type = self.native_type()
460 if self._ref_counted: 455 if self._ref_counted:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 if self._idl_type.startswith('SVGPathSeg'): 489 if self._idl_type.startswith('SVGPathSeg'):
495 include = self._idl_type.replace('Abs', '').replace('Rel', '') 490 include = self._idl_type.replace('Abs', '').replace('Rel', '')
496 else: 491 else:
497 include = self._idl_type 492 include = self._idl_type
498 return ['"%s.h"' % include] + _svg_supplemental_includes 493 return ['"%s.h"' % include] + _svg_supplemental_includes
499 494
500 def receiver(self): 495 def receiver(self):
501 return 'receiver->' 496 return 'receiver->'
502 497
503 def conversion_includes(self): 498 def conversion_includes(self):
504 def NeededDartTypes(type_name):
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 499 return ['"Dart%s.h"' % include
512 for include in 500 for include in
513 NeededDartTypes(self.dart_type()) + self._conversion_includes] 501 [self.idl_type()] + self._conversion_includes]
Anton Muhin 2012/04/18 14:25:53 maybe always add self.idl_type() into self._conver
podivilov 2012/04/18 14:56:26 Done.
514 502
515 def conversion_cast(self, expression): 503 def conversion_cast(self, expression):
516 if self._conversion_template: 504 if self._conversion_template:
517 return self._conversion_template % expression 505 return self._conversion_template % expression
518 return expression 506 return expression
519 507
520 def custom_to_dart(self): 508 def custom_to_dart(self):
521 return self._custom_to_dart 509 return self._custom_to_dart
522 510
511
512 class CompositeIDLTypeInfo(IDLTypeInfo):
Anton Muhin 2012/04/18 14:25:53 do you want be that generic? do we expect to have
podivilov 2012/04/18 14:56:26 Done.
513 def __init__(self, idl_type, collection_info, item_info):
514 super(CompositeIDLTypeInfo, self).__init__(idl_type)
515 self._collection_info = collection_info
516 self._item_info = item_info
517
518 def dart_type(self):
519 collection_type = self._collection_info.dart_type()
520 item_type = self._item_info.dart_type()
521 return '%s<%s>' % (collection_type, item_type)
522
523 def conversion_includes(self):
524 return self._item_info.conversion_includes()
525
526
523 class PrimitiveIDLTypeInfo(IDLTypeInfo): 527 class PrimitiveIDLTypeInfo(IDLTypeInfo):
524 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, 528 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False,
525 conversion_template=None, conversion_includes=[], 529 conversion_template=None,
526 webcore_getter_name='getAttribute', 530 webcore_getter_name='getAttribute',
527 webcore_setter_name='setAttribute'): 531 webcore_setter_name='setAttribute'):
528 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 532 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
529 native_type=native_type, ref_counted=ref_counted, 533 native_type=native_type, ref_counted=ref_counted,
530 conversion_template=conversion_template, 534 conversion_template=conversion_template)
531 conversion_includes=conversion_includes)
532 self._webcore_getter_name = webcore_getter_name 535 self._webcore_getter_name = webcore_getter_name
533 self._webcore_setter_name = webcore_setter_name 536 self._webcore_setter_name = webcore_setter_name
534 537
535 def parameter_adapter_info(self): 538 def parameter_adapter_info(self):
536 native_type = self.native_type() 539 native_type = self.native_type()
537 if self._ref_counted: 540 if self._ref_counted:
538 native_type = 'RefPtr< %s >' % native_type 541 native_type = 'RefPtr< %s >' % native_type
539 return ('ParameterAdapter< %s >' % native_type, None) 542 return ('ParameterAdapter< %s >' % native_type, None)
540 543
541 def parameter_type(self): 544 def parameter_type(self):
542 if self.native_type() == 'String': 545 if self.native_type() == 'String':
543 return 'const String&' 546 return 'const String&'
544 return self.native_type() 547 return self.native_type()
545 548
546 def conversion_includes(self): 549 def conversion_includes(self):
547 return ['"Dart%s.h"' % include for include in self._conversion_includes] 550 return []
548 551
549 def webcore_getter_name(self): 552 def webcore_getter_name(self):
550 return self._webcore_getter_name 553 return self._webcore_getter_name
551 554
552 def webcore_setter_name(self): 555 def webcore_setter_name(self):
553 return self._webcore_setter_name 556 return self._webcore_setter_name
554 557
555 class SVGTearOffIDLTypeInfo(IDLTypeInfo): 558 class SVGTearOffIDLTypeInfo(IDLTypeInfo):
556 def __init__(self, idl_type, native_type='', ref_counted=True): 559 def __init__(self, idl_type, native_type='', ref_counted=True):
557 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, 560 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'), 616 '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 617 # 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 618 # the documentation, the user is made aware that only a limited subset of
616 # serializable types are actually permitted. 619 # serializable types are actually permitted.
617 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), 620 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True),
618 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 621 # 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 622 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
620 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), 623 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'),
621 624
622 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'), 625 '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'), 626 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'),
626 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), 627 'void': PrimitiveIDLTypeInfo('void', dart_type='void'),
627 628
628 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), 629 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']),
629 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), 630 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'),
631 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') ,
630 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), 632 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True),
631 'Element': IDLTypeInfo('Element', custom_to_dart=True), 633 'Element': IDLTypeInfo('Element', custom_to_dart=True),
632 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), 634 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False),
633 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), 635 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False),
634 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), 636 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True),
635 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', 637 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', has_dart_wrapper=False) ,
636 native_type='IDBAny', 638 '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), 639 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra pper=False),
644 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), 640 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False),
645 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]), 641 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]),
646 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), 642 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True),
647 643
648 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), 644 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'),
649 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), 645 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'),
650 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False), 646 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False),
651 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), 647 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'),
652 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'), 648 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'),
(...skipping 11 matching lines...) Expand all
664 _svg_supplemental_includes = [ 660 _svg_supplemental_includes = [
665 '"SVGAnimatedPropertyTearOff.h"', 661 '"SVGAnimatedPropertyTearOff.h"',
666 '"SVGAnimatedListPropertyTearOff.h"', 662 '"SVGAnimatedListPropertyTearOff.h"',
667 '"SVGStaticListPropertyTearOff.h"', 663 '"SVGStaticListPropertyTearOff.h"',
668 '"SVGAnimatedListPropertyTearOff.h"', 664 '"SVGAnimatedListPropertyTearOff.h"',
669 '"SVGTransformListPropertyTearOff.h"', 665 '"SVGTransformListPropertyTearOff.h"',
670 '"SVGPathSegListPropertyTearOff.h"', 666 '"SVGPathSegListPropertyTearOff.h"',
671 ] 667 ]
672 668
673 def GetIDLTypeInfo(idl_type_name): 669 def GetIDLTypeInfo(idl_type_name):
670 match = re.match(r'(\w+)<(\w+)>$', idl_type_name)
671 if match:
672 collection_info = GetIDLTypeInfo(match.group(1))
673 item_info = GetIDLTypeInfo(match.group(2))
674 return CompositeIDLTypeInfo(idl_type_name, collection_info, item_info)
674 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 675 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