Chromium Code Reviews| 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 provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 | 10 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 "Node.get:nodeValue", | 264 "Node.get:nodeValue", |
| 265 "Node.set:nodeValue", | 265 "Node.set:nodeValue", |
| 266 "Node.get:CDATA_SECTION_NODE", | 266 "Node.get:CDATA_SECTION_NODE", |
| 267 "Node.get:nodeName", | 267 "Node.get:nodeName", |
| 268 "Node.lookupPrefix", | 268 "Node.lookupPrefix", |
| 269 "Node.get:PROCESSING_INSTRUCTION_NODE", | 269 "Node.get:PROCESSING_INSTRUCTION_NODE", |
| 270 "IFrameElement.get:contentDocument", | 270 "IFrameElement.get:contentDocument", |
| 271 "Window.get:frameElement", | 271 "Window.get:frameElement", |
| 272 ]) | 272 ]) |
| 273 | 273 |
| 274 _html_library_custom = set([ | |
| 275 'IFrameElement.contentWindow', | |
| 276 'Window.document', | |
| 277 'Window.top', | |
| 278 'Window.location', | |
| 279 'Window.open', | |
| 280 'IDBDatabase.transaction', | |
| 281 ]) | |
| 282 | |
| 283 # This map controls merging of interfaces in dart:html library. | 274 # This map controls merging of interfaces in dart:html library. |
| 284 # All constants, attributes, and operations of merged interface (key) are | 275 # All constants, attributes, and operations of merged interface (key) are |
| 285 # added to target interface (value). All references to the merged interface | 276 # added to target interface (value). All references to the merged interface |
| 286 # (e.g. parameter types, return types, parent interfaces) are replaced with | 277 # (e.g. parameter types, return types, parent interfaces) are replaced with |
| 287 # target interface. There are two important restrictions: | 278 # target interface. There are two important restrictions: |
| 288 # 1) Merged and target interfaces shouldn't have common members, otherwise there | 279 # 1) Merged and target interfaces shouldn't have common members, otherwise there |
| 289 # would be duplicated declarations in generated Dart code. | 280 # would be duplicated declarations in generated Dart code. |
| 290 # 2) Merged interface should be direct child of target interface, so the | 281 # 2) Merged interface should be direct child of target interface, so the |
| 291 # children of merged interface are not affected by the merge. | 282 # children of merged interface are not affected by the merge. |
| 292 # As a consequence, target interface implementation and its direct children | 283 # As a consequence, target interface implementation and its direct children |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 TYPE=self._NarrowInputType(element_type)) | 1226 TYPE=self._NarrowInputType(element_type)) |
| 1236 | 1227 |
| 1237 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 1228 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 1238 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 1229 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| 1239 if self._interface.id != 'NodeList': | 1230 if self._interface.id != 'NodeList': |
| 1240 template_file = 'immutable_list_mixin.darttemplate' | 1231 template_file = 'immutable_list_mixin.darttemplate' |
| 1241 template = self._system._templates.Load(template_file) | 1232 template = self._system._templates.Load(template_file) |
| 1242 self._members_emitter.Emit(template, E=self._shared.DartType(element_type) ) | 1233 self._members_emitter.Emit(template, E=self._shared.DartType(element_type) ) |
| 1243 | 1234 |
| 1244 def AddAttribute(self, attribute, html_name, read_only): | 1235 def AddAttribute(self, attribute, html_name, read_only): |
| 1245 if self._shared.IsCustomInHtmlLibrary(self._interface, attribute.id): | 1236 if self._HasCustomImplementation(attribute.id): |
| 1246 return | 1237 return |
| 1247 | 1238 |
| 1248 if attribute.id != html_name: | 1239 if attribute.id != html_name: |
| 1249 self._AddRenamingGetter(attribute, html_name) | 1240 self._AddRenamingGetter(attribute, html_name) |
| 1250 if not read_only: | 1241 if not read_only: |
| 1251 self._AddRenamingSetter(attribute, html_name) | 1242 self._AddRenamingSetter(attribute, html_name) |
| 1252 return | 1243 return |
| 1253 | 1244 |
| 1254 # If the attribute is shadowing, we can't generate a shadowing | 1245 # If the attribute is shadowing, we can't generate a shadowing |
| 1255 # field (Issue 1633). | 1246 # field (Issue 1633). |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 ' native "this.$NAME = value;";\n', | 1301 ' native "this.$NAME = value;";\n', |
| 1311 HTML_NAME=html_name, | 1302 HTML_NAME=html_name, |
| 1312 NAME=attr.id, | 1303 NAME=attr.id, |
| 1313 TYPE=self._NarrowInputType(attr.type.id)) | 1304 TYPE=self._NarrowInputType(attr.type.id)) |
| 1314 | 1305 |
| 1315 def AddOperation(self, info): | 1306 def AddOperation(self, info): |
| 1316 """ | 1307 """ |
| 1317 Arguments: | 1308 Arguments: |
| 1318 info: An OperationInfo object. | 1309 info: An OperationInfo object. |
| 1319 """ | 1310 """ |
| 1320 if self._shared.IsCustomInHtmlLibrary(self._interface, info.name): | 1311 if self._HasCustomImplementation(info.name): |
| 1321 return | 1312 return |
| 1322 | 1313 |
| 1323 html_name = self._shared.RenameInHtmlLibrary( | 1314 html_name = self._shared.RenameInHtmlLibrary( |
| 1324 self._interface.id, info.name, implementation_class=True) | 1315 self._interface.id, info.name, implementation_class=True) |
| 1325 if not html_name: | 1316 if not html_name: |
| 1326 return | 1317 return |
| 1327 | 1318 |
| 1328 # Do we need a native body? | 1319 # Do we need a native body? |
| 1329 if html_name != info.declared_name: | 1320 if html_name != info.declared_name: |
| 1330 return_type = self._NarrowOutputType(info.type_name) | 1321 return_type = self._NarrowOutputType(info.type_name) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1341 ' $TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 1332 ' $TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
| 1342 else: | 1333 else: |
| 1343 self._members_emitter.Emit( | 1334 self._members_emitter.Emit( |
| 1344 '\n' | 1335 '\n' |
| 1345 ' $TYPE $NAME($PARAMS) native;\n', | 1336 ' $TYPE $NAME($PARAMS) native;\n', |
| 1346 TYPE=self._NarrowOutputType(info.type_name), | 1337 TYPE=self._NarrowOutputType(info.type_name), |
| 1347 NAME=info.name, | 1338 NAME=info.name, |
| 1348 PARAMS=info.ParametersImplementationDeclaration( | 1339 PARAMS=info.ParametersImplementationDeclaration( |
| 1349 lambda type_name: self._NarrowInputType(type_name))) | 1340 lambda type_name: self._NarrowInputType(type_name))) |
| 1350 | 1341 |
| 1342 def _HasCustomImplementation(self, member_name): | |
| 1343 return '%s.%s' % (self._html_interface_name, member_name) in self._custom_me mbers | |
|
Anton Muhin
2012/07/05 16:00:15
nit: class name instead of self should be preferre
| |
| 1344 | |
| 1345 _custom_members = set([ | |
|
sra1
2012/07/06 07:20:11
Please keep these tables at the top of the file.
podivilov
2012/07/06 16:18:19
Done.
| |
| 1346 'IFrameElement.contentWindow', | |
| 1347 'Window.document', | |
| 1348 'Window.top', | |
| 1349 'Window.location', | |
| 1350 'Window.open', | |
| 1351 'IDBDatabase.transaction', | |
| 1352 ]) | |
| 1353 | |
| 1351 # ------------------------------------------------------------------------------ | 1354 # ------------------------------------------------------------------------------ |
| 1352 | 1355 |
| 1353 class HtmlFrogSystem(HtmlSystem): | 1356 class HtmlFrogSystem(HtmlSystem): |
| 1354 | 1357 |
| 1355 def __init__(self, templates, database, emitters, output_dir): | 1358 def __init__(self, templates, database, emitters, output_dir): |
| 1356 super(HtmlFrogSystem, self).__init__( | 1359 super(HtmlFrogSystem, self).__init__( |
| 1357 templates, database, emitters, output_dir) | 1360 templates, database, emitters, output_dir) |
| 1358 | 1361 |
| 1359 def ImplementationGenerator(self, interface): | 1362 def ImplementationGenerator(self, interface): |
| 1360 return HtmlFrogClassGenerator(self, interface) | 1363 return HtmlFrogClassGenerator(self, interface) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1386 Collect(database.GetInterface(parent.type.id), | 1389 Collect(database.GetInterface(parent.type.id), |
| 1387 seen, collected) | 1390 seen, collected) |
| 1388 | 1391 |
| 1389 inheritance_closure = {} | 1392 inheritance_closure = {} |
| 1390 for interface in database.GetInterfaces(): | 1393 for interface in database.GetInterfaces(): |
| 1391 seen = set() | 1394 seen = set() |
| 1392 collected = [] | 1395 collected = [] |
| 1393 Collect(interface, seen, collected) | 1396 Collect(interface, seen, collected) |
| 1394 inheritance_closure[interface.id] = collected | 1397 inheritance_closure[interface.id] = collected |
| 1395 return inheritance_closure | 1398 return inheritance_closure |
| OLD | NEW |