Chromium Code Reviews| Index: lib/compiler/implementation/resolver.dart |
| diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart |
| index d9fde2468d86e0429f93c1ff3365cc7208d162d2..574492e51839fa38b15d182de464afbafdfed3ce 100644 |
| --- a/lib/compiler/implementation/resolver.dart |
| +++ b/lib/compiler/implementation/resolver.dart |
| @@ -945,6 +945,7 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| final Element enclosingElement; |
| final TypeResolver typeResolver; |
| bool inInstanceContext; |
| + bool inCheckContext; |
| Scope scope; |
| ClassElement currentClass; |
| bool typeRequired = false; |
| @@ -959,12 +960,12 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| // fields. |
| inInstanceContext = (element.isInstanceMember() && !element.isField()) |
| || element.isGenerativeConstructor(), |
| - this.currentClass = element.isMember() ? |
| - element.getEnclosingClass() : |
| - null, |
| + this.currentClass = element.isMember() ? element.getEnclosingClass() |
| + : null, |
| this.statementScope = new StatementScope(), |
| typeResolver = new TypeResolver(compiler), |
| scope = element.buildEnclosingScope(), |
| + inCheckContext = compiler.enableTypeAssertions, |
| super(compiler) { |
| } |
| @@ -990,6 +991,14 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| return element; |
| } |
| + doInCheckContext(action()) { |
| + bool wasInCheckContext = inCheckContext; |
| + inCheckContext = true; |
| + var result = action(); |
| + inCheckContext = wasInCheckContext; |
| + return result; |
| + } |
| + |
| inStaticContext(action()) { |
| bool wasInstanceContext = inInstanceContext; |
| inInstanceContext = false; |
| @@ -1030,7 +1039,12 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| Element visitTypeAnnotation(TypeAnnotation node) { |
| Type type = resolveTypeAnnotation(node); |
| - if (type !== null) return type.element; |
| + if (type !== null) { |
| + if (inCheckContext) { |
| + compiler.registerIsCheck(type); |
|
ngeoffray
2012/08/30 11:03:33
Just enqueuer.resolution
karlklose
2012/08/30 13:04:31
Done.
|
| + } |
| + return type.element; |
| + } |
| return null; |
| } |
| @@ -1336,7 +1350,10 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| String operatorString = node.selector.asOperator().source.stringValue; |
| if (operatorString === 'is' || operatorString === 'as') { |
| assert(node.arguments.tail.isEmpty()); |
| - resolveTypeTest(node.arguments.head); |
| + Type type = resolveTypeTest(node.arguments.head); |
| + if (type != null) { |
| + compiler.registerIsCheck(type); |
|
ngeoffray
2012/08/30 11:03:33
ditto
karlklose
2012/08/30 13:04:31
Done.
|
| + } |
| resolvedArguments = true; |
| } |
| } |
| @@ -1595,9 +1612,14 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| Type resolveTypeAnnotation(TypeAnnotation node) { |
| Function report = typeRequired ? error : warning; |
| - return typeResolver.resolveTypeAnnotation(node, inScope: scope, |
| - onFailure: report, |
| - whenResolved: useType); |
| + Type type = typeResolver.resolveTypeAnnotation(node, inScope: scope, |
| + onFailure: report, |
| + whenResolved: useType); |
| + if (compiler.enableTypeAssertions) { |
| + compiler.enqueuer.codegen.registerIsCheck(type); |
|
ngeoffray
2012/08/30 11:03:33
Not codegen, just resolution.
karlklose
2012/08/30 13:04:31
Done.
|
| + compiler.enqueuer.resolution.registerIsCheck(type); |
| + } |
| + return type; |
| } |
| visitModifiers(Modifiers node) { |
| @@ -1848,8 +1870,16 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| error(extra, MessageKind.EXTRA_CATCH_DECLARATION); |
| } |
| } |
| - visitIn(node.type, blockScope); |
| - visitIn(node.formals, blockScope); |
| + if (node.type != null) { |
| + doInCheckContext(() => visitIn(node.type, blockScope)); |
|
ngeoffray
2012/08/30 11:03:33
Do you need the inCheckContext state? If visiting
karlklose
2012/08/30 13:04:31
True, but currently ResolverVisitor is a visitor o
|
| + visitIn(node.formals, blockScope); |
| + } else { |
| + // The type annotation for the exception type is on the first formal. |
| + doInCheckContext(() => visitIn(node.formals.nodes.head, blockScope)); |
| + if (!node.formals.nodes.tail.isEmpty()) { |
| + visitIn(node.formals.nodes.tail.head, blockScope); |
| + } |
| + } |
| visitIn(node.block, blockScope); |
| } |