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

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

Issue 1128523003: Add support for passing errors through PopulateArrayFromList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated JSON schema tests. Created 5 years, 7 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/test/error_generation_unittest.cc » ('j') | 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 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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 c.Sblock('else {') 771 c.Sblock('else {')
772 item_type = self._type_helper.FollowRef(underlying_type.item_type) 772 item_type = self._type_helper.FollowRef(underlying_type.item_type)
773 if item_type.property_type == PropertyType.ENUM: 773 if item_type.property_type == PropertyType.ENUM:
774 c.Concat(self._GenerateListValueToEnumArrayConversion( 774 c.Concat(self._GenerateListValueToEnumArrayConversion(
775 item_type, 775 item_type,
776 'list', 776 'list',
777 dst_var, 777 dst_var,
778 failure_value, 778 failure_value,
779 is_ptr=is_ptr)) 779 is_ptr=is_ptr))
780 else: 780 else:
781 c.Sblock('if (!%s) {' % self._util_cc_helper.PopulateArrayFromList( 781 c.Sblock('if (!%s(%s)) {' % (
782 'list', 782 self._util_cc_helper.PopulateArrayFromListFunction(is_ptr),
783 dst_var, 783 self._GenerateArgs(('*list', '&%(dst_var)s'))))
784 is_ptr))
785 c.Concat(self._GenerateError( 784 c.Concat(self._GenerateError(
786 '"unable to populate array \'%%(parent_key)s\'"')) 785 '"unable to populate array \'%%(parent_key)s\'"'))
787 if is_ptr and self._generate_error_messages: 786 if is_ptr and self._generate_error_messages:
788 c.Append('%(dst_var)s.reset();') 787 c.Append('%(dst_var)s.reset();')
789 else: 788 else:
790 c.Append('return %(failure_value)s;') 789 c.Append('return %(failure_value)s;')
791 c.Eblock('}') 790 c.Eblock('}')
792 c.Eblock('}') 791 c.Eblock('}')
793 elif underlying_type.property_type == PropertyType.CHOICES: 792 elif underlying_type.property_type == PropertyType.CHOICES:
794 if is_ptr: 793 if is_ptr:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 if self._generate_error_messages: 1067 if self._generate_error_messages:
1069 params = list(params) + ['base::string16* error'] 1068 params = list(params) + ['base::string16* error']
1070 return ', '.join(str(p) for p in params) 1069 return ', '.join(str(p) for p in params)
1071 1070
1072 def _GenerateArgs(self, args): 1071 def _GenerateArgs(self, args):
1073 """Builds the argument list for a function, given an array of arguments. 1072 """Builds the argument list for a function, given an array of arguments.
1074 """ 1073 """
1075 if self._generate_error_messages: 1074 if self._generate_error_messages:
1076 args = list(args) + ['error'] 1075 args = list(args) + ['error']
1077 return ', '.join(str(a) for a in args) 1076 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/test/error_generation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698