| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if mojom.IsStructKind(kind) and kind.native_only: | 77 if mojom.IsStructKind(kind) and kind.native_only: |
| 78 return "mojo::Array_Data<uint8_t>" | 78 return "mojo::Array_Data<uint8_t>" |
| 79 if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind) or | 79 if (mojom.IsStructKind(kind) or mojom.IsUnionKind(kind) or |
| 80 mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind)): | 80 mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind)): |
| 81 return kind.name + "_Data" | 81 return kind.name + "_Data" |
| 82 return kind.name | 82 return kind.name |
| 83 | 83 |
| 84 parts = [] | 84 parts = [] |
| 85 if kind.imported_from: | 85 if kind.imported_from: |
| 86 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) | 86 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) |
| 87 if _variant and add_variant: |
| 88 parts.append(_variant) |
| 87 elif add_same_module_namespaces: | 89 elif add_same_module_namespaces: |
| 88 if hasattr(kind, "module"): | 90 if hasattr(kind, "module"): |
| 89 parts.extend(NamespaceToArray(kind.module.namespace)) | 91 parts.extend(NamespaceToArray(kind.module.namespace)) |
| 90 if _variant and add_variant: | 92 if _variant and add_variant: |
| 91 parts.append(_variant) | 93 parts.append(_variant) |
| 92 if internal: | 94 if internal: |
| 93 parts.append("internal") | 95 parts.append("internal") |
| 94 if kind.parent_kind: | 96 if kind.parent_kind: |
| 95 parts.append(MapKindName_(kind.parent_kind)) | 97 parts.append(MapKindName_(kind.parent_kind)) |
| 96 parts.append(MapKindName_(kind)) | 98 parts.append(MapKindName_(kind)) |
| 97 return parts | 99 return parts |
| 98 | 100 |
| 99 def GetNameForKind(kind, internal=False): | 101 def GetNameForKind(kind, internal=False): |
| 100 parts = GetNamePartsForKind(kind, False, False, internal) | 102 parts = GetNamePartsForKind(kind, False, True, internal) |
| 101 return "::".join(parts) | 103 return "::".join(parts) |
| 102 | 104 |
| 103 def GetQualifiedNameForKind(kind, internal=False): | 105 def GetQualifiedNameForKind(kind, internal=False): |
| 104 # Always start with an empty part to force a leading "::" on output. | 106 # Always start with an empty part to force a leading "::" on output. |
| 105 parts = [""] | 107 parts = [""] |
| 106 parts.extend(GetNamePartsForKind(kind, True, True, internal)) | 108 parts.extend(GetNamePartsForKind(kind, True, True, internal)) |
| 107 return "::".join(parts) | 109 return "::".join(parts) |
| 108 | 110 |
| 109 def GetFullMojomNameForKind(kind): | 111 def GetFullMojomNameForKind(kind): |
| 110 parts = GetNamePartsForKind(kind, True, False, False) | 112 parts = GetNamePartsForKind(kind, True, False, False) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 return GetCppResultWrapperType(kind) | 377 return GetCppResultWrapperType(kind) |
| 376 | 378 |
| 377 def TranslateConstants(token, kind): | 379 def TranslateConstants(token, kind): |
| 378 if isinstance(token, mojom.NamedValue): | 380 if isinstance(token, mojom.NamedValue): |
| 379 # Both variable and enum constants are constructed like: | 381 # Both variable and enum constants are constructed like: |
| 380 # Namespace::Struct::CONSTANT_NAME | 382 # Namespace::Struct::CONSTANT_NAME |
| 381 # For enums, CONSTANT_NAME is ENUM_NAME_ENUM_VALUE. | 383 # For enums, CONSTANT_NAME is ENUM_NAME_ENUM_VALUE. |
| 382 name = [] | 384 name = [] |
| 383 if token.imported_from: | 385 if token.imported_from: |
| 384 name.extend(NamespaceToArray(token.namespace)) | 386 name.extend(NamespaceToArray(token.namespace)) |
| 387 if _variant: |
| 388 name.append(_variant) |
| 385 if token.parent_kind: | 389 if token.parent_kind: |
| 386 name.append(token.parent_kind.name) | 390 name.append(token.parent_kind.name) |
| 387 if isinstance(token, mojom.EnumValue): | 391 if isinstance(token, mojom.EnumValue): |
| 388 name.extend([token.enum.name, token.name]) | 392 name.extend([token.enum.name, token.name]) |
| 389 else: | 393 else: |
| 390 name.append(token.name) | 394 name.append(token.name) |
| 391 return "::".join(name) | 395 return "::".join(name) |
| 392 | 396 |
| 393 if isinstance(token, mojom.BuiltinValue): | 397 if isinstance(token, mojom.BuiltinValue): |
| 394 if token.value == "double.INFINITY" or token.value == "float.INFINITY": | 398 if token.value == "double.INFINITY" or token.value == "float.INFINITY": |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 _for_blink = self.for_blink | 572 _for_blink = self.for_blink |
| 569 global _variant | 573 global _variant |
| 570 _variant = self.variant | 574 _variant = self.variant |
| 571 suffix = "-%s" % self.variant if self.variant else "" | 575 suffix = "-%s" % self.variant if self.variant else "" |
| 572 self.Write(self.GenerateModuleHeader(), | 576 self.Write(self.GenerateModuleHeader(), |
| 573 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 577 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 574 self.Write(self.GenerateModuleInternalHeader(), | 578 self.Write(self.GenerateModuleInternalHeader(), |
| 575 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 579 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 576 self.Write(self.GenerateModuleSource(), | 580 self.Write(self.GenerateModuleSource(), |
| 577 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 581 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |