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

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

Issue 10700194: Represent BINARY properties using std::string instead of BinaryValue, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo values.h change. Created 8 years, 5 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 | « tools/json_schema_compiler/cc_generator.py ('k') | no next file » | 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 any_helper 7 import any_helper
8 import cpp_util 8 import cpp_util
9 import schema_util 9 import schema_util
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 If REF types from different namespaces are referenced, will resolve 112 If REF types from different namespaces are referenced, will resolve
113 using self._type_namespaces. 113 using self._type_namespaces.
114 114
115 Use pad_for_generics when using as a generic to avoid operator ambiguity. 115 Use pad_for_generics when using as a generic to avoid operator ambiguity.
116 116
117 Use wrap_optional to wrap the type in a scoped_ptr<T> if the Property is 117 Use wrap_optional to wrap the type in a scoped_ptr<T> if the Property is
118 optional. 118 optional.
119 """ 119 """
120 cpp_type = None 120 cpp_type = None
121 force_wrapping = False
122 if prop.type_ == PropertyType.REF: 121 if prop.type_ == PropertyType.REF:
123 dependency_namespace = self._ResolveTypeNamespace(prop.ref_type) 122 dependency_namespace = self._ResolveTypeNamespace(prop.ref_type)
124 if not dependency_namespace: 123 if not dependency_namespace:
125 raise KeyError('Cannot find referenced type: %s' % prop.ref_type) 124 raise KeyError('Cannot find referenced type: %s' % prop.ref_type)
126 if self._namespace != dependency_namespace: 125 if self._namespace != dependency_namespace:
127 cpp_type = '%s::%s' % (self._cpp_namespaces[dependency_namespace], 126 cpp_type = '%s::%s' % (self._cpp_namespaces[dependency_namespace],
128 schema_util.StripSchemaNamespace(prop.ref_type)) 127 schema_util.StripSchemaNamespace(prop.ref_type))
129 else: 128 else:
130 cpp_type = schema_util.StripSchemaNamespace(prop.ref_type) 129 cpp_type = schema_util.StripSchemaNamespace(prop.ref_type)
131 elif prop.type_ == PropertyType.BOOLEAN: 130 elif prop.type_ == PropertyType.BOOLEAN:
(...skipping 17 matching lines...) Expand all
149 if item_type.type_ == PropertyType.REF: 148 if item_type.type_ == PropertyType.REF:
150 item_type = self.GetReferencedProperty(item_type) 149 item_type = self.GetReferencedProperty(item_type)
151 if item_type.type_ in ( 150 if item_type.type_ in (
152 PropertyType.REF, PropertyType.ANY, PropertyType.OBJECT): 151 PropertyType.REF, PropertyType.ANY, PropertyType.OBJECT):
153 cpp_type = 'std::vector<linked_ptr<%s> > ' 152 cpp_type = 'std::vector<linked_ptr<%s> > '
154 else: 153 else:
155 cpp_type = 'std::vector<%s> ' 154 cpp_type = 'std::vector<%s> '
156 cpp_type = cpp_type % self.GetType( 155 cpp_type = cpp_type % self.GetType(
157 prop.item_type, pad_for_generics=True) 156 prop.item_type, pad_for_generics=True)
158 elif prop.type_ == PropertyType.BINARY: 157 elif prop.type_ == PropertyType.BINARY:
159 # Since base::BinaryValue's are immutable, we wrap them in a scoped_ptr to 158 cpp_type = 'std::string'
160 # allow them to be modified after the fact.
161 force_wrapping = True
162 cpp_type = 'base::BinaryValue'
163 else: 159 else:
164 raise NotImplementedError(prop.type_) 160 raise NotImplementedError(prop.type_)
165 161
166 # Enums aren't wrapped because C++ won't allow it. Optional enums have a 162 # Enums aren't wrapped because C++ won't allow it. Optional enums have a
167 # NONE value generated instead. 163 # NONE value generated instead.
168 if force_wrapping or (wrap_optional and prop.optional and prop.type_ != 164 if wrap_optional and prop.optional and prop.type_ != PropertyType.ENUM:
169 PropertyType.ENUM):
170 cpp_type = 'scoped_ptr<%s> ' % cpp_type 165 cpp_type = 'scoped_ptr<%s> ' % cpp_type
171 if pad_for_generics: 166 if pad_for_generics:
172 return cpp_type 167 return cpp_type
173 return cpp_type.strip() 168 return cpp_type.strip()
174 169
175 def GenerateForwardDeclarations(self): 170 def GenerateForwardDeclarations(self):
176 """Returns the forward declarations for self._namespace. 171 """Returns the forward declarations for self._namespace.
177 172
178 Use after GetRootNamespaceStart. Assumes all namespaces are relative to 173 Use after GetRootNamespaceStart. Assumes all namespaces are relative to
179 self._root_namespace. 174 self._root_namespace.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 """ 302 """
308 if type_ == PropertyType.BOOLEAN: 303 if type_ == PropertyType.BOOLEAN:
309 return 'bool' 304 return 'bool'
310 elif type_ == PropertyType.INTEGER: 305 elif type_ == PropertyType.INTEGER:
311 return 'int' 306 return 'int'
312 elif type_ == PropertyType.DOUBLE: 307 elif type_ == PropertyType.DOUBLE:
313 return 'double' 308 return 'double'
314 elif type_ == PropertyType.STRING: 309 elif type_ == PropertyType.STRING:
315 return 'char*' 310 return 'char*'
316 raise Exception(type_ + ' is not primitive') 311 raise Exception(type_ + ' is not primitive')
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698