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

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

Issue 10831035: Refactor conversion to native. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | lib/dom/scripts/systemnative.py » ('j') | 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 copy 9 import copy
10 import re 10 import re
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 def dart_type(self): 477 def dart_type(self):
478 return self._data.dart_type or self._idl_type 478 return self._data.dart_type or self._idl_type
479 479
480 def native_type(self): 480 def native_type(self):
481 return self._data.native_type or self._idl_type 481 return self._data.native_type or self._idl_type
482 482
483 def requires_v8_scope(self): 483 def requires_v8_scope(self):
484 return self._data.requires_v8_scope 484 return self._data.requires_v8_scope
485 485
486 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa ce_name): 486 def to_native_info(self, idl_node, accept_null, name, interface_name):
487 cls = 'Dart%s' % self.idl_type()
488
487 if 'Callback' in idl_node.ext_attrs: 489 if 'Callback' in idl_node.ext_attrs:
488 function_name = 'create' 490 function_name = 'create'
489 if accept_null: 491 if accept_null:
490 function_name += 'WithNullCheck' 492 function_name += 'WithNullCheck'
491 emitter.Emit( 493 return name, 'RefPtr<%s>' % self.native_type(), cls, function_name
podivilov 2012/08/21 12:11:31 I believe we had an agreement that the code should
492 '\n'
493 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::$FUNCTION_NAME($HANDLE, ex ception);\n'
494 ' if (exception)\n'
495 ' goto fail;\n',
496 TYPE=self.native_type(),
497 NAME=name,
498 FUNCTION_NAME=function_name,
499 IDL_TYPE=self.idl_type(),
500 HANDLE=handle)
501 return name
502 494
503 argument = name 495 argument = name
504 if self.custom_to_native(): 496 if self.custom_to_native():
505 type = 'RefPtr<%s>' % self.native_type() 497 type = 'RefPtr<%s>' % self.native_type()
506 argument = '%s.get()' % name 498 argument = '%s.get()' % name
507 else: 499 else:
508 type = '%s*' % self.native_type() 500 type = '%s*' % self.native_type()
509 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'): 501 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'):
510 argument = '%s->propertyReference()' % name 502 argument = '%s->propertyReference()' % name
511 emitter.Emit( 503 return argument, type, cls, 'toNative'
512 '\n'
513 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n'
514 ' if (exception)\n'
515 ' goto fail;\n',
516 TYPE=type,
517 NAME=name,
518 IDL_TYPE=self.idl_type(),
519 HANDLE=handle)
520 return argument
521 504
522 def custom_to_native(self): 505 def custom_to_native(self):
523 return self._data.custom_to_native 506 return self._data.custom_to_native
524 507
525 def parameter_type(self): 508 def parameter_type(self):
526 return '%s*' % self.native_type() 509 return '%s*' % self.native_type()
527 510
528 def webcore_includes(self): 511 def webcore_includes(self):
529 WTF_INCLUDES = [ 512 WTF_INCLUDES = [
530 'ArrayBuffer', 513 'ArrayBuffer',
(...skipping 23 matching lines...) Expand all
554 include = self._idl_type 537 include = self._idl_type
555 return ['"%s.h"' % include] + _svg_supplemental_includes 538 return ['"%s.h"' % include] + _svg_supplemental_includes
556 539
557 def receiver(self): 540 def receiver(self):
558 return 'receiver->' 541 return 'receiver->'
559 542
560 def conversion_includes(self): 543 def conversion_includes(self):
561 includes = [self._idl_type] + (self._data.conversion_includes or []) 544 includes = [self._idl_type] + (self._data.conversion_includes or [])
562 return ['"Dart%s.h"' % include for include in includes] 545 return ['"Dart%s.h"' % include for include in includes]
563 546
564 def to_native_includes(self):
565 return ['"Dart%s.h"' % self.idl_type()]
566
567 def to_dart_conversion(self, value, interface_name=None, attributes=None): 547 def to_dart_conversion(self, value, interface_name=None, attributes=None):
568 return 'Dart%s::toDart(%s)' % (self._idl_type, value) 548 return 'Dart%s::toDart(%s)' % (self._idl_type, value)
569 549
570 def custom_to_dart(self): 550 def custom_to_dart(self):
571 return self._data.custom_to_dart 551 return self._data.custom_to_dart
572 552
573 553
574 class InterfaceIDLTypeInfo(IDLTypeInfo): 554 class InterfaceIDLTypeInfo(IDLTypeInfo):
575 def __init__(self, idl_type, data): 555 def __init__(self, idl_type, data):
576 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) 556 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
(...skipping 11 matching lines...) Expand all
588 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value) 568 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value)
589 569
590 def conversion_includes(self): 570 def conversion_includes(self):
591 return self._item_info.conversion_includes() 571 return self._item_info.conversion_includes()
592 572
593 573
594 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): 574 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo):
595 def __init__(self, data, item_info): 575 def __init__(self, data, item_info):
596 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) 576 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info)
597 577
598 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa ce_name): 578 def to_native_info(self, idl_node, accept_null, name, interface_name):
599 assert not accept_null 579 assert not accept_null
600 emitter.Emit( 580 return name, 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative'
601 '\n'
602 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND LE, exception);\n'
603 ' if (exception)\n'
604 ' goto fail;\n',
605 NAME=name,
606 HANDLE=handle)
607 return name
608
609 def to_native_includes(self):
610 return ['"DartDOMStringList.h"']
611 581
612 582
613 class PrimitiveIDLTypeInfo(IDLTypeInfo): 583 class PrimitiveIDLTypeInfo(IDLTypeInfo):
614 def __init__(self, idl_type, data): 584 def __init__(self, idl_type, data):
615 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) 585 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data)
616 586
617 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa ce_name): 587 def to_native_info(self, idl_node, accept_null, name, interface_name):
618 function_name = 'dartTo%s' % self._capitalized_native_type() 588 function_name = 'dartTo%s' % self._capitalized_native_type()
619 if accept_null: 589 if accept_null:
620 function_name += 'WithNullCheck' 590 function_name += 'WithNullCheck'
621 type = self.native_type() 591 type = self.native_type()
622 if type == 'SerializedScriptValue': 592 if type == 'SerializedScriptValue':
623 type = 'RefPtr<%s>' % type 593 type = 'RefPtr<%s>' % type
624 if type == 'String': 594 if type == 'String':
625 type = 'DartStringAdapter' 595 type = 'DartStringAdapter'
626 emitter.Emit( 596 return name, type, 'DartUtilities', function_name
627 '\n'
628 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception) ;\n'
629 ' if (exception)\n'
630 ' goto fail;\n',
631 TYPE=type,
632 NAME=name,
633 FUNCTION_NAME=function_name,
634 HANDLE=handle)
635 return name
636 597
637 def parameter_type(self): 598 def parameter_type(self):
638 if self.native_type() == 'String': 599 if self.native_type() == 'String':
639 return 'const String&' 600 return 'const String&'
640 return self.native_type() 601 return self.native_type()
641 602
642 def conversion_includes(self): 603 def conversion_includes(self):
643 return [] 604 return []
644 605
645 def to_native_includes(sefl):
646 return []
647
648 def to_dart_conversion(self, value, interface_name=None, attributes=None): 606 def to_dart_conversion(self, value, interface_name=None, attributes=None):
649 function_name = self._capitalized_native_type() 607 function_name = self._capitalized_native_type()
650 function_name = function_name[0].lower() + function_name[1:] 608 function_name = function_name[0].lower() + function_name[1:]
651 function_name = 'DartUtilities::%sToDart' % function_name 609 function_name = 'DartUtilities::%sToDart' % function_name
652 if attributes and 'TreatReturnedNullStringAs' in attributes: 610 if attributes and 'TreatReturnedNullStringAs' in attributes:
653 function_name += 'WithNullCheck' 611 function_name += 'WithNullCheck'
654 return '%s(%s)' % (function_name, value) 612 return '%s(%s)' % (function_name, value)
655 613
656 def webcore_getter_name(self): 614 def webcore_getter_name(self):
657 return self._data.webcore_getter_name 615 return self._data.webcore_getter_name
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 if match: 792 if match:
835 if type_name == 'DOMString[]': 793 if type_name == 'DOMString[]':
836 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 794 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
837 item_info = self.TypeInfo(match.group(1) or match.group(2)) 795 item_info = self.TypeInfo(match.group(1) or match.group(2))
838 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 796 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
839 if not type_name in _idl_type_registry: 797 if not type_name in _idl_type_registry:
840 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 798 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
841 type_data = _idl_type_registry.get(type_name) 799 type_data = _idl_type_registry.get(type_name)
842 class_name = '%sIDLTypeInfo' % type_data.clazz 800 class_name = '%sIDLTypeInfo' % type_data.clazz
843 return globals()[class_name](type_name, type_data) 801 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698