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 interface TreeElements { | 5 interface TreeElements { |
6 Element operator[](Node node); | 6 Element operator[](Node node); |
7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
9 } | 9 } |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 if (isConstructor) { | 121 if (isConstructor) { |
122 resolveConstructorImplementation(element, tree); | 122 resolveConstructorImplementation(element, tree); |
123 } | 123 } |
124 ResolverVisitor visitor = new ResolverVisitor(compiler, element); | 124 ResolverVisitor visitor = new ResolverVisitor(compiler, element); |
125 visitor.useElement(tree, element); | 125 visitor.useElement(tree, element); |
126 visitor.setupFunction(tree, element); | 126 visitor.setupFunction(tree, element); |
127 | 127 |
128 if (isConstructor) { | 128 if (isConstructor) { |
129 // Even if there is no initializer list we still have to do the | 129 // Even if there is no initializer list we still have to do the |
130 // resolution in case there is an implicit super constructor call. | 130 // resolution in case there is an implicit super constructor call. |
131 InitializerResolver resolver = new InitializerResolver(visitor); | 131 InitializerResolver resolver = |
132 new InitializerResolver(compiler, visitor); | |
132 FunctionElement redirection = | 133 FunctionElement redirection = |
133 resolver.resolveInitializers(element, tree); | 134 resolver.resolveInitializers(element, tree); |
134 if (redirection !== null) { | 135 if (redirection !== null) { |
135 resolveRedirectingConstructor(resolver, tree, element, redirection); | 136 resolveRedirectingConstructor(resolver, tree, element, redirection); |
136 } | 137 } |
137 } else if (tree.initializers != null) { | 138 } else if (tree.initializers != null) { |
138 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); | 139 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); |
139 } | 140 } |
140 visitBody(visitor, tree.body); | 141 visitBody(visitor, tree.body); |
141 | 142 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 element); | 400 element); |
400 } | 401 } |
401 | 402 |
402 error(Node node, MessageKind kind, [arguments = const []]) { | 403 error(Node node, MessageKind kind, [arguments = const []]) { |
403 ResolutionError message = new ResolutionError(kind, arguments); | 404 ResolutionError message = new ResolutionError(kind, arguments); |
404 compiler.reportError(node, message); | 405 compiler.reportError(node, message); |
405 } | 406 } |
406 } | 407 } |
407 | 408 |
408 class InitializerResolver { | 409 class InitializerResolver { |
410 final Compiler compiler; | |
ahe
2012/08/15 10:47:07
Don't need this field.
| |
409 final ResolverVisitor visitor; | 411 final ResolverVisitor visitor; |
410 final Map<SourceString, Node> initialized; | 412 final Map<SourceString, Node> initialized; |
411 Link<Node> initializers; | 413 Link<Node> initializers; |
412 bool hasSuper; | 414 bool hasSuper; |
413 | 415 |
414 InitializerResolver(this.visitor) | 416 InitializerResolver(this.compiler, this.visitor) |
415 : initialized = new Map<SourceString, Node>(), hasSuper = false; | 417 : initialized = new Map<SourceString, Node>(), hasSuper = false; |
416 | 418 |
417 error(Node node, MessageKind kind, [arguments = const []]) { | 419 error(Node node, MessageKind kind, [arguments = const []]) { |
418 visitor.error(node, kind, arguments); | 420 visitor.error(node, kind, arguments); |
419 } | 421 } |
420 | 422 |
421 warning(Node node, MessageKind kind, [arguments = const []]) { | 423 warning(Node node, MessageKind kind, [arguments = const []]) { |
422 visitor.warning(node, kind, arguments); | 424 visitor.warning(node, kind, arguments); |
423 } | 425 } |
424 | 426 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 } | 547 } |
546 return null; | 548 return null; |
547 } | 549 } |
548 | 550 |
549 /** | 551 /** |
550 * Resolve all initializers of this constructor. In the case of a redirecting | 552 * Resolve all initializers of this constructor. In the case of a redirecting |
551 * constructor, the resolved constructor's function element is returned. | 553 * constructor, the resolved constructor's function element is returned. |
552 */ | 554 */ |
553 FunctionElement resolveInitializers(FunctionElement constructor, | 555 FunctionElement resolveInitializers(FunctionElement constructor, |
554 FunctionExpression functionNode) { | 556 FunctionExpression functionNode) { |
557 // keep track of all "this.param" parameters specified for constructor so | |
ahe
2012/08/15 10:47:07
Not a proper sentence. By which I mean: please cap
| |
558 // that we can ensure that fields are initialized only once | |
559 FunctionSignature functionParameters = | |
560 constructor.computeSignature(compiler); | |
ahe
2012/08/15 10:47:07
You can get this from visitor.compiler.
| |
561 if (functionParameters != null) { | |
562 functionParameters.forEachParameter((Element element) { | |
563 if (element.kind == ElementKind.FIELD_PARAMETER) { | |
564 initialized[element.name] = element; | |
565 } | |
566 }); | |
567 } | |
568 | |
555 if (functionNode.initializers === null) { | 569 if (functionNode.initializers === null) { |
556 initializers = const EmptyLink<Node>(); | 570 initializers = const EmptyLink<Node>(); |
557 } else { | 571 } else { |
558 initializers = functionNode.initializers.nodes; | 572 initializers = functionNode.initializers.nodes; |
559 } | 573 } |
560 FunctionElement result; | 574 FunctionElement result; |
561 bool resolvedSuper = false; | 575 bool resolvedSuper = false; |
562 for (Link<Node> link = initializers; | 576 for (Link<Node> link = initializers; |
563 !link.isEmpty(); | 577 !link.isEmpty(); |
564 link = link.tail) { | 578 link = link.tail) { |
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2458 TopScope(LibraryElement library) : super(null, library); | 2472 TopScope(LibraryElement library) : super(null, library); |
2459 Element lookup(SourceString name) { | 2473 Element lookup(SourceString name) { |
2460 return library.find(name); | 2474 return library.find(name); |
2461 } | 2475 } |
2462 | 2476 |
2463 Element add(Element newElement) { | 2477 Element add(Element newElement) { |
2464 throw "Cannot add an element in the top scope"; | 2478 throw "Cannot add an element in the top scope"; |
2465 } | 2479 } |
2466 String toString() => '$element'; | 2480 String toString() => '$element'; |
2467 } | 2481 } |
OLD | NEW |