| 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 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 c.Append(cpp_util.CHROMIUM_LICENSE) | 319 c.Append(cpp_util.CHROMIUM_LICENSE) |
| 320 c.Append() | 320 c.Append() |
| 321 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir, | 321 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir, |
| 322 'generated_schemas.h'))) | 322 'generated_schemas.h'))) |
| 323 c.Append() | 323 c.Append() |
| 324 c.Append('#include "base/lazy_instance.h"') | 324 c.Append('#include "base/lazy_instance.h"') |
| 325 c.Append() | 325 c.Append() |
| 326 c.Append('namespace {') | 326 c.Append('namespace {') |
| 327 for api in self._bundle._api_defs: | 327 for api in self._bundle._api_defs: |
| 328 namespace = self._bundle._model.namespaces[api.get('namespace')] | 328 namespace = self._bundle._model.namespaces[api.get('namespace')] |
| 329 # JSON parsing code expects lists of schemas, so dump a singleton list. | 329 json_content = json.dumps(_PrefixSchemaWithNamespace( |
| 330 json_content = json.dumps([_PrefixSchemaWithNamespace( | 330 _RemoveUnneededFields(api)), |
| 331 _RemoveUnneededFields(api))], | |
| 332 separators=(',', ':')) | 331 separators=(',', ':')) |
| 333 # Escape all double-quotes and backslashes. For this to output a valid | 332 # Escape all double-quotes and backslashes. For this to output a valid |
| 334 # JSON C string, we need to escape \ and ". Note that some schemas are | 333 # JSON C string, we need to escape \ and ". Note that some schemas are |
| 335 # too large to compile on windows. Split the JSON up into several | 334 # too large to compile on windows. Split the JSON up into several |
| 336 # strings, since apparently that helps. | 335 # strings, since apparently that helps. |
| 337 max_length = 8192 | 336 max_length = 8192 |
| 338 segments = [json_content[i:i + max_length].replace('\\', '\\\\') | 337 segments = [json_content[i:i + max_length].replace('\\', '\\\\') |
| 339 .replace('"', '\\"') | 338 .replace('"', '\\"') |
| 340 for i in xrange(0, len(json_content), max_length)] | 339 for i in xrange(0, len(json_content), max_length)] |
| 341 c.Append('const char %s[] = "%s";' % | 340 c.Append('const char %s[] = "%s";' % |
| (...skipping 25 matching lines...) Expand all Loading... |
| 367 c.Append() | 366 c.Append() |
| 368 c.Append('// static') | 367 c.Append('// static') |
| 369 c.Sblock('bool %s::IsGenerated(std::string name) {' % | 368 c.Sblock('bool %s::IsGenerated(std::string name) {' % |
| 370 self._bundle._GenerateBundleClass('GeneratedSchemas')) | 369 self._bundle._GenerateBundleClass('GeneratedSchemas')) |
| 371 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') | 370 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') |
| 372 c.Eblock('}') | 371 c.Eblock('}') |
| 373 c.Append() | 372 c.Append() |
| 374 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) | 373 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) |
| 375 c.Append() | 374 c.Append() |
| 376 return c | 375 return c |
| OLD | NEW |