Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10834358: Remove cached constructor elements from the resolver. They are already stored in the resolution wor… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 Type getType(TypeAnnotation annotation) => types[annotation]; 29 Type getType(TypeAnnotation annotation) => types[annotation];
30 30
31 void setSelector(Send send, Selector selector) { 31 void setSelector(Send send, Selector selector) {
32 selectors[send] = selector; 32 selectors[send] = selector;
33 } 33 }
34 34
35 Selector getSelector(Send send) => selectors[send]; 35 Selector getSelector(Send send) => selectors[send];
36 } 36 }
37 37
38 class ResolverTask extends CompilerTask { 38 class ResolverTask extends CompilerTask {
39 // Caches the elements of analyzed constructors to make them available 39 ResolverTask(Compiler compiler) : super(compiler);
40 // for inlining in later tasks.
41 Map<FunctionElement, TreeElements> constructorElements;
42
43 ResolverTask(Compiler compiler)
44 : super(compiler),
45 constructorElements = new Map<FunctionElement, TreeElements>();
46 40
47 String get name() => 'Resolver'; 41 String get name() => 'Resolver';
48 42
49 TreeElements resolve(Element element) { 43 TreeElements resolve(Element element) {
50 return measure(() { 44 return measure(() {
51 ElementKind kind = element.kind; 45 ElementKind kind = element.kind;
52 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR || 46 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR ||
53 kind === ElementKind.FUNCTION || 47 kind === ElementKind.FUNCTION ||
54 kind === ElementKind.GETTER || 48 kind === ElementKind.GETTER ||
55 kind === ElementKind.SETTER) { 49 kind === ElementKind.SETTER) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return; 99 return;
106 } 100 }
107 seen.add(redirection); 101 seen.add(redirection);
108 redirection = resolveConstructorRedirection(redirection); 102 redirection = resolveConstructorRedirection(redirection);
109 } 103 }
110 } 104 }
111 105
112 TreeElements resolveMethodElement(FunctionElement element) { 106 TreeElements resolveMethodElement(FunctionElement element) {
113 return compiler.withCurrentElement(element, () { 107 return compiler.withCurrentElement(element, () {
114 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; 108 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR;
115 if (constructorElements.containsKey(element)) { 109 TreeElements elements =
110 compiler.enqueuer.resolution.getCachedElements(element);
111 if (elements !== null) {
116 assert(isConstructor); 112 assert(isConstructor);
117 TreeElements elements = constructorElements[element]; 113 return elements;
118 if (elements !== null) return elements;
119 } 114 }
120 FunctionExpression tree = element.parseNode(compiler); 115 FunctionExpression tree = element.parseNode(compiler);
121 if (isConstructor) { 116 if (isConstructor) {
122 resolveConstructorImplementation(element, tree); 117 resolveConstructorImplementation(element, tree);
123 } 118 }
124 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 119 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
125 visitor.useElement(tree, element); 120 visitor.useElement(tree, element);
126 visitor.setupFunction(tree, element); 121 visitor.setupFunction(tree, element);
127 122
128 if (isConstructor) { 123 if (isConstructor) {
129 // Even if there is no initializer list we still have to do the 124 // Even if there is no initializer list we still have to do the
130 // resolution in case there is an implicit super constructor call. 125 // resolution in case there is an implicit super constructor call.
131 InitializerResolver resolver = new InitializerResolver(visitor); 126 InitializerResolver resolver = new InitializerResolver(visitor);
132 FunctionElement redirection = 127 FunctionElement redirection =
133 resolver.resolveInitializers(element, tree); 128 resolver.resolveInitializers(element, tree);
134 if (redirection !== null) { 129 if (redirection !== null) {
135 resolveRedirectingConstructor(resolver, tree, element, redirection); 130 resolveRedirectingConstructor(resolver, tree, element, redirection);
136 } 131 }
137 } else if (tree.initializers != null) { 132 } else if (tree.initializers != null) {
138 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); 133 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER);
139 } 134 }
140 visitBody(visitor, tree.body); 135 visitBody(visitor, tree.body);
141 136
142 if (isConstructor) {
143 constructorElements[element] = visitor.mapping;
144 }
145 return visitor.mapping; 137 return visitor.mapping;
146 }); 138 });
147 } 139 }
148 140
149 void visitBody(ResolverVisitor visitor, Statement body) { 141 void visitBody(ResolverVisitor visitor, Statement body) {
150 visitor.visit(body); 142 visitor.visit(body);
151 } 143 }
152 144
153 void resolveConstructorImplementation(FunctionElement constructor, 145 void resolveConstructorImplementation(FunctionElement constructor,
154 FunctionExpression node) { 146 FunctionExpression node) {
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 TopScope(LibraryElement library) : super(null, library); 2451 TopScope(LibraryElement library) : super(null, library);
2460 Element lookup(SourceString name) { 2452 Element lookup(SourceString name) {
2461 return library.find(name); 2453 return library.find(name);
2462 } 2454 }
2463 2455
2464 Element add(Element newElement) { 2456 Element add(Element newElement) {
2465 throw "Cannot add an element in the top scope"; 2457 throw "Cannot add an element in the top scope";
2466 } 2458 }
2467 String toString() => '$element'; 2459 String toString() => '$element';
2468 } 2460 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698