| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 const bool REMOVE_ASSERTS = false; | 5 const bool REMOVE_ASSERTS = false; |
| 6 | 6 |
| 7 class ElementAst { | 7 class ElementAst { |
| 8 final Node ast; | 8 final Node ast; |
| 9 final TreeElements treeElements; | 9 final TreeElements treeElements; |
| 10 | 10 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 classMembers[enclosingClass].add(element); | 322 classMembers[enclosingClass].add(element); |
| 323 processElement(element, elementAst); | 323 processElement(element, elementAst); |
| 324 } else { | 324 } else { |
| 325 if (!element.isTopLevel()) { | 325 if (!element.isTopLevel()) { |
| 326 compiler.cancel(reason: 'Cannot process $element', element: element); | 326 compiler.cancel(reason: 'Cannot process $element', element: element); |
| 327 } | 327 } |
| 328 addTopLevel(element, elementAst); | 328 addTopLevel(element, elementAst); |
| 329 } | 329 } |
| 330 }); | 330 }); |
| 331 | 331 |
| 332 // Add synthesized constructors to classes with no resolved constructors, |
| 333 // but which originally had any constructor. That should prevent |
| 334 // those classes from being instantiable with default constructor. |
| 335 Identifier synthesizedIdentifier = |
| 336 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); |
| 337 |
| 338 NextClassElement: |
| 339 for (ClassElement classElement in classMembers.getKeys()) { |
| 340 for (Element member in classMembers[classElement]) { |
| 341 if (member.isConstructor()) continue NextClassElement; |
| 342 } |
| 343 if (classElement.constructors.isEmpty()) continue NextClassElement; |
| 344 |
| 345 // TODO(antonm): check with AAR team if there is better approach. |
| 346 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
| 347 // and then overwrite necessary parts. |
| 348 SynthesizedConstructorElement constructor = |
| 349 new SynthesizedConstructorElement(classElement); |
| 350 constructor.type = new FunctionType( |
| 351 compiler.types.voidType, const EmptyLink<DartType>(), |
| 352 constructor); |
| 353 constructor.cachedNode = new FunctionExpression( |
| 354 new Send(receiver: classElement.parseNode(compiler).name, |
| 355 selector: synthesizedIdentifier), |
| 356 new NodeList(beginToken: new StringToken(OPEN_PAREN_INFO, '(', -1), |
| 357 endToken: new StringToken(CLOSE_PAREN_INFO, ')', -1), |
| 358 nodes: const EmptyLink<Node>()), |
| 359 new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)), |
| 360 null, null, null, null); |
| 361 |
| 362 classMembers[classElement].add(constructor); |
| 363 elementAsts[constructor] = |
| 364 new ElementAst(constructor.cachedNode, new TreeElementMapping()); |
| 365 } |
| 366 |
| 332 // Create all necessary placeholders. | 367 // Create all necessary placeholders. |
| 333 PlaceholderCollector collector = | 368 PlaceholderCollector collector = |
| 334 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); | 369 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); |
| 370 // Add synthesizedIdentifier to set of unresolved names to rename it to |
| 371 // some unused identifier. |
| 372 collector.unresolvedNodes.add(synthesizedIdentifier); |
| 335 makePlaceholders(element) { | 373 makePlaceholders(element) { |
| 336 collector.collect(element); | 374 collector.collect(element); |
| 337 if (element is ClassElement) { | 375 if (element is ClassElement) { |
| 338 classMembers[element].forEach(makePlaceholders); | 376 classMembers[element].forEach(makePlaceholders); |
| 339 } | 377 } |
| 340 } | 378 } |
| 341 topLevelElements.forEach(makePlaceholders); | 379 topLevelElements.forEach(makePlaceholders); |
| 342 // Create renames. | 380 // Create renames. |
| 343 Map<Node, String> renames = new Map<Node, String>(); | 381 Map<Node, String> renames = new Map<Node, String>(); |
| 344 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); | 382 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 493 } |
| 456 | 494 |
| 457 compareElements(e0, e1) { | 495 compareElements(e0, e1) { |
| 458 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 496 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 459 if (result != 0) return result; | 497 if (result != 0) return result; |
| 460 return compareBy((e) => e.position().charOffset)(e0, e1); | 498 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 461 } | 499 } |
| 462 | 500 |
| 463 List<Element> sortElements(Collection<Element> elements) => | 501 List<Element> sortElements(Collection<Element> elements) => |
| 464 sorted(elements, compareElements); | 502 sorted(elements, compareElements); |
| OLD | NEW |