| 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 library closureToClassMapper; | 5 library closureToClassMapper; |
| 6 | 6 |
| 7 import 'common/names.dart' show | 7 import 'common/names.dart' show |
| 8 Identifiers; | 8 Identifiers; |
| 9 import 'common/resolution.dart' show |
| 10 Parsing, |
| 11 Resolution; |
| 9 import 'common/tasks.dart' show | 12 import 'common/tasks.dart' show |
| 10 CompilerTask; | 13 CompilerTask; |
| 11 import 'compiler.dart' show | 14 import 'compiler.dart' show |
| 12 Compiler; | 15 Compiler; |
| 13 import 'constants/expressions.dart'; | 16 import 'constants/expressions.dart'; |
| 14 import 'dart_types.dart'; | 17 import 'dart_types.dart'; |
| 15 import 'diagnostics/diagnostic_listener.dart'; | 18 import 'diagnostics/diagnostic_listener.dart'; |
| 16 import 'diagnostics/spannable.dart' show | 19 import 'diagnostics/spannable.dart' show |
| 17 SpannableAssertionFailure; | 20 SpannableAssertionFailure; |
| 18 import 'elements/elements.dart'; | 21 import 'elements/elements.dart'; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 136 } |
| 134 | 137 |
| 135 Expression get initializer { | 138 Expression get initializer { |
| 136 throw new SpannableAssertionFailure(local, | 139 throw new SpannableAssertionFailure(local, |
| 137 'Should not access initializer of ClosureFieldElement.'); | 140 'Should not access initializer of ClosureFieldElement.'); |
| 138 } | 141 } |
| 139 | 142 |
| 140 bool get isInstanceMember => true; | 143 bool get isInstanceMember => true; |
| 141 bool get isAssignable => false; | 144 bool get isAssignable => false; |
| 142 | 145 |
| 143 DartType computeType(Compiler compiler) => type; | 146 DartType computeType(Resolution resolution) => type; |
| 144 | 147 |
| 145 DartType get type { | 148 DartType get type { |
| 146 if (local is LocalElement) { | 149 if (local is LocalElement) { |
| 147 LocalElement element = local; | 150 LocalElement element = local; |
| 148 return element.type; | 151 return element.type; |
| 149 } | 152 } |
| 150 return const DynamicType(); | 153 return const DynamicType(); |
| 151 } | 154 } |
| 152 | 155 |
| 153 String toString() => "ClosureFieldElement($name)"; | 156 String toString() => "ClosureFieldElement($name)"; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 closure.compilationUnit, | 193 closure.compilationUnit, |
| 191 // By assigning a fresh class-id we make sure that the hashcode | 194 // By assigning a fresh class-id we make sure that the hashcode |
| 192 // is unique, but also emit closure classes after all other | 195 // is unique, but also emit closure classes after all other |
| 193 // classes (since the emitter sorts classes by their id). | 196 // classes (since the emitter sorts classes by their id). |
| 194 compiler.getNextFreeClassId(), | 197 compiler.getNextFreeClassId(), |
| 195 STATE_DONE) { | 198 STATE_DONE) { |
| 196 JavaScriptBackend backend = compiler.backend; | 199 JavaScriptBackend backend = compiler.backend; |
| 197 ClassElement superclass = methodElement.isInstanceMember | 200 ClassElement superclass = methodElement.isInstanceMember |
| 198 ? backend.boundClosureClass | 201 ? backend.boundClosureClass |
| 199 : backend.closureClass; | 202 : backend.closureClass; |
| 200 superclass.ensureResolved(compiler); | 203 superclass.ensureResolved(compiler.resolution); |
| 201 supertype = superclass.thisType; | 204 supertype = superclass.thisType; |
| 202 interfaces = const Link<DartType>(); | 205 interfaces = const Link<DartType>(); |
| 203 thisType = rawType = new InterfaceType(this); | 206 thisType = rawType = new InterfaceType(this); |
| 204 allSupertypesAndSelf = | 207 allSupertypesAndSelf = |
| 205 superclass.allSupertypesAndSelf.extendClass(thisType); | 208 superclass.allSupertypesAndSelf.extendClass(thisType); |
| 206 callType = methodElement.type; | 209 callType = methodElement.type; |
| 207 } | 210 } |
| 208 | 211 |
| 209 Iterable<ClosureFieldElement> get closureFields => _closureFields; | 212 Iterable<ClosureFieldElement> get closureFields => _closureFields; |
| 210 | 213 |
| 211 void addField(ClosureFieldElement field, DiagnosticListener listener) { | 214 void addField(ClosureFieldElement field, DiagnosticListener listener) { |
| 212 _closureFields.add(field); | 215 _closureFields.add(field); |
| 213 addMember(field, listener); | 216 addMember(field, listener); |
| 214 } | 217 } |
| 215 | 218 |
| 216 bool get hasNode => true; | 219 bool get hasNode => true; |
| 217 | 220 |
| 218 bool get isClosure => true; | 221 bool get isClosure => true; |
| 219 | 222 |
| 220 Token get position => node.getBeginToken(); | 223 Token get position => node.getBeginToken(); |
| 221 | 224 |
| 222 Node parseNode(DiagnosticListener listener) => node; | 225 Node parseNode(Parsing parsing) => node; |
| 223 | 226 |
| 224 // A [ClosureClassElement] is nested inside a function or initializer in terms | 227 // A [ClosureClassElement] is nested inside a function or initializer in terms |
| 225 // of [enclosingElement], but still has to be treated as a top-level | 228 // of [enclosingElement], but still has to be treated as a top-level |
| 226 // element. | 229 // element. |
| 227 bool get isTopLevel => true; | 230 bool get isTopLevel => true; |
| 228 | 231 |
| 229 get enclosingElement => methodElement; | 232 get enclosingElement => methodElement; |
| 230 | 233 |
| 231 accept(ElementVisitor visitor, arg) { | 234 accept(ElementVisitor visitor, arg) { |
| 232 return visitor.visitClosureClassElement(this, arg); | 235 return visitor.visitClosureClassElement(this, arg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 245 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to | 248 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to |
| 246 // find a more general solution. | 249 // find a more general solution. |
| 247 class BoxFieldElement extends ElementX | 250 class BoxFieldElement extends ElementX |
| 248 implements TypedElement, CapturedVariable, FieldElement { | 251 implements TypedElement, CapturedVariable, FieldElement { |
| 249 final BoxLocal box; | 252 final BoxLocal box; |
| 250 | 253 |
| 251 BoxFieldElement(String name, this.variableElement, BoxLocal box) | 254 BoxFieldElement(String name, this.variableElement, BoxLocal box) |
| 252 : this.box = box, | 255 : this.box = box, |
| 253 super(name, ElementKind.FIELD, box.executableContext); | 256 super(name, ElementKind.FIELD, box.executableContext); |
| 254 | 257 |
| 255 DartType computeType(Compiler compiler) => type; | 258 DartType computeType(Resolution resolution) => type; |
| 256 | 259 |
| 257 DartType get type => variableElement.type; | 260 DartType get type => variableElement.type; |
| 258 | 261 |
| 259 final VariableElement variableElement; | 262 final VariableElement variableElement; |
| 260 | 263 |
| 261 accept(ElementVisitor visitor, arg) { | 264 accept(ElementVisitor visitor, arg) { |
| 262 return visitor.visitBoxFieldElement(this, arg); | 265 return visitor.visitBoxFieldElement(this, arg); |
| 263 } | 266 } |
| 264 | 267 |
| 265 @override | 268 @override |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 ClosureClassElement get closureClass => super.enclosingElement; | 328 ClosureClassElement get closureClass => super.enclosingElement; |
| 326 | 329 |
| 327 MemberElement get memberContext { | 330 MemberElement get memberContext { |
| 328 return closureClass.methodElement.memberContext; | 331 return closureClass.methodElement.memberContext; |
| 329 } | 332 } |
| 330 | 333 |
| 331 bool get hasNode => expression.hasNode; | 334 bool get hasNode => expression.hasNode; |
| 332 | 335 |
| 333 FunctionExpression get node => expression.node; | 336 FunctionExpression get node => expression.node; |
| 334 | 337 |
| 335 FunctionExpression parseNode(DiagnosticListener listener) => node; | 338 FunctionExpression parseNode(Parsing parsing) => node; |
| 336 | 339 |
| 337 ResolvedAst get resolvedAst { | 340 ResolvedAst get resolvedAst { |
| 338 return new ResolvedAst(this, node, treeElements); | 341 return new ResolvedAst(this, node, treeElements); |
| 339 } | 342 } |
| 340 | 343 |
| 341 Element get analyzableElement => closureClass.methodElement.analyzableElement; | 344 Element get analyzableElement => closureClass.methodElement.analyzableElement; |
| 342 } | 345 } |
| 343 | 346 |
| 344 // The box-element for a scope, and the captured variables that need to be | 347 // The box-element for a scope, and the captured variables that need to be |
| 345 // stored in the box. | 348 // stored in the box. |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 | 1123 |
| 1121 String get name => typeVariable.name; | 1124 String get name => typeVariable.name; |
| 1122 | 1125 |
| 1123 int get hashCode => typeVariable.hashCode; | 1126 int get hashCode => typeVariable.hashCode; |
| 1124 | 1127 |
| 1125 bool operator ==(other) { | 1128 bool operator ==(other) { |
| 1126 if (other is! TypeVariableLocal) return false; | 1129 if (other is! TypeVariableLocal) return false; |
| 1127 return typeVariable == other.typeVariable; | 1130 return typeVariable == other.typeVariable; |
| 1128 } | 1131 } |
| 1129 } | 1132 } |
| OLD | NEW |