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

Side by Side Diff: Source/bindings/scripts/v8_types.py

Issue 1086113002: IDL: Improve "includes for type" mechanism in various ways (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/scripts/v8_union.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 'core/dom/NodeList.h', 359 'core/dom/NodeList.h',
360 'core/dom/StaticNodeList.h', 360 'core/dom/StaticNodeList.h',
361 'core/html/LabelsNodeList.h']), 361 'core/html/LabelsNodeList.h']),
362 'Promise': set(['bindings/core/v8/ScriptPromise.h']), 362 'Promise': set(['bindings/core/v8/ScriptPromise.h']),
363 'SerializedScriptValue': set(['bindings/core/v8/SerializedScriptValue.h', 363 'SerializedScriptValue': set(['bindings/core/v8/SerializedScriptValue.h',
364 'bindings/core/v8/SerializedScriptValueFactory .h']), 364 'bindings/core/v8/SerializedScriptValueFactory .h']),
365 'ScriptValue': set(['bindings/core/v8/ScriptValue.h']), 365 'ScriptValue': set(['bindings/core/v8/ScriptValue.h']),
366 } 366 }
367 367
368 368
369 def includes_for_type(idl_type): 369 def includes_for_type(idl_type, extended_attributes=None):
370 idl_type = idl_type.preprocessed_type 370 idl_type = idl_type.preprocessed_type
371 extended_attributes = extended_attributes or {}
371 372
372 # Simple types 373 # Simple types
373 base_idl_type = idl_type.base_type 374 base_idl_type = idl_type.base_type
374 if base_idl_type in INCLUDES_FOR_TYPE: 375 if base_idl_type in INCLUDES_FOR_TYPE:
375 return INCLUDES_FOR_TYPE[base_idl_type] 376 return INCLUDES_FOR_TYPE[base_idl_type]
376 if idl_type.is_basic_type: 377 if idl_type.is_basic_type:
377 return set() 378 return set()
378 if base_idl_type.endswith('ConstructorConstructor'): 379 if base_idl_type.endswith('ConstructorConstructor'):
379 # FIXME: rename to NamedConstructor 380 # FIXME: rename to NamedConstructor
380 # FIXME: replace with a [NamedConstructorAttribute] extended attribute 381 # FIXME: replace with a [NamedConstructorAttribute] extended attribute
381 # Ending with 'ConstructorConstructor' indicates a named constructor, 382 # Ending with 'ConstructorConstructor' indicates a named constructor,
382 # and these do not have header files, as they are part of the generated 383 # and these do not have header files, as they are part of the generated
383 # bindings for the interface 384 # bindings for the interface
384 return set() 385 return set()
385 if base_idl_type.endswith('Constructor'): 386 if base_idl_type.endswith('Constructor'):
386 # FIXME: replace with a [ConstructorAttribute] extended attribute 387 # FIXME: replace with a [ConstructorAttribute] extended attribute
387 base_idl_type = idl_type.constructor_type_name 388 base_idl_type = idl_type.constructor_type_name
388 if base_idl_type not in component_dir: 389 if base_idl_type not in component_dir:
389 return set() 390 return set()
390 return set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], 391 return set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type],
391 base_idl_type)]) 392 base_idl_type)])
392 393
393 IdlType.includes_for_type = property(includes_for_type) 394 IdlType.includes_for_type = includes_for_type
394 IdlUnionType.includes_for_type = property(
395 lambda self: set.union(*[member_type.includes_for_type
396 for member_type in self.member_types]))
397 IdlArrayOrSequenceType.includes_for_type = property(
398 lambda self: self.element_type.includes_for_type)
399 395
400 396
401 def add_includes_for_type(idl_type): 397 def includes_for_union_type(idl_type, extended_attributes=None):
402 includes.update(idl_type.includes_for_type) 398 return set.union(*[member_type.includes_for_type(extended_attributes)
399 for member_type in idl_type.member_types])
400
401 IdlUnionType.includes_for_type = includes_for_union_type
402
403
404 def includes_for_array_or_sequence_type(idl_type, extended_attributes=None):
405 return idl_type.element_type.includes_for_type(extended_attributes)
406
407 IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type
408
409
410 def add_includes_for_type(idl_type, extended_attributes=None):
411 includes.update(idl_type.includes_for_type(extended_attributes))
403 412
404 IdlTypeBase.add_includes_for_type = add_includes_for_type 413 IdlTypeBase.add_includes_for_type = add_includes_for_type
405 414
406 415
407 def includes_for_interface(interface_name): 416 def includes_for_interface(interface_name):
408 return IdlType(interface_name).includes_for_type 417 return IdlType(interface_name).includes_for_type()
409 418
410 419
411 def add_includes_for_interface(interface_name): 420 def add_includes_for_interface(interface_name):
412 includes.update(includes_for_interface(interface_name)) 421 includes.update(includes_for_interface(interface_name))
413 422
414 423
415 def impl_should_use_nullable_container(idl_type): 424 def impl_should_use_nullable_container(idl_type):
416 return not(idl_type.cpp_type_has_null_value) 425 return not(idl_type.cpp_type_has_null_value)
417 426
418 IdlTypeBase.impl_should_use_nullable_container = property( 427 IdlTypeBase.impl_should_use_nullable_container = property(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if idl_type.name == 'void': 541 if idl_type.name == 'void':
533 return '' 542 return ''
534 543
535 # Array or sequence types 544 # Array or sequence types
536 native_array_element_type = idl_type.native_array_element_type 545 native_array_element_type = idl_type.native_array_element_type
537 if native_array_element_type: 546 if native_array_element_type:
538 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) 547 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate)
539 548
540 # Simple types 549 # Simple types
541 idl_type = idl_type.preprocessed_type 550 idl_type = idl_type.preprocessed_type
542 add_includes_for_type(idl_type)
543 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type 551 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type
544 552
545 if idl_type.is_integer_type: 553 if idl_type.is_integer_type:
546 configuration = 'NormalConversion' 554 configuration = 'NormalConversion'
547 if 'EnforceRange' in extended_attributes: 555 if 'EnforceRange' in extended_attributes:
548 configuration = 'EnforceRange' 556 configuration = 'EnforceRange'
549 elif 'Clamp' in extended_attributes: 557 elif 'Clamp' in extended_attributes:
550 configuration = 'Clamp' 558 configuration = 'Clamp'
551 arguments = ', '.join([v8_value, configuration, 'exceptionState']) 559 arguments = ', '.join([v8_value, configuration, 'exceptionState'])
552 elif idl_type.v8_conversion_needs_exception_state: 560 elif idl_type.v8_conversion_needs_exception_state:
(...skipping 22 matching lines...) Expand all
575 # and is used to provide a human-readable exception message 583 # and is used to provide a human-readable exception message
576 if index is None: 584 if index is None:
577 index = 0 # special case, meaning "setter" 585 index = 0 # special case, meaning "setter"
578 else: 586 else:
579 index += 1 # human-readable index 587 index += 1 # human-readable index
580 if (native_array_element_type.is_interface_type and 588 if (native_array_element_type.is_interface_type and
581 native_array_element_type.name != 'Dictionary'): 589 native_array_element_type.name != 'Dictionary'):
582 this_cpp_type = None 590 this_cpp_type = None
583 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type) 591 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type)
584 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))' 592 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))'
585 add_includes_for_type(native_array_element_type)
586 else: 593 else:
587 ref_ptr_type = None 594 ref_ptr_type = None
588 this_cpp_type = native_array_element_type.cpp_type 595 this_cpp_type = native_array_element_type.cpp_type
589 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' 596 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)'
590 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate) 597 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate)
591 return expression 598 return expression
592 599
593 600
594 # FIXME: this function should be refactored, as this takes too many flags. 601 # FIXME: this function should be refactored, as this takes too many flags.
595 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_ return_value=None, use_exception_state=False, restricted_float=False): 602 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_ return_value=None, use_exception_state=False, restricted_float=False):
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 # non-nullable dictionaries or unions. 729 # non-nullable dictionaries or unions.
723 if idl_type.is_dictionary and idl_type.is_nullable: 730 if idl_type.is_dictionary and idl_type.is_nullable:
724 return 'NullableDictionary' 731 return 'NullableDictionary'
725 732
726 if idl_type.is_dictionary or idl_type.is_union_type: 733 if idl_type.is_dictionary or idl_type.is_union_type:
727 return 'DictionaryOrUnion' 734 return 'DictionaryOrUnion'
728 735
729 # Array or sequence types 736 # Array or sequence types
730 native_array_element_type = idl_type.native_array_element_type 737 native_array_element_type = idl_type.native_array_element_type
731 if native_array_element_type: 738 if native_array_element_type:
732 if native_array_element_type.is_interface_type:
733 add_includes_for_type(native_array_element_type)
734 return 'array' 739 return 'array'
735 740
736 # Simple types 741 # Simple types
737 base_idl_type = idl_type.base_type 742 base_idl_type = idl_type.base_type
738 # Basic types, without additional includes 743 # Basic types, without additional includes
739 if base_idl_type in CPP_INT_TYPES: 744 if base_idl_type in CPP_INT_TYPES:
740 return 'int' 745 return 'int'
741 if base_idl_type in CPP_UNSIGNED_TYPES: 746 if base_idl_type in CPP_UNSIGNED_TYPES:
742 return 'unsigned' 747 return 'unsigned'
743 if idl_type.is_string_type: 748 if idl_type.is_string_type:
744 if idl_type.is_nullable: 749 if idl_type.is_nullable:
745 return 'StringOrNull' 750 return 'StringOrNull'
746 if 'TreatReturnedNullStringAs' not in extended_attributes: 751 if 'TreatReturnedNullStringAs' not in extended_attributes:
747 return base_idl_type 752 return base_idl_type
748 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] 753 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs']
749 if treat_returned_null_string_as == 'Null': 754 if treat_returned_null_string_as == 'Null':
750 return 'StringOrNull' 755 return 'StringOrNull'
751 if treat_returned_null_string_as == 'Undefined': 756 if treat_returned_null_string_as == 'Undefined':
752 return 'StringOrUndefined' 757 return 'StringOrUndefined'
753 raise 'Unrecognized TreatReturnedNullStringAs value: "%s"' % treat_retur ned_null_string_as 758 raise 'Unrecognized TreatReturnedNullStringAs value: "%s"' % treat_retur ned_null_string_as
754 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': 759 if idl_type.is_basic_type or base_idl_type == 'ScriptValue':
755 return base_idl_type 760 return base_idl_type
756 # Generic dictionary type 761 # Generic dictionary type
757 if base_idl_type == 'Dictionary': 762 if base_idl_type == 'Dictionary':
758 return 'Dictionary' 763 return 'Dictionary'
759 764
760 # Data type with potential additional includes 765 # Data type with potential additional includes
761 add_includes_for_type(idl_type)
762 if base_idl_type in V8_SET_RETURN_VALUE: # Special v8SetReturnValue treatme nt 766 if base_idl_type in V8_SET_RETURN_VALUE: # Special v8SetReturnValue treatme nt
763 return base_idl_type 767 return base_idl_type
764 768
765 # Pointer type 769 # Pointer type
766 return 'DOMWrapper' 770 return 'DOMWrapper'
767 771
768 IdlTypeBase.v8_conversion_type = v8_conversion_type 772 IdlTypeBase.v8_conversion_type = v8_conversion_type
769 773
770 774
771 V8_SET_RETURN_VALUE = { 775 V8_SET_RETURN_VALUE = {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 number_of_nullable_member_types_union) 974 number_of_nullable_member_types_union)
971 975
972 976
973 def includes_nullable_type_union(idl_type): 977 def includes_nullable_type_union(idl_type):
974 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 978 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
975 return idl_type.number_of_nullable_member_types == 1 979 return idl_type.number_of_nullable_member_types == 1
976 980
977 IdlTypeBase.includes_nullable_type = False 981 IdlTypeBase.includes_nullable_type = False
978 IdlNullableType.includes_nullable_type = True 982 IdlNullableType.includes_nullable_type = True
979 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 983 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/scripts/v8_union.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698