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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 for field in struct.fields: | 475 for field in struct.fields: |
| 476 if IsMoveOnlyKind(field.kind): | 476 if IsMoveOnlyKind(field.kind): |
| 477 return True | 477 return True |
| 478 return False | 478 return False |
| 479 | 479 |
| 480 def ShouldInlineUnion(union): | 480 def ShouldInlineUnion(union): |
| 481 return not any( | 481 return not any( |
| 482 mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind) | 482 mojom.IsReferenceKind(field.kind) and not mojom.IsStringKind(field.kind) |
| 483 for field in union.fields) | 483 for field in union.fields) |
| 484 | 484 |
| 485 | |
| 486 def GetNumConstructorParams(kind): | |
| 487 for i, field in enumerate(kind.fields): | |
| 488 # mojo.common.mojom.LegacyListValue is neither copyable nor movable so can't | |
|
yzshen1
2017/02/13 17:45:53
It is unfortunate to have a special case for this.
Sam McNally
2017/02/14 02:32:24
Done.
| |
| 489 # be passed to a struct constructor so any constructors containing this | |
| 490 # struct are skipped. | |
| 491 if (mojom.IsStructKind(field.kind) and GetFullMojomNameForKind( | |
| 492 field.kind) == "mojo.common.mojom.LegacyListValue"): | |
| 493 return i | |
| 494 return len(kind.fields) + 1 | |
| 495 | |
| 496 | |
| 485 def GetContainerValidateParamsCtorArgs(kind): | 497 def GetContainerValidateParamsCtorArgs(kind): |
| 486 if mojom.IsStringKind(kind): | 498 if mojom.IsStringKind(kind): |
| 487 expected_num_elements = 0 | 499 expected_num_elements = 0 |
| 488 element_is_nullable = False | 500 element_is_nullable = False |
| 489 key_validate_params = "nullptr" | 501 key_validate_params = "nullptr" |
| 490 element_validate_params = "nullptr" | 502 element_validate_params = "nullptr" |
| 491 enum_validate_func = "nullptr" | 503 enum_validate_func = "nullptr" |
| 492 elif mojom.IsMapKind(kind): | 504 elif mojom.IsMapKind(kind): |
| 493 expected_num_elements = 0 | 505 expected_num_elements = 0 |
| 494 element_is_nullable = False | 506 element_is_nullable = False |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 "is_associated_kind": mojom.IsAssociatedKind, | 576 "is_associated_kind": mojom.IsAssociatedKind, |
| 565 "is_hashable": IsHashableKind, | 577 "is_hashable": IsHashableKind, |
| 566 "is_map_kind": mojom.IsMapKind, | 578 "is_map_kind": mojom.IsMapKind, |
| 567 "is_nullable_kind": mojom.IsNullableKind, | 579 "is_nullable_kind": mojom.IsNullableKind, |
| 568 "is_object_kind": mojom.IsObjectKind, | 580 "is_object_kind": mojom.IsObjectKind, |
| 569 "is_reference_kind": mojom.IsReferenceKind, | 581 "is_reference_kind": mojom.IsReferenceKind, |
| 570 "is_string_kind": mojom.IsStringKind, | 582 "is_string_kind": mojom.IsStringKind, |
| 571 "is_struct_kind": mojom.IsStructKind, | 583 "is_struct_kind": mojom.IsStructKind, |
| 572 "is_typemapped_kind": IsTypemappedKind, | 584 "is_typemapped_kind": IsTypemappedKind, |
| 573 "is_union_kind": mojom.IsUnionKind, | 585 "is_union_kind": mojom.IsUnionKind, |
| 586 "num_constructor_params": GetNumConstructorParams, | |
| 574 "passes_associated_kinds": mojom.PassesAssociatedKinds, | 587 "passes_associated_kinds": mojom.PassesAssociatedKinds, |
| 575 "stylize_method": generator.StudlyCapsToCamel, | 588 "stylize_method": generator.StudlyCapsToCamel, |
| 576 "under_to_camel": generator.UnderToCamel, | 589 "under_to_camel": generator.UnderToCamel, |
| 577 "unmapped_type_for_serializer": GetUnmappedTypeForSerializer, | 590 "unmapped_type_for_serializer": GetUnmappedTypeForSerializer, |
| 578 } | 591 } |
| 579 | 592 |
| 580 def GetExtraTraitsHeaders(self): | 593 def GetExtraTraitsHeaders(self): |
| 581 extra_headers = set() | 594 extra_headers = set() |
| 582 for typemap in self._GetAllUsedTypemaps(): | 595 for typemap in self._GetAllUsedTypemaps(): |
| 583 extra_headers.update(typemap.get("traits_headers", [])) | 596 extra_headers.update(typemap.get("traits_headers", [])) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 729 global _use_once_callback | 742 global _use_once_callback |
| 730 _use_once_callback = self.use_once_callback | 743 _use_once_callback = self.use_once_callback |
| 731 global _variant | 744 global _variant |
| 732 _variant = self.variant | 745 _variant = self.variant |
| 733 suffix = "-%s" % self.variant if self.variant else "" | 746 suffix = "-%s" % self.variant if self.variant else "" |
| 734 self.Write(self.GenerateModuleHeader(), | 747 self.Write(self.GenerateModuleHeader(), |
| 735 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 748 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 736 self.Write( | 749 self.Write( |
| 737 self.GenerateModuleSource(), | 750 self.GenerateModuleSource(), |
| 738 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 751 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |