| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 def _GetPlatformIfdefs(self, model_object): | 72 def _GetPlatformIfdefs(self, model_object): |
| 73 """Generates the "defined" conditional for an #if check if |model_object| | 73 """Generates the "defined" conditional for an #if check if |model_object| |
| 74 has platform restrictions. Returns None if there are no restrictions. | 74 has platform restrictions. Returns None if there are no restrictions. |
| 75 """ | 75 """ |
| 76 if model_object.platforms is None: | 76 if model_object.platforms is None: |
| 77 return None | 77 return None |
| 78 ifdefs = [] | 78 ifdefs = [] |
| 79 for platform in model_object.platforms: | 79 for platform in model_object.platforms: |
| 80 if platform == Platforms.CHROMEOS: | 80 if platform == Platforms.CHROMEOS: |
| 81 ifdefs.append('defined(OS_CHROMEOS)') | 81 ifdefs.append('defined(OS_CHROMEOS)') |
| 82 elif platform == Platforms.LINUX: |
| 83 ifdefs.append('defined(OS_LINUX)') |
| 84 elif platform == Platforms.MAC: |
| 85 ifdefs.append('defined(OS_MACOSX)') |
| 86 elif platform == Platforms.WIN: |
| 87 ifdefs.append('defined(OS_WIN)') |
| 82 else: | 88 else: |
| 83 raise ValueError("Unsupported platform ifdef: %s" % platform.name) | 89 raise ValueError("Unsupported platform ifdef: %s" % platform.name) |
| 84 return ' and '.join(ifdefs) | 90 return ' || '.join(ifdefs) |
| 85 | 91 |
| 86 def _GenerateRegisterFunctions(self, namespace_name, function): | 92 def _GenerateRegisterFunctions(self, namespace_name, function): |
| 87 c = code.Code() | 93 c = code.Code() |
| 88 function_ifdefs = self._GetPlatformIfdefs(function) | 94 function_ifdefs = self._GetPlatformIfdefs(function) |
| 89 if function_ifdefs is not None: | 95 if function_ifdefs is not None: |
| 90 c.Append("#if %s" % function_ifdefs, indent_level=0) | 96 c.Append("#if %s" % function_ifdefs, indent_level=0) |
| 91 | 97 |
| 92 function_name = JsFunctionNameToClassName(namespace_name, function.name) | 98 function_name = JsFunctionNameToClassName(namespace_name, function.name) |
| 93 c.Append("registry->RegisterFunction<%sFunction>();" % ( | 99 c.Append("registry->RegisterFunction<%sFunction>();" % ( |
| 94 function_name)) | 100 function_name)) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 c.Eblock('}') | 294 c.Eblock('}') |
| 289 c.Append() | 295 c.Append() |
| 290 c.Append('// static') | 296 c.Append('// static') |
| 291 c.Sblock('bool GeneratedSchemas::IsGenerated(std::string name) {') | 297 c.Sblock('bool GeneratedSchemas::IsGenerated(std::string name) {') |
| 292 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') | 298 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') |
| 293 c.Eblock('}') | 299 c.Eblock('}') |
| 294 c.Append() | 300 c.Append() |
| 295 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) | 301 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) |
| 296 c.Append() | 302 c.Append() |
| 297 return c | 303 return c |
| OLD | NEW |