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