OLD | NEW |
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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 def includes_for_interface(interface_name): | 390 def includes_for_interface(interface_name): |
391 return IdlType(interface_name).includes_for_type | 391 return IdlType(interface_name).includes_for_type |
392 | 392 |
393 | 393 |
394 def add_includes_for_interface(interface_name): | 394 def add_includes_for_interface(interface_name): |
395 includes.update(includes_for_interface(interface_name)) | 395 includes.update(includes_for_interface(interface_name)) |
396 | 396 |
397 | 397 |
398 def impl_should_use_nullable_container(idl_type): | 398 def impl_should_use_nullable_container(idl_type): |
399 return idl_type.native_array_element_type or idl_type.is_primitive_type | 399 return not(idl_type.cpp_type_has_null_value) |
400 | 400 |
401 IdlTypeBase.impl_should_use_nullable_container = property( | 401 IdlTypeBase.impl_should_use_nullable_container = property( |
402 impl_should_use_nullable_container) | 402 impl_should_use_nullable_container) |
403 | 403 |
404 | 404 |
405 def impl_includes_for_type(idl_type, interfaces_info): | 405 def impl_includes_for_type(idl_type, interfaces_info): |
406 includes_for_type = set() | 406 includes_for_type = set() |
407 if idl_type.impl_should_use_nullable_container: | 407 if idl_type.impl_should_use_nullable_container: |
408 includes_for_type.add('bindings/core/v8/Nullable.h') | 408 includes_for_type.add('bindings/core/v8/Nullable.h') |
409 | 409 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 return literal_value | 783 return literal_value |
784 | 784 |
785 IdlType.literal_cpp_value = literal_cpp_value | 785 IdlType.literal_cpp_value = literal_cpp_value |
786 | 786 |
787 | 787 |
788 ################################################################################ | 788 ################################################################################ |
789 # Utility properties for nullable types | 789 # Utility properties for nullable types |
790 ################################################################################ | 790 ################################################################################ |
791 | 791 |
792 | 792 |
| 793 def cpp_type_has_null_value(idl_type): |
| 794 # - String types (String/AtomicString) represent null as a null string, |
| 795 # i.e. one for which String::isNull() returns true. |
| 796 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as |
| 797 # a null pointer. |
| 798 return ((idl_type.is_string_type or idl_type.is_wrapper_type) and |
| 799 not idl_type.native_array_element_type) |
| 800 |
| 801 IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value) |
| 802 |
| 803 |
793 def is_implicit_nullable(idl_type): | 804 def is_implicit_nullable(idl_type): |
794 # Nullable type where the corresponding C++ type supports a null value. | 805 # Nullable type where the corresponding C++ type supports a null value. |
795 # - String types (String/AtomicString) represent null as a null string, | 806 return idl_type.is_nullable and idl_type.cpp_type_has_null_value |
796 # i.e. one for which String::isNull() returns true. | |
797 # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as | |
798 # a null pointer. | |
799 return idl_type.is_nullable and ( | |
800 (idl_type.is_string_type or idl_type.is_wrapper_type) and | |
801 not idl_type.native_array_element_type) | |
802 | 807 |
803 | 808 |
804 def is_explicit_nullable(idl_type): | 809 def is_explicit_nullable(idl_type): |
805 # Nullable type that isn't implicit nullable (see above.) For such types, | 810 # Nullable type that isn't implicit nullable (see above.) For such types, |
806 # we use Nullable<T> or similar explicit ways to represent a null value. | 811 # we use Nullable<T> or similar explicit ways to represent a null value. |
807 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 812 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
808 | 813 |
809 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) | 814 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
810 IdlUnionType.is_implicit_nullable = False | 815 IdlUnionType.is_implicit_nullable = False |
811 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 816 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |