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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 * or type variable bounds typedefs. | 124 * or type variable bounds typedefs. |
| 125 * These restrictions can be less strict. | 125 * These restrictions can be less strict. |
| 126 */ | 126 */ |
| 127 bool isSafeToRemoveTypeDeclarations( | 127 bool isSafeToRemoveTypeDeclarations( |
| 128 Map<ClassElement, Set<Element>> classMembers) { | 128 Map<ClassElement, Set<Element>> classMembers) { |
| 129 Set<DartType> processedTypes = new Set<DartType>(); | 129 Set<DartType> processedTypes = new Set<DartType>(); |
| 130 List<DartType> workQueue = new List<DartType>(); | 130 List<DartType> workQueue = new List<DartType>(); |
| 131 workQueue.addAll( | 131 workQueue.addAll( |
| 132 classMembers.getKeys().map((classElement) => classElement.type)); | 132 classMembers.getKeys().map((classElement) => classElement.type)); |
| 133 workQueue.addAll(compiler.resolverWorld.isChecks); | 133 workQueue.addAll(compiler.resolverWorld.isChecks); |
| 134 DartType typeErrorType = | 134 Element typeErrorElement = |
| 135 compiler.coreLibrary.find(new SourceString('TypeError')).type; | 135 compiler.coreLibrary.find(new SourceString('TypeError')); |
| 136 DartType typeErrorType = typeErrorElement.computeType(compiler); | |
| 136 if (workQueue.indexOf(typeErrorType) != -1) { | 137 if (workQueue.indexOf(typeErrorType) != -1) { |
| 137 return false; | 138 return false; |
| 138 } | 139 } |
| 139 | 140 |
| 140 void processTypeArguments(Element classElement, NodeList typeArguments) { | 141 void processTypeArguments(Element classElement, NodeList typeArguments) { |
| 141 if (typeArguments == null) return; | 142 if (typeArguments == null) return; |
| 142 for (Node typeArgument in typeArguments.nodes) { | 143 for (Node typeArgument in typeArguments.nodes) { |
| 143 if (typeArgument is TypeVariable) { | 144 if (typeArgument is TypeVariable) { |
| 144 typeArgument = typeArgument.bound; | 145 typeArgument = typeArgument.bound; |
| 145 } | 146 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 if (classElement.constructors.isEmpty()) continue NextClassElement; | 341 if (classElement.constructors.isEmpty()) continue NextClassElement; |
| 341 | 342 |
| 342 // TODO(antonm): check with AAR team if there is better approach. | 343 // TODO(antonm): check with AAR team if there is better approach. |
| 343 // As an idea: provide template as a Dart code---class C { C.name(); }--- | 344 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
| 344 // and then overwrite necessary parts. | 345 // and then overwrite necessary parts. |
| 345 SynthesizedConstructorElement constructor = | 346 SynthesizedConstructorElement constructor = |
| 346 new SynthesizedConstructorElement(classElement); | 347 new SynthesizedConstructorElement(classElement); |
| 347 constructor.type = new FunctionType( | 348 constructor.type = new FunctionType( |
| 348 compiler.types.voidType, const EmptyLink<DartType>(), | 349 compiler.types.voidType, const EmptyLink<DartType>(), |
| 349 constructor); | 350 constructor); |
| 351 ClassNode classNode = classElement.parseNode(compiler); | |
|
ahe
2012/10/03 14:56:33
Couldn't you change the return type?
karlklose
2012/10/04 08:50:00
Done.
| |
| 350 constructor.cachedNode = new FunctionExpression( | 352 constructor.cachedNode = new FunctionExpression( |
| 351 new Send(receiver: classElement.parseNode(compiler).name, | 353 new Send(receiver: classNode.name, |
| 352 selector: synthesizedIdentifier), | 354 selector: synthesizedIdentifier), |
| 353 new NodeList(beginToken: new StringToken(OPEN_PAREN_INFO, '(', -1), | 355 new NodeList(beginToken: new StringToken(OPEN_PAREN_INFO, '(', -1), |
| 354 endToken: new StringToken(CLOSE_PAREN_INFO, ')', -1), | 356 endToken: new StringToken(CLOSE_PAREN_INFO, ')', -1), |
| 355 nodes: const EmptyLink<Node>()), | 357 nodes: const EmptyLink<Node>()), |
| 356 new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)), | 358 new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)), |
| 357 null, Modifiers.EMPTY, null, null); | 359 null, Modifiers.EMPTY, null, null); |
| 358 | 360 |
| 359 classMembers[classElement].add(constructor); | 361 classMembers[classElement].add(constructor); |
| 360 elementAsts[constructor] = | 362 elementAsts[constructor] = |
| 361 new ElementAst(constructor.cachedNode, new TreeElementMapping()); | 363 new ElementAst(constructor.cachedNode, new TreeElementMapping()); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 } | 511 } |
| 510 | 512 |
| 511 compareElements(e0, e1) { | 513 compareElements(e0, e1) { |
| 512 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 514 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 513 if (result != 0) return result; | 515 if (result != 0) return result; |
| 514 return compareBy((e) => e.position().charOffset)(e0, e1); | 516 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 515 } | 517 } |
| 516 | 518 |
| 517 List<Element> sortElements(Collection<Element> elements) => | 519 List<Element> sortElements(Collection<Element> elements) => |
| 518 sorted(elements, compareElements); | 520 sorted(elements, compareElements); |
| OLD | NEW |