| 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 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 else: | 1117 else: |
| 1118 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) | 1118 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) |
| 1119 | 1119 |
| 1120 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): | 1120 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): |
| 1121 | 1121 |
| 1122 def GenerateCall( | 1122 def GenerateCall( |
| 1123 stmts_emitter, call_emitter, version, operation, argument_count): | 1123 stmts_emitter, call_emitter, version, operation, argument_count): |
| 1124 native_suffix = 'Callback' | 1124 native_suffix = 'Callback' |
| 1125 actuals = info.ParametersAsListOfVariables(argument_count) | 1125 actuals = info.ParametersAsListOfVariables(argument_count) |
| 1126 return_type = self.SecureOutputType(operation.type.id) | 1126 return_type = self.SecureOutputType(operation.type.id) |
| 1127 native_suffix = 'Callback' |
| 1127 if self._dart_use_blink: | 1128 if self._dart_use_blink: |
| 1128 base_name = '_%s_%s' % (operation.id, version) | 1129 base_name = '_%s_%s' % (operation.id, version) |
| 1130 cpp_base_name = '%s' % operation.id |
| 1129 overload_name = \ | 1131 overload_name = \ |
| 1130 DeriveNativeName(self._interface.id, base_name, native_suffix) | 1132 DeriveNativeName(self._interface.id, base_name, native_suffix) |
| 1131 static = True | 1133 static = True |
| 1132 if not operation.is_static: | 1134 if not operation.is_static: |
| 1133 actuals = ['mthis'] + actuals | 1135 actuals = ['mthis'] + actuals |
| 1134 actuals_s = ", ".join(actuals) | 1136 actuals_s = ", ".join(actuals) |
| 1135 dart_declaration = '%s(%s)' % ( | 1137 dart_declaration = '%s(%s)' % ( |
| 1136 base_name, actuals_s) | 1138 base_name, actuals_s) |
| 1139 type_string = \ |
| 1140 "_".join([argument.type.id |
| 1141 for argument in operation.arguments[:argument_count]]) |
| 1142 components = \ |
| 1143 [self._interface.id, cpp_base_name, native_suffix, |
| 1144 str(argument_count), type_string] |
| 1145 resolver_string = "_".join(components) |
| 1137 else: | 1146 else: |
| 1138 base_name = '_%s_%s' % (operation.id, version) | 1147 base_name = '_%s_%s' % (operation.id, version) |
| 1148 cpp_base_name = base_name |
| 1139 overload_name = base_name | 1149 overload_name = base_name |
| 1140 static = operation.is_static | 1150 static = operation.is_static |
| 1141 actuals_s = ", ".join(actuals) | 1151 actuals_s = ", ".join(actuals) |
| 1142 dart_declaration = '%s%s %s(%s)' % ( | 1152 dart_declaration = '%s%s %s(%s)' % ( |
| 1143 'static ' if static else '', | 1153 'static ' if static else '', |
| 1144 return_type, | 1154 return_type, |
| 1145 overload_name, actuals_s) | 1155 overload_name, actuals_s) |
| 1156 resolver_string = None |
| 1146 | 1157 |
| 1147 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) | 1158 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) |
| 1148 is_custom = 'Custom' in operation.ext_attrs | 1159 is_custom = 'Custom' in operation.ext_attrs |
| 1149 native_suffix = 'Callback' | |
| 1150 auto_scope_setup = \ | 1160 auto_scope_setup = \ |
| 1151 self._GenerateAutoSetupScope(base_name, native_suffix) | 1161 self._GenerateAutoSetupScope(base_name, native_suffix) |
| 1152 cpp_callback_name = self._GenerateNativeBinding( | 1162 cpp_callback_name = self._GenerateNativeBinding( |
| 1153 base_name, (0 if static else 1) + argument_count, | 1163 base_name, (0 if static else 1) + argument_count, |
| 1154 dart_declaration, static, return_type, actuals, | 1164 dart_declaration, static, return_type, actuals, |
| 1155 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, | 1165 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, |
| 1156 emit_to_native=self._dart_use_blink) | 1166 emit_to_native=self._dart_use_blink, resolver_string=resolver_string) |
| 1157 if not is_custom: | 1167 if not is_custom: |
| 1158 self._GenerateOperationNativeCallback(operation, | 1168 self._GenerateOperationNativeCallback(operation, |
| 1159 operation.arguments[:argument_count], cpp_callback_name, | 1169 operation.arguments[:argument_count], cpp_callback_name, |
| 1160 auto_scope_setup) | 1170 auto_scope_setup) |
| 1161 | 1171 |
| 1162 | 1172 |
| 1163 if self._dart_use_blink: | 1173 if self._dart_use_blink: |
| 1164 name = DeriveNativeName(self._interface.id, html_name, "") | 1174 name = DeriveNativeName(self._interface.id, html_name, "") |
| 1165 qual_name = DeriveQualifiedName(self._native_library_name, | 1175 qual_name = DeriveQualifiedName(self._native_library_name, |
| 1166 name) | 1176 name) |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 auto_scope_setup, | 1584 auto_scope_setup, |
| 1575 self._interface.id, | 1585 self._interface.id, |
| 1576 ext_attrs) | 1586 ext_attrs) |
| 1577 set_return_value = '%s' % (return_to_dart_conversion) | 1587 set_return_value = '%s' % (return_to_dart_conversion) |
| 1578 invocation_emitter.Emit( | 1588 invocation_emitter.Emit( |
| 1579 ' $RETURN_VALUE;\n', | 1589 ' $RETURN_VALUE;\n', |
| 1580 RETURN_VALUE=set_return_value) | 1590 RETURN_VALUE=set_return_value) |
| 1581 | 1591 |
| 1582 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, | 1592 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, |
| 1583 static, return_type, parameters, native_suffix, is_custom, | 1593 static, return_type, parameters, native_suffix, is_custom, |
| 1584 auto_scope_setup=True, emit_metadata=True, emit_to_native=False): | 1594 auto_scope_setup=True, emit_metadata=True, emit_to_native=False, |
| 1595 resolver_string=None): |
| 1585 metadata = [] | 1596 metadata = [] |
| 1586 if emit_metadata: | 1597 if emit_metadata: |
| 1587 metadata = self._metadata.GetFormattedMetadata( | 1598 metadata = self._metadata.GetFormattedMetadata( |
| 1588 self._renamer.GetLibraryName(self._interface), | 1599 self._renamer.GetLibraryName(self._interface), |
| 1589 self._interface, idl_name, ' ') | 1600 self._interface, idl_name, ' ') |
| 1590 dart_native_name = \ | 1601 dart_native_name = \ |
| 1591 DeriveNativeName(self._interface.id, idl_name, native_suffix) | 1602 DeriveNativeName(self._interface.id, idl_name, native_suffix) |
| 1592 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) | 1603 |
| 1604 if (resolver_string): |
| 1605 native_binding = resolver_string |
| 1606 else: |
| 1607 native_binding = \ |
| 1608 '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) |
| 1609 |
| 1593 if self._dart_use_blink: | 1610 if self._dart_use_blink: |
| 1594 if not static: | 1611 if not static: |
| 1595 formals = ", ".join(['mthis'] + parameters) | 1612 formals = ", ".join(['mthis'] + parameters) |
| 1596 actuals = ", ".join(['this'] + parameters) | 1613 actuals = ", ".join(['this'] + parameters) |
| 1597 else: | 1614 else: |
| 1598 formals = ", ".join(parameters) | 1615 formals = ", ".join(parameters) |
| 1599 actuals = ", ".join(parameters) | 1616 actuals = ", ".join(parameters) |
| 1600 | 1617 |
| 1601 self._native_library_emitter.Emit( | 1618 self._native_library_emitter.Emit( |
| 1602 '\n' | 1619 '\n' |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 e.Emit("};\n"); | 1901 e.Emit("};\n"); |
| 1885 e.Emit('\n'); | 1902 e.Emit('\n'); |
| 1886 e.Emit('} // namespace WebCore\n'); | 1903 e.Emit('} // namespace WebCore\n'); |
| 1887 | 1904 |
| 1888 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1905 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1889 return ( | 1906 return ( |
| 1890 interface.id.endswith('Event') and | 1907 interface.id.endswith('Event') and |
| 1891 operation.id.startswith('init') and | 1908 operation.id.startswith('init') and |
| 1892 argument.ext_attrs.get('Default') == 'Undefined' and | 1909 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1893 argument.type.id == 'DOMString') | 1910 argument.type.id == 'DOMString') |
| OLD | NEW |