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

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

Issue 10022005: Let json schema compiler handle using arrays as types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor style changes Created 8 years, 8 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/test/browserAction.json ('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 class UtilCCHelper(object): 7 class UtilCCHelper(object):
8 """A util class that generates code that uses 8 """A util class that generates code that uses
9 tools/json_schema_compiler/util.cc. 9 tools/json_schema_compiler/util.cc.
10 """ 10 """
(...skipping 17 matching lines...) Expand all
28 sub['type'] = self._type_manager.GetType(prop) 28 sub['type'] = self._type_manager.GetType(prop)
29 if array_prop.optional: 29 if array_prop.optional:
30 val = ('%(namespace)s::PopulateOptionalArrayFromDictionary' 30 val = ('%(namespace)s::PopulateOptionalArrayFromDictionary'
31 '(*%(src)s, "%(name)s", &%(dst)s)') 31 '(*%(src)s, "%(name)s", &%(dst)s)')
32 else: 32 else:
33 val = ('%(namespace)s::PopulateArrayFromDictionary' 33 val = ('%(namespace)s::PopulateArrayFromDictionary'
34 '(*%(src)s, "%(name)s", &%(dst)s)') 34 '(*%(src)s, "%(name)s", &%(dst)s)')
35 35
36 return val % sub 36 return val % sub
37 37
38 def PopulateArrayFromList(self, array_prop, src, dst): 38 def PopulateArrayFromList(self, array_prop, src, dst, optional):
39 """Generates code to get an array from src into dst. 39 """Generates code to get an array from src into dst.
40 40
41 src: ListValue* 41 src: ListValue*
42 dst: std::vector or scoped_ptr<std::vector> 42 dst: std::vector or scoped_ptr<std::vector>
43 """ 43 """
44 prop = array_prop.item_type 44 prop = array_prop.item_type
45 sub = { 45 sub = {
46 'namespace': API_UTIL_NAMESPACE, 46 'namespace': API_UTIL_NAMESPACE,
47 'src': src, 47 'src': src,
48 'dst': dst, 48 'dst': dst,
49 'type': self._type_manager.GetType(prop), 49 'type': self._type_manager.GetType(prop),
50 } 50 }
51 51
52 if array_prop.optional: 52 if optional:
53 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)' 53 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)'
54 else: 54 else:
55 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)' 55 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)'
56 56
57 return val % sub 57 return val % sub
58 58
59 def CreateValueFromArray(self, array_prop, src): 59 def CreateValueFromArray(self, array_prop, src, optional):
60 """Generates code to create a scoped_pt<Value> from the array at src. 60 """Generates code to create a scoped_pt<Value> from the array at src.
61 61
62 src: std::vector or scoped_ptr<std::vector> 62 src: std::vector or scoped_ptr<std::vector>
63 """ 63 """
64 prop = array_prop.item_type 64 prop = array_prop.item_type
65 sub = { 65 sub = {
66 'namespace': API_UTIL_NAMESPACE, 66 'namespace': API_UTIL_NAMESPACE,
67 'src': src, 67 'src': src,
68 'type': self._type_manager.GetType(prop), 68 'type': self._type_manager.GetType(prop),
69 } 69 }
70 70
71 if array_prop.optional: 71 if optional:
72 val = '%(namespace)s::CreateValueFromOptionalArray(%(src)s)' 72 val = '%(namespace)s::CreateValueFromOptionalArray(%(src)s)'
73 else: 73 else:
74 val = '%(namespace)s::CreateValueFromArray(%(src)s)' 74 val = '%(namespace)s::CreateValueFromArray(%(src)s)'
75 75
76 return val % sub 76 return val % sub
77 77
78 def GetIncludePath(self): 78 def GetIncludePath(self):
79 return '#include "tools/json_schema_compiler/util.h"' 79 return '#include "tools/json_schema_compiler/util.h"'
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/browserAction.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698