Chromium Code Reviews| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 classMembers[enclosingClass].add(element); | 318 classMembers[enclosingClass].add(element); |
| 319 processElement(element, elementAst); | 319 processElement(element, elementAst); |
| 320 } else { | 320 } else { |
| 321 if (!element.isTopLevel()) { | 321 if (!element.isTopLevel()) { |
| 322 compiler.cancel(reason: 'Cannot process $element', element: element); | 322 compiler.cancel(reason: 'Cannot process $element', element: element); |
| 323 } | 323 } |
| 324 addTopLevel(element, elementAst); | 324 addTopLevel(element, elementAst); |
| 325 } | 325 } |
| 326 }); | 326 }); |
| 327 | 327 |
| 328 // Add synthesized constructors to classes with no resolved constructors, | |
| 329 // but which originally had any constructor. That should prevent | |
| 330 // those classes from being instantiable with default constructor. | |
| 331 Identifier synthesizedIdentifier = | |
| 332 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); | |
| 333 | |
| 334 NextClassElement: | |
| 335 for (ClassElement classElement in classMembers.getKeys()) { | |
| 336 for (Element member in classMembers[classElement]) { | |
| 337 if (member.isConstructor()) continue NextClassElement; | |
| 338 } | |
| 339 if (classElement.constructors.isEmpty()) continue NextClassElement; | |
| 340 | |
| 341 // TODO(antonm): check with AAR team if there is better approach. | |
| 342 // As an idea: provide template as a Dart code---class C { C.name(); }--- | |
| 343 // and then overwrite necessary parts. | |
| 344 SynthesizedConstructorElement constructor = | |
|
Anton Muhin
2012/09/27 06:14:28
SCE assumes it's a default ctor at least as the el
| |
| 345 new SynthesizedConstructorElement(classElement); | |
| 346 constructor.type = new FunctionType( | |
| 347 compiler.types.voidType, const EmptyLink<DartType>(), | |
| 348 constructor); | |
| 349 constructor.cachedNode = new FunctionExpression( | |
| 350 new Send(receiver: classElement.parseNode(compiler).name, | |
| 351 selector: synthesizedIdentifier), | |
| 352 new NodeList(beginToken: new StringToken(OPEN_PAREN_INFO, '(', -1), | |
| 353 endToken: new StringToken(CLOSE_PAREN_INFO, ')', -1), | |
| 354 nodes: const EmptyLink<Node>()), | |
| 355 new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)), | |
| 356 null, null, null, null); | |
| 357 | |
| 358 classMembers[classElement].add(constructor); | |
| 359 elementAsts[constructor] = new ElementAst(constructor.cachedNode, new Tree ElementMapping()); | |
|
Roman
2012/09/27 12:40:50
80 chars
Anton Muhin
2012/09/28 12:21:27
Done.
| |
| 360 } | |
| 361 | |
| 328 // Create all necessary placeholders. | 362 // Create all necessary placeholders. |
| 329 PlaceholderCollector collector = | 363 PlaceholderCollector collector = |
| 330 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); | 364 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); |
| 365 collector.unresolvedNodes.add(synthesizedIdentifier); | |
|
Roman
2012/09/27 12:40:50
Please add a comment that this is for renamer cons
Anton Muhin
2012/09/28 12:21:27
Done.
| |
| 331 makePlaceholders(element) { | 366 makePlaceholders(element) { |
| 332 collector.collect(element); | 367 collector.collect(element); |
| 333 if (element is ClassElement) { | 368 if (element is ClassElement) { |
| 334 classMembers[element].forEach(makePlaceholders); | 369 classMembers[element].forEach(makePlaceholders); |
| 335 } | 370 } |
| 336 } | 371 } |
| 337 topLevelElements.forEach(makePlaceholders); | 372 topLevelElements.forEach(makePlaceholders); |
| 338 // Create renames. | 373 // Create renames. |
| 339 Map<Node, String> renames = new Map<Node, String>(); | 374 Map<Node, String> renames = new Map<Node, String>(); |
| 340 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); | 375 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 } | 486 } |
| 452 | 487 |
| 453 compareElements(e0, e1) { | 488 compareElements(e0, e1) { |
| 454 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 489 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 455 if (result != 0) return result; | 490 if (result != 0) return result; |
| 456 return compareBy((e) => e.position().charOffset)(e0, e1); | 491 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 457 } | 492 } |
| 458 | 493 |
| 459 List<Element> sortElements(Collection<Element> elements) => | 494 List<Element> sortElements(Collection<Element> elements) => |
| 460 sorted(elements, compareElements); | 495 sorted(elements, compareElements); |
| OLD | NEW |