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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 else: | 490 else: |
491 return '(%s).ToValue().release()' % var | 491 return '(%s).ToValue().release()' % var |
492 elif (underlying_type.property_type == PropertyType.ANY or | 492 elif (underlying_type.property_type == PropertyType.ANY or |
493 underlying_type.property_type == PropertyType.FUNCTION): | 493 underlying_type.property_type == PropertyType.FUNCTION): |
494 if is_ptr: | 494 if is_ptr: |
495 vardot = '(%s)->' % var | 495 vardot = '(%s)->' % var |
496 else: | 496 else: |
497 vardot = '(%s).' % var | 497 vardot = '(%s).' % var |
498 return '%sDeepCopy()' % vardot | 498 return '%sDeepCopy()' % vardot |
499 elif underlying_type.property_type == PropertyType.ENUM: | 499 elif underlying_type.property_type == PropertyType.ENUM: |
500 classname = cpp_util.Classname(schema_util.StripNamespace( | 500 maybe_namespace = '' |
501 underlying_type.name)) | 501 if type_.property_type == PropertyType.REF: |
502 return 'new base::StringValue(%sToString(%s))' % (classname, var) | 502 maybe_namespace = '%s::' % underlying_type.namespace.unix_name |
| 503 return 'new base::StringValue(%sToString(%s))' % (maybe_namespace, var) |
503 elif underlying_type.property_type == PropertyType.BINARY: | 504 elif underlying_type.property_type == PropertyType.BINARY: |
504 if is_ptr: | 505 if is_ptr: |
505 vardot = var + '->' | 506 vardot = var + '->' |
506 else: | 507 else: |
507 vardot = var + '.' | 508 vardot = var + '.' |
508 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % | 509 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % |
509 (vardot, vardot)) | 510 (vardot, vardot)) |
510 elif underlying_type.property_type == PropertyType.ARRAY: | 511 elif underlying_type.property_type == PropertyType.ARRAY: |
511 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( | 512 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( |
512 cpp_namespace, | 513 cpp_namespace, |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 def _GenerateEnumToString(self, cpp_namespace, type_): | 882 def _GenerateEnumToString(self, cpp_namespace, type_): |
882 """Generates ToString() which gets the string representation of an enum. | 883 """Generates ToString() which gets the string representation of an enum. |
883 """ | 884 """ |
884 c = Code() | 885 c = Code() |
885 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) | 886 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) |
886 | 887 |
887 if cpp_namespace is not None: | 888 if cpp_namespace is not None: |
888 c.Append('// static') | 889 c.Append('// static') |
889 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace | 890 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace |
890 | 891 |
891 c.Sblock('std::string %s%sToString(%s enum_param) {' % | 892 c.Sblock('std::string %sToString(%s enum_param) {' % |
892 (maybe_namespace, classname, classname)) | 893 (maybe_namespace, classname)) |
893 c.Sblock('switch (enum_param) {') | 894 c.Sblock('switch (enum_param) {') |
894 for enum_value in self._type_helper.FollowRef(type_).enum_values: | 895 for enum_value in self._type_helper.FollowRef(type_).enum_values: |
895 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) | 896 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) |
896 .Append(' return "%s";' % enum_value.name)) | 897 .Append(' return "%s";' % enum_value.name)) |
897 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) | 898 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) |
898 .Append(' return "";') | 899 .Append(' return "";') |
899 .Eblock('}') | 900 .Eblock('}') |
900 .Append('NOTREACHED();') | 901 .Append('NOTREACHED();') |
901 .Append('return "";') | 902 .Append('return "";') |
902 .Eblock('}') | 903 .Eblock('}') |
903 ) | 904 ) |
904 | |
905 (c.Append() | |
906 .Sblock('std::string %sToString(%s enum_param) {' % | |
907 (maybe_namespace, classname)) | |
908 .Append('return %s%sToString(enum_param);' % (maybe_namespace, classname)) | |
909 .Eblock('}')) | |
910 return c | 905 return c |
911 | 906 |
912 def _GenerateEnumFromString(self, cpp_namespace, type_): | 907 def _GenerateEnumFromString(self, cpp_namespace, type_): |
913 """Generates FromClassNameString() which gets an enum from its string | 908 """Generates FromClassNameString() which gets an enum from its string |
914 representation. | 909 representation. |
915 """ | 910 """ |
916 c = Code() | 911 c = Code() |
917 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) | 912 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) |
918 | 913 |
919 if cpp_namespace is not None: | 914 if cpp_namespace is not None: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 if self._generate_error_messages: | 1013 if self._generate_error_messages: |
1019 params = list(params) + ['base::string16* error'] | 1014 params = list(params) + ['base::string16* error'] |
1020 return ', '.join(str(p) for p in params) | 1015 return ', '.join(str(p) for p in params) |
1021 | 1016 |
1022 def _GenerateArgs(self, args): | 1017 def _GenerateArgs(self, args): |
1023 """Builds the argument list for a function, given an array of arguments. | 1018 """Builds the argument list for a function, given an array of arguments. |
1024 """ | 1019 """ |
1025 if self._generate_error_messages: | 1020 if self._generate_error_messages: |
1026 args = list(args) + ['error'] | 1021 args = list(args) + ['error'] |
1027 return ', '.join(str(a) for a in args) | 1022 return ', '.join(str(a) for a in args) |
OLD | NEW |