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

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

Issue 10824002: JSON Schema Compiler supports functions as PropertyTypes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: bool function; becomes bool has_function; Created 8 years, 4 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 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 9
10 class HGenerator(object): 10 class HGenerator(object):
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 """ 149 """
150 c = Code() 150 c = Code()
151 # Generate the enums needed for any fields with "choices" 151 # Generate the enums needed for any fields with "choices"
152 for prop in props: 152 for prop in props:
153 if prop.type_ == PropertyType.CHOICES: 153 if prop.type_ == PropertyType.CHOICES:
154 enum_name = self._cpp_type_generator.GetChoicesEnumType(prop) 154 enum_name = self._cpp_type_generator.GetChoicesEnumType(prop)
155 c.Append('%s %s_type;' % (enum_name, prop.unix_name)) 155 c.Append('%s %s_type;' % (enum_name, prop.unix_name))
156 c.Append() 156 c.Append()
157 157
158 for prop in self._cpp_type_generator.ExpandParams(props): 158 for prop in self._cpp_type_generator.ExpandParams(props):
159 if prop.description: 159 if prop.type_ == PropertyType.FUNCTION and prop.optional:
160 c.Comment('Determines whether the given optional function was passed '
161 'as a parameter.')
not at google - send to devlin 2012/07/25 01:32:33 include the function name here, and include the ov
chebert 2012/07/25 18:38:30 Done.
162 elif prop.description:
160 c.Comment(prop.description) 163 c.Comment(prop.description)
161 c.Append('%s %s;' % ( 164 if prop.type_ == PropertyType.FUNCTION:
162 self._cpp_type_generator.GetType(prop, wrap_optional=True), 165 c.Append('bool has_%s;' % prop.unix_name)
not at google - send to devlin 2012/07/25 01:32:33 i think you only want this if it's optional too.
chebert 2012/07/25 18:38:30 Done.
163 prop.unix_name)) 166 else:
167 c.Append('%s %s;' % (
168 self._cpp_type_generator.GetType(prop, wrap_optional=True),
169 prop.unix_name))
164 c.Append() 170 c.Append()
165 return c 171 return c
166 172
167 def _GenerateType(self, type_): 173 def _GenerateType(self, type_):
168 """Generates a struct for a type. 174 """Generates a struct for a type.
169 """ 175 """
170 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) 176 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name))
171 c = Code() 177 c = Code()
172 178
173 if type_.functions: 179 if type_.functions:
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 350
345 def _GenerateFunctionResults(self, callback): 351 def _GenerateFunctionResults(self, callback):
346 """Generates namespace for passing a function's result back. 352 """Generates namespace for passing a function's result back.
347 """ 353 """
348 c = Code() 354 c = Code()
349 (c.Sblock('namespace Results {') 355 (c.Sblock('namespace Results {')
350 .Concat(self._GenerateCreateCallbackArguments(callback)) 356 .Concat(self._GenerateCreateCallbackArguments(callback))
351 .Eblock('};') 357 .Eblock('};')
352 ) 358 )
353 return c 359 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698