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

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

Issue 10907151: Extensions Docs Server: Enum values do not show up if enum is a type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToString and FromString Created 8 years, 3 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
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 any_helper 7 import any_helper
8 import cpp_util 8 import cpp_util
9 import model 9 import model
10 import schema_util 10 import schema_util
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 """ 102 """
103 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) 103 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name))
104 c = Code() 104 c = Code()
105 105
106 if type_.functions: 106 if type_.functions:
107 for function in type_.functions.values(): 107 for function in type_.functions.values():
108 (c.Concat( 108 (c.Concat(
109 self._GenerateFunction( 109 self._GenerateFunction(
110 cpp_namespace + '::' + cpp_util.Classname(function.name), 110 cpp_namespace + '::' + cpp_util.Classname(function.name),
111 function)) 111 function))
112 .Append() 112 .Append())
113 )
114 elif type_.type_ == PropertyType.OBJECT: 113 elif type_.type_ == PropertyType.OBJECT:
115 (c.Concat(self._GeneratePropertyFunctions( 114 (c.Concat(self._GeneratePropertyFunctions(
116 cpp_namespace, type_.properties.values())) 115 cpp_namespace, type_.properties.values()))
117 .Sblock('%(namespace)s::%(classname)s()') 116 .Sblock('%(namespace)s::%(classname)s()')
118 .Concat(self._GenerateInitializersAndBody(type_)) 117 .Concat(self._GenerateInitializersAndBody(type_))
119 .Eblock('%(namespace)s::~%(classname)s() {}') 118 .Eblock('%(namespace)s::~%(classname)s() {}')
120 .Append() 119 .Append())
121 )
122 if type_.from_json: 120 if type_.from_json:
123 (c.Concat(self._GenerateTypePopulate(cpp_namespace, type_)) 121 (c.Concat(self._GenerateTypePopulate(cpp_namespace, type_))
124 .Append() 122 .Append())
125 )
126 if type_.from_client: 123 if type_.from_client:
127 (c.Concat(self._GenerateTypeToValue(cpp_namespace, type_)) 124 (c.Concat(self._GenerateTypeToValue(cpp_namespace, type_))
128 .Append() 125 .Append())
129 )
130 elif self._cpp_type_generator.IsEnumOrEnumRef(type_): 126 elif self._cpp_type_generator.IsEnumOrEnumRef(type_):
131 c.Concat(self._GenerateCreateEnumTypeValue(cpp_namespace, type_)) 127 (c.Concat(self._GenerateCreateEnumTypeValue(cpp_namespace, type_))
132 c.Append() 128 .Append()
129 .Concat(self._GenerateEnumFromString(cpp_namespace, type_))
130 .Append()
131 .Concat(self._GenerateEnumToString(cpp_namespace, type_))
132 .Append())
133 c.Substitute({'classname': classname, 'namespace': cpp_namespace}) 133 c.Substitute({'classname': classname, 'namespace': cpp_namespace})
134 134
135 return c 135 return c
136 136
137 def _GenerateInitializersAndBody(self, type_): 137 def _GenerateInitializersAndBody(self, type_):
138 items = [] 138 items = []
139 for prop in type_.properties.values(): 139 for prop in type_.properties.values():
140 if prop.optional: 140 if prop.optional:
141 continue 141 continue
142 142
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 """Generate the code to populate a single property in a type. 213 """Generate the code to populate a single property in a type.
214 214
215 src: base::DictionaryValue* 215 src: base::DictionaryValue*
216 dst: Type* 216 dst: Type*
217 """ 217 """
218 c = Code() 218 c = Code()
219 value_var = prop.unix_name + '_value' 219 value_var = prop.unix_name + '_value'
220 c.Append('const base::Value* %(value_var)s = NULL;') 220 c.Append('const base::Value* %(value_var)s = NULL;')
221 if prop.optional: 221 if prop.optional:
222 (c.Sblock( 222 (c.Sblock(
223 'if (%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {' 223 'if (%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s)) {')
224 )
225 .Concat(self._GeneratePopulatePropertyFromValue( 224 .Concat(self._GeneratePopulatePropertyFromValue(
226 prop, value_var, dst, 'false')) 225 prop, value_var, dst, 'false')))
227 .Eblock('}') 226 if self._cpp_type_generator.IsEnumOrEnumRef(prop):
228 ) 227 (c.Append('} else {')
228 .Append('%%(dst)s->%%(name)s = %s;' %
229 self._cpp_type_generator.GetEnumNoneValue(prop)))
230 c.Eblock('}')
229 else: 231 else:
230 (c.Append( 232 (c.Append(
231 'if (!%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s))') 233 'if (!%(src)s->GetWithoutPathExpansion("%(key)s", &%(value_var)s))')
232 .Append(' return false;') 234 .Append(' return false;')
233 .Concat(self._GeneratePopulatePropertyFromValue( 235 .Concat(self._GeneratePopulatePropertyFromValue(
234 prop, value_var, dst, 'false')) 236 prop, value_var, dst, 'false'))
235 ) 237 )
236 c.Append() 238 c.Append()
237 c.Substitute({'value_var': value_var, 'key': prop.name, 'src': src}) 239 c.Substitute({
240 'value_var': value_var,
241 'key': prop.name,
242 'src': src,
243 'dst': dst,
244 'name': prop.unix_name
245 })
238 return c 246 return c
239 247
240 def _GenerateTypeToValue(self, cpp_namespace, type_): 248 def _GenerateTypeToValue(self, cpp_namespace, type_):
241 """Generates a function that serializes the type into a 249 """Generates a function that serializes the type into a
242 |base::DictionaryValue|. 250 |base::DictionaryValue|.
243 251
244 E.g. for type "Foo" generates Foo::ToValue() 252 E.g. for type "Foo" generates Foo::ToValue()
245 """ 253 """
246 c = Code() 254 c = Code()
247 (c.Sblock('scoped_ptr<base::DictionaryValue> %s::ToValue() const {' % 255 (c.Sblock('scoped_ptr<base::DictionaryValue> %s::ToValue() const {' %
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) 344 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var)
337 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: 345 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES:
338 return '%s.DeepCopy()' % var 346 return '%s.DeepCopy()' % var
339 elif prop.type_ == PropertyType.FUNCTION: 347 elif prop.type_ == PropertyType.FUNCTION:
340 if prop.optional: 348 if prop.optional:
341 vardot = var + '->' 349 vardot = var + '->'
342 else: 350 else:
343 vardot = var + '.' 351 vardot = var + '.'
344 return '%sDeepCopy()' % vardot 352 return '%sDeepCopy()' % vardot
345 elif self._cpp_type_generator.IsEnumOrEnumRef(prop): 353 elif self._cpp_type_generator.IsEnumOrEnumRef(prop):
346 return 'CreateEnumValue(%s).release()' % var 354 return 'base::Value::CreateStringValue(ToString(%s))' % var
347 elif prop.type_ == PropertyType.BINARY: 355 elif prop.type_ == PropertyType.BINARY:
348 if prop.optional: 356 if prop.optional:
349 vardot = var + '->' 357 vardot = var + '->'
350 else: 358 else:
351 vardot = var + '.' 359 vardot = var + '.'
352 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % 360 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' %
353 (vardot, vardot)) 361 (vardot, vardot))
354 elif self._IsArrayOrArrayRef(prop): 362 elif self._IsArrayOrArrayRef(prop):
355 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( 363 return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
356 self._cpp_type_generator.GetReferencedProperty(prop), var, 364 self._cpp_type_generator.GetReferencedProperty(prop), var,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 c.Append('%(dst)s->%(name)s.reset(new std::vector<' + ( 649 c.Append('%(dst)s->%(name)s.reset(new std::vector<' + (
642 self._cpp_type_generator.GetType(prop.item_type) + '>);')) 650 self._cpp_type_generator.GetType(prop.item_type) + '>);'))
643 accessor = '->' 651 accessor = '->'
644 c.Sblock('for (ListValue::const_iterator it = list->begin(); ' 652 c.Sblock('for (ListValue::const_iterator it = list->begin(); '
645 'it != list->end(); ++it) {') 653 'it != list->end(); ++it) {')
646 self._GenerateStringToEnumConversion( 654 self._GenerateStringToEnumConversion(
647 c, prop.item_type, '(*it)', 'enum_temp') 655 c, prop.item_type, '(*it)', 'enum_temp')
648 c.Append('%(dst)s->%(name)s' + accessor + 'push_back(enum_temp);') 656 c.Append('%(dst)s->%(name)s' + accessor + 'push_back(enum_temp);')
649 c.Eblock('}') 657 c.Eblock('}')
650 658
651 def _GenerateStringToEnumConversion(self, 659 def _GenerateStringToEnumConversion(self, c, prop, value_var, enum_temp):
652 c,
653 prop,
654 value_var,
655 enum_temp):
656 """Appends code that converts a string to an enum. 660 """Appends code that converts a string to an enum.
657 Leaves failure_value unsubstituted. 661 Leaves failure_value unsubstituted.
658 662
659 c: the code that is appended to. 663 c: the code that is appended to.
660 prop: the property that the code is populating. 664 prop: the property that the code is populating.
661 value_var: the string value that is being converted. 665 value_var: the string value that is being converted.
662 enum_temp: the name used to store the temporary enum value. 666 enum_temp: the name used to store the temporary enum value.
663 """ 667 """
664 (c.Append('%s %s;' % (self._cpp_type_generator.GetCompiledType(prop), 668 (c.Append('std::string enum_as_string;')
665 enum_temp))
666 .Append('std::string enum_as_string;')
667 .Append('if (!%s->GetAsString(&enum_as_string))' % value_var) 669 .Append('if (!%s->GetAsString(&enum_as_string))' % value_var)
668 .Append(' return %(failure_value)s;') 670 .Append(' return %(failure_value)s;')
669 ) 671 .Append('%s %s = From%sString(enum_as_string);' %
670 for i, enum_value in enumerate( 672 (self._cpp_type_generator.GetCompiledType(prop),
671 self._cpp_type_generator.GetReferencedProperty(prop).enum_values): 673 enum_temp,
672 (c.Append( 674 self._cpp_type_generator.GetCompiledType(prop)))
not at google - send to devlin 2012/09/18 03:55:20 use %s(tring) replacements so that you don't need
cduvall 2012/09/21 00:39:28 Done.
673 ('if' if i == 0 else 'else if') + 675 .Append('if (%s == %s)' %
674 '(enum_as_string == "%s")' % enum_value) 676 (enum_temp, self._cpp_type_generator.GetEnumNoneValue(prop)))
675 .Append(' ' + enum_temp + ' = %s;' % ( 677 .Append(' return %(failure_value)s;'))
676 self._cpp_type_generator.GetEnumValue(prop, enum_value)))
677 )
678 (c.Append('else')
679 .Append(' return %(failure_value)s;')
680 )
681 678
682 def _GeneratePropertyFunctions(self, param_namespace, params): 679 def _GeneratePropertyFunctions(self, param_namespace, params):
683 """Generate the functions for structures generated by a property such as 680 """Generate the functions for structures generated by a property such as
684 CreateEnumValue for ENUMs and Populate/ToValue for Params/Results objects. 681 CreateEnumValue for ENUMs and Populate/ToValue for Params/Results objects.
685 """ 682 """
686 c = Code() 683 c = Code()
687 for param in params: 684 for param in params:
688 if param.type_ == PropertyType.OBJECT: 685 if param.type_ == PropertyType.OBJECT:
689 c.Concat(self._GenerateType( 686 c.Concat(self._GenerateType(
690 param_namespace + '::' + cpp_util.Classname(param.name), 687 param_namespace + '::' + cpp_util.Classname(param.name),
691 param)) 688 param))
692 c.Append() 689 c.Append()
693 elif param.type_ == PropertyType.ARRAY: 690 elif param.type_ == PropertyType.ARRAY:
694 c.Concat(self._GeneratePropertyFunctions( 691 c.Concat(self._GeneratePropertyFunctions(
695 param_namespace, [param.item_type])) 692 param_namespace, [param.item_type]))
696 elif param.type_ == PropertyType.CHOICES: 693 elif param.type_ == PropertyType.CHOICES:
697 c.Concat(self._GeneratePropertyFunctions( 694 c.Concat(self._GeneratePropertyFunctions(
698 param_namespace, param.choices.values())) 695 param_namespace, param.choices.values()))
699 if param.from_client: 696 if param.from_client:
700 c.Concat(self._GenerateGetChoiceValue(param_namespace, param)) 697 c.Concat(self._GenerateGetChoiceValue(param_namespace, param))
701 elif param.type_ == PropertyType.ENUM: 698 elif param.type_ == PropertyType.ENUM:
702 c.Concat(self._GenerateCreateEnumValue(param_namespace, param)) 699 (c.Concat(self._GenerateCreateEnumValue(param_namespace, param))
703 c.Append() 700 .Append()
701 .Concat(self._GenerateEnumFromString(param_namespace,
702 param,
703 use_namespace=True))
704 .Append()
705 .Concat(self._GenerateEnumToString(param_namespace,
706 param,
707 use_namespace=True))
708 .Append())
704 return c 709 return c
705 710
706 def _GenerateGetChoiceValue(self, cpp_namespace, prop): 711 def _GenerateGetChoiceValue(self, cpp_namespace, prop):
707 """Generates Get<Type>ChoiceValue() that returns a scoped_ptr<base::Value> 712 """Generates Get<Type>ChoiceValue() that returns a scoped_ptr<base::Value>
708 representing the choice value. 713 representing the choice value.
709 """ 714 """
710 c = Code() 715 c = Code()
711 (c.Sblock('scoped_ptr<base::Value> ' 716 (c.Sblock('scoped_ptr<base::Value> '
712 '%(cpp_namespace)s::Get%(choice)sChoiceValue() const {') 717 '%(cpp_namespace)s::Get%(choice)sChoiceValue() const {')
713 .Sblock('switch (%s_type) {' % prop.unix_name) 718 .Sblock('switch (%s_type) {' % prop.unix_name)
714 ) 719 .Concat(self._GenerateReturnCase(
715 if prop.optional:
716 c.Concat(self._GenerateReturnCase(
717 self._cpp_type_generator.GetEnumNoneValue(prop), 720 self._cpp_type_generator.GetEnumNoneValue(prop),
718 'scoped_ptr<base::Value>()')) 721 'scoped_ptr<base::Value>()')))
719 for choice in self._cpp_type_generator.ExpandParams([prop]): 722 for choice in self._cpp_type_generator.ExpandParams([prop]):
720 c.Concat(self._GenerateReturnCase( 723 c.Concat(self._GenerateReturnCase(
721 self._cpp_type_generator.GetEnumValue(prop, choice.type_.name), 724 self._cpp_type_generator.GetEnumValue(prop, choice.type_.name),
722 'make_scoped_ptr<base::Value>(%s)' % 725 'make_scoped_ptr<base::Value>(%s)' %
723 self._CreateValueFromProperty(choice, choice.unix_name))) 726 self._CreateValueFromProperty(choice, choice.unix_name)))
724 (c.Eblock('}') 727 (c.Eblock('}')
725 .Append('NOTREACHED();')
726 .Append('return scoped_ptr<base::Value>();') 728 .Append('return scoped_ptr<base::Value>();')
727 .Eblock('}') 729 .Eblock('}')
728 .Append() 730 .Append()
729 .Substitute({ 731 .Substitute({
730 'cpp_namespace': cpp_namespace, 732 'cpp_namespace': cpp_namespace,
731 'choice': cpp_util.Classname(prop.name) 733 'choice': cpp_util.Classname(prop.name)
732 }) 734 })
733 ) 735 )
734 return c 736 return c
735 737
736 def _GenerateCreateEnumTypeValue(self, cpp_namespace, prop): 738 def _GenerateCreateEnumTypeValue(self, cpp_namespace, prop):
737 """Generates CreateEnumValue() that returns the base::StringValue 739 """Generates CreateEnumValue() that returns the base::StringValue
738 representation of an enum type. 740 representation of an enum type.
739 """ 741 """
740 c = Code() 742 c = Code()
741 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(prop.name)) 743 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(prop.name))
742 c.Sblock('scoped_ptr<base::Value> CreateEnumValue(%s %s) {' % ( 744 c.Sblock('scoped_ptr<base::Value> CreateEnumValue(%s %s) {' % (
743 classname, classname.lower())) 745 classname, classname.lower()))
744 c.Sblock('switch (%s) {' % classname.lower()) 746 c.Sblock('switch (%s) {' % classname.lower())
745 747
746 enum_prop = self._cpp_type_generator.GetReferencedProperty(prop) 748 enum_prop = self._cpp_type_generator.GetReferencedProperty(prop)
747 for enum_value in enum_prop.enum_values: 749 for enum_value in enum_prop.enum_values:
748 c.Concat(self._GenerateReturnCase( 750 c.Concat(self._GenerateReturnCase(
749 '%s_%s' % (classname.upper(), enum_value.upper()), 751 '%s' % self._cpp_type_generator.GetEnumValue(prop, enum_value),
750 'scoped_ptr<base::Value>(base::Value::CreateStringValue("%s"))' % 752 'scoped_ptr<base::Value>(base::Value::CreateStringValue("%s"))' %
751 enum_value)) 753 enum_value))
752 (c.Eblock('}') 754 (c.Append('case %s:' % self._cpp_type_generator.GetEnumNoneValue(prop))
753 .Append('NOTREACHED();') 755 .Append(' return scoped_ptr<base::Value>();')
756 .Eblock('}')
754 .Append('return scoped_ptr<base::Value>();') 757 .Append('return scoped_ptr<base::Value>();')
758 .Eblock('}'))
759 return c
760
761 def _GenerateEnumToString(self, cpp_namespace, prop, use_namespace=False):
762 """Generates ToString() which gets the string representation of an enum.
763 """
764 c = Code()
765 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(prop.name))
766 if use_namespace:
767 namespace = '%s::' % cpp_namespace
768 else:
769 namespace = ''
770
771 (c.Append('// static')
772 .Sblock('std::string %(namespace)sToString(%(class)s enum_param) {')
773 .Append('std::string temp_string;')
774 .Append('scoped_ptr<base::Value> enum_value('
775 'CreateEnumValue(enum_param));')
776 .Append('if (!enum_value.get())')
777 .Append(' return "";')
778 .Append('if (!enum_value->GetAsString(&temp_string))')
not at google - send to devlin 2012/09/18 03:55:20 Pulling the string out of the value here seems rou
cduvall 2012/09/21 00:39:28 Done.
779 .Append(' return "";')
780 .Append('return temp_string;')
755 .Eblock('}') 781 .Eblock('}')
756 ) 782 .Substitute({
783 'namespace': namespace,
784 'class': classname
785 }))
786 return c
787
788 def _GenerateEnumFromString(self, cpp_namespace, prop, use_namespace=False):
789 """Generates FromClassNameString() which gets an enum from its string
790 representation.
791 """
792 c = Code()
793 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(prop.name))
794 if use_namespace:
795 namespace = '%s::' % cpp_namespace
796 else:
797 namespace = ''
798
799 (c.Append('// static')
800 .Sblock('%(namespace)s%(class)s'
801 ' %(namespace)sFrom%(class)sString('
802 'const std::string& enum_string) {'))
803 enum_prop = self._cpp_type_generator.GetReferencedProperty(prop)
804 for i, enum_value in enumerate(
805 self._cpp_type_generator.GetReferencedProperty(prop).enum_values):
806 # This is broken up into all ifs with no else ifs because we get
807 # "fatal error C1061: compiler limit : blocks nested too deeply"
808 # on Windows.
809 (c.Append('if (enum_string == "%s")' % enum_value)
810 .Append(' return %s;' %
811 self._cpp_type_generator.GetEnumValue(prop, enum_value)))
812 (c.Append('return %s;' %
813 self._cpp_type_generator.GetEnumNoneValue(prop))
814 .Eblock('}')
815 .Substitute({
816 'namespace': namespace,
817 'class': classname
818 }))
757 return c 819 return c
758 820
759 # TODO(chebert): This is basically the same as GenerateCreateEnumTypeValue(). 821 # TODO(chebert): This is basically the same as GenerateCreateEnumTypeValue().
760 # The plan is to phase out the old-style enums, and make all enums into REF 822 # The plan is to phase out the old-style enums, and make all enums into REF
761 # types. 823 # types.
762 def _GenerateCreateEnumValue(self, cpp_namespace, prop): 824 def _GenerateCreateEnumValue(self, cpp_namespace, prop):
763 """Generates CreateEnumValue() that returns the base::StringValue 825 """Generates CreateEnumValue() that returns the base::StringValue
764 representation of an enum. 826 representation of an enum.
765 """ 827 """
766 c = Code() 828 c = Code()
767 c.Append('// static') 829 (c.Append('// static')
768 c.Sblock('scoped_ptr<base::Value> %(cpp_namespace)s::CreateEnumValue(' 830 .Sblock('scoped_ptr<base::Value> %(cpp_namespace)s::CreateEnumValue('
769 '%(arg)s) {') 831 '%(arg)s) {')
770 c.Sblock('switch (%s) {' % prop.unix_name) 832 .Sblock('switch (%s) {' % prop.unix_name)
771 if prop.optional: 833 .Concat(self._GenerateReturnCase(
772 c.Concat(self._GenerateReturnCase( 834 self._cpp_type_generator.GetEnumNoneValue(prop),
773 self._cpp_type_generator.GetEnumNoneValue(prop), 835 'scoped_ptr<base::Value>()')))
774 'scoped_ptr<base::Value>()'))
775 for enum_value in prop.enum_values: 836 for enum_value in prop.enum_values:
776 c.Concat(self._GenerateReturnCase( 837 c.Concat(self._GenerateReturnCase(
777 self._cpp_type_generator.GetEnumValue(prop, enum_value), 838 self._cpp_type_generator.GetEnumValue(prop, enum_value),
not at google - send to devlin 2012/09/18 03:55:20 can you make this method just call FromString? it
cduvall 2012/09/21 00:39:28 Done, assuming you meant ToString.
778 'scoped_ptr<base::Value>(base::Value::CreateStringValue("%s"))' % 839 'scoped_ptr<base::Value>(base::Value::CreateStringValue("%s"))' %
779 enum_value)) 840 enum_value))
780 (c.Eblock('}') 841 (c.Eblock('}')
781 .Append('NOTREACHED();')
782 .Append('return scoped_ptr<base::Value>();') 842 .Append('return scoped_ptr<base::Value>();')
783 .Eblock('}') 843 .Eblock('}')
784 .Substitute({ 844 .Substitute({
785 'cpp_namespace': cpp_namespace, 845 'cpp_namespace': cpp_namespace,
786 'arg': cpp_util.GetParameterDeclaration( 846 'arg': cpp_util.GetParameterDeclaration(
787 prop, self._cpp_type_generator.GetType(prop)) 847 prop, self._cpp_type_generator.GetType(prop))
788 }) 848 }))
789 )
790 return c 849 return c
791 850
792 def _GenerateReturnCase(self, case_value, return_value): 851 def _GenerateReturnCase(self, case_value, return_value):
793 """Generates a single return case for a switch block. 852 """Generates a single return case for a switch block.
794 """ 853 """
795 c = Code() 854 c = Code()
796 (c.Append('case %s:' % case_value) 855 (c.Append('case %s:' % case_value)
797 .Append(' return %s;' % return_value) 856 .Append(' return %s;' % return_value)
798 ) 857 )
799 return c 858 return c
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 """ 957 """
899 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == 958 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ ==
900 PropertyType.ARRAY) 959 PropertyType.ARRAY)
901 960
902 def _IsFundamentalOrFundamentalRef(self, prop): 961 def _IsFundamentalOrFundamentalRef(self, prop):
903 """Determines if this property is a Fundamental type or is a ref to a 962 """Determines if this property is a Fundamental type or is a ref to a
904 Fundamental type. 963 Fundamental type.
905 """ 964 """
906 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. 965 return (self._cpp_type_generator.GetReferencedProperty(prop).type_.
907 is_fundamental) 966 is_fundamental)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698