| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 typename = self._interface.id | 78 typename = self._interface.id |
| 79 | 79 |
| 80 | 80 |
| 81 extends = [] | 81 extends = [] |
| 82 suppressed_extends = [] | 82 suppressed_extends = [] |
| 83 | 83 |
| 84 for parent in self._interface.parents: | 84 for parent in self._interface.parents: |
| 85 # TODO(vsm): Remove source_filter. | 85 # TODO(vsm): Remove source_filter. |
| 86 if MatchSourceFilter(parent): | 86 if MatchSourceFilter(parent): |
| 87 # Parent is a DOM type. | 87 # Parent is a DOM type. |
| 88 extends.append(DartType(parent.type.id)) | 88 extends.append(self._DartType(parent.type.id)) |
| 89 elif '<' in parent.type.id: | 89 elif '<' in parent.type.id: |
| 90 # Parent is a Dart collection type. | 90 # Parent is a Dart collection type. |
| 91 # TODO(vsm): Make this check more robust. | 91 # TODO(vsm): Make this check more robust. |
| 92 extends.append(parent.type.id) | 92 extends.append(parent.type.id) |
| 93 else: | 93 else: |
| 94 suppressed_extends.append('%s.%s' % | 94 suppressed_extends.append('%s.%s' % |
| 95 (self._common_prefix, parent.type.id)) | 95 (self._common_prefix, parent.type.id)) |
| 96 | 96 |
| 97 comment = ' extends' | 97 comment = ' extends' |
| 98 extends_str = '' | 98 extends_str = '' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 118 self._top_level_emitter) = self._emitter.Emit( | 118 self._top_level_emitter) = self._emitter.Emit( |
| 119 self._template + '$!TOP_LEVEL', | 119 self._template + '$!TOP_LEVEL', |
| 120 ID=typename, | 120 ID=typename, |
| 121 EXTENDS=extends_str) | 121 EXTENDS=extends_str) |
| 122 | 122 |
| 123 if constructor_info: | 123 if constructor_info: |
| 124 self._members_emitter.Emit( | 124 self._members_emitter.Emit( |
| 125 '\n' | 125 '\n' |
| 126 ' $CTOR($PARAMS);\n', | 126 ' $CTOR($PARAMS);\n', |
| 127 CTOR=typename, | 127 CTOR=typename, |
| 128 PARAMS=constructor_info.ParametersInterfaceDeclaration()) | 128 PARAMS=constructor_info.ParametersInterfaceDeclaration(self._DartType)
) |
| 129 | 129 |
| 130 element_type = MaybeTypedArrayElementTypeInHierarchy( | 130 element_type = MaybeTypedArrayElementTypeInHierarchy( |
| 131 self._interface, self._system._database) | 131 self._interface, self._system._database) |
| 132 if element_type: | 132 if element_type: |
| 133 self._members_emitter.Emit( | 133 self._members_emitter.Emit( |
| 134 '\n' | 134 '\n' |
| 135 ' $CTOR(int length);\n' | 135 ' $CTOR(int length);\n' |
| 136 '\n' | 136 '\n' |
| 137 ' $CTOR.fromList(List<$TYPE> list);\n' | 137 ' $CTOR.fromList(List<$TYPE> list);\n' |
| 138 '\n' | 138 '\n' |
| 139 ' $CTOR.fromBuffer(ArrayBuffer buffer,' | 139 ' $CTOR.fromBuffer(ArrayBuffer buffer,' |
| 140 ' [int byteOffset, int length]);\n', | 140 ' [int byteOffset, int length]);\n', |
| 141 CTOR=self._interface.id, | 141 CTOR=self._interface.id, |
| 142 TYPE=DartType(element_type)) | 142 TYPE=self._DartType(element_type)) |
| 143 | 143 |
| 144 | 144 |
| 145 def FinishInterface(self): | 145 def FinishInterface(self): |
| 146 # TODO(vsm): Use typedef if / when that is supported in Dart. | 146 # TODO(vsm): Use typedef if / when that is supported in Dart. |
| 147 # Define variant as subtype. | 147 # Define variant as subtype. |
| 148 if (self._super_interface and | 148 if (self._super_interface and |
| 149 self._interface.id is not self._super_interface): | 149 self._interface.id is not self._super_interface): |
| 150 consts_emitter = self._top_level_emitter.Emit( | 150 consts_emitter = self._top_level_emitter.Emit( |
| 151 '\n' | 151 '\n' |
| 152 'interface $NAME extends $BASE {\n' | 152 'interface $NAME extends $BASE {\n' |
| 153 '$!CONSTS' | 153 '$!CONSTS' |
| 154 '}\n', | 154 '}\n', |
| 155 NAME=self._interface.id, | 155 NAME=self._interface.id, |
| 156 BASE=self._super_interface) | 156 BASE=self._super_interface) |
| 157 for const in sorted(self._interface.constants, ConstantOutputOrder): | 157 for const in sorted(self._interface.constants, ConstantOutputOrder): |
| 158 self._EmitConstant(consts_emitter, const) | 158 self._EmitConstant(consts_emitter, const) |
| 159 | 159 |
| 160 def AddConstant(self, constant): | 160 def AddConstant(self, constant): |
| 161 if (not self._super_interface or | 161 if (not self._super_interface or |
| 162 self._interface.id is self._super_interface): | 162 self._interface.id is self._super_interface): |
| 163 self._EmitConstant(self._members_emitter, constant) | 163 self._EmitConstant(self._members_emitter, constant) |
| 164 | 164 |
| 165 def _EmitConstant(self, emitter, constant): | 165 def _EmitConstant(self, emitter, constant): |
| 166 emitter.Emit('\n static final $TYPE$NAME = $VALUE;\n', | 166 emitter.Emit('\n static final $TYPE$NAME = $VALUE;\n', |
| 167 NAME=constant.id, | 167 NAME=constant.id, |
| 168 TYPE=TypeOrNothing(DartType(constant.type.id), | 168 TYPE=TypeOrNothing(self._DartType(constant.type.id), |
| 169 constant.type.id), | 169 constant.type.id), |
| 170 VALUE=constant.value) | 170 VALUE=constant.value) |
| 171 | 171 |
| 172 def AddAttribute(self, attribute): | 172 def AddAttribute(self, attribute): |
| 173 getter = attribute | 173 getter = attribute |
| 174 setter = attribute if not systembase.IsReadOnly(attribute) else None | 174 setter = attribute if not systembase.IsReadOnly(attribute) else None |
| 175 if getter and setter and getter.type.id == setter.type.id: | 175 if getter and setter and getter.type.id == setter.type.id: |
| 176 self._members_emitter.Emit('\n $TYPE $NAME;\n', | 176 self._members_emitter.Emit('\n $TYPE $NAME;\n', |
| 177 NAME=DartDomNameOfAttribute(getter), | 177 NAME=DartDomNameOfAttribute(getter), |
| 178 TYPE=TypeOrVar(DartType(getter.type.id), | 178 TYPE=TypeOrVar(self._DartType(getter.type.id), |
| 179 getter.type.id)) | 179 getter.type.id)) |
| 180 return | 180 return |
| 181 if getter and not setter: | 181 if getter and not setter: |
| 182 self._members_emitter.Emit('\n final $TYPE$NAME;\n', | 182 self._members_emitter.Emit('\n final $TYPE$NAME;\n', |
| 183 NAME=DartDomNameOfAttribute(getter), | 183 NAME=DartDomNameOfAttribute(getter), |
| 184 TYPE=TypeOrNothing(DartType(getter.type.id), | 184 TYPE=TypeOrNothing(self._DartType(getter.type.i
d), |
| 185 getter.type.id)) | 185 getter.type.id)) |
| 186 return | 186 return |
| 187 raise Exception('Unexpected getter/setter combination %s %s' % | 187 raise Exception('Unexpected getter/setter combination %s %s' % |
| 188 (getter, setter)) | 188 (getter, setter)) |
| 189 | 189 |
| 190 def AddOperation(self, info): | 190 def AddOperation(self, info): |
| 191 """ | 191 """ |
| 192 Arguments: | 192 Arguments: |
| 193 operations - contains the overloads, one or more operations with the same | 193 operations - contains the overloads, one or more operations with the same |
| 194 name. | 194 name. |
| 195 """ | 195 """ |
| 196 self._members_emitter.Emit('\n' | 196 self._members_emitter.Emit('\n' |
| 197 ' $TYPE $NAME($PARAMS);\n', | 197 ' $TYPE $NAME($PARAMS);\n', |
| 198 TYPE=info.type_name, | 198 TYPE=self._DartType(info.type_name), |
| 199 NAME=info.name, | 199 NAME=info.name, |
| 200 PARAMS=info.ParametersInterfaceDeclaration()) | 200 PARAMS=info.ParametersInterfaceDeclaration(self._
DartType)) |
| OLD | NEW |