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 | 11 import systembase |
| 12 from generator import * | 12 from generator import * |
| 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared | 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared |
| 14 from systemhtml import HtmlElementConstructorInfos | 14 from systemhtml import HtmlElementConstructorInfos |
| 15 from systemhtml import EmitHtmlElementFactoryConstructors | 15 from systemhtml import EmitHtmlElementFactoryConstructors |
| 16 | 16 |
| 17 def toWebKitName(name): | |
|
podivilov
2012/06/26 12:33:01
please move this helper to the end of the file and
Anton Muhin
2012/06/26 12:37:25
Done.
| |
| 18 name = name[0].lower() + name[1:] | |
| 19 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | |
| 20 name) | |
| 21 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , | |
| 22 name) | |
| 23 | |
| 17 class NativeImplementationSystem(systembase.System): | 24 class NativeImplementationSystem(systembase.System): |
| 18 | 25 |
| 19 def __init__(self, templates, database, emitters, output_dir): | 26 def __init__(self, templates, database, emitters, output_dir): |
| 20 super(NativeImplementationSystem, self).__init__( | 27 super(NativeImplementationSystem, self).__init__( |
| 21 templates, database, emitters, output_dir) | 28 templates, database, emitters, output_dir) |
| 22 | 29 |
| 23 self._dom_impl_files = [] | 30 self._dom_impl_files = [] |
| 24 self._cpp_header_files = [] | 31 self._cpp_header_files = [] |
| 25 self._cpp_impl_files = [] | 32 self._cpp_impl_files = [] |
| 26 self._html_system = HtmlSystemShared(database) | 33 self._html_system = HtmlSystemShared(database) |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 self._cpp_resolver_emitter.Emit( | 255 self._cpp_resolver_emitter.Emit( |
| 249 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' | 256 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' |
| 250 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', | 257 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', |
| 251 INTERFACE_NAME=self._interface.id) | 258 INTERFACE_NAME=self._interface.id) |
| 252 | 259 |
| 253 | 260 |
| 254 constructor_info = AnalyzeConstructor(self._interface) | 261 constructor_info = AnalyzeConstructor(self._interface) |
| 255 if constructor_info: | 262 if constructor_info: |
| 256 self._EmitFactoryProvider(self._interface.id, constructor_info) | 263 self._EmitFactoryProvider(self._interface.id, constructor_info) |
| 257 | 264 |
| 258 if 'CustomConstructor' in self._interface.ext_attrs: | 265 ext_attrs = self._interface.ext_attrs |
| 266 | |
| 267 if 'CustomConstructor' in ext_attrs: | |
| 259 # We have a custom implementation for it. | 268 # We have a custom implementation for it. |
| 260 self._cpp_declarations_emitter.Emit( | 269 self._cpp_declarations_emitter.Emit( |
| 261 '\n' | 270 '\n' |
| 262 'void constructorCallback(Dart_NativeArguments);\n') | 271 'void constructorCallback(Dart_NativeArguments);\n') |
| 263 return | 272 return |
| 264 | 273 |
| 265 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs | 274 raises_dom_exceptions = 'ConstructorRaisesException' in ext_attrs |
| 266 raises_exceptions = raises_dom_exceptions or len(constructor_info.idl_args) > 0 | 275 raises_exceptions = raises_dom_exceptions or len(constructor_info.idl_args) > 0 |
| 267 arguments = [] | 276 arguments = [] |
| 268 parameter_definitions_emitter = emitter.Emitter() | 277 parameter_definitions_emitter = emitter.Emitter() |
| 269 create_function = 'create' | 278 create_function = 'create' |
| 270 if 'NamedConstructor' in self._interface.ext_attrs: | 279 if 'NamedConstructor' in ext_attrs: |
| 271 raises_exceptions = True | 280 raises_exceptions = True |
| 281 self._cpp_impl_includes.add('"DOMWindow.h"') | |
| 272 parameter_definitions_emitter.Emit( | 282 parameter_definitions_emitter.Emit( |
| 273 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' | 283 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' |
| 274 ' if (!domWindow) {\n' | 284 ' if (!domWindow) {\n' |
| 275 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' | 285 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' |
| 276 ' goto fail;\n' | 286 ' goto fail;\n' |
| 277 ' }\n' | 287 ' }\n' |
| 278 ' Document* document = domWindow->document();\n') | 288 ' Document* document = domWindow->document();\n') |
| 279 self._cpp_impl_includes.add('"DOMWindow.h"') | |
| 280 arguments.append('document') | 289 arguments.append('document') |
| 281 create_function = 'createForJSConstructor' | 290 create_function = 'createForJSConstructor' |
| 282 if 'CallWith' in self._interface.ext_attrs: | 291 if 'CallWith' in ext_attrs: |
| 283 call_with = self._interface.ext_attrs['CallWith'] | 292 call_with = ext_attrs['CallWith'] |
| 284 if call_with == 'ScriptExecutionContext': | 293 if call_with == 'ScriptExecutionContext': |
| 285 raises_exceptions = True | 294 raises_exceptions = True |
| 286 parameter_definitions_emitter.Emit( | 295 parameter_definitions_emitter.Emit( |
| 287 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' | 296 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' |
| 288 ' if (!context) {\n' | 297 ' if (!context) {\n' |
| 289 ' exception = Dart_NewString("Failed to create an object" );\n' | 298 ' exception = Dart_NewString("Failed to create an object" );\n' |
| 290 ' goto fail;\n' | 299 ' goto fail;\n' |
| 291 ' }\n') | 300 ' }\n') |
| 292 arguments.append('context') | 301 arguments.append('context') |
| 293 else: | 302 else: |
| 294 raise Exception('Unsupported CallWith=%s attribute' % call_with) | 303 raise Exception('Unsupported CallWith=%s attribute' % call_with) |
| 295 | 304 |
| 296 # Process constructor arguments. | 305 # Process constructor arguments. |
| 297 for (i, argument) in enumerate(constructor_info.idl_args): | 306 for (i, argument) in enumerate(constructor_info.idl_args): |
| 298 argument_expression = self._GenerateToNative( | 307 argument_expression = self._GenerateToNative( |
| 299 parameter_definitions_emitter, argument, i) | 308 parameter_definitions_emitter, argument, i) |
| 300 arguments.append(argument_expression) | 309 arguments.append(argument_expression) |
| 301 | 310 |
| 302 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) | 311 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) |
| 303 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 312 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
| 304 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) | 313 self._interface.id, ext_attrs, raises_dom_exceptions) |
| 305 | 314 |
| 306 runtime_check = None | 315 runtime_check = None |
| 307 database = self._system._database | 316 database = self._system._database |
| 308 if 'synthesizedV8EnabledPerContext' in self._interface.ext_attrs: | 317 assert (not ( |
| 318 'synthesizedV8EnabledPerContext' in ext_attrs and | |
| 319 'synthesizedV8EnabledAtRuntime' in ext_attrs)) | |
| 320 if 'synthesizedV8EnabledPerContext' in ext_attrs: | |
| 309 raises_exceptions = True | 321 raises_exceptions = True |
| 310 self._cpp_impl_includes.add('"ContextFeatures.h"') | 322 self._cpp_impl_includes.add('"ContextFeatures.h"') |
| 311 runtime_check = emitter.Format( | 323 runtime_check = emitter.Format( |
| 312 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n' | 324 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n' |
| 313 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' | 325 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' |
| 314 ' goto fail;\n' | 326 ' goto fail;\n' |
| 315 ' }', | 327 ' }', |
| 316 FEATURE=self._interface.ext_attrs['synthesizedV8EnabledPerContext']) | 328 FEATURE=ext_attrs['synthesizedV8EnabledPerContext']) |
| 329 | |
| 330 if 'synthesizedV8EnabledAtRuntime' in ext_attrs: | |
| 331 raises_exceptions = True | |
| 332 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"') | |
| 333 runtime_check = emitter.Format( | |
| 334 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' | |
| 335 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' | |
| 336 ' goto fail;\n' | |
| 337 ' }', | |
| 338 FEATURE=toWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) | |
| 317 | 339 |
| 318 self._GenerateNativeCallback(callback_name='constructorCallback', | 340 self._GenerateNativeCallback(callback_name='constructorCallback', |
| 319 parameter_definitions=parameter_definitions_emitter.Fragments(), | 341 parameter_definitions=parameter_definitions_emitter.Fragments(), |
| 320 needs_receiver=False, invocation=invocation, | 342 needs_receiver=False, invocation=invocation, |
| 321 raises_exceptions=raises_exceptions, | 343 raises_exceptions=raises_exceptions, |
| 322 runtime_check=runtime_check) | 344 runtime_check=runtime_check) |
| 323 | 345 |
| 324 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name): | 346 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name): |
| 325 EmitHtmlElementFactoryConstructors( | 347 EmitHtmlElementFactoryConstructors( |
| 326 self._system._EmitterForFactoryProviderBody( | 348 self._system._EmitterForFactoryProviderBody( |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 webcore_function_name = 'getNonEmptyURLAttribute' | 626 webcore_function_name = 'getNonEmptyURLAttribute' |
| 605 else: | 627 else: |
| 606 webcore_function_name = 'getURLAttribute' | 628 webcore_function_name = 'getURLAttribute' |
| 607 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) | 629 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) |
| 608 else: | 630 else: |
| 609 if attr.id == 'operator': | 631 if attr.id == 'operator': |
| 610 webcore_function_name = '_operator' | 632 webcore_function_name = '_operator' |
| 611 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': | 633 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': |
| 612 webcore_function_name = 'svgTarget' | 634 webcore_function_name = 'svgTarget' |
| 613 else: | 635 else: |
| 614 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', | 636 webcore_function_name = toWebKitName(attr.id) |
| 615 lambda s: s.group(1).lower(), | |
| 616 attr.id) | |
| 617 webcore_function_name = re.sub(r'^(create|exclusive)', | |
| 618 lambda s: 'is' + s.group(1).capitalize(), | |
| 619 webcore_function_name) | |
| 620 if attr.type.id.startswith('SVGAnimated'): | 637 if attr.type.id.startswith('SVGAnimated'): |
| 621 webcore_function_name += 'Animated' | 638 webcore_function_name += 'Animated' |
| 622 | 639 |
| 623 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) | 640 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) |
| 624 invocation = self._GenerateWebCoreInvocation(function_expression, | 641 invocation = self._GenerateWebCoreInvocation(function_expression, |
| 625 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) | 642 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) |
| 626 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), | 643 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), |
| 627 True, invocation, raises_exceptions=raises_exceptions) | 644 True, invocation, raises_exceptions=raises_exceptions) |
| 628 | 645 |
| 629 def _AddSetter(self, attr, html_name): | 646 def _AddSetter(self, attr, html_name): |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 continue | 1089 continue |
| 1073 parent_interface = database.GetInterface(parent.type.id) | 1090 parent_interface = database.GetInterface(parent.type.id) |
| 1074 if callback(parent_interface): | 1091 if callback(parent_interface): |
| 1075 return parent_interface | 1092 return parent_interface |
| 1076 parent_interface = _FindParent(parent_interface, database, callback) | 1093 parent_interface = _FindParent(parent_interface, database, callback) |
| 1077 if parent_interface: | 1094 if parent_interface: |
| 1078 return parent_interface | 1095 return parent_interface |
| 1079 | 1096 |
| 1080 def _IsArgumentOptionalInWebCore(argument): | 1097 def _IsArgumentOptionalInWebCore(argument): |
| 1081 return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 1098 return IsOptional(argument) and not 'Callback' in argument.ext_attrs |
| OLD | NEW |