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

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

Issue 10796114: Added ToJson to JSON schema compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed scope Created 8 years, 4 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 .Eblock('};') 223 .Eblock('};')
224 ) 224 )
225 c.Substitute({'classname': classname}) 225 c.Substitute({'classname': classname})
226 return c 226 return c
227 227
228 def _GenerateEvent(self, event): 228 def _GenerateEvent(self, event):
229 """Generates the namespaces for an event. 229 """Generates the namespaces for an event.
230 """ 230 """
231 c = Code() 231 c = Code()
232 (c.Sblock('namespace %s {' % cpp_util.Classname(event.name)) 232 (c.Sblock('namespace %s {' % cpp_util.Classname(event.name))
233 .Concat(self._GenerateCreateCallbackArguments(event)) 233 .Concat(self._GenerateCreateCallbackArguments(event,
234 generate_to_json=True))
234 .Eblock('};') 235 .Eblock('};')
235 ) 236 )
236 return c 237 return c
237 238
238 def _GenerateFunction(self, function): 239 def _GenerateFunction(self, function):
239 """Generates the namespaces and structs for a function. 240 """Generates the namespaces and structs for a function.
240 """ 241 """
241 c = Code() 242 c = Code()
242 (c.Sblock('namespace %s {' % cpp_util.Classname(function.name)) 243 (c.Sblock('namespace %s {' % cpp_util.Classname(function.name))
243 .Concat(self._GenerateFunctionParams(function)) 244 .Concat(self._GenerateFunctionParams(function))
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 if prop.type_ == PropertyType.ARRAY: 318 if prop.type_ == PropertyType.ARRAY:
318 c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type])) 319 c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type]))
319 c.Append() 320 c.Append()
320 elif prop.type_ == PropertyType.CHOICES: 321 elif prop.type_ == PropertyType.CHOICES:
321 # We only need GetChoiceValue() if there is a ToValue() method. 322 # We only need GetChoiceValue() if there is a ToValue() method.
322 if prop.from_client: 323 if prop.from_client:
323 c.Append('scoped_ptr<base::Value> Get%sChoiceValue() const;' % ( 324 c.Append('scoped_ptr<base::Value> Get%sChoiceValue() const;' % (
324 cpp_util.Classname(prop.name))) 325 cpp_util.Classname(prop.name)))
325 return c 326 return c
326 327
327 def _GenerateCreateCallbackArguments(self, function): 328 def _GenerateCreateCallbackArguments(self, function, generate_to_json=False):
328 """Generates functions for passing paramaters to a callback. 329 """Generates functions for passing paramaters to a callback.
329 """ 330 """
330 c = Code() 331 c = Code()
331 params = function.params 332 params = function.params
332 c.Concat(self._GeneratePropertyStructures(params)) 333 c.Concat(self._GeneratePropertyStructures(params))
333 334
334 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params) 335 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params)
335 for param_list in param_lists: 336 for param_list in param_lists:
336 declaration_list = [] 337 declaration_list = []
337 for param in param_list: 338 for param in param_list:
338 if param.description: 339 if param.description:
339 c.Comment(param.description) 340 c.Comment(param.description)
340 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration( 341 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration(
341 param, self._cpp_type_generator.GetType(param))) 342 param, self._cpp_type_generator.GetType(param)))
342 c.Append('scoped_ptr<base::ListValue> Create(%s);' % 343 c.Append('scoped_ptr<base::ListValue> Create(%s);' %
343 ', '.join(declaration_list)) 344 ', '.join(declaration_list))
345 if generate_to_json:
346 c.Append('std::string ToJson(%s);' % ', '.join(declaration_list))
344 return c 347 return c
345 348
346 def _GenerateFunctionResults(self, callback): 349 def _GenerateFunctionResults(self, callback):
347 """Generates namespace for passing a function's result back. 350 """Generates namespace for passing a function's result back.
348 """ 351 """
349 c = Code() 352 c = Code()
350 (c.Sblock('namespace Results {') 353 (c.Sblock('namespace Results {')
351 .Concat(self._GenerateCreateCallbackArguments(callback)) 354 .Concat(self._GenerateCreateCallbackArguments(callback))
352 .Eblock('};') 355 .Eblock('};')
353 ) 356 )
354 return c 357 return c
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cpp_util.py ('k') | tools/json_schema_compiler/test/content_settings.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698