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

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

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rework, add a couple of tests Created 8 years, 10 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/cpp_util.py ('k') | tools/json_schema_compiler/model.py » ('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 model import PropertyType 5 from model import PropertyType
6 import code 6 import code
7 import cpp_util 7 import cpp_util
8 import os 8 import os
9 9
10 class HGenerator(object): 10 class HGenerator(object):
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 self._cpp_type_generator.GetType(prop, wrap_optional=True), 90 self._cpp_type_generator.GetType(prop, wrap_optional=True),
91 prop.unix_name)) 91 prop.unix_name))
92 c.Append() 92 c.Append()
93 # Generate the enums needed for any fields with "choices" 93 # Generate the enums needed for any fields with "choices"
94 for prop in props: 94 for prop in props:
95 if prop.type_ == PropertyType.CHOICES: 95 if prop.type_ == PropertyType.CHOICES:
96 c.Sblock('enum %(enum_type)s {') 96 c.Sblock('enum %(enum_type)s {')
97 c.Append(self._cpp_type_generator.GetChoiceEnumNoneValue(prop) + ',') 97 c.Append(self._cpp_type_generator.GetChoiceEnumNoneValue(prop) + ',')
98 for choice in prop.choices.values(): 98 for choice in prop.choices.values():
99 c.Append( 99 c.Append(
100 self._cpp_type_generator.GetChoiceEnumValue( prop, choice.type_) 100 self._cpp_type_generator.GetChoiceEnumValue(prop, choice.type_)
101 + ',') 101 + ',')
102 (c.Eblock('};') 102 (c.Eblock('};')
103 .Append() 103 .Append()
104 .Append('%(enum_type)s %(name)s_type;') 104 .Append('%(enum_type)s %(name)s_type;')
105 ) 105 )
106 c.Substitute({ 106 c.Substitute({
107 'enum_type': self._cpp_type_generator.GetChoicesEnumType(prop), 107 'enum_type': self._cpp_type_generator.GetChoicesEnumType(prop),
108 'name': prop.unix_name 108 'name': prop.unix_name
109 }) 109 })
110 return c 110 return c
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if not params: 189 if not params:
190 c.Append('Value* Create();') 190 c.Append('Value* Create();')
191 else: 191 else:
192 # If there is a single parameter, this is straightforward. However, if 192 # If there is a single parameter, this is straightforward. However, if
193 # the callback parameter is of 'choices', this generates a Create method 193 # the callback parameter is of 'choices', this generates a Create method
194 # for each choice. This works because only 1 choice can be returned at a 194 # for each choice. This works because only 1 choice can be returned at a
195 # time. 195 # time.
196 for param in self._cpp_type_generator.GetExpandedChoicesInParams(params): 196 for param in self._cpp_type_generator.GetExpandedChoicesInParams(params):
197 if param.description: 197 if param.description:
198 c.Comment(param.description) 198 c.Comment(param.description)
199 c.Append('Value* Create(%s);' % 199 if param.type_ == PropertyType.OBJECT:
200 cpp_util.GetConstParameterDeclaration( 200 raise NotImplementedError('OBJECT return type not supported')
201 param, self._cpp_type_generator)) 201 c.Append('Value* Create(%s);' % cpp_util.GetParameterDeclaration(
202 param, self._cpp_type_generator.GetType(param)))
202 c.Eblock('};') 203 c.Eblock('};')
203 204
204 return c 205 return c
205 206
206 def _GenerateIfndefName(self): 207 def _GenerateIfndefName(self):
207 """Formats a path and filename as a #define name. 208 """Formats a path and filename as a #define name.
208 209
209 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. 210 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
210 """ 211 """
211 return (('%s_%s_H__' % 212 return (('%s_%s_H__' %
212 (self._namespace.source_file_dir, self._target_namespace)) 213 (self._namespace.source_file_dir, self._target_namespace))
213 .upper().replace(os.sep, '_')) 214 .upper().replace(os.sep, '_'))
214 215
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cpp_util.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698