OLD | NEW |
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 |
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, cpp_namespace): | 11 def __init__(self, type_generator, cpp_namespace): |
12 self._type_generator = type_generator | 12 self._type_generator = type_generator |
13 self._cpp_namespace = cpp_namespace | 13 self._cpp_namespace = cpp_namespace |
14 | 14 |
15 def Generate(self, namespace): | 15 def Generate(self, namespace): |
16 return _Generator(namespace, | 16 return _Generator(namespace, |
17 self._type_generator, | 17 self._type_generator, |
18 self._cpp_namespace).Generate() | 18 self._cpp_namespace).Generate() |
19 | 19 |
| 20 |
20 class _Generator(object): | 21 class _Generator(object): |
21 """A .h generator for a namespace. | 22 """A .h generator for a namespace. |
22 """ | 23 """ |
23 def __init__(self, namespace, cpp_type_generator, cpp_namespace): | 24 def __init__(self, namespace, cpp_type_generator, cpp_namespace): |
24 self._namespace = namespace | 25 self._namespace = namespace |
25 self._type_helper = cpp_type_generator | 26 self._type_helper = cpp_type_generator |
26 self._cpp_namespace = cpp_namespace | 27 self._cpp_namespace = cpp_namespace |
27 self._target_namespace = ( | 28 self._target_namespace = ( |
28 self._type_helper.GetCppNamespaceName(self._namespace)) | 29 self._type_helper.GetCppNamespaceName(self._namespace)) |
29 self._generate_error_messages = namespace.compiler_options.get( | 30 self._generate_error_messages = namespace.compiler_options.get( |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 .Eblock('} // namespace %s' % event_namespace) | 297 .Eblock('} // namespace %s' % event_namespace) |
297 ) | 298 ) |
298 return c | 299 return c |
299 | 300 |
300 def _GenerateFunction(self, function): | 301 def _GenerateFunction(self, function): |
301 """Generates the namespaces and structs for a function. | 302 """Generates the namespaces and structs for a function. |
302 """ | 303 """ |
303 c = Code() | 304 c = Code() |
304 # TODO(kalman): Use function.unix_name not Classname here. | 305 # TODO(kalman): Use function.unix_name not Classname here. |
305 function_namespace = cpp_util.Classname(function.name) | 306 function_namespace = cpp_util.Classname(function.name) |
306 """Windows has a #define for SendMessage, so to avoid any issues, we need | 307 # Windows has a #define for SendMessage, so to avoid any issues, we need |
307 to not use the name. | 308 # to not use the name. |
308 """ | |
309 if function_namespace == 'SendMessage': | 309 if function_namespace == 'SendMessage': |
310 function_namespace = 'PassMessage' | 310 function_namespace = 'PassMessage' |
311 (c.Append('namespace %s {' % function_namespace) | 311 (c.Append('namespace %s {' % function_namespace) |
312 .Append() | 312 .Append() |
313 .Cblock(self._GenerateFunctionParams(function)) | 313 .Cblock(self._GenerateFunctionParams(function)) |
314 ) | 314 ) |
315 if function.callback: | 315 if function.callback: |
316 c.Cblock(self._GenerateFunctionResults(function.callback)) | 316 c.Cblock(self._GenerateFunctionResults(function.callback)) |
317 c.Append('} // namespace %s' % function_namespace) | 317 c.Append('} // namespace %s' % function_namespace) |
318 return c | 318 return c |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 .Append('} // namespace Results') | 388 .Append('} // namespace Results') |
389 ) | 389 ) |
390 return c | 390 return c |
391 | 391 |
392 def _GenerateParams(self, params): | 392 def _GenerateParams(self, params): |
393 """Builds the parameter list for a function, given an array of parameters. | 393 """Builds the parameter list for a function, given an array of parameters. |
394 """ | 394 """ |
395 if self._generate_error_messages: | 395 if self._generate_error_messages: |
396 params += ('base::string16* error = NULL',) | 396 params += ('base::string16* error = NULL',) |
397 return ', '.join(str(p) for p in params) | 397 return ', '.join(str(p) for p in params) |
OLD | NEW |