| 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 | 6 from model import PropertyType |
| 7 import cpp_util | 7 import cpp_util |
| 8 import schema_util | 8 import schema_util |
| 9 import util_cc_helper | 9 import util_cc_helper |
| 10 from cpp_namespace_environment import CppNamespaceEnvironment |
| 10 | 11 |
| 11 class CCGenerator(object): | 12 class CCGenerator(object): |
| 12 def __init__(self, type_generator, cpp_namespace_pattern): | 13 def __init__(self, type_generator): |
| 13 self._type_generator = type_generator | 14 self._type_generator = type_generator |
| 14 self._cpp_namespace_pattern = cpp_namespace_pattern | |
| 15 | 15 |
| 16 def Generate(self, namespace): | 16 def Generate(self, namespace): |
| 17 return _Generator(namespace, | 17 return _Generator(namespace, self._type_generator).Generate() |
| 18 self._type_generator, | |
| 19 self._cpp_namespace_pattern).Generate() | |
| 20 | 18 |
| 21 | 19 |
| 22 class _Generator(object): | 20 class _Generator(object): |
| 23 """A .cc generator for a namespace. | 21 """A .cc generator for a namespace. |
| 24 """ | 22 """ |
| 25 def __init__(self, namespace, cpp_type_generator, cpp_namespace_pattern): | 23 def __init__(self, namespace, cpp_type_generator): |
| 24 assert type(namespace.environment) is CppNamespaceEnvironment |
| 26 self._namespace = namespace | 25 self._namespace = namespace |
| 27 self._type_helper = cpp_type_generator | 26 self._type_helper = cpp_type_generator |
| 28 self._cpp_namespace_pattern = cpp_namespace_pattern | |
| 29 self._util_cc_helper = ( | 27 self._util_cc_helper = ( |
| 30 util_cc_helper.UtilCCHelper(self._type_helper)) | 28 util_cc_helper.UtilCCHelper(self._type_helper)) |
| 31 self._generate_error_messages = namespace.compiler_options.get( | 29 self._generate_error_messages = namespace.compiler_options.get( |
| 32 'generate_error_messages', False) | 30 'generate_error_messages', False) |
| 33 | 31 |
| 34 def Generate(self): | 32 def Generate(self): |
| 35 """Generates a Code object with the .cc for a single namespace. | 33 """Generates a Code object with the .cc for a single namespace. |
| 36 """ | 34 """ |
| 37 cpp_namespace = cpp_util.GetCppNamespace(self._cpp_namespace_pattern, | 35 cpp_namespace = cpp_util.GetCppNamespace( |
| 38 self._namespace.unix_name) | 36 self._namespace.environment.namespace_pattern, |
| 37 self._namespace.unix_name) |
| 39 | 38 |
| 40 c = Code() | 39 c = Code() |
| 41 (c.Append(cpp_util.CHROMIUM_LICENSE) | 40 (c.Append(cpp_util.CHROMIUM_LICENSE) |
| 42 .Append() | 41 .Append() |
| 43 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) | 42 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) |
| 44 .Append() | 43 .Append() |
| 45 .Append(self._util_cc_helper.GetIncludePath()) | 44 .Append(self._util_cc_helper.GetIncludePath()) |
| 46 .Append('#include "base/logging.h"') | 45 .Append('#include "base/logging.h"') |
| 47 .Append('#include "base/strings/string_number_conversions.h"') | 46 .Append('#include "base/strings/string_number_conversions.h"') |
| 48 .Append('#include "base/strings/utf_string_conversions.h"') | 47 .Append('#include "base/strings/utf_string_conversions.h"') |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 if self._generate_error_messages: | 1061 if self._generate_error_messages: |
| 1063 params = list(params) + ['base::string16* error'] | 1062 params = list(params) + ['base::string16* error'] |
| 1064 return ', '.join(str(p) for p in params) | 1063 return ', '.join(str(p) for p in params) |
| 1065 | 1064 |
| 1066 def _GenerateArgs(self, args): | 1065 def _GenerateArgs(self, args): |
| 1067 """Builds the argument list for a function, given an array of arguments. | 1066 """Builds the argument list for a function, given an array of arguments. |
| 1068 """ | 1067 """ |
| 1069 if self._generate_error_messages: | 1068 if self._generate_error_messages: |
| 1070 args = list(args) + ['error'] | 1069 args = list(args) + ['error'] |
| 1071 return ', '.join(str(a) for a in args) | 1070 return ', '.join(str(a) for a in args) |
| OLD | NEW |