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

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

Issue 10790040: JSON Schema Compiler now supports conversion from Choice to base::Value. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
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 9
10 class HGenerator(object): 10 class HGenerator(object):
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 if type_.from_client: 208 if type_.from_client:
209 (c.Comment('Returns a new base::DictionaryValue representing the' 209 (c.Comment('Returns a new base::DictionaryValue representing the'
210 ' serialized form of this %s object. Passes ' 210 ' serialized form of this %s object. Passes '
211 'ownership to caller.' % classname) 211 'ownership to caller.' % classname)
212 .Append('scoped_ptr<base::DictionaryValue> ToValue() const;') 212 .Append('scoped_ptr<base::DictionaryValue> ToValue() const;')
213 ) 213 )
214 214
215 (c.Eblock() 215 (c.Eblock()
216 .Sblock(' private:') 216 .Sblock(' private:')
217 .Concat(self._GeneratePrivatePropertyStructures(
218 type_.properties.values()))
219 .Append()
217 .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);') 220 .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);')
218 .Eblock('};') 221 .Eblock('};')
219 ) 222 )
220 c.Substitute({'classname': classname}) 223 c.Substitute({'classname': classname})
221 return c 224 return c
222 225
223 def _GenerateEvent(self, event): 226 def _GenerateEvent(self, event):
224 """Generates the namespaces for an event. 227 """Generates the namespaces for an event.
225 """ 228 """
226 c = Code() 229 c = Code()
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 create_enum_value = ('scoped_ptr<base::Value> CreateEnumValue(%s %s);' % 299 create_enum_value = ('scoped_ptr<base::Value> CreateEnumValue(%s %s);' %
297 (enum_name, prop.unix_name)) 300 (enum_name, prop.unix_name))
298 # If the property is from the UI then we're in a struct so this function 301 # If the property is from the UI then we're in a struct so this function
299 # should be static. If it's from the client, then we're just in a 302 # should be static. If it's from the client, then we're just in a
300 # namespace so we can't have the static keyword. 303 # namespace so we can't have the static keyword.
301 if prop.from_json: 304 if prop.from_json:
302 create_enum_value = 'static ' + create_enum_value 305 create_enum_value = 'static ' + create_enum_value
303 c.Append(create_enum_value) 306 c.Append(create_enum_value)
304 return c 307 return c
305 308
309 def _GeneratePrivatePropertyStructures(self, props):
310 """Generate the private structures required by a property such as OBJECT
311 classes and enums.
312 """
313 c = Code()
314 for prop in props:
315 if prop.type_ == PropertyType.ARRAY:
316 c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type]))
317 c.Append()
318 elif prop.type_ == PropertyType.CHOICES:
319 # We only need GetChoiceValue() if there is a ToValue() method.
320 if prop.from_json and prop.from_client:
not at google - send to devlin 2012/07/19 01:48:22 ditto, why prop.from_json?
chebert 2012/07/19 21:06:17 see cc_generator comment. On 2012/07/19 01:48:22,
321 c.Append('scoped_ptr<base::Value> GetChoiceValue(%s) const;' %
not at google - send to devlin 2012/07/19 01:48:22 static?
chebert 2012/07/19 21:06:17 see cc_generator comment. On 2012/07/19 01:48:22,
322 cpp_util.GetParameterDeclaration(prop,
323 self._cpp_type_generator.GetChoicesEnumType(prop)))
324 return c
325
306 def _GenerateCreateCallbackArguments(self, function): 326 def _GenerateCreateCallbackArguments(self, function):
307 """Generates functions for passing paramaters to a callback. 327 """Generates functions for passing paramaters to a callback.
308 """ 328 """
309 c = Code() 329 c = Code()
310 params = function.params 330 params = function.params
311 c.Concat(self._GeneratePropertyStructures(params)) 331 c.Concat(self._GeneratePropertyStructures(params))
312 332
313 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params) 333 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params)
314 for param_list in param_lists: 334 for param_list in param_lists:
315 declaration_list = [] 335 declaration_list = []
316 for param in param_list: 336 for param in param_list:
317 if param.description: 337 if param.description:
318 c.Comment(param.description) 338 c.Comment(param.description)
319 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration( 339 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration(
320 param, self._cpp_type_generator.GetType(param))) 340 param, self._cpp_type_generator.GetType(param)))
321 c.Append('scoped_ptr<base::ListValue> Create(%s);' % 341 c.Append('scoped_ptr<base::ListValue> Create(%s);' %
322 ', '.join(declaration_list)) 342 ', '.join(declaration_list))
323 return c 343 return c
324 344
325 def _GenerateFunctionResults(self, callback): 345 def _GenerateFunctionResults(self, callback):
326 """Generates namespace for passing a function's result back. 346 """Generates namespace for passing a function's result back.
327 """ 347 """
328 c = Code() 348 c = Code()
329 (c.Sblock('namespace Results {') 349 (c.Sblock('namespace Results {')
330 .Concat(self._GenerateCreateCallbackArguments(callback)) 350 .Concat(self._GenerateCreateCallbackArguments(callback))
331 .Eblock('};') 351 .Eblock('};')
332 ) 352 )
333 return c 353 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698