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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
| 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
| 9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
| 10 class ElementAst { | 10 class ElementAst { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 workQueue.addAll( | 142 workQueue.addAll( |
| 143 classMembers.keys.map((classElement) => classElement.thisType)); | 143 classMembers.keys.map((classElement) => classElement.thisType)); |
| 144 workQueue.addAll(compiler.resolverWorld.isChecks); | 144 workQueue.addAll(compiler.resolverWorld.isChecks); |
| 145 Element typeErrorElement = | 145 Element typeErrorElement = |
| 146 compiler.coreLibrary.find(new SourceString('TypeError')); | 146 compiler.coreLibrary.find(new SourceString('TypeError')); |
| 147 DartType typeErrorType = typeErrorElement.computeType(compiler); | 147 DartType typeErrorType = typeErrorElement.computeType(compiler); |
| 148 if (workQueue.indexOf(typeErrorType) != -1) { | 148 if (workQueue.indexOf(typeErrorType) != -1) { |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void processTypeArguments(Element classElement, NodeList typeArguments) { | |
| 153 if (typeArguments == null) return; | |
| 154 for (Node typeArgument in typeArguments.nodes) { | |
| 155 if (typeArgument is TypeVariable) { | |
| 156 TypeVariable typeVariable = typeArgument; | |
| 157 typeArgument = typeVariable.bound; | |
| 158 } | |
| 159 if (typeArgument == null) continue; | |
| 160 assert(typeArgument is TypeAnnotation); | |
| 161 DartType argumentType = | |
| 162 compiler.resolveTypeAnnotation(classElement, typeArgument); | |
| 163 assert(argumentType != null); | |
| 164 workQueue.add(argumentType); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 void processTypeAnnotationList(Element classElement, NodeList annotations) { | |
| 169 for (Link link = annotations.nodes; !link.isEmpty; link = link.tail) { | |
| 170 TypeAnnotation typeAnnotation = link.head; | |
| 171 NodeList typeArguments = typeAnnotation.typeArguments; | |
| 172 processTypeArguments(classElement, typeArguments); | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 void processSuperclassTypeArguments(Element classElement, Node superclass) { | |
| 177 if (superclass == null) return; | |
| 178 MixinApplication superMixinApplication = superclass.asMixinApplication(); | |
| 179 if (superMixinApplication != null) { | |
| 180 processTypeAnnotationList(classElement, superMixinApplication.mixins); | |
| 181 } else { | |
| 182 TypeAnnotation typeAnnotation = superclass; | |
| 183 NodeList typeArguments = typeAnnotation.typeArguments; | |
| 184 processTypeArguments(classElement, typeArguments); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 while (!workQueue.isEmpty) { | 152 while (!workQueue.isEmpty) { |
| 189 DartType type = workQueue.removeLast(); | 153 DartType type = workQueue.removeLast(); |
| 190 if (processedTypes.contains(type)) continue; | 154 if (processedTypes.contains(type)) continue; |
| 191 processedTypes.add(type); | 155 processedTypes.add(type); |
| 156 if (type is FunctionType) return false; | |
| 192 if (type is TypedefType) return false; | 157 if (type is TypedefType) return false; |
| 193 if (type is InterfaceType) { | 158 if (type is InterfaceType) { |
| 159 InterfaceType interfaceType = type; | |
| 160 // Check all type arguments. | |
| 161 workQueue.addAll(interfaceType.typeArguments.toList()); | |
| 194 ClassElement element = type.element; | 162 ClassElement element = type.element; |
| 195 Node node = element.parseNode(compiler); | |
| 196 if (node is ClassNode) { | |
| 197 ClassNode classNode = node; | |
| 198 processTypeArguments(element, classNode.typeParameters); | |
| 199 processSuperclassTypeArguments(element, classNode.superclass); | |
|
Anton Muhin
2013/07/02 11:39:03
do not you need to check superclass still?
Johnni Winther
2013/07/02 11:42:10
All superclasses of [type] are handled by adding t
Anton Muhin
2013/07/02 11:43:02
Thanks!
| |
| 200 processTypeAnnotationList(element, classNode.interfaces); | |
| 201 } else { | |
| 202 MixinApplication mixinNode = node; | |
| 203 processSuperclassTypeArguments(element, mixinNode.superclass); | |
| 204 if (mixinNode is NamedMixinApplication) { | |
| 205 NamedMixinApplication namedMixinNode = mixinNode; | |
| 206 processTypeArguments(element, namedMixinNode.typeParameters); | |
| 207 } | |
| 208 } | |
| 209 // Check all supertypes. | 163 // Check all supertypes. |
| 210 if (element.allSupertypes != null) { | 164 if (element.allSupertypes != null) { |
| 211 workQueue.addAll(element.allSupertypes.toList()); | 165 workQueue.addAll(element.allSupertypes.toList()); |
| 212 } | 166 } |
| 213 } | 167 } |
| 214 } | 168 } |
| 215 return true; | 169 return true; |
| 216 } | 170 } |
| 217 | 171 |
| 218 DartBackend(Compiler compiler, List<String> strips) | 172 DartBackend(Compiler compiler, List<String> strips) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 NextClassElement: | 347 NextClassElement: |
| 394 for (ClassElement classElement in classMembers.keys) { | 348 for (ClassElement classElement in classMembers.keys) { |
| 395 for (Element member in classMembers[classElement]) { | 349 for (Element member in classMembers[classElement]) { |
| 396 if (member.isConstructor()) continue NextClassElement; | 350 if (member.isConstructor()) continue NextClassElement; |
| 397 } | 351 } |
| 398 if (classElement.constructors.isEmpty) continue NextClassElement; | 352 if (classElement.constructors.isEmpty) continue NextClassElement; |
| 399 | 353 |
| 400 // TODO(antonm): check with AAR team if there is better approach. | 354 // TODO(antonm): check with AAR team if there is better approach. |
| 401 // As an idea: provide template as a Dart code---class C { C.name(); }--- | 355 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
| 402 // and then overwrite necessary parts. | 356 // and then overwrite necessary parts. |
| 403 ClassNode classNode = classElement.parseNode(compiler); | 357 var classNode = classElement.parseNode(compiler); |
|
Johnni Winther
2013/07/02 11:33:51
This can also be NamedMixinApplication nodes.
karlklose
2013/07/02 12:16:39
Could we let them share common base class (the Mix
Johnni Winther
2013/07/03 05:41:57
We could but the only thing used here is their [na
| |
| 404 SynthesizedConstructorElementX constructor = | 358 SynthesizedConstructorElementX constructor = |
| 405 new SynthesizedConstructorElementX(classElement); | 359 new SynthesizedConstructorElementX(classElement); |
| 406 constructor.type = new FunctionType( | 360 constructor.type = new FunctionType( |
| 407 constructor, | 361 constructor, |
| 408 compiler.types.voidType, | 362 compiler.types.voidType, |
| 409 const Link<DartType>(), | 363 const Link<DartType>(), |
| 410 const Link<DartType>(), | 364 const Link<DartType>(), |
| 411 const Link<SourceString>(), | 365 const Link<SourceString>(), |
| 412 const Link<DartType>() | 366 const Link<DartType>() |
| 413 ); | 367 ); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 } | 545 } |
| 592 | 546 |
| 593 compareElements(e0, e1) { | 547 compareElements(e0, e1) { |
| 594 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); | 548 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); |
| 595 if (result != 0) return result; | 549 if (result != 0) return result; |
| 596 return compareBy((e) => e.position().charOffset)(e0, e1); | 550 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 597 } | 551 } |
| 598 | 552 |
| 599 List<Element> sortElements(Iterable<Element> elements) => | 553 List<Element> sortElements(Iterable<Element> elements) => |
| 600 sorted(elements, compareElements); | 554 sorted(elements, compareElements); |
| OLD | NEW |