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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 typename = self._interface.id | 91 typename = self._interface.id |
92 | 92 |
93 | 93 |
94 extends = [] | 94 extends = [] |
95 suppressed_extends = [] | 95 suppressed_extends = [] |
96 | 96 |
97 for parent in self._interface.parents: | 97 for parent in self._interface.parents: |
98 # TODO(vsm): Remove source_filter. | 98 # TODO(vsm): Remove source_filter. |
99 if MatchSourceFilter(self._source_filter, parent): | 99 if MatchSourceFilter(self._source_filter, parent): |
100 # Parent is a DOM type. | 100 # Parent is a DOM type. |
101 extends.append(parent.type.id) | 101 extends.append(DartType(parent.type.id)) |
102 elif '<' in parent.type.id: | 102 elif '<' in parent.type.id: |
103 # Parent is a Dart collection type. | 103 # Parent is a Dart collection type. |
104 # TODO(vsm): Make this check more robust. | 104 # TODO(vsm): Make this check more robust. |
105 extends.append(parent.type.id) | 105 extends.append(parent.type.id) |
106 else: | 106 else: |
107 suppressed_extends.append('%s.%s' % | 107 suppressed_extends.append('%s.%s' % |
108 (self._common_prefix, parent.type.id)) | 108 (self._common_prefix, parent.type.id)) |
109 | 109 |
110 comment = ' extends' | 110 comment = ' extends' |
111 extends_str = '' | 111 extends_str = '' |
(...skipping 30 matching lines...) Expand all Loading... |
142 | 142 |
143 element_type = MaybeTypedArrayElementType(self._interface) | 143 element_type = MaybeTypedArrayElementType(self._interface) |
144 if element_type: | 144 if element_type: |
145 self._members_emitter.Emit( | 145 self._members_emitter.Emit( |
146 '\n' | 146 '\n' |
147 ' $CTOR(int length);\n' | 147 ' $CTOR(int length);\n' |
148 '\n' | 148 '\n' |
149 ' $CTOR.fromList(List<$TYPE> list);\n' | 149 ' $CTOR.fromList(List<$TYPE> list);\n' |
150 '\n' | 150 '\n' |
151 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 151 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
152 CTOR=self._interface.id, | 152 CTOR=self._interface.id, |
153 TYPE=element_type) | 153 TYPE=DartType(element_type)) |
154 | 154 |
155 | 155 |
156 def FinishInterface(self): | 156 def FinishInterface(self): |
157 # TODO(vsm): Use typedef if / when that is supported in Dart. | 157 # TODO(vsm): Use typedef if / when that is supported in Dart. |
158 # Define variant as subtype. | 158 # Define variant as subtype. |
159 if (self._super_interface and | 159 if (self._super_interface and |
160 self._interface.id is not self._super_interface): | 160 self._interface.id is not self._super_interface): |
161 consts_emitter = self._top_level_emitter.Emit( | 161 consts_emitter = self._top_level_emitter.Emit( |
162 '\n' | 162 '\n' |
163 'interface $NAME extends $BASE {\n' | 163 'interface $NAME extends $BASE {\n' |
164 '$!CONSTS' | 164 '$!CONSTS' |
165 '}\n', | 165 '}\n', |
166 NAME=self._interface.id, | 166 NAME=self._interface.id, |
167 BASE=self._super_interface) | 167 BASE=self._super_interface) |
168 for const in sorted(self._interface.constants, ConstantOutputOrder): | 168 for const in sorted(self._interface.constants, ConstantOutputOrder): |
169 self._EmitConstant(consts_emitter, const) | 169 self._EmitConstant(consts_emitter, const) |
170 | 170 |
171 def AddConstant(self, constant): | 171 def AddConstant(self, constant): |
172 if (not self._super_interface or | 172 if (not self._super_interface or |
173 self._interface.id is self._super_interface): | 173 self._interface.id is self._super_interface): |
174 self._EmitConstant(self._members_emitter, constant) | 174 self._EmitConstant(self._members_emitter, constant) |
175 | 175 |
176 def _EmitConstant(self, emitter, constant): | 176 def _EmitConstant(self, emitter, constant): |
177 emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', | 177 emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', |
178 NAME=constant.id, | 178 NAME=constant.id, |
179 TYPE=constant.type.id, | 179 TYPE=DartType(constant.type.id), |
180 VALUE=constant.value) | 180 VALUE=constant.value) |
181 | 181 |
182 def AddAttribute(self, getter, setter): | 182 def AddAttribute(self, getter, setter): |
183 if getter and setter and getter.type.id == setter.type.id: | 183 if getter and setter and getter.type.id == setter.type.id: |
184 self._members_emitter.Emit('\n $TYPE $NAME;\n', | 184 self._members_emitter.Emit('\n $TYPE $NAME;\n', |
185 NAME=getter.id, TYPE=getter.type.id); | 185 NAME=getter.id, TYPE=DartType(getter.type.id)); |
186 return | 186 return |
187 if getter and not setter: | 187 if getter and not setter: |
188 self._members_emitter.Emit('\n final $TYPE $NAME;\n', | 188 self._members_emitter.Emit('\n final $TYPE $NAME;\n', |
189 NAME=getter.id, TYPE=getter.type.id); | 189 NAME=getter.id, TYPE=DartType(getter.type.id)); |
190 return | 190 return |
191 raise Exception('Unexpected getter/setter combination %s %s' % | 191 raise Exception('Unexpected getter/setter combination %s %s' % |
192 (getter, setter)) | 192 (getter, setter)) |
193 | 193 |
194 def AddIndexer(self, element_type): | 194 def AddIndexer(self, element_type): |
195 # Interface inherits all operations from List<element_type>. | 195 # Interface inherits all operations from List<element_type>. |
196 pass | 196 pass |
197 | 197 |
198 def AddOperation(self, info): | 198 def AddOperation(self, info): |
199 """ | 199 """ |
200 Arguments: | 200 Arguments: |
201 operations - contains the overloads, one or more operations with the same | 201 operations - contains the overloads, one or more operations with the same |
202 name. | 202 name. |
203 """ | 203 """ |
204 self._members_emitter.Emit('\n' | 204 self._members_emitter.Emit('\n' |
205 ' $TYPE $NAME($PARAMS);\n', | 205 ' $TYPE $NAME($PARAMS);\n', |
206 TYPE=info.type_name, | 206 TYPE=info.type_name, |
207 NAME=info.name, | 207 NAME=info.name, |
208 PARAMS=info.ParametersInterfaceDeclaration()) | 208 PARAMS=info.ParametersInterfaceDeclaration()) |
209 | 209 |
210 # Interfaces get secondary members directly via the superinterfaces. | 210 # Interfaces get secondary members directly via the superinterfaces. |
211 def AddSecondaryAttribute(self, interface, getter, setter): | 211 def AddSecondaryAttribute(self, interface, getter, setter): |
212 pass | 212 pass |
213 | 213 |
214 def AddSecondaryOperation(self, interface, attr): | 214 def AddSecondaryOperation(self, interface, attr): |
215 pass | 215 pass |
216 | 216 |
217 def AddEventAttributes(self, event_attrs): | 217 def AddEventAttributes(self, event_attrs): |
218 pass | 218 pass |
OLD | NEW |