| 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 import os | 5 import os |
| 6 | 6 |
| 7 from code import Code | 7 from code import Code |
| 8 from model import PropertyType | 8 from model import PropertyType |
| 9 import cpp_util | 9 import cpp_util |
| 10 import schema_util | 10 import schema_util |
| 11 | 11 |
| 12 class HGenerator(object): | 12 class HGenerator(object): |
| 13 def __init__(self, type_generator, cpp_namespace_pattern): | 13 def __init__(self, type_generator): |
| 14 self._type_generator = type_generator | 14 self._type_generator = type_generator |
| 15 self._cpp_namespace_pattern = cpp_namespace_pattern | |
| 16 | 15 |
| 17 def Generate(self, namespace): | 16 def Generate(self, namespace): |
| 18 return _Generator(namespace, | 17 return _Generator(namespace, self._type_generator).Generate() |
| 19 self._type_generator, | |
| 20 self._cpp_namespace_pattern).Generate() | |
| 21 | 18 |
| 22 | 19 |
| 23 class _Generator(object): | 20 class _Generator(object): |
| 24 """A .h generator for a namespace. | 21 """A .h generator for a namespace. |
| 25 """ | 22 """ |
| 26 def __init__(self, namespace, cpp_type_generator, cpp_namespace_pattern): | 23 def __init__(self, namespace, cpp_type_generator): |
| 27 self._namespace = namespace | 24 self._namespace = namespace |
| 28 self._type_helper = cpp_type_generator | 25 self._type_helper = cpp_type_generator |
| 29 self._cpp_namespace_pattern = cpp_namespace_pattern | |
| 30 self._generate_error_messages = namespace.compiler_options.get( | 26 self._generate_error_messages = namespace.compiler_options.get( |
| 31 'generate_error_messages', False) | 27 'generate_error_messages', False) |
| 32 | 28 |
| 33 def Generate(self): | 29 def Generate(self): |
| 34 """Generates a Code object with the .h for a single namespace. | 30 """Generates a Code object with the .h for a single namespace. |
| 35 """ | 31 """ |
| 36 c = Code() | 32 c = Code() |
| 37 (c.Append(cpp_util.CHROMIUM_LICENSE) | 33 (c.Append(cpp_util.CHROMIUM_LICENSE) |
| 38 .Append() | 34 .Append() |
| 39 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) | 35 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 .Append('#include "base/memory/scoped_ptr.h"') | 54 .Append('#include "base/memory/scoped_ptr.h"') |
| 59 .Append('#include "base/values.h"') | 55 .Append('#include "base/values.h"') |
| 60 .Cblock(self._type_helper.GenerateIncludes()) | 56 .Cblock(self._type_helper.GenerateIncludes()) |
| 61 .Append() | 57 .Append() |
| 62 ) | 58 ) |
| 63 | 59 |
| 64 # TODO(calamity): These forward declarations should be #includes to allow | 60 # TODO(calamity): These forward declarations should be #includes to allow |
| 65 # $ref types from other files to be used as required params. This requires | 61 # $ref types from other files to be used as required params. This requires |
| 66 # some detangling of windows and tabs which will currently lead to circular | 62 # some detangling of windows and tabs which will currently lead to circular |
| 67 # #includes. | 63 # #includes. |
| 68 c.Cblock(self._type_helper.GenerateForwardDeclarations( | 64 c.Cblock(self._type_helper.GenerateForwardDeclarations()) |
| 69 self._cpp_namespace_pattern)) | |
| 70 | 65 |
| 71 cpp_namespace = cpp_util.GetCppNamespace(self._cpp_namespace_pattern, | 66 cpp_namespace = cpp_util.GetCppNamespace( |
| 72 self._namespace.unix_name) | 67 self._namespace.environment.namespace_pattern, |
| 68 self._namespace.unix_name) |
| 73 c.Concat(cpp_util.OpenNamespace(cpp_namespace)) | 69 c.Concat(cpp_util.OpenNamespace(cpp_namespace)) |
| 74 c.Append() | 70 c.Append() |
| 75 if self._namespace.properties: | 71 if self._namespace.properties: |
| 76 (c.Append('//') | 72 (c.Append('//') |
| 77 .Append('// Properties') | 73 .Append('// Properties') |
| 78 .Append('//') | 74 .Append('//') |
| 79 .Append() | 75 .Append() |
| 80 ) | 76 ) |
| 81 for property in self._namespace.properties.values(): | 77 for property in self._namespace.properties.values(): |
| 82 property_code = self._type_helper.GeneratePropertyValues( | 78 property_code = self._type_helper.GeneratePropertyValues( |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 """Builds the parameter list for a function, given an array of parameters. | 388 """Builds the parameter list for a function, given an array of parameters. |
| 393 """ | 389 """ |
| 394 # |error| is populated with warnings and/or errors found during parsing. | 390 # |error| is populated with warnings and/or errors found during parsing. |
| 395 # |error| being set does not necessarily imply failure and may be | 391 # |error| being set does not necessarily imply failure and may be |
| 396 # recoverable. | 392 # recoverable. |
| 397 # For example, optional properties may have failed to parse, but the | 393 # For example, optional properties may have failed to parse, but the |
| 398 # parser was able to continue. | 394 # parser was able to continue. |
| 399 if self._generate_error_messages: | 395 if self._generate_error_messages: |
| 400 params += ('base::string16* error',) | 396 params += ('base::string16* error',) |
| 401 return ', '.join(str(p) for p in params) | 397 return ', '.join(str(p) for p in params) |
| OLD | NEW |