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

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

Issue 851673003: Cleanup: Some simplifications in json_schema_compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_dart_tests
Patch Set: Add unit test for GetAsBinary. Created 5 years, 11 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
« base/values.h ('K') | « 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 PopulateArrayFromList(self, src, dst, optional, items_are_binary=False):
16 """Generates code to get an array from src into dst. 16 """Generates code to get an array from src into dst.
17 17
18 src: ListValue* 18 src: ListValue*
19 dst: std::vector or scoped_ptr<std::vector> 19 dst: std::vector or scoped_ptr<std::vector>
20 """ 20 """
21 if optional: 21 populate_item_fn = ('PopulateStringFromBinaryValue' if items_are_binary
22 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)' 22 else 'PopulateItem')
23 else: 23 populate_list_fn = ('PopulateOptionalArrayFromList' if optional
24 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)' 24 else 'PopulateArrayFromList')
25 return val % { 25 return ('%s::%s(*%s, &%s::%s, &%s)') % (_API_UTIL_NAMESPACE,
26 'namespace': _API_UTIL_NAMESPACE, 26 populate_list_fn,
27 'src': src, 27 src,
28 'dst': dst 28 _API_UTIL_NAMESPACE,
29 } 29 populate_item_fn,
30 dst)
30 31
31 def CreateValueFromArray(self, src, optional): 32 def CreateValueFromArray(self, src, optional):
32 """Generates code to create a scoped_pt<Value> from the array at src. 33 """Generates code to create a scoped_pt<Value> from the array at src.
33 34
34 |src| The variable to convert, either a vector or scoped_ptr<vector>. 35 |src| The variable to convert, either a vector or scoped_ptr<vector>.
35 |optional| Whether |type_| was optional. Optional types are pointers so 36 |optional| Whether |type_| was optional. Optional types are pointers so
36 must be treated differently. 37 must be treated differently.
37 """ 38 """
38 if optional: 39 if optional:
39 name = 'CreateValueFromOptionalArray' 40 name = 'CreateValueFromOptionalArray'
40 else: 41 else:
41 name = 'CreateValueFromArray' 42 name = 'CreateValueFromArray'
42 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src) 43 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
43 44
44 def GetIncludePath(self): 45 def GetIncludePath(self):
45 return '#include "tools/json_schema_compiler/util.h"' 46 return '#include "tools/json_schema_compiler/util.h"'
46 47
47 def GetValueTypeString(self, value, is_ptr=False): 48 def GetValueTypeString(self, value, is_ptr=False):
48 call = '.GetType()' 49 call = '.GetType()'
49 if is_ptr: 50 if is_ptr:
50 call = '->GetType()' 51 call = '->GetType()'
51 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call) 52 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)
OLDNEW
« base/values.h ('K') | « tools/json_schema_compiler/util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698