OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 from code import Code | 5 from code import Code |
6 from model import PropertyType | 6 from model import PropertyType |
7 import cpp_util | 7 import cpp_util |
8 import schema_util | 8 import schema_util |
9 import util_cc_helper | 9 import util_cc_helper |
10 from cpp_namespace_environment import CppNamespaceEnvironment | 10 from cpp_namespace_environment import CppNamespaceEnvironment |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 elif underlying_type.property_type == PropertyType.ARRAY: | 643 elif underlying_type.property_type == PropertyType.ARRAY: |
644 return '%s' % self._util_cc_helper.CreateValueFromArray( | 644 return '%s' % self._util_cc_helper.CreateValueFromArray( |
645 var, | 645 var, |
646 is_ptr) | 646 is_ptr) |
647 elif underlying_type.property_type.is_fundamental: | 647 elif underlying_type.property_type.is_fundamental: |
648 if is_ptr: | 648 if is_ptr: |
649 var = '*%s' % var | 649 var = '*%s' % var |
650 if underlying_type.property_type == PropertyType.STRING: | 650 if underlying_type.property_type == PropertyType.STRING: |
651 return 'base::MakeUnique<base::StringValue>(%s)' % var | 651 return 'base::MakeUnique<base::StringValue>(%s)' % var |
652 else: | 652 else: |
653 return 'base::MakeUnique<base::FundamentalValue>(%s)' % var | 653 return 'base::MakeUnique<base::Value>(%s)' % var |
654 else: | 654 else: |
655 raise NotImplementedError('Conversion of %s to base::Value not ' | 655 raise NotImplementedError('Conversion of %s to base::Value not ' |
656 'implemented' % repr(type_.type_)) | 656 'implemented' % repr(type_.type_)) |
657 | 657 |
658 def _GenerateParamsCheck(self, function, var): | 658 def _GenerateParamsCheck(self, function, var): |
659 """Generates a check for the correct number of arguments when creating | 659 """Generates a check for the correct number of arguments when creating |
660 Params. | 660 Params. |
661 """ | 661 """ |
662 c = Code() | 662 c = Code() |
663 num_required = 0 | 663 num_required = 0 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 code, if |dst_var| fails to be populated then Populate will return | 759 code, if |dst_var| fails to be populated then Populate will return |
760 |failure_value|. | 760 |failure_value|. |
761 """ | 761 """ |
762 c = Code() | 762 c = Code() |
763 | 763 |
764 underlying_type = self._type_helper.FollowRef(type_) | 764 underlying_type = self._type_helper.FollowRef(type_) |
765 | 765 |
766 if underlying_type.property_type.is_fundamental: | 766 if underlying_type.property_type.is_fundamental: |
767 if is_ptr: | 767 if is_ptr: |
768 (c.Append('%(cpp_type)s temp;') | 768 (c.Append('%(cpp_type)s temp;') |
769 .Sblock('if (!%s) {' % cpp_util.GetAsFundamentalValue( | 769 .Sblock('if (!%s) {' % cpp_util.GetAsValue( |
770 self._type_helper.FollowRef(type_), src_var, '&temp')) | 770 self._type_helper.FollowRef(type_), src_var, '&temp')) |
771 .Concat(self._GenerateError( | 771 .Concat(self._GenerateError( |
772 '"\'%%(key)s\': expected ' + '%s, got " + %s' % ( | 772 '"\'%%(key)s\': expected ' + '%s, got " + %s' % ( |
773 type_.name, | 773 type_.name, |
774 self._util_cc_helper.GetValueTypeString( | 774 self._util_cc_helper.GetValueTypeString( |
775 '%%(src_var)s', True))))) | 775 '%%(src_var)s', True))))) |
776 c.Append('%(dst_var)s.reset();') | 776 c.Append('%(dst_var)s.reset();') |
777 if not self._generate_error_messages: | 777 if not self._generate_error_messages: |
778 c.Append('return %(failure_value)s;') | 778 c.Append('return %(failure_value)s;') |
779 (c.Eblock('}') | 779 (c.Eblock('}') |
780 .Append('else') | 780 .Append('else') |
781 .Append(' %(dst_var)s.reset(new %(cpp_type)s(temp));') | 781 .Append(' %(dst_var)s.reset(new %(cpp_type)s(temp));') |
782 ) | 782 ) |
783 else: | 783 else: |
784 (c.Sblock('if (!%s) {' % cpp_util.GetAsFundamentalValue( | 784 (c.Sblock('if (!%s) {' % cpp_util.GetAsValue( |
785 self._type_helper.FollowRef(type_), | 785 self._type_helper.FollowRef(type_), |
786 src_var, | 786 src_var, |
787 '&%s' % dst_var)) | 787 '&%s' % dst_var)) |
788 .Concat(self._GenerateError( | 788 .Concat(self._GenerateError( |
789 '"\'%%(key)s\': expected ' + '%s, got " + %s' % ( | 789 '"\'%%(key)s\': expected ' + '%s, got " + %s' % ( |
790 type_.name, | 790 type_.name, |
791 self._util_cc_helper.GetValueTypeString( | 791 self._util_cc_helper.GetValueTypeString( |
792 '%%(src_var)s', True)))) | 792 '%%(src_var)s', True)))) |
793 .Append('return %(failure_value)s;') | 793 .Append('return %(failure_value)s;') |
794 .Eblock('}') | 794 .Eblock('}') |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 if self._generate_error_messages: | 1150 if self._generate_error_messages: |
1151 params = list(params) + ['base::string16* error'] | 1151 params = list(params) + ['base::string16* error'] |
1152 return ', '.join(str(p) for p in params) | 1152 return ', '.join(str(p) for p in params) |
1153 | 1153 |
1154 def _GenerateArgs(self, args): | 1154 def _GenerateArgs(self, args): |
1155 """Builds the argument list for a function, given an array of arguments. | 1155 """Builds the argument list for a function, given an array of arguments. |
1156 """ | 1156 """ |
1157 if self._generate_error_messages: | 1157 if self._generate_error_messages: |
1158 args = list(args) + ['error'] | 1158 args = list(args) + ['error'] |
1159 return ', '.join(str(a) for a in args) | 1159 return ', '.join(str(a) for a in args) |
OLD | NEW |