| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module providesfunctionality for systems to generate | 6 """This module providesfunctionality for systems to generate |
| 7 Dart interfaces from the IDL database.""" | 7 Dart interfaces from the IDL database.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import systembase | 10 import systembase |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 pass | 52 pass |
| 53 | 53 |
| 54 | 54 |
| 55 def _FilePathForDartInterface(self, interface_name): | 55 def _FilePathForDartInterface(self, interface_name): |
| 56 """Returns the file path of the Dart interface definition.""" | 56 """Returns the file path of the Dart interface definition.""" |
| 57 return os.path.join(self._output_dir, 'src', 'interface', | 57 return os.path.join(self._output_dir, 'src', 'interface', |
| 58 '%s.dart' % interface_name) | 58 '%s.dart' % interface_name) |
| 59 | 59 |
| 60 # ------------------------------------------------------------------------------ | 60 # ------------------------------------------------------------------------------ |
| 61 | 61 |
| 62 class DartInterfaceGenerator(object): | 62 class DartInterfaceGenerator(systembase.BaseGenerator): |
| 63 """Generates Dart Interface definition for one DOM IDL interface.""" | 63 """Generates Dart Interface definition for one DOM IDL interface.""" |
| 64 | 64 |
| 65 def __init__(self, system, interface, emitter, template, | 65 def __init__(self, system, interface, emitter, template, |
| 66 common_prefix, super_interface, source_filter): | 66 common_prefix, super_interface, source_filter): |
| 67 """Generates Dart code for the given interface. | 67 """Generates Dart code for the given interface. |
| 68 | 68 |
| 69 Args: | 69 Args: |
| 70 interface -- an IDLInterface instance. It is assumed that all types have | 70 interface -- an IDLInterface instance. It is assumed that all types have |
| 71 been converted to Dart types (e.g. int, String), unless they are in the | 71 been converted to Dart types (e.g. int, String), unless they are in the |
| 72 same package as the interface. | 72 same package as the interface. |
| 73 common_prefix -- the prefix for the common library, if any. | 73 common_prefix -- the prefix for the common library, if any. |
| 74 super_interface -- the name of the common interface that this interface | 74 super_interface -- the name of the common interface that this interface |
| 75 implements, if any. | 75 implements, if any. |
| 76 source_filter -- if specified, rewrites the names of any superinterfaces | 76 source_filter -- if specified, rewrites the names of any superinterfaces |
| 77 that are not from these sources to use the common prefix. | 77 that are not from these sources to use the common prefix. |
| 78 """ | 78 """ |
| 79 super(DartInterfaceGenerator, self).__init__(system._database) |
| 79 self._system = system | 80 self._system = system |
| 80 self._interface = interface | 81 self._interface = interface |
| 81 self._emitter = emitter | 82 self._emitter = emitter |
| 82 self._template = template | 83 self._template = template |
| 83 self._common_prefix = common_prefix | 84 self._common_prefix = common_prefix |
| 84 self._super_interface = super_interface | 85 self._super_interface = super_interface |
| 85 self._source_filter = source_filter | 86 self._source_filter = source_filter |
| 86 | 87 |
| 87 | 88 |
| 88 def StartInterface(self): | 89 def StartInterface(self): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 return | 193 return |
| 193 if getter and not setter: | 194 if getter and not setter: |
| 194 self._members_emitter.Emit('\n final $TYPE$NAME;\n', | 195 self._members_emitter.Emit('\n final $TYPE$NAME;\n', |
| 195 NAME=DartDomNameOfAttribute(getter), | 196 NAME=DartDomNameOfAttribute(getter), |
| 196 TYPE=TypeOrNothing(DartType(getter.type.id), | 197 TYPE=TypeOrNothing(DartType(getter.type.id), |
| 197 getter.type.id)) | 198 getter.type.id)) |
| 198 return | 199 return |
| 199 raise Exception('Unexpected getter/setter combination %s %s' % | 200 raise Exception('Unexpected getter/setter combination %s %s' % |
| 200 (getter, setter)) | 201 (getter, setter)) |
| 201 | 202 |
| 202 def AddIndexer(self, element_type): | |
| 203 # Interface inherits all operations from List<element_type>. | |
| 204 pass | |
| 205 | |
| 206 def AmendIndexer(self, element_type): | |
| 207 pass | |
| 208 | |
| 209 def AddOperation(self, info): | 203 def AddOperation(self, info): |
| 210 """ | 204 """ |
| 211 Arguments: | 205 Arguments: |
| 212 operations - contains the overloads, one or more operations with the same | 206 operations - contains the overloads, one or more operations with the same |
| 213 name. | 207 name. |
| 214 """ | 208 """ |
| 215 self._members_emitter.Emit('\n' | 209 self._members_emitter.Emit('\n' |
| 216 ' $TYPE $NAME($PARAMS);\n', | 210 ' $TYPE $NAME($PARAMS);\n', |
| 217 TYPE=info.type_name, | 211 TYPE=info.type_name, |
| 218 NAME=info.name, | 212 NAME=info.name, |
| 219 PARAMS=info.ParametersInterfaceDeclaration()) | 213 PARAMS=info.ParametersInterfaceDeclaration()) |
| 220 | |
| 221 def AddStaticOperation(self, info): | |
| 222 pass | |
| 223 | |
| 224 # Interfaces get secondary members directly via the superinterfaces. | |
| 225 def AddSecondaryAttribute(self, interface, getter, setter): | |
| 226 pass | |
| 227 | |
| 228 def AddSecondaryOperation(self, interface, attr): | |
| 229 pass | |
| OLD | NEW |