Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Side by Side Diff: tools/json_schema_compiler/cc_generator.py

Issue 197873009: Support scoped types in PPAPI IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/generators/idl_parser.py ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 ) 679 )
680 if is_ptr and self._generate_error_messages: 680 if is_ptr and self._generate_error_messages:
681 c.Append('%(dst_var)s.reset();') 681 c.Append('%(dst_var)s.reset();')
682 else: 682 else:
683 c.Append('return %(failure_value)s;') 683 c.Append('return %(failure_value)s;')
684 c.Eblock('}') 684 c.Eblock('}')
685 c.Sblock('else {') 685 c.Sblock('else {')
686 item_type = self._type_helper.FollowRef(underlying_type.item_type) 686 item_type = self._type_helper.FollowRef(underlying_type.item_type)
687 if item_type.property_type == PropertyType.ENUM: 687 if item_type.property_type == PropertyType.ENUM:
688 c.Concat(self._GenerateListValueToEnumArrayConversion( 688 c.Concat(self._GenerateListValueToEnumArrayConversion(
689 item_type, 689 underlying_type.item_type,
690 'list', 690 'list',
691 dst_var, 691 dst_var,
692 failure_value, 692 failure_value,
693 is_ptr=is_ptr)) 693 is_ptr=is_ptr))
694 else: 694 else:
695 (c.Sblock('if (!%s) {' % self._util_cc_helper.PopulateArrayFromList( 695 (c.Sblock('if (!%s) {' % self._util_cc_helper.PopulateArrayFromList(
696 underlying_type, 696 underlying_type,
697 'list', 697 'list',
698 dst_var, 698 dst_var,
699 is_ptr))) 699 is_ptr)))
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 .Concat(self._GenerateStringToEnumConversion(item_type, 782 .Concat(self._GenerateStringToEnumConversion(item_type,
783 '(*it)', 783 '(*it)',
784 'tmp', 784 'tmp',
785 failure_value)) 785 failure_value))
786 .Append('%s%spush_back(tmp);' % (dst_var, accessor)) 786 .Append('%s%spush_back(tmp);' % (dst_var, accessor))
787 .Eblock('}') 787 .Eblock('}')
788 ) 788 )
789 return c 789 return c
790 790
791 def _GenerateStringToEnumConversion(self, 791 def _GenerateStringToEnumConversion(self,
792 type_, 792 type_,
not at google - send to devlin 2014/03/31 15:18:59 can you just pass in the correct underlying type h
mtomasz 2014/04/03 21:50:22 Done.
793 src_var, 793 src_var,
794 dst_var, 794 dst_var,
795 failure_value): 795 failure_value):
796 """Returns Code that converts a string type in |src_var| to an enum with 796 """Returns Code that converts a string type in |src_var| to an enum with
797 type |type_| in |dst_var|. In the generated code, if |src_var| is not 797 type |type_| in |dst_var|. In the generated code, if |src_var| is not
798 a valid enum name then the function will return |failure_value|. 798 a valid enum name then the function will return |failure_value|.
799 """ 799 """
800 c = Code() 800 c = Code()
801 enum_as_string = '%s_as_string' % type_.unix_name 801 enum_as_string = '%s_as_string' % type_.unix_name
802 cpp_type_fullname = self._type_helper.GetCppType(type_)
not at google - send to devlin 2014/03/31 15:18:59 this isn't used
mtomasz 2014/04/03 21:50:22 Done.
803 # The passed type may be either of REF type, or directly ENUM. Note, that
804 # the second case is used only by JSON.
805 enum_type = (type_ if type_.property_type == PropertyType.ENUM else
not at google - send to devlin 2014/03/31 15:18:59 see comment above, note that FollowRef does this c
mtomasz 2014/04/03 21:50:22 Done.
806 self._type_helper.FollowRef(type_))
807 cpp_type_namespace = (enum_type.namespace.unix_name
not at google - send to devlin 2014/03/31 15:18:59 if you make sure this includes the '::' then that
Nils Barth (inactive) 2014/04/01 01:39:16 BTW, as a style point, an alternative style is sin
not at google - send to devlin 2014/04/01 01:40:25 I don't mind either way.
mtomasz 2014/04/03 21:50:22 Done.
808 if enum_type.namespace != self._namespace else '')
809 cpp_type_name = self._type_helper.GetCppType(enum_type)
not at google - send to devlin 2014/03/31 15:18:59 if you go back to inlining this, and implement the
mtomasz 2014/04/03 21:50:22 Done.
802 (c.Append('std::string %s;' % enum_as_string) 810 (c.Append('std::string %s;' % enum_as_string)
803 .Sblock('if (!%s->GetAsString(&%s)) {' % (src_var, enum_as_string)) 811 .Sblock('if (!%s->GetAsString(&%s)) {' % (src_var, enum_as_string))
804 .Concat(self._GenerateError( 812 .Concat(self._GenerateError(
805 '"\'%%(key)s\': expected string, got " + ' + 813 '"\'%%(key)s\': expected string, got " + ' +
806 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) 814 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True)))
807 .Append('return %s;' % failure_value) 815 .Append('return %s;' % failure_value)
808 .Eblock('}') 816 .Eblock('}')
809 .Append('%s = Parse%s(%s);' % (dst_var, 817 .Append('%s = %sParse%s(%s);' % (
810 self._type_helper.GetCppType(type_), 818 dst_var,
811 enum_as_string)) 819 cpp_type_namespace + '::' if cpp_type_namespace else '',
812 .Sblock('if (%s == %s) {' % (dst_var, 820 cpp_type_name,
813 self._type_helper.GetEnumNoneValue(type_))) 821 enum_as_string))
not at google - send to devlin 2014/03/31 15:18:59 if/when you do change this back, mind indenting th
mtomasz 2014/04/03 21:50:22 Done.
822 .Sblock('if (%s == %s%s) {' % (
823 dst_var,
824 cpp_type_namespace + '::' if cpp_type_namespace else '',
825 self._type_helper.GetEnumNoneValue(type_)))
814 .Concat(self._GenerateError( 826 .Concat(self._GenerateError(
815 '\"\'%%(key)s\': expected \\"' + 827 '\"\'%%(key)s\': expected \\"' +
816 '\\" or \\"'.join( 828 '\\" or \\"'.join(
817 enum_value.name 829 enum_value.name
818 for enum_value in self._type_helper.FollowRef(type_).enum_values) + 830 for enum_value in self._type_helper.FollowRef(type_).enum_values) +
819 '\\", got \\"" + %s + "\\""' % enum_as_string)) 831 '\\", got \\"" + %s + "\\""' % enum_as_string))
820 .Append('return %s;' % failure_value) 832 .Append('return %s;' % failure_value)
821 .Eblock('}') 833 .Eblock('}')
822 .Substitute({'src_var': src_var, 'key': type_.name}) 834 .Substitute({'src_var': src_var, 'key': type_.name})
823 ) 835 )
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if self._generate_error_messages: 981 if self._generate_error_messages:
970 params = list(params) + ['base::string16* error'] 982 params = list(params) + ['base::string16* error']
971 return ', '.join(str(p) for p in params) 983 return ', '.join(str(p) for p in params)
972 984
973 def _GenerateArgs(self, args): 985 def _GenerateArgs(self, args):
974 """Builds the argument list for a function, given an array of arguments. 986 """Builds the argument list for a function, given an array of arguments.
975 """ 987 """
976 if self._generate_error_messages: 988 if self._generate_error_messages:
977 args = list(args) + ['error'] 989 args = list(args) + ['error']
978 return ', '.join(str(a) for a in args) 990 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « ppapi/generators/idl_parser.py ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698