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

Side by Side Diff: tools/json_schema_compiler/util_cc_helper.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 | « tools/json_schema_compiler/util.cc ('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 _API_UTIL_NAMESPACE = 'json_schema_compiler::util' 5 _API_UTIL_NAMESPACE = 'json_schema_compiler::util'
6 6
7 7
8 class UtilCCHelper(object): 8 class UtilCCHelper(object):
9 """A util class that generates code that uses 9 """A util class that generates code that uses
10 tools/json_schema_compiler/util.cc. 10 tools/json_schema_compiler/util.cc.
11 """ 11 """
12 def __init__(self, type_manager): 12 def __init__(self, type_manager):
13 self._type_manager = type_manager 13 self._type_manager = type_manager
14 14
15 def PopulateArrayFromList(self, src, dst, optional): 15 def PopulateArrayFromListFunction(self, optional):
16 """Generates code to get an array from src into dst. 16 """Returns the function to turn a list into a vector.
17
18 src: ListValue*
19 dst: std::vector or scoped_ptr<std::vector>
20 """ 17 """
21 populate_list_fn = ('PopulateOptionalArrayFromList' if optional 18 populate_list_fn = ('PopulateOptionalArrayFromList' if optional
22 else 'PopulateArrayFromList') 19 else 'PopulateArrayFromList')
23 return ('%s::%s(*%s, &%s)') % (_API_UTIL_NAMESPACE, 20 return ('%s::%s') % (_API_UTIL_NAMESPACE, populate_list_fn)
24 populate_list_fn,
25 src,
26 dst)
27 21
28 def CreateValueFromArray(self, src, optional): 22 def CreateValueFromArray(self, src, optional):
29 """Generates code to create a scoped_pt<Value> from the array at src. 23 """Generates code to create a scoped_pt<Value> from the array at src.
30 24
31 |src| The variable to convert, either a vector or scoped_ptr<vector>. 25 |src| The variable to convert, either a vector or scoped_ptr<vector>.
32 |optional| Whether |type_| was optional. Optional types are pointers so 26 |optional| Whether |type_| was optional. Optional types are pointers so
33 must be treated differently. 27 must be treated differently.
34 """ 28 """
35 if optional: 29 if optional:
36 name = 'CreateValueFromOptionalArray' 30 name = 'CreateValueFromOptionalArray'
37 else: 31 else:
38 name = 'CreateValueFromArray' 32 name = 'CreateValueFromArray'
39 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src) 33 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
40 34
41 def GetIncludePath(self): 35 def GetIncludePath(self):
42 return '#include "tools/json_schema_compiler/util.h"' 36 return '#include "tools/json_schema_compiler/util.h"'
43 37
44 def GetValueTypeString(self, value, is_ptr=False): 38 def GetValueTypeString(self, value, is_ptr=False):
45 call = '.GetType()' 39 call = '.GetType()'
46 if is_ptr: 40 if is_ptr:
47 call = '->GetType()' 41 call = '->GetType()'
48 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call) 42 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698