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 |
11 from generator import * | 11 from generator import * |
12 from htmldartgenerator import * | 12 from htmldartgenerator import * |
13 from idlnode import IDLArgument, IDLAttribute, IDLEnum | 13 from idlnode import IDLArgument, IDLAttribute, IDLEnum, IDLMember |
14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES | 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES |
15 | 15 |
16 # This is an ugly hack to get things working on the M35 roll. Once we | 16 # This is an ugly hack to get things working on the M35 roll. Once we |
17 # generate dart:blink from the new scripts, this shouldn't be needed. | 17 # generate dart:blink from the new scripts, this shouldn't be needed. |
18 _cpp_resolver_string_map = { | 18 _cpp_resolver_string_map = { |
19 # These custom constructors all resolve to a common entry, so choosing any | 19 # These custom constructors all resolve to a common entry, so choosing any |
20 # of the generated strings works. | 20 # of the generated strings works. |
21 'ConsoleBase_assertCondition_Callback_boolean_object': | 21 'ConsoleBase_assertCondition_Callback_boolean_object': |
22 'ConsoleBase_assert_Callback_boolean_object', | 22 'ConsoleBase_assert_Callback_boolean_object', |
23 'FormData_constructorCallback': | 23 'FormData_constructorCallback': |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 PARAMETERS=', '.join(parameters)) | 512 PARAMETERS=', '.join(parameters)) |
513 continue | 513 continue |
514 | 514 |
515 cpp_header_handlers_emitter.Emit( | 515 cpp_header_handlers_emitter.Emit( |
516 '\n' | 516 '\n' |
517 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS);\n', | 517 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS);\n', |
518 RETURN_TYPE=return_type, | 518 RETURN_TYPE=return_type, |
519 FUNCTION=function_name, | 519 FUNCTION=function_name, |
520 PARAMETERS=', '.join(parameters)) | 520 PARAMETERS=', '.join(parameters)) |
521 | 521 |
522 if 'Custom' in operation.ext_attrs: | 522 if _IsCustom(operation): |
523 continue | 523 continue |
524 | 524 |
525 cpp_impl_includes |= set(conversion_includes) | 525 cpp_impl_includes |= set(conversion_includes) |
526 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg
uments) | 526 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg
uments) |
527 if not len(arguments): | 527 if not len(arguments): |
528 arguments_declaration = 'Dart_Handle* arguments = 0' | 528 arguments_declaration = 'Dart_Handle* arguments = 0' |
529 if (return_type == 'void'): | 529 if (return_type == 'void'): |
530 ret1 = 'return' | 530 ret1 = 'return' |
531 ret2 = '' | 531 ret2 = '' |
532 else: | 532 else: |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 982 |
983 def _AddGetter(self, attr, html_name, read_only): | 983 def _AddGetter(self, attr, html_name, read_only): |
984 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. | 984 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. |
985 # TODO(antonm): solve in principled way. | 985 # TODO(antonm): solve in principled way. |
986 if self._interface.id == 'ImageData' and html_name == 'data': | 986 if self._interface.id == 'ImageData' and html_name == 'data': |
987 html_name = '_data' | 987 html_name = '_data' |
988 type_info = self._TypeInfo(attr.type.id) | 988 type_info = self._TypeInfo(attr.type.id) |
989 return_type = self.SecureOutputType(attr.type.id, False, read_only) | 989 return_type = self.SecureOutputType(attr.type.id, False, read_only) |
990 parameters = [] | 990 parameters = [] |
991 dart_declaration = '%s get %s' % (return_type, html_name) | 991 dart_declaration = '%s get %s' % (return_type, html_name) |
992 is_custom = ('Custom' in attr.ext_attrs and | 992 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or |
993 (attr.ext_attrs['Custom'] == None or | 993 _IsCustomValue(attr, 'Getter')) |
994 attr.ext_attrs['Custom'] == 'Getter')) | |
995 # This seems to have been replaced with Custom=Getter (see above), but | 994 # This seems to have been replaced with Custom=Getter (see above), but |
996 # check to be sure we don't see the old syntax | 995 # check to be sure we don't see the old syntax |
997 assert(not ('CustomGetter' in attr.ext_attrs)) | 996 assert(not ('CustomGetter' in attr.ext_attrs)) |
998 native_suffix = 'Getter' | 997 native_suffix = 'Getter' |
999 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) | 998 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) |
1000 native_entry = \ | 999 native_entry = \ |
1001 self.DeriveNativeEntry(attr.id, native_suffix, [], True) | 1000 self.DeriveNativeEntry(attr.id, native_suffix, [], True) |
1002 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, | 1001 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, |
1003 dart_declaration, False, return_type, parameters, | 1002 dart_declaration, False, return_type, parameters, |
1004 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry) | 1003 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 attr.type.nullable, | 1036 attr.type.nullable, |
1038 raises, | 1037 raises, |
1039 auto_scope_setup) | 1038 auto_scope_setup) |
1040 | 1039 |
1041 def _AddSetter(self, attr, html_name): | 1040 def _AddSetter(self, attr, html_name): |
1042 type_info = self._TypeInfo(attr.type.id) | 1041 type_info = self._TypeInfo(attr.type.id) |
1043 return_type = 'void' | 1042 return_type = 'void' |
1044 parameters = ['value'] | 1043 parameters = ['value'] |
1045 ptype = self._DartType(attr.type.id) | 1044 ptype = self._DartType(attr.type.id) |
1046 dart_declaration = 'void set %s(%s value)' % (html_name, ptype) | 1045 dart_declaration = 'void set %s(%s value)' % (html_name, ptype) |
1047 is_custom = ('Custom' in attr.ext_attrs and | 1046 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or |
1048 (attr.ext_attrs['Custom'] == None or | 1047 _IsCustomValue(attr, 'Setter')) |
1049 attr.ext_attrs['Custom'] == 'Setter')) | |
1050 # This seems to have been replaced with Custom=Setter (see above), but | 1048 # This seems to have been replaced with Custom=Setter (see above), but |
1051 # check to be sure we don't see the old syntax | 1049 # check to be sure we don't see the old syntax |
1052 assert(not ('CustomSetter' in attr.ext_attrs)) | 1050 assert(not ('CustomSetter' in attr.ext_attrs)) |
1053 assert(not ('V8CustomSetter' in attr.ext_attrs)) | 1051 assert(not ('V8CustomSetter' in attr.ext_attrs)) |
1054 native_suffix = 'Setter' | 1052 native_suffix = 'Setter' |
1055 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) | 1053 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) |
1056 native_entry = \ | 1054 native_entry = \ |
1057 self.DeriveNativeEntry(attr.id, native_suffix, [attr.type.id], True) | 1055 self.DeriveNativeEntry(attr.id, native_suffix, [attr.type.id], True) |
1058 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 1056 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
1059 dart_declaration, False, return_type, parameters, | 1057 dart_declaration, False, return_type, parameters, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 # and | 1104 # and |
1107 # | 1105 # |
1108 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 1106 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
1109 # | 1107 # |
1110 dart_element_type = self._DartType(element_type) | 1108 dart_element_type = self._DartType(element_type) |
1111 if self._HasNativeIndexGetter(): | 1109 if self._HasNativeIndexGetter(): |
1112 self._EmitNativeIndexGetter(dart_element_type) | 1110 self._EmitNativeIndexGetter(dart_element_type) |
1113 elif self._HasExplicitIndexedGetter(): | 1111 elif self._HasExplicitIndexedGetter(): |
1114 self._EmitExplicitIndexedGetter(dart_element_type) | 1112 self._EmitExplicitIndexedGetter(dart_element_type) |
1115 else: | 1113 else: |
1116 is_custom = any((op.id == 'item' and 'Custom' in op.ext_attrs) for op in s
elf._interface.operations) | 1114 is_custom = any((op.id == 'item' and _IsCustom(op)) for op in self._interf
ace.operations) |
1117 # First emit a toplevel function to do the native call | 1115 # First emit a toplevel function to do the native call |
1118 # Calls to this are emitted elsewhere, | 1116 # Calls to this are emitted elsewhere, |
1119 dart_native_name, resolver_string = \ | 1117 dart_native_name, resolver_string = \ |
1120 self.DeriveNativeEntry("item", "Callback", ["unsigned long"], | 1118 self.DeriveNativeEntry("item", "Callback", ["unsigned long"], |
1121 is_custom) | 1119 is_custom) |
1122 if resolver_string in _cpp_resolver_string_map: | 1120 if resolver_string in _cpp_resolver_string_map: |
1123 resolver_string = \ | 1121 resolver_string = \ |
1124 _cpp_resolver_string_map[resolver_string] | 1122 _cpp_resolver_string_map[resolver_string] |
1125 | 1123 |
1126 # Emit the method which calls the toplevel function, along with | 1124 # Emit the method which calls the toplevel function, along with |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 return_type = self.SecureOutputType(info.type_name, False, True) | 1214 return_type = self.SecureOutputType(info.type_name, False, True) |
1217 formals = info.ParametersAsDeclaration(self._DartType) | 1215 formals = info.ParametersAsDeclaration(self._DartType) |
1218 parameters = info.ParametersAsListOfVariables() | 1216 parameters = info.ParametersAsListOfVariables() |
1219 dart_declaration = '%s%s %s(%s)' % ( | 1217 dart_declaration = '%s%s %s(%s)' % ( |
1220 'static ' if info.IsStatic() else '', | 1218 'static ' if info.IsStatic() else '', |
1221 return_type, | 1219 return_type, |
1222 html_name, | 1220 html_name, |
1223 formals) | 1221 formals) |
1224 | 1222 |
1225 operation = info.operations[0] | 1223 operation = info.operations[0] |
1226 is_custom = 'Custom' in operation.ext_attrs | 1224 is_custom = _IsCustom(operation) |
1227 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) | 1225 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) |
1228 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | 1226 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
1229 | 1227 |
1230 if info.callback_args: | 1228 if info.callback_args: |
1231 self._AddFutureifiedOperation(info, html_name) | 1229 self._AddFutureifiedOperation(info, html_name) |
1232 elif not needs_dispatcher: | 1230 elif not needs_dispatcher: |
1233 # Bind directly to native implementation | 1231 # Bind directly to native implementation |
1234 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 1232 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
1235 native_suffix = 'Callback' | 1233 native_suffix = 'Callback' |
1236 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) | 1234 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) |
(...skipping 15 matching lines...) Expand all Loading... |
1252 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): | 1250 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): |
1253 | 1251 |
1254 def GenerateCall( | 1252 def GenerateCall( |
1255 stmts_emitter, call_emitter, version, operation, argument_count): | 1253 stmts_emitter, call_emitter, version, operation, argument_count): |
1256 native_suffix = 'Callback' | 1254 native_suffix = 'Callback' |
1257 actuals = info.ParametersAsListOfVariables(argument_count) | 1255 actuals = info.ParametersAsListOfVariables(argument_count) |
1258 actuals_s = ", ".join(actuals) | 1256 actuals_s = ", ".join(actuals) |
1259 formals=actuals | 1257 formals=actuals |
1260 return_type = self.SecureOutputType(operation.type.id) | 1258 return_type = self.SecureOutputType(operation.type.id) |
1261 native_suffix = 'Callback' | 1259 native_suffix = 'Callback' |
1262 is_custom = 'Custom' in operation.ext_attrs | 1260 is_custom = _IsCustom(operation) |
1263 base_name = '_%s_%s' % (operation.id, version) | 1261 base_name = '_%s_%s' % (operation.id, version) |
1264 static = True | 1262 static = True |
1265 if not operation.is_static: | 1263 if not operation.is_static: |
1266 actuals = ['this'] + actuals | 1264 actuals = ['this'] + actuals |
1267 formals = ['mthis'] + formals | 1265 formals = ['mthis'] + formals |
1268 actuals_s = ", ".join(actuals) | 1266 actuals_s = ", ".join(actuals) |
1269 formals_s = ", ".join(formals) | 1267 formals_s = ", ".join(formals) |
1270 dart_declaration = '%s(%s)' % ( | 1268 dart_declaration = '%s(%s)' % ( |
1271 base_name, formals_s) | 1269 base_name, formals_s) |
1272 type_ids = [argument.type.id | 1270 type_ids = [argument.type.id |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 e.Emit("};\n"); | 1991 e.Emit("};\n"); |
1994 e.Emit('\n'); | 1992 e.Emit('\n'); |
1995 e.Emit('} // namespace WebCore\n'); | 1993 e.Emit('} // namespace WebCore\n'); |
1996 | 1994 |
1997 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1995 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
1998 return ( | 1996 return ( |
1999 interface.id.endswith('Event') and | 1997 interface.id.endswith('Event') and |
2000 operation.id.startswith('init') and | 1998 operation.id.startswith('init') and |
2001 argument.default_value == 'Undefined' and | 1999 argument.default_value == 'Undefined' and |
2002 argument.type.id == 'DOMString') | 2000 argument.type.id == 'DOMString') |
| 2001 |
| 2002 def _IsCustom(op_or_attr): |
| 2003 assert(isinstance(op_or_attr, IDLMember)) |
| 2004 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s |
| 2005 |
| 2006 def _IsCustomValue(op_or_attr, value): |
| 2007 if _IsCustom(op_or_attr): |
| 2008 return op_or_attr.ext_attrs.get('Custom') == value \ |
| 2009 or op_or_attr.ext_attrs.get('DartCustom') == value |
| 2010 return False |
OLD | NEW |