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

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 259773004: Generate dart:blink in the SDK (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding dart:blink to SDK Created 6 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 | « tools/dom/scripts/go.sh ('k') | tools/dom/templates/html/dartium/chrome_dartium.darttemplate » ('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 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 # track the necessary info. 164 # track the necessary info.
165 _url_utils = ['hash', 'host', 'hostname', 'origin', 165 _url_utils = ['hash', 'host', 'hostname', 'origin',
166 'password', 'pathname', 'port', 'protocol', 166 'password', 'pathname', 'port', 'protocol',
167 'search', 'username'] 167 'search', 'username']
168 _cpp_static_call_map = { 168 _cpp_static_call_map = {
169 'DOMURL': _url_utils + ['href', 'toString'], 169 'DOMURL': _url_utils + ['href', 'toString'],
170 'HTMLAnchorElement': _url_utils, 170 'HTMLAnchorElement': _url_utils,
171 'HTMLAreaElement': _url_utils, 171 'HTMLAreaElement': _url_utils,
172 } 172 }
173 173
174 # This goes away after the Chrome 35 roll (or whenever we commit to the
175 # dart:blink refactor)
176 dart_use_blink = False
177
178 def _GetCPPPartialNames(interface): 174 def _GetCPPPartialNames(interface):
179 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) 175 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id)
180 if not _cpp_partial_map: 176 if not _cpp_partial_map:
181 for (type, member) in _cpp_callback_map.keys(): 177 for (type, member) in _cpp_callback_map.keys():
182 if type not in _cpp_partial_map: 178 if type not in _cpp_partial_map:
183 _cpp_partial_map[type] = set([]) 179 _cpp_partial_map[type] = set([])
184 180
185 name_with_path = _cpp_callback_map[(type, member)] 181 name_with_path = _cpp_callback_map[(type, member)]
186 if name_with_path in _cpp_import_map: 182 if name_with_path in _cpp_import_map:
187 name_with_path = _cpp_import_map[name_with_path] 183 name_with_path = _cpp_import_map[name_with_path]
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 auxiliary_dir = os.path.relpath(auxiliary_dir, dartium_output_dir) 237 auxiliary_dir = os.path.relpath(auxiliary_dir, dartium_output_dir)
242 emitter = \ 238 emitter = \
243 library_emitter.Emit(template, 239 library_emitter.Emit(template,
244 AUXILIARY_DIR=massage_path(auxiliary_dir)) 240 AUXILIARY_DIR=massage_path(auxiliary_dir))
245 return emitter 241 return emitter
246 242
247 class DartiumBackend(HtmlDartGenerator): 243 class DartiumBackend(HtmlDartGenerator):
248 """Generates Dart implementation for one DOM IDL interface.""" 244 """Generates Dart implementation for one DOM IDL interface."""
249 245
250 def __init__(self, interface, native_library_emitter, 246 def __init__(self, interface, native_library_emitter,
251 cpp_library_emitter, options): 247 cpp_library_emitter, options, dart_use_blink):
252 super(DartiumBackend, self).__init__(interface, options) 248 super(DartiumBackend, self).__init__(interface, options)
253 249
254 self._interface = interface 250 self._interface = interface
255 self._cpp_library_emitter = cpp_library_emitter 251 self._cpp_library_emitter = cpp_library_emitter
256 self._native_library_emitter = native_library_emitter 252 self._native_library_emitter = native_library_emitter
257 self._database = options.database 253 self._database = options.database
258 self._template_loader = options.templates 254 self._template_loader = options.templates
259 self._type_registry = options.type_registry 255 self._type_registry = options.type_registry
260 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) 256 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id)
261 self._metadata = options.metadata 257 self._metadata = options.metadata
262 self._native_library_name = "blink" 258 self._native_library_name = "blink"
259 # This goes away after the Chrome 35 roll (or whenever we commit to the
260 # dart:blink refactor)
261 self._dart_use_blink = dart_use_blink
263 # These get initialized by StartInterface 262 # These get initialized by StartInterface
264 self._cpp_header_emitter = None 263 self._cpp_header_emitter = None
265 self._cpp_impl_emitter = None 264 self._cpp_impl_emitter = None
266 self._members_emitter = None 265 self._members_emitter = None
267 self._cpp_declarations_emitter = None 266 self._cpp_declarations_emitter = None
268 self._cpp_impl_includes = None 267 self._cpp_impl_includes = None
269 self._cpp_definitions_emitter = None 268 self._cpp_definitions_emitter = None
270 self._cpp_resolver_emitter = None 269 self._cpp_resolver_emitter = None
271 270
272 def ImplementsMergedMembers(self): 271 def ImplementsMergedMembers(self):
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 constructor_info, constructor_callback_cpp_name, factory_method_name, 464 constructor_info, constructor_callback_cpp_name, factory_method_name,
466 argument_count=None): 465 argument_count=None):
467 constructor_callback_id = self._interface.id + '_' + constructor_callback_cp p_name 466 constructor_callback_id = self._interface.id + '_' + constructor_callback_cp p_name
468 if argument_count is None: 467 if argument_count is None:
469 argument_count = len(constructor_info.param_infos) 468 argument_count = len(constructor_info.param_infos)
470 469
471 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) 470 typed_formals = constructor_info.ParametersAsArgumentList(argument_count)
472 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) 471 parameters = constructor_info.ParametersAsStringOfVariables(argument_count)
473 interface_name = self._interface_type_info.interface_name() 472 interface_name = self._interface_type_info.interface_name()
474 473
475 if dart_use_blink: 474 if self._dart_use_blink:
476 # First we emit the toplevel function 475 # First we emit the toplevel function
477 dart_native_name = \ 476 dart_native_name = \
478 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "") 477 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "")
479 self._native_library_emitter.Emit( 478 self._native_library_emitter.Emit(
480 '\n' 479 '\n'
481 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', 480 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n',
482 FACTORY_METHOD_NAME=dart_native_name, 481 FACTORY_METHOD_NAME=dart_native_name,
483 PARAMETERS=parameters, 482 PARAMETERS=parameters,
484 ID=constructor_callback_id) 483 ID=constructor_callback_id)
485 484
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 # and 877 # and
879 # 878 #
880 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 879 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
881 # 880 #
882 dart_element_type = self._DartType(element_type) 881 dart_element_type = self._DartType(element_type)
883 if self._HasNativeIndexGetter(): 882 if self._HasNativeIndexGetter():
884 self._EmitNativeIndexGetter(dart_element_type) 883 self._EmitNativeIndexGetter(dart_element_type)
885 elif self._HasExplicitIndexedGetter(): 884 elif self._HasExplicitIndexedGetter():
886 self._EmitExplicitIndexedGetter(dart_element_type) 885 self._EmitExplicitIndexedGetter(dart_element_type)
887 else: 886 else:
888 if dart_use_blink: 887 if self._dart_use_blink:
889 dart_native_name = \ 888 dart_native_name = \
890 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") 889 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter")
891 # First emit a toplevel function to do the native call 890 # First emit a toplevel function to do the native call
892 # Calls to this are emitted elsewhere, 891 # Calls to this are emitted elsewhere,
893 self._native_library_emitter.Emit( 892 self._native_library_emitter.Emit(
894 '\n' 893 '\n'
895 '$(DART_NATIVE_NAME)(mthis, index) ' 894 '$(DART_NATIVE_NAME)(mthis, index) '
896 'native "$(INTERFACE)_item_Callback";\n', 895 'native "$(INTERFACE)_item_Callback";\n',
897 DART_NATIVE_NAME = dart_native_name, 896 DART_NATIVE_NAME = dart_native_name,
898 INTERFACE=self._interface.id) 897 INTERFACE=self._interface.id)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 1242
1244 body_emitter.Emit( 1243 body_emitter.Emit(
1245 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol ate();\n' 1244 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol ate();\n'
1246 ' if (!domWindow) {\n' 1245 ' if (!domWindow) {\n'
1247 ' exception = Dart_NewStringFromCString("Failed to fetch do mWindow");\n' 1246 ' exception = Dart_NewStringFromCString("Failed to fetch do mWindow");\n'
1248 ' goto fail;\n' 1247 ' goto fail;\n'
1249 ' }\n' 1248 ' }\n'
1250 ' Document& document = *domWindow->document();\n') 1249 ' Document& document = *domWindow->document();\n')
1251 1250
1252 if needs_receiver: 1251 if needs_receiver:
1253 if dart_use_blink: 1252 if self._dart_use_blink:
1254 body_emitter.Emit( 1253 body_emitter.Emit(
1255 ' $WEBCORE_CLASS_NAME* receiver = ' 1254 ' $WEBCORE_CLASS_NAME* receiver = '
1256 'DartDOMWrapper::receiverChecked<Dart$INTERFACE>(args, exception);\n ' 1255 'DartDOMWrapper::receiverChecked<Dart$INTERFACE>(args, exception);\n '
1257 ' if (exception)\n' 1256 ' if (exception)\n'
1258 ' goto fail;\n', 1257 ' goto fail;\n',
1259 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 1258 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
1260 INTERFACE=self._interface.id) 1259 INTERFACE=self._interface.id)
1261 else: 1260 else:
1262 body_emitter.Emit( 1261 body_emitter.Emit(
1263 ' $WEBCORE_CLASS_NAME* receiver = ' 1262 ' $WEBCORE_CLASS_NAME* receiver = '
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 static, return_type, parameters, native_suffix, is_custom, 1455 static, return_type, parameters, native_suffix, is_custom,
1457 auto_scope_setup=True, emit_metadata=True): 1456 auto_scope_setup=True, emit_metadata=True):
1458 metadata = [] 1457 metadata = []
1459 if emit_metadata: 1458 if emit_metadata:
1460 metadata = self._metadata.GetFormattedMetadata( 1459 metadata = self._metadata.GetFormattedMetadata(
1461 self._renamer.GetLibraryName(self._interface), 1460 self._renamer.GetLibraryName(self._interface),
1462 self._interface, idl_name, ' ') 1461 self._interface, idl_name, ' ')
1463 dart_native_name = \ 1462 dart_native_name = \
1464 DeriveNativeName(self._interface.id, idl_name, native_suffix) 1463 DeriveNativeName(self._interface.id, idl_name, native_suffix)
1465 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 1464 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
1466 if dart_use_blink: 1465 if self._dart_use_blink:
1467 if not static: 1466 if not static:
1468 formals = ", ".join(['mthis'] + parameters) 1467 formals = ", ".join(['mthis'] + parameters)
1469 actuals = ", ".join(['this'] + parameters) 1468 actuals = ", ".join(['this'] + parameters)
1470 else: 1469 else:
1471 formals = ", ".join(parameters) 1470 formals = ", ".join(parameters)
1472 actuals = ", ".join(parameters) 1471 actuals = ", ".join(parameters)
1473 1472
1474 self._native_library_emitter.Emit( 1473 self._native_library_emitter.Emit(
1475 '\n' 1474 '\n'
1476 '$DART_NAME($FORMALS) native "$NATIVE_BINDING";\n', 1475 '$DART_NAME($FORMALS) native "$NATIVE_BINDING";\n',
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 e.Emit("};\n"); 1756 e.Emit("};\n");
1758 e.Emit('\n'); 1757 e.Emit('\n');
1759 e.Emit('} // namespace WebCore\n'); 1758 e.Emit('} // namespace WebCore\n');
1760 1759
1761 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1760 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1762 return ( 1761 return (
1763 interface.id.endswith('Event') and 1762 interface.id.endswith('Event') and
1764 operation.id.startswith('init') and 1763 operation.id.startswith('init') and
1765 argument.ext_attrs.get('Default') == 'Undefined' and 1764 argument.ext_attrs.get('Default') == 'Undefined' and
1766 argument.type.id == 'DOMString') 1765 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/go.sh ('k') | tools/dom/templates/html/dartium/chrome_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698