| 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 | 10 |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) | 777 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) |
| 778 .Append('return %s;' % failure_value) | 778 .Append('return %s;' % failure_value) |
| 779 .Eblock('}') | 779 .Eblock('}') |
| 780 .Append('%s = Parse%s(%s);' % (dst_var, | 780 .Append('%s = Parse%s(%s);' % (dst_var, |
| 781 self._type_helper.GetCppType(type_), | 781 self._type_helper.GetCppType(type_), |
| 782 enum_as_string)) | 782 enum_as_string)) |
| 783 .Sblock('if (%s == %s) {' % (dst_var, | 783 .Sblock('if (%s == %s) {' % (dst_var, |
| 784 self._type_helper.GetEnumNoneValue(type_))) | 784 self._type_helper.GetEnumNoneValue(type_))) |
| 785 .Concat(self._GenerateError( | 785 .Concat(self._GenerateError( |
| 786 '\"\'%%(key)s\': expected \\"' + | 786 '\"\'%%(key)s\': expected \\"' + |
| 787 '\\" or \\"'.join(self._type_helper.FollowRef(type_).enum_values) + | 787 '\\" or \\"'.join( |
| 788 enum_value.name |
| 789 for enum_value in self._type_helper.FollowRef(type_).enum_values) + |
| 788 '\\", got \\"" + %s + "\\""' % enum_as_string)) | 790 '\\", got \\"" + %s + "\\""' % enum_as_string)) |
| 789 .Append('return %s;' % failure_value) | 791 .Append('return %s;' % failure_value) |
| 790 .Eblock('}') | 792 .Eblock('}') |
| 791 .Substitute({'src_var': src_var, 'key': type_.name}) | 793 .Substitute({'src_var': src_var, 'key': type_.name}) |
| 792 ) | 794 ) |
| 793 return c | 795 return c |
| 794 | 796 |
| 795 def _GeneratePropertyFunctions(self, namespace, params): | 797 def _GeneratePropertyFunctions(self, namespace, params): |
| 796 """Generates the member functions for a list of parameters. | 798 """Generates the member functions for a list of parameters. |
| 797 """ | 799 """ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 813 | 815 |
| 814 if cpp_namespace is not None: | 816 if cpp_namespace is not None: |
| 815 c.Append('// static') | 817 c.Append('// static') |
| 816 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace | 818 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace |
| 817 | 819 |
| 818 c.Sblock('std::string %sToString(%s enum_param) {' % | 820 c.Sblock('std::string %sToString(%s enum_param) {' % |
| 819 (maybe_namespace, classname)) | 821 (maybe_namespace, classname)) |
| 820 c.Sblock('switch (enum_param) {') | 822 c.Sblock('switch (enum_param) {') |
| 821 for enum_value in self._type_helper.FollowRef(type_).enum_values: | 823 for enum_value in self._type_helper.FollowRef(type_).enum_values: |
| 822 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) | 824 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) |
| 823 .Append(' return "%s";' % enum_value)) | 825 .Append(' return "%s";' % enum_value.name)) |
| 824 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) | 826 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) |
| 825 .Append(' return "";') | 827 .Append(' return "";') |
| 826 .Eblock('}') | 828 .Eblock('}') |
| 827 .Append('NOTREACHED();') | 829 .Append('NOTREACHED();') |
| 828 .Append('return "";') | 830 .Append('return "";') |
| 829 .Eblock('}') | 831 .Eblock('}') |
| 830 ) | 832 ) |
| 831 return c | 833 return c |
| 832 | 834 |
| 833 def _GenerateEnumFromString(self, cpp_namespace, type_): | 835 def _GenerateEnumFromString(self, cpp_namespace, type_): |
| 834 """Generates FromClassNameString() which gets an enum from its string | 836 """Generates FromClassNameString() which gets an enum from its string |
| 835 representation. | 837 representation. |
| 836 """ | 838 """ |
| 837 c = Code() | 839 c = Code() |
| 838 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) | 840 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) |
| 839 | 841 |
| 840 if cpp_namespace is not None: | 842 if cpp_namespace is not None: |
| 841 c.Append('// static') | 843 c.Append('// static') |
| 842 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace | 844 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace |
| 843 | 845 |
| 844 c.Sblock('%s%s %sParse%s(const std::string& enum_string) {' % | 846 c.Sblock('%s%s %sParse%s(const std::string& enum_string) {' % |
| 845 (maybe_namespace, classname, maybe_namespace, classname)) | 847 (maybe_namespace, classname, maybe_namespace, classname)) |
| 846 for i, enum_value in enumerate( | 848 for i, enum_value in enumerate( |
| 847 self._type_helper.FollowRef(type_).enum_values): | 849 self._type_helper.FollowRef(type_).enum_values): |
| 848 # This is broken up into all ifs with no else ifs because we get | 850 # This is broken up into all ifs with no else ifs because we get |
| 849 # "fatal error C1061: compiler limit : blocks nested too deeply" | 851 # "fatal error C1061: compiler limit : blocks nested too deeply" |
| 850 # on Windows. | 852 # on Windows. |
| 851 (c.Append('if (enum_string == "%s")' % enum_value) | 853 (c.Append('if (enum_string == "%s")' % enum_value.name) |
| 852 .Append(' return %s;' % | 854 .Append(' return %s;' % |
| 853 self._type_helper.GetEnumValue(type_, enum_value))) | 855 self._type_helper.GetEnumValue(type_, enum_value))) |
| 854 (c.Append('return %s;' % self._type_helper.GetEnumNoneValue(type_)) | 856 (c.Append('return %s;' % self._type_helper.GetEnumNoneValue(type_)) |
| 855 .Eblock('}') | 857 .Eblock('}') |
| 856 ) | 858 ) |
| 857 return c | 859 return c |
| 858 | 860 |
| 859 def _GenerateCreateCallbackArguments(self, function_scope, callback): | 861 def _GenerateCreateCallbackArguments(self, function_scope, callback): |
| 860 """Generate all functions to create Value parameters for a callback. | 862 """Generate all functions to create Value parameters for a callback. |
| 861 | 863 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 if self._generate_error_messages: | 935 if self._generate_error_messages: |
| 934 params = list(params) + ['base::string16* error'] | 936 params = list(params) + ['base::string16* error'] |
| 935 return ', '.join(str(p) for p in params) | 937 return ', '.join(str(p) for p in params) |
| 936 | 938 |
| 937 def _GenerateArgs(self, args): | 939 def _GenerateArgs(self, args): |
| 938 """Builds the argument list for a function, given an array of arguments. | 940 """Builds the argument list for a function, given an array of arguments. |
| 939 """ | 941 """ |
| 940 if self._generate_error_messages: | 942 if self._generate_error_messages: |
| 941 args = list(args) + ['error'] | 943 args = list(args) + ['error'] |
| 942 return ', '.join(str(a) for a in args) | 944 return ', '.join(str(a) for a in args) |
| OLD | NEW |