Chromium Code Reviews| 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 import systembase | |
| 12 from generator import * | 11 from generator import * |
| 12 from systembase import BaseGenerator | |
| 13 | 13 |
| 14 | 14 |
| 15 class NativeImplementationSystem(systembase.System): | 15 class DartiumGeneratorBackend(BaseGenerator): |
|
Anton Muhin
2012/09/26 14:20:36
NativeGeneratorBackend or even NativeGenerator?
podivilov
2012/09/26 15:02:04
"native" is confusing. Renamed to DartiumBackend.
| |
| 16 """Generates Dart implementation for one DOM IDL interface.""" | |
| 16 | 17 |
| 17 def __init__(self, options, cpp_library_emitter): | 18 def __init__(self, interface, cpp_library_emitter, options): |
| 18 super(NativeImplementationSystem, self).__init__(options) | 19 super(DartiumGeneratorBackend, self).__init__( |
| 20 options.database, options.type_registry, interface) | |
| 19 self._cpp_library_emitter = cpp_library_emitter | 21 self._cpp_library_emitter = cpp_library_emitter |
| 22 self._template_loader = options.templates | |
| 23 self._html_interface_name = options.renamer.RenameInterface(self._interface) | |
| 20 | 24 |
| 21 def ImplementationGenerator(self, interface): | 25 def HasImplementation(self): |
| 22 return NativeImplementationGenerator(self, interface) | 26 return not IsPureInterface(self._interface.id) |
| 23 | 27 |
| 24 def ProcessCallback(self, interface, info): | 28 def ImplementationClassName(self): |
| 25 self._interface = interface | 29 return self._ImplClassName(self._interface.id) |
| 26 | 30 |
| 31 def SetImplementationEmitter(self, implementation_emitter): | |
| 32 self._dart_impl_emitter = implementation_emitter | |
| 33 | |
| 34 def ImplementsMergedMembers(self): | |
| 35 # We could not add merged functions to implementation class because | |
| 36 # underlying c++ object doesn't implement them. Merged functions are | |
| 37 # generated on merged interface implementation instead. | |
| 38 return False | |
| 39 | |
| 40 def GenerateCallback(self, info): | |
| 27 if IsPureInterface(self._interface.id): | 41 if IsPureInterface(self._interface.id): |
| 28 return None | 42 return |
| 29 | 43 |
| 30 cpp_impl_includes = set() | 44 cpp_impl_includes = set() |
| 31 cpp_header_handlers_emitter = emitter.Emitter() | 45 cpp_header_handlers_emitter = emitter.Emitter() |
| 32 cpp_impl_handlers_emitter = emitter.Emitter() | 46 cpp_impl_handlers_emitter = emitter.Emitter() |
| 33 class_name = 'Dart%s' % self._interface.id | 47 class_name = 'Dart%s' % self._interface.id |
| 34 for operation in interface.operations: | 48 for operation in self._interface.operations: |
| 35 parameters = [] | 49 parameters = [] |
| 36 arguments = [] | 50 arguments = [] |
| 37 conversion_includes = [] | 51 conversion_includes = [] |
| 38 for argument in operation.arguments: | 52 for argument in operation.arguments: |
| 39 argument_type_info = self._type_registry.TypeInfo(argument.type.id) | 53 argument_type_info = self._TypeInfo(argument.type.id) |
| 40 parameters.append('%s %s' % (argument_type_info.parameter_type(), | 54 parameters.append('%s %s' % (argument_type_info.parameter_type(), |
| 41 argument.id)) | 55 argument.id)) |
| 42 arguments.append(argument_type_info.to_dart_conversion(argument.id)) | 56 arguments.append(argument_type_info.to_dart_conversion(argument.id)) |
| 43 conversion_includes.extend(argument_type_info.conversion_includes()) | 57 conversion_includes.extend(argument_type_info.conversion_includes()) |
| 44 | 58 |
| 45 cpp_header_handlers_emitter.Emit( | 59 cpp_header_handlers_emitter.Emit( |
| 46 '\n' | 60 '\n' |
| 47 ' virtual bool handleEvent($PARAMETERS);\n', | 61 ' virtual bool handleEvent($PARAMETERS);\n', |
| 48 PARAMETERS=', '.join(parameters)) | 62 PARAMETERS=', '.join(parameters)) |
| 49 | 63 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 65 ' $ARGUMENTS_DECLARATION;\n' | 79 ' $ARGUMENTS_DECLARATION;\n' |
| 66 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' | 80 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' |
| 67 '}\n', | 81 '}\n', |
| 68 CLASS_NAME=class_name, | 82 CLASS_NAME=class_name, |
| 69 PARAMETERS=', '.join(parameters), | 83 PARAMETERS=', '.join(parameters), |
| 70 ARGUMENTS_DECLARATION=arguments_declaration, | 84 ARGUMENTS_DECLARATION=arguments_declaration, |
| 71 ARGUMENT_COUNT=len(arguments)) | 85 ARGUMENT_COUNT=len(arguments)) |
| 72 | 86 |
| 73 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(self._int erface.id, True) | 87 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(self._int erface.id, True) |
| 74 cpp_header_emitter.Emit( | 88 cpp_header_emitter.Emit( |
| 75 self._templates.Load('cpp_callback_header.template'), | 89 self._template_loader.Load('cpp_callback_header.template'), |
| 76 INTERFACE=self._interface.id, | 90 INTERFACE=self._interface.id, |
| 77 HANDLERS=cpp_header_handlers_emitter.Fragments()) | 91 HANDLERS=cpp_header_handlers_emitter.Fragments()) |
| 78 | 92 |
| 79 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter face.id) | 93 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter face.id) |
| 80 cpp_impl_emitter.Emit( | 94 cpp_impl_emitter.Emit( |
| 81 self._templates.Load('cpp_callback_implementation.template'), | 95 self._template_loader.Load('cpp_callback_implementation.template'), |
| 82 INCLUDES=_GenerateCPPIncludes(cpp_impl_includes), | 96 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes), |
| 83 INTERFACE=self._interface.id, | 97 INTERFACE=self._interface.id, |
| 84 HANDLERS=cpp_impl_handlers_emitter.Fragments()) | 98 HANDLERS=cpp_impl_handlers_emitter.Fragments()) |
| 85 | 99 |
| 86 | |
| 87 class NativeImplementationGenerator(systembase.BaseGenerator): | |
| 88 """Generates Dart implementation for one DOM IDL interface.""" | |
| 89 | |
| 90 def __init__(self, system, interface): | |
| 91 """Generates Dart and C++ code for the given interface. | |
| 92 | |
| 93 Args: | |
| 94 system: The NativeImplementationSystem. | |
| 95 interface: an IDLInterface instance. It is assumed that all types have | |
| 96 been converted to Dart types (e.g. int, String), unless they are in | |
| 97 the same package as the interface. | |
| 98 """ | |
| 99 super(NativeImplementationGenerator, self).__init__( | |
| 100 system._database, interface) | |
| 101 self._system = system | |
| 102 self._current_secondary_parent = None | |
| 103 self._html_interface_name = system._renamer.RenameInterface(self._interface) | |
| 104 | |
| 105 def HasImplementation(self): | |
| 106 return not IsPureInterface(self._interface.id) | |
| 107 | |
| 108 def ImplementationClassName(self): | |
| 109 return self._ImplClassName(self._interface.id) | |
| 110 | |
| 111 def SetImplementationEmitter(self, implementation_emitter): | |
| 112 self._dart_impl_emitter = implementation_emitter | |
| 113 | |
| 114 def ImplementsMergedMembers(self): | |
| 115 # We could not add merged functions to implementation class because | |
| 116 # underlying c++ object doesn't implement them. Merged functions are | |
| 117 # generated on merged interface implementation instead. | |
| 118 return False | |
| 119 | |
| 120 def StartInterface(self): | 100 def StartInterface(self): |
| 121 # Create emitters for c++ implementation. | 101 # Create emitters for c++ implementation. |
| 122 if self.HasImplementation(): | 102 if self.HasImplementation(): |
| 123 self._cpp_header_emitter = self._system._cpp_library_emitter.CreateHeaderE mitter(self._interface.id) | 103 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(s elf._interface.id) |
| 124 self._cpp_impl_emitter = self._system._cpp_library_emitter.CreateSourceEmi tter(self._interface.id) | 104 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel f._interface.id) |
| 125 else: | 105 else: |
| 126 self._cpp_header_emitter = emitter.Emitter() | 106 self._cpp_header_emitter = emitter.Emitter() |
| 127 self._cpp_impl_emitter = emitter.Emitter() | 107 self._cpp_impl_emitter = emitter.Emitter() |
| 128 | 108 |
| 129 self._interface_type_info = self._TypeInfo(self._interface.id) | 109 self._interface_type_info = self._TypeInfo(self._interface.id) |
| 130 self._members_emitter = emitter.Emitter() | 110 self._members_emitter = emitter.Emitter() |
| 131 self._cpp_declarations_emitter = emitter.Emitter() | 111 self._cpp_declarations_emitter = emitter.Emitter() |
| 132 self._cpp_impl_includes = set() | 112 self._cpp_impl_includes = set() |
| 133 self._cpp_definitions_emitter = emitter.Emitter() | 113 self._cpp_definitions_emitter = emitter.Emitter() |
| 134 self._cpp_resolver_emitter = emitter.Emitter() | 114 self._cpp_resolver_emitter = emitter.Emitter() |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return True | 200 return True |
| 221 | 201 |
| 222 # FIXME: support other types of ConstructorTemplate. | 202 # FIXME: support other types of ConstructorTemplate. |
| 223 if ext_attrs.get('ConstructorTemplate') == 'TypedArray': | 203 if ext_attrs.get('ConstructorTemplate') == 'TypedArray': |
| 224 return True | 204 return True |
| 225 | 205 |
| 226 return False | 206 return False |
| 227 | 207 |
| 228 def EmitFactoryProvider(self, constructor_info, factory_provider, emitter): | 208 def EmitFactoryProvider(self, constructor_info, factory_provider, emitter): |
| 229 template_file = 'factoryprovider_%s.darttemplate' % self._html_interface_nam e | 209 template_file = 'factoryprovider_%s.darttemplate' % self._html_interface_nam e |
| 230 template = self._system._templates.TryLoad(template_file) | 210 template = self._template_loader.TryLoad(template_file) |
| 231 if not template: | 211 if not template: |
| 232 template = self._system._templates.Load('factoryprovider.darttemplate') | 212 template = self._template_loader.Load('factoryprovider.darttemplate') |
| 233 | 213 |
| 234 native_binding = '%s_constructor_Callback' % self._interface.id | 214 native_binding = '%s_constructor_Callback' % self._interface.id |
| 235 emitter.Emit( | 215 emitter.Emit( |
| 236 template, | 216 template, |
| 237 FACTORYPROVIDER=factory_provider, | 217 FACTORYPROVIDER=factory_provider, |
| 238 INTERFACE=self._html_interface_name, | 218 INTERFACE=self._html_interface_name, |
| 239 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType), | 219 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType), |
| 240 ARGUMENTS=constructor_info.ParametersAsArgumentList(), | 220 ARGUMENTS=constructor_info.ParametersAsArgumentList(), |
| 241 NATIVE_NAME=native_binding) | 221 NATIVE_NAME=native_binding) |
| 242 | 222 |
| 243 def FinishInterface(self): | 223 def FinishInterface(self): |
| 244 template = None | 224 template = None |
| 245 if self._html_interface_name == self._interface.id or not self._database.Has Interface(self._html_interface_name): | 225 if self._html_interface_name == self._interface.id or not self._database.Has Interface(self._html_interface_name): |
| 246 template_file = 'impl_%s.darttemplate' % self._html_interface_name | 226 template_file = 'impl_%s.darttemplate' % self._html_interface_name |
| 247 template = self._system._templates.TryLoad(template_file) | 227 template = self._template_loader.TryLoad(template_file) |
| 248 if not template: | 228 if not template: |
| 249 template = self._system._templates.Load('dart_implementation.darttemplate' ) | 229 template = self._template_loader.Load('dart_implementation.darttemplate') |
| 250 | 230 |
| 251 class_name = self._ImplClassName(self._interface.id) | 231 class_name = self._ImplClassName(self._interface.id) |
| 252 members_emitter = self._dart_impl_emitter.Emit( | 232 members_emitter = self._dart_impl_emitter.Emit( |
| 253 template, | 233 template, |
| 254 CLASSNAME=class_name, | 234 CLASSNAME=class_name, |
| 255 EXTENDS=' extends ' + self._BaseClassName(), | 235 EXTENDS=' extends ' + self._BaseClassName(), |
| 256 IMPLEMENTS=' implements ' + self._html_interface_name, | 236 IMPLEMENTS=' implements ' + self._html_interface_name, |
| 257 NATIVESPEC='') | 237 NATIVESPEC='') |
| 258 members_emitter.Emit(''.join(self._members_emitter.Fragments())) | 238 members_emitter.Emit(''.join(self._members_emitter.Fragments())) |
| 259 | 239 |
| 260 self._GenerateCPPHeader() | 240 self._GenerateCPPHeader() |
| 261 | 241 |
| 262 self._cpp_impl_emitter.Emit( | 242 self._cpp_impl_emitter.Emit( |
| 263 self._system._templates.Load('cpp_implementation.template'), | 243 self._template_loader.Load('cpp_implementation.template'), |
| 264 INTERFACE=self._interface.id, | 244 INTERFACE=self._interface.id, |
| 265 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), | 245 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 266 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 246 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 267 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 247 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 268 DART_IMPLEMENTATION_CLASS=class_name) | 248 DART_IMPLEMENTATION_CLASS=class_name) |
| 269 | 249 |
| 270 def _GenerateCPPHeader(self): | 250 def _GenerateCPPHeader(self): |
| 271 to_native_emitter = emitter.Emitter() | 251 to_native_emitter = emitter.Emitter() |
| 272 if self._interface_type_info.custom_to_native(): | 252 if self._interface_type_info.custom_to_native(): |
| 273 to_native_emitter.Emit( | 253 to_native_emitter.Emit( |
| 274 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n') | 254 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n') |
| 275 else: | 255 else: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 292 to_dart_emitter.Emit( | 272 to_dart_emitter.Emit( |
| 293 ' static Dart_Handle toDart(NativeType* value);\n') | 273 ' static Dart_Handle toDart(NativeType* value);\n') |
| 294 else: | 274 else: |
| 295 to_dart_emitter.Emit( | 275 to_dart_emitter.Emit( |
| 296 ' static Dart_Handle toDart(NativeType* value)\n' | 276 ' static Dart_Handle toDart(NativeType* value)\n' |
| 297 ' {\n' | 277 ' {\n' |
| 298 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' | 278 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' |
| 299 ' }\n', | 279 ' }\n', |
| 300 INTERFACE=self._interface.id) | 280 INTERFACE=self._interface.id) |
| 301 | 281 |
| 302 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes()) | 282 webcore_includes = self._GenerateCPPIncludes( |
| 283 self._interface_type_info.webcore_includes()) | |
| 303 | 284 |
| 304 is_node_test = lambda interface: interface.id == 'Node' | 285 is_node_test = lambda interface: interface.id == 'Node' |
| 305 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs | 286 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs |
| 306 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s | 287 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s |
| 307 def TypeCheckHelper(test): | 288 def TypeCheckHelper(test): |
| 308 return 'true' if any(map(test, self._database.Hierarchy(self._interface))) else 'false' | 289 return 'true' if any(map(test, self._database.Hierarchy(self._interface))) else 'false' |
| 309 | 290 |
| 310 self._cpp_header_emitter.Emit( | 291 self._cpp_header_emitter.Emit( |
| 311 self._system._templates.Load('cpp_header.template'), | 292 self._template_loader.Load('cpp_header.template'), |
| 312 INTERFACE=self._interface.id, | 293 INTERFACE=self._interface.id, |
| 313 WEBCORE_INCLUDES=webcore_includes, | 294 WEBCORE_INCLUDES=webcore_includes, |
| 314 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 295 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 315 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), | 296 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), |
| 316 IS_NODE=TypeCheckHelper(is_node_test), | 297 IS_NODE=TypeCheckHelper(is_node_test), |
| 317 IS_ACTIVE=TypeCheckHelper(is_active_test), | 298 IS_ACTIVE=TypeCheckHelper(is_active_test), |
| 318 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), | 299 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), |
| 319 TO_NATIVE=to_native_emitter.Fragments(), | 300 TO_NATIVE=to_native_emitter.Fragments(), |
| 320 TO_DART=to_dart_emitter.Fragments()) | 301 TO_DART=to_dart_emitter.Fragments()) |
| 321 | 302 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 345 else: | 326 else: |
| 346 webcore_function_name = 'getURLAttribute' | 327 webcore_function_name = 'getURLAttribute' |
| 347 elif 'ImplementedAs' in attr.ext_attrs: | 328 elif 'ImplementedAs' in attr.ext_attrs: |
| 348 webcore_function_name = attr.ext_attrs['ImplementedAs'] | 329 webcore_function_name = attr.ext_attrs['ImplementedAs'] |
| 349 else: | 330 else: |
| 350 if attr.id == 'operator': | 331 if attr.id == 'operator': |
| 351 webcore_function_name = '_operator' | 332 webcore_function_name = '_operator' |
| 352 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': | 333 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': |
| 353 webcore_function_name = 'svgTarget' | 334 webcore_function_name = 'svgTarget' |
| 354 else: | 335 else: |
| 355 webcore_function_name = _ToWebKitName(attr.id) | 336 webcore_function_name = self._ToWebKitName(attr.id) |
| 356 if attr.type.id.startswith('SVGAnimated'): | 337 if attr.type.id.startswith('SVGAnimated'): |
| 357 webcore_function_name += 'Animated' | 338 webcore_function_name += 'Animated' |
| 358 | 339 |
| 359 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) | 340 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) |
| 360 self._GenerateNativeCallback( | 341 self._GenerateNativeCallback( |
| 361 cpp_callback_name, | 342 cpp_callback_name, |
| 362 True, | 343 True, |
| 363 function_expression, | 344 function_expression, |
| 364 attr, | 345 attr, |
| 365 [], | 346 [], |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 ' }\n', | 418 ' }\n', |
| 438 TYPE=dart_element_type) | 419 TYPE=dart_element_type) |
| 439 | 420 |
| 440 # The list interface for this class is manually generated. | 421 # The list interface for this class is manually generated. |
| 441 if self._interface.id == 'NodeList': | 422 if self._interface.id == 'NodeList': |
| 442 return | 423 return |
| 443 | 424 |
| 444 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 425 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 445 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 426 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| 446 template_file = 'immutable_list_mixin.darttemplate' | 427 template_file = 'immutable_list_mixin.darttemplate' |
| 447 template = self._system._templates.Load(template_file) | 428 template = self._template_loader.Load(template_file) |
| 448 self._members_emitter.Emit(template, E=dart_element_type) | 429 self._members_emitter.Emit(template, E=dart_element_type) |
| 449 | 430 |
| 450 def AmendIndexer(self, element_type): | 431 def AmendIndexer(self, element_type): |
| 451 # If interface is marked as having native indexed | 432 # If interface is marked as having native indexed |
| 452 # getter or setter, we must emit overrides as it's not | 433 # getter or setter, we must emit overrides as it's not |
| 453 # guaranteed that the corresponding methods in C++ would be | 434 # guaranteed that the corresponding methods in C++ would be |
| 454 # virtual. For example, as of time of writing, even though | 435 # virtual. For example, as of time of writing, even though |
| 455 # Uint8ClampedArray inherits from Uint8Array, ::set method | 436 # Uint8ClampedArray inherits from Uint8Array, ::set method |
| 456 # is not virtual and accessing it through Uint8Array pointer | 437 # is not virtual and accessing it through Uint8Array pointer |
| 457 # would lead to wrong semantics (modulo vs. clamping.) | 438 # would lead to wrong semantics (modulo vs. clamping.) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 FEATURE=v8EnabledPerContext) | 638 FEATURE=v8EnabledPerContext) |
| 658 | 639 |
| 659 if v8EnabledAtRuntime: | 640 if v8EnabledAtRuntime: |
| 660 raises_exceptions = True | 641 raises_exceptions = True |
| 661 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"') | 642 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"') |
| 662 runtime_check = emitter.Format( | 643 runtime_check = emitter.Format( |
| 663 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' | 644 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' |
| 664 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' | 645 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' |
| 665 ' goto fail;\n' | 646 ' goto fail;\n' |
| 666 ' }', | 647 ' }', |
| 667 FEATURE=_ToWebKitName(v8EnabledAtRuntime)) | 648 FEATURE=self._ToWebKitName(v8EnabledAtRuntime)) |
| 668 | 649 |
| 669 body_emitter = self._cpp_definitions_emitter.Emit( | 650 body_emitter = self._cpp_definitions_emitter.Emit( |
| 670 '\n' | 651 '\n' |
| 671 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' | 652 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' |
| 672 '{\n' | 653 '{\n' |
| 673 ' DartApiScope dartApiScope;\n' | 654 ' DartApiScope dartApiScope;\n' |
| 674 '$!BODY' | 655 '$!BODY' |
| 675 '}\n', | 656 '}\n', |
| 676 CALLBACK_NAME=callback_name) | 657 CALLBACK_NAME=callback_name) |
| 677 | 658 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() | 819 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() |
| 839 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) | 820 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) |
| 840 | 821 |
| 841 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): | 822 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): |
| 842 if 'ImplementedBy' in idl_node.ext_attrs: | 823 if 'ImplementedBy' in idl_node.ext_attrs: |
| 843 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) | 824 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) |
| 844 if idl_node.is_static: | 825 if idl_node.is_static: |
| 845 return '%s::%s' % (self._interface_type_info.idl_type(), function_name) | 826 return '%s::%s' % (self._interface_type_info.idl_type(), function_name) |
| 846 return '%s%s' % (self._interface_type_info.receiver(), function_name) | 827 return '%s%s' % (self._interface_type_info.receiver(), function_name) |
| 847 | 828 |
| 848 def _TypeInfo(self, type_name): | |
| 849 return self._system._type_registry.TypeInfo(type_name) | |
| 850 | |
| 851 def _IsArgumentOptionalInWebCore(self, operation, argument): | 829 def _IsArgumentOptionalInWebCore(self, operation, argument): |
| 852 if not IsOptional(argument): | 830 if not IsOptional(argument): |
| 853 return False | 831 return False |
| 854 if 'Callback' in argument.ext_attrs: | 832 if 'Callback' in argument.ext_attrs: |
| 855 return False | 833 return False |
| 856 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture': | 834 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture': |
| 857 return False | 835 return False |
| 858 # Another option would be to adjust in IDLs, but let's keep it here for now | 836 # Another option would be to adjust in IDLs, but let's keep it here for now |
| 859 # as it's a single instance. | 837 # as it's a single instance. |
| 860 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty' and argument.id == 'priority': | 838 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty' and argument.id == 'priority': |
| 861 return False | 839 return False |
| 862 return True | 840 return True |
| 863 | 841 |
| 842 def _GenerateCPPIncludes(self, includes): | |
|
Anton Muhin
2012/09/26 14:20:36
why it is method now, not a free function?
podivilov
2012/09/26 15:02:04
It's only used in DartiumBackend class.
Anton Muhin
2012/09/26 15:17:25
Up to you. I'd vote for keeping it free function
| |
| 843 return ''.join(['#include %s\n' % include for include in sorted(includes)]) | |
| 844 | |
| 845 def _ToWebKitName(self, name): | |
|
Anton Muhin
2012/09/26 14:20:36
ditto
| |
| 846 name = name[0].lower() + name[1:] | |
| 847 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | |
| 848 name) | |
| 849 return re.sub(r'^(create|exclusive)', | |
| 850 lambda s: 'is' + s.group(1).capitalize(), | |
| 851 name) | |
| 852 | |
| 864 | 853 |
| 865 class CPPLibraryEmitter(): | 854 class CPPLibraryEmitter(): |
| 866 def __init__(self, emitters, cpp_sources_dir): | 855 def __init__(self, emitters, cpp_sources_dir): |
| 867 self._emitters = emitters | 856 self._emitters = emitters |
| 868 self._cpp_sources_dir = cpp_sources_dir | 857 self._cpp_sources_dir = cpp_sources_dir |
| 869 self._headers_list = [] | 858 self._headers_list = [] |
| 870 self._sources_list = [] | 859 self._sources_list = [] |
| 871 | 860 |
| 872 def CreateHeaderEmitter(self, interface_name, is_callback=False): | 861 def CreateHeaderEmitter(self, interface_name, is_callback=False): |
| 873 path = os.path.join(self._cpp_sources_dir, 'Dart%s.h' % interface_name) | 862 path = os.path.join(self._cpp_sources_dir, 'Dart%s.h' % interface_name) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 893 def EmitResolver(self, template, output_dir): | 882 def EmitResolver(self, template, output_dir): |
| 894 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 883 file_path = os.path.join(output_dir, 'DartResolver.cpp') |
| 895 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) | 884 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) |
| 896 for header_file in self._headers_list: | 885 for header_file in self._headers_list: |
| 897 path = os.path.relpath(header_file, output_dir) | 886 path = os.path.relpath(header_file, output_dir) |
| 898 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 887 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 899 body_emitter.Emit( | 888 body_emitter.Emit( |
| 900 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' | 889 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' |
| 901 ' return func;\n', | 890 ' return func;\n', |
| 902 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 891 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 903 | |
| 904 | |
| 905 def _GenerateCPPIncludes(includes): | |
| 906 return ''.join(['#include %s\n' % include for include in sorted(includes)]) | |
| 907 | |
| 908 def _FindInHierarchy(database, interface, test): | |
| 909 if test(interface): | |
| 910 return interface | |
| 911 for parent in interface.parents: | |
| 912 parent_name = parent.type.id | |
| 913 if not database.HasInterface(parent.type.id): | |
| 914 continue | |
| 915 parent_interface = database.GetInterface(parent.type.id) | |
| 916 parent_interface = _FindInHierarchy(database, parent_interface, test) | |
| 917 if parent_interface: | |
| 918 return parent_interface | |
| 919 | |
| 920 def _ToWebKitName(name): | |
| 921 name = name[0].lower() + name[1:] | |
| 922 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | |
| 923 name) | |
| 924 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , | |
| 925 name) | |
| OLD | NEW |