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

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

Issue 12041098: Initial commit of the Dart Chrome Extension APIs generators (Closed) Base URL: http://git.chromium.org/chromium/src.git@file_path_bugfix
Patch Set: Added wrappers for more types of functions (including events, callbacks and lists) Created 7 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
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, Type 6 from model import PropertyType, Type
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):
11 def __init__(self, type_generator):
12 self._type_generator = type_generator
13
14 def Generate(self, namespace):
15 return _Generator(namespace, self._type_generator).Generate()
16
17 class _Generator(object):
11 """A .h generator for a namespace. 18 """A .h generator for a namespace.
12 """ 19 """
13 def __init__(self, namespace, cpp_type_generator): 20 def __init__(self, namespace, cpp_type_generator):
14 self._type_helper = cpp_type_generator 21 self._type_helper = cpp_type_generator
15 self._namespace = namespace 22 self._namespace = namespace
16 self._target_namespace = ( 23 self._target_namespace = (
17 self._type_helper.GetCppNamespaceName(self._namespace)) 24 self._type_helper.GetCppNamespaceName(self._namespace))
18 25
19 def Generate(self): 26 def Generate(self):
20 """Generates a Code object with the .h for a single namespace. 27 """Generates a Code object with the .h for a single namespace.
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if type_.additional_properties.property_type == PropertyType.ANY: 242 if type_.additional_properties.property_type == PropertyType.ANY:
236 c.Append('base::DictionaryValue additional_properties;') 243 c.Append('base::DictionaryValue additional_properties;')
237 else: 244 else:
238 (c.Cblock(self._GenerateType(type_.additional_properties)) 245 (c.Cblock(self._GenerateType(type_.additional_properties))
239 .Append('std::map<std::string, %s> additional_properties;' % 246 .Append('std::map<std::string, %s> additional_properties;' %
240 cpp_util.PadForGenerics( 247 cpp_util.PadForGenerics(
241 self._type_helper.GetCppType(type_.additional_properties, 248 self._type_helper.GetCppType(type_.additional_properties,
242 is_in_container=True))) 249 is_in_container=True)))
243 ) 250 )
244 (c.Eblock() 251 (c.Eblock()
252 .Append()
245 .Sblock(' private:') 253 .Sblock(' private:')
246 .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);') 254 .Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);')
247 .Eblock('};') 255 .Eblock('};')
248 ) 256 )
249 elif type_.property_type == PropertyType.CHOICES: 257 elif type_.property_type == PropertyType.CHOICES:
250 if type_.description: 258 if type_.description:
251 c.Comment(type_.description) 259 c.Comment(type_.description)
252 # Choices are modelled with optional fields for each choice. Exactly one 260 # Choices are modelled with optional fields for each choice. Exactly one
253 # field of the choice is guaranteed to be set by the compiler. 261 # field of the choice is guaranteed to be set by the compiler.
254 (c.Sblock('struct %(classname)s {') 262 (c.Sblock('struct %(classname)s {')
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return Code() 321 return Code()
314 322
315 c = Code() 323 c = Code()
316 (c.Sblock('struct Params {') 324 (c.Sblock('struct Params {')
317 .Append('static scoped_ptr<Params> Create(const base::ListValue& args);') 325 .Append('static scoped_ptr<Params> Create(const base::ListValue& args);')
318 .Append('~Params();') 326 .Append('~Params();')
319 .Append() 327 .Append()
320 .Cblock(self._GenerateTypes(p.type_ for p in function.params)) 328 .Cblock(self._GenerateTypes(p.type_ for p in function.params))
321 .Cblock(self._GenerateFields(function.params)) 329 .Cblock(self._GenerateFields(function.params))
322 .Eblock() 330 .Eblock()
331 .Append()
323 .Sblock(' private:') 332 .Sblock(' private:')
324 .Append('Params();') 333 .Append('Params();')
325 .Append() 334 .Append()
326 .Append('DISALLOW_COPY_AND_ASSIGN(Params);') 335 .Append('DISALLOW_COPY_AND_ASSIGN(Params);')
327 .Eblock('};') 336 .Eblock('};')
328 ) 337 )
329 return c 338 return c
330 339
331 def _GenerateTypes(self, types, is_toplevel=False, generate_typedefs=False): 340 def _GenerateTypes(self, types, is_toplevel=False, generate_typedefs=False):
332 """Generate the structures required by a property such as OBJECT classes 341 """Generate the structures required by a property such as OBJECT classes
(...skipping 26 matching lines...) Expand all
359 def _GenerateFunctionResults(self, callback): 368 def _GenerateFunctionResults(self, callback):
360 """Generates namespace for passing a function's result back. 369 """Generates namespace for passing a function's result back.
361 """ 370 """
362 c = Code() 371 c = Code()
363 (c.Append('namespace Results {') 372 (c.Append('namespace Results {')
364 .Append() 373 .Append()
365 .Concat(self._GenerateCreateCallbackArguments(callback)) 374 .Concat(self._GenerateCreateCallbackArguments(callback))
366 .Append('} // namespace Results') 375 .Append('} // namespace Results')
367 ) 376 )
368 return c 377 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698