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

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

Issue 13201004: Support nullable attributes and return types in Dartium. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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/idlrenderer.py ('k') | no next file » | 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if 'NamedConstructor' in ext_attrs: 220 if 'NamedConstructor' in ext_attrs:
221 create_function = 'createForJSConstructor' 221 create_function = 'createForJSConstructor'
222 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 222 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
223 self._GenerateNativeCallback( 223 self._GenerateNativeCallback(
224 constructor_callback_cpp_name, 224 constructor_callback_cpp_name,
225 False, 225 False,
226 function_expression, 226 function_expression,
227 self._interface, 227 self._interface,
228 arguments, 228 arguments,
229 self._interface.id, 229 self._interface.id,
230 False,
230 'ConstructorRaisesException' in ext_attrs) 231 'ConstructorRaisesException' in ext_attrs)
231 232
232 def HasSupportCheck(self): 233 def HasSupportCheck(self):
233 # Need to omit a support check if it is conditional in JS. 234 # Need to omit a support check if it is conditional in JS.
234 return self._interface.doc_js_name in js_support_checks 235 return self._interface.doc_js_name in js_support_checks
235 236
236 def GetSupportCheck(self): 237 def GetSupportCheck(self):
237 # Assume that everything is supported on Dartium. 238 # Assume that everything is supported on Dartium.
238 value = js_support_checks.get(self._interface.doc_js_name) 239 value = js_support_checks.get(self._interface.doc_js_name)
239 if type(value) == tuple: 240 if type(value) == tuple:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 webcore_function_name += 'Animated' 346 webcore_function_name += 'Animated'
346 347
347 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 348 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
348 self._GenerateNativeCallback( 349 self._GenerateNativeCallback(
349 cpp_callback_name, 350 cpp_callback_name,
350 True, 351 True,
351 function_expression, 352 function_expression,
352 attr, 353 attr,
353 [], 354 [],
354 attr.type.id, 355 attr.type.id,
356 attr.type.nullable,
355 attr.get_raises) 357 attr.get_raises)
356 358
357 def _AddSetter(self, attr, html_name): 359 def _AddSetter(self, attr, html_name):
358 type_info = self._TypeInfo(attr.type.id) 360 type_info = self._TypeInfo(attr.type.id)
359 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id)) 361 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id))
360 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 362 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
361 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 363 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
362 dart_declaration, 'Setter', is_custom) 364 dart_declaration, 'Setter', is_custom)
363 if is_custom: 365 if is_custom:
364 return 366 return
365 367
366 if 'Reflect' in attr.ext_attrs: 368 if 'Reflect' in attr.ext_attrs:
367 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() 369 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name()
368 else: 370 else:
369 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 371 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
370 lambda s: s.group(1).upper(), 372 lambda s: s.group(1).upper(),
371 attr.id) 373 attr.id)
372 webcore_function_name = 'set%s' % webcore_function_name 374 webcore_function_name = 'set%s' % webcore_function_name
373 if attr.type.id.startswith('SVGAnimated'): 375 if attr.type.id.startswith('SVGAnimated'):
374 webcore_function_name += 'Animated' 376 webcore_function_name += 'Animated'
375 377
376 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 378 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
377 self._GenerateNativeCallback( 379 self._GenerateNativeCallback(
378 cpp_callback_name, 380 cpp_callback_name,
379 True, 381 True,
380 function_expression, 382 function_expression,
381 attr, 383 attr,
382 [attr], 384 [attr],
383 'void', 385 'void',
386 False,
384 attr.set_raises) 387 attr.set_raises)
385 388
386 def AddIndexer(self, element_type): 389 def AddIndexer(self, element_type):
387 """Adds all the methods required to complete implementation of List.""" 390 """Adds all the methods required to complete implementation of List."""
388 # We would like to simply inherit the implementation of everything except 391 # We would like to simply inherit the implementation of everything except
389 # length, [], and maybe []=. It is possible to extend from a base 392 # length, [], and maybe []=. It is possible to extend from a base
390 # array implementation class only when there is no other implementation 393 # array implementation class only when there is no other implementation
391 # inheritance. There might be no implementation inheritance other than 394 # inheritance. There might be no implementation inheritance other than
392 # DOMBaseWrapper for many classes, but there might be some where the 395 # DOMBaseWrapper for many classes, but there might be some where the
393 # array-ness is introduced by a non-root interface: 396 # array-ness is introduced by a non-root interface:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): 520 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name):
518 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 521 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
519 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 522 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
520 self._GenerateNativeCallback( 523 self._GenerateNativeCallback(
521 cpp_callback_name, 524 cpp_callback_name,
522 not operation.is_static, 525 not operation.is_static,
523 function_expression, 526 function_expression,
524 operation, 527 operation,
525 arguments, 528 arguments,
526 operation.type.id, 529 operation.type.id,
530 operation.type.nullable,
527 operation.raises) 531 operation.raises)
528 532
529 def _GenerateNativeCallback(self, 533 def _GenerateNativeCallback(self,
530 callback_name, 534 callback_name,
531 needs_receiver, 535 needs_receiver,
532 function_expression, 536 function_expression,
533 node, 537 node,
534 arguments, 538 arguments,
535 return_type, 539 return_type,
540 return_type_is_nullable,
536 raises_dom_exception): 541 raises_dom_exception):
537 ext_attrs = node.ext_attrs 542 ext_attrs = node.ext_attrs
538 543
539 cpp_arguments = [] 544 cpp_arguments = []
540 runtime_check = None 545 runtime_check = None
541 raises_exceptions = raises_dom_exception or arguments 546 raises_exceptions = raises_dom_exception or arguments
542 547
543 # TODO(antonm): unify with ScriptState below. 548 # TODO(antonm): unify with ScriptState below.
544 requires_stack_info = ext_attrs.get('CallWith') == 'ScriptArguments|ScriptSt ate' 549 requires_stack_info = ext_attrs.get('CallWith') == 'ScriptArguments|ScriptSt ate'
545 if requires_stack_info: 550 if requires_stack_info:
(...skipping 28 matching lines...) Expand all
574 cpp_arguments = ['document'] 579 cpp_arguments = ['document']
575 580
576 if 'ImplementedBy' in ext_attrs: 581 if 'ImplementedBy' in ext_attrs:
577 assert needs_receiver 582 assert needs_receiver
578 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) 583 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy'])
579 cpp_arguments.append('receiver') 584 cpp_arguments.append('receiver')
580 585
581 if 'Reflect' in ext_attrs: 586 if 'Reflect' in ext_attrs:
582 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] 587 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)]
583 588
589 if return_type_is_nullable:
590 cpp_arguments = ['isNull']
591
584 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at trs.get('V8EnabledPerContext')) 592 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at trs.get('V8EnabledPerContext'))
585 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr s.get('V8EnabledAtRuntime')) 593 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr s.get('V8EnabledAtRuntime'))
586 assert(not (v8EnabledPerContext and v8EnabledAtRuntime)) 594 assert(not (v8EnabledPerContext and v8EnabledAtRuntime))
587 595
588 if v8EnabledPerContext: 596 if v8EnabledPerContext:
589 raises_exceptions = True 597 raises_exceptions = True
590 self._cpp_impl_includes.add('"ContextFeatures.h"') 598 self._cpp_impl_includes.add('"ContextFeatures.h"')
591 self._cpp_impl_includes.add('"DOMWindow.h"') 599 self._cpp_impl_includes.add('"DOMWindow.h"')
592 runtime_check = emitter.Format( 600 runtime_check = emitter.Format(
593 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n' 601 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n'
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 759
752 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) 760 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
753 if return_type == 'void': 761 if return_type == 'void':
754 invocation_emitter.Emit( 762 invocation_emitter.Emit(
755 ' $FUNCTION_CALL;\n', 763 ' $FUNCTION_CALL;\n',
756 FUNCTION_CALL=function_call) 764 FUNCTION_CALL=function_call)
757 else: 765 else:
758 return_type_info = self._TypeInfo(return_type) 766 return_type_info = self._TypeInfo(return_type)
759 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) 767 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
760 768
769 if return_type_is_nullable:
770 invocation_emitter.Emit(
771 ' bool isNull = false;\n'
772 ' $NATIVE_TYPE result = $FUNCTION_CALL;\n'
773 ' if (isNull)\n'
774 ' return;\n',
775 NATIVE_TYPE=return_type_info.native_type(),
776 FUNCTION_CALL=function_call)
777 value_expression = 'result'
778 else:
779 value_expression = function_call
780
761 # Generate to Dart conversion of C++ value. 781 # Generate to Dart conversion of C++ value.
762 to_dart_conversion = return_type_info.to_dart_conversion(function_call, se lf._interface.id, ext_attrs) 782 to_dart_conversion = return_type_info.to_dart_conversion(value_expression, self._interface.id, ext_attrs)
763 invocation_emitter.Emit( 783 invocation_emitter.Emit(
764 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n' 784 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n'
765 ' if (returnValue)\n' 785 ' if (returnValue)\n'
766 ' Dart_SetReturnValue(args, returnValue);\n', 786 ' Dart_SetReturnValue(args, returnValue);\n',
767 TO_DART_CONVERSION=to_dart_conversion) 787 TO_DART_CONVERSION=to_dart_conversion)
768 788
769 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 789 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
770 native_suffix, is_custom): 790 native_suffix, is_custom):
771 annotations = FormatAnnotationsAndComments( 791 annotations = FormatAnnotationsAndComments(
772 GetAnnotationsAndComments(self._renamer.GetLibraryName(self._interface), 792 GetAnnotationsAndComments(self._renamer.GetLibraryName(self._interface),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 916 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
897 ' return func;\n', 917 ' return func;\n',
898 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 918 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
899 919
900 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 920 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
901 return ( 921 return (
902 interface.id.endswith('Event') and 922 interface.id.endswith('Event') and
903 operation.id.startswith('init') and 923 operation.id.startswith('init') and
904 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and 924 argument.ext_attrs.get('Optional') == 'DefaultIsUndefined' and
905 argument.type.id == 'DOMString') 925 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/idlrenderer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698