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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 # We have a custom implementation for it. | 271 # We have a custom implementation for it. |
272 self._cpp_declarations_emitter.Emit( | 272 self._cpp_declarations_emitter.Emit( |
273 '\n' | 273 '\n' |
274 'void constructorCallback(Dart_NativeArguments);\n') | 274 'void constructorCallback(Dart_NativeArguments);\n') |
275 return | 275 return |
276 | 276 |
277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_
attrs | 277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_
attrs |
278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a
rgs) > 0 | 278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a
rgs) > 0 |
279 arguments = [] | 279 arguments = [] |
280 parameter_definitions_emitter = emitter.Emitter() | 280 parameter_definitions_emitter = emitter.Emitter() |
| 281 create_function = 'create' |
| 282 if 'NamedConstructor' in self._interface.ext_attrs: |
| 283 raises_dart_exceptions = True |
| 284 parameter_definitions_emitter.Emit( |
| 285 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs
olate();\n' |
| 286 ' if (!domWindow) {\n' |
| 287 ' exception = Dart_NewString("Failed to fetch domWindow")
;\n' |
| 288 ' goto fail;\n' |
| 289 ' }\n' |
| 290 ' Document* document = domWindow->document();\n') |
| 291 arguments.append('document') |
| 292 create_function = 'createForJSConstructor' |
281 if 'CallWith' in self._interface.ext_attrs: | 293 if 'CallWith' in self._interface.ext_attrs: |
282 call_with = self._interface.ext_attrs['CallWith'] | 294 call_with = self._interface.ext_attrs['CallWith'] |
283 if call_with == 'ScriptExecutionContext': | 295 if call_with == 'ScriptExecutionContext': |
284 raises_dart_exceptions = True | 296 raises_dart_exceptions = True |
285 parameter_definitions_emitter.Emit( | 297 parameter_definitions_emitter.Emit( |
286 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' | 298 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' |
287 ' if (!context) {\n' | 299 ' if (!context) {\n' |
288 ' exception = Dart_NewString("Failed to create an object"
);\n' | 300 ' exception = Dart_NewString("Failed to create an object"
);\n' |
289 ' goto fail;\n' | 301 ' goto fail;\n' |
290 ' }\n') | 302 ' }\n') |
291 arguments.append('context') | 303 arguments.append('context') |
292 else: | 304 else: |
293 raise Exception('Unsupported CallWith=%s attribute' % call_with) | 305 raise Exception('Unsupported CallWith=%s attribute' % call_with) |
294 | 306 |
295 # Process constructor arguments. | 307 # Process constructor arguments. |
296 for (i, arg) in enumerate(constructor_info.idl_args): | 308 for (i, arg) in enumerate(constructor_info.idl_args): |
297 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) | 309 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) |
298 arguments.append(arg.id) | 310 arguments.append(arg.id) |
299 | 311 |
300 function_expression = '%s::create' % self._interface_type_info.native_type() | 312 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
301 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 313 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
302 self._interface, self._interface.ext_attrs, raises_dom_exceptions) | 314 self._interface, self._interface.ext_attrs, raises_dom_exceptions) |
303 self._GenerateNativeCallback(callback_name='constructorCallback', | 315 self._GenerateNativeCallback(callback_name='constructorCallback', |
304 parameter_definitions=parameter_definitions_emitter.Fragments(), | 316 parameter_definitions=parameter_definitions_emitter.Fragments(), |
305 needs_receiver=False, invocation=invocation, | 317 needs_receiver=False, invocation=invocation, |
306 raises_exceptions=raises_dart_exceptions) | 318 raises_exceptions=raises_dart_exceptions) |
307 | 319 |
308 def _ImplClassName(self, interface_name): | 320 def _ImplClassName(self, interface_name): |
309 return interface_name + 'Implementation' | 321 return interface_name + 'Implementation' |
310 | 322 |
311 def _IsConstructable(self): | 323 def _IsConstructable(self): |
312 # FIXME: support ConstructorTemplate. | 324 # FIXME: support ConstructorTemplate. |
313 # FIXME: support NamedConstructor. | 325 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) |
314 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se
t(self._interface.ext_attrs) | |
315 | 326 |
316 def FinishInterface(self): | 327 def FinishInterface(self): |
317 base = self._BaseClassName(self._interface) | 328 base = self._BaseClassName(self._interface) |
318 self._dart_impl_emitter.Emit( | 329 self._dart_impl_emitter.Emit( |
319 self._templates.Load('dart_implementation.darttemplate'), | 330 self._templates.Load('dart_implementation.darttemplate'), |
320 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, | 331 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, |
321 MEMBERS=self._members_emitter.Fragments()) | 332 MEMBERS=self._members_emitter.Fragments()) |
322 | 333 |
323 self._GenerateCppHeader() | 334 self._GenerateCppHeader() |
324 | 335 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 '}\n', | 670 '}\n', |
660 CALLBACK_NAME=callback_name, | 671 CALLBACK_NAME=callback_name, |
661 BODY=body) | 672 BODY=body) |
662 | 673 |
663 def _GenerateParameterAdapter(self, emitter, idl_argument, index): | 674 def _GenerateParameterAdapter(self, emitter, idl_argument, index): |
664 type_info = GetIDLTypeInfo(idl_argument.type) | 675 type_info = GetIDLTypeInfo(idl_argument.type) |
665 (adapter_type, include_name) = type_info.parameter_adapter_info() | 676 (adapter_type, include_name) = type_info.parameter_adapter_info() |
666 if include_name: | 677 if include_name: |
667 self._cpp_impl_includes[include_name] = 1 | 678 self._cpp_impl_includes[include_name] = 1 |
668 flags = '' | 679 flags = '' |
669 if (idl_argument.ext_attrs.get('Optionial') == 'DefaultIsNullString' or | 680 if (idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString' or |
670 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext
_attrs)): | 681 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext
_attrs)): |
671 flags = ', DartUtilities::ConvertNullToDefaultValue' | 682 flags = ', DartUtilities::ConvertNullToDefaultValue' |
672 emitter.Emit( | 683 emitter.Emit( |
673 '\n' | 684 '\n' |
674 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$
FLAGS);\n' | 685 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$
FLAGS);\n' |
675 ' if (!$NAME.conversionSuccessful()) {\n' | 686 ' if (!$NAME.conversionSuccessful()) {\n' |
676 ' exception = $NAME.exception();\n' | 687 ' exception = $NAME.exception();\n' |
677 ' goto fail;\n' | 688 ' goto fail;\n' |
678 ' }\n', | 689 ' }\n', |
679 ADAPTER_TYPE=adapter_type, | 690 ADAPTER_TYPE=adapter_type, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 ' goto fail;\n' | 783 ' goto fail;\n' |
773 ' }\n', | 784 ' }\n', |
774 INVOCATION=invocation_template) | 785 INVOCATION=invocation_template) |
775 | 786 |
776 if 'ImplementedBy' in attributes: | 787 if 'ImplementedBy' in attributes: |
777 arguments.insert(0, 'receiver') | 788 arguments.insert(0, 'receiver') |
778 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 | 789 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 |
779 | 790 |
780 return emitter.Format(invocation_template, | 791 return emitter.Format(invocation_template, |
781 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) | 792 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) |
OLD | NEW |