Chromium Code Reviews| 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 code | 5 import code |
| 6 import cpp_util | 6 import cpp_util |
| 7 from model import Platforms | 7 from model import Platforms |
| 8 from schema_util import CapitalizeFirstLetter | 8 from schema_util import CapitalizeFirstLetter |
| 9 from schema_util import JsFunctionNameToClassName | 9 from schema_util import JsFunctionNameToClassName |
| 10 | 10 |
| 11 import json | 11 import json |
| 12 import os | 12 import os |
| 13 import re | 13 import re |
| 14 | 14 |
| 15 # TODO(miket/asargent) - parameterize this. | 15 # TODO(miket/asargent) - parameterize this. |
| 16 SOURCE_BASE_PATH = 'chrome/common/extensions/api' | 16 SOURCE_BASE_PATH = 'chrome/common/extensions/api' |
| 17 | 17 |
| 18 class SchemaBundleGenerator(object): | 18 class SchemaBundleGenerator(object): |
| 19 """This class contains methods to generate code based on multiple schemas. | 19 """This class contains methods to generate code based on multiple schemas. |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 def __init__(self, model, api_defs, cpp_type_generator): | 22 def __init__(self, root, model, api_defs, cpp_type_generator): |
| 23 self._root = root; | |
| 23 self._model = model | 24 self._model = model |
| 24 self._api_defs = api_defs | 25 self._api_defs = api_defs |
| 25 self._cpp_type_generator = cpp_type_generator | 26 self._cpp_type_generator = cpp_type_generator |
| 26 | 27 |
| 27 def GenerateHeader(self, file_base, body_code): | 28 def GenerateHeader(self, file_base, body_code): |
| 28 """Generates a code.Code object for a header file | 29 """Generates a code.Code object for a header file |
| 29 | 30 |
| 30 Parameters: | 31 Parameters: |
| 31 - |file_base| - the base of the filename, e.g. 'foo' (for 'foo.h') | 32 - |file_base| - the base of the filename, e.g. 'foo' (for 'foo.h') |
| 32 - |body_code| - the code to put in between the multiple inclusion guards""" | 33 - |body_code| - the code to put in between the multiple inclusion guards""" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 61 | 62 |
| 62 def GenerateAPIHeader(self): | 63 def GenerateAPIHeader(self): |
| 63 """Generates the header for API registration / declaration""" | 64 """Generates the header for API registration / declaration""" |
| 64 c = code.Code() | 65 c = code.Code() |
| 65 | 66 |
| 66 c.Append('#include <string>') | 67 c.Append('#include <string>') |
| 67 c.Append() | 68 c.Append() |
| 68 c.Append('#include "base/basictypes.h"') | 69 c.Append('#include "base/basictypes.h"') |
| 69 | 70 |
| 70 for namespace in self._model.namespaces.values(): | 71 for namespace in self._model.namespaces.values(): |
| 71 ifdefs = self._GetPlatformIfdefs(namespace) | |
| 72 if ifdefs is not None: | |
| 73 c.Append("#if %s" % ifdefs, indent_level=0) | |
| 74 | |
| 75 namespace_name = namespace.unix_name.replace("experimental_", "") | 72 namespace_name = namespace.unix_name.replace("experimental_", "") |
| 76 implementation_header = namespace.compiler_options.get( | 73 implementation_header = namespace.compiler_options.get( |
| 77 "implemented_in", | 74 "implemented_in", |
| 78 "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name, | 75 "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name, |
| 79 namespace_name)) | 76 namespace_name)) |
| 80 c.Append('#include "%s"' % implementation_header) | 77 if os.path.exists( |
| 78 os.path.join(self._root, os.path.normpath(implementation_header))): | |
|
not at google - send to devlin
2013/01/24 06:44:24
prefer to invert condition and continue here inste
not at google - send to devlin
2013/01/24 22:36:26
Another thing - we should throw an error if the pa
calamity
2013/01/24 23:25:55
Done.
| |
| 79 ifdefs = self._GetPlatformIfdefs(namespace) | |
| 80 if ifdefs is not None: | |
| 81 c.Append("#if %s" % ifdefs, indent_level=0) | |
| 81 | 82 |
| 82 if ifdefs is not None: | 83 c.Append('#include "%s"' % implementation_header) |
| 83 c.Append("#endif // %s" % ifdefs, indent_level=0) | 84 |
| 85 if ifdefs is not None: | |
| 86 c.Append("#endif // %s" % ifdefs, indent_level=0) | |
| 84 | 87 |
| 85 c.Append() | 88 c.Append() |
| 86 c.Append("class ExtensionFunctionRegistry;") | 89 c.Append("class ExtensionFunctionRegistry;") |
| 87 c.Append() | 90 c.Append() |
| 88 | 91 |
| 89 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) | 92 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) |
| 90 for namespace in self._model.namespaces.values(): | 93 for namespace in self._model.namespaces.values(): |
| 91 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) | 94 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) |
| 92 c.Append() | 95 c.Append() |
| 93 c.Concat(self.GenerateFunctionRegistry()) | 96 c.Concat(self.GenerateFunctionRegistry()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 for index, line in enumerate(lines): | 184 for index, line in enumerate(lines): |
| 182 line = ' "%s"' % line | 185 line = ' "%s"' % line |
| 183 if index == len(lines) - 1: | 186 if index == len(lines) - 1: |
| 184 line += ';' | 187 line += ';' |
| 185 c.Append(line) | 188 c.Append(line) |
| 186 c.Eblock('}') | 189 c.Eblock('}') |
| 187 c.Append() | 190 c.Append() |
| 188 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) | 191 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) |
| 189 c.Append() | 192 c.Append() |
| 190 return c | 193 return c |
| OLD | NEW |