Chromium Code Reviews| 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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 | 889 |
| 890 | 890 |
| 891 def literal_cpp_value(idl_type, idl_literal): | 891 def literal_cpp_value(idl_type, idl_literal): |
| 892 """Converts an expression that is a valid C++ literal for this type.""" | 892 """Converts an expression that is a valid C++ literal for this type.""" |
| 893 # FIXME: add validation that idl_type and idl_literal are compatible | 893 # FIXME: add validation that idl_type and idl_literal are compatible |
| 894 literal_value = str(idl_literal) | 894 literal_value = str(idl_literal) |
| 895 if idl_type.base_type in CPP_UNSIGNED_TYPES: | 895 if idl_type.base_type in CPP_UNSIGNED_TYPES: |
| 896 return literal_value + 'u' | 896 return literal_value + 'u' |
| 897 return literal_value | 897 return literal_value |
| 898 | 898 |
| 899 | |
| 900 def union_literal_cpp_value(idl_type, idl_literal): | |
|
haraken
2015/02/18 15:09:04
Can we merge literal_cpp_value and union_literal_c
Jens Widell
2015/02/18 15:14:39
We can implement a single function that handles bo
| |
| 901 if idl_literal.is_null: | |
| 902 return idl_type.name + '()' | |
| 903 elif idl_literal.idl_type == 'DOMString': | |
| 904 member_type = idl_type.string_member_type | |
| 905 elif idl_literal.idl_type in ('integer', 'float'): | |
| 906 member_type = idl_type.numeric_member_type | |
| 907 elif idl_literal.idl_type == 'boolean': | |
| 908 member_type = idl_type.boolean_member_type | |
| 909 else: | |
| 910 raise ValueError('Unsupported literal type: ' + idl_literal.idl_type) | |
| 911 | |
| 912 return '%s::from%s(%s)' % (idl_type.name, member_type.name, | |
| 913 member_type.literal_cpp_value(idl_literal)) | |
| 914 | |
| 899 IdlType.literal_cpp_value = literal_cpp_value | 915 IdlType.literal_cpp_value = literal_cpp_value |
| 916 IdlUnionType.literal_cpp_value = union_literal_cpp_value | |
| 900 | 917 |
| 901 | 918 |
| 902 ################################################################################ | 919 ################################################################################ |
| 903 # Utility properties for nullable types | 920 # Utility properties for nullable types |
| 904 ################################################################################ | 921 ################################################################################ |
| 905 | 922 |
| 906 | 923 |
| 907 def cpp_type_has_null_value(idl_type): | 924 def cpp_type_has_null_value(idl_type): |
| 908 # - String types (String/AtomicString) represent null as a null string, | 925 # - String types (String/AtomicString) represent null as a null string, |
| 909 # i.e. one for which String::isNull() returns true. | 926 # i.e. one for which String::isNull() returns true. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 number_of_nullable_member_types_union) | 966 number_of_nullable_member_types_union) |
| 950 | 967 |
| 951 | 968 |
| 952 def includes_nullable_type_union(idl_type): | 969 def includes_nullable_type_union(idl_type): |
| 953 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 970 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| 954 return idl_type.number_of_nullable_member_types == 1 | 971 return idl_type.number_of_nullable_member_types == 1 |
| 955 | 972 |
| 956 IdlTypeBase.includes_nullable_type = False | 973 IdlTypeBase.includes_nullable_type = False |
| 957 IdlNullableType.includes_nullable_type = True | 974 IdlNullableType.includes_nullable_type = True |
| 958 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 975 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
| OLD | NEW |