| OLD | NEW |
| 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 the systems to generate | 6 """This module provides shared functionality for the systems to generate |
| 7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 arr_match = array_type(t) | 357 arr_match = array_type(t) |
| 358 if arr_match is not None: | 358 if arr_match is not None: |
| 359 t = EncodeType(arr_match) | 359 t = EncodeType(arr_match) |
| 360 return "A_%s_A" % t | 360 return "A_%s_A" % t |
| 361 | 361 |
| 362 return _type_encoding_map.get(t) or t | 362 return _type_encoding_map.get(t) or t |
| 363 | 363 |
| 364 class DartiumBackend(HtmlDartGenerator): | 364 class DartiumBackend(HtmlDartGenerator): |
| 365 """Generates Dart implementation for one DOM IDL interface.""" | 365 """Generates Dart implementation for one DOM IDL interface.""" |
| 366 | 366 |
| 367 def __init__(self, interface, | 367 def __init__(self, interface, |
| 368 cpp_library_emitter, options): | 368 cpp_library_emitter, options): |
| 369 super(DartiumBackend, self).__init__(interface, options, True) | 369 super(DartiumBackend, self).__init__(interface, options, True) |
| 370 | 370 |
| 371 self._interface = interface | 371 self._interface = interface |
| 372 self._cpp_library_emitter = cpp_library_emitter | 372 self._cpp_library_emitter = cpp_library_emitter |
| 373 self._database = options.database | 373 self._database = options.database |
| 374 self._template_loader = options.templates | 374 self._template_loader = options.templates |
| 375 self._type_registry = options.type_registry | 375 self._type_registry = options.type_registry |
| 376 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 376 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 377 self._metadata = options.metadata | 377 self._metadata = options.metadata |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 self._members_emitter.Emit( | 665 self._members_emitter.Emit( |
| 666 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n
', | 666 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n
', |
| 667 ANNOTATIONS=annotations, | 667 ANNOTATIONS=annotations, |
| 668 CTOR=constructor_info._ConstructorFullName(self._DartType), | 668 CTOR=constructor_info._ConstructorFullName(self._DartType), |
| 669 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), | 669 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), |
| 670 FACTORY_PARAMS= \ | 670 FACTORY_PARAMS= \ |
| 671 constructor_info.ParametersAsArgumentList()) | 671 constructor_info.ParametersAsArgumentList()) |
| 672 | 672 |
| 673 constructor_callback_cpp_name = 'constructorCallback' | 673 constructor_callback_cpp_name = 'constructorCallback' |
| 674 self._EmitConstructorInfrastructure( | 674 self._EmitConstructorInfrastructure( |
| 675 constructor_info, "", constructor_callback_cpp_name, '_create', | 675 constructor_info, "", constructor_callback_cpp_name, '_create', |
| 676 is_custom=True) | 676 is_custom=True) |
| 677 | 677 |
| 678 self._cpp_declarations_emitter.Emit( | 678 self._cpp_declarations_emitter.Emit( |
| 679 '\n' | 679 '\n' |
| 680 'void $CPP_CALLBACK(Dart_NativeArguments);\n', | 680 'void $CPP_CALLBACK(Dart_NativeArguments);\n', |
| 681 CPP_CALLBACK=constructor_callback_cpp_name) | 681 CPP_CALLBACK=constructor_callback_cpp_name) |
| 682 | 682 |
| 683 return True | 683 return True |
| 684 | 684 |
| 685 def IsConstructorArgumentOptional(self, argument): | 685 def IsConstructorArgumentOptional(self, argument): |
| 686 return IsOptional(argument) | 686 return IsOptional(argument) |
| 687 | 687 |
| 688 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): | 688 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
| 689 constructor_callback_cpp_name = name + 'constructorCallback' | 689 constructor_callback_cpp_name = name + 'constructorCallback' |
| 690 self._EmitConstructorInfrastructure( | 690 self._EmitConstructorInfrastructure( |
| 691 constructor_info, name, 'constructorCallback', name, arguments, | 691 constructor_info, name, 'constructorCallback', name, arguments, |
| 692 emit_to_native=True, | 692 emit_to_native=True, |
| 693 is_custom=False) | 693 is_custom=False) |
| 694 | 694 |
| 695 ext_attrs = self._interface.ext_attrs | 695 ext_attrs = self._interface.ext_attrs |
| 696 | 696 |
| 697 create_function = 'create' | 697 create_function = 'create' |
| 698 if 'NamedConstructor' in ext_attrs: | 698 if 'NamedConstructor' in ext_attrs: |
| 699 create_function = 'createForJSConstructor' | 699 create_function = 'createForJSConstructor' |
| 700 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 700 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 701 self._GenerateNativeCallback( | 701 self._GenerateNativeCallback( |
| 702 constructor_callback_cpp_name, | 702 constructor_callback_cpp_name, |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1041 |
| 1042 # Emit the method which calls the toplevel function, along with | 1042 # Emit the method which calls the toplevel function, along with |
| 1043 # the [] operator. | 1043 # the [] operator. |
| 1044 dart_qualified_name = \ | 1044 dart_qualified_name = \ |
| 1045 self.DeriveQualifiedBlinkName(self._interface.id, | 1045 self.DeriveQualifiedBlinkName(self._interface.id, |
| 1046 dart_native_name) | 1046 dart_native_name) |
| 1047 self._members_emitter.Emit( | 1047 self._members_emitter.Emit( |
| 1048 '\n' | 1048 '\n' |
| 1049 ' $TYPE operator[](int index) {\n' | 1049 ' $TYPE operator[](int index) {\n' |
| 1050 ' if (index < 0 || index >= length)\n' | 1050 ' if (index < 0 || index >= length)\n' |
| 1051 ' throw new RangeError.range(index, 0, length);\n' | 1051 ' throw new RangeError.index(index, this);\n' |
| 1052 ' return $(DART_NATIVE_NAME)(this, index);\n' | 1052 ' return $(DART_NATIVE_NAME)(this, index);\n' |
| 1053 ' }\n\n' | 1053 ' }\n\n' |
| 1054 ' $TYPE _nativeIndexedGetter(int index) =>' | 1054 ' $TYPE _nativeIndexedGetter(int index) =>' |
| 1055 ' $(DART_NATIVE_NAME)(this, index);\n', | 1055 ' $(DART_NATIVE_NAME)(this, index);\n', |
| 1056 DART_NATIVE_NAME=dart_qualified_name, | 1056 DART_NATIVE_NAME=dart_qualified_name, |
| 1057 TYPE=self.SecureOutputType(element_type), | 1057 TYPE=self.SecureOutputType(element_type), |
| 1058 INTERFACE=self._interface.id) | 1058 INTERFACE=self._interface.id) |
| 1059 | 1059 |
| 1060 if self._HasNativeIndexSetter(): | 1060 if self._HasNativeIndexSetter(): |
| 1061 self._EmitNativeIndexSetter(dart_element_type) | 1061 self._EmitNativeIndexSetter(dart_element_type) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 return any(op.id == 'getItem' for op in self._interface.operations) | 1099 return any(op.id == 'getItem' for op in self._interface.operations) |
| 1100 | 1100 |
| 1101 def _EmitExplicitIndexedGetter(self, dart_element_type): | 1101 def _EmitExplicitIndexedGetter(self, dart_element_type): |
| 1102 if any(op.id == 'getItem' for op in self._interface.operations): | 1102 if any(op.id == 'getItem' for op in self._interface.operations): |
| 1103 indexed_getter = 'getItem' | 1103 indexed_getter = 'getItem' |
| 1104 | 1104 |
| 1105 self._members_emitter.Emit( | 1105 self._members_emitter.Emit( |
| 1106 '\n' | 1106 '\n' |
| 1107 ' $TYPE operator[](int index) {\n' | 1107 ' $TYPE operator[](int index) {\n' |
| 1108 ' if (index < 0 || index >= length)\n' | 1108 ' if (index < 0 || index >= length)\n' |
| 1109 ' throw new RangeError.range(index, 0, length);\n' | 1109 ' throw new RangeError.index(index, this);\n' |
| 1110 ' return $INDEXED_GETTER(index);\n' | 1110 ' return $INDEXED_GETTER(index);\n' |
| 1111 ' }\n', | 1111 ' }\n', |
| 1112 TYPE=dart_element_type, | 1112 TYPE=dart_element_type, |
| 1113 INDEXED_GETTER=indexed_getter) | 1113 INDEXED_GETTER=indexed_getter) |
| 1114 | 1114 |
| 1115 def _HasNativeIndexSetter(self): | 1115 def _HasNativeIndexSetter(self): |
| 1116 return 'CustomIndexedSetter' in self._interface.ext_attrs | 1116 return 'CustomIndexedSetter' in self._interface.ext_attrs |
| 1117 | 1117 |
| 1118 def _EmitNativeIndexSetter(self, element_type): | 1118 def _EmitNativeIndexSetter(self, element_type): |
| 1119 return_type = 'void' | 1119 return_type = 'void' |
| 1120 formals = ', '.join(['int index', '%s value' % element_type]) | 1120 formals = ', '.join(['int index', '%s value' % element_type]) |
| 1121 parameters = ['index', 'value'] | 1121 parameters = ['index', 'value'] |
| 1122 dart_declaration = 'void operator[]=(%s)' % formals | 1122 dart_declaration = 'void operator[]=(%s)' % formals |
| 1123 self._GenerateNativeBinding('numericIndexSetter', 3, | 1123 self._GenerateNativeBinding('numericIndexSetter', 3, |
| 1124 dart_declaration, False, return_type, parameters, | 1124 dart_declaration, False, return_type, parameters, |
| 1125 'Callback', True, False) | 1125 'Callback', True, False) |
| 1126 | 1126 |
| 1127 def EmitOperation(self, info, html_name): | 1127 def EmitOperation(self, info, html_name): |
| 1128 """ | 1128 """ |
| 1129 Arguments: | 1129 Arguments: |
| 1130 info: An OperationInfo object. | 1130 info: An OperationInfo object. |
| 1131 """ | 1131 """ |
| 1132 return_type = self.SecureOutputType(info.type_name, False, True) | 1132 return_type = self.SecureOutputType(info.type_name, False, True) |
| 1133 formals = info.ParametersAsDeclaration(self._DartType) | 1133 formals = info.ParametersAsDeclaration(self._DartType) |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 | 1907 |
| 1908 def _IsCustom(op_or_attr): | 1908 def _IsCustom(op_or_attr): |
| 1909 assert(isinstance(op_or_attr, IDLMember)) | 1909 assert(isinstance(op_or_attr, IDLMember)) |
| 1910 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s | 1910 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s |
| 1911 | 1911 |
| 1912 def _IsCustomValue(op_or_attr, value): | 1912 def _IsCustomValue(op_or_attr, value): |
| 1913 if _IsCustom(op_or_attr): | 1913 if _IsCustom(op_or_attr): |
| 1914 return op_or_attr.ext_attrs.get('Custom') == value \ | 1914 return op_or_attr.ext_attrs.get('Custom') == value \ |
| 1915 or op_or_attr.ext_attrs.get('DartCustom') == value | 1915 or op_or_attr.ext_attrs.get('DartCustom') == value |
| 1916 return False | 1916 return False |
| OLD | NEW |