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

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

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Addressed feedback Created 5 years, 11 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
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 from cpp_namespace_environment import CppNamespaceEnvironment 10 from cpp_namespace_environment import CppNamespaceEnvironment
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 elif prop.optional: 153 elif prop.optional:
154 continue 154 continue
155 elif t.property_type == PropertyType.INTEGER: 155 elif t.property_type == PropertyType.INTEGER:
156 items.append('%s(0)' % prop.unix_name) 156 items.append('%s(0)' % prop.unix_name)
157 elif t.property_type == PropertyType.DOUBLE: 157 elif t.property_type == PropertyType.DOUBLE:
158 items.append('%s(0.0)' % prop.unix_name) 158 items.append('%s(0.0)' % prop.unix_name)
159 elif t.property_type == PropertyType.BOOLEAN: 159 elif t.property_type == PropertyType.BOOLEAN:
160 items.append('%s(false)' % prop.unix_name) 160 items.append('%s(false)' % prop.unix_name)
161 elif (t.property_type == PropertyType.ANY or 161 elif (t.property_type == PropertyType.ANY or
162 t.property_type == PropertyType.ARRAY or 162 t.property_type == PropertyType.ARRAY or
163 t.property_type == PropertyType.BINARY or # mapped to std::string 163 t.property_type == PropertyType.BINARY or
164 t.property_type == PropertyType.CHOICES or 164 t.property_type == PropertyType.CHOICES or
165 t.property_type == PropertyType.OBJECT or 165 t.property_type == PropertyType.OBJECT or
166 t.property_type == PropertyType.FUNCTION or 166 t.property_type == PropertyType.FUNCTION or
167 t.property_type == PropertyType.REF or 167 t.property_type == PropertyType.REF or
168 t.property_type == PropertyType.STRING): 168 t.property_type == PropertyType.STRING):
169 # TODO(miket): It would be nice to initialize CHOICES, but we 169 # TODO(miket): It would be nice to initialize CHOICES, but we
170 # don't presently have the semantics to indicate which one of a set 170 # don't presently have the semantics to indicate which one of a set
171 # should be the default. 171 # should be the default.
172 continue 172 continue
173 else: 173 else:
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True))) 800 self._util_cc_helper.GetValueTypeString('%%(src_var)s', True)))
801 ) 801 )
802 if not self._generate_error_messages: 802 if not self._generate_error_messages:
803 c.Append('return %(failure_value)s;') 803 c.Append('return %(failure_value)s;')
804 (c.Eblock('}') 804 (c.Eblock('}')
805 .Sblock('else {') 805 .Sblock('else {')
806 .Append(' binary_value =') 806 .Append(' binary_value =')
807 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') 807 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);')
808 ) 808 )
809 if is_ptr: 809 if is_ptr:
810 (c.Append('%(dst_var)s.reset(') 810 (c.Append('%(dst_var)s.reset(new std::vector<char>(')
811 .Append(' new std::string(binary_value->GetBuffer(),') 811 .Append(' binary_value->GetBuffer(),')
812 .Append(' binary_value->GetSize()));') 812 .Append(' binary_value->GetBuffer() + binary_value->GetSize()));')
813 ) 813 )
814 else: 814 else:
815 (c.Append('%(dst_var)s.assign(binary_value->GetBuffer(),') 815 (c.Append('%(dst_var)s.assign(')
816 .Append(' binary_value->GetSize());') 816 .Append(' binary_value->GetBuffer(),')
817 .Append(' binary_value->GetBuffer() + binary_value->GetSize());')
817 ) 818 )
818 c.Eblock('}') 819 c.Eblock('}')
819 else: 820 else:
820 raise NotImplementedError(type_) 821 raise NotImplementedError(type_)
821 if c.IsEmpty(): 822 if c.IsEmpty():
822 return c 823 return c
823 return Code().Sblock('{').Concat(c.Substitute({ 824 return Code().Sblock('{').Concat(c.Substitute({
824 'cpp_type': self._type_helper.GetCppType(type_), 825 'cpp_type': self._type_helper.GetCppType(type_),
825 'src_var': src_var, 826 'src_var': src_var,
826 'dst_var': dst_var, 827 'dst_var': dst_var,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 if self._generate_error_messages: 1049 if self._generate_error_messages:
1049 params = list(params) + ['base::string16* error'] 1050 params = list(params) + ['base::string16* error']
1050 return ', '.join(str(p) for p in params) 1051 return ', '.join(str(p) for p in params)
1051 1052
1052 def _GenerateArgs(self, args): 1053 def _GenerateArgs(self, args):
1053 """Builds the argument list for a function, given an array of arguments. 1054 """Builds the argument list for a function, given an array of arguments.
1054 """ 1055 """
1055 if self._generate_error_messages: 1056 if self._generate_error_messages:
1056 args = list(args) + ['error'] 1057 args = list(args) + ['error']
1057 return ', '.join(str(a) for a in args) 1058 return ', '.join(str(a) for a in args)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698