| 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 Generator language component for compiler.py that adds Dart language support. | 5 Generator language component for compiler.py that adds Dart language support. |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 from code import Code | 8 from code import Code |
| 9 from model import * | 9 from model import Function, PropertyType |
| 10 from schema_util import * | 10 from schema_util import StripNamespace |
| 11 | 11 |
| 12 import os | 12 import os |
| 13 from datetime import datetime | 13 from datetime import datetime |
| 14 | 14 |
| 15 LICENSE = ( | 15 LICENSE = ( |
| 16 """// Copyright (c) %s, the Dart project authors. Please see the AUTHORS file | 16 """// Copyright (c) %s, the Dart project authors. Please see the AUTHORS file |
| 17 // for details. All rights reserved. Use of this source code is governed by a | 17 // for details. All rights reserved. Use of this source code is governed by a |
| 18 // BSD-style license that can be found in the LICENSE file.""" % | 18 // BSD-style license that can be found in the LICENSE file.""" % |
| 19 datetime.now().year) | 19 datetime.now().year) |
| 20 | 20 |
| 21 class DartGenerator(object): | 21 class DartGenerator(object): |
| 22 def __init__(self, dart_overrides_dir=None): | 22 def __init__(self, dart_overrides_dir=None): |
| 23 self._dart_overrides_dir = dart_overrides_dir | 23 self._dart_overrides_dir = dart_overrides_dir |
| 24 | 24 |
| 25 def Generate(self, namespace): | 25 def Generate(self, namespace): |
| 26 return _Generator(namespace, self._dart_overrides_dir).Generate() | 26 return _Generator(namespace, self._dart_overrides_dir).Generate() |
| 27 | 27 |
| 28 |
| 28 class _Generator(object): | 29 class _Generator(object): |
| 29 """A .dart generator for a namespace. | 30 """A .dart generator for a namespace. |
| 30 """ | 31 """ |
| 31 | 32 |
| 32 def __init__(self, namespace, dart_overrides_dir=None): | 33 def __init__(self, namespace, dart_overrides_dir=None): |
| 33 self._namespace = namespace | 34 self._namespace = namespace |
| 34 # TODO(sashab): Once inline type definitions start being added to | 35 # TODO(sashab): Once inline type definitions start being added to |
| 35 # self._types, make a _FindType(self, type_) function that looks at | 36 # self._types, make a _FindType(self, type_) function that looks at |
| 36 # self._namespace.types. | 37 # self._namespace.types. |
| 37 self._types = namespace.types | 38 self._types = namespace.types |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 c.Comment(line, comment_prefix='/// ') | 272 c.Comment(line, comment_prefix='/// ') |
| 272 return c | 273 return c |
| 273 | 274 |
| 274 def _GenerateFunction(self, f): | 275 def _GenerateFunction(self, f): |
| 275 """Returns the Code object for the given function. | 276 """Returns the Code object for the given function. |
| 276 """ | 277 """ |
| 277 c = Code() | 278 c = Code() |
| 278 c.Concat(self._GenerateDocumentation(f)) | 279 c.Concat(self._GenerateDocumentation(f)) |
| 279 | 280 |
| 280 if not self._NeedsProxiedCallback(f): | 281 if not self._NeedsProxiedCallback(f): |
| 281 c.Append("%s => %s;" % (self._GenerateFunctionSignature(f), | 282 c.Append("%s => %s;" % (self._GenerateFunctionSignature(f), |
| 282 self._GenerateProxyCall(f))) | 283 self._GenerateProxyCall(f))) |
| 283 return c | 284 return c |
| 284 | 285 |
| 285 (c.Sblock("%s {" % self._GenerateFunctionSignature(f)) | 286 (c.Sblock("%s {" % self._GenerateFunctionSignature(f)) |
| 286 .Concat(self._GenerateProxiedFunction(f.callback, f.callback.name)) | 287 .Concat(self._GenerateProxiedFunction(f.callback, f.callback.name)) |
| 287 .Append('%s;' % self._GenerateProxyCall(f)) | 288 .Append('%s;' % self._GenerateProxyCall(f)) |
| 288 .Eblock('}') | 289 .Eblock('}') |
| 289 ) | 290 ) |
| 290 | 291 |
| 291 return c | 292 return c |
| 292 | 293 |
| 293 def _GenerateProxiedFunction(self, f, callback_name): | 294 def _GenerateProxiedFunction(self, f, callback_name): |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 return 'Object' | 754 return 'Object' |
| 754 elif prop_type is PropertyType.FUNCTION: | 755 elif prop_type is PropertyType.FUNCTION: |
| 755 return 'Function' | 756 return 'Function' |
| 756 elif prop_type is PropertyType.ARRAY: | 757 elif prop_type is PropertyType.ARRAY: |
| 757 return 'List<%s>' % self._GetDartType(type_.item_type) | 758 return 'List<%s>' % self._GetDartType(type_.item_type) |
| 758 elif prop_type is PropertyType.BINARY: | 759 elif prop_type is PropertyType.BINARY: |
| 759 return 'String' | 760 return 'String' |
| 760 else: | 761 else: |
| 761 raise NotImplementedError(prop_type) | 762 raise NotImplementedError(prop_type) |
| 762 | 763 |
| OLD | NEW |