Chromium Code Reviews| 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): |
|
yzshen1
2015/12/15 21:20:27
Do you need to also update this method?
| |
| 78 if mojom.IsArrayKind(kind): | 102 if mojom.IsArrayKind(kind): |
| 79 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) | 103 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) |
| 80 if mojom.IsMapKind(kind): | 104 if mojom.IsMapKind(kind): |
| 81 return "mojo::internal::Map_Data<%s, %s>*" % ( | 105 return "mojo::internal::Map_Data<%s, %s>*" % ( |
| 82 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) | 106 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) |
| 83 if mojom.IsStructKind(kind): | 107 if mojom.IsStructKind(kind): |
| 84 return "%s_Data*" % GetNameForKind(kind, internal=True) | 108 return "%s_Data*" % GetNameForKind(kind, internal=True) |
| 85 if mojom.IsUnionKind(kind): | 109 if mojom.IsUnionKind(kind): |
| 86 return "%s_Data" % GetNameForKind(kind, internal=True) | 110 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 87 if mojom.IsInterfaceKind(kind): | 111 if mojom.IsInterfaceKind(kind): |
| 88 return "mojo::internal::Interface_Data" | 112 return "mojo::internal::Interface_Data" |
| 89 if mojom.IsInterfaceRequestKind(kind): | 113 if mojom.IsInterfaceRequestKind(kind): |
| 90 return "mojo::MessagePipeHandle" | 114 return "mojo::MessagePipeHandle" |
| 91 if mojom.IsAssociatedInterfaceKind(kind): | 115 if mojom.IsAssociatedInterfaceKind(kind): |
| 92 return "mojo::internal::AssociatedInterface_Data" | 116 return "mojo::internal::AssociatedInterface_Data" |
| 93 if mojom.IsAssociatedInterfaceRequestKind(kind): | 117 if mojom.IsAssociatedInterfaceRequestKind(kind): |
| 94 return "mojo::internal::AssociatedInterfaceRequest_Data" | 118 return "mojo::internal::AssociatedInterfaceRequest_Data" |
| 95 if mojom.IsEnumKind(kind): | 119 if mojom.IsEnumKind(kind): |
| 96 return "int32_t" | 120 return "int32_t" |
| 97 if mojom.IsStringKind(kind): | 121 if mojom.IsStringKind(kind): |
| 98 return "mojo::internal::String_Data*" | 122 return "mojo::internal::String_Data*" |
| 99 return _kind_to_cpp_type[kind] | 123 return _kind_to_cpp_type[kind] |
| 100 | 124 |
| 101 def GetCppPodType(kind): | 125 def GetCppPodType(kind): |
| 102 if mojom.IsStringKind(kind): | 126 if mojom.IsStringKind(kind): |
| 103 return "char*" | 127 return "char*" |
| 104 return _kind_to_cpp_type[kind] | 128 return _kind_to_cpp_type[kind] |
| 105 | 129 |
| 106 def GetCppArrayArgWrapperType(kind): | 130 def GetCppArrayArgWrapperType(kind): |
|
yzshen1
2015/12/15 21:20:27
Do you need to also update this method?
| |
| 107 if mojom.IsEnumKind(kind): | 131 if mojom.IsEnumKind(kind): |
| 108 return GetNameForKind(kind) | 132 return GetNameForKind(kind) |
| 109 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 133 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 110 return "%sPtr" % GetNameForKind(kind) | 134 return "%sPtr" % GetNameForKind(kind) |
| 111 if mojom.IsArrayKind(kind): | 135 if mojom.IsArrayKind(kind): |
| 112 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) | 136 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) |
| 113 if mojom.IsMapKind(kind): | 137 if mojom.IsMapKind(kind): |
| 114 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), | 138 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), |
| 115 GetCppArrayArgWrapperType(kind.value_kind)) | 139 GetCppArrayArgWrapperType(kind.value_kind)) |
| 116 if mojom.IsInterfaceKind(kind): | 140 if mojom.IsInterfaceKind(kind): |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 130 return "mojo::ScopedDataPipeConsumerHandle" | 154 return "mojo::ScopedDataPipeConsumerHandle" |
| 131 if mojom.IsDataPipeProducerKind(kind): | 155 if mojom.IsDataPipeProducerKind(kind): |
| 132 return "mojo::ScopedDataPipeProducerHandle" | 156 return "mojo::ScopedDataPipeProducerHandle" |
| 133 if mojom.IsMessagePipeKind(kind): | 157 if mojom.IsMessagePipeKind(kind): |
| 134 return "mojo::ScopedMessagePipeHandle" | 158 return "mojo::ScopedMessagePipeHandle" |
| 135 if mojom.IsSharedBufferKind(kind): | 159 if mojom.IsSharedBufferKind(kind): |
| 136 return "mojo::ScopedSharedBufferHandle" | 160 return "mojo::ScopedSharedBufferHandle" |
| 137 return _kind_to_cpp_type[kind] | 161 return _kind_to_cpp_type[kind] |
| 138 | 162 |
| 139 def GetCppResultWrapperType(kind): | 163 def GetCppResultWrapperType(kind): |
| 164 if IsTypemappedKind(kind): | |
| 165 return "const %s&" % GetNativeTypeName(kind) | |
| 140 if mojom.IsEnumKind(kind): | 166 if mojom.IsEnumKind(kind): |
| 141 return GetNameForKind(kind) | 167 return GetNameForKind(kind) |
| 142 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 168 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 143 return "%sPtr" % GetNameForKind(kind) | 169 return "%sPtr" % GetNameForKind(kind) |
| 144 if mojom.IsArrayKind(kind): | 170 if mojom.IsArrayKind(kind): |
| 145 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 171 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 146 if mojom.IsMapKind(kind): | 172 if mojom.IsMapKind(kind): |
| 147 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 173 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 148 GetCppArrayArgWrapperType(kind.value_kind)) | 174 GetCppArrayArgWrapperType(kind.value_kind)) |
| 149 if mojom.IsInterfaceKind(kind): | 175 if mojom.IsInterfaceKind(kind): |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 168 return "mojo::ScopedSharedBufferHandle" | 194 return "mojo::ScopedSharedBufferHandle" |
| 169 # TODO(rudominer) After improvements to compiler front end have landed, | 195 # TODO(rudominer) After improvements to compiler front end have landed, |
| 170 # revisit strategy used below for emitting a useful error message when an | 196 # revisit strategy used below for emitting a useful error message when an |
| 171 # undefined identifier is referenced. | 197 # undefined identifier is referenced. |
| 172 val = _kind_to_cpp_type.get(kind) | 198 val = _kind_to_cpp_type.get(kind) |
| 173 if (val is not None): | 199 if (val is not None): |
| 174 return val | 200 return val |
| 175 raise Exception("Unrecognized kind %s" % kind.spec) | 201 raise Exception("Unrecognized kind %s" % kind.spec) |
| 176 | 202 |
| 177 def GetCppWrapperType(kind): | 203 def GetCppWrapperType(kind): |
| 204 if IsTypemappedKind(kind): | |
| 205 return GetNativeTypeName(kind) | |
| 178 if mojom.IsEnumKind(kind): | 206 if mojom.IsEnumKind(kind): |
| 179 return GetNameForKind(kind) | 207 return GetNameForKind(kind) |
| 180 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 208 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 181 return "%sPtr" % GetNameForKind(kind) | 209 return "%sPtr" % GetNameForKind(kind) |
| 182 if mojom.IsArrayKind(kind): | 210 if mojom.IsArrayKind(kind): |
| 183 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 211 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 184 if mojom.IsMapKind(kind): | 212 if mojom.IsMapKind(kind): |
| 185 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 213 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 186 GetCppArrayArgWrapperType(kind.value_kind)) | 214 GetCppArrayArgWrapperType(kind.value_kind)) |
| 187 if mojom.IsInterfaceKind(kind): | 215 if mojom.IsInterfaceKind(kind): |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 200 return "mojo::ScopedDataPipeConsumerHandle" | 228 return "mojo::ScopedDataPipeConsumerHandle" |
| 201 if mojom.IsDataPipeProducerKind(kind): | 229 if mojom.IsDataPipeProducerKind(kind): |
| 202 return "mojo::ScopedDataPipeProducerHandle" | 230 return "mojo::ScopedDataPipeProducerHandle" |
| 203 if mojom.IsMessagePipeKind(kind): | 231 if mojom.IsMessagePipeKind(kind): |
| 204 return "mojo::ScopedMessagePipeHandle" | 232 return "mojo::ScopedMessagePipeHandle" |
| 205 if mojom.IsSharedBufferKind(kind): | 233 if mojom.IsSharedBufferKind(kind): |
| 206 return "mojo::ScopedSharedBufferHandle" | 234 return "mojo::ScopedSharedBufferHandle" |
| 207 return _kind_to_cpp_type[kind] | 235 return _kind_to_cpp_type[kind] |
| 208 | 236 |
| 209 def GetCppConstWrapperType(kind): | 237 def GetCppConstWrapperType(kind): |
| 238 if IsTypemappedKind(kind): | |
| 239 return "const %s&" % GetNativeTypeName(kind) | |
| 210 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 240 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 211 return "%sPtr" % GetNameForKind(kind) | 241 return "%sPtr" % GetNameForKind(kind) |
| 212 if mojom.IsArrayKind(kind): | 242 if mojom.IsArrayKind(kind): |
| 213 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 243 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 214 if mojom.IsMapKind(kind): | 244 if mojom.IsMapKind(kind): |
| 215 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 245 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 216 GetCppArrayArgWrapperType(kind.value_kind)) | 246 GetCppArrayArgWrapperType(kind.value_kind)) |
| 217 if mojom.IsInterfaceKind(kind): | 247 if mojom.IsInterfaceKind(kind): |
| 218 return "%sPtr" % GetNameForKind(kind) | 248 return "%sPtr" % GetNameForKind(kind) |
| 219 if mojom.IsInterfaceRequestKind(kind): | 249 if mojom.IsInterfaceRequestKind(kind): |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 234 return "mojo::ScopedDataPipeProducerHandle" | 264 return "mojo::ScopedDataPipeProducerHandle" |
| 235 if mojom.IsMessagePipeKind(kind): | 265 if mojom.IsMessagePipeKind(kind): |
| 236 return "mojo::ScopedMessagePipeHandle" | 266 return "mojo::ScopedMessagePipeHandle" |
| 237 if mojom.IsSharedBufferKind(kind): | 267 if mojom.IsSharedBufferKind(kind): |
| 238 return "mojo::ScopedSharedBufferHandle" | 268 return "mojo::ScopedSharedBufferHandle" |
| 239 if not kind in _kind_to_cpp_type: | 269 if not kind in _kind_to_cpp_type: |
| 240 print "missing:", kind.spec | 270 print "missing:", kind.spec |
| 241 return _kind_to_cpp_type[kind] | 271 return _kind_to_cpp_type[kind] |
| 242 | 272 |
| 243 def GetCppFieldType(kind): | 273 def GetCppFieldType(kind): |
| 274 if IsNativeOnlyKind(kind): | |
| 275 return "mojo::internal::NativePointer" | |
| 244 if mojom.IsStructKind(kind): | 276 if mojom.IsStructKind(kind): |
| 245 return ("mojo::internal::StructPointer<%s_Data>" % | 277 return ("mojo::internal::StructPointer<%s_Data>" % |
| 246 GetNameForKind(kind, internal=True)) | 278 GetNameForKind(kind, internal=True)) |
| 247 if mojom.IsUnionKind(kind): | 279 if mojom.IsUnionKind(kind): |
| 248 return "%s_Data" % GetNameForKind(kind, internal=True) | 280 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 249 if mojom.IsArrayKind(kind): | 281 if mojom.IsArrayKind(kind): |
| 250 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) | 282 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) |
| 251 if mojom.IsMapKind(kind): | 283 if mojom.IsMapKind(kind): |
| 252 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % | 284 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % |
| 253 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) | 285 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 "get_pad": pack.GetPad, | 431 "get_pad": pack.GetPad, |
| 400 "get_qualified_name_for_kind": GetQualifiedNameForKind, | 432 "get_qualified_name_for_kind": GetQualifiedNameForKind, |
| 401 "has_callbacks": mojom.HasCallbacks, | 433 "has_callbacks": mojom.HasCallbacks, |
| 402 "should_inline": ShouldInlineStruct, | 434 "should_inline": ShouldInlineStruct, |
| 403 "should_inline_union": ShouldInlineUnion, | 435 "should_inline_union": ShouldInlineUnion, |
| 404 "is_array_kind": mojom.IsArrayKind, | 436 "is_array_kind": mojom.IsArrayKind, |
| 405 "is_cloneable_kind": mojom.IsCloneableKind, | 437 "is_cloneable_kind": mojom.IsCloneableKind, |
| 406 "is_enum_kind": mojom.IsEnumKind, | 438 "is_enum_kind": mojom.IsEnumKind, |
| 407 "is_integral_kind": mojom.IsIntegralKind, | 439 "is_integral_kind": mojom.IsIntegralKind, |
| 408 "is_move_only_kind": mojom.IsMoveOnlyKind, | 440 "is_move_only_kind": mojom.IsMoveOnlyKind, |
| 441 "is_native_only_kind": IsNativeOnlyKind, | |
| 409 "is_any_handle_kind": mojom.IsAnyHandleKind, | 442 "is_any_handle_kind": mojom.IsAnyHandleKind, |
| 410 "is_interface_kind": mojom.IsInterfaceKind, | 443 "is_interface_kind": mojom.IsInterfaceKind, |
| 411 "is_interface_request_kind": mojom.IsInterfaceRequestKind, | 444 "is_interface_request_kind": mojom.IsInterfaceRequestKind, |
| 412 "is_associated_interface_kind": mojom.IsAssociatedInterfaceKind, | 445 "is_associated_interface_kind": mojom.IsAssociatedInterfaceKind, |
| 413 "is_associated_interface_request_kind": | 446 "is_associated_interface_request_kind": |
| 414 mojom.IsAssociatedInterfaceRequestKind, | 447 mojom.IsAssociatedInterfaceRequestKind, |
| 415 "is_associated_kind": mojom.IsAssociatedKind, | 448 "is_associated_kind": mojom.IsAssociatedKind, |
| 416 "is_map_kind": mojom.IsMapKind, | 449 "is_map_kind": mojom.IsMapKind, |
| 417 "is_nullable_kind": mojom.IsNullableKind, | 450 "is_nullable_kind": mojom.IsNullableKind, |
| 418 "is_object_kind": mojom.IsObjectKind, | 451 "is_object_kind": mojom.IsObjectKind, |
| 419 "is_string_kind": mojom.IsStringKind, | 452 "is_string_kind": mojom.IsStringKind, |
| 420 "is_struct_kind": mojom.IsStructKind, | 453 "is_struct_kind": mojom.IsStructKind, |
| 454 "is_typemapped_kind": IsTypemappedKind, | |
| 421 "is_union_kind": mojom.IsUnionKind, | 455 "is_union_kind": mojom.IsUnionKind, |
| 422 "passes_associated_kinds": mojom.PassesAssociatedKinds, | 456 "passes_associated_kinds": mojom.PassesAssociatedKinds, |
| 423 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, | 457 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, |
| 424 "stylize_method": generator.StudlyCapsToCamel, | 458 "stylize_method": generator.StudlyCapsToCamel, |
| 425 "to_all_caps": generator.CamelCaseToAllCaps, | 459 "to_all_caps": generator.CamelCaseToAllCaps, |
| 426 "under_to_camel": generator.UnderToCamel, | 460 "under_to_camel": generator.UnderToCamel, |
| 427 } | 461 } |
| 428 | 462 |
| 463 def GetExtraHeaders(self): | |
| 464 extra_headers = set() | |
| 465 for name, entry in self.typemap.iteritems(): | |
| 466 extra_headers.update(entry["headers"]) | |
| 467 return list(extra_headers) | |
| 468 | |
| 429 def GetJinjaExports(self): | 469 def GetJinjaExports(self): |
| 430 return { | 470 return { |
| 431 "module": self.module, | 471 "module": self.module, |
| 432 "namespace": self.module.namespace, | 472 "namespace": self.module.namespace, |
| 433 "namespaces_as_array": NamespaceToArray(self.module.namespace), | 473 "namespaces_as_array": NamespaceToArray(self.module.namespace), |
| 434 "imports": self.module.imports, | 474 "imports": self.module.imports, |
| 435 "kinds": self.module.kinds, | 475 "kinds": self.module.kinds, |
| 436 "enums": self.module.enums, | 476 "enums": self.module.enums, |
| 437 "structs": self.GetStructs(), | 477 "structs": self.GetStructs(), |
| 438 "unions": self.GetUnions(), | 478 "unions": self.GetUnions(), |
| 439 "interfaces": self.GetInterfaces(), | 479 "interfaces": self.GetInterfaces(), |
| 440 "variant": self.variant, | 480 "variant": self.variant, |
| 481 "extra_headers": self.GetExtraHeaders(), | |
| 441 } | 482 } |
| 442 | 483 |
| 443 @UseJinja("cpp_templates/module.h.tmpl", filters=cpp_filters) | 484 @UseJinja("cpp_templates/module.h.tmpl", filters=cpp_filters) |
| 444 def GenerateModuleHeader(self): | 485 def GenerateModuleHeader(self): |
| 445 return self.GetJinjaExports() | 486 return self.GetJinjaExports() |
| 446 | 487 |
| 447 @UseJinja("cpp_templates/module-internal.h.tmpl", filters=cpp_filters) | 488 @UseJinja("cpp_templates/module-internal.h.tmpl", filters=cpp_filters) |
| 448 def GenerateModuleInternalHeader(self): | 489 def GenerateModuleInternalHeader(self): |
| 449 return self.GetJinjaExports() | 490 return self.GetJinjaExports() |
| 450 | 491 |
| 451 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) | 492 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) |
| 452 def GenerateModuleSource(self): | 493 def GenerateModuleSource(self): |
| 453 return self.GetJinjaExports() | 494 return self.GetJinjaExports() |
| 454 | 495 |
| 455 def GenerateFiles(self, args): | 496 def GenerateFiles(self, args): |
| 497 global _current_typemap | |
| 498 _current_typemap = self.typemap | |
| 456 suffix = "-%s" % self.variant if self.variant else "" | 499 suffix = "-%s" % self.variant if self.variant else "" |
| 457 self.Write(self.GenerateModuleHeader(), | 500 self.Write(self.GenerateModuleHeader(), |
| 458 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 501 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 459 self.Write(self.GenerateModuleInternalHeader(), | 502 self.Write(self.GenerateModuleInternalHeader(), |
| 460 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 503 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 461 self.Write(self.GenerateModuleSource(), | 504 self.Write(self.GenerateModuleSource(), |
| 462 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 505 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |