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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 implemented_as_class = idl_type.implemented_as | 183 implemented_as_class = idl_type.implemented_as |
184 if raw_type: | 184 if raw_type: |
185 return implemented_as_class + '*' | 185 return implemented_as_class + '*' |
186 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 186 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
187 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument else 'RefPtr')
, new_type, idl_type.gc_type) | 187 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument else 'RefPtr')
, new_type, idl_type.gc_type) |
188 return cpp_template_type(ptr_type, implemented_as_class) | 188 return cpp_template_type(ptr_type, implemented_as_class) |
189 # Default, assume native type is a pointer with same type name as idl type | 189 # Default, assume native type is a pointer with same type name as idl type |
190 return base_idl_type + '*' | 190 return base_idl_type + '*' |
191 | 191 |
192 | 192 |
| 193 def cpp_type_initializer(idl_type): |
| 194 """Returns a string containing a C++ initialization statement for the |
| 195 corresponding type. |
| 196 |
| 197 |idl_type| argument is of type IdlType. |
| 198 """ |
| 199 |
| 200 if (idl_type.is_numeric_type): |
| 201 return ' = 0' |
| 202 if idl_type.base_type == 'boolean': |
| 203 return ' = false' |
| 204 return '' |
| 205 |
| 206 |
193 def cpp_type_union(idl_type, extended_attributes=None, raw_type=False): | 207 def cpp_type_union(idl_type, extended_attributes=None, raw_type=False): |
194 return (member_type.cpp_type for member_type in idl_type.member_types) | 208 return (member_type.cpp_type for member_type in idl_type.member_types) |
195 | 209 |
196 | 210 |
| 211 def cpp_type_initializer_union(idl_type): |
| 212 return (member_type.cpp_type_initializer for member_type in idl_type.member_
types) |
| 213 |
| 214 |
197 # Allow access as idl_type.cpp_type if no arguments | 215 # Allow access as idl_type.cpp_type if no arguments |
198 IdlType.cpp_type = property(cpp_type) | 216 IdlType.cpp_type = property(cpp_type) |
| 217 IdlType.cpp_type_initializer = property(cpp_type_initializer) |
199 IdlUnionType.cpp_type = property(cpp_type_union) | 218 IdlUnionType.cpp_type = property(cpp_type_union) |
| 219 IdlUnionType.cpp_type_initializer = property(cpp_type_initializer_union) |
200 IdlType.cpp_type_args = cpp_type | 220 IdlType.cpp_type_args = cpp_type |
201 IdlUnionType.cpp_type_args = cpp_type_union | 221 IdlUnionType.cpp_type_args = cpp_type_union |
202 | 222 |
203 | 223 |
204 def cpp_template_type(template, inner_type): | 224 def cpp_template_type(template, inner_type): |
205 """Returns C++ template specialized to type, with space added if needed.""" | 225 """Returns C++ template specialized to type, with space added if needed.""" |
206 if inner_type.endswith('>'): | 226 if inner_type.endswith('>'): |
207 format_string = '{template}<{inner_type} >' | 227 format_string = '{template}<{inner_type} >' |
208 else: | 228 else: |
209 format_string = '{template}<{inner_type}>' | 229 format_string = '{template}<{inner_type}>' |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 | 761 |
742 def is_explicit_nullable(idl_type): | 762 def is_explicit_nullable(idl_type): |
743 # Nullable type that isn't implicit nullable (see above.) For such types, | 763 # Nullable type that isn't implicit nullable (see above.) For such types, |
744 # we use Nullable<T> or similar explicit ways to represent a null value. | 764 # we use Nullable<T> or similar explicit ways to represent a null value. |
745 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 765 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
746 | 766 |
747 IdlType.is_implicit_nullable = property(is_implicit_nullable) | 767 IdlType.is_implicit_nullable = property(is_implicit_nullable) |
748 IdlType.is_explicit_nullable = property(is_explicit_nullable) | 768 IdlType.is_explicit_nullable = property(is_explicit_nullable) |
749 IdlUnionType.is_implicit_nullable = False | 769 IdlUnionType.is_implicit_nullable = False |
750 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) | 770 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |