| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 constructor_info = AnalyzeConstructor(self._interface) | 242 constructor_info = AnalyzeConstructor(self._interface) |
| 243 if constructor_info is None: | 243 if constructor_info is None: |
| 244 # We have a custom implementation for it. | 244 # We have a custom implementation for it. |
| 245 self._cpp_declarations_emitter.Emit( | 245 self._cpp_declarations_emitter.Emit( |
| 246 '\n' | 246 '\n' |
| 247 'void constructorCallback(Dart_NativeArguments);\n') | 247 'void constructorCallback(Dart_NativeArguments);\n') |
| 248 return | 248 return |
| 249 | 249 |
| 250 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_
attrs | 250 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_
attrs |
| 251 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a
rgs) > 0 | 251 raises_exceptions = raises_dom_exceptions or len(constructor_info.idl_args)
> 0 |
| 252 arguments = [] | 252 arguments = [] |
| 253 parameter_definitions_emitter = emitter.Emitter() | 253 parameter_definitions_emitter = emitter.Emitter() |
| 254 create_function = 'create' | 254 create_function = 'create' |
| 255 if 'NamedConstructor' in self._interface.ext_attrs: | 255 if 'NamedConstructor' in self._interface.ext_attrs: |
| 256 raises_dart_exceptions = True | 256 raises_exceptions = True |
| 257 parameter_definitions_emitter.Emit( | 257 parameter_definitions_emitter.Emit( |
| 258 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs
olate();\n' | 258 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs
olate();\n' |
| 259 ' if (!domWindow) {\n' | 259 ' if (!domWindow) {\n' |
| 260 ' exception = Dart_NewString("Failed to fetch domWindow")
;\n' | 260 ' exception = Dart_NewString("Failed to fetch domWindow")
;\n' |
| 261 ' goto fail;\n' | 261 ' goto fail;\n' |
| 262 ' }\n' | 262 ' }\n' |
| 263 ' Document* document = domWindow->document();\n') | 263 ' Document* document = domWindow->document();\n') |
| 264 self._cpp_impl_includes.add('DOMWindow') | 264 self._cpp_impl_includes.add('DOMWindow') |
| 265 arguments.append('document') | 265 arguments.append('document') |
| 266 create_function = 'createForJSConstructor' | 266 create_function = 'createForJSConstructor' |
| 267 if 'CallWith' in self._interface.ext_attrs: | 267 if 'CallWith' in self._interface.ext_attrs: |
| 268 call_with = self._interface.ext_attrs['CallWith'] | 268 call_with = self._interface.ext_attrs['CallWith'] |
| 269 if call_with == 'ScriptExecutionContext': | 269 if call_with == 'ScriptExecutionContext': |
| 270 raises_dart_exceptions = True | 270 raises_exceptions = True |
| 271 parameter_definitions_emitter.Emit( | 271 parameter_definitions_emitter.Emit( |
| 272 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' | 272 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' |
| 273 ' if (!context) {\n' | 273 ' if (!context) {\n' |
| 274 ' exception = Dart_NewString("Failed to create an object"
);\n' | 274 ' exception = Dart_NewString("Failed to create an object"
);\n' |
| 275 ' goto fail;\n' | 275 ' goto fail;\n' |
| 276 ' }\n') | 276 ' }\n') |
| 277 arguments.append('context') | 277 arguments.append('context') |
| 278 else: | 278 else: |
| 279 raise Exception('Unsupported CallWith=%s attribute' % call_with) | 279 raise Exception('Unsupported CallWith=%s attribute' % call_with) |
| 280 | 280 |
| 281 # Process constructor arguments. | 281 # Process constructor arguments. |
| 282 for (i, arg) in enumerate(constructor_info.idl_args): | 282 for (i, arg) in enumerate(constructor_info.idl_args): |
| 283 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) | 283 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) |
| 284 arguments.append(arg.id) | 284 arguments.append(arg.id) |
| 285 | 285 |
| 286 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 286 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 287 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 287 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
| 288 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) | 288 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) |
| 289 self._GenerateNativeCallback(callback_name='constructorCallback', | 289 self._GenerateNativeCallback(callback_name='constructorCallback', |
| 290 parameter_definitions=parameter_definitions_emitter.Fragments(), | 290 parameter_definitions=parameter_definitions_emitter.Fragments(), |
| 291 needs_receiver=False, invocation=invocation, | 291 needs_receiver=False, invocation=invocation, |
| 292 raises_exceptions=raises_dart_exceptions) | 292 raises_exceptions=raises_exceptions) |
| 293 | 293 |
| 294 def _ImplClassName(self, interface_name): | 294 def _ImplClassName(self, interface_name): |
| 295 return interface_name + 'Implementation' | 295 return interface_name + 'Implementation' |
| 296 | 296 |
| 297 def _IsConstructable(self): | 297 def _IsConstructable(self): |
| 298 # FIXME: support ConstructorTemplate. | 298 # FIXME: support ConstructorTemplate. |
| 299 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) | 299 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) |
| 300 | 300 |
| 301 def FinishInterface(self): | 301 def FinishInterface(self): |
| 302 base = self._BaseClassName(self._interface) | 302 base = self._BaseClassName(self._interface) |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', | 577 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', |
| 578 is_custom) | 578 is_custom) |
| 579 if is_custom: | 579 if is_custom: |
| 580 return | 580 return |
| 581 | 581 |
| 582 # Generate callback. | 582 # Generate callback. |
| 583 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) | 583 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i
d) |
| 584 | 584 |
| 585 parameter_definitions_emitter = emitter.Emitter() | 585 parameter_definitions_emitter = emitter.Emitter() |
| 586 arguments = [] | 586 arguments = [] |
| 587 raises_dart_exceptions = self._GenerateCallWithHandling( | 587 raises_exceptions = self._GenerateCallWithHandling( |
| 588 operation, parameter_definitions_emitter, arguments) | 588 operation, parameter_definitions_emitter, arguments) |
| 589 raises_dart_exceptions = raises_dart_exceptions or len(operation.arguments)
> 0 or operation.raises | 589 raises_exceptions = raises_exceptions or len(operation.arguments) > 0 or ope
ration.raises |
| 590 | 590 |
| 591 # Process Dart arguments. | 591 # Process Dart arguments. |
| 592 for (i, argument) in enumerate(operation.arguments): | 592 for (i, argument) in enumerate(operation.arguments): |
| 593 if (i == len(operation.arguments) - 1 and | 593 if (i == len(operation.arguments) - 1 and |
| 594 self._interface.id == 'Console' and | 594 self._interface.id == 'Console' and |
| 595 argument.id == 'arg'): | 595 argument.id == 'arg'): |
| 596 # FIXME: we are skipping last argument here because it was added in | 596 # FIXME: we are skipping last argument here because it was added in |
| 597 # supplemental dart.idl. Cleanup dart.idl and remove this check. | 597 # supplemental dart.idl. Cleanup dart.idl and remove this check. |
| 598 break | 598 break |
| 599 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i) | 599 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 613 | 613 |
| 614 if 'NeedsUserGestureCheck' in operation.ext_attrs: | 614 if 'NeedsUserGestureCheck' in operation.ext_attrs: |
| 615 arguments.append('DartUtilities::processingUserGesture') | 615 arguments.append('DartUtilities::processingUserGesture') |
| 616 | 616 |
| 617 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) | 617 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, operation) |
| 618 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 618 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
| 619 operation.type.id, operation.ext_attrs, operation.raises) | 619 operation.type.id, operation.ext_attrs, operation.raises) |
| 620 self._GenerateNativeCallback(cpp_callback_name, | 620 self._GenerateNativeCallback(cpp_callback_name, |
| 621 parameter_definitions=parameter_definitions_emitter.Fragments(), | 621 parameter_definitions=parameter_definitions_emitter.Fragments(), |
| 622 needs_receiver=True, invocation=invocation, | 622 needs_receiver=True, invocation=invocation, |
| 623 raises_exceptions=raises_dart_exceptions) | 623 raises_exceptions=raises_exceptions) |
| 624 | 624 |
| 625 def _GenerateNativeCallback(self, callback_name, parameter_definitions, | 625 def _GenerateNativeCallback(self, callback_name, parameter_definitions, |
| 626 needs_receiver, invocation, raises_exceptions): | 626 needs_receiver, invocation, raises_exceptions): |
| 627 | 627 |
| 628 if needs_receiver: | 628 if needs_receiver: |
| 629 parameter_definitions = emitter.Format( | 629 parameter_definitions = emitter.Format( |
| 630 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n' | 630 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n' |
| 631 ' $PARAMETER_DEFINITIONS\n', | 631 ' $PARAMETER_DEFINITIONS\n', |
| 632 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 632 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 633 PARAMETER_DEFINITIONS=parameter_definitions) | 633 PARAMETER_DEFINITIONS=parameter_definitions) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 777 |
| 778 if 'ImplementedBy' in attributes: | 778 if 'ImplementedBy' in attributes: |
| 779 arguments.insert(0, 'receiver') | 779 arguments.insert(0, 'receiver') |
| 780 self._cpp_impl_includes.add(attributes['ImplementedBy']) | 780 self._cpp_impl_includes.add(attributes['ImplementedBy']) |
| 781 | 781 |
| 782 return emitter.Format(invocation_template, | 782 return emitter.Format(invocation_template, |
| 783 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) | 783 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) |
| 784 | 784 |
| 785 def _GenerateCPPIncludes(includes): | 785 def _GenerateCPPIncludes(includes): |
| 786 return ''.join(['#include "%s.h"\n' % include for include in includes]) | 786 return ''.join(['#include "%s.h"\n' % include for include in includes]) |
| OLD | NEW |