| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generates C++ source files from a mojom.Module.""" | 5 """Generates C++ source files from a mojom.Module.""" |
| 6 | 6 |
| 7 import mojom.generate.generator as generator | 7 import mojom.generate.generator as generator |
| 8 import mojom.generate.module as mojom | 8 import mojom.generate.module as mojom |
| 9 import mojom.generate.pack as pack | 9 import mojom.generate.pack as pack |
| 10 from mojom.generate.template_expander import UseJinja | 10 from mojom.generate.template_expander import UseJinja |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 | 36 |
| 37 _kind_to_cpp_literal_suffix = { | 37 _kind_to_cpp_literal_suffix = { |
| 38 mojom.UINT8: "U", | 38 mojom.UINT8: "U", |
| 39 mojom.UINT16: "U", | 39 mojom.UINT16: "U", |
| 40 mojom.UINT32: "U", | 40 mojom.UINT32: "U", |
| 41 mojom.FLOAT: "f", | 41 mojom.FLOAT: "f", |
| 42 mojom.UINT64: "ULL", | 42 mojom.UINT64: "ULL", |
| 43 } | 43 } |
| 44 | 44 |
| 45 # TODO(rockot): Get rid of this global. This requires some refactoring of the |
| 46 # generator library code so that filters can use the generator as context. |
| 47 _current_typemap = {} |
| 48 |
| 49 |
| 45 def ConstantValue(constant): | 50 def ConstantValue(constant): |
| 46 return ExpressionToText(constant.value, kind=constant.kind) | 51 return ExpressionToText(constant.value, kind=constant.kind) |
| 47 | 52 |
| 48 def DefaultValue(field): | 53 def DefaultValue(field): |
| 49 if field.default: | 54 if field.default: |
| 50 if mojom.IsStructKind(field.kind): | 55 if mojom.IsStructKind(field.kind): |
| 51 assert field.default == "default" | 56 assert field.default == "default" |
| 52 return "%s::New()" % GetNameForKind(field.kind) | 57 return "%s::New()" % GetNameForKind(field.kind) |
| 53 return ExpressionToText(field.default, kind=field.kind) | 58 return ExpressionToText(field.default, kind=field.kind) |
| 54 return "" | 59 return "" |
| 55 | 60 |
| 56 def NamespaceToArray(namespace): | 61 def NamespaceToArray(namespace): |
| 57 return namespace.split(".") if namespace else [] | 62 return namespace.split(".") if namespace else [] |
| 58 | 63 |
| 59 def GetNameForKind(kind, internal = False): | 64 def GetNameForKind(kind, internal = False): |
| 60 parts = [] | 65 parts = [] |
| 61 if kind.imported_from: | 66 if kind.imported_from: |
| 62 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) | 67 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) |
| 63 if internal: | 68 if internal: |
| 64 parts.append("internal") | 69 parts.append("internal") |
| 65 if kind.parent_kind: | 70 if kind.parent_kind: |
| 66 parts.append(kind.parent_kind.name) | 71 parts.append(kind.parent_kind.name) |
| 67 parts.append(kind.name) | 72 parts.append(kind.name) |
| 68 return "::".join(parts) | 73 return "::".join(parts) |
| 69 | 74 |
| 75 def GetFullMojomNameForKind(kind): |
| 76 parts = [] |
| 77 if kind.imported_from: |
| 78 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) |
| 79 elif hasattr(kind, "module"): |
| 80 parts.extend(NamespaceToArray(kind.module.namespace)) |
| 81 parts.append(kind.name) |
| 82 return ".".join(parts) |
| 83 |
| 84 def IsTypemappedKind(kind): |
| 85 return hasattr(kind, "name") and \ |
| 86 GetFullMojomNameForKind(kind) in _current_typemap |
| 87 |
| 88 def IsNativeOnlyKind(kind): |
| 89 return IsTypemappedKind(kind) and kind.native_only |
| 90 |
| 91 def GetNativeTypeName(typemapped_kind): |
| 92 return _current_typemap[GetFullMojomNameForKind(typemapped_kind)]["typename"] |
| 93 |
| 70 def GetQualifiedNameForKind(kind): | 94 def GetQualifiedNameForKind(kind): |
| 71 # Always start with an empty part to force a leading "::" on output. | 95 # Always start with an empty part to force a leading "::" on output. |
| 72 parts = [""] | 96 parts = [""] |
| 73 parts.extend(NamespaceToArray(kind.module.namespace)) | 97 parts.extend(NamespaceToArray(kind.module.namespace)) |
| 74 parts.append(kind.name) | 98 parts.append(kind.name) |
| 75 return "::".join(parts) | 99 return "::".join(parts) |
| 76 | 100 |
| 77 def GetCppType(kind): | 101 def GetCppType(kind): |
| 102 if mojom.IsStructKind(kind) and kind.native_only: |
| 103 raise Exception("Should not be reached!") |
| 78 if mojom.IsArrayKind(kind): | 104 if mojom.IsArrayKind(kind): |
| 79 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) | 105 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) |
| 80 if mojom.IsMapKind(kind): | 106 if mojom.IsMapKind(kind): |
| 81 return "mojo::internal::Map_Data<%s, %s>*" % ( | 107 return "mojo::internal::Map_Data<%s, %s>*" % ( |
| 82 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) | 108 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) |
| 83 if mojom.IsStructKind(kind): | 109 if mojom.IsStructKind(kind): |
| 84 return "%s_Data*" % GetNameForKind(kind, internal=True) | 110 return "%s_Data*" % GetNameForKind(kind, internal=True) |
| 85 if mojom.IsUnionKind(kind): | 111 if mojom.IsUnionKind(kind): |
| 86 return "%s_Data" % GetNameForKind(kind, internal=True) | 112 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 87 if mojom.IsInterfaceKind(kind): | 113 if mojom.IsInterfaceKind(kind): |
| 88 return "mojo::internal::Interface_Data" | 114 return "mojo::internal::Interface_Data" |
| 89 if mojom.IsInterfaceRequestKind(kind): | 115 if mojom.IsInterfaceRequestKind(kind): |
| 90 return "mojo::MessagePipeHandle" | 116 return "mojo::MessagePipeHandle" |
| 91 if mojom.IsAssociatedInterfaceKind(kind): | 117 if mojom.IsAssociatedInterfaceKind(kind): |
| 92 return "mojo::internal::AssociatedInterface_Data" | 118 return "mojo::internal::AssociatedInterface_Data" |
| 93 if mojom.IsAssociatedInterfaceRequestKind(kind): | 119 if mojom.IsAssociatedInterfaceRequestKind(kind): |
| 94 return "mojo::internal::AssociatedInterfaceRequest_Data" | 120 return "mojo::internal::AssociatedInterfaceRequest_Data" |
| 95 if mojom.IsEnumKind(kind): | 121 if mojom.IsEnumKind(kind): |
| 96 return "int32_t" | 122 return "int32_t" |
| 97 if mojom.IsStringKind(kind): | 123 if mojom.IsStringKind(kind): |
| 98 return "mojo::internal::String_Data*" | 124 return "mojo::internal::String_Data*" |
| 99 return _kind_to_cpp_type[kind] | 125 return _kind_to_cpp_type[kind] |
| 100 | 126 |
| 101 def GetCppPodType(kind): | 127 def GetCppPodType(kind): |
| 102 if mojom.IsStringKind(kind): | 128 if mojom.IsStringKind(kind): |
| 103 return "char*" | 129 return "char*" |
| 104 return _kind_to_cpp_type[kind] | 130 return _kind_to_cpp_type[kind] |
| 105 | 131 |
| 106 def GetCppArrayArgWrapperType(kind): | 132 def GetCppArrayArgWrapperType(kind): |
| 133 if mojom.IsStructKind(kind) and kind.native_only: |
| 134 raise Exception("Cannot serialize containers of native-only types yet!") |
| 107 if mojom.IsEnumKind(kind): | 135 if mojom.IsEnumKind(kind): |
| 108 return GetNameForKind(kind) | 136 return GetNameForKind(kind) |
| 109 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 137 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 110 return "%sPtr" % GetNameForKind(kind) | 138 return "%sPtr" % GetNameForKind(kind) |
| 111 if mojom.IsArrayKind(kind): | 139 if mojom.IsArrayKind(kind): |
| 112 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) | 140 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) |
| 113 if mojom.IsMapKind(kind): | 141 if mojom.IsMapKind(kind): |
| 114 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), | 142 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), |
| 115 GetCppArrayArgWrapperType(kind.value_kind)) | 143 GetCppArrayArgWrapperType(kind.value_kind)) |
| 116 if mojom.IsInterfaceKind(kind): | 144 if mojom.IsInterfaceKind(kind): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 130 return "mojo::ScopedDataPipeConsumerHandle" | 158 return "mojo::ScopedDataPipeConsumerHandle" |
| 131 if mojom.IsDataPipeProducerKind(kind): | 159 if mojom.IsDataPipeProducerKind(kind): |
| 132 return "mojo::ScopedDataPipeProducerHandle" | 160 return "mojo::ScopedDataPipeProducerHandle" |
| 133 if mojom.IsMessagePipeKind(kind): | 161 if mojom.IsMessagePipeKind(kind): |
| 134 return "mojo::ScopedMessagePipeHandle" | 162 return "mojo::ScopedMessagePipeHandle" |
| 135 if mojom.IsSharedBufferKind(kind): | 163 if mojom.IsSharedBufferKind(kind): |
| 136 return "mojo::ScopedSharedBufferHandle" | 164 return "mojo::ScopedSharedBufferHandle" |
| 137 return _kind_to_cpp_type[kind] | 165 return _kind_to_cpp_type[kind] |
| 138 | 166 |
| 139 def GetCppResultWrapperType(kind): | 167 def GetCppResultWrapperType(kind): |
| 168 if IsTypemappedKind(kind): |
| 169 return "const %s&" % GetNativeTypeName(kind) |
| 140 if mojom.IsEnumKind(kind): | 170 if mojom.IsEnumKind(kind): |
| 141 return GetNameForKind(kind) | 171 return GetNameForKind(kind) |
| 142 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 172 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 143 return "%sPtr" % GetNameForKind(kind) | 173 return "%sPtr" % GetNameForKind(kind) |
| 144 if mojom.IsArrayKind(kind): | 174 if mojom.IsArrayKind(kind): |
| 145 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 175 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 146 if mojom.IsMapKind(kind): | 176 if mojom.IsMapKind(kind): |
| 147 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 177 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 148 GetCppArrayArgWrapperType(kind.value_kind)) | 178 GetCppArrayArgWrapperType(kind.value_kind)) |
| 149 if mojom.IsInterfaceKind(kind): | 179 if mojom.IsInterfaceKind(kind): |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 return "mojo::ScopedSharedBufferHandle" | 198 return "mojo::ScopedSharedBufferHandle" |
| 169 # TODO(rudominer) After improvements to compiler front end have landed, | 199 # TODO(rudominer) After improvements to compiler front end have landed, |
| 170 # revisit strategy used below for emitting a useful error message when an | 200 # revisit strategy used below for emitting a useful error message when an |
| 171 # undefined identifier is referenced. | 201 # undefined identifier is referenced. |
| 172 val = _kind_to_cpp_type.get(kind) | 202 val = _kind_to_cpp_type.get(kind) |
| 173 if (val is not None): | 203 if (val is not None): |
| 174 return val | 204 return val |
| 175 raise Exception("Unrecognized kind %s" % kind.spec) | 205 raise Exception("Unrecognized kind %s" % kind.spec) |
| 176 | 206 |
| 177 def GetCppWrapperType(kind): | 207 def GetCppWrapperType(kind): |
| 208 if IsTypemappedKind(kind): |
| 209 return GetNativeTypeName(kind) |
| 178 if mojom.IsEnumKind(kind): | 210 if mojom.IsEnumKind(kind): |
| 179 return GetNameForKind(kind) | 211 return GetNameForKind(kind) |
| 180 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 212 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 181 return "%sPtr" % GetNameForKind(kind) | 213 return "%sPtr" % GetNameForKind(kind) |
| 182 if mojom.IsArrayKind(kind): | 214 if mojom.IsArrayKind(kind): |
| 183 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 215 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 184 if mojom.IsMapKind(kind): | 216 if mojom.IsMapKind(kind): |
| 185 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 217 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 186 GetCppArrayArgWrapperType(kind.value_kind)) | 218 GetCppArrayArgWrapperType(kind.value_kind)) |
| 187 if mojom.IsInterfaceKind(kind): | 219 if mojom.IsInterfaceKind(kind): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 200 return "mojo::ScopedDataPipeConsumerHandle" | 232 return "mojo::ScopedDataPipeConsumerHandle" |
| 201 if mojom.IsDataPipeProducerKind(kind): | 233 if mojom.IsDataPipeProducerKind(kind): |
| 202 return "mojo::ScopedDataPipeProducerHandle" | 234 return "mojo::ScopedDataPipeProducerHandle" |
| 203 if mojom.IsMessagePipeKind(kind): | 235 if mojom.IsMessagePipeKind(kind): |
| 204 return "mojo::ScopedMessagePipeHandle" | 236 return "mojo::ScopedMessagePipeHandle" |
| 205 if mojom.IsSharedBufferKind(kind): | 237 if mojom.IsSharedBufferKind(kind): |
| 206 return "mojo::ScopedSharedBufferHandle" | 238 return "mojo::ScopedSharedBufferHandle" |
| 207 return _kind_to_cpp_type[kind] | 239 return _kind_to_cpp_type[kind] |
| 208 | 240 |
| 209 def GetCppConstWrapperType(kind): | 241 def GetCppConstWrapperType(kind): |
| 242 if IsTypemappedKind(kind): |
| 243 return "const %s&" % GetNativeTypeName(kind) |
| 210 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 244 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 211 return "%sPtr" % GetNameForKind(kind) | 245 return "%sPtr" % GetNameForKind(kind) |
| 212 if mojom.IsArrayKind(kind): | 246 if mojom.IsArrayKind(kind): |
| 213 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 247 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 214 if mojom.IsMapKind(kind): | 248 if mojom.IsMapKind(kind): |
| 215 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 249 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 216 GetCppArrayArgWrapperType(kind.value_kind)) | 250 GetCppArrayArgWrapperType(kind.value_kind)) |
| 217 if mojom.IsInterfaceKind(kind): | 251 if mojom.IsInterfaceKind(kind): |
| 218 return "%sPtr" % GetNameForKind(kind) | 252 return "%sPtr" % GetNameForKind(kind) |
| 219 if mojom.IsInterfaceRequestKind(kind): | 253 if mojom.IsInterfaceRequestKind(kind): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 234 return "mojo::ScopedDataPipeProducerHandle" | 268 return "mojo::ScopedDataPipeProducerHandle" |
| 235 if mojom.IsMessagePipeKind(kind): | 269 if mojom.IsMessagePipeKind(kind): |
| 236 return "mojo::ScopedMessagePipeHandle" | 270 return "mojo::ScopedMessagePipeHandle" |
| 237 if mojom.IsSharedBufferKind(kind): | 271 if mojom.IsSharedBufferKind(kind): |
| 238 return "mojo::ScopedSharedBufferHandle" | 272 return "mojo::ScopedSharedBufferHandle" |
| 239 if not kind in _kind_to_cpp_type: | 273 if not kind in _kind_to_cpp_type: |
| 240 print "missing:", kind.spec | 274 print "missing:", kind.spec |
| 241 return _kind_to_cpp_type[kind] | 275 return _kind_to_cpp_type[kind] |
| 242 | 276 |
| 243 def GetCppFieldType(kind): | 277 def GetCppFieldType(kind): |
| 278 if IsNativeOnlyKind(kind): |
| 279 return "mojo::internal::ArrayPointer<uint8_t>" |
| 244 if mojom.IsStructKind(kind): | 280 if mojom.IsStructKind(kind): |
| 245 return ("mojo::internal::StructPointer<%s_Data>" % | 281 return ("mojo::internal::StructPointer<%s_Data>" % |
| 246 GetNameForKind(kind, internal=True)) | 282 GetNameForKind(kind, internal=True)) |
| 247 if mojom.IsUnionKind(kind): | 283 if mojom.IsUnionKind(kind): |
| 248 return "%s_Data" % GetNameForKind(kind, internal=True) | 284 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 249 if mojom.IsArrayKind(kind): | 285 if mojom.IsArrayKind(kind): |
| 250 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) | 286 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) |
| 251 if mojom.IsMapKind(kind): | 287 if mojom.IsMapKind(kind): |
| 252 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % | 288 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % |
| 253 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) | 289 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 return False | 376 return False |
| 341 for field in struct.fields: | 377 for field in struct.fields: |
| 342 if mojom.IsMoveOnlyKind(field.kind): | 378 if mojom.IsMoveOnlyKind(field.kind): |
| 343 return False | 379 return False |
| 344 return True | 380 return True |
| 345 | 381 |
| 346 def ShouldInlineUnion(union): | 382 def ShouldInlineUnion(union): |
| 347 return not any(mojom.IsMoveOnlyKind(field.kind) for field in union.fields) | 383 return not any(mojom.IsMoveOnlyKind(field.kind) for field in union.fields) |
| 348 | 384 |
| 349 def GetArrayValidateParamsCtorArgs(kind): | 385 def GetArrayValidateParamsCtorArgs(kind): |
| 350 if mojom.IsStringKind(kind): | 386 if mojom.IsStringKind(kind) or (mojom.IsStructKind(kind) and |
| 387 kind.native_only): |
| 351 expected_num_elements = 0 | 388 expected_num_elements = 0 |
| 352 element_is_nullable = False | 389 element_is_nullable = False |
| 353 element_validate_params = "nullptr" | 390 element_validate_params = "nullptr" |
| 354 elif mojom.IsMapKind(kind): | 391 elif mojom.IsMapKind(kind): |
| 355 expected_num_elements = 0 | 392 expected_num_elements = 0 |
| 356 element_is_nullable = mojom.IsNullableKind(kind.value_kind) | 393 element_is_nullable = mojom.IsNullableKind(kind.value_kind) |
| 357 element_validate_params = GetNewArrayValidateParams(kind.value_kind) | 394 element_validate_params = GetNewArrayValidateParams(kind.value_kind) |
| 358 else: | 395 else: |
| 359 expected_num_elements = generator.ExpectedArraySize(kind) or 0 | 396 expected_num_elements = generator.ExpectedArraySize(kind) or 0 |
| 360 element_is_nullable = mojom.IsNullableKind(kind.kind) | 397 element_is_nullable = mojom.IsNullableKind(kind.kind) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 "get_pad": pack.GetPad, | 436 "get_pad": pack.GetPad, |
| 400 "get_qualified_name_for_kind": GetQualifiedNameForKind, | 437 "get_qualified_name_for_kind": GetQualifiedNameForKind, |
| 401 "has_callbacks": mojom.HasCallbacks, | 438 "has_callbacks": mojom.HasCallbacks, |
| 402 "should_inline": ShouldInlineStruct, | 439 "should_inline": ShouldInlineStruct, |
| 403 "should_inline_union": ShouldInlineUnion, | 440 "should_inline_union": ShouldInlineUnion, |
| 404 "is_array_kind": mojom.IsArrayKind, | 441 "is_array_kind": mojom.IsArrayKind, |
| 405 "is_cloneable_kind": mojom.IsCloneableKind, | 442 "is_cloneable_kind": mojom.IsCloneableKind, |
| 406 "is_enum_kind": mojom.IsEnumKind, | 443 "is_enum_kind": mojom.IsEnumKind, |
| 407 "is_integral_kind": mojom.IsIntegralKind, | 444 "is_integral_kind": mojom.IsIntegralKind, |
| 408 "is_move_only_kind": mojom.IsMoveOnlyKind, | 445 "is_move_only_kind": mojom.IsMoveOnlyKind, |
| 446 "is_native_only_kind": IsNativeOnlyKind, |
| 409 "is_any_handle_kind": mojom.IsAnyHandleKind, | 447 "is_any_handle_kind": mojom.IsAnyHandleKind, |
| 410 "is_interface_kind": mojom.IsInterfaceKind, | 448 "is_interface_kind": mojom.IsInterfaceKind, |
| 411 "is_interface_request_kind": mojom.IsInterfaceRequestKind, | 449 "is_interface_request_kind": mojom.IsInterfaceRequestKind, |
| 412 "is_associated_interface_kind": mojom.IsAssociatedInterfaceKind, | 450 "is_associated_interface_kind": mojom.IsAssociatedInterfaceKind, |
| 413 "is_associated_interface_request_kind": | 451 "is_associated_interface_request_kind": |
| 414 mojom.IsAssociatedInterfaceRequestKind, | 452 mojom.IsAssociatedInterfaceRequestKind, |
| 415 "is_associated_kind": mojom.IsAssociatedKind, | 453 "is_associated_kind": mojom.IsAssociatedKind, |
| 416 "is_map_kind": mojom.IsMapKind, | 454 "is_map_kind": mojom.IsMapKind, |
| 417 "is_nullable_kind": mojom.IsNullableKind, | 455 "is_nullable_kind": mojom.IsNullableKind, |
| 418 "is_object_kind": mojom.IsObjectKind, | 456 "is_object_kind": mojom.IsObjectKind, |
| 419 "is_string_kind": mojom.IsStringKind, | 457 "is_string_kind": mojom.IsStringKind, |
| 420 "is_struct_kind": mojom.IsStructKind, | 458 "is_struct_kind": mojom.IsStructKind, |
| 459 "is_typemapped_kind": IsTypemappedKind, |
| 421 "is_union_kind": mojom.IsUnionKind, | 460 "is_union_kind": mojom.IsUnionKind, |
| 422 "passes_associated_kinds": mojom.PassesAssociatedKinds, | 461 "passes_associated_kinds": mojom.PassesAssociatedKinds, |
| 423 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, | 462 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, |
| 424 "stylize_method": generator.StudlyCapsToCamel, | 463 "stylize_method": generator.StudlyCapsToCamel, |
| 425 "to_all_caps": generator.CamelCaseToAllCaps, | 464 "to_all_caps": generator.CamelCaseToAllCaps, |
| 426 "under_to_camel": generator.UnderToCamel, | 465 "under_to_camel": generator.UnderToCamel, |
| 427 } | 466 } |
| 428 | 467 |
| 468 def GetExtraHeaders(self): |
| 469 extra_headers = set() |
| 470 for name, entry in self.typemap.iteritems(): |
| 471 extra_headers.update(entry["headers"]) |
| 472 return list(extra_headers) |
| 473 |
| 429 def GetJinjaExports(self): | 474 def GetJinjaExports(self): |
| 430 return { | 475 return { |
| 431 "module": self.module, | 476 "module": self.module, |
| 432 "namespace": self.module.namespace, | 477 "namespace": self.module.namespace, |
| 433 "namespaces_as_array": NamespaceToArray(self.module.namespace), | 478 "namespaces_as_array": NamespaceToArray(self.module.namespace), |
| 434 "imports": self.module.imports, | 479 "imports": self.module.imports, |
| 435 "kinds": self.module.kinds, | 480 "kinds": self.module.kinds, |
| 436 "enums": self.module.enums, | 481 "enums": self.module.enums, |
| 437 "structs": self.GetStructs(), | 482 "structs": self.GetStructs(), |
| 438 "unions": self.GetUnions(), | 483 "unions": self.GetUnions(), |
| 439 "interfaces": self.GetInterfaces(), | 484 "interfaces": self.GetInterfaces(), |
| 440 "variant": self.variant, | 485 "variant": self.variant, |
| 486 "extra_headers": self.GetExtraHeaders(), |
| 441 } | 487 } |
| 442 | 488 |
| 443 @UseJinja("cpp_templates/module.h.tmpl", filters=cpp_filters) | 489 @UseJinja("cpp_templates/module.h.tmpl", filters=cpp_filters) |
| 444 def GenerateModuleHeader(self): | 490 def GenerateModuleHeader(self): |
| 445 return self.GetJinjaExports() | 491 return self.GetJinjaExports() |
| 446 | 492 |
| 447 @UseJinja("cpp_templates/module-internal.h.tmpl", filters=cpp_filters) | 493 @UseJinja("cpp_templates/module-internal.h.tmpl", filters=cpp_filters) |
| 448 def GenerateModuleInternalHeader(self): | 494 def GenerateModuleInternalHeader(self): |
| 449 return self.GetJinjaExports() | 495 return self.GetJinjaExports() |
| 450 | 496 |
| 451 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) | 497 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) |
| 452 def GenerateModuleSource(self): | 498 def GenerateModuleSource(self): |
| 453 return self.GetJinjaExports() | 499 return self.GetJinjaExports() |
| 454 | 500 |
| 455 def GenerateFiles(self, args): | 501 def GenerateFiles(self, args): |
| 502 global _current_typemap |
| 503 _current_typemap = self.typemap |
| 456 suffix = "-%s" % self.variant if self.variant else "" | 504 suffix = "-%s" % self.variant if self.variant else "" |
| 457 self.Write(self.GenerateModuleHeader(), | 505 self.Write(self.GenerateModuleHeader(), |
| 458 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 506 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 459 self.Write(self.GenerateModuleInternalHeader(), | 507 self.Write(self.GenerateModuleInternalHeader(), |
| 460 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 508 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 461 self.Write(self.GenerateModuleSource(), | 509 self.Write(self.GenerateModuleSource(), |
| 462 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 510 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |