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

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

Issue 1151763007: Add the boilerplate for actions to File System Provider API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 5 years, 6 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 413
414 def _GenerateChoiceTypeToValue(self, cpp_namespace, type_): 414 def _GenerateChoiceTypeToValue(self, cpp_namespace, type_):
415 """Generates a function that serializes a choice-representing type 415 """Generates a function that serializes a choice-representing type
416 into a base::Value. 416 into a base::Value.
417 """ 417 """
418 c = Code() 418 c = Code()
419 c.Sblock('scoped_ptr<base::Value> %s::ToValue() const {' % cpp_namespace) 419 c.Sblock('scoped_ptr<base::Value> %s::ToValue() const {' % cpp_namespace)
420 c.Append('scoped_ptr<base::Value> result;') 420 c.Append('scoped_ptr<base::Value> result;')
421 for choice in type_.choices: 421 for choice in type_.choices:
422 choice_var = 'as_%s' % choice.unix_name 422 choice_var = 'as_%s' % choice.unix_name
423 # Enums cannot be wrapped with scoped_ptr, but the XXX_NONE enum value
424 # is equal to 0.
423 (c.Sblock('if (%s) {' % choice_var) 425 (c.Sblock('if (%s) {' % choice_var)
424 .Append('DCHECK(!result) << "Cannot set multiple choices for %s";' % 426 .Append('DCHECK(!result) << "Cannot set multiple choices for %s";' %
425 type_.unix_name) 427 type_.unix_name)
426 .Cblock(self._CreateValueFromType('result.reset(%s);', 428 .Cblock(self._CreateValueFromType('result.reset(%s);',
427 choice.name, 429 choice.name,
428 choice, 430 choice,
429 '*%s' % choice_var)) 431 choice_var,
432 True))
430 .Eblock('}') 433 .Eblock('}')
431 ) 434 )
432 (c.Append('DCHECK(result) << "Must set at least one choice for %s";' % 435 (c.Append('DCHECK(result) << "Must set at least one choice for %s";' %
433 type_.unix_name) 436 type_.unix_name)
434 .Append('return result.Pass();') 437 .Append('return result.Pass();')
435 .Eblock('}') 438 .Eblock('}')
436 ) 439 )
437 return c 440 return c
438 441
439 def _GenerateFunction(self, function): 442 def _GenerateFunction(self, function):
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 if self._generate_error_messages: 1073 if self._generate_error_messages:
1071 params = list(params) + ['base::string16* error'] 1074 params = list(params) + ['base::string16* error']
1072 return ', '.join(str(p) for p in params) 1075 return ', '.join(str(p) for p in params)
1073 1076
1074 def _GenerateArgs(self, args): 1077 def _GenerateArgs(self, args):
1075 """Builds the argument list for a function, given an array of arguments. 1078 """Builds the argument list for a function, given an array of arguments.
1076 """ 1079 """
1077 if self._generate_error_messages: 1080 if self._generate_error_messages:
1078 args = list(args) + ['error'] 1081 args = list(args) + ['error']
1079 return ', '.join(str(a) for a in args) 1082 return ', '.join(str(a) for a in args)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698