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 resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element get currentElement; | 8 Element get currentElement; |
| 9 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 3212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3223 TypedefType type = element.computeType(compiler); | 3223 TypedefType type = element.computeType(compiler); |
| 3224 scope = new TypeDeclarationScope(scope, element); | 3224 scope = new TypeDeclarationScope(scope, element); |
| 3225 resolveTypeVariableBounds(node.typeParameters); | 3225 resolveTypeVariableBounds(node.typeParameters); |
| 3226 | 3226 |
| 3227 element.functionSignature = SignatureResolver.analyze( | 3227 element.functionSignature = SignatureResolver.analyze( |
| 3228 compiler, node.formals, node.returnType, element); | 3228 compiler, node.formals, node.returnType, element); |
| 3229 | 3229 |
| 3230 element.alias = compiler.computeFunctionType( | 3230 element.alias = compiler.computeFunctionType( |
| 3231 element, element.functionSignature); | 3231 element, element.functionSignature); |
| 3232 | 3232 |
| 3233 // TODO(johnniwinther): Check for cyclic references in the typedef alias. | 3233 void checkCyclicReference() { |
| 3234 var visitor = new TypedefCyclicVisitor(compiler, element); | |
| 3235 type.accept(visitor, null); | |
| 3236 } | |
| 3237 compiler.enqueuer.resolution.addPostProcessAction(element, | |
| 3238 checkCyclicReference); | |
|
ahe
2013/09/17 09:40:18
Weird indentation.
Johnni Winther
2013/09/18 07:57:15
Done.
| |
| 3234 } | 3239 } |
| 3235 } | 3240 } |
| 3236 | 3241 |
| 3242 // TODO(johnniwinther): Replace with a traversal on the AST when the type | |
| 3243 // annotations in typedef alias are stored in a [TreeElements] mapping. | |
| 3244 class TypedefCyclicVisitor extends DartTypeVisitor { | |
| 3245 final Compiler compiler; | |
| 3246 final TypedefElement element; | |
| 3247 bool hasCyclicReference = false; | |
| 3248 int seenBoundsCount = 0; | |
|
ahe
2013/09/17 09:40:18
Please document this field.
Johnni Winther
2013/09/18 07:57:15
Done.
| |
| 3249 Link<TypedefElement> seenTypedefs = const Link<TypedefElement>(); | |
| 3250 Link<TypeVariableElement> seenTypeVariables = | |
| 3251 const Link<TypeVariableElement>(); | |
| 3252 | |
| 3253 TypedefCyclicVisitor(Compiler this.compiler, TypedefElement this.element); | |
| 3254 | |
| 3255 visitType(DartType type, _) { | |
| 3256 // Do nothing. | |
| 3257 } | |
| 3258 | |
| 3259 visitTypedefType(TypedefType type, _) { | |
| 3260 TypedefElement typedefElement = type.element; | |
| 3261 if (seenTypedefs.contains(typedefElement)) { | |
| 3262 if (!hasCyclicReference && identical(element, typedefElement)) { | |
| 3263 // Only report an error on the checked typedef to avoid generating | |
| 3264 // multiple errors for the same cyclicity. | |
| 3265 hasCyclicReference = true; | |
| 3266 if (seenBoundsCount > 0) { | |
| 3267 compiler.reportError(element, MessageKind.CYCLIC_TYPEDEF_TYPEVAR); | |
| 3268 } else if (seenTypedefs.tail.isEmpty) { | |
| 3269 // Direct cyclicity. | |
| 3270 compiler.reportError(element, | |
| 3271 MessageKind.CYCLIC_TYPEDEF, | |
| 3272 {'typedefName': element.name}); | |
| 3273 } else if (seenTypedefs.tail.tail.isEmpty) { | |
|
karlklose
2013/09/17 08:56:15
It would be easier to read if you computed (or tra
Johnni Winther
2013/09/18 07:57:15
Done.
| |
| 3274 // Cyclicity through one other typedef. | |
| 3275 compiler.reportError(element, | |
| 3276 MessageKind.CYCLIC_TYPEDEF_ONE, | |
| 3277 {'typedefName': element.name, | |
| 3278 'otherTypedefName': seenTypedefs.head.name}); | |
| 3279 } else { | |
| 3280 // Cyclicity through more than one other typedef. | |
| 3281 for (TypedefElement cycle in seenTypedefs) { | |
| 3282 if (!identical(typedefElement, cycle)) { | |
| 3283 compiler.reportError(element, | |
| 3284 MessageKind.CYCLIC_TYPEDEF_ONE, | |
| 3285 {'typedefName': element.name, | |
| 3286 'otherTypedefName': cycle.name}); | |
| 3287 } | |
| 3288 } | |
| 3289 } | |
| 3290 } | |
| 3291 return; | |
| 3292 } | |
|
karlklose
2013/09/17 08:56:15
Please use an else block here. The return is easy
Johnni Winther
2013/09/18 07:57:15
Done.
| |
| 3293 seenTypedefs = seenTypedefs.prepend(typedefElement); | |
| 3294 type.visitChildren(this, null); | |
| 3295 typedefElement.alias.accept(this, null); | |
| 3296 seenTypedefs = seenTypedefs.tail; | |
| 3297 } | |
| 3298 | |
| 3299 visitFunctionType(FunctionType type, _) { | |
| 3300 type.visitChildren(this, null); | |
| 3301 } | |
| 3302 | |
| 3303 visitInterfaceType(InterfaceType type, _) { | |
| 3304 type.visitChildren(this, null); | |
| 3305 } | |
| 3306 | |
| 3307 visitTypeVariableType(TypeVariableType type, _) { | |
| 3308 TypeVariableElement typeVariableElement = type.element; | |
| 3309 if (seenTypeVariables.contains(typeVariableElement)) { | |
| 3310 // Avoid running in cycles on cyclic type variable bounds. | |
| 3311 // Cyclicity is reported elsewhere. | |
| 3312 return; | |
| 3313 } | |
| 3314 seenTypeVariables = seenTypeVariables.prepend(typeVariableElement); | |
| 3315 seenBoundsCount++; | |
| 3316 typeVariableElement.bound.accept(this, null); | |
| 3317 seenBoundsCount--; | |
| 3318 seenTypeVariables = seenTypeVariables.tail; | |
| 3319 } | |
| 3320 } | |
| 3321 | |
| 3237 /** | 3322 /** |
| 3238 * The implementation of [ResolverTask.resolveClass]. | 3323 * The implementation of [ResolverTask.resolveClass]. |
| 3239 * | 3324 * |
| 3240 * This visitor has to be extra careful as it is building the basic | 3325 * This visitor has to be extra careful as it is building the basic |
| 3241 * element information, and cannot safely look at other elements as | 3326 * element information, and cannot safely look at other elements as |
| 3242 * this may lead to cycles. | 3327 * this may lead to cycles. |
| 3243 * | 3328 * |
| 3244 * This visitor can assume that the supertypes have already been | 3329 * This visitor can assume that the supertypes have already been |
| 3245 * resolved, but it cannot call [ResolverTask.resolveClass] directly | 3330 * resolved, but it cannot call [ResolverTask.resolveClass] directly |
| 3246 * or indirectly (through [ClassElement.ensureResolved]) for any other | 3331 * or indirectly (through [ClassElement.ensureResolved]) for any other |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4093 return e; | 4178 return e; |
| 4094 } | 4179 } |
| 4095 | 4180 |
| 4096 /// Assumed to be called by [resolveRedirectingFactory]. | 4181 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4097 Element visitReturn(Return node) { | 4182 Element visitReturn(Return node) { |
| 4098 Node expression = node.expression; | 4183 Node expression = node.expression; |
| 4099 return finishConstructorReference(visit(expression), | 4184 return finishConstructorReference(visit(expression), |
| 4100 expression, expression); | 4185 expression, expression); |
| 4101 } | 4186 } |
| 4102 } | 4187 } |
| OLD | NEW |