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

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: 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
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.
(...skipping 18 matching lines...) Expand all
29 sub['type'] = self._type_manager.GetCppType(prop), 29 sub['type'] = self._type_manager.GetCppType(prop),
30 if array_prop.optional: 30 if array_prop.optional:
31 val = ('%(namespace)s::PopulateOptionalArrayFromDictionary' 31 val = ('%(namespace)s::PopulateOptionalArrayFromDictionary'
32 '(*%(src)s, "%(name)s", &%(dst)s)') 32 '(*%(src)s, "%(name)s", &%(dst)s)')
33 else: 33 else:
34 val = ('%(namespace)s::PopulateArrayFromDictionary' 34 val = ('%(namespace)s::PopulateArrayFromDictionary'
35 '(*%(src)s, "%(name)s", &%(dst)s)') 35 '(*%(src)s, "%(name)s", &%(dst)s)')
36 36
37 return val % sub 37 return val % sub
38 38
39 def PopulateArrayFromList(self, src, dst, optional): 39 def PopulateArrayFromList(self, src, dst, optional, items_are_binary):
not at google - send to devlin 2015/01/13 18:15:14 For boolean flags I prefer to make it explicit, li
pneubeck (no reviews) 2015/01/14 10:54:15 Not sure how you could /force/ the caller to use n
40 """Generates code to get an array from src into dst. 40 """Generates code to get an array from src into dst.
41 41
42 src: ListValue* 42 src: ListValue*
43 dst: std::vector or scoped_ptr<std::vector> 43 dst: std::vector or scoped_ptr<std::vector>
44 """ 44 """
45
46 binary_tag = 'ITEMS_ARE_NOT_BINARY';
47 if items_are_binary:
48 binary_tag = 'ITEMS_ARE_BINARY';
45 if optional: 49 if optional:
46 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)' 50 val = ('%(namespace)s::PopulateOptionalArrayFromList'
51 '(*%(src)s, %(namespace)s::%(binary_tag)s(), &%(dst)s)')
47 else: 52 else:
48 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)' 53 val = ('%(namespace)s::PopulateArrayFromList'
54 '(*%(src)s, %(namespace)s::%(binary_tag)s(), &%(dst)s)')
not at google - send to devlin 2015/01/13 18:15:14 Given there's even more duplication, you should be
pneubeck (no reviews) 2015/01/14 10:54:15 Slight variation of what you proposed because conc
49 return val % { 55 return val % {
56 'binary_tag': binary_tag,
50 'namespace': _API_UTIL_NAMESPACE, 57 'namespace': _API_UTIL_NAMESPACE,
51 'src': src, 58 'src': src,
52 'dst': dst 59 'dst': dst
53 } 60 }
54 61
55 def CreateValueFromArray(self, src, optional): 62 def CreateValueFromArray(self, src, optional):
56 """Generates code to create a scoped_pt<Value> from the array at src. 63 """Generates code to create a scoped_pt<Value> from the array at src.
57 64
58 |src| The variable to convert, either a vector or scoped_ptr<vector>. 65 |src| The variable to convert, either a vector or scoped_ptr<vector>.
59 |optional| Whether |type_| was optional. Optional types are pointers so 66 |optional| Whether |type_| was optional. Optional types are pointers so
60 must be treated differently. 67 must be treated differently.
61 """ 68 """
62 if optional: 69 if optional:
63 name = 'CreateValueFromOptionalArray' 70 name = 'CreateValueFromOptionalArray'
64 else: 71 else:
65 name = 'CreateValueFromArray' 72 name = 'CreateValueFromArray'
66 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src) 73 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
67 74
68 def GetIncludePath(self): 75 def GetIncludePath(self):
69 return '#include "tools/json_schema_compiler/util.h"' 76 return '#include "tools/json_schema_compiler/util.h"'
70 77
71 def GetValueTypeString(self, value, is_ptr=False): 78 def GetValueTypeString(self, value, is_ptr=False):
72 call = '.GetType()' 79 call = '.GetType()'
73 if is_ptr: 80 if is_ptr:
74 call = '->GetType()' 81 call = '->GetType()'
75 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call) 82 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)
OLDNEW
« tools/json_schema_compiler/util.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